From 602dc3a970421f5a6238e285b1471de006de7fcd Mon Sep 17 00:00:00 2001 From: Pedro Andres Blanco Date: Mon, 13 May 2024 10:14:45 +0200 Subject: [PATCH] refactor: extract tempdb prefix to const --- extension/storage/filestorage/client.go | 7 ++++--- extension/storage/filestorage/client_test.go | 4 ++-- extension/storage/filestorage/extension_test.go | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/extension/storage/filestorage/client.go b/extension/storage/filestorage/client.go index 1496ca14d464..752f99b876a7 100644 --- a/extension/storage/filestorage/client.go +++ b/extension/storage/filestorage/client.go @@ -25,7 +25,8 @@ const ( directoryKey = "directory" tempDirectoryKey = "tempDirectory" - oneMiB = 1048576 + tempDbPrefix = "tempdb" + oneMiB = 1048576 ) type fileStorageClient struct { @@ -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 } @@ -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 diff --git a/extension/storage/filestorage/client_test.go b/extension/storage/filestorage/client_test.go index 16b47f8cbfd0..4e7c91d5ecc3 100644 --- a/extension/storage/filestorage/client_test.go +++ b/extension/storage/filestorage/client_test.go @@ -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{ diff --git a/extension/storage/filestorage/extension_test.go b/extension/storage/filestorage/extension_test.go index cd4bf16f77fb..ca09d4a307c6 100644 --- a/extension/storage/filestorage/extension_test.go +++ b/extension/storage/filestorage/extension_test.go @@ -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()