Skip to content

Improve error message for search.check_ccs_compatibility=true mode flag #97059

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

Merged
merged 2 commits into from
Jun 28, 2023
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 @@ -18,6 +18,7 @@
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.script.mustache.MultiSearchTemplateResponse.Item;
import org.elasticsearch.search.DummyQueryParserPlugin;
import org.elasticsearch.search.FailBeforeCurrentVersionQueryBuilder;
import org.elasticsearch.search.SearchService;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.xcontent.json.JsonXContent;
Expand Down Expand Up @@ -200,9 +201,14 @@ public void testCCSCheckCompatibility() throws Exception {
Exception ex = response.getFailure();
assertThat(ex.getMessage(), containsString("[class org.elasticsearch.action.search.SearchRequest] is not compatible with version"));
assertThat(ex.getMessage(), containsString("'search.check_ccs_compatibility' setting is enabled."));
assertEquals(
"This query isn't serializable with transport versions before " + TransportVersion.current(),
ex.getCause().getMessage()

String expectedCause = Strings.format(
"[fail_before_current_version] was released first in version %s, failed compatibility "
+ "check trying to send it to node with version %s",
FailBeforeCurrentVersionQueryBuilder.FUTURE_VERSION,
TransportVersion.MINIMUM_CCS_VERSION
);
String actualCause = ex.getCause().getMessage();
assertEquals(expectedCause, actualCause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package org.elasticsearch.script.mustache;

import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.search.SearchRequest;
Expand Down Expand Up @@ -365,14 +364,22 @@ public void testCCSCheckCompatibility() throws Exception {
ExecutionException.class,
() -> client().execute(SearchTemplateAction.INSTANCE, request).get()
);

Throwable primary = ex.getCause();
assertNotNull(primary);

Throwable underlying = primary.getCause();
assertNotNull(underlying);

assertThat(
ex.getCause().getMessage(),
primary.getMessage(),
containsString("[class org.elasticsearch.action.search.SearchRequest] is not compatible with version")
);
assertThat(ex.getCause().getMessage(), containsString("'search.check_ccs_compatibility' setting is enabled."));
assertEquals(
"This query isn't serializable with transport versions before " + TransportVersion.current(),
ex.getCause().getCause().getMessage()
);
assertThat(primary.getMessage(), containsString("'search.check_ccs_compatibility' setting is enabled."));

String expectedCause = "[fail_before_current_version] was released first in version XXXXXXX, failed compatibility check trying to"
+ " send it to node with version XXXXXXX";
String actualCause = underlying.getMessage().replaceAll("\\d{7,}", "XXXXXXX");
assertEquals(expectedCause, actualCause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.elasticsearch.TransportVersion;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryRewriteContext;
import org.elasticsearch.xcontent.XContentParser;
Expand All @@ -23,22 +22,14 @@
public class FailBeforeCurrentVersionQueryBuilder extends DummyQueryBuilder {

public static final String NAME = "fail_before_current_version";
public static final int FUTURE_VERSION = TransportVersion.current().id() + 11_111;

public FailBeforeCurrentVersionQueryBuilder(StreamInput in) throws IOException {
super(in);
}

public FailBeforeCurrentVersionQueryBuilder() {}

@Override
protected void doWriteTo(StreamOutput out) {
if (out.getTransportVersion().before(TransportVersion.current())) {
throw new IllegalArgumentException(
"This query isn't serializable with transport versions before " + TransportVersion.current()
);
}
}

public static DummyQueryBuilder fromXContent(XContentParser parser) throws IOException {
DummyQueryBuilder.fromXContent(parser);
return new FailBeforeCurrentVersionQueryBuilder();
Expand All @@ -53,4 +44,11 @@ public String getWriteableName() {
protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws IOException {
return this;
}

@Override
public TransportVersion getMinimalSupportedVersion() {
// this is what causes the failure - it always reports a version in the future, so it is never compatible with
// current or minimum CCS TransportVersion
return new TransportVersion(FUTURE_VERSION);
}
}