67
67
import org .opensearch .common .annotation .PublicApi ;
68
68
import org .opensearch .common .lease .Releasable ;
69
69
import org .opensearch .common .lucene .search .TopDocsAndMaxScore ;
70
+ import org .opensearch .core .common .breaker .CircuitBreakingException ;
70
71
import org .opensearch .search .DocValueFormat ;
71
72
import org .opensearch .search .SearchService ;
72
73
import org .opensearch .search .dfs .AggregatedDfs ;
@@ -269,6 +270,11 @@ public void search(
269
270
270
271
@ Override
271
272
protected void search (List <LeafReaderContext > leaves , Weight weight , Collector collector ) throws IOException {
273
+
274
+ if (searchContext .isCircuitBreakerTripped ()) {
275
+ return ;
276
+ }
277
+
272
278
// Time series based workload by default traverses segments in desc order i.e. latest to the oldest order.
273
279
// This is actually beneficial for search queries to start search on latest segments first for time series workload.
274
280
// That can slow down ASC order queries on timestamp workload. So to avoid that slowdown, we will reverse leaf
@@ -297,6 +303,9 @@ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collecto
297
303
if (canMatch (ctx ) == false ) {
298
304
return ;
299
305
}
306
+ if (searchContext .isCircuitBreakerTripped ()) {
307
+ return ;
308
+ }
300
309
301
310
final LeafCollector leafCollector ;
302
311
try {
@@ -315,6 +324,9 @@ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collecto
315
324
} catch (QueryPhase .TimeExceededException e ) {
316
325
searchContext .setSearchTimedOut (true );
317
326
return ;
327
+ } catch (CircuitBreakingException e ) {
328
+ searchContext .setCircuitBreakerTripped (true );
329
+ return ;
318
330
}
319
331
// catch early terminated exception and rethrow?
320
332
Bits liveDocs = ctx .reader ().getLiveDocs ();
@@ -330,6 +342,9 @@ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collecto
330
342
} catch (QueryPhase .TimeExceededException e ) {
331
343
searchContext .setSearchTimedOut (true );
332
344
return ;
345
+ } catch (CircuitBreakingException e ) {
346
+ searchContext .setCircuitBreakerTripped (true );
347
+ return ;
333
348
}
334
349
}
335
350
} else {
@@ -349,6 +364,9 @@ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collecto
349
364
} catch (QueryPhase .TimeExceededException e ) {
350
365
searchContext .setSearchTimedOut (true );
351
366
return ;
367
+ } catch (CircuitBreakingException e ) {
368
+ searchContext .setCircuitBreakerTripped (true );
369
+ return ;
352
370
}
353
371
}
354
372
}
0 commit comments