s1monw commented on a change in pull request #725: LUCENE-8865: Use incoming 
thread for execution if IndexSearcher has an executor
URL: https://github.com/apache/lucene-solr/pull/725#discussion_r294396310
 
 

 ##########
 File path: lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
 ##########
 @@ -636,16 +636,45 @@ public TopFieldDocs reduce(Collection<TopFieldCollector> 
collectors) throws IOEx
       query = rewrite(query);
       final Weight weight = createWeight(query, scoreMode, 1);
       final List<Future<C>> topDocsFutures = new 
ArrayList<>(leafSlices.length);
+
       for (int i = 0; i < leafSlices.length; ++i) {
         final LeafReaderContext[] leaves = leafSlices[i].leaves;
         final C collector = collectors.get(i);
-        topDocsFutures.add(executor.submit(new Callable<C>() {
-          @Override
-          public C call() throws Exception {
+        if (i == leafSlices.length-1) { // execute the last on the caller 
thread
+          search(Arrays.asList(leaves), weight, collector);
+          topDocsFutures.add(new Future<>() {
+
+            @Override
+            public boolean cancel(boolean mayInterruptIfRunning) {
+              return false;
+            }
+
+            @Override
+            public boolean isCancelled() {
+              return false;
+            }
+
+            @Override
+            public boolean isDone() {
+              return true;
+            }
+
+            @Override
+            public C get() {
+              return collector;
+            }
+
+            @Override
+            public C get(long timeout, TimeUnit unit) {
+              return get();
+            }
 
 Review comment:
   well I looked at this code accidentally investigating some idea and I 
figured it doesn't make sense to just block and wait instead of executing a 
search so if you are having a single segment you never pay the price of 
spawning a thread and you don't do any unnecessary work.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to