workers: Handle init on first run
This commit is contained in:
parent
7e997e40f3
commit
de1c984b48
@ -182,7 +182,7 @@ 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
|
||||
WorkerAttachStorage func(context.Context, stores.StorageInfo) error `perm:"admin"`
|
||||
StorageAttach func(context.Context, stores.StorageInfo) 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(ctx context.Context) (map[stores.ID][]stores.Decl, error) `perm:"admin"`
|
||||
@ -655,7 +655,7 @@ func (c *StorageMinerStruct) WorkerConnect(ctx context.Context, url string) erro
|
||||
}
|
||||
|
||||
func (c *StorageMinerStruct) StorageAttach(ctx context.Context, si stores.StorageInfo) error {
|
||||
return c.Internal.WorkerAttachStorage(ctx, si)
|
||||
return c.Internal.StorageAttach(ctx, si)
|
||||
}
|
||||
|
||||
func (c *StorageMinerStruct) StorageDeclareSector(ctx context.Context, storageId stores.ID, s abi.SectorID, ft sectorbuilder.SectorFileType) error {
|
||||
|
@ -2,12 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/mux"
|
||||
logging "github.com/ipfs/go-log/v2"
|
||||
"golang.org/x/xerrors"
|
||||
@ -21,6 +25,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/lib/auth"
|
||||
"github.com/filecoin-project/lotus/lib/jsonrpc"
|
||||
"github.com/filecoin-project/lotus/lib/lotuslog"
|
||||
"github.com/filecoin-project/lotus/node/config"
|
||||
"github.com/filecoin-project/lotus/node/repo"
|
||||
"github.com/filecoin-project/lotus/storage/sealmgr/advmgr"
|
||||
"github.com/filecoin-project/lotus/storage/sealmgr/stores"
|
||||
@ -80,6 +85,10 @@ var runCmd = &cli.Command{
|
||||
Name: "address",
|
||||
Usage: "Locally reachable address",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "no-local-storage",
|
||||
Usage: "don't use storageminer repo for sector storage",
|
||||
},
|
||||
},
|
||||
Action: func(cctx *cli.Context) error {
|
||||
if !cctx.Bool("enable-gpu-proving") {
|
||||
@ -141,7 +150,46 @@ var runCmd = &cli.Command{
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-seal-worker init' to set it up", repoPath)
|
||||
if err := r.Init(repo.Worker); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lr, err := r.Lock(repo.Worker)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var localPaths []config.LocalPath
|
||||
|
||||
if !cctx.Bool("no-local-storage") {
|
||||
b, err := json.MarshalIndent(&stores.StorageMeta{
|
||||
ID: stores.ID(uuid.New().String()),
|
||||
Weight: 10,
|
||||
CanSeal: true,
|
||||
CanStore: false,
|
||||
}, "", " ")
|
||||
if err != nil {
|
||||
return xerrors.Errorf("marshaling storage config: %w", err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(lr.Path(), "sectorstore.json"), b, 0644); err != nil {
|
||||
return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(lr.Path(), "sectorstore.json"), err)
|
||||
}
|
||||
|
||||
localPaths = append(localPaths, config.LocalPath{
|
||||
Path: lr.Path(),
|
||||
})
|
||||
}
|
||||
|
||||
if err := lr.SetStorage(func(sc *config.StorageConfig) {
|
||||
sc.StoragePaths = append(sc.StoragePaths, localPaths...)
|
||||
}); err != nil {
|
||||
return xerrors.Errorf("set storage config: %w", err)
|
||||
}
|
||||
|
||||
if err := lr.Close(); err != nil {
|
||||
return xerrors.Errorf("close repo: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
lr, err := r.Lock(repo.Worker)
|
||||
|
@ -176,7 +176,7 @@ func DeclareLocalStorage(ctx context.Context, idx SectorIndex, localStore *Local
|
||||
CanStore: path.CanStore,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("attaching local storage to remote: %+v")
|
||||
log.Errorf("attaching local storage to remote: %+v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user