Skip to content

Commit d541cbe

Browse files
jihoonsonjon-wei
authored andcommitted
Support both IndexTuningConfig and ParallelIndexTuningConfig for compaction task (#9222)
* Support both IndexTuningConfig and ParallelIndexTuningConfig for compaction task * tuningConfig module * fix tests
1 parent 0b0056b commit d541cbe

File tree

11 files changed

+377
-8
lines changed

11 files changed

+377
-8
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.druid.guice;
21+
22+
import com.fasterxml.jackson.databind.Module;
23+
import com.fasterxml.jackson.databind.jsontype.NamedType;
24+
import com.fasterxml.jackson.databind.module.SimpleModule;
25+
import com.google.common.collect.ImmutableList;
26+
import com.google.inject.Binder;
27+
import org.apache.druid.indexing.common.task.IndexTask.IndexTuningConfig;
28+
import org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexTuningConfig;
29+
import org.apache.druid.initialization.DruidModule;
30+
31+
import java.util.List;
32+
33+
public class IndexingServiceTuningConfigModule implements DruidModule
34+
{
35+
@Override
36+
public List<? extends Module> getJacksonModules()
37+
{
38+
return ImmutableList.of(
39+
new SimpleModule(IndexingServiceTuningConfigModule.class.getSimpleName())
40+
.registerSubtypes(
41+
new NamedType(IndexTuningConfig.class, "index"),
42+
new NamedType(ParallelIndexTuningConfig.class, "index_parallel")
43+
)
44+
);
45+
}
46+
47+
@Override
48+
public void configure(Binder binder)
49+
{
50+
}
51+
}

indexing-service/src/main/java/org/apache/druid/indexing/common/task/CompactionTask.java

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.apache.druid.indexing.common.actions.RetrieveUsedSegmentsAction;
5252
import org.apache.druid.indexing.common.actions.TaskActionClient;
5353
import org.apache.druid.indexing.common.stats.RowIngestionMetersFactory;
54+
import org.apache.druid.indexing.common.task.IndexTask.IndexTuningConfig;
5455
import org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexIOConfig;
5556
import org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexIngestionSpec;
5657
import org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexSupervisorTask;
@@ -74,6 +75,7 @@
7475
import org.apache.druid.segment.column.ColumnHolder;
7576
import org.apache.druid.segment.column.ValueType;
7677
import org.apache.druid.segment.indexing.DataSchema;
78+
import org.apache.druid.segment.indexing.TuningConfig;
7779
import org.apache.druid.segment.indexing.granularity.GranularitySpec;
7880
import org.apache.druid.segment.indexing.granularity.UniformGranularitySpec;
7981
import org.apache.druid.segment.loading.SegmentLoadingException;
@@ -177,7 +179,7 @@ public CompactionTask(
177179
@JsonProperty("dimensionsSpec") @Nullable final DimensionsSpec dimensionsSpec,
178180
@JsonProperty("metricsSpec") @Nullable final AggregatorFactory[] metricsSpec,
179181
@JsonProperty("segmentGranularity") @Nullable final Granularity segmentGranularity,
180-
@JsonProperty("tuningConfig") @Nullable final ParallelIndexTuningConfig tuningConfig,
182+
@JsonProperty("tuningConfig") @Nullable final TuningConfig tuningConfig,
181183
@JsonProperty("context") @Nullable final Map<String, Object> context,
182184
@JacksonInject ObjectMapper jsonMapper,
183185
@JacksonInject AuthorizerMapper authorizerMapper,
@@ -213,10 +215,10 @@ public CompactionTask(
213215
this.dimensionsSpec = dimensionsSpec == null ? dimensions : dimensionsSpec;
214216
this.metricsSpec = metricsSpec;
215217
this.segmentGranularity = segmentGranularity;
216-
this.tuningConfig = tuningConfig;
218+
this.tuningConfig = tuningConfig != null ? getTuningConfig(tuningConfig) : null;
217219
this.jsonMapper = jsonMapper;
218220
this.segmentProvider = new SegmentProvider(dataSource, this.ioConfig.getInputSpec());
219-
this.partitionConfigurationManager = new PartitionConfigurationManager(tuningConfig);
221+
this.partitionConfigurationManager = new PartitionConfigurationManager(this.tuningConfig);
220222
this.authorizerMapper = authorizerMapper;
221223
this.chatHandlerProvider = chatHandlerProvider;
222224
this.rowIngestionMetersFactory = rowIngestionMetersFactory;
@@ -227,6 +229,51 @@ public CompactionTask(
227229
this.appenderatorsManager = appenderatorsManager;
228230
}
229231

232+
@VisibleForTesting
233+
static ParallelIndexTuningConfig getTuningConfig(TuningConfig tuningConfig)
234+
{
235+
if (tuningConfig instanceof ParallelIndexTuningConfig) {
236+
return (ParallelIndexTuningConfig) tuningConfig;
237+
} else if (tuningConfig instanceof IndexTuningConfig) {
238+
final IndexTuningConfig indexTuningConfig = (IndexTuningConfig) tuningConfig;
239+
return new ParallelIndexTuningConfig(
240+
null,
241+
indexTuningConfig.getMaxRowsPerSegment(),
242+
indexTuningConfig.getMaxRowsPerSegment(),
243+
indexTuningConfig.getMaxBytesInMemory(),
244+
indexTuningConfig.getMaxTotalRows(),
245+
indexTuningConfig.getNumShards(),
246+
null,
247+
indexTuningConfig.getPartitionsSpec(),
248+
indexTuningConfig.getIndexSpec(),
249+
indexTuningConfig.getIndexSpecForIntermediatePersists(),
250+
indexTuningConfig.getMaxPendingPersists(),
251+
indexTuningConfig.isForceGuaranteedRollup(),
252+
indexTuningConfig.isReportParseExceptions(),
253+
indexTuningConfig.getPushTimeout(),
254+
indexTuningConfig.getSegmentWriteOutMediumFactory(),
255+
null,
256+
null,
257+
null,
258+
null,
259+
null,
260+
null,
261+
null,
262+
null,
263+
indexTuningConfig.isLogParseExceptions(),
264+
indexTuningConfig.getMaxParseExceptions(),
265+
indexTuningConfig.getMaxSavedParseExceptions()
266+
);
267+
} else {
268+
throw new ISE(
269+
"Unknown tuningConfig type: [%s], Must be either [%s] or [%s]",
270+
tuningConfig.getClass().getName(),
271+
ParallelIndexTuningConfig.class.getName(),
272+
IndexTuningConfig.class.getName()
273+
);
274+
}
275+
}
276+
230277
@JsonProperty
231278
public CompactionIOConfig getIoConfig()
232279
{
@@ -848,7 +895,7 @@ public static class Builder
848895
@Nullable
849896
private Granularity segmentGranularity;
850897
@Nullable
851-
private ParallelIndexTuningConfig tuningConfig;
898+
private TuningConfig tuningConfig;
852899
@Nullable
853900
private Map<String, Object> context;
854901

@@ -911,7 +958,7 @@ public Builder segmentGranularity(Granularity segmentGranularity)
911958
return this;
912959
}
913960

914-
public Builder tuningConfig(ParallelIndexTuningConfig tuningConfig)
961+
public Builder tuningConfig(TuningConfig tuningConfig)
915962
{
916963
this.tuningConfig = tuningConfig;
917964
return this;

indexing-service/src/main/java/org/apache/druid/indexing/common/task/IndexTask.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,6 @@ public boolean isAppendToExisting()
11711171
}
11721172
}
11731173

1174-
@JsonTypeName("index")
11751174
public static class IndexTuningConfig implements TuningConfig, AppenderatorConfig
11761175
{
11771176
private static final IndexSpec DEFAULT_INDEX_SPEC = new IndexSpec();

indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/ParallelIndexTuningConfig.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import com.fasterxml.jackson.annotation.JsonCreator;
2323
import com.fasterxml.jackson.annotation.JsonProperty;
24-
import com.fasterxml.jackson.annotation.JsonTypeName;
2524
import com.google.common.base.Preconditions;
2625
import org.apache.druid.data.input.SplitHintSpec;
2726
import org.apache.druid.indexer.partitions.PartitionsSpec;
@@ -35,7 +34,6 @@
3534
import javax.annotation.Nullable;
3635
import java.util.Objects;
3736

38-
@JsonTypeName("index_parallel")
3937
public class ParallelIndexTuningConfig extends IndexTuningConfig
4038
{
4139
private static final int DEFAULT_MAX_NUM_CONCURRENT_SUB_TASKS = 1;

indexing-service/src/test/java/org/apache/druid/indexing/common/task/ClientCompactQuerySerdeTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.fasterxml.jackson.databind.ObjectMapper;
2323
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
24+
import com.fasterxml.jackson.databind.jsontype.NamedType;
2425
import com.google.common.collect.ImmutableList;
2526
import org.apache.druid.client.coordinator.CoordinatorClient;
2627
import org.apache.druid.client.indexing.ClientCompactQuery;
@@ -36,6 +37,7 @@
3637
import org.apache.druid.indexing.common.SegmentLoaderFactory;
3738
import org.apache.druid.indexing.common.TestUtils;
3839
import org.apache.druid.indexing.common.stats.RowIngestionMetersFactory;
40+
import org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexTuningConfig;
3941
import org.apache.druid.jackson.DefaultObjectMapper;
4042
import org.apache.druid.java.util.common.Intervals;
4143
import org.apache.druid.segment.IndexSpec;
@@ -168,6 +170,7 @@ private static ObjectMapper setupInjectablesInObjectMapper(ObjectMapper objectMa
168170
)
169171
);
170172
objectMapper.setInjectableValues(injectableValues);
173+
objectMapper.registerSubtypes(new NamedType(ParallelIndexTuningConfig.class, "index_parallel"));
171174
return objectMapper;
172175
}
173176
}

0 commit comments

Comments
 (0)