thecoop commented on code in PR #16883:
URL: https://github.com/apache/lucene/pull/16883#discussion_r4361260480


##########
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:
   Oh, it's checked for efficientFor above. But then it's re-opened below. Is 
there a hidden link between the order of things in `data` and in `fileSlices`?



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

Reply via email to