Merge branch 'miner-sectors-info' of github.com:shaodan/lotus into shaodan-miner-sectors-info
This commit is contained in:
commit
d347e7ab8f
@ -43,6 +43,12 @@ type StorageMiner interface {
|
|||||||
// List all staged sectors
|
// List all staged sectors
|
||||||
SectorsList(context.Context) ([]abi.SectorNumber, error)
|
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)
|
SectorsRefs(context.Context) (map[string][]SealedRef, error)
|
||||||
|
|
||||||
// SectorStartSealing can be called on sectors in Empty or WaitDeals states
|
// SectorStartSealing can be called on sectors in Empty or WaitDeals states
|
||||||
|
@ -302,6 +302,8 @@ type StorageMinerStruct struct {
|
|||||||
|
|
||||||
SectorsStatus func(ctx context.Context, sid abi.SectorNumber, showOnChainInfo bool) (api.SectorInfo, error) `perm:"read"`
|
SectorsStatus func(ctx context.Context, sid abi.SectorNumber, showOnChainInfo bool) (api.SectorInfo, error) `perm:"read"`
|
||||||
SectorsList func(context.Context) ([]abi.SectorNumber, 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"`
|
SectorsRefs func(context.Context) (map[string][]api.SealedRef, error) `perm:"read"`
|
||||||
SectorStartSealing func(context.Context, abi.SectorNumber) error `perm:"write"`
|
SectorStartSealing func(context.Context, abi.SectorNumber) error `perm:"write"`
|
||||||
SectorSetSealDelay func(context.Context, time.Duration) 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)
|
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) {
|
func (c *StorageMinerStruct) SectorsRefs(ctx context.Context) (map[string][]api.SealedRef, error) {
|
||||||
return c.Internal.SectorsRefs(ctx)
|
return c.Internal.SectorsRefs(ctx)
|
||||||
}
|
}
|
||||||
|
@ -327,22 +327,18 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sectorsInfo(ctx context.Context, napi api.StorageMiner) error {
|
func sectorsInfo(ctx context.Context, napi api.StorageMiner) error {
|
||||||
sectors, err := napi.SectorsList(ctx)
|
summary, err := napi.SectorsSummary(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
buckets := map[sealing.SectorState]int{
|
buckets := make(map[sealing.SectorState]int)
|
||||||
"Total": len(sectors),
|
var total int
|
||||||
}
|
for s, c := range summary {
|
||||||
for _, s := range sectors {
|
buckets[sealing.SectorState(s)] = c
|
||||||
st, err := napi.SectorsStatus(ctx, s, false)
|
total += c
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
buckets[sealing.SectorState(st.State)]++
|
|
||||||
}
|
}
|
||||||
|
buckets["Total"] = total
|
||||||
|
|
||||||
var sorted []stateMeta
|
var sorted []stateMeta
|
||||||
for state, i := range buckets {
|
for state, i := range buckets {
|
||||||
|
@ -164,6 +164,10 @@ var sectorsListCmd = &cli.Command{
|
|||||||
Name: "seal-time",
|
Name: "seal-time",
|
||||||
Usage: "display how long it took for the sector to be sealed",
|
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 {
|
Action: func(cctx *cli.Context) error {
|
||||||
color.NoColor = !cctx.Bool("color")
|
color.NoColor = !cctx.Bool("color")
|
||||||
@ -182,7 +186,22 @@ var sectorsListCmd = &cli.Command{
|
|||||||
|
|
||||||
ctx := lcli.ReqContext(cctx)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -244,7 +263,7 @@ var sectorsListCmd = &cli.Command{
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if cctx.Bool("show-removed") || st.State != api.SectorState(sealing.Removed) {
|
if showRemoved || st.State != api.SectorState(sealing.Removed) {
|
||||||
_, inSSet := commitedIDs[s]
|
_, inSSet := commitedIDs[s]
|
||||||
_, inASet := activeIDs[s]
|
_, inASet := activeIDs[s]
|
||||||
|
|
||||||
|
@ -218,6 +218,49 @@ func (sm *StorageMinerAPI) SectorsList(context.Context) ([]abi.SectorNumber, err
|
|||||||
return out, nil
|
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) {
|
func (sm *StorageMinerAPI) StorageLocal(ctx context.Context) (map[stores.ID]string, error) {
|
||||||
return sm.StorageMgr.StorageLocal(ctx)
|
return sm.StorageMgr.StorageLocal(ctx)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user