From 5b9ea1b4e04c9e418b482041bfb5623f729b05a6 Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 31 Jan 2022 18:47:08 +0200 Subject: [PATCH] avoid races in beginCriticalSection --- blockstore/splitstore/splitstore_compact.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/blockstore/splitstore/splitstore_compact.go b/blockstore/splitstore/splitstore_compact.go index 6175818bb..af5a425e9 100644 --- a/blockstore/splitstore/splitstore_compact.go +++ b/blockstore/splitstore/splitstore_compact.go @@ -711,6 +711,11 @@ func (s *SplitStore) beginTxnProtect() { func (s *SplitStore) beginCriticalSection(markSet MarkSet) error { log.Info("beginning critical section") + // do that once first to get the bulk before the markset is in critical section + if err := s.protectTxnRefs(markSet); err != nil { + return xerrors.Errorf("error protecting transactional references: %w", err) + } + if err := markSet.BeginCriticalSection(); err != nil { return xerrors.Errorf("error beginning critical section for markset: %w", err) } @@ -719,6 +724,7 @@ func (s *SplitStore) beginCriticalSection(markSet MarkSet) error { s.txnMarkSet = markSet s.txnLk.Unlock() + // and do it again to mark references that might have been created in the meantime if err := s.protectTxnRefs(markSet); err != nil { return xerrors.Errorf("error protecting transactional references: %w", err) }