Skip to content

Commit

Permalink
Fix AbstractBulkByScrollRequest slices parameter via Rest (#53068)
Browse files Browse the repository at this point in the history
Currently the AbstractBulkByScrollRequest accepts slice values of 0 via its
`setSlices` method, denoting the "auto" slicing behaviour that is usable by
settting the "slices=auto" parameter on rest requests. When using the High Level
Rest Client, however, we send the 0 value as an integer, which is then rejected
as invalid by `AbstractBulkByScrollRequest#parseSlices`. Instead of making
parsing of the rest request more lenient, this PR opts for changing the
RequestConverter logic in the client to translate 0 values to "auto" on the rest
requests.

Closes #53044
  • Loading branch information
Christoph Büscher authored Mar 6, 2020
1 parent 10f9a8f commit bc978e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,10 @@ Params withRouting(String routing) {
}

Params withSlices(int slices) {
if (slices == 0) {
// translate to "auto" value in rest request so the receiving end doesn't throw error
return putParam("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
}
return putParam("slices", String.valueOf(slices));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.elasticsearch.index.rankeval.RankEvalSpec;
import org.elasticsearch.index.rankeval.RatedRequest;
import org.elasticsearch.index.rankeval.RestRankEvalAction;
import org.elasticsearch.index.reindex.AbstractBulkByScrollRequest;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.elasticsearch.index.reindex.ReindexRequest;
import org.elasticsearch.index.reindex.RemoteInfo;
Expand Down Expand Up @@ -437,9 +438,13 @@ public void testReindex() throws IOException {
reindexRequest.setSourceQuery(new TermQueryBuilder("foo", "fooval"));
}
if (randomBoolean()) {
int slices = randomInt(100);
int slices = randomIntBetween(0,4);
reindexRequest.setSlices(slices);
expectedParams.put("slices", String.valueOf(slices));
if (slices == 0) {
expectedParams.put("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
} else {
expectedParams.put("slices", Integer.toString(slices));
}
} else {
expectedParams.put("slices", "1");
}
Expand Down Expand Up @@ -500,7 +505,11 @@ public void testUpdateByQuery() throws IOException {
}
if (randomBoolean()) {
int slices = randomIntBetween(0, 4);
expectedParams.put("slices", Integer.toString(slices));
if (slices == 0) {
expectedParams.put("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
} else {
expectedParams.put("slices", Integer.toString(slices));
}
updateByQueryRequest.setSlices(slices);
} else {
expectedParams.put("slices", "1");
Expand Down Expand Up @@ -556,7 +565,11 @@ public void testDeleteByQuery() throws IOException {
}
if (randomBoolean()) {
int slices = randomIntBetween(0, 4);
expectedParams.put("slices", Integer.toString(slices));
if (slices == 0) {
expectedParams.put("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
} else {
expectedParams.put("slices", Integer.toString(slices));
}
deleteByQueryRequest.setSlices(slices);
} else {
expectedParams.put("slices", "1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ public TimeValue getScrollTime() {

/**
* The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks.
* A value of 0 is equivalent to the "auto" slices parameter of the Rest API.
*/
public Self setSlices(int slices) {
if (slices < 0) {
Expand Down

0 comments on commit bc978e4

Please sign in to comment.