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 ;
52
51
import org .elasticsearch .index .query .QueryRewriteContext ;
53
52
import org .elasticsearch .index .query .QueryShardContext ;
54
53
import org .elasticsearch .index .query .TermQueryBuilder ;
54
+ import org .elasticsearch .index .search .stats .SearchStats ;
55
55
import org .elasticsearch .index .shard .IndexShard ;
56
56
import org .elasticsearch .index .shard .SearchOperationListener ;
57
57
import org .elasticsearch .index .shard .ShardId ;
@@ -229,6 +229,7 @@ public void testSearchWhileIndexDeleted() throws InterruptedException {
229
229
AtomicBoolean running = new AtomicBoolean (true );
230
230
CountDownLatch startGun = new CountDownLatch (1 );
231
231
Semaphore semaphore = new Semaphore (Integer .MAX_VALUE );
232
+
232
233
final Thread thread = new Thread () {
233
234
@ Override
234
235
public void run () {
@@ -267,10 +268,17 @@ public void onFailure(Exception e) {
267
268
try {
268
269
try {
269
270
PlainActionFuture <SearchPhaseResult > result = new PlainActionFuture <>();
270
- service .executeQueryPhase (
271
- new ShardSearchLocalRequest (indexShard .shardId (), 1 , SearchType .DEFAULT ,
271
+ final boolean useScroll = randomBoolean ();
272
+ ShardSearchLocalRequest shardRequest ;
273
+ if (useScroll ) {
274
+ shardRequest = new ShardScrollRequestTest (indexShard .shardId ());
275
+ } else {
276
+ shardRequest = new ShardSearchLocalRequest (indexShard .shardId (), 1 , SearchType .DEFAULT ,
272
277
new SearchSourceBuilder (), new String [0 ], false , new AliasFilter (null , Strings .EMPTY_ARRAY ), 1.0f ,
273
- true , null , null ),
278
+ true , null , null );
279
+ }
280
+ service .executeQueryPhase (
281
+ shardRequest ,
274
282
new SearchTask (123L , "" , "" , "" , null , Collections .emptyMap ()), result );
275
283
SearchPhaseResult searchPhaseResult = result .get ();
276
284
IntArrayList intCursors = new IntArrayList (1 );
@@ -279,6 +287,9 @@ public void onFailure(Exception e) {
279
287
PlainActionFuture <FetchSearchResult > listener = new PlainActionFuture <>();
280
288
service .executeFetchPhase (req , new SearchTask (123L , "" , "" , "" , null , Collections .emptyMap ()), listener );
281
289
listener .get ();
290
+ if (useScroll ) {
291
+ service .freeContext (searchPhaseResult .getRequestId ());
292
+ }
282
293
} catch (ExecutionException ex ) {
283
294
assertThat (ex .getCause (), instanceOf (RuntimeException .class ));
284
295
throw ((RuntimeException )ex .getCause ());
@@ -296,6 +307,13 @@ public void onFailure(Exception e) {
296
307
thread .join ();
297
308
semaphore .acquire (Integer .MAX_VALUE );
298
309
}
310
+
311
+ assertEquals (0 , service .getActiveContexts ());
312
+
313
+ SearchStats .Stats totalStats = indexShard .searchStats ().getTotal ();
314
+ assertEquals (0 , totalStats .getQueryCurrent ());
315
+ assertEquals (0 , totalStats .getScrollCurrent ());
316
+ assertEquals (0 , totalStats .getFetchCurrent ());
299
317
}
300
318
301
319
public void testTimeout () throws IOException {
0 commit comments