wait for reify workers to finish when closing

This commit is contained in:
vyzo 2022-02-14 16:10:54 +02:00
parent 6c7ababd3f
commit 4524fbe936
2 changed files with 4 additions and 0 deletions

View File

@ -162,6 +162,7 @@ type SplitStore struct {
txnSync bool
// background cold object reification
reifyWorkers sync.WaitGroup
reifyMx sync.Mutex
reifyCond sync.Cond
reifyPend map[cid.Cid]struct{}
@ -707,6 +708,7 @@ func (s *SplitStore) Close() error {
}
s.reifyCond.Broadcast()
s.reifyWorkers.Wait()
s.cancel()
return multierr.Combine(s.markSetEnv.Close(), s.debug.Close())
}

View File

@ -41,6 +41,7 @@ func (s *SplitStore) reifyOrchestrator() {
defer close(workch)
for i := 0; i < workers; i++ {
s.reifyWorkers.Add(1)
go s.reifyWorker(workch)
}
@ -70,6 +71,7 @@ func (s *SplitStore) reifyOrchestrator() {
}
func (s *SplitStore) reifyWorker(workch chan cid.Cid) {
defer s.reifyWorkers.Done()
for c := range workch {
s.doReify(c)
}