From 92dcfe530b967093bd6c832684259f1d4c73b665 Mon Sep 17 00:00:00 2001 From: Aayush Date: Fri, 5 May 2023 13:48:46 -0400 Subject: [PATCH] feat: splitstore: access warmupepoch atomically instead of locking --- blockstore/splitstore/splitstore.go | 10 ++++------ blockstore/splitstore/splitstore_check.go | 2 +- blockstore/splitstore/splitstore_warmup.go | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index ba53feb77..b42028e28 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -164,7 +164,7 @@ type SplitStore struct { path string mx sync.Mutex - warmupEpoch abi.ChainEpoch // protected by mx + warmupEpoch int64 // atomically accessed baseEpoch abi.ChainEpoch // protected by compaction lock pruneEpoch abi.ChainEpoch // protected by compaction lock @@ -684,9 +684,7 @@ func (s *SplitStore) View(ctx context.Context, cid cid.Cid, cb func([]byte) erro } func (s *SplitStore) isWarm() bool { - s.mx.Lock() - defer s.mx.Unlock() - return s.warmupEpoch > 0 + return atomic.LoadInt64(&s.warmupEpoch) > 0 } // State tracking @@ -757,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: - s.warmupEpoch = bytesToEpoch(bs) + atomic.StoreInt64(&s.warmupEpoch, bytesToInt64(bs)) case dstore.ErrNotFound: warmup = true @@ -791,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", s.warmupEpoch) + log.Infow("starting splitstore", "baseEpoch", s.baseEpoch, "warmupEpoch", atomic.LoadInt64(&s.warmupEpoch)) if warmup { err = s.warmup(curTs) diff --git a/blockstore/splitstore/splitstore_check.go b/blockstore/splitstore/splitstore_check.go index 2645c78c5..6a58ee0bf 100644 --- a/blockstore/splitstore/splitstore_check.go +++ b/blockstore/splitstore/splitstore_check.go @@ -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"] = s.warmupEpoch + info["warmup epoch"] = atomic.LoadInt64(&s.warmupEpoch) info["compactions"] = s.compactionIndex info["prunes"] = s.pruneIndex info["compacting"] = s.compacting == 1 diff --git a/blockstore/splitstore/splitstore_warmup.go b/blockstore/splitstore/splitstore_warmup.go index e387263da..9f079344f 100644 --- a/blockstore/splitstore/splitstore_warmup.go +++ b/blockstore/splitstore/splitstore_warmup.go @@ -137,7 +137,7 @@ func (s *SplitStore) doWarmup(curTs *types.TipSet) error { return xerrors.Errorf("error saving warm up epoch: %w", err) } s.mx.Lock() - s.warmupEpoch = epoch + atomic.StoreInt64(&s.warmupEpoch, int64(epoch)) s.mx.Unlock() // also save the compactionIndex, as this is used as an indicator of warmup for upgraded nodes