sohami commented on code in PR #12374:
URL: https://github.com/apache/lucene/pull/12374#discussion_r1237934932


##########
lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java:
##########
@@ -1014,4 +1021,48 @@ private static SliceExecutor 
getSliceExecutionControlPlane(Executor executor) {
 
     return new SliceExecutor(executor);
   }
+
+  /**
+   * Supplier for {@link LeafSlice} slices when passed in executor is 
non-null. This supplier
+   * computes and caches the value on first invocation and returns cached 
value on subsequent
+   * invocation. If the passed in provider for slice computation throws 
exception then same will be
+   * passed to the caller of this supplier on each invocation. If the provider 
returns null then
+   * {@link NullPointerException} will be thrown to the caller.
+   */
+  private static class CachingLeafSlicesSupplier implements 
Supplier<LeafSlice[]> {
+    private volatile LeafSlice[] leafSlices;
+
+    private final Executor executor;
+
+    private final Function<List<LeafReaderContext>, LeafSlice[]> sliceProvider;
+
+    private final List<LeafReaderContext> leaves;
+
+    private CachingLeafSlicesSupplier(
+        Executor executor,
+        Function<List<LeafReaderContext>, LeafSlice[]> provider,
+        List<LeafReaderContext> leaves) {
+      this.executor = executor;
+      this.sliceProvider = Objects.requireNonNull(provider, "leaf slice 
provider cannot be null");
+      this.leaves = Objects.requireNonNull(leaves, "list of LeafReaderContext 
cannot be null");
+    }
+
+    @Override
+    public LeafSlice[] get() {
+      if (executor == null) {
+        return null;
+      }

Review Comment:
   I did it this way because `IndexSearcher` can access `leafSlicesSupplier` 
without using `getSlices`. So everywhere it will need to perform explicit check 
for executor being `non-null` too for such usages. With current mechanism non 
null check for executor will not be needed for any future usages as well. This 
is also keeping the current behavior to return `null` slices when `executor` is 
`null`



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to