[#168] node: Refactor container services

Resolve containedctx for remoteLoadAnnounceWriter struct

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-03-24 11:08:45 +03:00
parent 28dc9e2190
commit 56161d39b4
6 changed files with 12 additions and 16 deletions

View file

@ -309,7 +309,7 @@ func (w *morphLoadWriter) Put(a containerSDK.SizeEstimation) error {
return w.cnrMorphClient.AnnounceLoad(prm) return w.cnrMorphClient.AnnounceLoad(prm)
} }
func (*morphLoadWriter) Close() error { func (*morphLoadWriter) Close(context.Context) error {
return nil return nil
} }
@ -319,7 +319,7 @@ func (nopLoadWriter) Put(containerSDK.SizeEstimation) error {
return nil return nil
} }
func (nopLoadWriter) Close() error { func (nopLoadWriter) Close(context.Context) error {
return nil return nil
} }
@ -368,15 +368,11 @@ type remoteLoadAnnounceWriterProvider struct {
func (p *remoteLoadAnnounceWriterProvider) InitWriter(ctx context.Context) (loadcontroller.Writer, error) { func (p *remoteLoadAnnounceWriterProvider) InitWriter(ctx context.Context) (loadcontroller.Writer, error) {
return &remoteLoadAnnounceWriter{ return &remoteLoadAnnounceWriter{
ctx: ctx,
client: p.client, client: p.client,
}, nil }, nil
} }
// nolint: containedctx
type remoteLoadAnnounceWriter struct { type remoteLoadAnnounceWriter struct {
ctx context.Context
client client.Client client client.Client
buf []containerSDK.SizeEstimation buf []containerSDK.SizeEstimation
@ -388,12 +384,12 @@ func (r *remoteLoadAnnounceWriter) Put(a containerSDK.SizeEstimation) error {
return nil return nil
} }
func (r *remoteLoadAnnounceWriter) Close() error { func (r *remoteLoadAnnounceWriter) Close(ctx context.Context) error {
var cliPrm apiClient.PrmAnnounceSpace var cliPrm apiClient.PrmAnnounceSpace
cliPrm.SetValues(r.buf) cliPrm.SetValues(r.buf)
_, err := r.client.ContainerAnnounceUsedSpace(r.ctx, cliPrm) _, err := r.client.ContainerAnnounceUsedSpace(ctx, cliPrm)
return err return err
} }

View file

@ -100,7 +100,7 @@ func (c *announceContext) announce() {
} }
// finish writing // finish writing
err = targetWriter.Close() err = targetWriter.Close(c.ctx)
if err != nil { if err != nil {
c.log.Debug("could not finish writing local announcements", c.log.Debug("could not finish writing local announcements",
zap.String("error", err.Error()), zap.String("error", err.Error()),
@ -301,7 +301,7 @@ func (c *stopContext) report() {
} }
// finish writing // finish writing
err = resultWriter.Close() err = resultWriter.Close(c.ctx)
if err != nil { if err != nil {
c.log.Debug("could not finish writing load estimations", c.log.Debug("could not finish writing load estimations",
zap.String("error", err.Error()), zap.String("error", err.Error()),

View file

@ -69,7 +69,7 @@ func (s *testAnnouncementStorage) Put(v container.SizeEstimation) error {
return nil return nil
} }
func (s *testAnnouncementStorage) Close() error { func (s *testAnnouncementStorage) Close(context.Context) error {
return nil return nil
} }

View file

@ -2,7 +2,6 @@ package loadcontroller
import ( import (
"context" "context"
"io"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
) )
@ -70,7 +69,7 @@ type Writer interface {
// the Close's return. // the Close's return.
// //
// Methods must not be called after Close. // Methods must not be called after Close.
io.Closer Close(ctx context.Context) error
} }
// WriterProvider is a group of methods provided // WriterProvider is a group of methods provided

View file

@ -154,9 +154,9 @@ func (w *loadWriter) Put(a container.SizeEstimation) error {
return nil return nil
} }
func (w *loadWriter) Close() error { func (w *loadWriter) Close(ctx context.Context) error {
for key, wRemote := range w.mServers { for key, wRemote := range w.mServers {
err := wRemote.Close() err := wRemote.Close(ctx)
if err != nil { if err != nil {
w.router.log.Debug("could not close remote server writer", w.router.log.Debug("could not close remote server writer",
zap.String("key", key), zap.String("key", key),

View file

@ -1,6 +1,7 @@
package loadstorage package loadstorage
import ( import (
"context"
"sort" "sort"
"sync" "sync"
@ -89,7 +90,7 @@ func (s *Storage) Put(a container.SizeEstimation) error {
return nil return nil
} }
func (s *Storage) Close() error { func (s *Storage) Close(context.Context) error {
return nil return nil
} }