congbobo184 commented on code in PR #15021:
URL: https://github.com/apache/pulsar/pull/15021#discussion_r851945509
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TransactionBufferHandlerImpl.java:
##########
@@ -222,6 +233,42 @@ public void handleEndTxnOnSubscriptionResponse(long
requestId,
}
}
+ private void continueCheckOutstandingRequestIfTimeout() {
+ Map.Entry<Long, OpRequestSend> entry =
outstandingRequests.firstEntry();
+ if (entry == null) {
+ timoutCheckIsRunning.set(false);
+ // To avoid race conditions, the scenarios are as follows.
+ // Thread A: after if(entry=null) => Thread B: put a new entry and
then get timoutCheckIsRunning=true =>
+ // Thread A: set timoutCheckIsRunning = false
+ if (outstandingRequests.firstEntry() != null
+ && timoutCheckIsRunning.compareAndSet(false, true)) {
+ continueCheckOutstandingRequestIfTimeout();
+ }
+ return;
+ }
+ OpRequestSend op = entry.getValue();
+ final long finalRequestId = op.requestId;
+ if (!op.isTimeout(operationTimeoutInMills)) {
+ timer.newTimeout(task ->
continueCheckOutstandingRequestIfTimeout(),
+ outstandingRequests.firstEntry().getValue()
+ .getTimeoutMs(operationTimeoutInMills),
TimeUnit.MILLISECONDS);
+ return;
+ }
+ if (!op.tryOwnership(finalRequestId)) {
+ // Just safe check to ensure endless loop cause StackOverFlow,
+ // because other operation will remove this request firstly.
+ outstandingRequests.remove(finalRequestId);
+ // This operation already handle by other thread, we need to check
next.
+ continueCheckOutstandingRequestIfTimeout();
+ return;
+ }
+ outstandingRequests.remove(entry.getKey());
+ op.cb.completeExceptionally(new TransactionBufferClientException
Review Comment:
yes, you are right. but we should remove finalRequestId
`outstandingRequests.remove(finalRequestId);`
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TransactionBufferHandlerImpl.java:
##########
@@ -222,6 +233,42 @@ public void handleEndTxnOnSubscriptionResponse(long
requestId,
}
}
+ private void continueCheckOutstandingRequestIfTimeout() {
+ Map.Entry<Long, OpRequestSend> entry =
outstandingRequests.firstEntry();
+ if (entry == null) {
+ timoutCheckIsRunning.set(false);
+ // To avoid race conditions, the scenarios are as follows.
+ // Thread A: after if(entry=null) => Thread B: put a new entry and
then get timoutCheckIsRunning=true =>
+ // Thread A: set timoutCheckIsRunning = false
+ if (outstandingRequests.firstEntry() != null
+ && timoutCheckIsRunning.compareAndSet(false, true)) {
+ continueCheckOutstandingRequestIfTimeout();
+ }
+ return;
+ }
+ OpRequestSend op = entry.getValue();
+ final long finalRequestId = op.requestId;
+ if (!op.isTimeout(operationTimeoutInMills)) {
Review Comment:
If this op have been completed by handle response, the timeout time is not
correct
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]