Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unsupported group_shard_failures parameter #33208

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ private static String buildMessage(String phaseName, String msg, ShardSearchFail
@Override
protected void metadataToXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("phase", phaseName);
final boolean group = params.paramAsBoolean("group_shard_failures", true); // we group by default
builder.field("grouped", group); // notify that it's grouped
builder.field("grouped", true); // notify that it's grouped
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is only here for backwards compatibility?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea I did not want to change the output format at this stage. Also, given that the flag was not exposed, we would always return true anyways even before the change. We should remove this at some point though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

builder.field("failed_shards");
builder.startArray();
ShardOperationFailedException[] failures = group ? ExceptionsHelper.groupBy(shardFailures) : shardFailures;
ShardOperationFailedException[] failures = ExceptionsHelper.groupBy(shardFailures);
for (ShardOperationFailedException failure : failures) {
builder.startObject();
failure.toXContent(builder, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public static void buildBroadcastShardsHeader(XContentBuilder builder, Params pa
builder.field(FAILED_FIELD.getPreferredName(), failed);
if (shardFailures != null && shardFailures.length > 0) {
builder.startArray(FAILURES_FIELD.getPreferredName());
final boolean group = params.paramAsBoolean("group_shard_failures", true); // we group by default
for (ShardOperationFailedException shardFailure : group ? ExceptionsHelper.groupBy(shardFailures) : shardFailures) {
for (ShardOperationFailedException shardFailure : ExceptionsHelper.groupBy(shardFailures)) {
builder.startObject();
shardFailure.toXContent(builder, params);
builder.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
Expand All @@ -38,8 +37,6 @@

import java.io.IOException;

import static java.util.Collections.singletonMap;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.Matchers.hasSize;

Expand Down Expand Up @@ -87,56 +84,6 @@ public void testToXContent() throws IOException {
"}" +
"}" +
"]}", Strings.toString(exception));

// Failures are NOT grouped
ToXContent.MapParams params = new ToXContent.MapParams(singletonMap("group_shard_failures", "false"));
try (XContentBuilder builder = jsonBuilder()) {
builder.startObject();
exception.toXContent(builder, params);
builder.endObject();

assertEquals("{" +
"\"type\":\"search_phase_execution_exception\"," +
"\"reason\":\"all shards failed\"," +
"\"phase\":\"test\"," +
"\"grouped\":false," +
"\"failed_shards\":[" +
"{" +
"\"shard\":0," +
"\"index\":\"foo\"," +
"\"node\":\"node_1\"," +
"\"reason\":{" +
"\"type\":\"parsing_exception\"," +
"\"reason\":\"foobar\"," +
"\"line\":1," +
"\"col\":2" +
"}" +
"}," +
"{" +
"\"shard\":1," +
"\"index\":\"foo\"," +
"\"node\":\"node_2\"," +
"\"reason\":{" +
"\"type\":\"index_shard_closed_exception\"," +
"\"reason\":\"CurrentState[CLOSED] Closed\"," +
"\"index_uuid\":\"_na_\"," +
"\"shard\":\"1\"," +
"\"index\":\"foo\"" +
"}" +
"}," +
"{" +
"\"shard\":2," +
"\"index\":\"foo\"," +
"\"node\":\"node_3\"," +
"\"reason\":{" +
"\"type\":\"parsing_exception\"," +
"\"reason\":\"foobar\"," +
"\"line\":5," +
"\"col\":7" +
"}" +
"}" +
"]}", Strings.toString(builder));
}
}

public void testToAndFromXContent() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.hamcrest.CoreMatchers.anyOf;
Expand Down Expand Up @@ -130,29 +129,6 @@ public void testFailuresDeduplication() throws IOException {
assertThat(parsedFailures[1].shardId(), equalTo(2));
assertThat(parsedFailures[1].status(), equalTo(RestStatus.INTERNAL_SERVER_ERROR));
assertThat(parsedFailures[1].getCause().getMessage(), containsString("fizz"));

ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap("group_shard_failures", "false"));
BytesReference bytesReferenceWithoutDedup = toShuffledXContent(response, xContentType, params, humanReadable);
try(XContentParser parser = createParser(xContentType.xContent(), bytesReferenceWithoutDedup)) {
parsedResponse = doParseInstance(parser);
assertNull(parser.nextToken());
}

assertThat(parsedResponse.getShardFailures().length, equalTo(3));
parsedFailures = parsedResponse.getShardFailures();
for (int i = 0; i < 3; i++) {
if (i < 2) {
assertThat(parsedFailures[i].index(), equalTo("test"));
assertThat(parsedFailures[i].shardId(), equalTo(i));
assertThat(parsedFailures[i].status(), equalTo(RestStatus.INTERNAL_SERVER_ERROR));
assertThat(parsedFailures[i].getCause().getMessage(), containsString("foo"));
} else {
assertThat(parsedFailures[i].index(), equalTo("test"));
assertThat(parsedFailures[i].shardId(), equalTo(i));
assertThat(parsedFailures[i].status(), equalTo(RestStatus.INTERNAL_SERVER_ERROR));
assertThat(parsedFailures[i].getCause().getMessage(), containsString("fizz"));
}
}
}

public void testToXContent() {
Expand Down