LUCENE-3418: fsync files during commit so on crash/power loss we don't corrumpt the index

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1165902 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2011-09-06 22:12:54 +00:00
parent 374538c68d
commit 9e1960350e
2 changed files with 7 additions and 2 deletions

View File

@ -581,6 +581,10 @@ Bug fixes
* LUCENE-3409: IndexWriter.deleteAll was failing to close pooled NRT
SegmentReaders, leading to unused files accumulating in the
Directory. (tal steier via Mike McCandless)
* LUCENE-3418: Lucene was failing to fsync index files on commit,
meaning a crash or power loss could easily corrupt the index (Mark
Miller, Robert Muir, Mike McCandless)
New Features

View File

@ -457,6 +457,7 @@ public abstract class FSDirectory extends Directory {
@Override
public void close() throws IOException {
parent.onIndexOutputClosed(this);
// only close the file if it has not been closed yet
if (isOpen) {
boolean success = false;
@ -468,12 +469,12 @@ public abstract class FSDirectory extends Directory {
if (!success) {
try {
file.close();
parent.onIndexOutputClosed(this);
} catch (Throwable t) {
// Suppress so we don't mask original exception
}
} else
} else {
file.close();
}
}
}
}