diff --git a/api/api_storage.go b/api/api_storage.go index f4b06d00a..bd7578593 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -24,7 +24,6 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" - "github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/lotus/extern/storage-sealing/sealiface" ) @@ -140,21 +139,21 @@ type StorageMiner interface { SealingSchedDiag(ctx context.Context, doSched bool) (interface{}, error) //perm:admin SealingAbort(ctx context.Context, call storiface.CallID) error //perm:admin - //stores.SectorIndex - StorageAttach(context.Context, stores.StorageInfo, fsutil.FsStat) error //perm:admin - StorageInfo(context.Context, stores.ID) (stores.StorageInfo, error) //perm:admin - StorageReportHealth(context.Context, stores.ID, stores.HealthReport) error //perm:admin - StorageDeclareSector(ctx context.Context, storageID stores.ID, s abi.SectorID, ft storiface.SectorFileType, primary bool) error //perm:admin - StorageDropSector(ctx context.Context, storageID stores.ID, s abi.SectorID, ft storiface.SectorFileType) error //perm:admin - StorageFindSector(ctx context.Context, sector abi.SectorID, ft storiface.SectorFileType, ssize abi.SectorSize, allowFetch bool) ([]stores.SectorStorageInfo, error) //perm:admin - StorageBestAlloc(ctx context.Context, allocate storiface.SectorFileType, ssize abi.SectorSize, pathType storiface.PathType) ([]stores.StorageInfo, error) //perm:admin - StorageLock(ctx context.Context, sector abi.SectorID, read storiface.SectorFileType, write storiface.SectorFileType) error //perm:admin - StorageTryLock(ctx context.Context, sector abi.SectorID, read storiface.SectorFileType, write storiface.SectorFileType) (bool, error) //perm:admin - StorageList(ctx context.Context) (map[stores.ID][]stores.Decl, error) //perm:admin - StorageGetLocks(ctx context.Context) (storiface.SectorLocks, error) //perm:admin + // SectorIndex + StorageAttach(context.Context, storiface.StorageInfo, fsutil.FsStat) error //perm:admin + StorageInfo(context.Context, storiface.ID) (storiface.StorageInfo, error) //perm:admin + StorageReportHealth(context.Context, storiface.ID, storiface.HealthReport) error //perm:admin + StorageDeclareSector(ctx context.Context, storageID storiface.ID, s abi.SectorID, ft storiface.SectorFileType, primary bool) error //perm:admin + StorageDropSector(ctx context.Context, storageID storiface.ID, s abi.SectorID, ft storiface.SectorFileType) error //perm:admin + StorageFindSector(ctx context.Context, sector abi.SectorID, ft storiface.SectorFileType, ssize abi.SectorSize, allowFetch bool) ([]storiface.SectorStorageInfo, error) //perm:admin + StorageBestAlloc(ctx context.Context, allocate storiface.SectorFileType, ssize abi.SectorSize, pathType storiface.PathType) ([]storiface.StorageInfo, error) //perm:admin + StorageLock(ctx context.Context, sector abi.SectorID, read storiface.SectorFileType, write storiface.SectorFileType) error //perm:admin + StorageTryLock(ctx context.Context, sector abi.SectorID, read storiface.SectorFileType, write storiface.SectorFileType) (bool, error) //perm:admin + StorageList(ctx context.Context) (map[storiface.ID][]storiface.Decl, error) //perm:admin + StorageGetLocks(ctx context.Context) (storiface.SectorLocks, error) //perm:admin - StorageLocal(ctx context.Context) (map[stores.ID]string, error) //perm:admin - StorageStat(ctx context.Context, id stores.ID) (fsutil.FsStat, error) //perm:admin + StorageLocal(ctx context.Context) (map[storiface.ID]string, error) //perm:admin + StorageStat(ctx context.Context, id storiface.ID) (fsutil.FsStat, error) //perm:admin MarketImportDealData(ctx context.Context, propcid cid.Cid, path string) error //perm:write MarketListDeals(ctx context.Context) ([]MarketDeal, error) //perm:read @@ -259,7 +258,6 @@ type StorageMiner interface { } var _ storiface.WorkerReturn = *new(StorageMiner) -var _ stores.SectorIndex = *new(StorageMiner) type SealRes struct { Err string diff --git a/api/api_worker.go b/api/api_worker.go index 1fafea8b8..c28b086ea 100644 --- a/api/api_worker.go +++ b/api/api_worker.go @@ -10,7 +10,6 @@ import ( "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" - "github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/specs-storage/storage" ) @@ -31,7 +30,7 @@ type Worker interface { // TaskType -> Weight TaskTypes(context.Context) (map[sealtasks.TaskType]struct{}, error) //perm:admin - Paths(context.Context) ([]stores.StoragePath, error) //perm:admin + Paths(context.Context) ([]storiface.StoragePath, error) //perm:admin Info(context.Context) (storiface.WorkerInfo, error) //perm:admin // storiface.WorkerCalls diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index 571599935..744d84da7 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -40,7 +40,6 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" - "github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" "github.com/filecoin-project/lotus/node/modules/dtypes" @@ -199,10 +198,10 @@ func init() { }, }) addExample(api.SectorState(sealing.Proving)) - addExample(stores.ID("76f1988b-ef30-4d7e-b3ec-9a627f4ba5a8")) + addExample(storiface.ID("76f1988b-ef30-4d7e-b3ec-9a627f4ba5a8")) addExample(storiface.FTUnsealed) addExample(storiface.PathSealing) - addExample(map[stores.ID][]stores.Decl{ + addExample(map[storiface.ID][]storiface.Decl{ "76f1988b-ef30-4d7e-b3ec-9a627f4ba5a8": { { SectorID: abi.SectorID{Miner: 1000, Number: 100}, @@ -210,7 +209,7 @@ func init() { }, }, }) - addExample(map[stores.ID]string{ + addExample(map[storiface.ID]string{ "76f1988b-ef30-4d7e-b3ec-9a627f4ba5a8": "/data/path", }) addExample(map[uuid.UUID][]storiface.WorkerJob{ diff --git a/api/proxy_gen.go b/api/proxy_gen.go index 00abca49b..9cb51b626 100644 --- a/api/proxy_gen.go +++ b/api/proxy_gen.go @@ -25,7 +25,6 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" - "github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/lotus/extern/storage-sealing/sealiface" "github.com/filecoin-project/lotus/journal/alerting" @@ -798,29 +797,29 @@ type StorageMinerStruct struct { StorageAddLocal func(p0 context.Context, p1 string) error `perm:"admin"` - StorageAttach func(p0 context.Context, p1 stores.StorageInfo, p2 fsutil.FsStat) error `perm:"admin"` + StorageAttach func(p0 context.Context, p1 storiface.StorageInfo, p2 fsutil.FsStat) error `perm:"admin"` - StorageBestAlloc func(p0 context.Context, p1 storiface.SectorFileType, p2 abi.SectorSize, p3 storiface.PathType) ([]stores.StorageInfo, error) `perm:"admin"` + StorageBestAlloc func(p0 context.Context, p1 storiface.SectorFileType, p2 abi.SectorSize, p3 storiface.PathType) ([]storiface.StorageInfo, error) `perm:"admin"` - StorageDeclareSector func(p0 context.Context, p1 stores.ID, p2 abi.SectorID, p3 storiface.SectorFileType, p4 bool) error `perm:"admin"` + StorageDeclareSector func(p0 context.Context, p1 storiface.ID, p2 abi.SectorID, p3 storiface.SectorFileType, p4 bool) error `perm:"admin"` - StorageDropSector func(p0 context.Context, p1 stores.ID, p2 abi.SectorID, p3 storiface.SectorFileType) error `perm:"admin"` + StorageDropSector func(p0 context.Context, p1 storiface.ID, p2 abi.SectorID, p3 storiface.SectorFileType) error `perm:"admin"` - StorageFindSector func(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 abi.SectorSize, p4 bool) ([]stores.SectorStorageInfo, error) `perm:"admin"` + StorageFindSector func(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 abi.SectorSize, p4 bool) ([]storiface.SectorStorageInfo, error) `perm:"admin"` StorageGetLocks func(p0 context.Context) (storiface.SectorLocks, error) `perm:"admin"` - StorageInfo func(p0 context.Context, p1 stores.ID) (stores.StorageInfo, error) `perm:"admin"` + StorageInfo func(p0 context.Context, p1 storiface.ID) (storiface.StorageInfo, error) `perm:"admin"` - StorageList func(p0 context.Context) (map[stores.ID][]stores.Decl, error) `perm:"admin"` + StorageList func(p0 context.Context) (map[storiface.ID][]storiface.Decl, error) `perm:"admin"` - StorageLocal func(p0 context.Context) (map[stores.ID]string, error) `perm:"admin"` + StorageLocal func(p0 context.Context) (map[storiface.ID]string, error) `perm:"admin"` StorageLock func(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 storiface.SectorFileType) error `perm:"admin"` - StorageReportHealth func(p0 context.Context, p1 stores.ID, p2 stores.HealthReport) error `perm:"admin"` + StorageReportHealth func(p0 context.Context, p1 storiface.ID, p2 storiface.HealthReport) error `perm:"admin"` - StorageStat func(p0 context.Context, p1 stores.ID) (fsutil.FsStat, error) `perm:"admin"` + StorageStat func(p0 context.Context, p1 storiface.ID) (fsutil.FsStat, error) `perm:"admin"` StorageTryLock func(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 storiface.SectorFileType) (bool, error) `perm:"admin"` @@ -879,7 +878,7 @@ type WorkerStruct struct { MoveStorage func(p0 context.Context, p1 storage.SectorRef, p2 storiface.SectorFileType) (storiface.CallID, error) `perm:"admin"` - Paths func(p0 context.Context) ([]stores.StoragePath, error) `perm:"admin"` + Paths func(p0 context.Context) ([]storiface.StoragePath, error) `perm:"admin"` ProcessSession func(p0 context.Context) (uuid.UUID, error) `perm:"admin"` @@ -4686,59 +4685,59 @@ func (s *StorageMinerStub) StorageAddLocal(p0 context.Context, p1 string) error return ErrNotSupported } -func (s *StorageMinerStruct) StorageAttach(p0 context.Context, p1 stores.StorageInfo, p2 fsutil.FsStat) error { +func (s *StorageMinerStruct) StorageAttach(p0 context.Context, p1 storiface.StorageInfo, p2 fsutil.FsStat) error { if s.Internal.StorageAttach == nil { return ErrNotSupported } return s.Internal.StorageAttach(p0, p1, p2) } -func (s *StorageMinerStub) StorageAttach(p0 context.Context, p1 stores.StorageInfo, p2 fsutil.FsStat) error { +func (s *StorageMinerStub) StorageAttach(p0 context.Context, p1 storiface.StorageInfo, p2 fsutil.FsStat) error { return ErrNotSupported } -func (s *StorageMinerStruct) StorageBestAlloc(p0 context.Context, p1 storiface.SectorFileType, p2 abi.SectorSize, p3 storiface.PathType) ([]stores.StorageInfo, error) { +func (s *StorageMinerStruct) StorageBestAlloc(p0 context.Context, p1 storiface.SectorFileType, p2 abi.SectorSize, p3 storiface.PathType) ([]storiface.StorageInfo, error) { if s.Internal.StorageBestAlloc == nil { - return *new([]stores.StorageInfo), ErrNotSupported + return *new([]storiface.StorageInfo), ErrNotSupported } return s.Internal.StorageBestAlloc(p0, p1, p2, p3) } -func (s *StorageMinerStub) StorageBestAlloc(p0 context.Context, p1 storiface.SectorFileType, p2 abi.SectorSize, p3 storiface.PathType) ([]stores.StorageInfo, error) { - return *new([]stores.StorageInfo), ErrNotSupported +func (s *StorageMinerStub) StorageBestAlloc(p0 context.Context, p1 storiface.SectorFileType, p2 abi.SectorSize, p3 storiface.PathType) ([]storiface.StorageInfo, error) { + return *new([]storiface.StorageInfo), ErrNotSupported } -func (s *StorageMinerStruct) StorageDeclareSector(p0 context.Context, p1 stores.ID, p2 abi.SectorID, p3 storiface.SectorFileType, p4 bool) error { +func (s *StorageMinerStruct) StorageDeclareSector(p0 context.Context, p1 storiface.ID, p2 abi.SectorID, p3 storiface.SectorFileType, p4 bool) error { if s.Internal.StorageDeclareSector == nil { return ErrNotSupported } return s.Internal.StorageDeclareSector(p0, p1, p2, p3, p4) } -func (s *StorageMinerStub) StorageDeclareSector(p0 context.Context, p1 stores.ID, p2 abi.SectorID, p3 storiface.SectorFileType, p4 bool) error { +func (s *StorageMinerStub) StorageDeclareSector(p0 context.Context, p1 storiface.ID, p2 abi.SectorID, p3 storiface.SectorFileType, p4 bool) error { return ErrNotSupported } -func (s *StorageMinerStruct) StorageDropSector(p0 context.Context, p1 stores.ID, p2 abi.SectorID, p3 storiface.SectorFileType) error { +func (s *StorageMinerStruct) StorageDropSector(p0 context.Context, p1 storiface.ID, p2 abi.SectorID, p3 storiface.SectorFileType) error { if s.Internal.StorageDropSector == nil { return ErrNotSupported } return s.Internal.StorageDropSector(p0, p1, p2, p3) } -func (s *StorageMinerStub) StorageDropSector(p0 context.Context, p1 stores.ID, p2 abi.SectorID, p3 storiface.SectorFileType) error { +func (s *StorageMinerStub) StorageDropSector(p0 context.Context, p1 storiface.ID, p2 abi.SectorID, p3 storiface.SectorFileType) error { return ErrNotSupported } -func (s *StorageMinerStruct) StorageFindSector(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 abi.SectorSize, p4 bool) ([]stores.SectorStorageInfo, error) { +func (s *StorageMinerStruct) StorageFindSector(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 abi.SectorSize, p4 bool) ([]storiface.SectorStorageInfo, error) { if s.Internal.StorageFindSector == nil { - return *new([]stores.SectorStorageInfo), ErrNotSupported + return *new([]storiface.SectorStorageInfo), ErrNotSupported } return s.Internal.StorageFindSector(p0, p1, p2, p3, p4) } -func (s *StorageMinerStub) StorageFindSector(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 abi.SectorSize, p4 bool) ([]stores.SectorStorageInfo, error) { - return *new([]stores.SectorStorageInfo), ErrNotSupported +func (s *StorageMinerStub) StorageFindSector(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 abi.SectorSize, p4 bool) ([]storiface.SectorStorageInfo, error) { + return *new([]storiface.SectorStorageInfo), ErrNotSupported } func (s *StorageMinerStruct) StorageGetLocks(p0 context.Context) (storiface.SectorLocks, error) { @@ -4752,37 +4751,37 @@ func (s *StorageMinerStub) StorageGetLocks(p0 context.Context) (storiface.Sector return *new(storiface.SectorLocks), ErrNotSupported } -func (s *StorageMinerStruct) StorageInfo(p0 context.Context, p1 stores.ID) (stores.StorageInfo, error) { +func (s *StorageMinerStruct) StorageInfo(p0 context.Context, p1 storiface.ID) (storiface.StorageInfo, error) { if s.Internal.StorageInfo == nil { - return *new(stores.StorageInfo), ErrNotSupported + return *new(storiface.StorageInfo), ErrNotSupported } return s.Internal.StorageInfo(p0, p1) } -func (s *StorageMinerStub) StorageInfo(p0 context.Context, p1 stores.ID) (stores.StorageInfo, error) { - return *new(stores.StorageInfo), ErrNotSupported +func (s *StorageMinerStub) StorageInfo(p0 context.Context, p1 storiface.ID) (storiface.StorageInfo, error) { + return *new(storiface.StorageInfo), ErrNotSupported } -func (s *StorageMinerStruct) StorageList(p0 context.Context) (map[stores.ID][]stores.Decl, error) { +func (s *StorageMinerStruct) StorageList(p0 context.Context) (map[storiface.ID][]storiface.Decl, error) { if s.Internal.StorageList == nil { - return *new(map[stores.ID][]stores.Decl), ErrNotSupported + return *new(map[storiface.ID][]storiface.Decl), ErrNotSupported } return s.Internal.StorageList(p0) } -func (s *StorageMinerStub) StorageList(p0 context.Context) (map[stores.ID][]stores.Decl, error) { - return *new(map[stores.ID][]stores.Decl), ErrNotSupported +func (s *StorageMinerStub) StorageList(p0 context.Context) (map[storiface.ID][]storiface.Decl, error) { + return *new(map[storiface.ID][]storiface.Decl), ErrNotSupported } -func (s *StorageMinerStruct) StorageLocal(p0 context.Context) (map[stores.ID]string, error) { +func (s *StorageMinerStruct) StorageLocal(p0 context.Context) (map[storiface.ID]string, error) { if s.Internal.StorageLocal == nil { - return *new(map[stores.ID]string), ErrNotSupported + return *new(map[storiface.ID]string), ErrNotSupported } return s.Internal.StorageLocal(p0) } -func (s *StorageMinerStub) StorageLocal(p0 context.Context) (map[stores.ID]string, error) { - return *new(map[stores.ID]string), ErrNotSupported +func (s *StorageMinerStub) StorageLocal(p0 context.Context) (map[storiface.ID]string, error) { + return *new(map[storiface.ID]string), ErrNotSupported } func (s *StorageMinerStruct) StorageLock(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 storiface.SectorFileType) error { @@ -4796,25 +4795,25 @@ func (s *StorageMinerStub) StorageLock(p0 context.Context, p1 abi.SectorID, p2 s return ErrNotSupported } -func (s *StorageMinerStruct) StorageReportHealth(p0 context.Context, p1 stores.ID, p2 stores.HealthReport) error { +func (s *StorageMinerStruct) StorageReportHealth(p0 context.Context, p1 storiface.ID, p2 storiface.HealthReport) error { if s.Internal.StorageReportHealth == nil { return ErrNotSupported } return s.Internal.StorageReportHealth(p0, p1, p2) } -func (s *StorageMinerStub) StorageReportHealth(p0 context.Context, p1 stores.ID, p2 stores.HealthReport) error { +func (s *StorageMinerStub) StorageReportHealth(p0 context.Context, p1 storiface.ID, p2 storiface.HealthReport) error { return ErrNotSupported } -func (s *StorageMinerStruct) StorageStat(p0 context.Context, p1 stores.ID) (fsutil.FsStat, error) { +func (s *StorageMinerStruct) StorageStat(p0 context.Context, p1 storiface.ID) (fsutil.FsStat, error) { if s.Internal.StorageStat == nil { return *new(fsutil.FsStat), ErrNotSupported } return s.Internal.StorageStat(p0, p1) } -func (s *StorageMinerStub) StorageStat(p0 context.Context, p1 stores.ID) (fsutil.FsStat, error) { +func (s *StorageMinerStub) StorageStat(p0 context.Context, p1 storiface.ID) (fsutil.FsStat, error) { return *new(fsutil.FsStat), ErrNotSupported } @@ -5038,15 +5037,15 @@ func (s *WorkerStub) MoveStorage(p0 context.Context, p1 storage.SectorRef, p2 st return *new(storiface.CallID), ErrNotSupported } -func (s *WorkerStruct) Paths(p0 context.Context) ([]stores.StoragePath, error) { +func (s *WorkerStruct) Paths(p0 context.Context) ([]storiface.StoragePath, error) { if s.Internal.Paths == nil { - return *new([]stores.StoragePath), ErrNotSupported + return *new([]storiface.StoragePath), ErrNotSupported } return s.Internal.Paths(p0) } -func (s *WorkerStub) Paths(p0 context.Context) ([]stores.StoragePath, error) { - return *new([]stores.StoragePath), ErrNotSupported +func (s *WorkerStub) Paths(p0 context.Context) ([]storiface.StoragePath, error) { + return *new([]storiface.StoragePath), ErrNotSupported } func (s *WorkerStruct) ProcessSession(p0 context.Context) (uuid.UUID, error) { diff --git a/cmd/lotus-miner/init.go b/cmd/lotus-miner/init.go index ae742c663..0d1958b10 100644 --- a/cmd/lotus-miner/init.go +++ b/cmd/lotus-miner/init.go @@ -34,6 +34,7 @@ import ( sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/extern/sector-storage/stores" + "github.com/filecoin-project/lotus/extern/sector-storage/storiface" market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" @@ -231,7 +232,7 @@ var initCmd = &cli.Command{ if !cctx.Bool("no-local-storage") { b, err := json.MarshalIndent(&stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: 10, CanSeal: true, CanStore: true, diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index ee15785fe..77e0e747a 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -17,7 +17,7 @@ import ( "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" - "github.com/filecoin-project/lotus/extern/sector-storage/stores" + "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/specs-storage/storage" ) @@ -420,7 +420,7 @@ var provingCheckProvableCmd = &cli.Command{ if err != nil { return err } - decls := sl[stores.ID(cctx.String("storage-id"))] + decls := sl[storiface.ID(cctx.String("storage-id"))] filter = map[abi.SectorID]struct{}{} for _, decl := range decls { diff --git a/cmd/lotus-miner/storage.go b/cmd/lotus-miner/storage.go index 6f7a627f6..61dbf86fb 100644 --- a/cmd/lotus-miner/storage.go +++ b/cmd/lotus-miner/storage.go @@ -146,7 +146,7 @@ over time } cfg := &stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: cctx.Uint64("weight"), CanSeal: cctx.Bool("seal"), CanStore: cctx.Bool("store"), @@ -209,8 +209,8 @@ var storageListCmd = &cli.Command{ } type fsInfo struct { - stores.ID - sectors []stores.Decl + storiface.ID + sectors []storiface.Decl stat fsutil.FsStat } @@ -364,8 +364,8 @@ var storageListCmd = &cli.Command{ } type storedSector struct { - id stores.ID - store stores.SectorStorageInfo + id storiface.ID + store storiface.SectorStorageInfo unsealed, sealed, cache bool } @@ -421,7 +421,7 @@ var storageFindCmd = &cli.Command{ return xerrors.Errorf("finding cache: %w", err) } - byId := map[stores.ID]*storedSector{} + byId := map[storiface.ID]*storedSector{} for _, info := range u { sts, ok := byId[info.ID] if !ok { @@ -555,7 +555,7 @@ var storageListSectorsCmd = &cli.Command{ type entry struct { id abi.SectorNumber - storage stores.ID + storage storiface.ID ft storiface.SectorFileType urls string diff --git a/cmd/lotus-seal-worker/main.go b/cmd/lotus-seal-worker/main.go index da2a54363..11718ea7a 100644 --- a/cmd/lotus-seal-worker/main.go +++ b/cmd/lotus-seal-worker/main.go @@ -33,6 +33,7 @@ import ( sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" "github.com/filecoin-project/lotus/extern/sector-storage/stores" + "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/lotus/lib/lotuslog" "github.com/filecoin-project/lotus/metrics" "github.com/filecoin-project/lotus/node/modules" @@ -338,7 +339,7 @@ var runCmd = &cli.Command{ if !cctx.Bool("no-local-storage") { b, err := json.MarshalIndent(&stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: 10, CanSeal: true, CanStore: false, diff --git a/cmd/lotus-seal-worker/storage.go b/cmd/lotus-seal-worker/storage.go index 721523fd0..0855ddf6a 100644 --- a/cmd/lotus-seal-worker/storage.go +++ b/cmd/lotus-seal-worker/storage.go @@ -14,6 +14,7 @@ import ( lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/extern/sector-storage/stores" + "github.com/filecoin-project/lotus/extern/sector-storage/storiface" ) const metaFile = "sectorstore.json" @@ -101,7 +102,7 @@ var storageAttachCmd = &cli.Command{ } cfg := &stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: cctx.Uint64("weight"), CanSeal: cctx.Bool("seal"), CanStore: cctx.Bool("store"), diff --git a/cmd/lotus-seed/seed/seed.go b/cmd/lotus-seed/seed/seed.go index 48183690d..3fbe66556 100644 --- a/cmd/lotus-seed/seed/seed.go +++ b/cmd/lotus-seed/seed/seed.go @@ -129,7 +129,7 @@ func PreSeal(maddr address.Address, spt abi.RegisteredSealProof, offset abi.Sect { b, err := json.MarshalIndent(&stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: 0, // read-only CanSeal: false, CanStore: false, diff --git a/extern/sector-storage/manager.go b/extern/sector-storage/manager.go index 9624c4d20..d4a78e1c2 100644 --- a/extern/sector-storage/manager.go +++ b/extern/sector-storage/manager.go @@ -35,7 +35,7 @@ type Worker interface { TaskTypes(context.Context) (map[sealtasks.TaskType]struct{}, error) // Returns paths accessible to the worker - Paths(context.Context) ([]stores.StoragePath, error) + Paths(context.Context) ([]storiface.StoragePath, error) Info(context.Context) (storiface.WorkerInfo, error) @@ -924,13 +924,13 @@ func (m *Manager) ReturnFetch(ctx context.Context, callID storiface.CallID, err return m.returnResult(ctx, callID, nil, err) } -func (m *Manager) StorageLocal(ctx context.Context) (map[stores.ID]string, error) { +func (m *Manager) StorageLocal(ctx context.Context) (map[storiface.ID]string, error) { l, err := m.localStore.Local(ctx) if err != nil { return nil, err } - out := map[stores.ID]string{} + out := map[storiface.ID]string{} for _, st := range l { out[st.ID] = st.LocalPath } @@ -938,7 +938,7 @@ func (m *Manager) StorageLocal(ctx context.Context) (map[stores.ID]string, error return out, nil } -func (m *Manager) FsStat(ctx context.Context, id stores.ID) (fsutil.FsStat, error) { +func (m *Manager) FsStat(ctx context.Context, id storiface.ID) (fsutil.FsStat, error) { return m.storage.FsStat(ctx, id) } diff --git a/extern/sector-storage/manager_test.go b/extern/sector-storage/manager_test.go index 9c63d9498..34521be2a 100644 --- a/extern/sector-storage/manager_test.go +++ b/extern/sector-storage/manager_test.go @@ -49,7 +49,7 @@ func newTestStorage(t *testing.T) *testStorage { { b, err := json.MarshalIndent(&stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: 1, CanSeal: true, CanStore: true, diff --git a/extern/sector-storage/sched_test.go b/extern/sector-storage/sched_test.go index 03d2acdce..d45b9cb13 100644 --- a/extern/sector-storage/sched_test.go +++ b/extern/sector-storage/sched_test.go @@ -58,7 +58,7 @@ var constrainedWorkerResources = storiface.WorkerResources{ type schedTestWorker struct { name string taskTypes map[sealtasks.TaskType]struct{} - paths []stores.StoragePath + paths []storiface.StoragePath closed bool session uuid.UUID @@ -147,7 +147,7 @@ func (s *schedTestWorker) TaskTypes(ctx context.Context) (map[sealtasks.TaskType return s.taskTypes, nil } -func (s *schedTestWorker) Paths(ctx context.Context) ([]stores.StoragePath, error) { +func (s *schedTestWorker) Paths(ctx context.Context) ([]storiface.StoragePath, error) { return s.paths, nil } @@ -178,7 +178,7 @@ func addTestWorker(t *testing.T, sched *scheduler, index *stores.Index, name str w := &schedTestWorker{ name: name, taskTypes: taskTypes, - paths: []stores.StoragePath{{ID: "bb-8", Weight: 2, LocalPath: "food", CanSeal: true, CanStore: true}}, + paths: []storiface.StoragePath{{ID: "bb-8", Weight: 2, LocalPath: "food", CanSeal: true, CanStore: true}}, session: uuid.New(), @@ -187,7 +187,7 @@ func addTestWorker(t *testing.T, sched *scheduler, index *stores.Index, name str } for _, path := range w.paths { - err := index.StorageAttach(context.TODO(), stores.StorageInfo{ + err := index.StorageAttach(context.TODO(), storiface.StorageInfo{ ID: path.ID, URLs: nil, Weight: path.Weight, diff --git a/extern/sector-storage/selector_alloc.go b/extern/sector-storage/selector_alloc.go index 14724fbe8..3212161af 100644 --- a/extern/sector-storage/selector_alloc.go +++ b/extern/sector-storage/selector_alloc.go @@ -40,7 +40,7 @@ func (s *allocSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi return false, xerrors.Errorf("getting worker paths: %w", err) } - have := map[stores.ID]struct{}{} + have := map[storiface.ID]struct{}{} for _, path := range paths { have[path.ID] = struct{}{} } diff --git a/extern/sector-storage/selector_existing.go b/extern/sector-storage/selector_existing.go index 0e3a41aeb..4c0ba379c 100644 --- a/extern/sector-storage/selector_existing.go +++ b/extern/sector-storage/selector_existing.go @@ -42,7 +42,7 @@ func (s *existingSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt return false, xerrors.Errorf("getting worker paths: %w", err) } - have := map[stores.ID]struct{}{} + have := map[storiface.ID]struct{}{} for _, path := range paths { have[path.ID] = struct{}{} } diff --git a/extern/sector-storage/selector_task.go b/extern/sector-storage/selector_task.go index e4d92757e..15c71b648 100644 --- a/extern/sector-storage/selector_task.go +++ b/extern/sector-storage/selector_task.go @@ -8,11 +8,11 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" - "github.com/filecoin-project/lotus/extern/sector-storage/stores" + "github.com/filecoin-project/lotus/extern/sector-storage/storiface" ) type taskSelector struct { - best []stores.StorageInfo //nolint: unused, structcheck + best []storiface.StorageInfo //nolint: unused, structcheck } func newTaskSelector() *taskSelector { diff --git a/extern/sector-storage/stores/http_handler.go b/extern/sector-storage/stores/http_handler.go index e3caceb5d..126888295 100644 --- a/extern/sector-storage/stores/http_handler.go +++ b/extern/sector-storage/stores/http_handler.go @@ -62,7 +62,7 @@ func (handler *FetchHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (handler *FetchHandler) remoteStatFs(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - id := ID(vars["id"]) + id := storiface.ID(vars["id"]) st, err := handler.Local.FsStat(r.Context(), id) switch err { @@ -173,7 +173,7 @@ func (handler *FetchHandler) remoteDeleteSector(w http.ResponseWriter, r *http.R return } - if err := handler.Local.Remove(r.Context(), id, ft, false, []ID{ID(r.FormValue("keep"))}); err != nil { + if err := handler.Local.Remove(r.Context(), id, ft, false, []storiface.ID{storiface.ID(r.FormValue("keep"))}); err != nil { log.Errorf("%+v", err) w.WriteHeader(500) return diff --git a/extern/sector-storage/stores/index.go b/extern/sector-storage/stores/index.go index 16171237c..60042428e 100644 --- a/extern/sector-storage/stores/index.go +++ b/extern/sector-storage/stores/index.go @@ -25,75 +25,34 @@ import ( var HeartbeatInterval = 10 * time.Second var SkippedHeartbeatThresh = HeartbeatInterval * 5 -// ID identifies sector storage by UUID. One sector storage should map to one -// filesystem, local or networked / shared by multiple machines -type ID string - -type Group = string - -type StorageInfo struct { - ID ID - URLs []string // TODO: Support non-http transports - Weight uint64 - MaxStorage uint64 - - CanSeal bool - CanStore bool - - Groups []Group - AllowTo []Group -} - -type HealthReport struct { - Stat fsutil.FsStat - Err string -} - -type SectorStorageInfo struct { - ID ID - URLs []string // TODO: Support non-http transports - BaseURLs []string - Weight uint64 - - CanSeal bool - CanStore bool - - Primary bool -} - //go:generate go run github.com/golang/mock/mockgen -destination=mocks/index.go -package=mocks . SectorIndex type SectorIndex interface { // part of storage-miner api - StorageAttach(context.Context, StorageInfo, fsutil.FsStat) error - StorageInfo(context.Context, ID) (StorageInfo, error) - StorageReportHealth(context.Context, ID, HealthReport) error + StorageAttach(context.Context, storiface.StorageInfo, fsutil.FsStat) error + StorageInfo(context.Context, storiface.ID) (storiface.StorageInfo, error) + StorageReportHealth(context.Context, storiface.ID, storiface.HealthReport) error - StorageDeclareSector(ctx context.Context, storageID ID, s abi.SectorID, ft storiface.SectorFileType, primary bool) error - StorageDropSector(ctx context.Context, storageID ID, s abi.SectorID, ft storiface.SectorFileType) error - StorageFindSector(ctx context.Context, sector abi.SectorID, ft storiface.SectorFileType, ssize abi.SectorSize, allowFetch bool) ([]SectorStorageInfo, error) + StorageDeclareSector(ctx context.Context, storageID storiface.ID, s abi.SectorID, ft storiface.SectorFileType, primary bool) error + StorageDropSector(ctx context.Context, storageID storiface.ID, s abi.SectorID, ft storiface.SectorFileType) error + StorageFindSector(ctx context.Context, sector abi.SectorID, ft storiface.SectorFileType, ssize abi.SectorSize, allowFetch bool) ([]storiface.SectorStorageInfo, error) - StorageBestAlloc(ctx context.Context, allocate storiface.SectorFileType, ssize abi.SectorSize, pathType storiface.PathType) ([]StorageInfo, error) + StorageBestAlloc(ctx context.Context, allocate storiface.SectorFileType, ssize abi.SectorSize, pathType storiface.PathType) ([]storiface.StorageInfo, error) // atomically acquire locks on all sector file types. close ctx to unlock StorageLock(ctx context.Context, sector abi.SectorID, read storiface.SectorFileType, write storiface.SectorFileType) error StorageTryLock(ctx context.Context, sector abi.SectorID, read storiface.SectorFileType, write storiface.SectorFileType) (bool, error) StorageGetLocks(ctx context.Context) (storiface.SectorLocks, error) - StorageList(ctx context.Context) (map[ID][]Decl, error) -} - -type Decl struct { - abi.SectorID - storiface.SectorFileType + StorageList(ctx context.Context) (map[storiface.ID][]storiface.Decl, error) } type declMeta struct { - storage ID + storage storiface.ID primary bool } type storageEntry struct { - info *StorageInfo + info *storiface.StorageInfo fsi fsutil.FsStat lastHeartbeat time.Time @@ -104,8 +63,8 @@ type Index struct { *indexLocks lk sync.RWMutex - sectors map[Decl][]*declMeta - stores map[ID]*storageEntry + sectors map[storiface.Decl][]*declMeta + stores map[storiface.ID]*storageEntry } func NewIndex() *Index { @@ -113,16 +72,16 @@ func NewIndex() *Index { indexLocks: &indexLocks{ locks: map[abi.SectorID]*sectorLock{}, }, - sectors: map[Decl][]*declMeta{}, - stores: map[ID]*storageEntry{}, + sectors: map[storiface.Decl][]*declMeta{}, + stores: map[storiface.ID]*storageEntry{}, } } -func (i *Index) StorageList(ctx context.Context) (map[ID][]Decl, error) { +func (i *Index) StorageList(ctx context.Context) (map[storiface.ID][]storiface.Decl, error) { i.lk.RLock() defer i.lk.RUnlock() - byID := map[ID]map[abi.SectorID]storiface.SectorFileType{} + byID := map[storiface.ID]map[abi.SectorID]storiface.SectorFileType{} for id := range i.stores { byID[id] = map[abi.SectorID]storiface.SectorFileType{} @@ -133,11 +92,11 @@ func (i *Index) StorageList(ctx context.Context) (map[ID][]Decl, error) { } } - out := map[ID][]Decl{} + out := map[storiface.ID][]storiface.Decl{} for id, m := range byID { - out[id] = []Decl{} + out[id] = []storiface.Decl{} for sectorID, fileType := range m { - out[id] = append(out[id], Decl{ + out[id] = append(out[id], storiface.Decl{ SectorID: sectorID, SectorFileType: fileType, }) @@ -147,7 +106,7 @@ func (i *Index) StorageList(ctx context.Context) (map[ID][]Decl, error) { return out, nil } -func (i *Index) StorageAttach(ctx context.Context, si StorageInfo, st fsutil.FsStat) error { +func (i *Index) StorageAttach(ctx context.Context, si storiface.StorageInfo, st fsutil.FsStat) error { i.lk.Lock() defer i.lk.Unlock() @@ -189,7 +148,7 @@ func (i *Index) StorageAttach(ctx context.Context, si StorageInfo, st fsutil.FsS return nil } -func (i *Index) StorageReportHealth(ctx context.Context, id ID, report HealthReport) error { +func (i *Index) StorageReportHealth(ctx context.Context, id storiface.ID, report storiface.HealthReport) error { i.lk.Lock() defer i.lk.Unlock() @@ -228,7 +187,7 @@ func (i *Index) StorageReportHealth(ctx context.Context, id ID, report HealthRep return nil } -func (i *Index) StorageDeclareSector(ctx context.Context, storageID ID, s abi.SectorID, ft storiface.SectorFileType, primary bool) error { +func (i *Index) StorageDeclareSector(ctx context.Context, storageID storiface.ID, s abi.SectorID, ft storiface.SectorFileType, primary bool) error { i.lk.Lock() defer i.lk.Unlock() @@ -238,7 +197,7 @@ loop: continue } - d := Decl{s, fileType} + d := storiface.Decl{s, fileType} for _, sid := range i.sectors[d] { if sid.storage == storageID { @@ -260,7 +219,7 @@ loop: return nil } -func (i *Index) StorageDropSector(ctx context.Context, storageID ID, s abi.SectorID, ft storiface.SectorFileType) error { +func (i *Index) StorageDropSector(ctx context.Context, storageID storiface.ID, s abi.SectorID, ft storiface.SectorFileType) error { i.lk.Lock() defer i.lk.Unlock() @@ -269,7 +228,7 @@ func (i *Index) StorageDropSector(ctx context.Context, storageID ID, s abi.Secto continue } - d := Decl{s, fileType} + d := storiface.Decl{s, fileType} if len(i.sectors[d]) == 0 { continue @@ -294,27 +253,27 @@ func (i *Index) StorageDropSector(ctx context.Context, storageID ID, s abi.Secto return nil } -func (i *Index) StorageFindSector(ctx context.Context, s abi.SectorID, ft storiface.SectorFileType, ssize abi.SectorSize, allowFetch bool) ([]SectorStorageInfo, error) { +func (i *Index) StorageFindSector(ctx context.Context, s abi.SectorID, ft storiface.SectorFileType, ssize abi.SectorSize, allowFetch bool) ([]storiface.SectorStorageInfo, error) { i.lk.RLock() defer i.lk.RUnlock() - storageIDs := map[ID]uint64{} - isprimary := map[ID]bool{} + storageIDs := map[storiface.ID]uint64{} + isprimary := map[storiface.ID]bool{} - allowTo := map[Group]struct{}{} + allowTo := map[storiface.Group]struct{}{} for _, pathType := range storiface.PathTypes { if ft&pathType == 0 { continue } - for _, id := range i.sectors[Decl{s, pathType}] { + for _, id := range i.sectors[storiface.Decl{s, pathType}] { storageIDs[id.storage]++ isprimary[id.storage] = isprimary[id.storage] || id.primary } } - out := make([]SectorStorageInfo, 0, len(storageIDs)) + out := make([]storiface.SectorStorageInfo, 0, len(storageIDs)) for id, n := range storageIDs { st, ok := i.stores[id] @@ -343,7 +302,7 @@ func (i *Index) StorageFindSector(ctx context.Context, s abi.SectorID, ft storif allowTo = nil // allow to any } - out = append(out, SectorStorageInfo{ + out = append(out, storiface.SectorStorageInfo{ ID: id, URLs: urls, BaseURLs: burls, @@ -414,7 +373,7 @@ func (i *Index) StorageFindSector(ctx context.Context, s abi.SectorID, ft storif burls[k] = u } - out = append(out, SectorStorageInfo{ + out = append(out, storiface.SectorStorageInfo{ ID: id, URLs: urls, BaseURLs: burls, @@ -431,19 +390,19 @@ func (i *Index) StorageFindSector(ctx context.Context, s abi.SectorID, ft storif return out, nil } -func (i *Index) StorageInfo(ctx context.Context, id ID) (StorageInfo, error) { +func (i *Index) StorageInfo(ctx context.Context, id storiface.ID) (storiface.StorageInfo, error) { i.lk.RLock() defer i.lk.RUnlock() si, found := i.stores[id] if !found { - return StorageInfo{}, xerrors.Errorf("sector store not found") + return storiface.StorageInfo{}, xerrors.Errorf("sector store not found") } return *si.info, nil } -func (i *Index) StorageBestAlloc(ctx context.Context, allocate storiface.SectorFileType, ssize abi.SectorSize, pathType storiface.PathType) ([]StorageInfo, error) { +func (i *Index) StorageBestAlloc(ctx context.Context, allocate storiface.SectorFileType, ssize abi.SectorSize, pathType storiface.PathType) ([]storiface.StorageInfo, error) { i.lk.RLock() defer i.lk.RUnlock() @@ -500,7 +459,7 @@ func (i *Index) StorageBestAlloc(ctx context.Context, allocate storiface.SectorF return iw.GreaterThan(jw) }) - out := make([]StorageInfo, len(candidates)) + out := make([]storiface.StorageInfo, len(candidates)) for i, candidate := range candidates { out[i] = *candidate.info } @@ -508,18 +467,18 @@ func (i *Index) StorageBestAlloc(ctx context.Context, allocate storiface.SectorF return out, nil } -func (i *Index) FindSector(id abi.SectorID, typ storiface.SectorFileType) ([]ID, error) { +func (i *Index) FindSector(id abi.SectorID, typ storiface.SectorFileType) ([]storiface.ID, error) { i.lk.RLock() defer i.lk.RUnlock() - f, ok := i.sectors[Decl{ + f, ok := i.sectors[storiface.Decl{ SectorID: id, SectorFileType: typ, }] if !ok { return nil, nil } - out := make([]ID, 0, len(f)) + out := make([]storiface.ID, 0, len(f)) for _, meta := range f { out = append(out, meta.storage) } diff --git a/extern/sector-storage/stores/index_test.go b/extern/sector-storage/stores/index_test.go index bb4239035..64a9271c4 100644 --- a/extern/sector-storage/stores/index_test.go +++ b/extern/sector-storage/stores/index_test.go @@ -18,9 +18,9 @@ func init() { logging.SetLogLevel("stores", "DEBUG") } -func newTestStorage() StorageInfo { - return StorageInfo{ - ID: ID(uuid.New().String()), +func newTestStorage() storiface.StorageInfo { + return storiface.StorageInfo{ + ID: storiface.ID(uuid.New().String()), CanSeal: true, CanStore: true, Groups: nil, @@ -81,7 +81,7 @@ func TestFindNoAllow(t *testing.T) { i := NewIndex() stor1 := newTestStorage() - stor1.AllowTo = []Group{"grp1"} + stor1.AllowTo = []storiface.Group{"grp1"} stor2 := newTestStorage() require.NoError(t, i.StorageAttach(ctx, stor1, bigFsStat)) @@ -114,13 +114,13 @@ func TestFindAllow(t *testing.T) { i := NewIndex() stor1 := newTestStorage() - stor1.AllowTo = []Group{"grp1"} + stor1.AllowTo = []storiface.Group{"grp1"} stor2 := newTestStorage() - stor2.Groups = []Group{"grp1"} + stor2.Groups = []storiface.Group{"grp1"} stor3 := newTestStorage() - stor3.Groups = []Group{"grp2"} + stor3.Groups = []storiface.Group{"grp2"} require.NoError(t, i.StorageAttach(ctx, stor1, bigFsStat)) require.NoError(t, i.StorageAttach(ctx, stor2, bigFsStat)) diff --git a/extern/sector-storage/stores/interface.go b/extern/sector-storage/stores/interface.go index 85e3abfa8..980beee47 100644 --- a/extern/sector-storage/stores/interface.go +++ b/extern/sector-storage/stores/interface.go @@ -35,7 +35,7 @@ type PartialFileHandler interface { type Store interface { AcquireSector(ctx context.Context, s storage.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, sealing storiface.PathType, op storiface.AcquireMode) (paths storiface.SectorPaths, stores storiface.SectorPaths, err error) - Remove(ctx context.Context, s abi.SectorID, types storiface.SectorFileType, force bool, keepIn []ID) error + Remove(ctx context.Context, s abi.SectorID, types storiface.SectorFileType, force bool, keepIn []storiface.ID) error // like remove, but doesn't remove the primary sector copy, nor the last // non-primary copy if there no primary copies @@ -44,7 +44,7 @@ type Store interface { // move sectors into storage MoveStorage(ctx context.Context, s storage.SectorRef, types storiface.SectorFileType) error - FsStat(ctx context.Context, id ID) (fsutil.FsStat, error) + FsStat(ctx context.Context, id storiface.ID) (fsutil.FsStat, error) Reserve(ctx context.Context, sid storage.SectorRef, ft storiface.SectorFileType, storageIDs storiface.SectorPaths, overheadTab map[storiface.SectorFileType]int) (func(), error) diff --git a/extern/sector-storage/stores/local.go b/extern/sector-storage/stores/local.go index eed7cf09e..5bac8ca50 100644 --- a/extern/sector-storage/stores/local.go +++ b/extern/sector-storage/stores/local.go @@ -22,19 +22,9 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/storiface" ) -type StoragePath struct { - ID ID - Weight uint64 - - LocalPath string - - CanSeal bool - CanStore bool -} - // LocalStorageMeta [path]/sectorstore.json type LocalStorageMeta struct { - ID ID + ID storiface.ID // A high weight means data is more likely to be stored in this path Weight uint64 // 0 = readonly @@ -84,7 +74,7 @@ type Local struct { index SectorIndex urls []string - paths map[ID]*path + paths map[storiface.ID]*path localLk sync.RWMutex } @@ -180,7 +170,7 @@ func NewLocal(ctx context.Context, ls LocalStorage, index SectorIndex, urls []st index: index, urls: urls, - paths: map[ID]*path{}, + paths: map[storiface.ID]*path{}, } return l, l.open(ctx) } @@ -214,7 +204,7 @@ func (st *Local) OpenPath(ctx context.Context, p string) error { return err } - err = st.index.StorageAttach(ctx, StorageInfo{ + err = st.index.StorageAttach(ctx, storiface.StorageInfo{ ID: meta.ID, URLs: st.urls, Weight: meta.Weight, @@ -280,7 +270,7 @@ func (st *Local) Redeclare(ctx context.Context) error { continue } - err = st.index.StorageAttach(ctx, StorageInfo{ + err = st.index.StorageAttach(ctx, storiface.StorageInfo{ ID: id, URLs: st.urls, Weight: meta.Weight, @@ -302,7 +292,7 @@ func (st *Local) Redeclare(ctx context.Context) error { return nil } -func (st *Local) declareSectors(ctx context.Context, p string, id ID, primary bool) error { +func (st *Local) declareSectors(ctx context.Context, p string, id storiface.ID, primary bool) error { for _, t := range storiface.PathTypes { ents, err := ioutil.ReadDir(filepath.Join(p, t.String())) if err != nil { @@ -353,10 +343,10 @@ func (st *Local) reportHealth(ctx context.Context) { func (st *Local) reportStorage(ctx context.Context) { st.localLk.RLock() - toReport := map[ID]HealthReport{} + toReport := map[storiface.ID]storiface.HealthReport{} for id, p := range st.paths { stat, err := p.stat(st.localStorage) - r := HealthReport{Stat: stat} + r := storiface.HealthReport{Stat: stat} if err != nil { r.Err = err.Error() } @@ -393,7 +383,7 @@ func (st *Local) Reserve(ctx context.Context, sid storage.SectorRef, ft storifac continue } - id := ID(storiface.PathByType(storageIDs, fileType)) + id := storiface.ID(storiface.PathByType(storageIDs, fileType)) p, ok := st.paths[id] if !ok { @@ -491,7 +481,7 @@ func (st *Local) AcquireSector(ctx context.Context, sid storage.SectorRef, exist } var best string - var bestID ID + var bestID storiface.ID for _, si := range sis { p, ok := st.paths[si.ID] @@ -530,11 +520,11 @@ func (st *Local) AcquireSector(ctx context.Context, sid storage.SectorRef, exist return out, storageIDs, nil } -func (st *Local) Local(ctx context.Context) ([]StoragePath, error) { +func (st *Local) Local(ctx context.Context) ([]storiface.StoragePath, error) { st.localLk.RLock() defer st.localLk.RUnlock() - var out []StoragePath + var out []storiface.StoragePath for id, p := range st.paths { if p.local == "" { continue @@ -545,7 +535,7 @@ func (st *Local) Local(ctx context.Context) ([]StoragePath, error) { return nil, xerrors.Errorf("get storage info for %s: %w", id, err) } - out = append(out, StoragePath{ + out = append(out, storiface.StoragePath{ ID: id, Weight: si.Weight, LocalPath: p.local, @@ -557,7 +547,7 @@ func (st *Local) Local(ctx context.Context) ([]StoragePath, error) { return out, nil } -func (st *Local) Remove(ctx context.Context, sid abi.SectorID, typ storiface.SectorFileType, force bool, keepIn []ID) error { +func (st *Local) Remove(ctx context.Context, sid abi.SectorID, typ storiface.SectorFileType, force bool, keepIn []storiface.ID) error { if bits.OnesCount(uint(typ)) != 1 { return xerrors.New("delete expects one file type") } @@ -623,7 +613,7 @@ func (st *Local) RemoveCopies(ctx context.Context, sid abi.SectorID, typ storifa return nil } -func (st *Local) removeSector(ctx context.Context, sid abi.SectorID, typ storiface.SectorFileType, storage ID) error { +func (st *Local) removeSector(ctx context.Context, sid abi.SectorID, typ storiface.SectorFileType, storage storiface.ID) error { p, ok := st.paths[storage] if !ok { return nil @@ -665,12 +655,12 @@ func (st *Local) MoveStorage(ctx context.Context, s storage.SectorRef, types sto continue } - sst, err := st.index.StorageInfo(ctx, ID(storiface.PathByType(srcIds, fileType))) + sst, err := st.index.StorageInfo(ctx, storiface.ID(storiface.PathByType(srcIds, fileType))) if err != nil { return xerrors.Errorf("failed to get source storage info: %w", err) } - dst, err := st.index.StorageInfo(ctx, ID(storiface.PathByType(destIds, fileType))) + dst, err := st.index.StorageInfo(ctx, storiface.ID(storiface.PathByType(destIds, fileType))) if err != nil { return xerrors.Errorf("failed to get source storage info: %w", err) } @@ -687,7 +677,7 @@ func (st *Local) MoveStorage(ctx context.Context, s storage.SectorRef, types sto log.Debugf("moving %v(%d) to storage: %s(se:%t; st:%t) -> %s(se:%t; st:%t)", s, fileType, sst.ID, sst.CanSeal, sst.CanStore, dst.ID, dst.CanSeal, dst.CanStore) - if err := st.index.StorageDropSector(ctx, ID(storiface.PathByType(srcIds, fileType)), s.ID, fileType); err != nil { + if err := st.index.StorageDropSector(ctx, storiface.ID(storiface.PathByType(srcIds, fileType)), s.ID, fileType); err != nil { return xerrors.Errorf("dropping source sector from index: %w", err) } @@ -696,8 +686,8 @@ func (st *Local) MoveStorage(ctx context.Context, s storage.SectorRef, types sto return xerrors.Errorf("moving sector %v(%d): %w", s, fileType, err) } - if err := st.index.StorageDeclareSector(ctx, ID(storiface.PathByType(destIds, fileType)), s.ID, fileType, true); err != nil { - return xerrors.Errorf("declare sector %d(t:%d) -> %s: %w", s, fileType, ID(storiface.PathByType(destIds, fileType)), err) + if err := st.index.StorageDeclareSector(ctx, storiface.ID(storiface.PathByType(destIds, fileType)), s.ID, fileType, true); err != nil { + return xerrors.Errorf("declare sector %d(t:%d) -> %s: %w", s, fileType, storiface.ID(storiface.PathByType(destIds, fileType)), err) } } @@ -708,7 +698,7 @@ func (st *Local) MoveStorage(ctx context.Context, s storage.SectorRef, types sto var errPathNotFound = xerrors.Errorf("fsstat: path not found") -func (st *Local) FsStat(ctx context.Context, id ID) (fsutil.FsStat, error) { +func (st *Local) FsStat(ctx context.Context, id storiface.ID) (fsutil.FsStat, error) { st.localLk.RLock() defer st.localLk.RUnlock() diff --git a/extern/sector-storage/stores/local_test.go b/extern/sector-storage/stores/local_test.go index ac5f6f341..5068a0796 100644 --- a/extern/sector-storage/stores/local_test.go +++ b/extern/sector-storage/stores/local_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" + "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/google/uuid" "github.com/stretchr/testify/require" @@ -51,7 +52,7 @@ func (t *TestingLocalStorage) init(subpath string) error { metaFile := filepath.Join(path, MetaFile) meta := &LocalStorageMeta{ - ID: ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: 1, CanSeal: true, CanStore: true, diff --git a/extern/sector-storage/stores/mocks/index.go b/extern/sector-storage/stores/mocks/index.go index 268148536..26b98766e 100644 --- a/extern/sector-storage/stores/mocks/index.go +++ b/extern/sector-storage/stores/mocks/index.go @@ -10,7 +10,6 @@ import ( abi "github.com/filecoin-project/go-state-types/abi" fsutil "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" - stores "github.com/filecoin-project/lotus/extern/sector-storage/stores" storiface "github.com/filecoin-project/lotus/extern/sector-storage/storiface" gomock "github.com/golang/mock/gomock" ) @@ -39,7 +38,7 @@ func (m *MockSectorIndex) EXPECT() *MockSectorIndexMockRecorder { } // StorageAttach mocks base method. -func (m *MockSectorIndex) StorageAttach(arg0 context.Context, arg1 stores.StorageInfo, arg2 fsutil.FsStat) error { +func (m *MockSectorIndex) StorageAttach(arg0 context.Context, arg1 storiface.StorageInfo, arg2 fsutil.FsStat) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StorageAttach", arg0, arg1, arg2) ret0, _ := ret[0].(error) @@ -53,10 +52,10 @@ func (mr *MockSectorIndexMockRecorder) StorageAttach(arg0, arg1, arg2 interface{ } // StorageBestAlloc mocks base method. -func (m *MockSectorIndex) StorageBestAlloc(arg0 context.Context, arg1 storiface.SectorFileType, arg2 abi.SectorSize, arg3 storiface.PathType) ([]stores.StorageInfo, error) { +func (m *MockSectorIndex) StorageBestAlloc(arg0 context.Context, arg1 storiface.SectorFileType, arg2 abi.SectorSize, arg3 storiface.PathType) ([]storiface.StorageInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StorageBestAlloc", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].([]stores.StorageInfo) + ret0, _ := ret[0].([]storiface.StorageInfo) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -68,7 +67,7 @@ func (mr *MockSectorIndexMockRecorder) StorageBestAlloc(arg0, arg1, arg2, arg3 i } // StorageDeclareSector mocks base method. -func (m *MockSectorIndex) StorageDeclareSector(arg0 context.Context, arg1 stores.ID, arg2 abi.SectorID, arg3 storiface.SectorFileType, arg4 bool) error { +func (m *MockSectorIndex) StorageDeclareSector(arg0 context.Context, arg1 storiface.ID, arg2 abi.SectorID, arg3 storiface.SectorFileType, arg4 bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StorageDeclareSector", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(error) @@ -82,7 +81,7 @@ func (mr *MockSectorIndexMockRecorder) StorageDeclareSector(arg0, arg1, arg2, ar } // StorageDropSector mocks base method. -func (m *MockSectorIndex) StorageDropSector(arg0 context.Context, arg1 stores.ID, arg2 abi.SectorID, arg3 storiface.SectorFileType) error { +func (m *MockSectorIndex) StorageDropSector(arg0 context.Context, arg1 storiface.ID, arg2 abi.SectorID, arg3 storiface.SectorFileType) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StorageDropSector", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(error) @@ -96,10 +95,10 @@ func (mr *MockSectorIndexMockRecorder) StorageDropSector(arg0, arg1, arg2, arg3 } // StorageFindSector mocks base method. -func (m *MockSectorIndex) StorageFindSector(arg0 context.Context, arg1 abi.SectorID, arg2 storiface.SectorFileType, arg3 abi.SectorSize, arg4 bool) ([]stores.SectorStorageInfo, error) { +func (m *MockSectorIndex) StorageFindSector(arg0 context.Context, arg1 abi.SectorID, arg2 storiface.SectorFileType, arg3 abi.SectorSize, arg4 bool) ([]storiface.SectorStorageInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StorageFindSector", arg0, arg1, arg2, arg3, arg4) - ret0, _ := ret[0].([]stores.SectorStorageInfo) + ret0, _ := ret[0].([]storiface.SectorStorageInfo) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -126,10 +125,10 @@ func (mr *MockSectorIndexMockRecorder) StorageGetLocks(arg0 interface{}) *gomock } // StorageInfo mocks base method. -func (m *MockSectorIndex) StorageInfo(arg0 context.Context, arg1 stores.ID) (stores.StorageInfo, error) { +func (m *MockSectorIndex) StorageInfo(arg0 context.Context, arg1 storiface.ID) (storiface.StorageInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StorageInfo", arg0, arg1) - ret0, _ := ret[0].(stores.StorageInfo) + ret0, _ := ret[0].(storiface.StorageInfo) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -141,10 +140,10 @@ func (mr *MockSectorIndexMockRecorder) StorageInfo(arg0, arg1 interface{}) *gomo } // StorageList mocks base method. -func (m *MockSectorIndex) StorageList(arg0 context.Context) (map[stores.ID][]stores.Decl, error) { +func (m *MockSectorIndex) StorageList(arg0 context.Context) (map[storiface.ID][]storiface.Decl, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StorageList", arg0) - ret0, _ := ret[0].(map[stores.ID][]stores.Decl) + ret0, _ := ret[0].(map[storiface.ID][]storiface.Decl) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -170,7 +169,7 @@ func (mr *MockSectorIndexMockRecorder) StorageLock(arg0, arg1, arg2, arg3 interf } // StorageReportHealth mocks base method. -func (m *MockSectorIndex) StorageReportHealth(arg0 context.Context, arg1 stores.ID, arg2 stores.HealthReport) error { +func (m *MockSectorIndex) StorageReportHealth(arg0 context.Context, arg1 storiface.ID, arg2 storiface.HealthReport) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StorageReportHealth", arg0, arg1, arg2) ret0, _ := ret[0].(error) diff --git a/extern/sector-storage/stores/mocks/store.go b/extern/sector-storage/stores/mocks/store.go index 0df7513ad..fbb9deefa 100644 --- a/extern/sector-storage/stores/mocks/store.go +++ b/extern/sector-storage/stores/mocks/store.go @@ -10,7 +10,6 @@ import ( abi "github.com/filecoin-project/go-state-types/abi" fsutil "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" - stores "github.com/filecoin-project/lotus/extern/sector-storage/stores" storiface "github.com/filecoin-project/lotus/extern/sector-storage/storiface" storage "github.com/filecoin-project/specs-storage/storage" gomock "github.com/golang/mock/gomock" @@ -56,7 +55,7 @@ func (mr *MockStoreMockRecorder) AcquireSector(arg0, arg1, arg2, arg3, arg4, arg } // FsStat mocks base method. -func (m *MockStore) FsStat(arg0 context.Context, arg1 stores.ID) (fsutil.FsStat, error) { +func (m *MockStore) FsStat(arg0 context.Context, arg1 storiface.ID) (fsutil.FsStat, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "FsStat", arg0, arg1) ret0, _ := ret[0].(fsutil.FsStat) @@ -100,7 +99,7 @@ func (mr *MockStoreMockRecorder) MoveStorage(arg0, arg1, arg2 interface{}) *gomo } // Remove mocks base method. -func (m *MockStore) Remove(arg0 context.Context, arg1 abi.SectorID, arg2 storiface.SectorFileType, arg3 bool, arg4 []stores.ID) error { +func (m *MockStore) Remove(arg0 context.Context, arg1 abi.SectorID, arg2 storiface.SectorFileType, arg3 bool, arg4 []storiface.ID) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Remove", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(error) diff --git a/extern/sector-storage/stores/remote.go b/extern/sector-storage/stores/remote.go index cc2e28f58..3df6bd867 100644 --- a/extern/sector-storage/stores/remote.go +++ b/extern/sector-storage/stores/remote.go @@ -150,13 +150,13 @@ func (r *Remote) AcquireSector(ctx context.Context, s storage.SectorRef, existin storiface.SetPathByType(&paths, fileType, dest) storiface.SetPathByType(&stores, fileType, storageID) - if err := r.index.StorageDeclareSector(ctx, ID(storageID), s.ID, fileType, op == storiface.AcquireMove); err != nil { + if err := r.index.StorageDeclareSector(ctx, storiface.ID(storageID), s.ID, fileType, op == storiface.AcquireMove); err != nil { log.Warnf("declaring sector %v in %s failed: %+v", s, storageID, err) continue } if op == storiface.AcquireMove { - id := ID(storageID) + id := storiface.ID(storageID) if err := r.deleteFromRemote(ctx, url, &id); err != nil { log.Warnf("deleting sector %v from %s (delete %s): %+v", s, storageID, url, err) } @@ -334,7 +334,7 @@ func (r *Remote) MoveStorage(ctx context.Context, s storage.SectorRef, types sto return r.local.MoveStorage(ctx, s, types) } -func (r *Remote) Remove(ctx context.Context, sid abi.SectorID, typ storiface.SectorFileType, force bool, keepIn []ID) error { +func (r *Remote) Remove(ctx context.Context, sid abi.SectorID, typ storiface.SectorFileType, force bool, keepIn []storiface.ID) error { if bits.OnesCount(uint(typ)) != 1 { return xerrors.New("delete expects one file type") } @@ -367,7 +367,7 @@ storeLoop: return nil } -func (r *Remote) deleteFromRemote(ctx context.Context, url string, keepIn *ID) error { +func (r *Remote) deleteFromRemote(ctx context.Context, url string, keepIn *storiface.ID) error { if keepIn != nil { url = url + "?keep=" + string(*keepIn) } @@ -394,7 +394,7 @@ func (r *Remote) deleteFromRemote(ctx context.Context, url string, keepIn *ID) e return nil } -func (r *Remote) FsStat(ctx context.Context, id ID) (fsutil.FsStat, error) { +func (r *Remote) FsStat(ctx context.Context, id storiface.ID) (fsutil.FsStat, error) { st, err := r.local.FsStat(ctx, id) switch err { case nil: diff --git a/extern/sector-storage/stores/remote_test.go b/extern/sector-storage/stores/remote_test.go index 0bc439dee..a0493e917 100644 --- a/extern/sector-storage/stores/remote_test.go +++ b/extern/sector-storage/stores/remote_test.go @@ -30,7 +30,7 @@ import ( const metaFile = "sectorstore.json" -func createTestStorage(t *testing.T, p string, seal bool, att ...*stores.Local) stores.ID { +func createTestStorage(t *testing.T, p string, seal bool, att ...*stores.Local) storiface.ID { if err := os.MkdirAll(p, 0755); err != nil { if !os.IsExist(err) { require.NoError(t, err) @@ -38,7 +38,7 @@ func createTestStorage(t *testing.T, p string, seal bool, att ...*stores.Local) } cfg := &stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: 10, CanSeal: seal, CanStore: !seal, @@ -129,14 +129,14 @@ func TestMoveShared(t *testing.T) { sp, sid, err := rs1.AcquireSector(ctx, s1ref, storiface.FTNone, storiface.FTSealed, storiface.PathSealing, storiface.AcquireMove) require.NoError(t, err) - require.Equal(t, id2, stores.ID(sid.Sealed)) + require.Equal(t, id2, storiface.ID(sid.Sealed)) data := make([]byte, 2032) data[1] = 54 require.NoError(t, ioutil.WriteFile(sp.Sealed, data, 0666)) fmt.Println("write to ", sp.Sealed) - require.NoError(t, index.StorageDeclareSector(ctx, stores.ID(sid.Sealed), s1ref.ID, storiface.FTSealed, true)) + require.NoError(t, index.StorageDeclareSector(ctx, storiface.ID(sid.Sealed), s1ref.ID, storiface.FTSealed, true)) // move to the shared path from the second node (remote move / delete) @@ -145,7 +145,7 @@ func TestMoveShared(t *testing.T) { // check that the file still exists sp, sid, err = rs2.AcquireSector(ctx, s1ref, storiface.FTSealed, storiface.FTNone, storiface.PathStorage, storiface.AcquireMove) require.NoError(t, err) - require.Equal(t, id1, stores.ID(sid.Sealed)) + require.Equal(t, id1, storiface.ID(sid.Sealed)) fmt.Println("read from ", sp.Sealed) read, err := ioutil.ReadFile(sp.Sealed) @@ -298,12 +298,12 @@ func TestReader(t *testing.T) { }, indexFnc: func(in *mocks.MockSectorIndex, url string) { - si := stores.SectorStorageInfo{ + si := storiface.SectorStorageInfo{ URLs: []string{url}, } in.EXPECT().StorageFindSector(gomock.Any(), sectorRef.ID, storiface.FTUnsealed, gomock.Any(), - false).Return([]stores.SectorStorageInfo{si}, nil).Times(1) + false).Return([]storiface.SectorStorageInfo{si}, nil).Times(1) }, needHttpServer: true, @@ -317,12 +317,12 @@ func TestReader(t *testing.T) { }, indexFnc: func(in *mocks.MockSectorIndex, url string) { - si := stores.SectorStorageInfo{ + si := storiface.SectorStorageInfo{ URLs: []string{url}, } in.EXPECT().StorageFindSector(gomock.Any(), sectorRef.ID, storiface.FTUnsealed, gomock.Any(), - false).Return([]stores.SectorStorageInfo{si}, nil).Times(1) + false).Return([]storiface.SectorStorageInfo{si}, nil).Times(1) }, needHttpServer: true, @@ -335,12 +335,12 @@ func TestReader(t *testing.T) { }, indexFnc: func(in *mocks.MockSectorIndex, url string) { - si := stores.SectorStorageInfo{ + si := storiface.SectorStorageInfo{ URLs: []string{url}, } in.EXPECT().StorageFindSector(gomock.Any(), sectorRef.ID, storiface.FTUnsealed, gomock.Any(), - false).Return([]stores.SectorStorageInfo{si}, nil).Times(1) + false).Return([]storiface.SectorStorageInfo{si}, nil).Times(1) }, needHttpServer: true, @@ -392,12 +392,12 @@ func TestReader(t *testing.T) { }, indexFnc: func(in *mocks.MockSectorIndex, url string) { - si := stores.SectorStorageInfo{ + si := storiface.SectorStorageInfo{ URLs: []string{url}, } in.EXPECT().StorageFindSector(gomock.Any(), sectorRef.ID, storiface.FTUnsealed, gomock.Any(), - false).Return([]stores.SectorStorageInfo{si}, nil).Times(1) + false).Return([]storiface.SectorStorageInfo{si}, nil).Times(1) }, needHttpServer: true, @@ -413,12 +413,12 @@ func TestReader(t *testing.T) { }, indexFnc: func(in *mocks.MockSectorIndex, url string) { - si := stores.SectorStorageInfo{ + si := storiface.SectorStorageInfo{ URLs: []string{url}, } in.EXPECT().StorageFindSector(gomock.Any(), sectorRef.ID, storiface.FTUnsealed, gomock.Any(), - false).Return([]stores.SectorStorageInfo{si}, nil).Times(1) + false).Return([]storiface.SectorStorageInfo{si}, nil).Times(1) }, needHttpServer: true, @@ -639,12 +639,12 @@ func TestCheckIsUnsealed(t *testing.T) { }, indexFnc: func(in *mocks.MockSectorIndex, url string) { - si := stores.SectorStorageInfo{ + si := storiface.SectorStorageInfo{ URLs: []string{url}, } in.EXPECT().StorageFindSector(gomock.Any(), sectorRef.ID, storiface.FTUnsealed, gomock.Any(), - false).Return([]stores.SectorStorageInfo{si}, nil).Times(1) + false).Return([]storiface.SectorStorageInfo{si}, nil).Times(1) }, needHttpServer: true, @@ -657,12 +657,12 @@ func TestCheckIsUnsealed(t *testing.T) { }, indexFnc: func(in *mocks.MockSectorIndex, url string) { - si := stores.SectorStorageInfo{ + si := storiface.SectorStorageInfo{ URLs: []string{url}, } in.EXPECT().StorageFindSector(gomock.Any(), sectorRef.ID, storiface.FTUnsealed, gomock.Any(), - false).Return([]stores.SectorStorageInfo{si}, nil).Times(1) + false).Return([]storiface.SectorStorageInfo{si}, nil).Times(1) }, needHttpServer: true, @@ -693,12 +693,12 @@ func TestCheckIsUnsealed(t *testing.T) { }, indexFnc: func(in *mocks.MockSectorIndex, url string) { - si := stores.SectorStorageInfo{ + si := storiface.SectorStorageInfo{ URLs: []string{url}, } in.EXPECT().StorageFindSector(gomock.Any(), sectorRef.ID, storiface.FTUnsealed, gomock.Any(), - false).Return([]stores.SectorStorageInfo{si}, nil).Times(1) + false).Return([]storiface.SectorStorageInfo{si}, nil).Times(1) }, needHttpServer: true, @@ -720,12 +720,12 @@ func TestCheckIsUnsealed(t *testing.T) { }, indexFnc: func(in *mocks.MockSectorIndex, url string) { - si := stores.SectorStorageInfo{ + si := storiface.SectorStorageInfo{ URLs: []string{url}, } in.EXPECT().StorageFindSector(gomock.Any(), sectorRef.ID, storiface.FTUnsealed, gomock.Any(), - false).Return([]stores.SectorStorageInfo{si}, nil).Times(1) + false).Return([]storiface.SectorStorageInfo{si}, nil).Times(1) }, needHttpServer: true, diff --git a/extern/sector-storage/storiface/index.go b/extern/sector-storage/storiface/index.go new file mode 100644 index 000000000..c7adfbe1d --- /dev/null +++ b/extern/sector-storage/storiface/index.go @@ -0,0 +1,57 @@ +package storiface + +import ( + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" +) + +// ID identifies sector storage by UUID. One sector storage should map to one +// filesystem, local or networked / shared by multiple machines +type ID string + +type Group = string + +type StorageInfo struct { + ID ID + URLs []string // TODO: Support non-http transports + Weight uint64 + MaxStorage uint64 + + CanSeal bool + CanStore bool + + Groups []Group + AllowTo []Group +} + +type HealthReport struct { + Stat fsutil.FsStat + Err string +} + +type SectorStorageInfo struct { + ID ID + URLs []string // TODO: Support non-http transports + BaseURLs []string + Weight uint64 + + CanSeal bool + CanStore bool + + Primary bool +} + +type Decl struct { + abi.SectorID + SectorFileType +} + +type StoragePath struct { + ID ID + Weight uint64 + + LocalPath string + + CanSeal bool + CanStore bool +} diff --git a/extern/sector-storage/testworker_test.go b/extern/sector-storage/testworker_test.go index dd23278ae..546a7902a 100644 --- a/extern/sector-storage/testworker_test.go +++ b/extern/sector-storage/testworker_test.go @@ -125,7 +125,7 @@ func (t *testWorker) TaskTypes(ctx context.Context) (map[sealtasks.TaskType]stru return t.acceptTasks, nil } -func (t *testWorker) Paths(ctx context.Context) ([]stores.StoragePath, error) { +func (t *testWorker) Paths(ctx context.Context) ([]storiface.StoragePath, error) { return t.lstor.Local(ctx) } diff --git a/extern/sector-storage/worker_local.go b/extern/sector-storage/worker_local.go index ae8fd2f1e..88c3be2df 100644 --- a/extern/sector-storage/worker_local.go +++ b/extern/sector-storage/worker_local.go @@ -149,7 +149,7 @@ func (l *localWorkerPathProvider) AcquireSector(ctx context.Context, sector stor } sid := storiface.PathByType(storageIDs, fileType) - if err := l.w.sindex.StorageDeclareSector(ctx, stores.ID(sid), sector.ID, fileType, l.op == storiface.AcquireMove); err != nil { + if err := l.w.sindex.StorageDeclareSector(ctx, storiface.ID(sid), sector.ID, fileType, l.op == storiface.AcquireMove); err != nil { log.Errorf("declare sector error: %+v", err) } } @@ -618,7 +618,7 @@ func (l *LocalWorker) TaskEnable(ctx context.Context, tt sealtasks.TaskType) err return nil } -func (l *LocalWorker) Paths(ctx context.Context) ([]stores.StoragePath, error) { +func (l *LocalWorker) Paths(ctx context.Context) ([]storiface.StoragePath, error) { return l.localStore.Local(ctx) } diff --git a/itests/kit/node_miner.go b/itests/kit/node_miner.go index ff406629c..e5c4bb2f0 100644 --- a/itests/kit/node_miner.go +++ b/itests/kit/node_miner.go @@ -21,6 +21,7 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/wallet" "github.com/filecoin-project/lotus/extern/sector-storage/stores" + "github.com/filecoin-project/lotus/extern/sector-storage/storiface" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" "github.com/filecoin-project/lotus/miner" libp2pcrypto "github.com/libp2p/go-libp2p-core/crypto" @@ -177,7 +178,7 @@ func (tm *TestMiner) AddStorage(ctx context.Context, t *testing.T, weight uint64 } cfg := &stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: weight, CanSeal: seal, CanStore: store, diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 0518323d2..96771b82c 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -294,13 +294,13 @@ func (sm *StorageMinerAPI) SectorsSummary(ctx context.Context) (map[api.SectorSt return out, nil } -func (sm *StorageMinerAPI) StorageLocal(ctx context.Context) (map[stores.ID]string, error) { +func (sm *StorageMinerAPI) StorageLocal(ctx context.Context) (map[storiface.ID]string, error) { l, err := sm.LocalStore.Local(ctx) if err != nil { return nil, err } - out := map[stores.ID]string{} + out := map[storiface.ID]string{} for _, st := range l { out[st.ID] = st.LocalPath } @@ -324,7 +324,7 @@ func (sm *StorageMinerAPI) SectorsRefs(ctx context.Context) (map[string][]api.Se return out, nil } -func (sm *StorageMinerAPI) StorageStat(ctx context.Context, id stores.ID) (fsutil.FsStat, error) { +func (sm *StorageMinerAPI) StorageStat(ctx context.Context, id storiface.ID) (fsutil.FsStat, error) { return sm.RemoteStore.FsStat(ctx, id) } diff --git a/node/repo/memrepo.go b/node/repo/memrepo.go index 6c5bcacdf..929137994 100644 --- a/node/repo/memrepo.go +++ b/node/repo/memrepo.go @@ -19,6 +19,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" "github.com/filecoin-project/lotus/extern/sector-storage/stores" + "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/lotus/node/config" ) @@ -132,7 +133,7 @@ func (lmem *lockedMemRepo) initSectorStore(t string) { } b, err := json.MarshalIndent(&stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: 10, CanSeal: true, CanStore: true, diff --git a/testplans/lotus-soup/testkit/role_miner.go b/testplans/lotus-soup/testkit/role_miner.go index 7204c71fe..2c7e0ff65 100644 --- a/testplans/lotus-soup/testkit/role_miner.go +++ b/testplans/lotus-soup/testkit/role_miner.go @@ -24,6 +24,7 @@ import ( "github.com/filecoin-project/lotus/chain/wallet" "github.com/filecoin-project/lotus/cmd/lotus-seed/seed" "github.com/filecoin-project/lotus/extern/sector-storage/stores" + "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/lotus/markets/storageadapter" "github.com/filecoin-project/lotus/miner" "github.com/filecoin-project/lotus/node" @@ -198,7 +199,7 @@ func PrepareMiner(t *TestEnvironment) (*LotusMiner, error) { var localPaths []stores.LocalPath b, err := json.MarshalIndent(&stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), + ID: storiface.ID(uuid.New().String()), Weight: 10, CanSeal: true, CanStore: true,