Metabase upgrade optimizations #1355
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 {
|
||||
log("deleted", count, "buckets")
|
||||
}
|
||||
count += uint64(len(keys))
|
||||
log("deleted", count, "buckets")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue
We can leave garbage in case of premature exit, do we handle this somehow?
It is a problem, because we can have no space and need to describe what to do.
No.
I dont want to do some delete by pattern to not to delete some manual created files.