You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by yo...@apache.org on 2006/06/20 23:28:42 UTC

svn commit: r415808 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/store/FSDirectory.java

Author: yonik
Date: Tue Jun 20 14:28:42 2006
New Revision: 415808

URL: http://svn.apache.org/viewvc?rev=415808&view=rev
Log:
truncate new segment files before use: LUCENE-415

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=415808&r1=415807&r2=415808&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Jun 20 14:28:42 2006
@@ -47,6 +47,10 @@
 
  8. LUCENE-607: ParallelReader's TermEnum fails to advance properly to
     new 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)
         
 Optimizations
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?rev=415808&r1=415807&r2=415808&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Tue Jun 20 14:28:42 2006
@@ -496,6 +496,13 @@
 
   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: */