[#9999] adm: Run metabase upgrade concurrently

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-09-06 11:16:12 +03:00
parent 273980cfb9
commit 1e0cce3aa9

View file

@ -3,6 +3,7 @@ package metabase
import ( import (
"errors" "errors"
"fmt" "fmt"
"sync"
"time" "time"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags" "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" 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" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
) )
const ( const (
@ -57,17 +59,29 @@ func upgrade(cmd *cobra.Command, _ []string) error {
cmd.Println(i+1, ":", path) cmd.Println(i+1, ":", path)
} }
result := make(map[string]bool) result := make(map[string]bool)
var resultGuard sync.Mutex
eg, ctx := errgroup.WithContext(cmd.Context())
for _, path := range paths { for _, path := range paths {
path := path
eg.Go(func() error {
var success bool
cmd.Println("upgrading metabase", path, "...") cmd.Println("upgrading metabase", path, "...")
if err := meta.Upgrade(cmd.Context(), path, !noCompact, func(a ...any) { if err := meta.Upgrade(ctx, path, !noCompact, func(a ...any) {
cmd.Println(append([]any{time.Now().Format(time.RFC3339), ":", path, ":"}, a...)...) cmd.Println(append([]any{time.Now().Format(time.RFC3339), ":", path, ":"}, a...)...)
}); err != nil { }); err != nil {
result[path] = false
cmd.Println("error: failed to upgrade metabase", path, ":", err) cmd.Println("error: failed to upgrade metabase", path, ":", err)
} else { } else {
result[path] = true success = true
cmd.Println("metabase", path, "upgraded successfully") 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 { for mb, ok := range result {
if ok { if ok {