2020-08-18 14:54:05 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
2021-10-19 16:52:54 +00:00
|
|
|
"context"
|
2021-10-19 16:56:30 +00:00
|
|
|
"sync"
|
|
|
|
|
2021-10-19 16:52:54 +00:00
|
|
|
"go.opencensus.io/stats"
|
|
|
|
"go.opencensus.io/tag"
|
2020-08-18 14:54:05 +00:00
|
|
|
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2021-10-19 16:56:30 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/metrics"
|
2022-06-14 17:41:59 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/pipeline/sealiface"
|
2020-08-18 14:54:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type statSectorState int
|
2020-08-18 16:27:28 +00:00
|
|
|
|
2020-08-18 14:54:05 +00:00
|
|
|
const (
|
2021-01-18 13:26:03 +00:00
|
|
|
sstStaging statSectorState = iota
|
|
|
|
sstSealing
|
2020-08-18 14:54:05 +00:00
|
|
|
sstFailed
|
|
|
|
sstProving
|
|
|
|
nsst
|
|
|
|
)
|
|
|
|
|
|
|
|
type SectorStats struct {
|
|
|
|
lk sync.Mutex
|
|
|
|
|
2021-10-19 16:52:54 +00:00
|
|
|
bySector map[abi.SectorID]SectorState
|
|
|
|
byState map[SectorState]int64
|
2020-08-18 16:27:28 +00:00
|
|
|
totals [nsst]uint64
|
2020-08-18 14:54:05 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 16:52:54 +00:00
|
|
|
func (ss *SectorStats) updateSector(ctx context.Context, cfg sealiface.Config, id abi.SectorID, st SectorState) (updateInput bool) {
|
2020-08-18 14:54:05 +00:00
|
|
|
ss.lk.Lock()
|
|
|
|
defer ss.lk.Unlock()
|
|
|
|
|
2021-03-12 16:00:20 +00:00
|
|
|
preSealing := ss.curSealingLocked()
|
|
|
|
preStaging := ss.curStagingLocked()
|
2021-03-12 13:54:10 +00:00
|
|
|
|
|
|
|
// update totals
|
2020-08-18 14:54:05 +00:00
|
|
|
oldst, found := ss.bySector[id]
|
|
|
|
if found {
|
2021-10-19 16:52:54 +00:00
|
|
|
ss.totals[toStatState(oldst, cfg.FinalizeEarly)]--
|
|
|
|
ss.byState[oldst]--
|
|
|
|
|
|
|
|
mctx, _ := tag.New(ctx, tag.Upsert(metrics.SectorState, string(oldst)))
|
|
|
|
stats.Record(mctx, metrics.SectorStates.M(ss.byState[oldst]))
|
2020-08-18 14:54:05 +00:00
|
|
|
}
|
|
|
|
|
2021-09-02 17:27:10 +00:00
|
|
|
sst := toStatState(st, cfg.FinalizeEarly)
|
2021-10-19 16:52:54 +00:00
|
|
|
ss.bySector[id] = st
|
2020-08-18 14:54:05 +00:00
|
|
|
ss.totals[sst]++
|
2021-10-19 16:52:54 +00:00
|
|
|
ss.byState[st]++
|
|
|
|
|
|
|
|
mctx, _ := tag.New(ctx, tag.Upsert(metrics.SectorState, string(st)))
|
|
|
|
stats.Record(mctx, metrics.SectorStates.M(ss.byState[st]))
|
2021-03-12 13:54:10 +00:00
|
|
|
|
|
|
|
// check if we may need be able to process more deals
|
2021-03-12 16:00:20 +00:00
|
|
|
sealing := ss.curSealingLocked()
|
|
|
|
staging := ss.curStagingLocked()
|
2021-03-12 13:54:10 +00:00
|
|
|
|
2021-03-12 16:25:24 +00:00
|
|
|
log.Debugw("sector stats", "sealing", sealing, "staging", staging)
|
|
|
|
|
2021-03-12 13:54:10 +00:00
|
|
|
if cfg.MaxSealingSectorsForDeals > 0 && // max sealing deal sector limit set
|
|
|
|
preSealing >= cfg.MaxSealingSectorsForDeals && // we were over limit
|
|
|
|
sealing < cfg.MaxSealingSectorsForDeals { // and we're below the limit now
|
|
|
|
updateInput = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.MaxWaitDealsSectors > 0 && // max waiting deal sector limit set
|
|
|
|
preStaging >= cfg.MaxWaitDealsSectors && // we were over limit
|
|
|
|
staging < cfg.MaxWaitDealsSectors { // and we're below the limit now
|
|
|
|
updateInput = true
|
|
|
|
}
|
|
|
|
|
|
|
|
return updateInput
|
2020-08-18 14:54:05 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 16:00:20 +00:00
|
|
|
func (ss *SectorStats) curSealingLocked() uint64 {
|
|
|
|
return ss.totals[sstStaging] + ss.totals[sstSealing] + ss.totals[sstFailed]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ss *SectorStats) curStagingLocked() uint64 {
|
|
|
|
return ss.totals[sstStaging]
|
|
|
|
}
|
|
|
|
|
2020-08-18 14:54:05 +00:00
|
|
|
// return the number of sectors currently in the sealing pipeline
|
|
|
|
func (ss *SectorStats) curSealing() uint64 {
|
|
|
|
ss.lk.Lock()
|
|
|
|
defer ss.lk.Unlock()
|
|
|
|
|
2021-03-12 16:00:20 +00:00
|
|
|
return ss.curSealingLocked()
|
2021-01-18 13:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return the number of sectors waiting to enter the sealing pipeline
|
|
|
|
func (ss *SectorStats) curStaging() uint64 {
|
|
|
|
ss.lk.Lock()
|
|
|
|
defer ss.lk.Unlock()
|
|
|
|
|
2021-03-12 16:00:20 +00:00
|
|
|
return ss.curStagingLocked()
|
2020-08-18 14:54:05 +00:00
|
|
|
}
|