Skip to content

Commit 3850256

Browse files
Reindex-from-remote: Fail on manual slicing param (#137275)
When the `_reindex` API is used with a remote source (`source.remote` is set in the request body), neither manual slicing (via `source.slice` in the request body) nor automatic slicing (via the `slices` URL parameter) are supported. Prior to this change, on sending a request with a remote source and manual slicing enabled, the manual slicing specification would be ignored, and the complete source would be reindexed without slicing. After this change, the API will return a response with an HTTP code 400 (Bad Request) instead. The new behaviour more correctly indicates to the user that the requested functionality is not available, rather than silently ignoring part of their request. Note that: - Prior to this change, sending a request with a remote source and *automatic* slicing enabled already resulted in the correct 400 response. - The [docs](https://www.elastic.co/docs/reference/elasticsearch/rest-apis/reindex-indices#docs-reindex-slice) already correctly stated "Reindexing from remote clusters does not support manual or automatic slicing." - As a drive-by, this change also adds a unit test for the validation with the `slices` parameter set to `auto`. (Previously, only the case where it was set to a number greater than 1 was tested.) Closes #136269
1 parent 48c1583 commit 3850256

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

docs/changelog/137275.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 137275
2+
summary: "Reindex-from-remote: Fail on manual slicing param"
3+
area: Indices APIs
4+
type: bug
5+
issues:
6+
- 136269

server/src/main/java/org/elasticsearch/index/reindex/ReindexRequest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ public ActionRequestValidationException validate() {
116116
if (getSlices() == AbstractBulkByScrollRequest.AUTO_SLICES || getSlices() > 1) {
117117
e = addValidationError("reindex from remote sources doesn't support slices > 1 but was [" + getSlices() + "]", e);
118118
}
119+
if (getSearchRequest().source().slice() != null) {
120+
e = addValidationError(
121+
"reindex from remote sources doesn't support source.slice but was [" + getSearchRequest().source().slice() + "]",
122+
e
123+
);
124+
}
119125
if (getRemoteInfo().getUsername() != null && getRemoteInfo().getPassword() == null) {
120126
e = addValidationError("reindex from remote source included username but not password", e);
121127
}

server/src/test/java/org/elasticsearch/index/reindex/ReindexRequestTests.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void testReindexFromRemoteDoesNotSupportSearchQuery() {
162162
);
163163
}
164164

165-
public void testReindexFromRemoteDoesNotSupportSlices() {
165+
public void testReindexFromRemoteDoesNotSupportSlicesParameterGreaterThan1() {
166166
ReindexRequest reindex = newRequest();
167167
reindex.setRemoteInfo(
168168
new RemoteInfo(
@@ -178,6 +178,7 @@ public void testReindexFromRemoteDoesNotSupportSlices() {
178178
RemoteInfo.DEFAULT_CONNECT_TIMEOUT
179179
)
180180
);
181+
// Enable automatic slicing with a random number of slices greater than 1 (like setting the slices URL parameter):
181182
reindex.setSlices(between(2, Integer.MAX_VALUE));
182183
ActionRequestValidationException e = reindex.validate();
183184
assertEquals(
@@ -186,6 +187,60 @@ public void testReindexFromRemoteDoesNotSupportSlices() {
186187
);
187188
}
188189

190+
public void testReindexFromRemoteDoesNotSupportSlicesParameterSetToAuto() {
191+
ReindexRequest reindex = newRequest();
192+
reindex.setRemoteInfo(
193+
new RemoteInfo(
194+
randomAlphaOfLength(5),
195+
randomAlphaOfLength(5),
196+
between(1, Integer.MAX_VALUE),
197+
null,
198+
matchAll,
199+
null,
200+
null,
201+
emptyMap(),
202+
RemoteInfo.DEFAULT_SOCKET_TIMEOUT,
203+
RemoteInfo.DEFAULT_CONNECT_TIMEOUT
204+
)
205+
);
206+
// Enable automatic slicing with an automatically chosen number of slices (like setting the slices URL parameter to "auto"):
207+
reindex.setSlices(AbstractBulkByScrollRequest.AUTO_SLICES);
208+
ActionRequestValidationException e = reindex.validate();
209+
assertEquals(
210+
"Validation Failed: 1: reindex from remote sources doesn't support slices > 1 but was [" + reindex.getSlices() + "];",
211+
e.getMessage()
212+
);
213+
}
214+
215+
public void testReindexFromRemoteDoesNotSupportSlicesSourceField() {
216+
ReindexRequest reindex = newRequest();
217+
reindex.setRemoteInfo(
218+
new RemoteInfo(
219+
randomAlphaOfLength(5),
220+
randomAlphaOfLength(5),
221+
between(1, Integer.MAX_VALUE),
222+
null,
223+
matchAll,
224+
null,
225+
null,
226+
emptyMap(),
227+
RemoteInfo.DEFAULT_SOCKET_TIMEOUT,
228+
RemoteInfo.DEFAULT_CONNECT_TIMEOUT
229+
)
230+
);
231+
// Enable manual slicing (like setting source.slice.max and source.slice.id in the request body):
232+
int numSlices = randomIntBetween(2, Integer.MAX_VALUE);
233+
int sliceId = randomIntBetween(0, numSlices - 1);
234+
reindex.getSearchRequest().source().slice(new SliceBuilder(sliceId, numSlices));
235+
ActionRequestValidationException e = reindex.validate();
236+
assertEquals(
237+
"Validation Failed: 1: reindex from remote sources doesn't support source.slice but was ["
238+
+ reindex.getSearchRequest().source().slice()
239+
+ "];",
240+
e.getMessage()
241+
);
242+
}
243+
189244
public void testReindexFromRemoteRejectsUsernameWithNoPassword() {
190245
ReindexRequest reindex = newRequest();
191246
reindex.setRemoteInfo(

0 commit comments

Comments
 (0)