diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexShardGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexShardGateway.java index 891056957d7..fe26f5ab9a7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexShardGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexShardGateway.java @@ -144,15 +144,24 @@ public class LocalIndexShardGateway extends AbstractIndexShardComponent implemen try { InputStreamStreamInput si = new InputStreamStreamInput(new FileInputStream(recoveringTranslogFile)); while (true) { - int opSize = si.readInt(); - Translog.Operation operation = TranslogStreams.readTranslogOperation(si); + Translog.Operation operation; + try { + int opSize = si.readInt(); + operation = TranslogStreams.readTranslogOperation(si); + } catch (EOFException e) { + // ignore, not properly written the last op + break; + } catch (IOException e) { + // ignore, not properly written last op + break; + } recoveryStatus.translog().addTranslogOperations(1); indexShard.performRecoveryOperation(operation); } - } catch (EOFException e) { - // ignore this exception, its fine - } catch (IOException e) { - // ignore this as well + } catch (Throwable e) { + // we failed to recovery, make sure to delete the translog file (and keep the recovering one) + indexShard.translog().close(true); + throw new IndexShardGatewayRecoveryException(shardId, "failed to recover shard", e); } indexShard.performRecoveryFinalization(true); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index a874a442c59..924201e0ea3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -539,7 +539,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent