You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2020/01/09 14:28:13 UTC
[lucene-solr] 02/03: LUCENE-9115: NRTCachingDirectory shouldn't
cache files of unknown size. (#1145)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit be17386a3295e5cd05b9c1bf8652f79851fde7a1
Author: Adrien Grand <jp...@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 412a53e..449a893 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -47,6 +47,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 0bbc5ae..597ea9d 100644
--- a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
@@ -218,6 +218,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 + cache.ramBytesUsed()) <= 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 227d41f..1a10515 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();
+ }
}