Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to update cluster-level compaction configs #16803

Merged
merged 5 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,12 @@ public void setup()
final String dataSource = DATA_SOURCE_PREFIX + i;
compactionConfigs.put(
dataSource,
new DataSourceCompactionConfig(
dataSource,
0,
inputSegmentSizeBytes,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
)
DataSourceCompactionConfig
.builder()
.forDataSource(dataSource)
.withTaskPriority(0)
.withInputSegmentSizeBytes(inputSegmentSizeBytes)
.build()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public CompactionConfigValidationResult validateCompactionTask(
return validationResults.stream()
.filter(result -> !result.isValid())
.findFirst()
.orElse(new CompactionConfigValidationResult(true, null));
.orElse(CompactionConfigValidationResult.success());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void testMSQEngineWithUnsupportedMetricsSpecIsInValid()
CompactionConfigValidationResult validationResult = MSQ_COMPACTION_RUNNER.validateCompactionTask(compactionTask);
Assert.assertFalse(validationResult.isValid());
Assert.assertEquals(
"Different name[sum_added] and fieldName(s)[[added]] for aggregator unsupported for MSQ engine.",
"MSQ: Different name[sum_added] and fieldName(s)[[added]] for aggregator",
validationResult.getReason()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public CompactionConfigValidationResult validateCompactionTask(
CompactionTask compactionTask
)
{
return new CompactionConfigValidationResult(true, null);
return CompactionConfigValidationResult.success();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static CompactionConfigValidationResult validateCompactionConfig(
{
CompactionEngine compactionEngine = newConfig.getEngine() == null ? defaultCompactionEngine : newConfig.getEngine();
if (compactionEngine == CompactionEngine.NATIVE) {
return new CompactionConfigValidationResult(true, null);
return CompactionConfigValidationResult.success();
} else {
return compactionConfigSupportedByMSQEngine(newConfig);
}
Expand Down Expand Up @@ -125,7 +125,7 @@ private static CompactionConfigValidationResult compactionConfigSupportedByMSQEn
return validationResults.stream()
.filter(result -> !result.isValid())
.findFirst()
.orElse(new CompactionConfigValidationResult(true, null));
.orElse(CompactionConfigValidationResult.success());
}

/**
Expand All @@ -135,22 +135,19 @@ public static CompactionConfigValidationResult validatePartitionsSpecForMSQ(Part
{
if (!(partitionsSpec instanceof DimensionRangePartitionsSpec
|| partitionsSpec instanceof DynamicPartitionsSpec)) {
return new CompactionConfigValidationResult(
false,
"Invalid partitionsSpec type[%s] for MSQ engine. Type must be either 'dynamic' or 'range'.",
return CompactionConfigValidationResult.failure(
"MSQ: Invalid partitioning type[%s]. Must be either 'dynamic' or 'range'",
partitionsSpec.getClass().getSimpleName()

);
}
if (partitionsSpec instanceof DynamicPartitionsSpec
&& ((DynamicPartitionsSpec) partitionsSpec).getMaxTotalRows() != null) {
return new CompactionConfigValidationResult(
false,
"maxTotalRows[%d] in DynamicPartitionsSpec not supported for MSQ engine.",
((DynamicPartitionsSpec) partitionsSpec).getMaxTotalRows()
return CompactionConfigValidationResult.failure(
"MSQ: 'maxTotalRows' not supported with 'dynamic' partitioning"
);
}
return new CompactionConfigValidationResult(true, null);
return CompactionConfigValidationResult.success();
}

/**
Expand All @@ -162,12 +159,11 @@ public static CompactionConfigValidationResult validateRollupForMSQ(
)
{
if (metricsSpec != null && isRollup != null && !isRollup) {
return new CompactionConfigValidationResult(
false,
"rollup in granularitySpec must be set to True if metricsSpec is specifed for MSQ engine."
return CompactionConfigValidationResult.failure(
"MSQ: 'granularitySpec.rollup' must be true if 'metricsSpec' is specified"
);
}
return new CompactionConfigValidationResult(true, null);
return CompactionConfigValidationResult.success();
}

/**
Expand All @@ -179,14 +175,13 @@ public static CompactionConfigValidationResult validateMaxNumTasksForMSQ(Map<Str
int maxNumTasks = QueryContext.of(context)
.getInt(ClientMSQContext.CTX_MAX_NUM_TASKS, ClientMSQContext.DEFAULT_MAX_NUM_TASKS);
if (maxNumTasks < 2) {
return new CompactionConfigValidationResult(false,
"MSQ context maxNumTasks [%,d] cannot be less than 2, "
+ "since at least 1 controller and 1 worker is necessary.",
maxNumTasks
return CompactionConfigValidationResult.failure(
"MSQ: Context maxNumTasks[%,d] must be at least 2 (1 controller + 1 worker)",
maxNumTasks
);
}
}
return new CompactionConfigValidationResult(true, null);
return CompactionConfigValidationResult.success();
}

/**
Expand All @@ -195,7 +190,7 @@ public static CompactionConfigValidationResult validateMaxNumTasksForMSQ(Map<Str
public static CompactionConfigValidationResult validateMetricsSpecForMSQ(AggregatorFactory[] metricsSpec)
{
if (metricsSpec == null) {
return new CompactionConfigValidationResult(true, null);
return CompactionConfigValidationResult.success();
}
return Arrays.stream(metricsSpec)
.filter(aggregatorFactory ->
Expand All @@ -206,11 +201,10 @@ public static CompactionConfigValidationResult validateMetricsSpecForMSQ(Aggrega
.equals(aggregatorFactory.getName())))
.findFirst()
.map(aggregatorFactory ->
new CompactionConfigValidationResult(
false,
"Different name[%s] and fieldName(s)[%s] for aggregator unsupported for MSQ engine.",
CompactionConfigValidationResult.failure(
"MSQ: Different name[%s] and fieldName(s)[%s] for aggregator",
aggregatorFactory.getName(),
aggregatorFactory.requiredFields()
)).orElse(new CompactionConfigValidationResult(true, null));
)).orElse(CompactionConfigValidationResult.success());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,23 @@

public class CompactionConfigValidationResult
{
private static final CompactionConfigValidationResult SUCCESS
= new CompactionConfigValidationResult(true, null);

private final boolean valid;
private final String reason;

public CompactionConfigValidationResult(boolean valid, String format, Object... args)
public static CompactionConfigValidationResult success()
{
return SUCCESS;
}

public static CompactionConfigValidationResult failure(String msgFormat, Object... args)
{
return new CompactionConfigValidationResult(false, msgFormat, args);
}

private CompactionConfigValidationResult(boolean valid, String format, Object... args)
{
this.valid = valid;
this.reason = format == null ? null : StringUtils.format(format, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.collect.ImmutableList;
import org.apache.druid.common.config.Configs;
import org.apache.druid.indexer.CompactionEngine;
import org.apache.druid.server.http.CompactionConfigUpdateRequest;

import javax.annotation.Nullable;
import java.util.List;
Expand Down Expand Up @@ -54,23 +55,21 @@ public static CoordinatorCompactionConfig from(
baseConfig.compactionTaskSlotRatio,
baseConfig.maxCompactionTaskSlots,
baseConfig.useAutoScaleSlots,
null
baseConfig.compactionEngine
);
}

public static CoordinatorCompactionConfig from(
CoordinatorCompactionConfig baseConfig,
@Nullable Double compactionTaskSlotRatio,
@Nullable Integer maxCompactionTaskSlots,
@Nullable Boolean useAutoScaleSlots
CompactionConfigUpdateRequest update
)
{
return new CoordinatorCompactionConfig(
baseConfig.compactionConfigs,
compactionTaskSlotRatio == null ? baseConfig.compactionTaskSlotRatio : compactionTaskSlotRatio,
maxCompactionTaskSlots == null ? baseConfig.maxCompactionTaskSlots : maxCompactionTaskSlots,
useAutoScaleSlots == null ? baseConfig.useAutoScaleSlots : useAutoScaleSlots,
null
Configs.valueOrDefault(update.getCompactionTaskSlotRatio(), baseConfig.compactionTaskSlotRatio),
Configs.valueOrDefault(update.getMaxCompactionTaskSlots(), baseConfig.maxCompactionTaskSlots),
Configs.valueOrDefault(update.getUseAutoScaleSlots(), baseConfig.useAutoScaleSlots),
Configs.valueOrDefault(update.getCompactionEngine(), baseConfig.compactionEngine)
);
}

Expand All @@ -90,7 +89,7 @@ public CoordinatorCompactionConfig(
@JsonProperty("compactionTaskSlotRatio") @Nullable Double compactionTaskSlotRatio,
@JsonProperty("maxCompactionTaskSlots") @Nullable Integer maxCompactionTaskSlots,
@JsonProperty("useAutoScaleSlots") @Nullable Boolean useAutoScaleSlots,
@JsonProperty("compactionEngine") @Nullable CompactionEngine compactionEngine
@JsonProperty("engine") @Nullable CompactionEngine compactionEngine
)
{
this.compactionConfigs = compactionConfigs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.base.Preconditions;
import org.apache.druid.indexer.CompactionEngine;
import org.apache.druid.query.aggregation.AggregatorFactory;
import org.apache.druid.server.coordinator.config.DataSourceCompactionConfigBuilder;
import org.joda.time.Period;

import javax.annotation.Nullable;
Expand All @@ -42,6 +43,12 @@ public class DataSourceCompactionConfig
private final String dataSource;
private final int taskPriority;
private final long inputSegmentSizeBytes;

public static DataSourceCompactionConfigBuilder builder()
{
return new DataSourceCompactionConfigBuilder();
}

/**
* The number of input segments is limited because the byte size of a serialized task spec is limited by
* org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig.maxZnodeBytes.
Expand Down
Loading
Loading