You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/04/06 07:40:37 UTC

[GitHub] [pulsar] codelipenghui commented on a diff in pull request #15021: [improve][transaction] Use a global timeout checker to avoid many timeout tasks.

codelipenghui commented on code in PR #15021:
URL: https://github.com/apache/pulsar/pull/15021#discussion_r843584594


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TransactionBufferHandlerImpl.java:
##########
@@ -287,6 +288,25 @@ private void checkPendingRequests() {
         }
     }
 
+    private void loopCheckOutstandingRequestIfTimeout() {
+        while (true) {
+            Map.Entry<Long, OpRequestSend> entry = outstandingRequests.firstEntry();
+            if (entry == null) {
+                timer.newTimeout(task -> loopCheckOutstandingRequestIfTimeout(), 100, TimeUnit.MILLISECONDS);
+                return;
+            }
+            OpRequestSend op = entry.getValue();
+            if (op.cb.isDone() || (System.currentTimeMillis() - op.createdAt) < operationTimeoutInMills) {
+                timer.newTimeout(task -> loopCheckOutstandingRequestIfTimeout(), 100, TimeUnit.MILLISECONDS);
+                return;
+            }
+            outstandingRequests.remove(entry.getKey());
+            op.cb.completeExceptionally(new TransactionBufferClientException
+                    .RequestTimeoutException());
+            onResponse(op);

Review Comment:
   Here will introduce a race condition, the op might be removed by another thread and been recycled.



-- 
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: commits-unsubscribe@pulsar.apache.org

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