thecoop commented on code in PR #16883:
URL: https://github.com/apache/lucene/pull/16883#discussion_r4350191765
##########
lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90CompoundReader.java:
##########
@@ -176,28 +182,50 @@ public IndexInput openInput(String name, IOContext
context) throws IOException {
+ entries.keySet()
+ ")");
}
- IndexInput data = context.context() == IOContext.Context.MERGE ?
mergeHandle() : handle;
- return data.slice(name, entry.offset, entry.length, context);
+ synchronized (this) {
+ Mapping mapping = mappingFor(id, context);
+ IndexInput slice = mapping.data.slice(name, entry.offset, entry.length,
context);
+ mapping.firstOpens.putIfAbsent(id, slice);
+ return slice;
+ }
}
/**
- * A merge reads through a mapping of its own, so the access it advises does
not replace the
- * advice of searches reading the same inner files. Merges of this segment
share it. Like the
- * search mapping, it is opened without advice: each inner file is advised
on its own region.
+ * Returns the first mapping where {@code id} is not open yet or reads as
{@code context}, and
+ * opens a new mapping otherwise. This way an inner file is never advised
twice on one mapping.
*/
- private synchronized IndexInput mergeHandle() throws IOException {
+ private Mapping mappingFor(String id, IOContext context) throws IOException {
+ assert Thread.holdsLock(this);
if (closed) {
throw new AlreadyClosedException("this Directory is closed");
}
- if (mergeHandle == null) {
- try {
- mergeHandle = directory.openInput(dataFileName, IOContext.DEFAULT);
- } catch (@SuppressWarnings("unused") FileNotFoundException |
NoSuchFileException e) {
- // an open reader outlives its files, so fall back to the mapping it
already holds
- mergeHandle = handle;
+ if (mappings.isEmpty()) {
+ mappings.add(new Mapping(handle));
+ }
+ for (Mapping mapping : mappings) {
+ IndexInput first = mapping.firstOpens.get(id);
+ if (first == null || first.readsAs(context)) {
+ return mapping;
}
}
- return mergeHandle;
+ IndexInput data;
+ try {
+ // like the reader's mapping, opened without advice
+ data = directory.openInput(dataFileName, IOContext.DEFAULT);
Review Comment:
Doesn't this need to open it with `context`, not `DEFAULT`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]