[#1085] writecache: add read-only mode

In read-only mode modifying operations are immediately returned with
error and all background operations are suspended.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-01-18 15:47:16 +03:00 committed by LeL
parent 9f963e001b
commit ad01aaf8bf
7 changed files with 139 additions and 28 deletions

View file

@ -21,6 +21,7 @@ type Cache interface {
Head(*objectSDK.Address) (*object.Object, error)
Delete(*objectSDK.Address) error
Put(*object.Object) error
SetMode(Mode)
DumpInfo() Info
Init() error
@ -35,6 +36,9 @@ type cache struct {
mtx sync.RWMutex
mem []objectInfo
mode Mode
modeMtx sync.RWMutex
// compressFlags maps address of a big object to boolean value indicating
// whether object should be compressed.
compressFlags map[string]struct{}
@ -83,6 +87,7 @@ func New(opts ...Option) Cache {
metaCh: make(chan *object.Object),
closeCh: make(chan struct{}),
evictCh: make(chan []byte),
mode: ModeReadWrite,
compressFlags: make(map[string]struct{}),
options: options{