[#569] writecache: Do not wait modeMtx if mode changes

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
rpc_not_defined
Dmitrii Stepanov 2023-12-27 11:40:55 +03:00
parent 32c282ca10
commit 7a9db5bcdd
2 changed files with 7 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import (
// Delete removes object from write-cache.
//
// Returns an error of type apistatus.ObjectNotFound if object is missing in write-cache.
// Returns ErrNotInitialized if write-cache has not been initialized yet.
func (c *cache) Delete(ctx context.Context, addr oid.Address) error {
ctx, span := tracing.StartSpanFromContext(ctx, "writecache.Delete",
trace.WithAttributes(
@ -32,7 +33,9 @@ func (c *cache) Delete(ctx context.Context, addr oid.Address) error {
c.metrics.Delete(time.Since(startedAt), deleted, storageType)
}()
c.modeMtx.RLock()
if !c.modeMtx.TryRLock() {
return ErrNotInitialized
}
defer c.modeMtx.RUnlock()
if c.readOnly() {
return ErrReadOnly

View File

@ -34,7 +34,9 @@ func (c *cache) Put(ctx context.Context, prm common.PutPrm) (common.PutRes, erro
c.metrics.Put(time.Since(startedAt), added, storageType)
}()
c.modeMtx.RLock()
if !c.modeMtx.TryRLock() {
return common.PutRes{}, ErrNotInitialized
}
defer c.modeMtx.RUnlock()
if c.readOnly() {
return common.PutRes{}, ErrReadOnly