Skip to content

Commit

Permalink
fix numShards = -1 not being handled correctly (apache#3937)
Browse files Browse the repository at this point in the history
  • Loading branch information
dclim authored and gianm committed Feb 15, 2017
1 parent a459db6 commit 3c54fc9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,15 @@ public boolean isSkipFirehoseCaching()
@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;
private static final boolean DEFAULT_BUILD_V9_DIRECTLY = true;
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;
Expand Down Expand Up @@ -666,15 +667,17 @@ private IndexTuningConfig(
)
{
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ public void testIndexTaskTuningConfigTargetPartitionSizeOrNumShards() throws Exc

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
Expand Down

0 comments on commit 3c54fc9

Please sign in to comment.