Skip to content

Commit

Permalink
Problem: code cleanup not backported (backport: #1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Nov 14, 2023
1 parent 07b5c1a commit a11de9d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions memiavl/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
const (
DefaultSnapshotInterval = 1000
LockFileName = "LOCK"
TmpSuffix = "-tmp"
)

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

for _, entry := range entries {
if !entry.IsDir() || !strings.HasSuffix(entry.Name(), "-tmp") {
if !entry.IsDir() || !strings.HasSuffix(entry.Name(), TmpSuffix) {
continue
}

Expand Down Expand Up @@ -628,7 +629,7 @@ func (db *DB) RewriteSnapshot() error {
}

snapshotDir := snapshotName(db.lastCommitInfo.Version)
tmpDir := snapshotDir + "-tmp"
tmpDir := snapshotDir + TmpSuffix
path := filepath.Join(db.dir, tmpDir)
if err := db.MultiTree.WriteSnapshot(path); err != nil {
return errors.Join(err, os.RemoveAll(path))
Expand Down Expand Up @@ -835,7 +836,7 @@ func currentPath(root string) string {
}

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

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

// atomicRemoveDir is equavalent to `mv snapshot snapshot-tmp && rm -r snapshot-tmp`
func atomicRemoveDir(path string) error {
tmpPath := path + "-tmp"
tmpPath := path + TmpSuffix
if err := os.Rename(path, tmpPath); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion memiavl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestRemoveSnapshotDir(t *testing.T) {
defer os.RemoveAll(dbDir)

snapshotDir := filepath.Join(dbDir, snapshotName(0))
tmpDir := snapshotDir + "-tmp"
tmpDir := snapshotDir + TmpSuffix
if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
t.Fatalf("Failed to create dummy snapshot directory: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion memiavl/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Import(
return snapshottypes.SnapshotItem{}, fmt.Errorf("version overflows uint32: %d", height)
}
snapshotDir := snapshotName(int64(height))
tmpDir := snapshotDir + "-tmp"
tmpDir := snapshotDir + TmpSuffix

var fileLock FileLock
fileLock, err = LockFile(filepath.Join(dir, LockFileName))
Expand Down

0 comments on commit a11de9d

Please sign in to comment.