From a550fb584bab7d904f4f327090a6a8c21263b64d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 14 Feb 2024 13:49:36 +0300 Subject: [PATCH] writecache: Check whether we are in a degraded mode Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/writecache/delete.go | 3 +++ pkg/local_object_storage/writecache/get.go | 8 ++++++++ pkg/local_object_storage/writecache/put.go | 3 +++ pkg/local_object_storage/writecache/seal.go | 3 +++ pkg/local_object_storage/writecache/writecache.go | 2 ++ 5 files changed, 19 insertions(+) diff --git a/pkg/local_object_storage/writecache/delete.go b/pkg/local_object_storage/writecache/delete.go index cedb9f4a..08f00806 100644 --- a/pkg/local_object_storage/writecache/delete.go +++ b/pkg/local_object_storage/writecache/delete.go @@ -37,6 +37,9 @@ func (c *cache) Delete(ctx context.Context, addr oid.Address) error { return ErrNotInitialized } defer c.modeMtx.RUnlock() + if c.mode.NoMetabase() { + return ErrDegraded + } if c.readOnly() { return ErrReadOnly } diff --git a/pkg/local_object_storage/writecache/get.go b/pkg/local_object_storage/writecache/get.go index d2496e44..06da7ede 100644 --- a/pkg/local_object_storage/writecache/get.go +++ b/pkg/local_object_storage/writecache/get.go @@ -41,6 +41,14 @@ func (c *cache) getInternal(ctx context.Context, saddr string, addr oid.Address) c.metrics.Get(time.Since(startedAt), found, storageType) }() + if !c.modeMtx.TryRLock() { + return nil, ErrNotInitialized + } + defer c.modeMtx.RUnlock() + if c.mode.NoMetabase() { + return nil, ErrDegraded + } + value, err := Get(c.db, []byte(saddr)) if err == nil { obj := objectSDK.New() diff --git a/pkg/local_object_storage/writecache/put.go b/pkg/local_object_storage/writecache/put.go index 8b6c09e9..bdadbfa9 100644 --- a/pkg/local_object_storage/writecache/put.go +++ b/pkg/local_object_storage/writecache/put.go @@ -38,6 +38,9 @@ func (c *cache) Put(ctx context.Context, prm common.PutPrm) (common.PutRes, erro return common.PutRes{}, ErrNotInitialized } defer c.modeMtx.RUnlock() + if c.mode.NoMetabase() { + return common.PutRes{}, ErrDegraded + } if c.readOnly() { return common.PutRes{}, ErrReadOnly } diff --git a/pkg/local_object_storage/writecache/seal.go b/pkg/local_object_storage/writecache/seal.go index be4fec36..56801125 100644 --- a/pkg/local_object_storage/writecache/seal.go +++ b/pkg/local_object_storage/writecache/seal.go @@ -18,6 +18,9 @@ func (c *cache) Seal(ctx context.Context, ignoreErrors bool) error { c.modeMtx.Lock() defer c.modeMtx.Unlock() + if c.mode.NoMetabase() { + return ErrDegraded + } // flush will be done by setMode err := c.setMode(ctx, mode.DegradedReadOnly, ignoreErrors) diff --git a/pkg/local_object_storage/writecache/writecache.go b/pkg/local_object_storage/writecache/writecache.go index 112594ec..f22f15c8 100644 --- a/pkg/local_object_storage/writecache/writecache.go +++ b/pkg/local_object_storage/writecache/writecache.go @@ -65,4 +65,6 @@ var ( ErrBigObject = errors.New("too big object") // ErrOutOfSpace is returned when there is no space left to put a new object. ErrOutOfSpace = errors.New("no space left in the write cache") + // ErrDegraded is returned when writecache is in degraded mode. + ErrDegraded = logicerr.New("write-cache is in degraded mode") )