Skip to content

Commit

Permalink
Merge pull request #9165 from filecoin-project/release1.17.1/detach-s…
Browse files Browse the repository at this point in the history
…torage-on-worker-shutdown

backport: 9153: detach storage on worker shutdown
  • Loading branch information
jennijuju authored Aug 12, 2022
2 parents 98e1282 + a7e99bc commit 8ecf6f3
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/api_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Worker interface {
StorageLocal(ctx context.Context) (map[storiface.ID]string, error) //perm:admin
StorageAddLocal(ctx context.Context, path string) error //perm:admin
StorageDetachLocal(ctx context.Context, path string) error //perm:admin
StorageDetachAll(ctx context.Context) error //perm:admin
StorageRedeclareLocal(ctx context.Context, id *storiface.ID, dropMissing bool) error //perm:admin

// SetEnabled marks the worker as enabled/disabled. Not that this setting
Expand Down
13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/gateway.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
7 changes: 7 additions & 0 deletions cmd/lotus-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ var stopCmd = &cli.Command{
defer closer()

ctx := lcli.ReqContext(cctx)

// Detach any storage associated with this worker
err = api.StorageDetachAll(ctx)
if err != nil {
return err
}

err = api.Shutdown(ctx)
if err != nil {
return err
Expand Down
20 changes: 20 additions & 0 deletions cmd/lotus-worker/sealworker/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/google/uuid"
"github.com/gorilla/mux"
logging "github.com/ipfs/go-log/v2"
"github.com/mitchellh/go-homedir"
"golang.org/x/xerrors"

Expand All @@ -23,6 +24,8 @@ import (
"github.com/filecoin-project/lotus/storage/sealer/storiface"
)

var log = logging.Logger("sealworker")

func WorkerHandler(authv func(ctx context.Context, token string) ([]auth.Permission, error), remote http.HandlerFunc, a api.Worker, permissioned bool) http.Handler {
mux := mux.NewRouter()
readerHandler, readerServerOpt := rpcenc.ReaderParamDecoder()
Expand Down Expand Up @@ -146,6 +149,23 @@ func (w *Worker) StorageDetachLocal(ctx context.Context, path string) error {
return w.LocalStore.ClosePath(ctx, localPath.ID)
}

func (w *Worker) StorageDetachAll(ctx context.Context) error {

lps, err := w.LocalStore.Local(ctx)
if err != nil {
return xerrors.Errorf("getting local path list: %w", err)
}

for _, lp := range lps {
err = w.LocalStore.ClosePath(ctx, lp.ID)
if err != nil {
log.Warnf("unable to close path: %w", err)
}
}

return nil
}

func (w *Worker) StorageRedeclareLocal(ctx context.Context, id *storiface.ID, dropMissing bool) error {
return w.LocalStore.Redeclare(ctx, id, dropMissing)
}
Expand Down
10 changes: 10 additions & 0 deletions documentation/en/api-v0-methods-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* [SetEnabled](#SetEnabled)
* [Storage](#Storage)
* [StorageAddLocal](#StorageAddLocal)
* [StorageDetachAll](#StorageDetachAll)
* [StorageDetachLocal](#StorageDetachLocal)
* [StorageLocal](#StorageLocal)
* [StorageRedeclareLocal](#StorageRedeclareLocal)
Expand Down Expand Up @@ -2121,6 +2122,15 @@ Inputs:

Response: `{}`

### StorageDetachAll


Perms: admin

Inputs: `null`

Response: `{}`

### StorageDetachLocal


Expand Down

0 comments on commit 8ecf6f3

Please sign in to comment.