From af399529ecca4c6e082474cada76c9b96a3d8f86 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 13 Jul 2021 09:06:40 +0300 Subject: [PATCH] finetune view waiting --- blockstore/splitstore/splitstore.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index 563b14bc4fe..75989b53c7e 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -146,15 +146,16 @@ type SplitStore struct { debug *debugLog // transactional protection for concurrent read/writes during compaction - txnLk sync.RWMutex - txnViewsMx sync.Mutex - txnViewsCond sync.Cond - txnViews int - txnActive bool - txnProtect MarkSet - txnRefsMx sync.Mutex - txnRefs map[cid.Cid]struct{} - txnMissing map[cid.Cid]struct{} + txnLk sync.RWMutex + txnViewsMx sync.Mutex + txnViewsCond sync.Cond + txnViews int + txnViewsWaiting bool + txnActive bool + txnProtect MarkSet + txnRefsMx sync.Mutex + txnRefs map[cid.Cid]struct{} + txnMissing map[cid.Cid]struct{} } var _ bstore.Blockstore = (*SplitStore)(nil) @@ -651,7 +652,7 @@ func (s *SplitStore) viewDone() { defer s.txnViewsMx.Unlock() s.txnViews-- - if s.txnViews == 0 { + if s.txnViews == 0 && s.txnViewsWaiting { s.txnViewsCond.Signal() } } @@ -660,9 +661,11 @@ func (s *SplitStore) viewWait() { s.txnViewsMx.Lock() defer s.txnViewsMx.Unlock() + s.txnViewsWaiting = true for s.txnViews > 0 { s.txnViewsCond.Wait() } + s.txnViewsWaiting = false } // transactionally protect a reference to an object