Skip to content

Commit

Permalink
address review: make warmupEpoch an atomic.Int64
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed May 10, 2023
1 parent fb228eb commit 1cf36d8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions blockstore/splitstore/splitstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ type SplitStore struct {
path string

mx sync.Mutex
warmupEpoch int64 // atomically accessed
warmupEpoch atomic.Int64
baseEpoch abi.ChainEpoch // protected by compaction lock
pruneEpoch abi.ChainEpoch // protected by compaction lock

Expand Down Expand Up @@ -684,7 +684,7 @@ func (s *SplitStore) View(ctx context.Context, cid cid.Cid, cb func([]byte) erro
}

func (s *SplitStore) isWarm() bool {
return atomic.LoadInt64(&s.warmupEpoch) > 0
return s.warmupEpoch.Load() > 0
}

// State tracking
Expand Down Expand Up @@ -755,7 +755,7 @@ func (s *SplitStore) Start(chain ChainAccessor, us stmgr.UpgradeSchedule) error
bs, err = s.ds.Get(s.ctx, warmupEpochKey)
switch err {
case nil:
atomic.StoreInt64(&s.warmupEpoch, bytesToInt64(bs))
s.warmupEpoch.Store(bytesToInt64(bs))

case dstore.ErrNotFound:
warmup = true
Expand Down Expand Up @@ -789,7 +789,7 @@ func (s *SplitStore) Start(chain ChainAccessor, us stmgr.UpgradeSchedule) error
return xerrors.Errorf("error loading compaction index: %w", err)
}

log.Infow("starting splitstore", "baseEpoch", s.baseEpoch, "warmupEpoch", atomic.LoadInt64(&s.warmupEpoch))
log.Infow("starting splitstore", "baseEpoch", s.baseEpoch, "warmupEpoch", s.warmupEpoch.Load())

if warmup {
err = s.warmup(curTs)
Expand Down
2 changes: 1 addition & 1 deletion blockstore/splitstore/splitstore_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (s *SplitStore) doCheck(curTs *types.TipSet) error {
func (s *SplitStore) Info() map[string]interface{} {
info := make(map[string]interface{})
info["base epoch"] = s.baseEpoch
info["warmup epoch"] = atomic.LoadInt64(&s.warmupEpoch)
info["warmup epoch"] = s.warmupEpoch.Load()
info["compactions"] = s.compactionIndex
info["prunes"] = s.pruneIndex
info["compacting"] = s.compacting == 1
Expand Down
5 changes: 2 additions & 3 deletions blockstore/splitstore/splitstore_warmup.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ func (s *SplitStore) doWarmup(curTs *types.TipSet) error {
if err != nil {
return xerrors.Errorf("error saving warm up epoch: %w", err)
}
s.mx.Lock()
atomic.StoreInt64(&s.warmupEpoch, int64(epoch))
s.mx.Unlock()

s.warmupEpoch.Store(int64(epoch))

// also save the compactionIndex, as this is used as an indicator of warmup for upgraded nodes
err = s.ds.Put(s.ctx, compactionIndexKey, int64ToBytes(s.compactionIndex))
Expand Down

0 comments on commit 1cf36d8

Please sign in to comment.