Skip to content

Commit

Permalink
refactor: extract tempdb prefix to const
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres-varian committed May 13, 2024
1 parent 6c4970a commit 602dc3a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions extension/storage/filestorage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const (
directoryKey = "directory"
tempDirectoryKey = "tempDirectory"

oneMiB = 1048576
tempDbPrefix = "tempdb"
oneMiB = 1048576
)

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

// create temporary file in compactionDirectory
file, err = os.CreateTemp(compactionDirectory, "tempdb")
file, err = os.CreateTemp(compactionDirectory, tempDbPrefix)
if err != nil {
return err
}
Expand Down Expand Up @@ -349,7 +350,7 @@ func moveFileWithFallback(src string, dest string) error {

// cleanup left compaction temporary files from previous killed process
func (c *fileStorageClient) cleanup(compactionDirectory string) error {
pattern := filepath.Join(compactionDirectory, "tempdb*")
pattern := filepath.Join(compactionDirectory, fmt.Sprintf("%s*", tempDbPrefix))
contents, err := filepath.Glob(pattern)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions extension/storage/filestorage/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ func TestClientConcurrentCompaction(t *testing.T) {
func TestClientCleanupOnStart(t *testing.T) {
tempDir := t.TempDir()
dbFile := filepath.Join(tempDir, "my_db")
temp, _ := os.CreateTemp(tempDir, "tempdb")
temp, _ := os.CreateTemp(tempDir, tempDbPrefix)
// simulate ongoing compaction in another instance
tempLocked, _ := os.CreateTemp(tempDir, "tempdb")
tempLocked, _ := os.CreateTemp(tempDir, tempDbPrefix)
temp.Close()

client, err := newClient(zap.NewNop(), dbFile, time.Second, &CompactionConfig{
Expand Down
2 changes: 1 addition & 1 deletion extension/storage/filestorage/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func TestCleanupOnStart(t *testing.T) {

tempDir := t.TempDir()
// simulate left temporary compaction file from killed process
temp, _ := os.CreateTemp(tempDir, "tempdb")
temp, _ := os.CreateTemp(tempDir, tempDbPrefix)
temp.Close()

f := NewFactory()
Expand Down

0 comments on commit 602dc3a

Please sign in to comment.