Skip to content

Make keep alive of point in time optional in search #62184

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 3 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -1676,33 +1676,35 @@ private static final class XContentParams {

public PointInTimeBuilder(String id, TimeValue keepAlive) {
this.id = Objects.requireNonNull(id);
this.keepAlive = Objects.requireNonNull(keepAlive);
this.keepAlive = keepAlive;
}

public PointInTimeBuilder(StreamInput in) throws IOException {
id = in.readString();
keepAlive = in.readTimeValue();
keepAlive = in.readOptionalTimeValue();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(id);
out.writeTimeValue(keepAlive);
out.writeOptionalTimeValue(keepAlive);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(POINT_IN_TIME.getPreferredName());
builder.field(ID_FIELD.getPreferredName(), id);
builder.field(KEEP_ALIVE_FIELD.getPreferredName(), keepAlive);
if (keepAlive != null) {
builder.field(KEEP_ALIVE_FIELD.getPreferredName(), keepAlive);
}
builder.endObject();
return builder;
}

public static PointInTimeBuilder fromXContent(XContentParser parser) throws IOException {
final XContentParams params = PARSER.parse(parser, null);
if (params.id == null || params.keepAlive == null) {
throw new IllegalArgumentException("id and keep_alive must be specified");
if (params.id == null) {
throw new IllegalArgumentException("point int time id is not provided");
}
return new PointInTimeBuilder(params.id, params.keepAlive);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private ShardSearchRequest(OriginalIndices originalIndices,
this.originalIndices = originalIndices;
this.readerId = readerId;
this.keepAlive = keepAlive;
assert (readerId != null) == (keepAlive != null);
assert keepAlive == null || readerId != null : "readerId: " + readerId + " keepAlive: " + keepAlive;
}

public ShardSearchRequest(StreamInput in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,17 +386,23 @@ public void testToXContent() throws IOException {
public void testToXContentWithPointInTime() throws IOException {
XContentType xContentType = randomFrom(XContentType.values());
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.pointInTimeBuilder(new SearchSourceBuilder.PointInTimeBuilder("id", TimeValue.timeValueHours(1)));
TimeValue keepAlive = randomBoolean() ? TimeValue.timeValueHours(1) : null;
searchSourceBuilder.pointInTimeBuilder(new SearchSourceBuilder.PointInTimeBuilder("id", keepAlive));
XContentBuilder builder = XContentFactory.contentBuilder(xContentType);
searchSourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
BytesReference bytes = BytesReference.bytes(builder);
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(bytes, false, xContentType).v2();
assertEquals(1, sourceAsMap.size());
@SuppressWarnings("unchecked")
Map<String, Object> pit = (Map<String, Object>) sourceAsMap.get("pit");
assertEquals(2, pit.size());
assertEquals("id", pit.get("id"));
assertEquals("1h", pit.get("keep_alive"));
if (keepAlive != null) {
assertEquals("1h", pit.get("keep_alive"));
assertEquals(2, pit.size());
} else {
assertNull(pit.get("keep_alive"));
assertEquals(1, pit.size());
}
}

public void testParseIndicesBoost() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ public static SearchSourceBuilder randomSearchSourceBuilder(
builder.collapse(randomCollapseBuilder.get());
}
if (randomBoolean()) {
builder.pointInTimeBuilder(new SearchSourceBuilder.PointInTimeBuilder(randomAlphaOfLengthBetween(3, 10),
TimeValue.timeValueMinutes(randomIntBetween(1, 60))));
TimeValue keepAlive = randomBoolean() ? TimeValue.timeValueMinutes(randomIntBetween(1, 60)) : null;
builder.pointInTimeBuilder(new SearchSourceBuilder.PointInTimeBuilder(randomAlphaOfLengthBetween(3, 10), keepAlive));
}
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ setup:
search_after: [24, 172]
pit:
id: "$point_in_time_id"
keep_alive: 1m

- match: {hits.total: 3 }
- length: {hits.hits: 1 }
Expand All @@ -106,7 +105,6 @@ setup:
search_after: [18, 42]
pit:
id: "$point_in_time_id"
keep_alive: 1m

- match: {hits.total: 3}
- length: {hits.hits: 1 }
Expand Down