diff --git a/storagenode/gracefulexit/chore.go b/storagenode/gracefulexit/chore.go index 1cbbe9d30..d6eaa0990 100644 --- a/storagenode/gracefulexit/chore.go +++ b/storagenode/gracefulexit/chore.go @@ -23,7 +23,7 @@ type Chore struct { dialer rpc.Dialer config Config - service Service + service *Service transferService piecetransfer.Service exitingMap sync.Map @@ -32,7 +32,7 @@ type Chore struct { } // NewChore instantiates Chore. -func NewChore(log *zap.Logger, service Service, transferService piecetransfer.Service, dialer rpc.Dialer, config Config) *Chore { +func NewChore(log *zap.Logger, service *Service, transferService piecetransfer.Service, dialer rpc.Dialer, config Config) *Chore { return &Chore{ log: log, dialer: dialer, diff --git a/storagenode/gracefulexit/service.go b/storagenode/gracefulexit/service.go index f6e7b8fa7..f5753a60f 100644 --- a/storagenode/gracefulexit/service.go +++ b/storagenode/gracefulexit/service.go @@ -19,49 +19,10 @@ import ( "storj.io/storj/storagenode/trust" ) -// Service acts as the gateway to the `satellites` db for graceful exit -// code (querying and updating that db as necessary). +// Service exposes methods to manage GE progress. // // architecture: Service -type Service interface { - // ListPendingExits returns a slice with one record for every satellite - // from which this node is gracefully exiting. Each record includes the - // satellite's ID/address and information about the graceful exit status - // and progress. - ListPendingExits(ctx context.Context) ([]ExitingSatellite, error) - - // DeletePiece deletes one piece stored for a satellite, and updates - // the deleted byte count for the corresponding graceful exit operation. - DeletePiece(ctx context.Context, satelliteID storj.NodeID, pieceID storj.PieceID) error - - // DeleteSatellitePieces deletes all pieces stored for a satellite, and updates - // the deleted byte count for the corresponding graceful exit operation. - DeleteSatellitePieces(ctx context.Context, satelliteID storj.NodeID) error - - // ExitFailed updates the database when a graceful exit has failed. - ExitFailed(ctx context.Context, satelliteID storj.NodeID, reason pb.ExitFailed_Reason, exitFailedBytes []byte) error - - // ExitCompleted updates the database when a graceful exit is completed. It also - // deletes all pieces and blobs for that satellite. - ExitCompleted(ctx context.Context, satelliteID storj.NodeID, completionReceipt []byte) error - - // ExitNotPossible deletes the entry for the corresponding graceful exit operation. - // This is intended to be called when a graceful exit operation was initiated but - // the satellite rejected it. - ExitNotPossible(ctx context.Context, satelliteID storj.NodeID) error - - // DeleteSatelliteData deletes all pieces and blobs stored for a satellite. - // Note: this should only ever be called after exit has finished. - DeleteSatelliteData(ctx context.Context, satelliteID storj.NodeID) error -} - -// ensures that service implements Service. -var _ Service = (*service)(nil) - -// service exposes methods to manage GE progress. -// -// architecture: Service -type service struct { +type Service struct { log *zap.Logger store *pieces.Store trust *trust.Pool @@ -71,8 +32,8 @@ type service struct { } // NewService is a constructor for a GE service. -func NewService(log *zap.Logger, store *pieces.Store, trust *trust.Pool, satelliteDB satellites.DB, dialer rpc.Dialer, config Config) Service { - return &service{ +func NewService(log *zap.Logger, store *pieces.Store, trust *trust.Pool, satelliteDB satellites.DB, dialer rpc.Dialer, config Config) *Service { + return &Service{ log: log, store: store, trust: trust, @@ -87,7 +48,11 @@ type ExitingSatellite struct { NodeURL storj.NodeURL } -func (c *service) ListPendingExits(ctx context.Context) (_ []ExitingSatellite, err error) { +// ListPendingExits returns a slice with one record for every satellite +// from which this node is gracefully exiting. Each record includes the +// satellite's ID/address and information about the graceful exit status +// and progress. +func (c *Service) ListPendingExits(ctx context.Context) (_ []ExitingSatellite, err error) { defer mon.Task()(&ctx)(&err) exitProgress, err := c.satelliteDB.ListGracefulExits(ctx) @@ -111,7 +76,7 @@ func (c *service) ListPendingExits(ctx context.Context) (_ []ExitingSatellite, e // DeletePiece deletes one piece stored for a satellite, and updates // the deleted byte count for the corresponding graceful exit operation. -func (c *service) DeletePiece(ctx context.Context, satelliteID storj.NodeID, pieceID storj.PieceID) (err error) { +func (c *Service) DeletePiece(ctx context.Context, satelliteID storj.NodeID, pieceID storj.PieceID) (err error) { defer mon.Task()(&ctx)(&err) piece, err := c.store.Reader(ctx, satelliteID, pieceID) @@ -127,9 +92,25 @@ func (c *service) DeletePiece(ctx context.Context, satelliteID storj.NodeID, pie return c.satelliteDB.UpdateGracefulExit(ctx, satelliteID, size) } -// DeleteSatellitePieces deletes all pieces stored for a satellite, and updates +// DeleteSatelliteData deletes all pieces and blobs stored for a satellite. +// +// Note: this should only ever be called after exit has finished. +func (c *Service) DeleteSatelliteData(ctx context.Context, satelliteID storj.NodeID) (err error) { + defer mon.Task()(&ctx)(&err) + + // delete all remaining pieces + err = c.deleteSatellitePieces(ctx, satelliteID) + if err != nil { + return errs.Wrap(err) + } + + // delete everything left in blobs folder of specific satellites + return c.store.DeleteSatelliteBlobs(ctx, satelliteID) +} + +// deleteSatellitePieces deletes all pieces stored for a satellite, and updates // the deleted byte count for the corresponding graceful exit operation. -func (c *service) DeleteSatellitePieces(ctx context.Context, satelliteID storj.NodeID) (err error) { +func (c *Service) deleteSatellitePieces(ctx context.Context, satelliteID storj.NodeID) (err error) { defer mon.Task()(&ctx)(&err) var totalDeleted int64 @@ -158,34 +139,21 @@ func (c *service) DeleteSatellitePieces(ctx context.Context, satelliteID storj.N } // ExitFailed updates the database when a graceful exit has failed. -func (c *service) ExitFailed(ctx context.Context, satelliteID storj.NodeID, reason pb.ExitFailed_Reason, exitFailedBytes []byte) (err error) { +func (c *Service) ExitFailed(ctx context.Context, satelliteID storj.NodeID, reason pb.ExitFailed_Reason, exitFailedBytes []byte) (err error) { defer mon.Task()(&ctx)(&err) return errs.Wrap(c.satelliteDB.CompleteGracefulExit(ctx, satelliteID, c.nowFunc(), satellites.ExitFailed, exitFailedBytes)) } // ExitCompleted updates the database when a graceful exit is completed. -func (c *service) ExitCompleted(ctx context.Context, satelliteID storj.NodeID, completionReceipt []byte) (err error) { +func (c *Service) ExitCompleted(ctx context.Context, satelliteID storj.NodeID, completionReceipt []byte) (err error) { defer mon.Task()(&ctx)(&err) return errs.Wrap(c.satelliteDB.CompleteGracefulExit(ctx, satelliteID, c.nowFunc(), satellites.ExitSucceeded, completionReceipt)) } -// DeleteSatelliteData deletes all pieces and blobs for that satellite. -func (c *service) DeleteSatelliteData(ctx context.Context, satelliteID storj.NodeID) (err error) { - defer mon.Task()(&ctx)(&err) - - // delete all remaining pieces - err = c.DeleteSatellitePieces(ctx, satelliteID) - if err != nil { - return errs.Wrap(err) - } - - // delete everything left in blobs folder of specific satellites - return c.store.DeleteSatelliteBlobs(ctx, satelliteID) -} - -// ExitNotPossible deletes the entry from satellite table and inform graceful exit -// has failed to start. -func (c *service) ExitNotPossible(ctx context.Context, satelliteID storj.NodeID) (err error) { +// ExitNotPossible deletes the entry for the corresponding graceful exit operation. +// This is intended to be called when a graceful exit operation was initiated but +// the satellite rejected it. +func (c *Service) ExitNotPossible(ctx context.Context, satelliteID storj.NodeID) (err error) { defer mon.Task()(&ctx)(&err) return c.satelliteDB.CancelGracefulExit(ctx, satelliteID) diff --git a/storagenode/gracefulexit/worker.go b/storagenode/gracefulexit/worker.go index 9f9aaec33..820c257c1 100644 --- a/storagenode/gracefulexit/worker.go +++ b/storagenode/gracefulexit/worker.go @@ -23,7 +23,7 @@ import ( type Worker struct { log *zap.Logger - service Service + service *Service transferService piecetransfer.Service dialer rpc.Dialer @@ -32,7 +32,7 @@ type Worker struct { } // NewWorker instantiates Worker. -func NewWorker(log *zap.Logger, service Service, transferService piecetransfer.Service, dialer rpc.Dialer, satelliteURL storj.NodeURL, config Config) *Worker { +func NewWorker(log *zap.Logger, service *Service, transferService piecetransfer.Service, dialer rpc.Dialer, satelliteURL storj.NodeURL, config Config) *Worker { return &Worker{ log: log.Named(satelliteURL.String()), service: service, @@ -48,7 +48,7 @@ func NewWorker(log *zap.Logger, service Service, transferService piecetransfer.S func (worker *Worker) Run(ctx context.Context) (err error) { defer mon.Task()(&ctx)(&err) - worker.log.Debug("worker") + worker.log.Debug("started") defer worker.log.Debug("finished") limiter := sync2.NewLimiter(worker.concurrentTransfers) diff --git a/storagenode/peer.go b/storagenode/peer.go index 410762185..6baf02de3 100644 --- a/storagenode/peer.go +++ b/storagenode/peer.go @@ -265,7 +265,7 @@ type Peer struct { } GracefulExit struct { - Service gracefulexit.Service + Service *gracefulexit.Service Endpoint *gracefulexit.Endpoint Chore *gracefulexit.Chore BlobsCleaner *gracefulexit.BlobsCleaner