writecache: Check whether we are in a degraded mode

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-02-14 13:49:36 +03:00
parent 5cbf57081f
commit a550fb584b
5 changed files with 19 additions and 0 deletions

View file

@ -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
}

View file

@ -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()

View file

@ -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
}

View file

@ -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)

View file

@ -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")
)