add logic for supressing compaction near upgrade boundaries
This commit is contained in:
parent
9331714089
commit
05c1325885
@ -18,6 +18,8 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
bstore "github.com/filecoin-project/lotus/blockstore"
|
bstore "github.com/filecoin-project/lotus/blockstore"
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/metrics"
|
"github.com/filecoin-project/lotus/metrics"
|
||||||
|
|
||||||
@ -47,6 +49,9 @@ var (
|
|||||||
enableDebugLog = false
|
enableDebugLog = false
|
||||||
// set this to true if you want to track origin stack traces in the write log
|
// set this to true if you want to track origin stack traces in the write log
|
||||||
enableDebugLogWriteTraces = false
|
enableDebugLogWriteTraces = false
|
||||||
|
|
||||||
|
// upgradeBoundary is the boundary before and after an upgrade where we supress compaction
|
||||||
|
upgradeBoundary = build.Finality
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -98,6 +103,12 @@ type ChainAccessor interface {
|
|||||||
SubscribeHeadChanges(change func(revert []*types.TipSet, apply []*types.TipSet) error)
|
SubscribeHeadChanges(change func(revert []*types.TipSet, apply []*types.TipSet) error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// upgradeRange is a precomputed epoch range during which we shouldn't compact so as to not
|
||||||
|
// interfere with an upgrade
|
||||||
|
type upgradeRange struct {
|
||||||
|
start, end abi.ChainEpoch
|
||||||
|
}
|
||||||
|
|
||||||
// hotstore is the interface that must be satisfied by the hot blockstore; it is an extension
|
// hotstore is the interface that must be satisfied by the hot blockstore; it is an extension
|
||||||
// of the Blockstore interface with the traits we need for compaction.
|
// of the Blockstore interface with the traits we need for compaction.
|
||||||
type hotstore interface {
|
type hotstore interface {
|
||||||
@ -125,6 +136,8 @@ type SplitStore struct {
|
|||||||
cold bstore.Blockstore
|
cold bstore.Blockstore
|
||||||
hot hotstore
|
hot hotstore
|
||||||
|
|
||||||
|
upgrades []upgradeRange
|
||||||
|
|
||||||
markSetEnv MarkSetEnv
|
markSetEnv MarkSetEnv
|
||||||
markSetSize int64
|
markSetSize int64
|
||||||
|
|
||||||
@ -463,10 +476,27 @@ func (s *SplitStore) isWarm() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// State tracking
|
// State tracking
|
||||||
func (s *SplitStore) Start(chain ChainAccessor) error {
|
func (s *SplitStore) Start(chain ChainAccessor, us stmgr.UpgradeSchedule) error {
|
||||||
s.chain = chain
|
s.chain = chain
|
||||||
curTs := chain.GetHeaviestTipSet()
|
curTs := chain.GetHeaviestTipSet()
|
||||||
|
|
||||||
|
// precompute the upgrade boundaries
|
||||||
|
s.upgrades = make([]upgradeRange, 0, len(us))
|
||||||
|
for _, upgrade := range us {
|
||||||
|
boundary := upgrade.Height
|
||||||
|
for _, pre := range upgrade.PreMigrations {
|
||||||
|
preMigrationBoundary := upgrade.Height - pre.StartWithin
|
||||||
|
if preMigrationBoundary < boundary {
|
||||||
|
boundary = preMigrationBoundary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
upgradeStart := boundary - upgradeBoundary
|
||||||
|
upgradeEnd := upgrade.Height + upgradeBoundary
|
||||||
|
|
||||||
|
s.upgrades = append(s.upgrades, upgradeRange{start: upgradeStart, end: upgradeEnd})
|
||||||
|
}
|
||||||
|
|
||||||
// should we warmup
|
// should we warmup
|
||||||
warmup := false
|
warmup := false
|
||||||
|
|
||||||
|
@ -99,6 +99,12 @@ func (s *SplitStore) HeadChange(_, apply []*types.TipSet) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.isNearUpgrade(epoch) {
|
||||||
|
// we are near an upgrade epoch, supress compaction
|
||||||
|
atomic.StoreInt32(&s.compacting, 0)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if epoch-s.baseEpoch > CompactionThreshold {
|
if epoch-s.baseEpoch > CompactionThreshold {
|
||||||
// it's time to compact -- prepare the transaction and go!
|
// it's time to compact -- prepare the transaction and go!
|
||||||
s.beginTxnProtect()
|
s.beginTxnProtect()
|
||||||
@ -121,6 +127,16 @@ func (s *SplitStore) HeadChange(_, apply []*types.TipSet) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SplitStore) isNearUpgrade(epoch abi.ChainEpoch) bool {
|
||||||
|
for _, upgrade := range s.upgrades {
|
||||||
|
if epoch >= upgrade.start && epoch <= upgrade.end {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// transactionally protect incoming tipsets
|
// transactionally protect incoming tipsets
|
||||||
func (s *SplitStore) protectTipSets(apply []*types.TipSet) {
|
func (s *SplitStore) protectTipSets(apply []*types.TipSet) {
|
||||||
s.txnLk.RLock()
|
s.txnLk.RLock()
|
||||||
|
Loading…
Reference in New Issue
Block a user