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 (
|
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,28 @@ 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 {
|
||||||
cmd.Println("upgrading metabase", path, "...")
|
eg.Go(func() error {
|
||||||
if err := meta.Upgrade(cmd.Context(), path, !noCompact, func(a ...any) {
|
var success bool
|
||||||
cmd.Println(append([]any{time.Now().Format(time.RFC3339), ":", path, ":"}, a...)...)
|
cmd.Println("upgrading metabase", path, "...")
|
||||||
}); err != nil {
|
if err := meta.Upgrade(ctx, path, !noCompact, func(a ...any) {
|
||||||
result[path] = false
|
cmd.Println(append([]any{time.Now().Format(time.RFC3339), ":", path, ":"}, a...)...)
|
||||||
cmd.Println("error: failed to upgrade metabase", path, ":", err)
|
}); err != nil {
|
||||||
} else {
|
cmd.Println("error: failed to upgrade metabase", path, ":", err)
|
||||||
result[path] = true
|
} else {
|
||||||
cmd.Println("metabase", path, "upgraded successfully")
|
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 {
|
for mb, ok := range result {
|
||||||
if ok {
|
if ok {
|
||||||
|
|
Loading…
Reference in a new issue