diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e160bdf966..8e05c6721a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,7 @@ * [BUGFIX] Ruler: Fixed leaking notifiers after users are removed #4718 * [BUGFIX] Distributor: Fix a memory leak in distributor due to the cluster label. #4739 * [BUGFIX] Memberlist: Avoid clock skew by limiting the timestamp accepted on gossip. #4750 - +* [BUGFIX] Compactor: skip compaction if there is only 1 block available for shuffle-sharding compactor. #4756 ## 1.11.0 2021-11-25 diff --git a/pkg/compactor/shuffle_sharding_planner.go b/pkg/compactor/shuffle_sharding_planner.go index d9e99ff0d35..4c38ff59823 100644 --- a/pkg/compactor/shuffle_sharding_planner.go +++ b/pkg/compactor/shuffle_sharding_planner.go @@ -46,5 +46,9 @@ func (p *ShuffleShardingPlanner) Plan(_ context.Context, metasByMinTime []*metad resultMetas = append(resultMetas, b) } + if len(resultMetas) < 2 { + return nil, nil + } + return resultMetas, nil } diff --git a/pkg/compactor/shuffle_sharding_planner_test.go b/pkg/compactor/shuffle_sharding_planner_test.go index 9a719a5abec..8dbf1c9de44 100644 --- a/pkg/compactor/shuffle_sharding_planner_test.go +++ b/pkg/compactor/shuffle_sharding_planner_test.go @@ -16,6 +16,7 @@ import ( func TestShuffleShardingPlanner_Plan(t *testing.T) { block1ulid := ulid.MustNew(1, nil) block2ulid := ulid.MustNew(2, nil) + block3ulid := ulid.MustNew(3, nil) tests := map[string]struct { ranges []int64 @@ -137,6 +138,13 @@ func TestShuffleShardingPlanner_Plan(t *testing.T) { MaxTime: 2 * time.Hour.Milliseconds(), }, }, + { + BlockMeta: tsdb.BlockMeta{ + ULID: block3ulid, + MinTime: 1 * time.Hour.Milliseconds(), + MaxTime: 2 * time.Hour.Milliseconds(), + }, + }, }, expected: []*metadata.Meta{ { @@ -146,7 +154,35 @@ func TestShuffleShardingPlanner_Plan(t *testing.T) { MaxTime: 2 * time.Hour.Milliseconds(), }, }, + { + BlockMeta: tsdb.BlockMeta{ + ULID: block3ulid, + MinTime: 1 * time.Hour.Milliseconds(), + MaxTime: 2 * time.Hour.Milliseconds(), + }, + }, + }, + }, + "test should not compact if there is only 1 compactable block": { + ranges: []int64{2 * time.Hour.Milliseconds()}, + noCompactBlocks: map[ulid.ULID]*metadata.NoCompactMark{block1ulid: {}}, + blocks: []*metadata.Meta{ + { + BlockMeta: tsdb.BlockMeta{ + ULID: block1ulid, + MinTime: 1 * time.Hour.Milliseconds(), + MaxTime: 2 * time.Hour.Milliseconds(), + }, + }, + { + BlockMeta: tsdb.BlockMeta{ + ULID: block2ulid, + MinTime: 1 * time.Hour.Milliseconds(), + MaxTime: 2 * time.Hour.Milliseconds(), + }, + }, }, + expected: []*metadata.Meta{}, }, }