Merge pull request #9165 from filecoin-project/release1.17.1/detach-storage-on-worker-shutdown

backport: 9153: detach storage on worker shutdown
This commit is contained in:
Jiaying Wang 2022-08-12 14:48:45 -04:00 committed by GitHub
commit 8ecf6f3ad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 51 additions and 0 deletions

View File

@ -62,6 +62,7 @@ type Worker interface {
StorageLocal(ctx context.Context) (map[storiface.ID]string, error) //perm:admin StorageLocal(ctx context.Context) (map[storiface.ID]string, error) //perm:admin
StorageAddLocal(ctx context.Context, path string) error //perm:admin StorageAddLocal(ctx context.Context, path string) error //perm:admin
StorageDetachLocal(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 StorageRedeclareLocal(ctx context.Context, id *storiface.ID, dropMissing bool) error //perm:admin
// SetEnabled marks the worker as enabled/disabled. Not that this setting // SetEnabled marks the worker as enabled/disabled. Not that this setting

View File

@ -981,6 +981,8 @@ type WorkerStruct struct {
StorageAddLocal func(p0 context.Context, p1 string) error `perm:"admin"` StorageAddLocal func(p0 context.Context, p1 string) error `perm:"admin"`
StorageDetachAll func(p0 context.Context) error `perm:"admin"`
StorageDetachLocal func(p0 context.Context, p1 string) error `perm:"admin"` StorageDetachLocal func(p0 context.Context, p1 string) error `perm:"admin"`
StorageLocal func(p0 context.Context) (map[storiface.ID]string, error) `perm:"admin"` StorageLocal func(p0 context.Context) (map[storiface.ID]string, error) `perm:"admin"`
@ -5668,6 +5670,17 @@ func (s *WorkerStub) StorageAddLocal(p0 context.Context, p1 string) error {
return ErrNotSupported return ErrNotSupported
} }
func (s *WorkerStruct) StorageDetachAll(p0 context.Context) error {
if s.Internal.StorageDetachAll == nil {
return ErrNotSupported
}
return s.Internal.StorageDetachAll(p0)
}
func (s *WorkerStub) StorageDetachAll(p0 context.Context) error {
return ErrNotSupported
}
func (s *WorkerStruct) StorageDetachLocal(p0 context.Context, p1 string) error { func (s *WorkerStruct) StorageDetachLocal(p0 context.Context, p1 string) error {
if s.Internal.StorageDetachLocal == nil { if s.Internal.StorageDetachLocal == nil {
return ErrNotSupported return ErrNotSupported

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -129,6 +129,13 @@ var stopCmd = &cli.Command{
defer closer() defer closer()
ctx := lcli.ReqContext(cctx) ctx := lcli.ReqContext(cctx)
// Detach any storage associated with this worker
err = api.StorageDetachAll(ctx)
if err != nil {
return err
}
err = api.Shutdown(ctx) err = api.Shutdown(ctx)
if err != nil { if err != nil {
return err return err

View File

@ -7,6 +7,7 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"github.com/gorilla/mux" "github.com/gorilla/mux"
logging "github.com/ipfs/go-log/v2"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -23,6 +24,8 @@ import (
"github.com/filecoin-project/lotus/storage/sealer/storiface" "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 { 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() mux := mux.NewRouter()
readerHandler, readerServerOpt := rpcenc.ReaderParamDecoder() readerHandler, readerServerOpt := rpcenc.ReaderParamDecoder()
@ -146,6 +149,23 @@ func (w *Worker) StorageDetachLocal(ctx context.Context, path string) error {
return w.LocalStore.ClosePath(ctx, localPath.ID) 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 { func (w *Worker) StorageRedeclareLocal(ctx context.Context, id *storiface.ID, dropMissing bool) error {
return w.LocalStore.Redeclare(ctx, id, dropMissing) return w.LocalStore.Redeclare(ctx, id, dropMissing)
} }

View File

@ -39,6 +39,7 @@
* [SetEnabled](#SetEnabled) * [SetEnabled](#SetEnabled)
* [Storage](#Storage) * [Storage](#Storage)
* [StorageAddLocal](#StorageAddLocal) * [StorageAddLocal](#StorageAddLocal)
* [StorageDetachAll](#StorageDetachAll)
* [StorageDetachLocal](#StorageDetachLocal) * [StorageDetachLocal](#StorageDetachLocal)
* [StorageLocal](#StorageLocal) * [StorageLocal](#StorageLocal)
* [StorageRedeclareLocal](#StorageRedeclareLocal) * [StorageRedeclareLocal](#StorageRedeclareLocal)
@ -2121,6 +2122,15 @@ Inputs:
Response: `{}` Response: `{}`
### StorageDetachAll
Perms: admin
Inputs: `null`
Response: `{}`
### StorageDetachLocal ### StorageDetachLocal