delete files that are no longer used from the fs gateway

This commit is contained in:
kimchy 2010-03-05 22:46:15 +02:00
parent 729baa6859
commit 290ecd4c95
1 changed files with 20 additions and 3 deletions

View File

@ -70,11 +70,11 @@ public class FsIndexShardGateway extends AbstractIndexShardComponent implements
private final File locationTranslog;
private long lastIndexVersion;
private volatile long lastIndexVersion;
private long lastTranslogId = -1;
private volatile long lastTranslogId = -1;
private int lastTranslogSize;
private volatile int lastTranslogSize;
private RandomAccessFile translogFile;
@ -237,6 +237,23 @@ public class FsIndexShardGateway extends AbstractIndexShardComponent implements
new File(locationTranslog, "translog-" + lastTranslogId).delete();
}
// delete files that no longer exists in the index
if (indexDirty) {
File[] existingFiles = locationIndex.listFiles();
for (File existingFile : existingFiles) {
boolean found = false;
for (final String fileName : snapshotIndexCommit.getFiles()) {
if (existingFile.getName().equals(fileName)) {
found = true;
break;
}
}
if (!found) {
existingFile.delete();
}
}
}
lastIndexVersion = snapshotIndexCommit.getVersion();
lastTranslogId = translogSnapshot.translogId();