53
53
errInvalidBlockRanges = "compactor block range periods should be divisible by the previous one, but %s is not divisible by %s"
54
54
RingOp = ring .NewOp ([]ring.InstanceState {ring .ACTIVE }, nil )
55
55
56
- supportedShardingStrategies = []string {util .ShardingStrategyDefault , util .ShardingStrategyShuffle }
57
- errInvalidShardingStrategy = errors .New ("invalid sharding strategy" )
58
- errInvalidTenantShardSize = errors .New ("invalid tenant shard size, the value must be greater than 0" )
56
+ supportedShardingStrategies = []string {util .ShardingStrategyDefault , util .ShardingStrategyShuffle }
57
+ errInvalidShardingStrategy = errors .New ("invalid sharding strategy" )
58
+ errInvalidTenantShardSize = errors .New ("invalid tenant shard size, the value must be greater than 0" )
59
+ supportedCompactionStrategies = []string {util .CompactionStrategyDefault , util .CompactionStrategyPartitioning }
60
+ errInvalidCompactionStrategy = errors .New ("invalid compaction strategy" )
61
+ errInvalidCompactionStrategyPartitioning = errors .New ("compaction strategy partitioning can only be enabled when shuffle sharding is enabled" )
59
62
60
63
DefaultBlocksGrouperFactory = func (ctx context.Context , cfg Config , bkt objstore.InstrumentedBucket , logger log.Logger , blocksMarkedForNoCompaction prometheus.Counter , _ prometheus.Counter , _ prometheus.Counter , syncerMetrics * compact.SyncerMetrics , compactorMetrics * compactorMetrics , _ * ring.Ring , _ * ring.Lifecycler , _ Limits , _ string , _ * compact.GatherNoCompactionMarkFilter ) compact.Grouper {
61
64
return compact .NewDefaultGrouperWithMetrics (
@@ -77,29 +80,33 @@ var (
77
80
}
78
81
79
82
ShuffleShardingGrouperFactory = func (ctx context.Context , cfg Config , bkt objstore.InstrumentedBucket , logger log.Logger , blocksMarkedForNoCompaction prometheus.Counter , blockVisitMarkerReadFailed prometheus.Counter , blockVisitMarkerWriteFailed prometheus.Counter , syncerMetrics * compact.SyncerMetrics , compactorMetrics * compactorMetrics , ring * ring.Ring , ringLifecycle * ring.Lifecycler , limits Limits , userID string , noCompactionMarkFilter * compact.GatherNoCompactionMarkFilter ) compact.Grouper {
80
- return NewShuffleShardingGrouper (
81
- ctx ,
82
- logger ,
83
- bkt ,
84
- cfg .AcceptMalformedIndex ,
85
- true , // Enable vertical compaction
86
- blocksMarkedForNoCompaction ,
87
- metadata .NoneFunc ,
88
- syncerMetrics ,
89
- compactorMetrics ,
90
- cfg ,
91
- ring ,
92
- ringLifecycle .Addr ,
93
- ringLifecycle .ID ,
94
- limits ,
95
- userID ,
96
- cfg .BlockFilesConcurrency ,
97
- cfg .BlocksFetchConcurrency ,
98
- cfg .CompactionConcurrency ,
99
- cfg .BlockVisitMarkerTimeout ,
100
- blockVisitMarkerReadFailed ,
101
- blockVisitMarkerWriteFailed ,
102
- noCompactionMarkFilter .NoCompactMarkedBlocks )
83
+ if cfg .CompactionStrategy == util .CompactionStrategyPartitioning {
84
+ return NewPartitionCompactionGrouper (ctx , logger , bkt )
85
+ } else {
86
+ return NewShuffleShardingGrouper (
87
+ ctx ,
88
+ logger ,
89
+ bkt ,
90
+ cfg .AcceptMalformedIndex ,
91
+ true , // Enable vertical compaction
92
+ blocksMarkedForNoCompaction ,
93
+ metadata .NoneFunc ,
94
+ syncerMetrics ,
95
+ compactorMetrics ,
96
+ cfg ,
97
+ ring ,
98
+ ringLifecycle .Addr ,
99
+ ringLifecycle .ID ,
100
+ limits ,
101
+ userID ,
102
+ cfg .BlockFilesConcurrency ,
103
+ cfg .BlocksFetchConcurrency ,
104
+ cfg .CompactionConcurrency ,
105
+ cfg .BlockVisitMarkerTimeout ,
106
+ blockVisitMarkerReadFailed ,
107
+ blockVisitMarkerWriteFailed ,
108
+ noCompactionMarkFilter .NoCompactMarkedBlocks )
109
+ }
103
110
}
104
111
105
112
DefaultBlocksCompactorFactory = func (ctx context.Context , cfg Config , logger log.Logger , reg prometheus.Registerer ) (compact.Compactor , PlannerFactory , error ) {
@@ -123,7 +130,11 @@ var (
123
130
124
131
plannerFactory := func (ctx context.Context , bkt objstore.InstrumentedBucket , logger log.Logger , cfg Config , noCompactionMarkFilter * compact.GatherNoCompactionMarkFilter , ringLifecycle * ring.Lifecycler , userID string , blockVisitMarkerReadFailed prometheus.Counter , blockVisitMarkerWriteFailed prometheus.Counter , compactorMetrics * compactorMetrics ) compact.Planner {
125
132
126
- return NewShuffleShardingPlanner (ctx , bkt , logger , cfg .BlockRanges .ToMilliseconds (), noCompactionMarkFilter .NoCompactMarkedBlocks , ringLifecycle .ID , cfg .BlockVisitMarkerTimeout , cfg .BlockVisitMarkerFileUpdateInterval , blockVisitMarkerReadFailed , blockVisitMarkerWriteFailed )
133
+ if cfg .CompactionStrategy == util .CompactionStrategyPartitioning {
134
+ return NewPartitionCompactionPlanner (ctx , bkt , logger )
135
+ } else {
136
+ return NewShuffleShardingPlanner (ctx , bkt , logger , cfg .BlockRanges .ToMilliseconds (), noCompactionMarkFilter .NoCompactMarkedBlocks , ringLifecycle .ID , cfg .BlockVisitMarkerTimeout , cfg .BlockVisitMarkerFileUpdateInterval , blockVisitMarkerReadFailed , blockVisitMarkerWriteFailed )
137
+ }
127
138
}
128
139
return compactor , plannerFactory , nil
129
140
}
@@ -202,6 +213,9 @@ type Config struct {
202
213
ShardingStrategy string `yaml:"sharding_strategy"`
203
214
ShardingRing RingConfig `yaml:"sharding_ring"`
204
215
216
+ // Compaction mode.
217
+ CompactionStrategy string `yaml:"compaction_mode"`
218
+
205
219
// No need to add options to customize the retry backoff,
206
220
// given the defaults should be fine, but allow to override
207
221
// it in tests.
@@ -244,6 +258,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
244
258
f .IntVar (& cfg .CleanupConcurrency , "compactor.cleanup-concurrency" , 20 , "Max number of tenants for which blocks cleanup and maintenance should run concurrently." )
245
259
f .BoolVar (& cfg .ShardingEnabled , "compactor.sharding-enabled" , false , "Shard tenants across multiple compactor instances. Sharding is required if you run multiple compactor instances, in order to coordinate compactions and avoid race conditions leading to the same tenant blocks simultaneously compacted by different instances." )
246
260
f .StringVar (& cfg .ShardingStrategy , "compactor.sharding-strategy" , util .ShardingStrategyDefault , fmt .Sprintf ("The sharding strategy to use. Supported values are: %s." , strings .Join (supportedShardingStrategies , ", " )))
261
+ f .StringVar (& cfg .CompactionStrategy , "compactor.compaction-mode" , util .CompactionStrategyDefault , fmt .Sprintf ("The compaction strategy to use. Supported values are: %s." , strings .Join (supportedCompactionStrategies , ", " )))
247
262
f .DurationVar (& cfg .DeletionDelay , "compactor.deletion-delay" , 12 * time .Hour , "Time before a block marked for deletion is deleted from bucket. " +
248
263
"If not 0, blocks will be marked for deletion and compactor component will permanently delete blocks marked for deletion from the bucket. " +
249
264
"If 0, blocks will be deleted straight away. Note that deleting blocks immediately can cause query failures." )
@@ -290,6 +305,15 @@ func (cfg *Config) Validate(limits validation.Limits) error {
290
305
}
291
306
}
292
307
308
+ // Make sure a valid compaction mode is being used
309
+ if ! util .StringsContain (supportedCompactionStrategies , cfg .CompactionStrategy ) {
310
+ return errInvalidCompactionStrategy
311
+ }
312
+
313
+ if ! cfg .ShardingEnabled && cfg .CompactionStrategy == util .CompactionStrategyPartitioning {
314
+ return errInvalidCompactionStrategyPartitioning
315
+ }
316
+
293
317
return nil
294
318
}
295
319
0 commit comments