Skip to content

Commit a11de9d

Browse files
author
HuangYi
committed
Problem: code cleanup not backported (backport: #1215)
1 parent 07b5c1a commit a11de9d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

memiavl/db.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
const (
2121
DefaultSnapshotInterval = 1000
2222
LockFileName = "LOCK"
23+
TmpSuffix = "-tmp"
2324
)
2425

2526
var errReadOnly = errors.New("db is read-only")
@@ -259,7 +260,7 @@ func removeTmpDirs(rootDir string) error {
259260
}
260261

261262
for _, entry := range entries {
262-
if !entry.IsDir() || !strings.HasSuffix(entry.Name(), "-tmp") {
263+
if !entry.IsDir() || !strings.HasSuffix(entry.Name(), TmpSuffix) {
263264
continue
264265
}
265266

@@ -628,7 +629,7 @@ func (db *DB) RewriteSnapshot() error {
628629
}
629630

630631
snapshotDir := snapshotName(db.lastCommitInfo.Version)
631-
tmpDir := snapshotDir + "-tmp"
632+
tmpDir := snapshotDir + TmpSuffix
632633
path := filepath.Join(db.dir, tmpDir)
633634
if err := db.MultiTree.WriteSnapshot(path); err != nil {
634635
return errors.Join(err, os.RemoveAll(path))
@@ -835,7 +836,7 @@ func currentPath(root string) string {
835836
}
836837

837838
func currentTmpPath(root string) string {
838-
return filepath.Join(root, "current-tmp")
839+
return currentPath(root) + TmpSuffix
839840
}
840841

841842
func currentVersion(root string) (int64, error) {
@@ -981,7 +982,7 @@ func traverseSnapshots(dir string, ascending bool, callback func(int64) (bool, e
981982

982983
// atomicRemoveDir is equavalent to `mv snapshot snapshot-tmp && rm -r snapshot-tmp`
983984
func atomicRemoveDir(path string) error {
984-
tmpPath := path + "-tmp"
985+
tmpPath := path + TmpSuffix
985986
if err := os.Rename(path, tmpPath); err != nil {
986987
return err
987988
}

memiavl/db_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestRemoveSnapshotDir(t *testing.T) {
4545
defer os.RemoveAll(dbDir)
4646

4747
snapshotDir := filepath.Join(dbDir, snapshotName(0))
48-
tmpDir := snapshotDir + "-tmp"
48+
tmpDir := snapshotDir + TmpSuffix
4949
if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
5050
t.Fatalf("Failed to create dummy snapshot directory: %v", err)
5151
}

memiavl/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func Import(
2525
return snapshottypes.SnapshotItem{}, fmt.Errorf("version overflows uint32: %d", height)
2626
}
2727
snapshotDir := snapshotName(int64(height))
28-
tmpDir := snapshotDir + "-tmp"
28+
tmpDir := snapshotDir + TmpSuffix
2929

3030
var fileLock FileLock
3131
fileLock, err = LockFile(filepath.Join(dir, LockFileName))

0 commit comments

Comments
 (0)