Skip to content

Commit f1338dc

Browse files
pstibranyalvinlin123
authored andcommitted
Don't try to compact blocks marked for deletion. (cortexproject#4328)
* Don't try to compact blocks marked for deletion. * Update CHANGELOG.md Signed-off-by: Peter Štibraný <[email protected]> Signed-off-by: Alvin Lin <[email protected]>
1 parent 1c65203 commit f1338dc

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [CHANGE] Prevent path traversal attack from users able to control the HTTP header `X-Scope-OrgID`. #4375 (CVE-2021-36157)
1212
* Users only have control of the HTTP header when Cortex is not frontend by an auth proxy validating the tenant IDs
1313
* [CHANGE] Some files and directories created by Mimir components on local disk now have stricter permissions, and are only readable by owner, but not group or others. #4394
14+
* [CHANGE] Compactor: compactor will no longer try to compact blocks that are already marked for deletion. Previously compactor would consider blocks marked for deletion within `-compactor.deletion-delay / 2` period as eligible for compaction. #4328
1415
* [ENHANCEMENT] Add timeout for waiting on compactor to become ACTIVE in the ring. #4262
1516
* [ENHANCEMENT] Reduce memory used by streaming queries, particularly in ruler. #4341
1617
* [ENHANCEMENT] Ring: allow experimental configuration of disabling of heartbeat timeouts by setting the relevant configuration value to zero. Applies to the following: #4342

pkg/compactor/compactor.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,11 @@ func (c *Compactor) compactUser(ctx context.Context, userID string) error {
644644
deduplicateBlocksFilter := block.NewDeduplicateFilter()
645645

646646
// While fetching blocks, we filter out blocks that were marked for deletion by using IgnoreDeletionMarkFilter.
647-
// The delay of deleteDelay/2 is added to ensure we fetch blocks that are meant to be deleted but do not have a replacement yet.
647+
// No delay is used -- all blocks with deletion marker are ignored, and not considered for compaction.
648648
ignoreDeletionMarkFilter := block.NewIgnoreDeletionMarkFilter(
649649
ulogger,
650650
bucket,
651-
time.Duration(c.compactorCfg.DeletionDelay.Seconds()/2)*time.Second,
651+
0,
652652
c.compactorCfg.MetaSyncConcurrency)
653653

654654
fetcher, err := block.NewMetaFetcher(

pkg/compactor/compactor_test.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,12 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForDeletion(t *testing.T) {
581581
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ"}, nil)
582582
bucketClient.MockExists(path.Join("user-1", cortex_tsdb.TenantDeletionMarkPath), false, nil)
583583

584+
// Block that has just been marked for deletion. It will not be deleted just yet, and it also will not be compacted.
584585
bucketClient.MockGet("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
585586
bucketClient.MockGet("user-1/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json", mockDeletionMarkJSON("01DTVP434PA9VFXSW2JKB3392D", time.Now()), nil)
586587
bucketClient.MockGet("user-1/markers/01DTVP434PA9VFXSW2JKB3392D-deletion-mark.json", mockDeletionMarkJSON("01DTVP434PA9VFXSW2JKB3392D", time.Now()), nil)
587588

589+
// This block will be deleted by cleaner.
588590
bucketClient.MockGet("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", mockBlockMetaJSON("01DTW0ZCPDDNV4BV83Q2SV4QAZ"), nil)
589591
bucketClient.MockGet("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/deletion-mark.json", mockDeletionMarkJSON("01DTW0ZCPDDNV4BV83Q2SV4QAZ", time.Now().Add(-cfg.DeletionDelay)), nil)
590592
bucketClient.MockGet("user-1/markers/01DTW0ZCPDDNV4BV83Q2SV4QAZ-deletion-mark.json", mockDeletionMarkJSON("01DTW0ZCPDDNV4BV83Q2SV4QAZ", time.Now().Add(-cfg.DeletionDelay)), nil)
@@ -608,12 +610,6 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForDeletion(t *testing.T) {
608610

609611
c, _, tsdbPlanner, logs, registry := prepare(t, cfg, bucketClient)
610612

611-
// Mock the planner as if there's no compaction to do,
612-
// in order to simplify tests (all in all, we just want to
613-
// test our logic and not TSDB compactor which we expect to
614-
// be already tested).
615-
tsdbPlanner.On("Plan", mock.Anything, mock.Anything).Return([]*metadata.Meta{}, nil)
616-
617613
require.NoError(t, services.StartAndAwaitRunning(context.Background(), c))
618614

619615
// Wait until a run has completed.
@@ -623,8 +619,8 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForDeletion(t *testing.T) {
623619

624620
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), c))
625621

626-
// Only one user's block is compacted.
627-
tsdbPlanner.AssertNumberOfCalls(t, "Plan", 1)
622+
// Since both blocks are marked for deletion, none of them are going to be compacted.
623+
tsdbPlanner.AssertNumberOfCalls(t, "Plan", 0)
628624

629625
assert.ElementsMatch(t, []string{
630626
`level=info component=cleaner msg="started blocks cleanup and maintenance"`,

0 commit comments

Comments
 (0)