diff --git a/indexing-service/src/main/java/io/druid/indexing/common/task/IndexTask.java b/indexing-service/src/main/java/io/druid/indexing/common/task/IndexTask.java index 9326279e8e5..1565871fb49 100644 --- a/indexing-service/src/main/java/io/druid/indexing/common/task/IndexTask.java +++ b/indexing-service/src/main/java/io/druid/indexing/common/task/IndexTask.java @@ -609,7 +609,6 @@ public class IndexTask extends AbstractTask @JsonTypeName("index") public static class IndexTuningConfig implements TuningConfig, AppenderatorConfig { - private static final int DEFAULT_TARGET_PARTITION_SIZE = 5000000; private static final int DEFAULT_MAX_ROWS_IN_MEMORY = 75000; private static final IndexSpec DEFAULT_INDEX_SPEC = new IndexSpec(); private static final int DEFAULT_MAX_PENDING_PERSISTS = 0; @@ -617,6 +616,8 @@ public class IndexTask extends AbstractTask private static final boolean DEFAULT_FORCE_EXTENDABLE_SHARD_SPECS = false; private static final boolean DEFAULT_REPORT_PARSE_EXCEPTIONS = false; + static final int DEFAULT_TARGET_PARTITION_SIZE = 5000000; + private final Integer targetPartitionSize; private final int maxRowsInMemory; private final Integer numShards; @@ -666,15 +667,17 @@ public class IndexTask extends AbstractTask ) { Preconditions.checkArgument( - targetPartitionSize == null || targetPartitionSize == -1 || numShards == null, + targetPartitionSize == null || targetPartitionSize.equals(-1) || numShards == null || numShards.equals(-1), "targetPartitionSize and numShards cannot both be set" ); - this.targetPartitionSize = numShards != null + this.targetPartitionSize = numShards != null && !numShards.equals(-1) ? null - : (targetPartitionSize == null ? DEFAULT_TARGET_PARTITION_SIZE : targetPartitionSize); + : (targetPartitionSize == null || targetPartitionSize.equals(-1) + ? DEFAULT_TARGET_PARTITION_SIZE + : targetPartitionSize); this.maxRowsInMemory = maxRowsInMemory == null ? DEFAULT_MAX_ROWS_IN_MEMORY : maxRowsInMemory; - this.numShards = numShards; + this.numShards = numShards == null || numShards.equals(-1) ? null : numShards; this.indexSpec = indexSpec == null ? DEFAULT_INDEX_SPEC : indexSpec; this.maxPendingPersists = maxPendingPersists == null ? DEFAULT_MAX_PENDING_PERSISTS : maxPendingPersists; this.buildV9Directly = buildV9Directly == null ? DEFAULT_BUILD_V9_DIRECTLY : buildV9Directly; diff --git a/indexing-service/src/test/java/io/druid/indexing/common/task/TaskSerdeTest.java b/indexing-service/src/test/java/io/druid/indexing/common/task/TaskSerdeTest.java index 48d283cd98d..0bc64d457d9 100644 --- a/indexing-service/src/test/java/io/druid/indexing/common/task/TaskSerdeTest.java +++ b/indexing-service/src/test/java/io/druid/indexing/common/task/TaskSerdeTest.java @@ -137,6 +137,25 @@ public class TaskSerdeTest Assert.assertEquals(null, tuningConfig.getTargetPartitionSize()); Assert.assertEquals(10, (int) tuningConfig.getNumShards()); + + tuningConfig = jsonMapper.readValue( + "{\"type\":\"index\", \"targetPartitionSize\":10, \"numShards\":-1}", + IndexTask.IndexTuningConfig.class + ); + + Assert.assertEquals(null, tuningConfig.getNumShards()); + Assert.assertEquals(10, (int) tuningConfig.getTargetPartitionSize()); + + tuningConfig = jsonMapper.readValue( + "{\"type\":\"index\", \"targetPartitionSize\":-1, \"numShards\":-1}", + IndexTask.IndexTuningConfig.class + ); + + Assert.assertEquals(null, tuningConfig.getNumShards()); + Assert.assertEquals( + IndexTask.IndexTuningConfig.DEFAULT_TARGET_PARTITION_SIZE, + (int) tuningConfig.getTargetPartitionSize() + ); } @Test