From 7a9db5bcdd2fd846252fa1388d76be2db8a9458d Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 27 Dec 2023 11:40:55 +0300 Subject: [PATCH] [#569] writecache: Do not wait modeMtx if mode changes Signed-off-by: Dmitrii Stepanov --- pkg/local_object_storage/writecache/delete.go | 5 ++++- pkg/local_object_storage/writecache/put.go | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/local_object_storage/writecache/delete.go b/pkg/local_object_storage/writecache/delete.go index 0a4f4d65..cedb9f4a 100644 --- a/pkg/local_object_storage/writecache/delete.go +++ b/pkg/local_object_storage/writecache/delete.go @@ -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 diff --git a/pkg/local_object_storage/writecache/put.go b/pkg/local_object_storage/writecache/put.go index 6fc655c6..8b6c09e9 100644 --- a/pkg/local_object_storage/writecache/put.go +++ b/pkg/local_object_storage/writecache/put.go @@ -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