Skip to content

Commit a6a063e

Browse files
committed
skip compaction if there is only 1 block available for shuffle-sharding compactor
Signed-off-by: Roy Chiang <[email protected]>
1 parent 5915bba commit a6a063e

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* [BUGFIX] Ruler: Fixed leaking notifiers after users are removed #4718
4545
* [BUGFIX] Distributor: Fix a memory leak in distributor due to the cluster label. #4739
4646
* [BUGFIX] Memberlist: Avoid clock skew by limiting the timestamp accepted on gossip. #4750
47-
47+
* [BUGFIX] Compactor: skip compaction if there is only 1 block available for shuffle-sharding compactor. #4756
4848

4949
## 1.11.0 2021-11-25
5050

pkg/compactor/shuffle_sharding_planner.go

+4
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@ func (p *ShuffleShardingPlanner) Plan(_ context.Context, metasByMinTime []*metad
4646
resultMetas = append(resultMetas, b)
4747
}
4848

49+
if len(resultMetas) < 2 {
50+
return nil, nil
51+
}
52+
4953
return resultMetas, nil
5054
}

pkg/compactor/shuffle_sharding_planner_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
func TestShuffleShardingPlanner_Plan(t *testing.T) {
1717
block1ulid := ulid.MustNew(1, nil)
1818
block2ulid := ulid.MustNew(2, nil)
19+
block3ulid := ulid.MustNew(3, nil)
1920

2021
tests := map[string]struct {
2122
ranges []int64
@@ -137,6 +138,13 @@ func TestShuffleShardingPlanner_Plan(t *testing.T) {
137138
MaxTime: 2 * time.Hour.Milliseconds(),
138139
},
139140
},
141+
{
142+
BlockMeta: tsdb.BlockMeta{
143+
ULID: block3ulid,
144+
MinTime: 1 * time.Hour.Milliseconds(),
145+
MaxTime: 2 * time.Hour.Milliseconds(),
146+
},
147+
},
140148
},
141149
expected: []*metadata.Meta{
142150
{
@@ -146,7 +154,35 @@ func TestShuffleShardingPlanner_Plan(t *testing.T) {
146154
MaxTime: 2 * time.Hour.Milliseconds(),
147155
},
148156
},
157+
{
158+
BlockMeta: tsdb.BlockMeta{
159+
ULID: block3ulid,
160+
MinTime: 1 * time.Hour.Milliseconds(),
161+
MaxTime: 2 * time.Hour.Milliseconds(),
162+
},
163+
},
164+
},
165+
},
166+
"test should not compact if there is only 1 compactable block": {
167+
ranges: []int64{2 * time.Hour.Milliseconds()},
168+
noCompactBlocks: map[ulid.ULID]*metadata.NoCompactMark{block1ulid: {}},
169+
blocks: []*metadata.Meta{
170+
{
171+
BlockMeta: tsdb.BlockMeta{
172+
ULID: block1ulid,
173+
MinTime: 1 * time.Hour.Milliseconds(),
174+
MaxTime: 2 * time.Hour.Milliseconds(),
175+
},
176+
},
177+
{
178+
BlockMeta: tsdb.BlockMeta{
179+
ULID: block2ulid,
180+
MinTime: 1 * time.Hour.Milliseconds(),
181+
MaxTime: 2 * time.Hour.Milliseconds(),
182+
},
183+
},
149184
},
185+
expected: []*metadata.Meta{},
150186
},
151187
}
152188

0 commit comments

Comments
 (0)