78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package sealing
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
|
)
|
|
|
|
type statSectorState int
|
|
|
|
const (
|
|
sstStaging statSectorState = iota
|
|
sstSealing
|
|
sstFailed
|
|
sstProving
|
|
nsst
|
|
)
|
|
|
|
type SectorStats struct {
|
|
lk sync.Mutex
|
|
|
|
bySector map[abi.SectorID]statSectorState
|
|
totals [nsst]uint64
|
|
}
|
|
|
|
func (ss *SectorStats) updateSector(cfg sealiface.Config, id abi.SectorID, st SectorState) (updateInput bool) {
|
|
ss.lk.Lock()
|
|
defer ss.lk.Unlock()
|
|
|
|
preSealing := ss.totals[sstStaging] + ss.totals[sstSealing] + ss.totals[sstFailed]
|
|
preStaging := ss.totals[sstStaging]
|
|
|
|
// update totals
|
|
oldst, found := ss.bySector[id]
|
|
if found {
|
|
ss.totals[oldst]--
|
|
}
|
|
|
|
sst := toStatState(st)
|
|
ss.bySector[id] = sst
|
|
ss.totals[sst]++
|
|
|
|
// check if we may need be able to process more deals
|
|
sealing := ss.totals[sstStaging] + ss.totals[sstSealing] + ss.totals[sstFailed]
|
|
staging := ss.totals[sstStaging]
|
|
|
|
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
|
|
}
|
|
|
|
// return the number of sectors currently in the sealing pipeline
|
|
func (ss *SectorStats) curSealing() uint64 {
|
|
ss.lk.Lock()
|
|
defer ss.lk.Unlock()
|
|
|
|
return ss.totals[sstStaging] + ss.totals[sstSealing] + ss.totals[sstFailed]
|
|
}
|
|
|
|
// return the number of sectors waiting to enter the sealing pipeline
|
|
func (ss *SectorStats) curStaging() uint64 {
|
|
ss.lk.Lock()
|
|
defer ss.lk.Unlock()
|
|
|
|
return ss.totals[sstStaging]
|
|
}
|