javanna commented on code in PR #13542:
URL: https://github.com/apache/lucene/pull/13542#discussion_r1731273966


##########
lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java:
##########
@@ -1024,10 +1138,50 @@ public LeafSlice[] get() {
             leafSlices =
                 Objects.requireNonNull(
                     sliceProvider.apply(leaves), "slices computed by the 
provider is null");
+            checkSlices(leafSlices);
           }
         }
       }
       return leafSlices;
     }
+
+    /**
+     * Enforce that there aren't multiple slices pointing to the same physical 
segment. It is a
+     * requirement that {@link Collector#getLeafCollector(LeafReaderContext)} 
gets called once per
+     * leaf context. Also, it does not make sense to partition a segment to 
then search those
+     * partitions as part of the same slice, because the goal of partitioning 
is parallel searching
+     * which happens at the slices level.
+     */
+    private static void checkSlices(LeafSlice[] leafSlices) {
+      for (LeafSlice leafSlice : leafSlices) {
+        Set<LeafReaderContext> distinctLeaves = new HashSet<>();
+        for (LeafReaderContextPartition leafPartition : leafSlice.leaves) {
+          distinctLeaves.add(leafPartition.ctx);
+        }
+        if (leafSlice.leaves.length != distinctLeaves.size()) {
+          throw new IllegalStateException(
+              "The same slice targets multiple partitions of the same leaf 
reader. "
+                  + "A segment should rather get partitioned to be searched 
concurrently from as many slices as the "
+                  + "number of partitions it is split into.");
+        }
+      }
+    }
+  }
+
+  /**
+   * Whether the provided leaf slices include leaf partitions.
+   *
+   * @param leafSlices the leaf slices
+   * @return true if the provided leaf slices include leaf partition, false if 
they all target
+   *     entire segments.
+   */
+  public static boolean hasLeafPartitions(IndexSearcher.LeafSlice[] 
leafSlices) {

Review Comment:
   I think that I will entirely remove this given Adrien's suggestion to not 
use partitions by default. That means we'll no longer need to check when there 
are partitions and skip Drill sideways tests accordingly. 



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