Skip to content

Commit

Permalink
put a mutex around HeadChange
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Jul 13, 2021
1 parent 759594d commit 60212c8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions blockstore/splitstore/splitstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 60212c8

Please sign in to comment.