Skip to content

Commit 6afb094

Browse files
committed
assert transport exception
1 parent ab65f4b commit 6afb094

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

server/src/main/java/org/elasticsearch/action/support/replication/ReplicationOperation.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.logging.log4j.Logger;
2222
import org.apache.logging.log4j.message.ParameterizedMessage;
2323
import org.apache.lucene.store.AlreadyClosedException;
24+
import org.elasticsearch.Assertions;
2425
import org.elasticsearch.ElasticsearchException;
2526
import org.elasticsearch.ExceptionsHelper;
2627
import org.elasticsearch.action.ActionListener;
@@ -203,15 +204,20 @@ public String toString() {
203204
}
204205

205206
private void onNoLongerPrimary(Exception failure) {
207+
final boolean nodeIsClosing = failure instanceof NodeClosedException ||
208+
(failure instanceof TransportException && "TransportService is closed stopped can't send request".equals(failure.getMessage()));
206209
final String message;
207-
if (failure instanceof ShardStateAction.NoLongerPrimaryShardException) {
210+
if (nodeIsClosing) {
211+
message = String.format(Locale.ROOT, "primary node [%s] is shutting down while failing replica shard", primary.routingEntry());
212+
} else {
213+
if (Assertions.ENABLED) {
214+
if (failure instanceof ShardStateAction.NoLongerPrimaryShardException == false) {
215+
throw new AssertionError("unexpected failure", failure);
216+
}
217+
}
208218
// we are no longer the primary, fail ourselves and start over
209219
message = String.format(Locale.ROOT, "primary shard [%s] was demoted while failing replica shard", primary.routingEntry());
210220
primary.failShard(message, failure);
211-
} else {
212-
// these can occur if the node is shutting down and are okay any other exception here is not expected and merits investigation.
213-
assert failure instanceof NodeClosedException || failure instanceof TransportException : failure;
214-
message = String.format(Locale.ROOT, "primary node [%s] is shutting down while failing replica shard", primary.routingEntry());
215221
}
216222
finishAsFailed(new RetryOnPrimaryException(primary.routingEntry().shardId(), message, failure));
217223
}

server/src/test/java/org/elasticsearch/action/support/replication/ReplicationOperationTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.index.shard.ShardId;
4444
import org.elasticsearch.node.NodeClosedException;
4545
import org.elasticsearch.test.ESTestCase;
46+
import org.elasticsearch.transport.TransportException;
4647

4748
import java.util.ArrayList;
4849
import java.util.Collections;
@@ -201,6 +202,8 @@ public void testNoLongerPrimary() throws Exception {
201202
final Exception shardActionFailure;
202203
if (randomBoolean()) {
203204
shardActionFailure = new NodeClosedException(new DiscoveryNode("foo", buildNewFakeTransportAddress(), Version.CURRENT));
205+
} else if (randomBoolean()) {
206+
shardActionFailure = new TransportException("TransportService is closed stopped can't send request");
204207
} else {
205208
shardActionFailure = new ShardStateAction.NoLongerPrimaryShardException(failedReplica.shardId(), "the king is dead");
206209
}

server/src/test/java/org/elasticsearch/action/support/replication/TransportWriteActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ public void testReplicaProxy() throws InterruptedException, ExecutionException {
335335
assertFalse(success.get());
336336
assertNotNull(failure.get());
337337
} else {
338-
// simulated an "ignored" exception
338+
// simulated a node closing exception
339339
transport.handleRemoteError(shardFailedRequest.requestId,
340340
new NodeClosedException(state.nodes().getLocalNode()));
341341
assertFalse(success.get());
342-
assertNull(failure.get());
342+
assertNotNull(failure.get());
343343
}
344344
}
345345

0 commit comments

Comments
 (0)