From 713fdab1779f10ab998c7da6c01c9a6dbbe5ffb3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 25 Oct 2022 09:08:18 +0300 Subject: [PATCH] [#1907] shard: Return from `Close` after GC has stopped Signed-off-by: Evgenii Stratonikov --- CHANGELOG.md | 1 + pkg/local_object_storage/shard/gc.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81c0712a..ae617c42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Changelog for NeoFS Node - Correctly sign new epoch transaction in neofs-adm for a committee of more than 4 nodes (#1949) - Inability to provide session to NeoFS CLI in a NeoFS-binary format (#1933) - `neofs-adm` now works correctly with a committee of more than 4 nodes (#1949, #1959) +- Closing a shard now waits until GC background workers stop (#1964) ### Removed ### Updated diff --git a/pkg/local_object_storage/shard/gc.go b/pkg/local_object_storage/shard/gc.go index 75db47cf..95a7ddba 100644 --- a/pkg/local_object_storage/shard/gc.go +++ b/pkg/local_object_storage/shard/gc.go @@ -65,6 +65,7 @@ type gc struct { onceStop sync.Once stopChannel chan struct{} + wg sync.WaitGroup workerPool util.WorkerPool @@ -103,11 +104,14 @@ func (gc *gc) init() { gc.workerPool = gc.workerPoolInit(sz) } + gc.wg.Add(2) go gc.tickRemover() go gc.listenEvents() } func (gc *gc) listenEvents() { + defer gc.wg.Done() + for { event, ok := <-gc.eventChan if !ok { @@ -147,6 +151,8 @@ func (gc *gc) listenEvents() { } func (gc *gc) tickRemover() { + defer gc.wg.Done() + timer := time.NewTimer(gc.removerInterval) defer timer.Stop() @@ -172,6 +178,9 @@ func (gc *gc) stop() { gc.onceStop.Do(func() { gc.stopChannel <- struct{}{} }) + + gc.log.Info("waiting for GC workers to stop...") + gc.wg.Wait() } // iterates over metabase and deletes objects