Browse Source

Remove some dead code from SearchPhase and friends (#116645) (#118032)

The separate `onFailure` is unnecessary, just fail the phase like we do
elsewhere. Also make utility method static.
Armin Braun 10 months ago
parent
commit
171d7c4c8f

+ 1 - 8
server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java

@@ -764,7 +764,7 @@ abstract class AbstractSearchAsyncAction<Result extends SearchPhaseResult> exten
      * @see #onShardFailure(int, SearchShardTarget, Exception)
      * @see #onShardResult(SearchPhaseResult, SearchShardIterator)
      */
-    final void onPhaseDone() {  // as a tribute to @kimchy aka. finishHim()
+    private void onPhaseDone() {  // as a tribute to @kimchy aka. finishHim()
         executeNextPhase(this, this::getNextPhase);
     }
 
@@ -792,13 +792,6 @@ abstract class AbstractSearchAsyncAction<Result extends SearchPhaseResult> exten
         executor.execute(command);
     }
 
-    /**
-      * Notifies the top-level listener of the provided exception
-    */
-    public void onFailure(Exception e) {
-        listener.onFailure(e);
-    }
-
     /**
      * Builds an request for the initial search phase.
      *

+ 6 - 2
server/src/main/java/org/elasticsearch/action/search/ExpandSearchPhase.java

@@ -102,7 +102,7 @@ final class ExpandSearchPhase extends SearchPhase {
                 for (InnerHitBuilder innerHitBuilder : innerHitBuilders) {
                     MultiSearchResponse.Item item = it.next();
                     if (item.isFailure()) {
-                        context.onPhaseFailure(this, "failed to expand hits", item.getFailure());
+                        phaseFailure(item.getFailure());
                         return;
                     }
                     SearchHits innerHits = item.getResponse().getHits();
@@ -119,7 +119,11 @@ final class ExpandSearchPhase extends SearchPhase {
                 }
             }
             onPhaseDone();
-        }, context::onFailure));
+        }, this::phaseFailure));
+    }
+
+    private void phaseFailure(Exception ex) {
+        context.onPhaseFailure(this, "failed to expand hits", ex);
     }
 
     private static SearchSourceBuilder buildExpandSearchSourceBuilder(InnerHitBuilder options, CollapseBuilder innerCollapseBuilder) {

+ 0 - 5
server/src/test/java/org/elasticsearch/action/search/MockSearchPhaseContext.java

@@ -154,11 +154,6 @@ public final class MockSearchPhaseContext extends AbstractSearchAsyncAction<Sear
         }, shardIt);
     }
 
-    @Override
-    public void onFailure(Exception e) {
-        Assert.fail("should not be called");
-    }
-
     @Override
     public void sendReleaseSearchContext(ShardSearchContextId contextId, Transport.Connection connection, OriginalIndices originalIndices) {
         releasedSearchContexts.add(contextId);