Skip to content

Commit be0d4d9

Browse files
Remove redundant o.e.search.Scroll class (#119718)
This is just a pointless wrapper around `TimeValue` at this point. It can be removed and all its uses replaced by `TimeValue` without any change to the transport protocol or logic => no reason to keep a redundant class around.
1 parent cf11cc0 commit be0d4d9

File tree

34 files changed

+98
-229
lines changed

34 files changed

+98
-229
lines changed

modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.common.bytes.BytesArray;
1414
import org.elasticsearch.rest.RestRequest;
1515
import org.elasticsearch.script.ScriptType;
16-
import org.elasticsearch.search.Scroll;
1716
import org.elasticsearch.search.builder.SearchSourceBuilder;
1817
import org.elasticsearch.test.ESTestCase;
1918
import org.elasticsearch.test.StreamsUtils;
@@ -102,7 +101,7 @@ public void testMultiSearchTemplateToJson() throws Exception {
102101
String[] indices = { "test" };
103102
SearchRequest searchRequest = new SearchRequest(indices);
104103
// scroll is not supported in the current msearch or msearchtemplate api, so unset it:
105-
searchRequest.scroll((Scroll) null);
104+
searchRequest.scroll(null);
106105
// batched reduce size is currently not set-able on a per-request basis as it is a query string parameter only
107106
searchRequest.setBatchedReduceSize(SearchRequest.DEFAULT_BATCHED_REDUCE_SIZE);
108107
SearchTemplateRequest searchTemplateRequest = new SearchTemplateRequest(searchRequest);

modules/reindex/src/main/java/org/elasticsearch/reindex/AbstractAsyncBulkByScrollAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.elasticsearch.script.Metadata;
4444
import org.elasticsearch.script.Script;
4545
import org.elasticsearch.script.ScriptService;
46-
import org.elasticsearch.search.Scroll;
4746
import org.elasticsearch.search.builder.SearchSourceBuilder;
4847
import org.elasticsearch.search.sort.SortBuilder;
4948
import org.elasticsearch.threadpool.ThreadPool;
@@ -212,7 +211,7 @@ static <Request extends AbstractBulkByScrollRequest<Request>> SearchRequest prep
212211
if (mainRequest.getMaxDocs() != MAX_DOCS_ALL_MATCHES
213212
&& mainRequest.getMaxDocs() <= preparedSearchRequest.source().size()
214213
&& mainRequest.isAbortOnVersionConflict()) {
215-
preparedSearchRequest.scroll((Scroll) null);
214+
preparedSearchRequest.scroll(null);
216215
}
217216

218217
return preparedSearchRequest;

modules/reindex/src/main/java/org/elasticsearch/reindex/remote/RemoteRequestBuilders.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
5353
Request request = new Request("POST", path.toString());
5454

5555
if (searchRequest.scroll() != null) {
56-
TimeValue keepAlive = searchRequest.scroll().keepAlive();
56+
TimeValue keepAlive = searchRequest.scroll();
5757
// V_5_0_0
5858
if (remoteVersion.before(Version.fromId(5000099))) {
5959
/* Versions of Elasticsearch before 5.0 couldn't parse nanos or micros

modules/reindex/src/main/java/org/elasticsearch/reindex/remote/RemoteScrollableHitSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private void onStartResponse(RejectAwareActionListener<Response> searchListener,
100100

101101
@Override
102102
protected void doStartNextScroll(String scrollId, TimeValue extraKeepAlive, RejectAwareActionListener<Response> searchListener) {
103-
TimeValue keepAlive = timeValueNanos(searchRequest.scroll().keepAlive().nanos() + extraKeepAlive.nanos());
103+
TimeValue keepAlive = timeValueNanos(searchRequest.scroll().nanos() + extraKeepAlive.nanos());
104104
execute(RemoteRequestBuilders.scroll(scrollId, keepAlive, remoteVersion), RESPONSE_PARSER, searchListener);
105105
}
106106

modules/reindex/src/test/java/org/elasticsearch/reindex/AsyncBulkByScrollActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ protected RequestWrapper<?> buildRequest(Hit doc) {
597597
capturedCommand.get().run();
598598

599599
// So the next request is going to have to wait an extra 100 seconds or so (base was 10 seconds, so 110ish)
600-
assertThat(client.lastScroll.get().request.scroll().keepAlive().seconds(), either(equalTo(110L)).or(equalTo(109L)));
600+
assertThat(client.lastScroll.get().request.scroll().seconds(), either(equalTo(110L)).or(equalTo(109L)));
601601

602602
// Now we can simulate a response and check the delay that we used for the task
603603
if (randomBoolean()) {

modules/reindex/src/test/java/org/elasticsearch/reindex/ClientScrollableHitSourceTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,7 @@ public void testScrollKeepAlive() {
155155
);
156156

157157
hitSource.startNextScroll(timeValueSeconds(100));
158-
client.validateRequest(
159-
TransportSearchScrollAction.TYPE,
160-
(SearchScrollRequest r) -> assertEquals(r.scroll().keepAlive().seconds(), 110)
161-
);
158+
client.validateRequest(TransportSearchScrollAction.TYPE, (SearchScrollRequest r) -> assertEquals(r.scroll().seconds(), 110));
162159
}
163160

164161
private SearchResponse createSearchResponse() {

server/src/internalClusterTest/java/org/elasticsearch/search/slice/SearchSliceIT.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.elasticsearch.common.bytes.BytesReference;
2525
import org.elasticsearch.common.settings.Settings;
2626
import org.elasticsearch.core.TimeValue;
27-
import org.elasticsearch.search.Scroll;
2827
import org.elasticsearch.search.SearchHit;
2928
import org.elasticsearch.search.builder.PointInTimeBuilder;
3029
import org.elasticsearch.search.sort.ShardDocSortField;
@@ -97,14 +96,14 @@ public void testSearchSort() throws Exception {
9796
int fetchSize = randomIntBetween(10, 100);
9897
// test _doc sort
9998
SearchRequestBuilder request = prepareSearch("test").setQuery(matchAllQuery())
100-
.setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
99+
.setScroll(TimeValue.timeValueSeconds(10))
101100
.setSize(fetchSize)
102101
.addSort(SortBuilders.fieldSort("_doc"));
103102
assertSearchSlicesWithScroll(request, field, max, numDocs);
104103

105104
// test numeric sort
106105
request = prepareSearch("test").setQuery(matchAllQuery())
107-
.setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
106+
.setScroll(TimeValue.timeValueSeconds(10))
108107
.addSort(SortBuilders.fieldSort("random_int"))
109108
.setSize(fetchSize);
110109
assertSearchSlicesWithScroll(request, field, max, numDocs);
@@ -121,7 +120,7 @@ public void testWithPreferenceAndRoutings() throws Exception {
121120
int max = randomIntBetween(2, numShards * 3);
122121
int fetchSize = randomIntBetween(10, 100);
123122
SearchRequestBuilder request = prepareSearch("test").setQuery(matchAllQuery())
124-
.setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
123+
.setScroll(TimeValue.timeValueSeconds(10))
125124
.setSize(fetchSize)
126125
.setPreference("_shards:1,4")
127126
.addSort(SortBuilders.fieldSort("_doc"));
@@ -133,7 +132,7 @@ public void testWithPreferenceAndRoutings() throws Exception {
133132
int max = randomIntBetween(2, numShards * 3);
134133
int fetchSize = randomIntBetween(10, 100);
135134
SearchRequestBuilder request = prepareSearch("test").setQuery(matchAllQuery())
136-
.setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
135+
.setScroll(TimeValue.timeValueSeconds(10))
137136
.setSize(fetchSize)
138137
.setRouting("foo", "bar")
139138
.addSort(SortBuilders.fieldSort("_doc"));
@@ -151,7 +150,7 @@ public void testWithPreferenceAndRoutings() throws Exception {
151150
int max = randomIntBetween(2, numShards * 3);
152151
int fetchSize = randomIntBetween(10, 100);
153152
SearchRequestBuilder request = prepareSearch("alias1", "alias3").setQuery(matchAllQuery())
154-
.setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
153+
.setScroll(TimeValue.timeValueSeconds(10))
155154
.setSize(fetchSize)
156155
.addSort(SortBuilders.fieldSort("_doc"));
157156
assertSearchSlicesWithScroll(request, "_id", max, numDocs);
@@ -176,7 +175,7 @@ private void assertSearchSlicesWithScroll(SearchRequestBuilder request, String f
176175
searchResponse.decRef();
177176
searchResponse = client().prepareSearchScroll("test")
178177
.setScrollId(scrollId)
179-
.setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
178+
.setScroll(TimeValue.timeValueSeconds(10))
180179
.get();
181180
scrollId = searchResponse.getScrollId();
182181
totalResults += searchResponse.getHits().getHits().length;
@@ -271,7 +270,7 @@ public void testInvalidFields() throws Exception {
271270
SearchPhaseExecutionException exc = expectThrows(
272271
SearchPhaseExecutionException.class,
273272
prepareSearch("test").setQuery(matchAllQuery())
274-
.setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
273+
.setScroll(TimeValue.timeValueSeconds(10))
275274
.slice(new SliceBuilder("invalid_random_int", 0, 10))
276275

277276
);
@@ -282,7 +281,7 @@ public void testInvalidFields() throws Exception {
282281
exc = expectThrows(
283282
SearchPhaseExecutionException.class,
284283
prepareSearch("test").setQuery(matchAllQuery())
285-
.setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
284+
.setScroll(TimeValue.timeValueSeconds(10))
286285
.slice(new SliceBuilder("invalid_random_kw", 0, 10))
287286
);
288287
rootCause = findRootCause(exc);

server/src/main/java/org/elasticsearch/action/search/CanMatchNodeRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.elasticsearch.core.TimeValue;
2222
import org.elasticsearch.index.query.QueryBuilder;
2323
import org.elasticsearch.index.shard.ShardId;
24-
import org.elasticsearch.search.Scroll;
2524
import org.elasticsearch.search.aggregations.AggregationBuilder;
2625
import org.elasticsearch.search.builder.SearchSourceBuilder;
2726
import org.elasticsearch.search.builder.SubSearchSourceBuilder;
@@ -49,7 +48,8 @@ public class CanMatchNodeRequest extends TransportRequest implements IndicesRequ
4948
private final SearchType searchType;
5049
private final Boolean requestCache;
5150
private final boolean allowPartialSearchResults;
52-
private final Scroll scroll;
51+
@Nullable
52+
private final TimeValue scroll;
5353
private final int numberOfShards;
5454
private final long nowInMillis;
5555
@Nullable
@@ -195,7 +195,7 @@ public CanMatchNodeRequest(StreamInput in) throws IOException {
195195
);
196196
}
197197
}
198-
scroll = in.readOptionalWriteable(Scroll::new);
198+
scroll = in.readOptionalTimeValue();
199199
requestCache = in.readOptionalBoolean();
200200
allowPartialSearchResults = in.readBoolean();
201201
numberOfShards = in.readVInt();
@@ -216,7 +216,7 @@ public void writeTo(StreamOutput out) throws IOException {
216216
// types not supported so send an empty array to previous versions
217217
out.writeStringArray(Strings.EMPTY_ARRAY);
218218
}
219-
out.writeOptionalWriteable(scroll);
219+
out.writeOptionalTimeValue(scroll);
220220
out.writeOptionalBoolean(requestCache);
221221
out.writeBoolean(allowPartialSearchResults);
222222
out.writeVInt(numberOfShards);

server/src/main/java/org/elasticsearch/action/search/SearchRequest.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.elasticsearch.index.mapper.SourceLoader;
2525
import org.elasticsearch.index.query.QueryRewriteContext;
2626
import org.elasticsearch.index.query.Rewriteable;
27-
import org.elasticsearch.search.Scroll;
2827
import org.elasticsearch.search.builder.PointInTimeBuilder;
2928
import org.elasticsearch.search.builder.SearchSourceBuilder;
3029
import org.elasticsearch.search.internal.SearchContext;
@@ -82,7 +81,7 @@ public class SearchRequest extends ActionRequest implements IndicesRequest.Repla
8281

8382
private Boolean allowPartialSearchResults;
8483

85-
private Scroll scroll;
84+
private TimeValue scrollKeepAlive;
8685

8786
private int batchedReduceSize = DEFAULT_BATCHED_REDUCE_SIZE;
8887

@@ -206,7 +205,7 @@ private SearchRequest(
206205
this.preFilterShardSize = searchRequest.preFilterShardSize;
207206
this.requestCache = searchRequest.requestCache;
208207
this.routing = searchRequest.routing;
209-
this.scroll = searchRequest.scroll;
208+
this.scrollKeepAlive = searchRequest.scrollKeepAlive;
210209
this.searchType = searchRequest.searchType;
211210
this.source = searchRequest.source;
212211
this.localClusterAlias = localClusterAlias;
@@ -229,7 +228,7 @@ public SearchRequest(StreamInput in) throws IOException {
229228
indices = in.readStringArray();
230229
routing = in.readOptionalString();
231230
preference = in.readOptionalString();
232-
scroll = in.readOptionalWriteable(Scroll::new);
231+
scrollKeepAlive = in.readOptionalTimeValue();
233232
source = in.readOptionalWriteable(SearchSourceBuilder::new);
234233
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
235234
// types no longer relevant so ignore
@@ -276,7 +275,7 @@ public void writeTo(StreamOutput out) throws IOException {
276275
out.writeStringArray(indices);
277276
out.writeOptionalString(routing);
278277
out.writeOptionalString(preference);
279-
out.writeOptionalWriteable(scroll);
278+
out.writeOptionalTimeValue(scrollKeepAlive);
280279
out.writeOptionalWriteable(source);
281280
if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) {
282281
// types not supported so send an empty array to previous versions
@@ -525,23 +524,16 @@ public String[] indices() {
525524
/**
526525
* If set, will enable scrolling of the search request.
527526
*/
528-
public Scroll scroll() {
529-
return scroll;
530-
}
531-
532-
/**
533-
* If set, will enable scrolling of the search request.
534-
*/
535-
public SearchRequest scroll(Scroll scroll) {
536-
this.scroll = scroll;
537-
return this;
527+
public TimeValue scroll() {
528+
return scrollKeepAlive;
538529
}
539530

540531
/**
541532
* If set, will enable scrolling of the search request for the specified timeout.
542533
*/
543534
public SearchRequest scroll(TimeValue keepAlive) {
544-
return scroll(new Scroll(keepAlive));
535+
this.scrollKeepAlive = keepAlive;
536+
return this;
545537
}
546538

547539
/**
@@ -681,7 +673,7 @@ public boolean hasKnnSearch() {
681673
}
682674

683675
public int resolveTrackTotalHitsUpTo() {
684-
return resolveTrackTotalHitsUpTo(scroll, source);
676+
return resolveTrackTotalHitsUpTo(scrollKeepAlive, source);
685677
}
686678

687679
/**
@@ -731,7 +723,7 @@ public SearchRequest rewrite(QueryRewriteContext ctx) throws IOException {
731723
return hasChanged ? new SearchRequest(this).source(source) : this;
732724
}
733725

734-
public static int resolveTrackTotalHitsUpTo(Scroll scroll, SearchSourceBuilder source) {
726+
public static int resolveTrackTotalHitsUpTo(TimeValue scroll, SearchSourceBuilder source) {
735727
if (scroll != null) {
736728
// no matter what the value of track_total_hits is
737729
return SearchContext.TRACK_TOTAL_HITS_ACCURATE;
@@ -752,8 +744,8 @@ public final String buildDescription() {
752744
Strings.arrayToDelimitedString(indices, ",", sb);
753745
sb.append("]");
754746
sb.append(", search_type[").append(searchType).append("]");
755-
if (scroll != null) {
756-
sb.append(", scroll[").append(scroll.keepAlive()).append("]");
747+
if (scrollKeepAlive != null) {
748+
sb.append(", scroll[").append(scrollKeepAlive).append("]");
757749
}
758750
if (source != null) {
759751
sb.append(", source[").append(source.toString(FORMAT_PARAMS)).append("]");
@@ -784,7 +776,7 @@ public boolean equals(Object o) {
784776
&& Objects.equals(preference, that.preference)
785777
&& Objects.equals(source, that.source)
786778
&& Objects.equals(requestCache, that.requestCache)
787-
&& Objects.equals(scroll, that.scroll)
779+
&& Objects.equals(scrollKeepAlive, that.scrollKeepAlive)
788780
&& Objects.equals(batchedReduceSize, that.batchedReduceSize)
789781
&& Objects.equals(maxConcurrentShardRequests, that.maxConcurrentShardRequests)
790782
&& Objects.equals(preFilterShardSize, that.preFilterShardSize)
@@ -805,7 +797,7 @@ public int hashCode() {
805797
preference,
806798
source,
807799
requestCache,
808-
scroll,
800+
scrollKeepAlive,
809801
indicesOptions,
810802
batchedReduceSize,
811803
maxConcurrentShardRequests,
@@ -836,7 +828,7 @@ public String toString() {
836828
+ ", requestCache="
837829
+ requestCache
838830
+ ", scroll="
839-
+ scroll
831+
+ scrollKeepAlive
840832
+ ", maxConcurrentShardRequests="
841833
+ maxConcurrentShardRequests
842834
+ ", batchedReduceSize="

server/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.core.TimeValue;
1717
import org.elasticsearch.index.query.QueryBuilder;
1818
import org.elasticsearch.script.Script;
19-
import org.elasticsearch.search.Scroll;
2019
import org.elasticsearch.search.aggregations.AggregationBuilder;
2120
import org.elasticsearch.search.aggregations.PipelineAggregationBuilder;
2221
import org.elasticsearch.search.builder.PointInTimeBuilder;
@@ -62,14 +61,6 @@ public SearchRequestBuilder setSearchType(SearchType searchType) {
6261
return this;
6362
}
6463

65-
/**
66-
* If set, will enable scrolling of the search request.
67-
*/
68-
public SearchRequestBuilder setScroll(Scroll scroll) {
69-
request.scroll(scroll);
70-
return this;
71-
}
72-
7364
/**
7465
* If set, will enable scrolling of the search request for the specified timeout.
7566
*/

0 commit comments

Comments
 (0)