[#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 <p.karpy@yadro.com>
This commit is contained in:
Pavel Karpy 2023-04-17 18:40:23 +03:00 committed by Evgenii Stratonikov
parent 3d43b0f7f9
commit 20cd080323

View file

@ -86,13 +86,21 @@ func (c *cache) fsTreeFlushMarkUpdate(ctx context.Context) {
} }
return nil return nil
} }
c.modeMtx.RLock()
defer c.modeMtx.RUnlock()
_, _ = c.fsTree.Iterate(prm) _, _ = c.fsTree.Iterate(prm)
c.log.Info(logs.WritecacheFinishedUpdatingFSTreeFlushMarks) c.log.Info(logs.WritecacheFinishedUpdatingFSTreeFlushMarks)
} }
func (c *cache) dbFlushMarkUpdate(ctx context.Context) { func (c *cache) dbFlushMarkUpdate(ctx context.Context) {
c.log.Info(logs.WritecacheFillingFlushMarksForObjectsInDatabase) c.log.Info(logs.WritecacheFillingFlushMarksForObjectsInDatabase)
c.modeMtx.RLock()
defer c.modeMtx.RUnlock()
var m []string var m []string
var indices []int var indices []int
var lastKey []byte var lastKey []byte