Merge branch 'miner-sectors-info' of github.com:shaodan/lotus into shaodan-miner-sectors-info

This commit is contained in:
Łukasz Magiera 2020-12-10 19:32:26 +01:00
commit d347e7ab8f
5 changed files with 87 additions and 13 deletions

View File

@ -43,6 +43,12 @@ type StorageMiner interface {
// List all staged sectors
SectorsList(context.Context) ([]abi.SectorNumber, error)
// Get summary info of sectors
SectorsSummary(ctx context.Context) (map[SectorState]int, error)
// List sectors in particular states
SectorsListInStates(context.Context, []SectorState) ([]abi.SectorNumber, error)
SectorsRefs(context.Context) (map[string][]SealedRef, error)
// SectorStartSealing can be called on sectors in Empty or WaitDeals states

View File

@ -302,6 +302,8 @@ type StorageMinerStruct struct {
SectorsStatus func(ctx context.Context, sid abi.SectorNumber, showOnChainInfo bool) (api.SectorInfo, error) `perm:"read"`
SectorsList func(context.Context) ([]abi.SectorNumber, error) `perm:"read"`
SectorsListInStates func(context.Context, []api.SectorState) ([]abi.SectorNumber, error) `perm:"read"`
SectorsSummary func(ctx context.Context) (map[api.SectorState]int, error) `perm:"read"`
SectorsRefs func(context.Context) (map[string][]api.SealedRef, error) `perm:"read"`
SectorStartSealing func(context.Context, abi.SectorNumber) error `perm:"write"`
SectorSetSealDelay func(context.Context, time.Duration) error `perm:"write"`
@ -1254,6 +1256,14 @@ func (c *StorageMinerStruct) SectorsList(ctx context.Context) ([]abi.SectorNumbe
return c.Internal.SectorsList(ctx)
}
func (c *StorageMinerStruct) SectorsListInStates(ctx context.Context, states []api.SectorState) ([]abi.SectorNumber, error) {
return c.Internal.SectorsListInStates(ctx, states)
}
func (c *StorageMinerStruct) SectorsSummary(ctx context.Context) (map[api.SectorState]int, error) {
return c.Internal.SectorsSummary(ctx)
}
func (c *StorageMinerStruct) SectorsRefs(ctx context.Context) (map[string][]api.SealedRef, error) {
return c.Internal.SectorsRefs(ctx)
}

View File

@ -327,22 +327,18 @@ func init() {
}
func sectorsInfo(ctx context.Context, napi api.StorageMiner) error {
sectors, err := napi.SectorsList(ctx)
summary, err := napi.SectorsSummary(ctx)
if err != nil {
return err
}
buckets := map[sealing.SectorState]int{
"Total": len(sectors),
}
for _, s := range sectors {
st, err := napi.SectorsStatus(ctx, s, false)
if err != nil {
return err
}
buckets[sealing.SectorState(st.State)]++
buckets := make(map[sealing.SectorState]int)
var total int
for s, c := range summary {
buckets[sealing.SectorState(s)] = c
total += c
}
buckets["Total"] = total
var sorted []stateMeta
for state, i := range buckets {

View File

@ -164,6 +164,10 @@ var sectorsListCmd = &cli.Command{
Name: "seal-time",
Usage: "display how long it took for the sector to be sealed",
},
&cli.StringFlag{
Name: "states",
Usage: "filter sectors by a comma-separated list of states",
},
},
Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color")
@ -182,7 +186,22 @@ var sectorsListCmd = &cli.Command{
ctx := lcli.ReqContext(cctx)
list, err := nodeApi.SectorsList(ctx)
var list []abi.SectorNumber
showRemoved := cctx.Bool("show-removed")
states := cctx.String("states")
if len(states) == 0 {
list, err = nodeApi.SectorsList(ctx)
} else {
showRemoved = true
sList := strings.Split(states, ",")
ss := make([]api.SectorState, len(sList))
for i := range sList {
ss[i] = api.SectorState(sList[i])
}
list, err = nodeApi.SectorsListInStates(ctx, ss)
}
if err != nil {
return err
}
@ -244,7 +263,7 @@ var sectorsListCmd = &cli.Command{
continue
}
if cctx.Bool("show-removed") || st.State != api.SectorState(sealing.Removed) {
if showRemoved || st.State != api.SectorState(sealing.Removed) {
_, inSSet := commitedIDs[s]
_, inASet := activeIDs[s]

View File

@ -218,6 +218,49 @@ func (sm *StorageMinerAPI) SectorsList(context.Context) ([]abi.SectorNumber, err
return out, nil
}
func (sm *StorageMinerAPI) SectorsListInStates(ctx context.Context, states []api.SectorState) ([]abi.SectorNumber, error) {
filterStates := make(map[sealing.SectorState]struct{})
for _, state := range states {
st := sealing.SectorState(state)
if _, ok := sealing.ExistSectorStateList[st]; !ok {
continue
}
filterStates[st] = struct{}{}
}
var sns []abi.SectorNumber
if len(filterStates) == 0 {
return sns, nil
}
sectors, err := sm.Miner.ListSectors()
if err != nil {
return nil, err
}
for i := range sectors {
if _, ok := filterStates[sectors[i].State]; ok {
sns = append(sns, sectors[i].SectorNumber)
}
}
return sns, nil
}
func (sm *StorageMinerAPI) SectorsSummary(ctx context.Context) (map[api.SectorState]int, error) {
sectors, err := sm.Miner.ListSectors()
if err != nil {
return nil, err
}
out := make(map[api.SectorState]int)
for i := range sectors {
state := api.SectorState(sectors[i].State)
out[state] += 1
}
return out, nil
}
func (sm *StorageMinerAPI) StorageLocal(ctx context.Context) (map[stores.ID]string, error) {
return sm.StorageMgr.StorageLocal(ctx)
}