Apache Solr open-source search software
truncate new segment files before use: LUCENE-415
Yonik Seeley66a23a87867e
diff --git a/CHANGES.txt b/CHANGES.txtindex ace80b1cf07..fb982034747 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -47,6 +47,10 @@ Bug fixes8. LUCENE-607: ParallelReader's TermEnum fails to advance properly tonew fields (Chuck Williams, Christian Kohlschuetter via Yonik Seeley)++ 9. LUCENE-415: A previously unclean shutdown during indexing can cause+ a non-empty segment file to be re-used, causing index corruption.+ (Andy Hind via Yonik Seeley)Optimizationsdiff --git a/src/java/org/apache/lucene/store/FSDirectory.java b/src/java/org/apache/lucene/store/FSDirectory.javaindex 88cbe5ea457..bea618a5c4a 100644--- a/src/java/org/apache/lucene/store/FSDirectory.java+++ b/src/java/org/apache/lucene/store/FSDirectory.java@@ -496,6 +496,13 @@ class FSIndexOutput extends BufferedIndexOutput {public FSIndexOutput(File path) throws IOException {file = new RandomAccessFile(path, "rw");+ if (file.length() == 0) {+ // This can happen if there was a previous crash / unclean shutdown that+ // left files around, then we end up re-using a segment name.+ // If we have a logging framework in the future, a warning here might be+ // a good idea.+ file.setLength(0);+ }}/** output methods: */