You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by do...@apache.org on 2012/02/07 07:59:56 UTC

svn commit: r1241363 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/contrib/CHANGES.txt lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/Sort.java solr/

Author: doronc
Date: Tue Feb  7 06:59:56 2012
New Revision: 1241363

URL: http://svn.apache.org/viewvc?rev=1241363&view=rev
Log:
LUCENE-3746: suggest.fst.Sort.BufferSize should not automatically fail just because of freeMemory() - merge from trunk.

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt
    lucene/dev/branches/branch_3x/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/Sort.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt?rev=1241363&r1=1241362&r2=1241363&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt Tue Feb  7 06:59:56 2012
@@ -84,6 +84,7 @@ Bug Fixes
    children (such docs will never match, but BJQ was tripping an
    assert if such a parent doc was the first doc in the segment).
    (Shay Banon, Mike McCandless)
+   
  * LUCENE-3609: Fix regression in BooleanFilter, introduced in Lucene 3.5,
    to correctly handle minShouldMatch behaviour of previous versions.
    (Shay Banon, Uwe Schindler)
@@ -114,6 +115,10 @@ Bug Fixes
  
  * LUCENE-3719: FVH: slow performance on very large queries.
    (Igor Motov via Koji Sekiguchi)
+   
+ * LUCENE-3746: Spell checker's sort could fail on low JVM free-heap-memory
+   even though max-memory settings allowed to allocate more.
+   (Doron Cohen)
 
 Documentation
 

Modified: lucene/dev/branches/branch_3x/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/Sort.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/Sort.java?rev=1241363&r1=1241362&r2=1241363&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/Sort.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/spellchecker/src/java/org/apache/lucene/search/suggest/fst/Sort.java Tue Feb  7 06:59:56 2012
@@ -49,6 +49,12 @@ public final class Sort {
   public final static int MIN_BUFFER_SIZE_MB = 32;
 
   /**
+   * Absolute minimum required buffer size for sorting.
+   */
+  public static final int ABSOLUTE_MIN_SORT_BUFFER_SIZE = MB / 2;
+  private static final String MIN_BUFFER_SIZE_MSG = "At least 0.5MB RAM buffer is needed";
+
+  /**
    * Maximum number of temporary files before doing an intermediate merge.
    */
   public final static int MAX_TEMPFILES = 128;
@@ -82,11 +88,26 @@ public final class Sort {
   
     /** 
      * Approximately half of the currently available free heap, but no less
-     * than {@link #MIN_BUFFER_SIZE_MB}.
+     * than {@link #MIN_BUFFER_SIZE_MB}. However if current heap allocation 
+     * is insufficient for sorting consult with max allowed heap size. 
      */
     public static BufferSize automatic() {
-      long freeHeap = Runtime.getRuntime().freeMemory();
-      return new BufferSize(Math.min(MIN_BUFFER_SIZE_MB * MB, freeHeap / 2));
+      Runtime rt = Runtime.getRuntime();
+      
+      // take sizes in "conservative" order
+      long max = rt.maxMemory();
+      long total = rt.totalMemory();
+      long free = rt.freeMemory();
+
+      // by free mem (attempting to not grow the heap for this)
+      long half = free/2;
+      if (half >= ABSOLUTE_MIN_SORT_BUFFER_SIZE) { 
+        return new BufferSize(Math.min(MIN_BUFFER_SIZE_MB * MB, half));
+      }
+      
+      // by max mem (heap will grow)
+      half = (max - total) / 2;
+      return new BufferSize(Math.min(MIN_BUFFER_SIZE_MB * MB, half));
     }
   }
 
@@ -151,10 +172,8 @@ public final class Sort {
    * All-details constructor.
    */
   public Sort(BufferSize ramBufferSize, File tempDirectory, int maxTempfiles) {
-    if (ramBufferSize.bytes < 1024 * 1024 / 2) {
-      // Half-meg buffer is the absolute minimum.
-      throw new IllegalArgumentException("At least 0.5MB RAM buffer is needed: "
-          + ramBufferSize.bytes);
+    if (ramBufferSize.bytes < ABSOLUTE_MIN_SORT_BUFFER_SIZE) {
+      throw new IllegalArgumentException(MIN_BUFFER_SIZE_MSG + ": " + ramBufferSize.bytes);
     }
     
     if (maxTempfiles < 2) {