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.