|
21 | 21 | import org.apache.logging.log4j.Logger;
|
22 | 22 | import org.apache.logging.log4j.message.ParameterizedMessage;
|
23 | 23 | import org.apache.lucene.store.AlreadyClosedException;
|
| 24 | +import org.elasticsearch.Assertions; |
24 | 25 | import org.elasticsearch.ElasticsearchException;
|
25 | 26 | import org.elasticsearch.ExceptionsHelper;
|
26 | 27 | import org.elasticsearch.action.ActionListener;
|
@@ -203,15 +204,20 @@ public String toString() {
|
203 | 204 | }
|
204 | 205 |
|
205 | 206 | 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())); |
206 | 209 | 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 | + } |
208 | 218 | // we are no longer the primary, fail ourselves and start over
|
209 | 219 | message = String.format(Locale.ROOT, "primary shard [%s] was demoted while failing replica shard", primary.routingEntry());
|
210 | 220 | 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()); |
215 | 221 | }
|
216 | 222 | finishAsFailed(new RetryOnPrimaryException(primary.routingEntry().shardId(), message, failure));
|
217 | 223 | }
|
|
0 commit comments