mirror of https://github.com/apache/lucene.git
LUCENE-9115: NRTCachingDirectory shouldn't cache files of unknown size. (#1145)
This commit is contained in:
parent
b11c3cffe4
commit
7ad33c3a98
|
@ -123,6 +123,9 @@ Bug Fixes
|
||||||
|
|
||||||
* LUCENE-9084: Fix potential deadlock due to circular synchronization in AnalyzingInfixSuggester (Paul Ward)
|
* 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
|
Other
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
|
@ -232,6 +232,8 @@ public class NRTCachingDirectory extends FilterDirectory implements Accountable
|
||||||
bytes = context.mergeInfo.estimatedMergeBytes;
|
bytes = context.mergeInfo.estimatedMergeBytes;
|
||||||
} else if (context.flushInfo != null) {
|
} else if (context.flushInfo != null) {
|
||||||
bytes = context.flushInfo.estimatedSegmentSize;
|
bytes = context.flushInfo.estimatedSegmentSize;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bytes <= maxMergeSizeBytes) && (bytes + cacheSize.get()) <= maxCachedBytes;
|
return (bytes <= maxMergeSizeBytes) && (bytes + cacheSize.get()) <= maxCachedBytes;
|
||||||
|
|
|
@ -136,4 +136,34 @@ public class TestNRTCachingDirectory extends BaseDirectoryTestCase {
|
||||||
nrtDir.close();
|
nrtDir.close();
|
||||||
fsDir.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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue