From 60212c86cbd855ba531fb9e7a8303cf57eb25b67 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 13 Jul 2021 03:14:13 +0300 Subject: [PATCH] put a mutex around HeadChange --- blockstore/splitstore/splitstore.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index 90ebbffcd..d45c79d93 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -128,6 +128,8 @@ type SplitStore struct { warmupEpoch abi.ChainEpoch // protected by mx baseEpoch abi.ChainEpoch // protected by compaction lock + headChangeMx sync.Mutex + coldPurgeSize int chain ChainAccessor @@ -552,6 +554,9 @@ func (s *SplitStore) Close() error { } func (s *SplitStore) HeadChange(_, apply []*types.TipSet) error { + s.headChangeMx.Lock() + defer s.headChangeMx.Unlock() + // Revert only. if len(apply) == 0 { return nil @@ -566,6 +571,8 @@ func (s *SplitStore) HeadChange(_, apply []*types.TipSet) error { // this is guaranteed by the chainstore, and it is pervasive in all lotus // -- if that ever changes then all hell will break loose in general and // we will have a rance to protectTipSets here. + // Reagrdless, we put a mutex in HeadChange just to be safe + if !atomic.CompareAndSwapInt32(&s.compacting, 0, 1) { // we are currently compacting -- protect the new tipset(s) s.protectTipSets(apply)