lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r833886 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/DocumentsWriter.java src/test/org/apache/lucene/index/TestIndexWriter.java
Date Sun, 08 Nov 2009 15:35:56 GMT
Author: mikemccand
Date: Sun Nov  8 15:35:56 2009
New Revision: 833886

URL: http://svn.apache.org/viewvc?rev=833886&view=rev
Log:
LUCENE-2045: fix false FNFE

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=833886&r1=833885&r2=833886&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Sun Nov  8 15:35:56 2009
@@ -184,6 +184,10 @@
    char (U+FFFD) during indexing, to prevent silent index corruption.
    (Peter Keegan, Mike McCandless)
 
+ * LUCENE-2045: Fix silly FileNotFoundException hit if you enable
+   infoStream on IndexWriter and then add an empty document and commit
+   (Shai Erera via Mike McCandless)
+
 API Changes
 
  * Un-deprecate search(Weight weight, Filter filter, int n) from

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java?rev=833886&r1=833885&r2=833886&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java Sun Nov  8 15:35:56
2009
@@ -584,7 +584,8 @@
       consumer.flush(threads, flushState);
 
       if (infoStream != null) {
-        final long newSegmentSize = segmentSize(flushState.segmentName);
+        SegmentInfo si = new SegmentInfo(flushState.segmentName, flushState.numDocs, directory);
+        final long newSegmentSize = si.sizeInBytes();
         String message = "  oldRAMSize=" + numBytesUsed +
           " newFlushedSize=" + newSegmentSize +
           " docs/MB=" + nf.format(numDocsInRAM/(newSegmentSize/1024./1024.)) +
@@ -1138,24 +1139,6 @@
 
   NumberFormat nf = NumberFormat.getInstance();
 
-  // TODO FI: this is not flexible -- we can't hardwire
-  // extensions in here:
-  private long segmentSize(String segmentName) throws IOException {
-    // Used only when infoStream != null
-    assert infoStream != null;
-    
-    long size = directory.fileLength(segmentName + ".tii") +
-      directory.fileLength(segmentName + ".tis") +
-      directory.fileLength(segmentName + ".frq") +
-      directory.fileLength(segmentName + ".prx");
-
-    final String normFileName = segmentName + ".nrm";
-    if (directory.fileExists(normFileName))
-      size += directory.fileLength(normFileName);
-
-    return size;
-  }
-
   // Coarse estimates used to measure RAM usage of buffered deletes
   final static int OBJECT_HEADER_BYTES = 8;
   final static int POINTER_NUM_BYTE = Constants.JRE_IS_64BIT ? 8 : 4;

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=833886&r1=833885&r2=833886&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Sun Nov  8 15:35:56
2009
@@ -4572,4 +4572,17 @@
     _TestUtil.checkIndex(d);
     d.close();
   }
+
+  public void testNoDocsIndex() throws Throwable {
+    Directory dir = new MockRAMDirectory();
+    IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+    writer.setUseCompoundFile(false);
+    ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
+    writer.setInfoStream(new PrintStream(bos));
+    writer.addDocument(new Document());
+    writer.close();
+
+    _TestUtil.checkIndex(dir);
+    dir.close();
+  }
 }



Mime
View raw message