diff --git a/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java b/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java index aaadf603e46..cd160dea539 100644 --- a/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java +++ b/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java @@ -203,7 +203,12 @@ public class TransportMultiPercolateAction extends TransportAction= 1; if (expectedOperationsPerItem[item.slot()].decrementAndGet() == 0) { - reduce(item.slot(), percolateRequests, expectedOperations, reducedResponses, listener, responsesByItemAndShard); + try { + reduce(item.slot(), percolateRequests, expectedOperations, reducedResponses, listener, responsesByItemAndShard); + } catch (Throwable t) { + // Don't let any failure bubble up, otherwise expectedOperationsPerItem will be decremented twice + listener.onFailure(t); + } } } } catch (Throwable e) { @@ -225,7 +230,7 @@ public class TransportMultiPercolateAction extends TransportAction= 1; + assert expectedOperationsPerItem[slot].get() >= 1 : "Caused by: " + e.getMessage(); if (expectedOperationsPerItem[slot].decrementAndGet() == 0) { reduce(slot, percolateRequests, expectedOperations, reducedResponses, listener, responsesByItemAndShard); } diff --git a/src/test/java/org/elasticsearch/test/integration/percolator/RecoveryPercolatorTests.java b/src/test/java/org/elasticsearch/test/integration/percolator/RecoveryPercolatorTests.java index 61a3aa70d07..8fd1c98a6f3 100644 --- a/src/test/java/org/elasticsearch/test/integration/percolator/RecoveryPercolatorTests.java +++ b/src/test/java/org/elasticsearch/test/integration/percolator/RecoveryPercolatorTests.java @@ -363,6 +363,7 @@ public class RecoveryPercolatorTests extends AbstractNodesTests { for (MultiPercolateResponse.Item item : response) { assertThat(item.isFailure(), equalTo(false)); assertNoFailures(item.getResponse()); + assertThat(item.getResponse().getSuccessfulShards(), equalTo(2)); assertThat(item.getResponse().getCount(), equalTo((long) numQueries)); assertThat(item.getResponse().getMatches().length, equalTo(numQueries)); } @@ -382,6 +383,7 @@ public class RecoveryPercolatorTests extends AbstractNodesTests { .execute().actionGet(); } assertNoFailures(response); + assertThat(response.getSuccessfulShards(), equalTo(2)); assertThat(response.getCount(), equalTo((long) numQueries)); assertThat(response.getMatches().length, equalTo(numQueries)); }