From d6bb697726a94e3180386313c27741f004cde6d0 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 22 Jun 2021 18:56:36 +0300 Subject: [PATCH] [#607] container/announce: Use public keys as keys to server cache In future server info will contain multiple endpoints whose string representation will be worse suited to the cache key. Signed-off-by: Leonard Lyubich --- .../container/announcement/load/route/calls.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/services/container/announcement/load/route/calls.go b/pkg/services/container/announcement/load/route/calls.go index f0e4147f1..7ad6a83b3 100644 --- a/pkg/services/container/announcement/load/route/calls.go +++ b/pkg/services/container/announcement/load/route/calls.go @@ -2,6 +2,7 @@ package loadroute import ( "context" + "encoding/hex" "sync" "github.com/nspcc-dev/neofs-api-go/pkg/container" @@ -110,13 +111,13 @@ func (w *loadWriter) Put(a container.UsedSpaceAnnouncement) error { } for _, remoteInfo := range routeValues.route { - var endpoint string + var key string if remoteInfo != nil { - endpoint = remoteInfo.Address() + key = hex.EncodeToString(remoteInfo.PublicKey()) } - remoteWriter, ok := w.mServers[endpoint] + remoteWriter, ok := w.mServers[key] if !ok { provider, err := w.router.remoteProvider.InitRemote(remoteInfo) if err != nil { @@ -136,7 +137,7 @@ func (w *loadWriter) Put(a container.UsedSpaceAnnouncement) error { continue // best effort } - w.mServers[endpoint] = remoteWriter + w.mServers[key] = remoteWriter } err := remoteWriter.Put(a) @@ -153,11 +154,11 @@ func (w *loadWriter) Put(a container.UsedSpaceAnnouncement) error { } func (w *loadWriter) Close() error { - for endpoint, wRemote := range w.mServers { + for key, wRemote := range w.mServers { err := wRemote.Close() if err != nil { w.router.log.Debug("could not close remote server writer", - zap.String("endpoint", endpoint), + zap.String("key", key), zap.String("error", err.Error()), ) }