forked from TrueCloudLab/frostfs-node
[#1355] adm: Run metabase upgrade
concurrently
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
d3b209c8e1
commit
654d970fad
1 changed files with 23 additions and 10 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue