clean files that are in the store but not in the gateway

This commit is contained in:
kimchy 2010-06-23 12:21:04 +03:00
parent d5f35f3cee
commit a7fdd36f6e
1 changed files with 16 additions and 0 deletions

View File

@ -472,6 +472,7 @@ public abstract class BlobStoreIndexShardGateway extends AbstractIndexShardCompo
throw new IndexShardGatewayRecoveryException(shardId, "Failed to recovery index", failures.get(0)); throw new IndexShardGatewayRecoveryException(shardId, "Failed to recovery index", failures.get(0));
} }
// read the gateway data persisted
long version = -1; long version = -1;
try { try {
if (IndexReader.indexExists(store.directory())) { if (IndexReader.indexExists(store.directory())) {
@ -481,6 +482,21 @@ public abstract class BlobStoreIndexShardGateway extends AbstractIndexShardCompo
throw new IndexShardGatewayRecoveryException(shardId(), "Failed to fetch index version after copying it over", e); throw new IndexShardGatewayRecoveryException(shardId(), "Failed to fetch index version after copying it over", e);
} }
/// now, go over and clean files that are in the store, but were not in the gateway
try {
for (String storeFile : store.directory().listAll()) {
if (!blobs.containsKey(storeFile)) {
try {
store.directory().deleteFile(storeFile);
} catch (IOException e) {
// ignore
}
}
}
} catch (IOException e) {
// ignore
}
return new RecoveryStatus.Index(version, filesToRecover.size(), new ByteSizeValue(totalSize, ByteSizeUnit.BYTES), TimeValue.timeValueMillis(throttlingWaitTime.get())); return new RecoveryStatus.Index(version, filesToRecover.size(), new ByteSizeValue(totalSize, ByteSizeUnit.BYTES), TimeValue.timeValueMillis(throttlingWaitTime.get()));
} }