lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject [lucene-solr] branch master updated: LUCENE-9115: NRTCachingDirectory shouldn't cache files of unknown size. (#1145)
Date Thu, 09 Jan 2020 14:15:41 GMT
This is an automated email from the ASF dual-hosted git repository.

jpountz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ad33c3  LUCENE-9115: NRTCachingDirectory shouldn't cache files of unknown size.
(#1145)
7ad33c3 is described below

commit 7ad33c3a98a15dfbf3d442a2c65b13fa2a748979
Author: Adrien Grand <jpountz@gmail.com>
AuthorDate: Thu Jan 9 15:15:30 2020 +0100

    LUCENE-9115: NRTCachingDirectory shouldn't cache files of unknown size. (#1145)
---
 lucene/CHANGES.txt                                 |  3 +++
 .../apache/lucene/store/NRTCachingDirectory.java   |  2 ++
 .../lucene/store/TestNRTCachingDirectory.java      | 30 ++++++++++++++++++++++
 3 files changed, 35 insertions(+)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 51d9475..fcc359f 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -123,6 +123,9 @@ Bug Fixes
 
 * LUCENE-9084: Fix potential deadlock due to circular synchronization in AnalyzingInfixSuggester
(Paul Ward)
 
+* LUCENE-9115: NRTCachingDirectory no longer caches files of unknown size.
+  (Adrien Grand)
+
 Other
 ---------------------
 
diff --git a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
index 6352674..0e4b922 100644
--- a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
@@ -232,6 +232,8 @@ public class NRTCachingDirectory extends FilterDirectory implements Accountable
       bytes = context.mergeInfo.estimatedMergeBytes;
     } else if (context.flushInfo != null) {
       bytes = context.flushInfo.estimatedSegmentSize;
+    } else {
+      return false;
     }
 
     return (bytes <= maxMergeSizeBytes) && (bytes + cacheSize.get()) <= maxCachedBytes;
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
index 0f2e200..502b181 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
@@ -136,4 +136,34 @@ public class TestNRTCachingDirectory extends BaseDirectoryTestCase {
     nrtDir.close();
     fsDir.close();
   }
+
+  public void testUnknownFileSize() throws IOException {
+    Directory dir = newDirectory();
+
+    Directory nrtDir1 = new NRTCachingDirectory(dir, 1, 1) {
+      @Override
+      protected boolean doCacheWrite(String name, IOContext context) {
+        boolean cache = super.doCacheWrite(name, context);
+        assertTrue(cache);
+        return cache;
+      }
+    };
+    IOContext ioContext = new IOContext(new FlushInfo(3, 42));
+    nrtDir1.createOutput("foo", ioContext).close();
+    nrtDir1.createTempOutput("bar", "baz", ioContext).close();
+
+    Directory nrtDir2 = new NRTCachingDirectory(dir, 1, 1) {
+      @Override
+      protected boolean doCacheWrite(String name, IOContext context) {
+        boolean cache = super.doCacheWrite(name, context);
+        assertFalse(cache);
+        return cache;
+      }
+    };
+    ioContext = IOContext.DEFAULT;
+    nrtDir2.createOutput("foo", ioContext).close();
+    nrtDir2.createTempOutput("bar", "baz", ioContext).close();
+
+    dir.close();
+  }
 }


Mime
View raw message