Clean up allowPartialSearchResults serialization (#37911)
When serializing allowPartialSearchResults to the shards through ShardSearchTransportRequest, we use an optional boolean field, though the corresponding instance member is declared `boolean` which can never be null. We also have an assert to verify that the incoming search request provides a non-null value for the flag, and a comment explaining that null should be considered a bug. This commit makes the allowPartialSearchResults method in ShardSearchRequest return a `boolean` rather than a `Boolean` and changes the serialization from optional to non optional, in a bw comp manner.
This commit is contained in:
parent
4f4113e964
commit
a6d4838a67
|
@ -170,7 +170,7 @@ public class ShardSearchLocalRequest implements ShardSearchRequest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean allowPartialSearchResults() {
|
||||
public boolean allowPartialSearchResults() {
|
||||
return allowPartialSearchResults;
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,9 @@ public class ShardSearchLocalRequest implements ShardSearchRequest {
|
|||
nowInMillis = in.readVLong();
|
||||
requestCache = in.readOptionalBoolean();
|
||||
clusterAlias = in.readOptionalString();
|
||||
if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
|
||||
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
|
||||
allowPartialSearchResults = in.readBoolean();
|
||||
} else if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
|
||||
allowPartialSearchResults = in.readOptionalBoolean();
|
||||
}
|
||||
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
|
||||
|
@ -244,7 +246,9 @@ public class ShardSearchLocalRequest implements ShardSearchRequest {
|
|||
}
|
||||
out.writeOptionalBoolean(requestCache);
|
||||
out.writeOptionalString(clusterAlias);
|
||||
if (out.getVersion().onOrAfter(Version.V_6_3_0)) {
|
||||
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
|
||||
out.writeBoolean(allowPartialSearchResults);
|
||||
} else if (out.getVersion().onOrAfter(Version.V_6_3_0)) {
|
||||
out.writeOptionalBoolean(allowPartialSearchResults);
|
||||
}
|
||||
if (asKey == false) {
|
||||
|
@ -295,5 +299,4 @@ public class ShardSearchLocalRequest implements ShardSearchRequest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public interface ShardSearchRequest {
|
|||
|
||||
Boolean requestCache();
|
||||
|
||||
Boolean allowPartialSearchResults();
|
||||
boolean allowPartialSearchResults();
|
||||
|
||||
Scroll scroll();
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ public class ShardSearchTransportRequest extends TransportRequest implements Sha
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean allowPartialSearchResults() {
|
||||
public boolean allowPartialSearchResults() {
|
||||
return shardSearchLocalRequest.allowPartialSearchResults();
|
||||
}
|
||||
|
||||
|
|
|
@ -114,8 +114,8 @@ public class SearchSlowLogTests extends ESSingleNodeTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean allowPartialSearchResults() {
|
||||
return null;
|
||||
public boolean allowPartialSearchResults() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.elasticsearch.index.query.RandomQueryBuilder;
|
|||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.indices.InvalidAliasNameException;
|
||||
import org.elasticsearch.search.AbstractSearchTestCase;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -76,6 +77,19 @@ public class ShardSearchTransportRequestTests extends AbstractSearchTestCase {
|
|||
assertEquals(deserializedRequest.getAliasFilter(), shardSearchTransportRequest.getAliasFilter());
|
||||
assertEquals(deserializedRequest.indexBoost(), shardSearchTransportRequest.indexBoost(), 0.0f);
|
||||
assertEquals(deserializedRequest.getClusterAlias(), shardSearchTransportRequest.getClusterAlias());
|
||||
assertEquals(shardSearchTransportRequest.allowPartialSearchResults(), deserializedRequest.allowPartialSearchResults());
|
||||
}
|
||||
|
||||
public void testAllowPartialResultsSerializationPre7_0_0() throws IOException {
|
||||
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.V_7_0_0));
|
||||
ShardSearchTransportRequest shardSearchTransportRequest = createShardSearchTransportRequest();
|
||||
ShardSearchTransportRequest deserializedRequest =
|
||||
copyWriteable(shardSearchTransportRequest, namedWriteableRegistry, ShardSearchTransportRequest::new, version);
|
||||
if (version.before(Version.V_6_3_0)) {
|
||||
assertFalse(deserializedRequest.allowPartialSearchResults());
|
||||
} else {
|
||||
assertEquals(shardSearchTransportRequest.allowPartialSearchResults(), deserializedRequest.allowPartialSearchResults());
|
||||
}
|
||||
}
|
||||
|
||||
private ShardSearchTransportRequest createShardSearchTransportRequest() throws IOException {
|
||||
|
|
|
@ -163,8 +163,8 @@ public class SliceBuilderTests extends ESTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean allowPartialSearchResults() {
|
||||
return null;
|
||||
public boolean allowPartialSearchResults() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue