From fbe960f2c1ad9d6f5fe2f267d2559bf7ecfab6df Mon Sep 17 00:00:00 2001 From: Nguyen Le Vu Long Date: Sat, 9 Jan 2021 16:02:26 +0700 Subject: [PATCH] fix: remove pre-2.21 tmp blocks on start (#8353) * fix: remove pre-2.21 tmp blocks on start Signed-off-by: Nguyen Le Vu Long * fix: commenting Signed-off-by: Nguyen Le Vu Long --- tsdb/db.go | 4 +++- tsdb/db_test.go | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tsdb/db.go b/tsdb/db.go index 9c15dd4c25..3ddf73d21a 100644 --- a/tsdb/db.go +++ b/tsdb/db.go @@ -56,6 +56,8 @@ const ( // about removing those too on start to save space. Currently only blocks tmp dirs are removed. tmpForDeletionBlockDirSuffix = ".tmp-for-deletion" tmpForCreationBlockDirSuffix = ".tmp-for-creation" + // Pre-2.21 tmp dir suffix, used in clean-up functions. + tmpLegacy = ".tmp" ) var ( @@ -1570,7 +1572,7 @@ func isTmpBlockDir(fi os.FileInfo) bool { fn := fi.Name() ext := filepath.Ext(fn) - if ext == tmpForDeletionBlockDirSuffix || ext == tmpForCreationBlockDirSuffix { + if ext == tmpForDeletionBlockDirSuffix || ext == tmpForCreationBlockDirSuffix || ext == tmpLegacy { if _, err := ulid.ParseStrict(fn[:len(fn)-len(ext)]); err == nil { return true } diff --git a/tsdb/db_test.go b/tsdb/db_test.go index 6bedae9f35..e00f0a8f85 100644 --- a/tsdb/db_test.go +++ b/tsdb/db_test.go @@ -2795,15 +2795,20 @@ func TestOpen_VariousBlockStates(t *testing.T) { require.NoError(t, os.Remove(filepath.Join(dir, metaFilename))) } { - // Tmp blocks during creation & deletion; those should be removed on start. + // Tmp blocks during creation; those should be removed on start. dir := createBlock(t, tmpDir, genSeries(10, 2, 30, 40)) require.NoError(t, fileutil.Replace(dir, dir+tmpForCreationBlockDirSuffix)) expectedRemovedDirs[dir+tmpForCreationBlockDirSuffix] = struct{}{} - // Tmp blocks during creation & deletion; those should be removed on start. + // Tmp blocks during deletion; those should be removed on start. dir = createBlock(t, tmpDir, genSeries(10, 2, 40, 50)) require.NoError(t, fileutil.Replace(dir, dir+tmpForDeletionBlockDirSuffix)) expectedRemovedDirs[dir+tmpForDeletionBlockDirSuffix] = struct{}{} + + // Pre-2.21 tmp blocks; those should be removed on start. + dir = createBlock(t, tmpDir, genSeries(10, 2, 50, 60)) + require.NoError(t, fileutil.Replace(dir, dir+tmpLegacy)) + expectedRemovedDirs[dir+tmpLegacy] = struct{}{} } { // One ok block; but two should be replaced.