externalize all checks for checksum file to a util method

This commit is contained in:
Shay Banon 2011-08-14 02:19:17 +03:00
parent b3d1525e41
commit b0caf0d761
3 changed files with 11 additions and 5 deletions

View File

@ -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) {

View File

@ -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<String, StoreFileMetaData> 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<String, String> 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);

View File

@ -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())));