Merge pull request #5176 from filecoin-project/shaodan-miner-sectors-info

Shaodan miner sectors info
This commit is contained in:
Łukasz Magiera 2020-12-10 20:09:15 +01:00 committed by GitHub
commit 2e154ef6d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 136 additions and 14 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"`
@ -1258,6 +1260,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

@ -237,6 +237,10 @@ func init() {
addExample(map[abi.SectorNumber]string{
123: "can't acquire read lock",
})
addExample(map[api.SectorState]int{
api.SectorState(sealing.Proving): 120,
})
addExample([]abi.SectorNumber{123, 124})
// worker specific
addExample(storiface.AcquireMove)

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

@ -101,8 +101,10 @@
* [SectorStartSealing](#SectorStartSealing)
* [Sectors](#Sectors)
* [SectorsList](#SectorsList)
* [SectorsListInStates](#SectorsListInStates)
* [SectorsRefs](#SectorsRefs)
* [SectorsStatus](#SectorsStatus)
* [SectorsSummary](#SectorsSummary)
* [SectorsUpdate](#SectorsUpdate)
* [Storage](#Storage)
* [StorageAddLocal](#StorageAddLocal)
@ -1544,7 +1546,34 @@ Perms: read
Inputs: `null`
Response: `null`
Response:
```json
[
123,
124
]
```
### SectorsListInStates
List sectors in particular states
Perms: read
Inputs:
```json
[
null
]
```
Response:
```json
[
123,
124
]
```
### SectorsRefs
There are not yet any comments for this method.
@ -1614,6 +1643,21 @@ Response:
}
```
### SectorsSummary
Get summary info of sectors
Perms: read
Inputs: `null`
Response:
```json
{
"Proving": 120
}
```
### SectorsUpdate
There are not yet any comments for this method.

View File

@ -222,6 +222,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]++
}
return out, nil
}
func (sm *StorageMinerAPI) StorageLocal(ctx context.Context) (map[stores.ID]string, error) {
return sm.StorageMgr.StorageLocal(ctx)
}