diff --git a/tsdb/db.go b/tsdb/db.go index 2ca6034a0..e181a8f20 100644 --- a/tsdb/db.go +++ b/tsdb/db.go @@ -2090,7 +2090,8 @@ func isBlockDir(fi fs.DirEntry) bool { return err == nil } -// isTmpDir returns true if the given file-info contains a block ULID or checkpoint prefix and a tmp extension. +// isTmpDir returns true if the given file-info contains a block ULID, a checkpoint prefix, +// or a chunk snapshot prefix and a tmp extension. func isTmpDir(fi fs.DirEntry) bool { if !fi.IsDir() { return false @@ -2102,6 +2103,9 @@ func isTmpDir(fi fs.DirEntry) bool { if strings.HasPrefix(fn, "checkpoint.") { return true } + if strings.HasPrefix(fn, chunkSnapshotPrefix) { + return true + } 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 772fcf9d1..6da774a35 100644 --- a/tsdb/db_test.go +++ b/tsdb/db_test.go @@ -3146,6 +3146,9 @@ func TestOpen_VariousBlockStates(t *testing.T) { tmpCheckpointDir := path.Join(tmpDir, "wal/checkpoint.00000001.tmp") err := os.MkdirAll(tmpCheckpointDir, 0o777) require.NoError(t, err) + tmpChunkSnapshotDir := path.Join(tmpDir, chunkSnapshotPrefix+"0000.00000001.tmp") + err = os.MkdirAll(tmpChunkSnapshotDir, 0o777) + require.NoError(t, err) opts := DefaultOptions() opts.RetentionDuration = 0 @@ -3179,6 +3182,8 @@ func TestOpen_VariousBlockStates(t *testing.T) { require.Equal(t, len(expectedIgnoredDirs), ignored) _, err = os.Stat(tmpCheckpointDir) require.True(t, os.IsNotExist(err)) + _, err = os.Stat(tmpChunkSnapshotDir) + require.True(t, os.IsNotExist(err)) } func TestOneCheckpointPerCompactCall(t *testing.T) {