On full cluster restart, replicas transaction logs are not getting cleaned, closes #465.

This commit is contained in:
kimchy 2010-10-31 14:36:10 +02:00
parent b8fa68f97a
commit feb854b742
3 changed files with 26 additions and 0 deletions

View File

@ -464,6 +464,9 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
}
scheduleRefresherIfNeeded();
engine.refresh(new Engine.Refresh(true));
// clear unreferenced files
translog.clearUnreferenced();
}
public void performRecoveryOperation(Translog.Operation operation) throws ElasticSearchException {

View File

@ -87,6 +87,11 @@ public interface Translog extends IndexShardComponent {
*/
Snapshot snapshot(Snapshot snapshot);
/**
* Clears unreferenced transaclogs.
*/
void clearUnreferenced();
/**
* Sync's the translog.
*/

View File

@ -92,6 +92,24 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog
return new ByteSizeValue(0, ByteSizeUnit.BYTES);
}
@Override public void clearUnreferenced() {
synchronized (mutex) {
File[] files = location.listFiles();
if (files != null) {
for (File file : files) {
if (file.getName().equals("translog-" + id)) {
continue;
}
try {
file.delete();
} catch (Exception e) {
// ignore
}
}
}
}
}
@Override public void newTranslog() throws TranslogException {
synchronized (mutex) {
operationCounter.set(0);