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


##########
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:
   As an alternative, could you move this check into the `provider` lambda? It 
still feels wrong to me that `CachingLeafSupplier` has to check the `executor`.



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