Skip to content

Commit

Permalink
Adjust keep alive assertion in ShardSearchRequest (#62582)
Browse files Browse the repository at this point in the history
Relates #62184
  • Loading branch information
dnhatn committed Sep 17, 2020
1 parent ede62d7 commit 0127b71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public ShardSearchRequest(StreamInput in) throws IOException {
this.keepAlive = null;
}
originalIndices = OriginalIndices.readOriginalIndices(in);
assert (readerId != null) == (keepAlive != null);
assert keepAlive == null || readerId != null : "readerId: " + readerId + " keepAlive: " + keepAlive;
}

public ShardSearchRequest(ShardSearchRequest clone) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand Down Expand Up @@ -94,9 +96,17 @@ private ShardSearchRequest createShardSearchRequest() throws IOException {
filteringAliases = new AliasFilter(null, Strings.EMPTY_ARRAY);
}
final String[] routings = generateRandomStringArray(5, 10, false, true);
ShardSearchContextId shardSearchContextId = null;
TimeValue keepAlive = null;
if (randomBoolean()) {
shardSearchContextId = new ShardSearchContextId(UUIDs.randomBase64UUID(), randomNonNegativeLong());
if (randomBoolean()) {
keepAlive = TimeValue.timeValueSeconds(randomIntBetween(0, 120));
}
}
ShardSearchRequest req = new ShardSearchRequest(new OriginalIndices(searchRequest), searchRequest, shardId,
randomIntBetween(1, 100), filteringAliases, randomBoolean() ? 1.0f : randomFloat(),
Math.abs(randomLong()), randomAlphaOfLengthBetween(3, 10), routings);
Math.abs(randomLong()), randomAlphaOfLengthBetween(3, 10), routings, shardSearchContextId, keepAlive);
req.canReturnNullResponseIfMatchNoDocs(randomBoolean());
if (randomBoolean()) {
req.setBottomSortValues(SearchSortValuesAndFormatsTests.randomInstance());
Expand Down

0 comments on commit 0127b71

Please sign in to comment.