From 20cd080323ef632ca09d34a7c5a2b3d4be5043df Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 17 Apr 2023 18:40:23 +0300 Subject: [PATCH] [#255] write-cache: Fix init race condition Do not use WC's internals in the initialization routines without mode protection. WC should be able to change its mode even if the initialization is not finished yet. Signed-off-by: Pavel Karpy --- pkg/local_object_storage/writecache/init.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/local_object_storage/writecache/init.go b/pkg/local_object_storage/writecache/init.go index d92e9a2d..2ca8ccee 100644 --- a/pkg/local_object_storage/writecache/init.go +++ b/pkg/local_object_storage/writecache/init.go @@ -86,13 +86,21 @@ func (c *cache) fsTreeFlushMarkUpdate(ctx context.Context) { } return nil } + + c.modeMtx.RLock() + defer c.modeMtx.RUnlock() + _, _ = c.fsTree.Iterate(prm) + c.log.Info(logs.WritecacheFinishedUpdatingFSTreeFlushMarks) } func (c *cache) dbFlushMarkUpdate(ctx context.Context) { c.log.Info(logs.WritecacheFillingFlushMarksForObjectsInDatabase) + c.modeMtx.RLock() + defer c.modeMtx.RUnlock() + var m []string var indices []int var lastKey []byte