mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Cleanup temporary chunk snapshot dirs
Simlar to cleanup of WAL files on startup, cleanup temporary chunk_snapshot dirs. This prevents storage space leaks due to terminated snapshots on shutdown. Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
parent
bb90379163
commit
8d38d59fc5
|
@ -2090,7 +2090,8 @@ func isBlockDir(fi fs.DirEntry) bool {
|
||||||
return err == nil
|
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 {
|
func isTmpDir(fi fs.DirEntry) bool {
|
||||||
if !fi.IsDir() {
|
if !fi.IsDir() {
|
||||||
return false
|
return false
|
||||||
|
@ -2102,6 +2103,9 @@ func isTmpDir(fi fs.DirEntry) bool {
|
||||||
if strings.HasPrefix(fn, "checkpoint.") {
|
if strings.HasPrefix(fn, "checkpoint.") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(fn, chunkSnapshotPrefix) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if _, err := ulid.ParseStrict(fn[:len(fn)-len(ext)]); err == nil {
|
if _, err := ulid.ParseStrict(fn[:len(fn)-len(ext)]); err == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -3146,6 +3146,9 @@ func TestOpen_VariousBlockStates(t *testing.T) {
|
||||||
tmpCheckpointDir := path.Join(tmpDir, "wal/checkpoint.00000001.tmp")
|
tmpCheckpointDir := path.Join(tmpDir, "wal/checkpoint.00000001.tmp")
|
||||||
err := os.MkdirAll(tmpCheckpointDir, 0o777)
|
err := os.MkdirAll(tmpCheckpointDir, 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
tmpChunkSnapshotDir := path.Join(tmpDir, chunkSnapshotPrefix+"0000.00000001.tmp")
|
||||||
|
err = os.MkdirAll(tmpChunkSnapshotDir, 0o777)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
opts := DefaultOptions()
|
opts := DefaultOptions()
|
||||||
opts.RetentionDuration = 0
|
opts.RetentionDuration = 0
|
||||||
|
@ -3179,6 +3182,8 @@ func TestOpen_VariousBlockStates(t *testing.T) {
|
||||||
require.Equal(t, len(expectedIgnoredDirs), ignored)
|
require.Equal(t, len(expectedIgnoredDirs), ignored)
|
||||||
_, err = os.Stat(tmpCheckpointDir)
|
_, err = os.Stat(tmpCheckpointDir)
|
||||||
require.True(t, os.IsNotExist(err))
|
require.True(t, os.IsNotExist(err))
|
||||||
|
_, err = os.Stat(tmpChunkSnapshotDir)
|
||||||
|
require.True(t, os.IsNotExist(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOneCheckpointPerCompactCall(t *testing.T) {
|
func TestOneCheckpointPerCompactCall(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue