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

View File

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