LUCENE-9115: NRTCachingDirectory shouldn't cache files of unknown size. (#1145)

This commit is contained in:
Adrien Grand 2020-01-09 15:15:30 +01:00 committed by GitHub
parent b11c3cffe4
commit 7ad33c3a98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View File

@ -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
---------------------

View File

@ -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;

View File

@ -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();
}
}