Skip to content

Commit

Permalink
Close all storage paths on worker shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrenuj Bansal authored and Shrenuj Bansal committed Aug 10, 2022
1 parent 3244969 commit f390c18
Show file tree
Hide file tree
Showing 9 changed files with 42 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.
4 changes: 4 additions & 0 deletions cmd/lotus-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ var stopCmd = &cli.Command{
defer closer()

ctx := lcli.ReqContext(cctx)

// Detach any storage associated with this worker
api.StorageDetachAll(ctx)

err = api.Shutdown(ctx)
if err != nil {
return err
Expand Down
14 changes: 14 additions & 0 deletions cmd/lotus-worker/sealworker/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ 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 {
w.LocalStore.ClosePath(ctx, lp.ID)
}

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 f390c18

Please sign in to comment.