diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGateway.java index 24998fa2eef..5fb919f42ca 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGateway.java @@ -51,7 +51,7 @@ public interface IndexShardGateway extends IndexShardComponent, CloseableIndexCo /** * Recovers the state of the shard from the gateway. */ - void recover(RecoveryStatus recoveryStatus) throws IndexShardGatewayRecoveryException; + void recover(boolean indexShouldExists, RecoveryStatus recoveryStatus) throws IndexShardGatewayRecoveryException; /** * Snapshots the given shard into the gateway. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayRecoveryException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayRecoveryException.java index a087d53581a..99c76975992 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayRecoveryException.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayRecoveryException.java @@ -26,6 +26,10 @@ import org.elasticsearch.index.shard.ShardId; */ public class IndexShardGatewayRecoveryException extends IndexShardGatewayException { + public IndexShardGatewayRecoveryException(ShardId shardId, String msg) { + super(shardId, msg); + } + public IndexShardGatewayRecoveryException(ShardId shardId, String msg, Throwable cause) { super(shardId, msg, cause); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java index 98bbb9c66fc..c6db2f20c60 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java @@ -151,7 +151,7 @@ public class IndexShardGatewayService extends AbstractIndexShardComponent implem /** * Recovers the state of the shard from the gateway. */ - public void recover(final RecoveryListener listener) throws IndexShardGatewayRecoveryException, IgnoreGatewayRecoveryException { + public void recover(final boolean indexShouldExists, final RecoveryListener listener) throws IndexShardGatewayRecoveryException, IgnoreGatewayRecoveryException { if (indexShard.state() == IndexShardState.CLOSED) { // got closed on us, just ignore this recovery listener.onIgnoreRecovery("shard closed"); @@ -176,7 +176,7 @@ public class IndexShardGatewayService extends AbstractIndexShardComponent implem try { logger.debug("starting recovery from {} ...", shardGateway); - shardGateway.recover(recoveryStatus); + shardGateway.recover(indexShouldExists, recoveryStatus); lastIndexVersion = recoveryStatus.index().version(); lastTranslogId = -1; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java index a086283de60..de6656868a4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java @@ -24,7 +24,11 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.IndexOutput; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.common.blobstore.*; +import org.elasticsearch.common.blobstore.BlobContainer; +import org.elasticsearch.common.blobstore.BlobMetaData; +import org.elasticsearch.common.blobstore.BlobPath; +import org.elasticsearch.common.blobstore.BlobStore; +import org.elasticsearch.common.blobstore.ImmutableBlobContainer; import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.collect.Iterables; import org.elasticsearch.common.collect.Lists; @@ -36,7 +40,14 @@ import org.elasticsearch.common.lucene.store.ThreadSafeInputStreamIndexInput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.index.deletionpolicy.SnapshotIndexCommit; -import org.elasticsearch.index.gateway.*; +import org.elasticsearch.index.gateway.CommitPoint; +import org.elasticsearch.index.gateway.CommitPoints; +import org.elasticsearch.index.gateway.IndexGateway; +import org.elasticsearch.index.gateway.IndexShardGateway; +import org.elasticsearch.index.gateway.IndexShardGatewayRecoveryException; +import org.elasticsearch.index.gateway.IndexShardGatewaySnapshotFailedException; +import org.elasticsearch.index.gateway.RecoveryStatus; +import org.elasticsearch.index.gateway.SnapshotStatus; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; @@ -358,7 +369,7 @@ public abstract class BlobStoreIndexShardGateway extends AbstractIndexShardCompo } } - @Override public void recover(RecoveryStatus recoveryStatus) throws IndexShardGatewayRecoveryException { + @Override public void recover(boolean indexShouldExists, RecoveryStatus recoveryStatus) throws IndexShardGatewayRecoveryException { this.recoveryStatus = recoveryStatus; final ImmutableMap blobs; 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 a36997eea8e..f008039b28f 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 @@ -82,7 +82,7 @@ public class LocalIndexShardGateway extends AbstractIndexShardComponent implemen return recoveryStatus; } - @Override public void recover(RecoveryStatus recoveryStatus) throws IndexShardGatewayRecoveryException { + @Override public void recover(boolean indexShouldExists, RecoveryStatus recoveryStatus) throws IndexShardGatewayRecoveryException { recoveryStatus.index().startTime(System.currentTimeMillis()); long version = -1; long translogId = -1; @@ -95,6 +95,8 @@ public class LocalIndexShardGateway extends AbstractIndexShardComponent implemen } else { translogId = version; } + } else if (indexShouldExists) { + throw new IndexShardGatewayRecoveryException(shardId(), "shard allocated for local recovery (post api), should exists, but doesn't"); } } catch (IOException e) { throw new IndexShardGatewayRecoveryException(shardId(), "Failed to fetch index version after copying it over", e); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexShardGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexShardGateway.java index f34a4ff4a56..a8c32d9ed76 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexShardGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexShardGateway.java @@ -56,7 +56,7 @@ public class NoneIndexShardGateway extends AbstractIndexShardComponent implement return recoveryStatus; } - @Override public void recover(RecoveryStatus recoveryStatus) throws IndexShardGatewayRecoveryException { + @Override public void recover(boolean indexShouldExists, RecoveryStatus recoveryStatus) throws IndexShardGatewayRecoveryException { recoveryStatus().index().startTime(System.currentTimeMillis()); // in the none case, we simply start the shard // clean the store, there should be nothing there... 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 77afcedf1b7..277c87b91b0 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 @@ -492,12 +492,12 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent