This is an automated email from the ASF dual-hosted git repository.
frankchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new ea9333663a1 Validate that dynamic partition spec values are positive
(#18684)
ea9333663a1 is described below
commit ea9333663a1c386ec6308998e32a2cef10842c8c
Author: Gabriel Chang <[email protected]>
AuthorDate: Tue Oct 28 17:42:40 2025 +0800
Validate that dynamic partition spec values are positive (#18684)
* Validate that dynamic partition spec values are positive
* Throw InvalidInput exception for non-positive values instead
* Update CompactionStatusTest
* Add DynamicPartitionsSpecTest
* Have partition spec check have same behaviour as when constructing
partition with findPartitionsSpecFromConfig
* Update docs
---
docs/ingestion/native-batch.md | 4 +-
.../indexer/partitions/DynamicPartitionsSpec.java | 10 ++++
.../partitions/DynamicPartitionsSpecTest.java | 67 ++++++++++++++++++++++
.../druid/server/compaction/CompactionStatus.java | 4 ++
.../server/compaction/CompactionStatusTest.java | 16 +++---
5 files changed, 91 insertions(+), 10 deletions(-)
diff --git a/docs/ingestion/native-batch.md b/docs/ingestion/native-batch.md
index be3219a5003..fb6b4f0d3df 100644
--- a/docs/ingestion/native-batch.md
+++ b/docs/ingestion/native-batch.md
@@ -333,8 +333,8 @@ The `partitionsSpec` types have different characteristics.
|Property|Description|Default|Required|
|--------|-----------|-------|---------|
|`type`|Set the value to `dynamic`.|none|yes|
-|`maxRowsPerSegment`|Used in sharding. Determines how many rows are in each
segment.|5000000|no|
-|`maxTotalRows`|Total number of rows across all segments waiting for being
pushed. Used in determining when intermediate segment push should
occur.|20000000|no|
+|`maxRowsPerSegment`|Used in sharding. Determines how many rows are in each
segment. Value must be greater than 0.|5000000|no|
+|`maxTotalRows`|Total number of rows across all segments waiting for being
pushed. Used in determining when intermediate segment push should occur. Value
must be greater than 0.|20000000|no|
With the dynamic partitioning, the parallel index task runs in a single phase
spawning multiple worker tasks (type `single_phase_sub_task`), each of which
creates segments.
diff --git
a/processing/src/main/java/org/apache/druid/indexer/partitions/DynamicPartitionsSpec.java
b/processing/src/main/java/org/apache/druid/indexer/partitions/DynamicPartitionsSpec.java
index 2c5d294f3c1..633078d375d 100644
---
a/processing/src/main/java/org/apache/druid/indexer/partitions/DynamicPartitionsSpec.java
+++
b/processing/src/main/java/org/apache/druid/indexer/partitions/DynamicPartitionsSpec.java
@@ -21,6 +21,7 @@ package org.apache.druid.indexer.partitions;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.error.InvalidInput;
import javax.annotation.Nullable;
import java.util.Objects;
@@ -50,6 +51,15 @@ public class DynamicPartitionsSpec implements PartitionsSpec
@JsonProperty("maxTotalRows") @Nullable Long maxTotalRows
)
{
+
+ if (!PartitionsSpec.isEffectivelyNull(maxRowsPerSegment) &&
maxRowsPerSegment <= 0) {
+ throw InvalidInput.exception("maxRowsPerSegment must be greater than 0");
+ }
+
+ if (!PartitionsSpec.isEffectivelyNull(maxTotalRows) && maxTotalRows <= 0) {
+ throw InvalidInput.exception("maxTotalRows must be greater than 0");
+ }
+
this.maxRowsPerSegment =
PartitionsSpec.isEffectivelyNull(maxRowsPerSegment)
? DEFAULT_MAX_ROWS_PER_SEGMENT
: maxRowsPerSegment;
diff --git
a/processing/src/test/java/org/apache/druid/indexer/partitions/DynamicPartitionsSpecTest.java
b/processing/src/test/java/org/apache/druid/indexer/partitions/DynamicPartitionsSpecTest.java
new file mode 100644
index 00000000000..d08443a6a28
--- /dev/null
+++
b/processing/src/test/java/org/apache/druid/indexer/partitions/DynamicPartitionsSpecTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.indexer.partitions;
+
+import org.apache.druid.error.DruidException;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class DynamicPartitionsSpecTest
+{
+ @Test
+ public void testConstructorWithValidParameters()
+ {
+ DynamicPartitionsSpec spec = new DynamicPartitionsSpec(1000, 10000L);
+ Assert.assertEquals(1000, spec.getMaxRowsPerSegment().intValue());
+ Assert.assertEquals(10000L, spec.getMaxTotalRows().longValue());
+
+ spec = new DynamicPartitionsSpec(1, 1L);
+ Assert.assertEquals(1, spec.getMaxRowsPerSegment().intValue());
+ Assert.assertEquals(1L, spec.getMaxTotalRows().longValue());
+
+ spec = new DynamicPartitionsSpec(null, 5000L);
+ Assert.assertEquals(5000L, spec.getMaxTotalRows().longValue());
+ Assert.assertEquals(PartitionsSpec.DEFAULT_MAX_ROWS_PER_SEGMENT,
spec.getMaxRowsPerSegment().intValue());
+
+ spec = new DynamicPartitionsSpec(500, null);
+ Assert.assertEquals(500, spec.getMaxRowsPerSegment().intValue());
+ Assert.assertNull(spec.getMaxTotalRows());
+
+ spec = new DynamicPartitionsSpec(-1, 3333L);
+ Assert.assertEquals(3333L, spec.getMaxTotalRows().longValue());
+ Assert.assertEquals(PartitionsSpec.DEFAULT_MAX_ROWS_PER_SEGMENT,
spec.getMaxRowsPerSegment().intValue());
+
+ spec = new DynamicPartitionsSpec(1000, -1L);
+ Assert.assertEquals(1000, spec.getMaxRowsPerSegment().intValue());
+ Assert.assertEquals(-1L, spec.getMaxTotalRows().longValue());
+ }
+
+ @Test
+ public void testConstructorWithInvalidParametersThrowsInvalidInput()
+ {
+ Assert.assertThrows(DruidException.class, () -> new
DynamicPartitionsSpec(0, 10000L));
+ Assert.assertThrows(DruidException.class, () -> new
DynamicPartitionsSpec(1000, 0L));
+ Assert.assertThrows(DruidException.class, () -> new
DynamicPartitionsSpec(0, 0L));
+ Assert.assertThrows(DruidException.class, () -> new
DynamicPartitionsSpec(-2, 3333L));
+ Assert.assertThrows(DruidException.class, () -> new
DynamicPartitionsSpec(1000, -2L));
+ Assert.assertThrows(DruidException.class, () -> new
DynamicPartitionsSpec(-100, -1000L));
+ }
+}
diff --git
a/server/src/main/java/org/apache/druid/server/compaction/CompactionStatus.java
b/server/src/main/java/org/apache/druid/server/compaction/CompactionStatus.java
index e34a59185f9..3c1616b6e78 100644
---
a/server/src/main/java/org/apache/druid/server/compaction/CompactionStatus.java
+++
b/server/src/main/java/org/apache/druid/server/compaction/CompactionStatus.java
@@ -332,6 +332,10 @@ public class CompactionStatus
PartitionsSpec existingPartionsSpec =
lastCompactionState.getPartitionsSpec();
if (existingPartionsSpec instanceof DimensionRangePartitionsSpec) {
existingPartionsSpec =
getEffectiveRangePartitionsSpec((DimensionRangePartitionsSpec)
existingPartionsSpec);
+ } else if (existingPartionsSpec instanceof DynamicPartitionsSpec) {
+ existingPartionsSpec = new DynamicPartitionsSpec(
+ existingPartionsSpec.getMaxRowsPerSegment(),
+ ((DynamicPartitionsSpec)
existingPartionsSpec).getMaxTotalRowsOr(Long.MAX_VALUE));
}
return CompactionStatus.completeIfEqual(
"partitionsSpec",
diff --git
a/server/src/test/java/org/apache/druid/server/compaction/CompactionStatusTest.java
b/server/src/test/java/org/apache/druid/server/compaction/CompactionStatusTest.java
index e9d70f44258..14af1c78da9 100644
---
a/server/src/test/java/org/apache/druid/server/compaction/CompactionStatusTest.java
+++
b/server/src/test/java/org/apache/druid/server/compaction/CompactionStatusTest.java
@@ -213,7 +213,7 @@ public class CompactionStatusTest
@Test
public void testStatusOnPartitionsSpecMismatch()
{
- final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, 0L);
+ final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, null);
final CompactionState lastCompactionState
= new CompactionState(currentPartitionsSpec, null, null, null, null,
null, null);
@@ -234,7 +234,7 @@ public class CompactionStatusTest
final IndexSpec currentIndexSpec
=
IndexSpec.builder().withDimensionCompression(CompressionStrategy.ZSTD).build();
- final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, 0L);
+ final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, null);
final CompactionState lastCompactionState = new CompactionState(
currentPartitionsSpec,
null,
@@ -271,7 +271,7 @@ public class CompactionStatusTest
final GranularitySpec currentGranularitySpec
= new UniformGranularitySpec(Granularities.HOUR, null, null);
- final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, 0L);
+ final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, null);
final IndexSpec currentIndexSpec
=
IndexSpec.builder().withDimensionCompression(CompressionStrategy.ZSTD).build();
final CompactionState lastCompactionState = new CompactionState(
@@ -302,7 +302,7 @@ public class CompactionStatusTest
{
final GranularitySpec currentGranularitySpec
= new UniformGranularitySpec(Granularities.HOUR, null, null);
- final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, 0L);
+ final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, null);
final IndexSpec currentIndexSpec
=
IndexSpec.builder().withDimensionCompression(CompressionStrategy.ZSTD).build();
final CompactionState lastCompactionState = new CompactionState(
@@ -335,7 +335,7 @@ public class CompactionStatusTest
{
final GranularitySpec currentGranularitySpec
= new UniformGranularitySpec(Granularities.HOUR, null, null);
- final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, 0L);
+ final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, null);
final IndexSpec currentIndexSpec
=
IndexSpec.builder().withDimensionCompression(CompressionStrategy.ZSTD).build();
final AggregateProjectionSpec projection1 =
@@ -385,7 +385,7 @@ public class CompactionStatusTest
{
final GranularitySpec currentGranularitySpec
= new UniformGranularitySpec(Granularities.HOUR, null, null);
- final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, 0L);
+ final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, null);
final IndexSpec currentIndexSpec
=
IndexSpec.builder().withDimensionCompression(CompressionStrategy.ZSTD).build();
final AggregateProjectionSpec projection1 =
@@ -440,7 +440,7 @@ public class CompactionStatusTest
{
final GranularitySpec currentGranularitySpec
= new UniformGranularitySpec(Granularities.HOUR, null, null);
- final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, 0L);
+ final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, null);
final CompactionState lastCompactionState = new CompactionState(
currentPartitionsSpec,
@@ -494,7 +494,7 @@ public class CompactionStatusTest
{
final GranularitySpec currentGranularitySpec
= new UniformGranularitySpec(Granularities.HOUR, null, null);
- final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, 0L);
+ final PartitionsSpec currentPartitionsSpec = new
DynamicPartitionsSpec(100, null);
final CompactionState lastCompactionState = new CompactionState(
currentPartitionsSpec,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]