[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-22 18:56:36 +03:00 committed by Leonard Lyubich
parent 44a2c81f8e
commit d6bb697726

View file

@ -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()),
)
}