diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/recovery/RecoveryTarget.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/recovery/RecoveryTarget.java index 54dfdcbd52f..d7438883692 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/recovery/RecoveryTarget.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/recovery/RecoveryTarget.java @@ -41,6 +41,7 @@ import org.elasticsearch.index.shard.IndexShardState; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.index.shard.service.InternalIndexShard; +import org.elasticsearch.index.store.support.AbstractStore; import org.elasticsearch.index.translog.Translog; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.indices.IndicesLifecycle; @@ -441,7 +442,8 @@ public class RecoveryTarget extends AbstractComponent { shard.store().writeChecksums(onGoingRecovery.checksums); for (String existingFile : shard.store().directory().listAll()) { - if (!request.snapshotFiles().contains(existingFile)) { + // don't delete snapshot file, or the checksums file (note, this is extra protection since the Store won't delete checksum) + if (!request.snapshotFiles().contains(existingFile) && !AbstractStore.isChecksum(existingFile)) { try { shard.store().directory().deleteFile(existingFile); } catch (Exception e) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/support/AbstractStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/support/AbstractStore.java index 167ebeb5d24..9b41217620c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/support/AbstractStore.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/support/AbstractStore.java @@ -53,6 +53,10 @@ public abstract class AbstractStore extends AbstractIndexShardComponent implemen static final String CHECKSUMS_PREFIX = "_checksums-"; + public static final boolean isChecksum(String name) { + return name.startsWith(CHECKSUMS_PREFIX); + } + protected final IndexStore indexStore; private volatile ImmutableMap filesMetadata = ImmutableMap.of(); @@ -100,7 +104,7 @@ public abstract class AbstractStore extends AbstractIndexShardComponent implemen String[] files = directory().listAll(); IOException lastException = null; for (String file : files) { - if (file.startsWith(CHECKSUMS_PREFIX)) { + if (isChecksum(file)) { ((StoreDirectory) directory()).deleteFileChecksum(file); } else { try { @@ -140,7 +144,7 @@ public abstract class AbstractStore extends AbstractIndexShardComponent implemen public static Map readChecksums(Directory dir) throws IOException { long lastFound = -1; for (String name : dir.listAll()) { - if (!name.startsWith(CHECKSUMS_PREFIX)) { + if (!isChecksum(name)) { continue; } long current = Long.parseLong(name.substring(CHECKSUMS_PREFIX.length())); @@ -316,7 +320,7 @@ public abstract class AbstractStore extends AbstractIndexShardComponent implemen @Override public void deleteFile(String name) throws IOException { // we don't allow to delete the checksums files, only using the deleteChecksum method - if (name.startsWith(CHECKSUMS_PREFIX)) { + if (isChecksum(name)) { return; } delegate.deleteFile(name); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java index 5dcca306757..ca9ea8cbc10 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java @@ -178,7 +178,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesOperatio if (file.getName().endsWith(".cks")) { continue; } - if (file.getName().startsWith("_checksums")) { + if (AbstractStore.isChecksum(file.getName())) { continue; } files.put(file.getName(), new StoreFileMetaData(file.getName(), file.length(), file.lastModified(), checksums.get(file.getName())));