Skip to content

Commit 602dc3a

Browse files
refactor: extract tempdb prefix to const
1 parent 6c4970a commit 602dc3a

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

extension/storage/filestorage/client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const (
2525
directoryKey = "directory"
2626
tempDirectoryKey = "tempDirectory"
2727

28-
oneMiB = 1048576
28+
tempDbPrefix = "tempdb"
29+
oneMiB = 1048576
2930
)
3031

3132
type fileStorageClient struct {
@@ -156,7 +157,7 @@ func (c *fileStorageClient) Compact(compactionDirectory string, timeout time.Dur
156157
var compactedDb *bbolt.DB
157158

158159
// create temporary file in compactionDirectory
159-
file, err = os.CreateTemp(compactionDirectory, "tempdb")
160+
file, err = os.CreateTemp(compactionDirectory, tempDbPrefix)
160161
if err != nil {
161162
return err
162163
}
@@ -349,7 +350,7 @@ func moveFileWithFallback(src string, dest string) error {
349350

350351
// cleanup left compaction temporary files from previous killed process
351352
func (c *fileStorageClient) cleanup(compactionDirectory string) error {
352-
pattern := filepath.Join(compactionDirectory, "tempdb*")
353+
pattern := filepath.Join(compactionDirectory, fmt.Sprintf("%s*", tempDbPrefix))
353354
contents, err := filepath.Glob(pattern)
354355
if err != nil {
355356
return err

extension/storage/filestorage/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ func TestClientConcurrentCompaction(t *testing.T) {
407407
func TestClientCleanupOnStart(t *testing.T) {
408408
tempDir := t.TempDir()
409409
dbFile := filepath.Join(tempDir, "my_db")
410-
temp, _ := os.CreateTemp(tempDir, "tempdb")
410+
temp, _ := os.CreateTemp(tempDir, tempDbPrefix)
411411
// simulate ongoing compaction in another instance
412-
tempLocked, _ := os.CreateTemp(tempDir, "tempdb")
412+
tempLocked, _ := os.CreateTemp(tempDir, tempDbPrefix)
413413
temp.Close()
414414

415415
client, err := newClient(zap.NewNop(), dbFile, time.Second, &CompactionConfig{

extension/storage/filestorage/extension_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ func TestCleanupOnStart(t *testing.T) {
454454

455455
tempDir := t.TempDir()
456456
// simulate left temporary compaction file from killed process
457-
temp, _ := os.CreateTemp(tempDir, "tempdb")
457+
temp, _ := os.CreateTemp(tempDir, tempDbPrefix)
458458
temp.Close()
459459

460460
f := NewFactory()

0 commit comments

Comments
 (0)