CaoManhDat commented on a change in pull request #1770:
URL: https://github.com/apache/lucene-solr/pull/1770#discussion_r481568904



##########
File path: 
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java
##########
@@ -112,95 +112,106 @@ public void onFailure(Exception e, boolean retryReq) {
               if (cancelled.get()) {
                 return;
               }
-              Cancellable cancellable = doRequest(url, req, rsp, 
isNonRetryable, it.isServingZombieServer(), this);
-              currentCancellable.set(cancellable);
+              CompletableFuture<NamedList<Object>> future = 
doAsyncRequest(url, req, rsp, isNonRetryable, it.isServingZombieServer(), this);
+              currentFuture.set(future);
             }
           } finally {
             MDC.remove("LBSolrClient.url");
           }
         } else {
-          asyncListener.onFailure(e);
+          apiFuture.completeExceptionally(e);
         }
       }
     };
     try {
-      Cancellable cancellable = doRequest(it.nextOrError(), req, rsp, 
isNonRetryable, it.isServingZombieServer(), retryListener);
-      currentCancellable.set(cancellable);
+      CompletableFuture<NamedList<Object>> future = 
doAsyncRequest(it.nextOrError(), req, rsp, isNonRetryable, 
it.isServingZombieServer(), retryListener);
+      currentFuture.set(future);
     } catch (SolrServerException e) {
-      asyncListener.onFailure(e);
+      apiFuture.completeExceptionally(e);
     }
-    return () -> {
-      synchronized (cancelled) {
-        cancelled.set(true);
-        if (currentCancellable.get() != null) {
-          currentCancellable.get().cancel();
+    apiFuture.exceptionally((error) -> {
+      if (apiFuture.isCancelled()) {
+        synchronized (cancelled) {
+          cancelled.set(true);
+          if (currentFuture.get() != null) {

Review comment:
       > Maybe we don't need RL but we just need a static utility method 
somewhere like boolean shouldRetry(Exception e)
   
   Yeah something like that, so the first CF will have an `exceptionally` 
handler which create a new CF on exception, etc.
   
   > With CompletableFuture, there's no harm in attempting to complete a future 
redundantly -- it's a no-op. Thus if currentFuture is already cancelled, no 
extra work.
   
   The flow here is: user call `apiFuture.cancel()`, then we need to propagate 
that signal to whatever running or upcoming futures created by 
`Http2SolrClient`. As I mention, the worst case here is cancel() will be called 
on previous future, so the current future still do its job which is not needed 
since its result will be discarded anyway. Doing sync will prevent doing 
`cancel()` on previous future. 
   But since that worst case will rarely happen so I kinda prefer on removing 
it, but we need to add some comment here.




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