fix numShards = -1 not being handled correctly (#3937)

This commit is contained in:
David Lim 2017-02-14 19:45:38 -07:00 committed by Gian Merlino
parent a459db68b6
commit 3c54fc912a
2 changed files with 27 additions and 5 deletions

View File

@ -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;

View File

@ -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