From 56161d39b4aa4129ae672d78294f26f7dc0877ea Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Fri, 24 Mar 2023 11:08:45 +0300 Subject: [PATCH] [#168] node: Refactor container services Resolve containedctx for remoteLoadAnnounceWriter struct Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-node/container.go | 12 ++++-------- .../container/announcement/load/controller/calls.go | 4 ++-- .../announcement/load/controller/calls_test.go | 2 +- .../container/announcement/load/controller/deps.go | 3 +-- .../container/announcement/load/route/calls.go | 4 ++-- .../container/announcement/load/storage/storage.go | 3 ++- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/cmd/frostfs-node/container.go b/cmd/frostfs-node/container.go index 23b175852..45c6e390c 100644 --- a/cmd/frostfs-node/container.go +++ b/cmd/frostfs-node/container.go @@ -309,7 +309,7 @@ func (w *morphLoadWriter) Put(a containerSDK.SizeEstimation) error { return w.cnrMorphClient.AnnounceLoad(prm) } -func (*morphLoadWriter) Close() error { +func (*morphLoadWriter) Close(context.Context) error { return nil } @@ -319,7 +319,7 @@ func (nopLoadWriter) Put(containerSDK.SizeEstimation) error { return nil } -func (nopLoadWriter) Close() error { +func (nopLoadWriter) Close(context.Context) error { return nil } @@ -368,15 +368,11 @@ type remoteLoadAnnounceWriterProvider struct { func (p *remoteLoadAnnounceWriterProvider) InitWriter(ctx context.Context) (loadcontroller.Writer, error) { return &remoteLoadAnnounceWriter{ - ctx: ctx, client: p.client, }, nil } -// nolint: containedctx type remoteLoadAnnounceWriter struct { - ctx context.Context - client client.Client buf []containerSDK.SizeEstimation @@ -388,12 +384,12 @@ func (r *remoteLoadAnnounceWriter) Put(a containerSDK.SizeEstimation) error { return nil } -func (r *remoteLoadAnnounceWriter) Close() error { +func (r *remoteLoadAnnounceWriter) Close(ctx context.Context) error { var cliPrm apiClient.PrmAnnounceSpace cliPrm.SetValues(r.buf) - _, err := r.client.ContainerAnnounceUsedSpace(r.ctx, cliPrm) + _, err := r.client.ContainerAnnounceUsedSpace(ctx, cliPrm) return err } diff --git a/pkg/services/container/announcement/load/controller/calls.go b/pkg/services/container/announcement/load/controller/calls.go index c6b574c32..fde6913a7 100644 --- a/pkg/services/container/announcement/load/controller/calls.go +++ b/pkg/services/container/announcement/load/controller/calls.go @@ -100,7 +100,7 @@ func (c *announceContext) announce() { } // finish writing - err = targetWriter.Close() + err = targetWriter.Close(c.ctx) if err != nil { c.log.Debug("could not finish writing local announcements", zap.String("error", err.Error()), @@ -301,7 +301,7 @@ func (c *stopContext) report() { } // finish writing - err = resultWriter.Close() + err = resultWriter.Close(c.ctx) if err != nil { c.log.Debug("could not finish writing load estimations", zap.String("error", err.Error()), diff --git a/pkg/services/container/announcement/load/controller/calls_test.go b/pkg/services/container/announcement/load/controller/calls_test.go index 1737921a2..8e4a3cedd 100644 --- a/pkg/services/container/announcement/load/controller/calls_test.go +++ b/pkg/services/container/announcement/load/controller/calls_test.go @@ -69,7 +69,7 @@ func (s *testAnnouncementStorage) Put(v container.SizeEstimation) error { return nil } -func (s *testAnnouncementStorage) Close() error { +func (s *testAnnouncementStorage) Close(context.Context) error { return nil } diff --git a/pkg/services/container/announcement/load/controller/deps.go b/pkg/services/container/announcement/load/controller/deps.go index 953ea452b..7f7a270b9 100644 --- a/pkg/services/container/announcement/load/controller/deps.go +++ b/pkg/services/container/announcement/load/controller/deps.go @@ -2,7 +2,6 @@ package loadcontroller import ( "context" - "io" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container" ) @@ -70,7 +69,7 @@ type Writer interface { // the Close's return. // // Methods must not be called after Close. - io.Closer + Close(ctx context.Context) error } // WriterProvider is a group of methods provided diff --git a/pkg/services/container/announcement/load/route/calls.go b/pkg/services/container/announcement/load/route/calls.go index 95099fd5a..1cdd65911 100644 --- a/pkg/services/container/announcement/load/route/calls.go +++ b/pkg/services/container/announcement/load/route/calls.go @@ -154,9 +154,9 @@ func (w *loadWriter) Put(a container.SizeEstimation) error { return nil } -func (w *loadWriter) Close() error { +func (w *loadWriter) Close(ctx context.Context) error { for key, wRemote := range w.mServers { - err := wRemote.Close() + err := wRemote.Close(ctx) if err != nil { w.router.log.Debug("could not close remote server writer", zap.String("key", key), diff --git a/pkg/services/container/announcement/load/storage/storage.go b/pkg/services/container/announcement/load/storage/storage.go index 70d82fc4e..4d3104c76 100644 --- a/pkg/services/container/announcement/load/storage/storage.go +++ b/pkg/services/container/announcement/load/storage/storage.go @@ -1,6 +1,7 @@ package loadstorage import ( + "context" "sort" "sync" @@ -89,7 +90,7 @@ func (s *Storage) Put(a container.SizeEstimation) error { return nil } -func (s *Storage) Close() error { +func (s *Storage) Close(context.Context) error { return nil }