From 4668efc0bfdfac3750307d0863effb991baa1a4b Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Fri, 6 Sep 2024 11:17:02 +0300 Subject: [PATCH] [#1355] metabase: Upgrade improvements 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 --- pkg/local_object_storage/metabase/upgrade.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/local_object_storage/metabase/upgrade.go b/pkg/local_object_storage/metabase/upgrade.go index e9abd746c..f677dcf8e 100644 --- a/pkg/local_object_storage/metabase/upgrade.go +++ b/pkg/local_object_storage/metabase/upgrade.go @@ -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 { - log("deleted", count, "buckets") - } + count += uint64(len(keys)) + log("deleted", count, "buckets") } }