diff --git a/pkg/local_object_storage/metabase/upgrade.go b/pkg/local_object_storage/metabase/upgrade.go index e9abd746..f677dcf8 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") } }