Skip to content

Commit ab448da

Browse files
Remote reindex failure parse fix (#42928)
A search request that partially fails with failures without an index (index: null) in the failure would cause a parse error in reindex from remote. This would hide the original exception, making it hard to debug the root cause. This commit fixes this so that we can tolerate null index entries in a search failure.
1 parent 57441e9 commit ab448da

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteResponseParsers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class Fields {
135135
return new SearchFailure(reasonThrowable, index, shardId, nodeId);
136136
});
137137
static {
138-
SEARCH_FAILURE_PARSER.declareString(optionalConstructorArg(), new ParseField("index"));
138+
SEARCH_FAILURE_PARSER.declareStringOrNull(optionalConstructorArg(), new ParseField("index"));
139139
SEARCH_FAILURE_PARSER.declareInt(optionalConstructorArg(), new ParseField("shard"));
140140
SEARCH_FAILURE_PARSER.declareString(optionalConstructorArg(), new ParseField("node"));
141141
SEARCH_FAILURE_PARSER.declareField(constructorArg(), (p, c) -> {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.index.reindex.remote;
21+
22+
import org.elasticsearch.action.search.ShardSearchFailure;
23+
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
24+
import org.elasticsearch.common.xcontent.ToXContent;
25+
import org.elasticsearch.common.xcontent.XContentBuilder;
26+
import org.elasticsearch.common.xcontent.XContentParser;
27+
import org.elasticsearch.common.xcontent.XContentType;
28+
import org.elasticsearch.index.reindex.ScrollableHitSource;
29+
import org.elasticsearch.test.ESTestCase;
30+
import org.hamcrest.Matchers;
31+
32+
import java.io.IOException;
33+
34+
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
35+
36+
public class RemoteResponseParsersTests extends ESTestCase {
37+
38+
/**
39+
* Check that we can parse shard search failures without index information.
40+
*/
41+
public void testFailureWithoutIndex() throws IOException {
42+
ShardSearchFailure failure = new ShardSearchFailure(new EsRejectedExecutionException("exhausted"));
43+
XContentBuilder builder = jsonBuilder();
44+
failure.toXContent(builder, ToXContent.EMPTY_PARAMS);
45+
try (XContentParser parser = createParser(builder)) {
46+
ScrollableHitSource.SearchFailure parsed = RemoteResponseParsers.SEARCH_FAILURE_PARSER.parse(parser, XContentType.JSON);
47+
assertNotNull(parsed.getReason());
48+
assertThat(parsed.getReason().getMessage(), Matchers.containsString("exhausted"));
49+
assertThat(parsed.getReason(), Matchers.instanceOf(EsRejectedExecutionException.class));
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)