jimczi commented on code in PR #16883:
URL: https://github.com/apache/lucene/pull/16883#discussion_r4361384288
##########
lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90CompoundReader.java:
##########
@@ -176,28 +185,33 @@ 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);
- }
-
- /**
- * 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.
- */
- private synchronized IndexInput mergeHandle() throws IOException {
- 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;
+ synchronized (this) {
+ if (closed) {
+ throw new AlreadyClosedException("this Directory is closed");
+ }
+ List<Slice> fileSlices = slices.computeIfAbsent(id, _ -> new
ArrayList<>());
+ int copy = 0;
+ while (copy < fileSlices.size()
+ && fileSlices.get(copy).input().isEfficientFor(context) == false) {
+ copy++;
+ }
+ // each slice of an inner file is on its own copy of the data file, so
it keeps its own advice
+ if (copy == fileSlices.size()) {
+ try {
+ if (copy == data.size()) {
+ // without advice, like handle, so inner files advise their own
pages
+ data.add(directory.openInput(dataFileName, IOContext.DEFAULT));
+ }
+ IndexInput input = data.get(copy).slice(name, entry.offset,
entry.length, context);
Review Comment:
Yeah, it was only kept to call isEfficientFor on, and the link was just the
index. I removed it: each copy of the data file now keeps the context each
inner file was first opened with on it, and openInput slices with that context
and checks the slice it returns. So nothing extra is kept, and there's a second
copy only when random and sequential reads of the same file conflict. Easier to
follow?
--
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]