lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r683206 - in /lucene/java/trunk/src/java/org/apache/lucene/index: TermsHash.java TermsHashPerThread.java
Date Wed, 06 Aug 2008 09:56:01 GMT
Author: mikemccand
Date: Wed Aug  6 02:56:00 2008
New Revision: 683206

URL: http://svn.apache.org/viewvc?rev=683206&view=rev
Log:
LUCENE-1301: fix cause of rare NPE in TestIndexWriterExceptions

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/TermsHash.java
    lucene/java/trunk/src/java/org/apache/lucene/index/TermsHashPerThread.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/TermsHash.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/TermsHash.java?rev=683206&r1=683205&r2=683206&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/TermsHash.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/TermsHash.java Wed Aug  6 02:56:00
2008
@@ -44,11 +44,11 @@
   final int postingsFreeChunk;
   final DocumentsWriter docWriter;
   
-  TermsHash primaryTermsHash;
+  private TermsHash primaryTermsHash;
 
-  RawPostingList[] postingsFreeList = new RawPostingList[1];
-  int postingsFreeCount;
-  int postingsAllocCount;
+  private RawPostingList[] postingsFreeList = new RawPostingList[1];
+  private int postingsFreeCount;
+  private int postingsAllocCount;
   boolean trackAllocations;
 
   public TermsHash(final DocumentsWriter docWriter, boolean trackAllocations, final TermsHashConsumer
consumer, final TermsHash nextTermsHash) {
@@ -176,17 +176,6 @@
     return any;
   }
 
-  // USE ONLY FOR DEBUGGING!
-  /*
-    public String getPostingText() {
-    char[] text = charPool.buffers[p.textStart >> CHAR_BLOCK_SHIFT];
-    int upto = p.textStart & CHAR_BLOCK_MASK;
-    while(text[upto] != 0xffff)
-    upto++;
-    return new String(text, p.textStart, upto-(p.textStart & BYTE_BLOCK_MASK));
-    }
-  */
-
   synchronized public void recyclePostings(final RawPostingList[] postings, final int numPostings)
{
 
     assert postings.length >= numPostings;
@@ -219,19 +208,21 @@
                      postings, 0, numToCopy);
 
     // Directly allocate the remainder if any
-    if (numToCopy < postings.length) {
+    if (numToCopy != postings.length) {
       final int extra = postings.length - numToCopy;
       final int newPostingsAllocCount = postingsAllocCount + extra;
 
-      if (newPostingsAllocCount > postingsFreeList.length)
-        postingsFreeList = new RawPostingList[ArrayUtil.getNextSize(newPostingsAllocCount)];
-
       consumer.createPostings(postings, numToCopy, extra);
       assert docWriter.writer.testPoint("TermsHash.getPostings after create");
       postingsAllocCount += extra;
 
       if (trackAllocations)
         docWriter.bytesAllocated(extra * bytesPerPosting);
+
+      if (newPostingsAllocCount > postingsFreeList.length)
+        // Pre-allocate the postingsFreeList so it's large
+        // enough to hold all postings we've given out
+        postingsFreeList = new RawPostingList[ArrayUtil.getNextSize(newPostingsAllocCount)];
     }
 
     postingsFreeCount -= numToCopy;

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/TermsHashPerThread.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/TermsHashPerThread.java?rev=683206&r1=683205&r2=683206&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/TermsHashPerThread.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/TermsHashPerThread.java Wed Aug  6
02:56:00 2008
@@ -74,8 +74,13 @@
     assert freePostingsCount == 0;
     termsHash.getPostings(freePostings);
     freePostingsCount = freePostings.length;
-    for(int i=0;i<freePostingsCount;i++)
-      assert freePostings[i] != null;
+    assert noNullPostings(freePostings, freePostingsCount, "consumer=" + consumer);
+  }
+
+  private static boolean noNullPostings(RawPostingList[] postings, int count, String details)
{
+    for(int i=0;i<count;i++)
+      assert postings[i] != null: "postings[" + i + "] of " + count + " is null: " + details;
+    return true;
   }
 
   public void startDocument() throws IOException {



Mime
View raw message