storage: storage find command

This commit is contained in:
Łukasz Magiera 2020-03-19 20:51:33 +01:00
parent 314fba049f
commit 978a718159
5 changed files with 148 additions and 3 deletions

View File

@ -109,6 +109,7 @@ type StorageMiner interface {
SectorsUpdate(context.Context, abi.SectorNumber, SectorState) error
StorageList(ctx context.Context) (map[stores.ID][]stores.Decl, error)
StorageLocal(ctx context.Context) (map[stores.ID]string, error)
// WorkerConnect tells the node to connect to workers RPC
WorkerConnect(context.Context, string) error

View File

@ -182,10 +182,11 @@ type StorageMinerStruct struct {
SectorsUpdate func(context.Context, abi.SectorNumber, api.SectorState) error `perm:"write"`
WorkerConnect func(context.Context, string) error `perm:"admin"` // TODO: worker perm
StorageList func(context.Context) (map[stores.ID][]stores.Decl, error) `perm:"admin"`
StorageLocal func(context.Context) (map[stores.ID]string, error) `perm:"admin"`
StorageAttach func(context.Context, stores.StorageInfo, stores.FsStat) error `perm:"admin"`
StorageDeclareSector func(context.Context, stores.ID, abi.SectorID, sectorbuilder.SectorFileType) error `perm:"admin"`
StorageFindSector func(context.Context, abi.SectorID, sectorbuilder.SectorFileType) ([]stores.StorageInfo, error) `perm:"admin"`
StorageList func(context.Context) (map[stores.ID][]stores.Decl, error) `perm:"admin"`
StorageInfo func(context.Context, stores.ID) (stores.StorageInfo, error) `perm:"admin"`
StorageBestAlloc func(ctx context.Context, allocate sectorbuilder.SectorFileType, sealing bool) ([]stores.StorageInfo, error) `perm:"admin"`
@ -671,6 +672,10 @@ func (c *StorageMinerStruct) StorageList(ctx context.Context) (map[stores.ID][]s
return c.Internal.StorageList(ctx)
}
func (c *StorageMinerStruct) StorageLocal(ctx context.Context) (map[stores.ID]string, error) {
return c.Internal.StorageLocal(ctx)
}
func (c *StorageMinerStruct) StorageInfo(ctx context.Context, id stores.ID) (stores.StorageInfo, error) {
return c.Internal.StorageInfo(ctx, id)
}

View File

@ -3,15 +3,18 @@ package main
import (
"encoding/json"
"fmt"
"github.com/filecoin-project/specs-actors/actors/abi"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"github.com/google/uuid"
"github.com/mitchellh/go-homedir"
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-sectorbuilder"
lcli "github.com/filecoin-project/lotus/cli"
@ -26,6 +29,7 @@ var storageCmd = &cli.Command{
Subcommands: []*cli.Command{
storageAttachCmd,
storageListCmd,
storageFindCmd,
},
}
@ -109,7 +113,8 @@ var storageAttachCmd = &cli.Command{
}
var storageListCmd = &cli.Command{
Name: "list",
Name: "list",
Usage: "list local storage paths",
Action: func(cctx *cli.Context) error {
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
@ -123,6 +128,11 @@ var storageListCmd = &cli.Command{
return err
}
local, err := nodeApi.StorageLocal(ctx)
if err != nil {
return err
}
for id, sectors := range st {
var u, s, c int
for _, decl := range sectors {
@ -145,8 +155,119 @@ var storageListCmd = &cli.Command{
return err
}
fmt.Printf("\tSeal: %t; Store: %t; Weight: %d\n", si.CanSeal, si.CanStore, si.Weight)
if localPath, ok := local[id]; ok {
fmt.Printf("\tLocal: %s\n", localPath)
}
for _, l := range si.URLs {
fmt.Printf("\tReachable %s\n", l) // TODO; try pinging maybe?? print latency?
fmt.Printf("\tURL: %s\n", l) // TODO; try pinging maybe?? print latency?
}
}
return nil
},
}
type storedSector struct {
store stores.StorageInfo
unsealed, sealed, cache bool
}
var storageFindCmd = &cli.Command{
Name: "find",
Usage: "find sector in the storage system",
ArgsUsage: "[sector number]",
Action: func(cctx *cli.Context) error {
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
ma, err := nodeApi.ActorAddress(ctx)
if err != nil {
return err
}
mid, err := address.IDFromAddress(ma)
if err != nil {
return err
}
if !cctx.Args().Present() {
return xerrors.New("Usage: lotus-storage-miner storage find [sector number]")
}
snum, err := strconv.ParseUint(cctx.Args().First(), 10, 64)
if err != nil {
return err
}
sid := abi.SectorID{
Miner: abi.ActorID(mid),
Number: abi.SectorNumber(snum),
}
u, err := nodeApi.StorageFindSector(ctx, sid, sectorbuilder.FTUnsealed)
if err != nil {
return xerrors.Errorf("finding unsealed: %w", err)
}
s, err := nodeApi.StorageFindSector(ctx, sid, sectorbuilder.FTSealed)
if err != nil {
return xerrors.Errorf("finding sealed: %w", err)
}
c, err := nodeApi.StorageFindSector(ctx, sid, sectorbuilder.FTCache)
if err != nil {
return xerrors.Errorf("finding cache: %w", err)
}
byId := map[stores.ID]*storedSector{}
for _, info := range u {
sts, ok := byId[info.ID]
if !ok {
sts = &storedSector{
store: info,
}
byId[info.ID] = sts
}
sts.unsealed = true
}
for _, info := range s {
sts, ok := byId[info.ID]
if !ok {
sts = &storedSector{
store: info,
}
byId[info.ID] = sts
}
sts.sealed = true
}
for _, info := range c {
sts, ok := byId[info.ID]
if !ok {
sts = &storedSector{
store: info,
}
byId[info.ID] = sts
}
sts.cache = true
}
local, err := nodeApi.StorageLocal(ctx)
if err != nil {
return err
}
for id, info := range byId {
fmt.Printf("In %s (Unsealed: %t; Sealed: %t; Cache: %t)\n", id, info.unsealed, info.sealed, info.cache)
fmt.Printf("\tSealing: %t; Storage: %t\n", info.store.CanSeal, info.store.CanSeal)
if localPath, ok := local[id]; ok {
fmt.Printf("\tLocal: %s\n", localPath)
}
for _, l := range info.store.URLs {
fmt.Printf("\tURL: %s\n", l)
}
}

View File

@ -123,6 +123,10 @@ func (sm *StorageMinerAPI) SectorsList(context.Context) ([]abi.SectorNumber, err
return out, nil
}
func (sm *StorageMinerAPI) StorageLocal(ctx context.Context) (map[stores.ID]string, error) {
return sm.StorageMgr.StorageLocal(ctx)
}
func (sm *StorageMinerAPI) SectorsRefs(context.Context) (map[string][]api.SealedRef, error) {
// json can't handle cids as map keys
out := map[string][]api.SealedRef{}

View File

@ -288,4 +288,18 @@ func (m *Manager) FinalizeSector(ctx context.Context, sector abi.SectorID) error
return candidateWorkers[0].FinalizeSector(ctx, sector)
}
func (m *Manager) StorageLocal(ctx context.Context) (map[stores.ID]string, error) {
l, err := m.localStore.Local(ctx)
if err != nil {
return nil, err
}
out := map[stores.ID]string{}
for _, st := range l {
out[st.ID] = st.LocalPath
}
return out, nil
}
var _ sealmgr.Manager = &Manager{}