19
19
package org .elasticsearch .search ;
20
20
21
21
import com .carrotsearch .hppc .IntArrayList ;
22
-
23
22
import org .apache .lucene .search .Query ;
24
23
import org .apache .lucene .store .AlreadyClosedException ;
25
24
import org .elasticsearch .ElasticsearchException ;
51
50
import org .elasticsearch .index .query .QueryRewriteContext ;
52
51
import org .elasticsearch .index .query .QueryShardContext ;
53
52
import org .elasticsearch .index .query .TermQueryBuilder ;
53
+ import org .elasticsearch .index .search .stats .SearchStats ;
54
54
import org .elasticsearch .index .shard .IndexShard ;
55
55
import org .elasticsearch .index .shard .SearchOperationListener ;
56
56
import org .elasticsearch .index .shard .ShardId ;
@@ -226,6 +226,7 @@ public void testSearchWhileIndexDeleted() throws InterruptedException {
226
226
AtomicBoolean running = new AtomicBoolean (true );
227
227
CountDownLatch startGun = new CountDownLatch (1 );
228
228
Semaphore semaphore = new Semaphore (Integer .MAX_VALUE );
229
+
229
230
final Thread thread = new Thread () {
230
231
@ Override
231
232
public void run () {
@@ -261,12 +262,16 @@ public void onFailure(Exception e) {
261
262
try {
262
263
final int rounds = scaledRandomIntBetween (100 , 10000 );
263
264
SearchRequest searchRequest = new SearchRequest ().allowPartialSearchResults (true );
265
+ SearchRequest scrollSearchRequest = new SearchRequest ().allowPartialSearchResults (true )
266
+ .scroll (new Scroll (TimeValue .timeValueMinutes (1 )));
264
267
for (int i = 0 ; i < rounds ; i ++) {
265
268
try {
266
269
try {
267
270
PlainActionFuture <SearchPhaseResult > result = new PlainActionFuture <>();
271
+ final boolean useScroll = randomBoolean ();
268
272
service .executeQueryPhase (
269
- new ShardSearchLocalRequest (searchRequest , indexShard .shardId (), 1 ,
273
+ new ShardSearchLocalRequest (useScroll ? scrollSearchRequest : searchRequest ,
274
+ indexShard .shardId (), 1 ,
270
275
new AliasFilter (null , Strings .EMPTY_ARRAY ), 1.0f , -1 , null , null ),
271
276
new SearchTask (123L , "" , "" , "" , null , Collections .emptyMap ()), result );
272
277
SearchPhaseResult searchPhaseResult = result .get ();
@@ -276,6 +281,9 @@ public void onFailure(Exception e) {
276
281
PlainActionFuture <FetchSearchResult > listener = new PlainActionFuture <>();
277
282
service .executeFetchPhase (req , new SearchTask (123L , "" , "" , "" , null , Collections .emptyMap ()), listener );
278
283
listener .get ();
284
+ if (useScroll ) {
285
+ service .freeContext (searchPhaseResult .getRequestId ());
286
+ }
279
287
} catch (ExecutionException ex ) {
280
288
assertThat (ex .getCause (), instanceOf (RuntimeException .class ));
281
289
throw ((RuntimeException )ex .getCause ());
@@ -293,6 +301,13 @@ public void onFailure(Exception e) {
293
301
thread .join ();
294
302
semaphore .acquire (Integer .MAX_VALUE );
295
303
}
304
+
305
+ assertEquals (0 , service .getActiveContexts ());
306
+
307
+ SearchStats .Stats totalStats = indexShard .searchStats ().getTotal ();
308
+ assertEquals (0 , totalStats .getQueryCurrent ());
309
+ assertEquals (0 , totalStats .getScrollCurrent ());
310
+ assertEquals (0 , totalStats .getFetchCurrent ());
296
311
}
297
312
298
313
public void testTimeout () throws IOException {
0 commit comments