Skip to content

Apache Lucene open-source search software

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

Michael McCandless9e1960350ef2
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f4325c4c688..96fcb02f739 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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
diff --git a/lucene/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/src/java/org/apache/lucene/store/FSDirectory.java
index 7d5e7dec4da..2ba1138cbb8 100644
--- a/lucene/src/java/org/apache/lucene/store/FSDirectory.java
+++ b/lucene/src/java/org/apache/lucene/store/FSDirectory.java
@@ -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();
+ }
}
}
}