Merge pull request #10202 from filecoin-project/feat/faster-sectors-list
sp cli: make sectors list much faster
This commit is contained in:
commit
285dfed338
@ -9,6 +9,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
@ -33,11 +34,14 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
cliutil "github.com/filecoin-project/lotus/cli/util"
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
||||||
|
"github.com/filecoin-project/lotus/lib/result"
|
||||||
"github.com/filecoin-project/lotus/lib/strle"
|
"github.com/filecoin-project/lotus/lib/strle"
|
||||||
"github.com/filecoin-project/lotus/lib/tablewriter"
|
"github.com/filecoin-project/lotus/lib/tablewriter"
|
||||||
sealing "github.com/filecoin-project/lotus/storage/pipeline"
|
sealing "github.com/filecoin-project/lotus/storage/pipeline"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const parallelSectorChecks = 300
|
||||||
|
|
||||||
var sectorsCmd = &cli.Command{
|
var sectorsCmd = &cli.Command{
|
||||||
Name: "sectors",
|
Name: "sectors",
|
||||||
Usage: "interact with sector store",
|
Usage: "interact with sector store",
|
||||||
@ -306,9 +310,15 @@ var sectorsListCmd = &cli.Command{
|
|||||||
Usage: "only show sectors which aren't in the 'Proving' state",
|
Usage: "only show sectors which aren't in the 'Proving' state",
|
||||||
Aliases: []string{"u"},
|
Aliases: []string{"u"},
|
||||||
},
|
},
|
||||||
|
&cli.Int64Flag{
|
||||||
|
Name: "check-parallelism",
|
||||||
|
Usage: "number of parallel requests to make for checking sector states",
|
||||||
|
Value: parallelSectorChecks,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
// http mode allows for parallel json decoding/encoding, which was a bottleneck here
|
||||||
|
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx, cliutil.StorageMinerUseHttp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -407,16 +417,37 @@ var sectorsListCmd = &cli.Command{
|
|||||||
|
|
||||||
fast := cctx.Bool("fast")
|
fast := cctx.Bool("fast")
|
||||||
|
|
||||||
for _, s := range list {
|
throttle := make(chan struct{}, cctx.Int64("check-parallelism"))
|
||||||
st, err := minerApi.SectorsStatus(ctx, s, !fast)
|
|
||||||
if err != nil {
|
slist := make([]result.Result[api.SectorInfo], len(list))
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
for i, s := range list {
|
||||||
|
throttle <- struct{}{}
|
||||||
|
wg.Add(1)
|
||||||
|
go func(i int, s abi.SectorNumber) {
|
||||||
|
defer wg.Done()
|
||||||
|
defer func() { <-throttle }()
|
||||||
|
r := result.Wrap(minerApi.SectorsStatus(ctx, s, !fast))
|
||||||
|
if r.Error != nil {
|
||||||
|
r.Value.SectorID = s
|
||||||
|
}
|
||||||
|
slist[i] = r
|
||||||
|
}(i, s)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
for _, rsn := range slist {
|
||||||
|
if rsn.Error != nil {
|
||||||
tw.Write(map[string]interface{}{
|
tw.Write(map[string]interface{}{
|
||||||
"ID": s,
|
"ID": rsn.Value.SectorID,
|
||||||
"Error": err,
|
"Error": err,
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
st := rsn.Value
|
||||||
|
s := st.SectorID
|
||||||
|
|
||||||
if !showRemoved && st.State == api.SectorState(sealing.Removed) {
|
if !showRemoved && st.State == api.SectorState(sealing.Removed) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1717,13 +1717,14 @@ USAGE:
|
|||||||
lotus-miner sectors list [command options] [arguments...]
|
lotus-miner sectors list [command options] [arguments...]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--events, -e display number of events the sector has received (default: false)
|
--check-parallelism value number of parallel requests to make for checking sector states (default: 300)
|
||||||
--fast, -f don't show on-chain info for better performance (default: false)
|
--events, -e display number of events the sector has received (default: false)
|
||||||
--initial-pledge, -p display initial pledge (default: false)
|
--fast, -f don't show on-chain info for better performance (default: false)
|
||||||
--seal-time, -t display how long it took for the sector to be sealed (default: false)
|
--initial-pledge, -p display initial pledge (default: false)
|
||||||
--show-removed, -r show removed sectors (default: false)
|
--seal-time, -t display how long it took for the sector to be sealed (default: false)
|
||||||
--states value filter sectors by a comma-separated list of states
|
--show-removed, -r show removed sectors (default: false)
|
||||||
--unproven, -u only show sectors which aren't in the 'Proving' state (default: false)
|
--states value filter sectors by a comma-separated list of states
|
||||||
|
--unproven, -u only show sectors which aren't in the 'Proving' state (default: false)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user