[#1355] metabase: Upgrade improvements
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 1m16s
DCO action / DCO (pull_request) Successful in 1m31s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m5s
Tests and linters / Run gofumpt (pull_request) Successful in 1m59s
Build / Build Components (pull_request) Successful in 2m13s
Tests and linters / gopls check (pull_request) Successful in 2m31s
Tests and linters / Staticcheck (pull_request) Successful in 2m38s
Tests and linters / Lint (pull_request) Successful in 3m15s
Tests and linters / Tests (pull_request) Successful in 3m32s
Tests and linters / Tests with -race (pull_request) Successful in 3m39s
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 1m16s
DCO action / DCO (pull_request) Successful in 1m31s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m5s
Tests and linters / Run gofumpt (pull_request) Successful in 1m59s
Build / Build Components (pull_request) Successful in 2m13s
Tests and linters / gopls check (pull_request) Successful in 2m31s
Tests and linters / Staticcheck (pull_request) Successful in 2m38s
Tests and linters / Lint (pull_request) Successful in 3m15s
Tests and linters / Tests (pull_request) Successful in 3m32s
Tests and linters / Tests with -race (pull_request) Successful in 3m39s
Do not fail on same latest version to run compact on upgraded metabase. Use NoSync on compact. Log every batch on bucket delete stage. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
654d970fad
commit
4668efc0bf
1 changed files with 10 additions and 3 deletions
|
@ -27,6 +27,10 @@ const (
|
|||
|
||||
var updates = map[uint64]func(ctx context.Context, db *bbolt.DB, log func(a ...any)) error{
|
||||
2: upgradeFromV2ToV3,
|
||||
3: func(_ context.Context, _ *bbolt.DB, log func(a ...any)) error {
|
||||
log("metabase already upgraded")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func Upgrade(ctx context.Context, path string, compact bool, log func(a ...any)) error {
|
||||
|
@ -86,6 +90,7 @@ func compactDB(db *bbolt.DB) error {
|
|||
}
|
||||
dst, err := bbolt.Open(tmpFileName, f.Mode(), &bbolt.Options{
|
||||
Timeout: 100 * time.Millisecond,
|
||||
NoSync: true,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't open new metabase to compact: %w", err)
|
||||
|
@ -93,6 +98,9 @@ func compactDB(db *bbolt.DB) error {
|
|||
if err := bbolt.Compact(dst, db, compactMaxTxSize); err != nil {
|
||||
return fmt.Errorf("compact metabase: %w", errors.Join(err, dst.Close(), os.Remove(tmpFileName)))
|
||||
}
|
||||
if err := dst.Sync(); err != nil {
|
||||
return fmt.Errorf("sync compacted metabase: %w", errors.Join(err, os.Remove(tmpFileName)))
|
||||
}
|
||||
if err := dst.Close(); err != nil {
|
||||
return fmt.Errorf("close compacted metabase: %w", errors.Join(err, os.Remove(tmpFileName)))
|
||||
}
|
||||
|
@ -369,8 +377,7 @@ func dropBucketsByPrefix(ctx context.Context, db *bbolt.DB, prefix []byte, log f
|
|||
log("deleting buckets completed with an error:", err)
|
||||
return err
|
||||
}
|
||||
if count += uint64(len(keys)); count%upgradeLogFrequency == 0 {
|
||||
count += uint64(len(keys))
|
||||
log("deleted", count, "buckets")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue