diff --git a/CHANGELOG.md b/CHANGELOG.md index 9076e978f80..6ba9dc94a1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ## New features - feat: Added new tracing API (**HIGHLY EXPERIMENTAL**) supporting two RPC methods: `trace_block` and `trace_replayBlockTransactions` ([filecoin-project/lotus#11100](https://github.com/filecoin-project/lotus/pull/11100)) +## Improvements +- fix: Add time slicing to splitstore purging step during compaction to reduce lock congestion [filecoin-project/lotus#11269](https://github.com/filecoin-project/lotus/pull/11269) + # v1.23.3 / 2023-08-01 This feature release of Lotus includes numerous improvements and enhancements for node operators, ETH RPC-providers and storage providers. diff --git a/blockstore/splitstore/splitstore_compact.go b/blockstore/splitstore/splitstore_compact.go index 534565bf388..47caca886da 100644 --- a/blockstore/splitstore/splitstore_compact.go +++ b/blockstore/splitstore/splitstore_compact.go @@ -66,8 +66,9 @@ var ( ) const ( - batchSize = 16384 - cidKeySize = 128 + batchSize = 16384 + cidKeySize = 128 + purgeWorkSliceDuration = time.Second ) func (s *SplitStore) HeadChange(_, apply []*types.TipSet) error { @@ -1372,9 +1373,21 @@ func (s *SplitStore) purge(coldr *ColdSetReader, checkpoint *Checkpoint, markSet return err } + now := time.Now() + err := coldr.ForEach(func(c cid.Cid) error { batch = append(batch, c) if len(batch) == batchSize { + // add some time slicing to the purge as this a very disk I/O heavy operation that + // requires write access to txnLk that may starve other operations that require + // access to the blockstore. + elapsed := time.Since(now) + if elapsed > purgeWorkSliceDuration { + // work 1 slice, sleep 4 slices, or 20% utilization + time.Sleep(4 * elapsed) + now = time.Now() + } + return deleteBatch() }