From 654d970fadfe7eb47a5ce566be81ad15119df6a0 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Fri, 6 Sep 2024 11:16:12 +0300 Subject: [PATCH] [#1355] adm: Run `metabase upgrade` concurrently Signed-off-by: Dmitrii Stepanov --- .../internal/modules/metabase/upgrade.go | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/metabase/upgrade.go b/cmd/frostfs-adm/internal/modules/metabase/upgrade.go index 83e085df..96cb62f1 100644 --- a/cmd/frostfs-adm/internal/modules/metabase/upgrade.go +++ b/cmd/frostfs-adm/internal/modules/metabase/upgrade.go @@ -3,6 +3,7 @@ package metabase import ( "errors" "fmt" + "sync" "time" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags" @@ -11,6 +12,7 @@ import ( shardconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" "github.com/spf13/cobra" + "golang.org/x/sync/errgroup" ) const ( @@ -57,17 +59,28 @@ func upgrade(cmd *cobra.Command, _ []string) error { cmd.Println(i+1, ":", path) } result := make(map[string]bool) + var resultGuard sync.Mutex + eg, ctx := errgroup.WithContext(cmd.Context()) for _, path := range paths { - cmd.Println("upgrading metabase", path, "...") - if err := meta.Upgrade(cmd.Context(), path, !noCompact, func(a ...any) { - cmd.Println(append([]any{time.Now().Format(time.RFC3339), ":", path, ":"}, a...)...) - }); err != nil { - result[path] = false - cmd.Println("error: failed to upgrade metabase", path, ":", err) - } else { - result[path] = true - cmd.Println("metabase", path, "upgraded successfully") - } + eg.Go(func() error { + var success bool + cmd.Println("upgrading metabase", path, "...") + if err := meta.Upgrade(ctx, path, !noCompact, func(a ...any) { + cmd.Println(append([]any{time.Now().Format(time.RFC3339), ":", path, ":"}, a...)...) + }); err != nil { + cmd.Println("error: failed to upgrade metabase", path, ":", err) + } else { + success = true + cmd.Println("metabase", path, "upgraded successfully") + } + resultGuard.Lock() + result[path] = success + resultGuard.Unlock() + return nil + }) + } + if err := eg.Wait(); err != nil { + return err } for mb, ok := range result { if ok {