[#1902] tree: Allow synchronize all the container trees

Add `SynchronizeAllTrees` method of the Tree service. It allows fetching
tree IDs and sync all of them. Share common logic b/w the new method and
the `SynchronizeTree`.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-10-18 17:15:24 +03:00 committed by Pavel Karpy
parent 1805c6606d
commit 1766ca2039
3 changed files with 103 additions and 7 deletions

View file

@ -7,9 +7,19 @@ import (
controlconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/control"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
"github.com/nspcc-dev/neofs-node/pkg/services/tree"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"google.golang.org/grpc"
)
type treeSynchronizer struct {
treeSvc *tree.Service
}
func (t treeSynchronizer) Synchronize(ctx context.Context, cnr cid.ID, treeID string) error {
return t.treeSvc.SynchronizeTree(ctx, cnr, treeID)
}
func initControlService(c *cfg) {
endpoint := controlconfig.GRPC(c.appCfg).Endpoint()
if endpoint == controlconfig.GRPCEndpointDefault {
@ -34,7 +44,9 @@ func initControlService(c *cfg) {
controlSvc.WithReplicator(c.replicator),
controlSvc.WithNodeState(c),
controlSvc.WithLocalStorage(c.cfgObject.cfgLocalStorage.localStorage),
controlSvc.WithTreeService(c.treeService),
controlSvc.WithTreeService(treeSynchronizer{
c.treeService,
}),
)
lis, err := net.Listen("tcp", endpoint)

View file

@ -80,13 +80,13 @@ func syncTrees(ctx context.Context, treeSvc *tree.Service, cnrCli *containerClie
wellKnownTrees := [...]string{"version", "system"}
for _, id := range ids {
for _, tID := range wellKnownTrees {
err = treeSvc.Synchronize(ctx, id, tID)
for i := range wellKnownTrees {
err = treeSvc.SynchronizeTree(ctx, id, wellKnownTrees[i])
if err != nil && !errors.Is(err, tree.ErrNotInContainer) {
log.Warn(
"tree synchronization failed",
zap.Stringer("cid", id),
zap.String("tree_id", tID),
zap.String("tree_id", wellKnownTrees[i]),
zap.Error(err),
)
}