You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "apoorvmittal10 (via GitHub)" <gi...@apache.org> on 2025/05/19 15:35:13 UTC
[PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
apoorvmittal10 opened a new pull request, #19759:
URL: https://github.com/apache/kafka/pull/19759
The `onComplete` method in DelayedOperation is guaranteed to run only once, either by `tryComplete` or `onExpiration`. The invocation of `tryComplete` is done by attaining `lock` so no concurrent execution of `tryComplete` happens for same delayed operation. However, there can be concurrent execution of `tryComplete` and `onComplete` as the `expiration` thread can trigger a separte run of `onComplete` while `tryComplete` is still executing. This behaviour is not ideal as there are parallel runs where 1 threads method execution is wasteful i.e. if `onComplete` is already invoked by another thread then execution of `tryComplete` is not required.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "junrao (via GitHub)" <gi...@apache.org>.
junrao commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2895167769
> This was a tricky bug to find, so nice catch.
@apoorvmittal10 : My understanding is that this PR is not fixing a bug. Without the PR, we still guarantee that onComplete() will be called exactly once. So, this PR just saves some unnecessary work after the operation completes. Is that 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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "junrao (via GitHub)" <gi...@apache.org>.
junrao commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2103085830
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
Review Comment:
Only the expiration logic checks the return value of forceComplete(). We could do the following in the expiration logic and change `forceComplete()` to return void and avoid using the lock there (the caller will get the lock instead).
```
lock.lock();
try {
if (!isCompleted()) {
forceComplete();
onExpiration();
}
} finally {
lock.unlock();
}
```
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -41,7 +40,7 @@
*/
public abstract class DelayedOperation extends TimerTask {
- private final AtomicBoolean completed = new AtomicBoolean(false);
+ private volatile boolean completed = false;
Review Comment:
> onComplete() can be triggered by either forceComplete(), which forces calling onComplete() after delayMs if the operation is not yet completed, or tryComplete(), which first checks if the operation can be completed or not now, and if yes calls forceComplete().
Could we adjust the comment to sth like the following?
onComplete() is called from forceComplete(), which is triggered once by either expiration if the operation is not completed after delayMs, or tryComplete() if the operation can be completed now.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #19759:
URL: https://github.com/apache/kafka/pull/19759
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2097557356
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
return false;
}
+ // Attain lock prior completing the request.
+ lock.lock();
Review Comment:
After this change, the lock must be reentrant, correct? If so, we should consider replacing the `Lock` type with `ReentrantLock` to prevent potential deadlocks.
Additionally, `DelayedOperation(long delayMs, Optional<Lock> lockOpt)` seems to lose its meaning once the old group coordinator is removed. We might want to clean that up.
These points can be addressed in a follow-up.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2101752608
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
Review Comment:
I can revert it to AtomicBoolean#compareAndSet but I didn't understand the problem. There would only be first execution of forceComplete which should be successful and return true. Subsequent executions will return false.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2101744337
##########
core/src/main/java/kafka/server/share/DelayedShareFetch.java:
##########
@@ -191,26 +191,23 @@ public void onExpiration() {
* Complete the share fetch operation by fetching records for all partitions in the share fetch request irrespective
* of whether they have any acquired records. This is called when the fetch operation is forced to complete either
* because records can be acquired for some partitions or due to MaxWaitMs timeout.
+ * <p>
+ * On operation timeout, onComplete is invoked, last try occurs to acquire partitions and read
+ * from log, if acquired. The fetch will only happen from local log and not remote storage, on
+ * operation expiration.
Review Comment:
I thought about it but it complicates the code execution in DelayedShareFetch. Clearing partitionsAcquired alone is not sufficient, as there could be pending remote fetch as well which might need additional time to finish. Hence I didn't go with that approach.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2101807355
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
Review Comment:
@junrao that is a good point. After avoiding concurrent execution, `forceComplete` MUST return true if it is executed by `tryComplete`. Hence, checking the returned value of `forceComplete` gets meaningless.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2102075597
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
Review Comment:
> Ok, so are we saying that first execution of forceComplete from tryComplete will return true? And as the operation is marked completed hence no further execution of tryComplete can trigger, which makes all executions of forceComplete within tryComplete always returns true?
yes, we are on the same page. I hope I'm not misunderstanding @junrao comment :)
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "junrao (via GitHub)" <gi...@apache.org>.
junrao commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2898796227
@apoorvmittal10 : Thanks for the explanation. It seems that we found a case that an acquired sharePartition lock was released more than once. I am still not sure how it happened. forceComplete() is supposed to only return true once and the lock is only released when forceComplete() returns true. How is the acquired lock released a second time?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2097405538
##########
core/src/main/java/kafka/server/share/DelayedShareFetch.java:
##########
@@ -191,26 +191,23 @@ public void onExpiration() {
* Complete the share fetch operation by fetching records for all partitions in the share fetch request irrespective
* of whether they have any acquired records. This is called when the fetch operation is forced to complete either
* because records can be acquired for some partitions or due to MaxWaitMs timeout.
+ * <p>
+ * On operation timeout, onComplete is invoked, last try occurs to acquire partitions and read
+ * from log, if acquired. The fetch will only happen from local log and not tier log, on operation
Review Comment:
nit: I'd say "remote storage" rather than "tier log".
##########
core/src/main/java/kafka/server/share/DelayedShareFetch.java:
##########
@@ -349,7 +346,7 @@ public boolean tryComplete() {
releasePartitionLocks(topicPartitionData.keySet());
}
} else {
- log.trace("Can't acquire records for any partition in the share fetch request for group {}, member {}, " +
+ log.trace("Can't acquire any partition in the share fetch request for group {}, member {}, " +
Review Comment:
nit: "any partitions"
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2104086816
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
Review Comment:
> and change forceComplete() to return void
Though I agree that now if forceComplete is invoked by tryComplete then it will return true but tryComplete still need to return boolean hence all places where we return the value from tryComplete based on forceComplete has to be changed and also requires explicit `return true` from all the places. I am of the opinion to not do this, I don't strong opinion though.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2893719889
> > The onComplete method in DelayedOperation is guaranteed to run only
> > once, either by tryComplete or onExpiration.
>
> `onExpiration`? or `forceComplete`?
>
> > if
> > onComplete is already invoked by another thread then execution of
> > tryComplete is not required.
>
> Excuse me, how to address it? do you plan to check `isCompleted` before executing `tryComplete`?
For 1) I meant the invocation by run method, I have updated the description. Thanks.
For 2) tryComplete invocation is in `lock` itself and there is also a checck for `isCompleted` prior invocation: https://github.com/apache/kafka/blob/d3f897948630d6f387969cdc9542fcabb6f1d2a9/server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java#L136
@chia7712 just rewriting, so we have corrected flow of comments.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2893712701
> @apoorvmittal10 It is too cool to add response in comment, so I don't notice your response :)
>
> > For 2) tryComplete invocation is in lock itself and there is also a checck for isCompleted prior invocation:
>
> Should we update `safeTryCompleteOrElse` to ensure it check for `isCompleted` prior invocation.
@chia7712 Ahhhh, my bad. I clicked edit instead of reply 🫣🤦♂️ My bad.
safeTryCompleteOrElse is invoked when the operation is being added to purgatory, if tryComplete returns false then it gets added in purgatory. An operation should never have completed true when invoking safeTryCompleteOrElse.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2102456553
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
return false;
}
+ // Attain lock prior completing the request.
+ lock.lock();
Review Comment:
I was a little bored, so I created Jira KAFKA-19322 (https://issues.apache.org/jira/browse/KAFKA-19322). Feel free to take it over, or I can assign it to a mentee :smile:
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "junrao (via GitHub)" <gi...@apache.org>.
junrao commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2105155776
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -29,10 +28,9 @@
* a delayed fetch operation could be waiting for a given number of bytes to accumulate.
* <br/>
* The logic upon completing a delayed operation is defined in onComplete() and will be called exactly once.
- * Once an operation is completed, isCompleted() will return true. onComplete() can be triggered by either
- * forceComplete(), which forces calling onComplete() after delayMs if the operation is not yet completed,
- * or tryComplete(), which first checks if the operation can be completed or not now, and if yes calls
- * forceComplete().
+ * Once an operation is completed, isCompleted() will return true. onComplete() is called from forceComplete(),
+ * which is triggered once by either expiration if the operation is not completed after delayMs, or tryComplete()
Review Comment:
Actually, it's possible for forceComplete() to be called once from tryComplete() and another from expiration. So, we need to remove `once`.
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
Review Comment:
Well, the issue is that there are quite a few places where tryComplete() calls forceComplete() and checks the return value of forceComplete(). You fixed the issue in DelayedShareFetch, but not in other places. As we evolve the code, it would be useful to leave the code base in a better place for future developers, even though it takes a bit of more work. This can be done in a followup jira. Filed https://issues.apache.org/jira/browse/KAFKA-19325 to track it.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2101752608
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
Review Comment:
I can revert it to AtomicBoolean#compareAndSet but I didn't understand the problem. There would only be first execution of forceComplete which should be successful and return true. Subsequent execustions will return false.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2101746039
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
return false;
}
+ // Attain lock prior completing the request.
+ lock.lock();
Review Comment:
Sure, I ll create a folow up.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2104104199
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -41,7 +40,7 @@
*/
public abstract class DelayedOperation extends TimerTask {
- private final AtomicBoolean completed = new AtomicBoolean(false);
+ private volatile boolean completed = false;
Review Comment:
Done.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2897267180
> @apoorvmittal10 : Thanks for the PR. The code looks reasonable to me. Could you run TestPurgatoryPerformance to see if there is any perf degradation?
I ran some tests and performance is same.
### After the chages:
```
--num 10000 --rate 100 --timeout 1000 --pct50 0.5 --pct75 0.75
# latency samples: pct75 = 0, pct50 = 0, min = 0, max = 7
# interval samples: rate = 100.068948, min = 0, max = 129
# enqueue rate (10000 requests):
# <elapsed time ms> <target rate> <actual rate> <process cpu time ms> <G1 Old Generation count> <G1 Young Generation count> <G1 Old Generation time ms> <G1 Young Generation time ms>
101196 99.809364 99.806376 3240 0 2 0 8
```
```
--num 10000 --rate 1000 --timeout 1000 --pct50 0.5 --pct75 0.75
# latency samples: pct75 = 0, pct50 = 0, min = 0, max = 9
# interval samples: rate = 999.371395, min = 0, max = 14
# enqueue rate (10000 requests):
# <elapsed time ms> <target rate> <actual rate> <process cpu time ms> <G1 Old Generation count> <G1 Young Generation count> <G1 Old Generation time ms> <G1 Young Generation time ms>
11104 989.902990 989.805008 1349 0 2 0 7
```
### Before changes:
```
--num 10000 --rate 100 --timeout 1000 --pct50 0.5 --pct75 0.75
# latency samples: pct75 = 0, pct50 = 0, min = 0, max = 9
# interval samples: rate = 100.020304, min = 0, max = 130
# enqueue rate (10000 requests):
# <elapsed time ms> <target rate> <actual rate> <process cpu time ms> <G1 Old Generation count> <G1 Young Generation count> <G1 Old Generation time ms> <G1 Young Generation time ms>
102366 98.657274 98.652408 3444 0 2 0 8
--num 10000 --rate 1000 --timeout 1000 --pct50 0.5 --pct75 0.75
# latency samples: pct75 = 0, pct50 = 0, min = 0, max = 8
# interval samples: rate = 997.134236, min = 0, max = 14
# enqueue rate (10000 requests):
# <elapsed time ms> <target rate> <actual rate> <process cpu time ms> <G1 Old Generation count> <G1 Young Generation count> <G1 Old Generation time ms> <G1 Young Generation time ms>
11218 978.665101 978.665101 1624 0 2 0 7
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2105470732
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -29,10 +28,9 @@
* a delayed fetch operation could be waiting for a given number of bytes to accumulate.
* <br/>
* The logic upon completing a delayed operation is defined in onComplete() and will be called exactly once.
- * Once an operation is completed, isCompleted() will return true. onComplete() can be triggered by either
- * forceComplete(), which forces calling onComplete() after delayMs if the operation is not yet completed,
- * or tryComplete(), which first checks if the operation can be completed or not now, and if yes calls
- * forceComplete().
+ * Once an operation is completed, isCompleted() will return true. onComplete() is called from forceComplete(),
+ * which is triggered once by either expiration if the operation is not completed after delayMs, or tryComplete()
Review Comment:
Done.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2898579823
> > Now the thread in tryComplete cannot invoke onComplete as completed is marked true in DelayedOperation, hence acquired partitions will be released.
>
> Hmm, is this true? tryComplete will only release the acquired locks if forceComplete() returns true, right?
Yes it's true, it can happen in current implementation. [This](https://github.com/apache/kafka/blob/e88c10d5952c464a0f597b295deaa51e4c9fa978/core/src/main/java/kafka/server/share/DelayedShareFetch.java#L902) line when invoked from tryComplete can release the locks, which is correct but conflicts with concurrent execution on request timeout. To make sure that our acquired share partitions release is correct, we added a check [here](https://github.com/apache/kafka/blob/e88c10d5952c464a0f597b295deaa51e4c9fa978/core/src/main/java/kafka/server/share/SharePartition.java#L1384). In our performance runs we saw the issue. However it will not cause issue per se for share fetches, as SharePartition will not acquire record offsets which are already acquired but it will have some wasted fetches.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2097549218
##########
core/src/main/java/kafka/server/share/DelayedShareFetch.java:
##########
@@ -349,7 +346,7 @@ public boolean tryComplete() {
releasePartitionLocks(topicPartitionData.keySet());
}
} else {
- log.trace("Can't acquire records for any partition in the share fetch request for group {}, member {}, " +
+ log.trace("Can't acquire any partition in the share fetch request for group {}, member {}, " +
Review Comment:
Done.
##########
core/src/main/java/kafka/server/share/DelayedShareFetch.java:
##########
@@ -191,26 +191,23 @@ public void onExpiration() {
* Complete the share fetch operation by fetching records for all partitions in the share fetch request irrespective
* of whether they have any acquired records. This is called when the fetch operation is forced to complete either
* because records can be acquired for some partitions or due to MaxWaitMs timeout.
+ * <p>
+ * On operation timeout, onComplete is invoked, last try occurs to acquire partitions and read
+ * from log, if acquired. The fetch will only happen from local log and not tier log, on operation
Review Comment:
Done.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2893580009
@apoorvmittal10 It is too cool to add response in comment, so I don't notice your response :)
> For 2) tryComplete invocation is in lock itself and there is also a checck for isCompleted prior invocation:
Should we update `safeTryCompleteOrElse` to ensure it check for `isCompleted` prior invocation.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "junrao (via GitHub)" <gi...@apache.org>.
junrao commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2898553890
> Now the thread in tryComplete cannot invoke onComplete as completed is marked true in DelayedOperation, hence acquired partitions will be released.
Hmm, is this true? tryComplete will only release the acquired locks if forceComplete() returns true, right?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2100858959
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
return false;
}
+ // Attain lock prior completing the request.
+ lock.lock();
Review Comment:
> Are you suggesting to make it more tighter and use ReentrantLock explicitly?
yes, but this change needs to cleanup the code. It can be addressed later if we want to merge this bug fix first.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2899443174
> @apoorvmittal10 : Thanks for the explanation. It seems that we found a case that an acquired sharePartition lock was released more than once. I am still not sure how it happened. forceComplete() is supposed to only return true once and the lock is only released when forceComplete() returns true. How is the acquired lock released a second time?
Prior to this PR there is no lock in [forceComplete](https://github.com/apache/kafka/blob/e88c10d5952c464a0f597b295deaa51e4c9fa978/server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java#L73) but a way to make sure that onComplete is not executed twice. However, consider that thread 1 has started executing [safeTryComplete](https://github.com/apache/kafka/blob/e88c10d5952c464a0f597b295deaa51e4c9fa978/server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java#L133) which attains lock and checks that if the operation has marked completed, if not then tryComplete is executed. Now thread 1 is executing tryComplete, then thread 2 on timeout executes [forceComplete](https://github.com/apache/kafka/blob/e88c10d5952c464a0f597b295deaa51e4c9fa978/server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java#L148) which marks completed as true and waits [here](https://github.com/apache/kafka/blob/e88c10d5952c464a0f59
7b295deaa51e4c9fa978/core/src/main/java/kafka/server/share/DelayedShareFetch.java#L199) for the operation lock. Now thread 1, in tryComplete, acquires some share partitions but as [completed](https://github.com/apache/kafka/blob/e88c10d5952c464a0f597b295deaa51e4c9fa978/core/src/main/java/kafka/server/share/DelayedShareFetch.java#L899) is already marked true then the share partitions are released and so the lock for delayed operation. Thread 2 now starts executing `onComplete` but as [partitionsAcquired](https://github.com/apache/kafka/blob/e88c10d5952c464a0f597b295deaa51e4c9fa978/core/src/main/java/kafka/server/share/DelayedShareFetch.java#L106) is at instance level hence `onComplete` tries to execute further with those share partitions which are already released. Once completed then onCompete releases those share partitions again.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2102477237
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
return false;
}
+ // Attain lock prior completing the request.
+ lock.lock();
Review Comment:
You are awesome, feel free to assign to a mentee and I can review or else I will pick it up.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2897258835
> > This was a tricky bug to find, so nice catch.
>
> @apoorvmittal10 : My understanding is that this PR is not fixing a bug. Without the PR, we still guarantee that onComplete() will be called exactly once. So, this PR just saves some unnecessary work after the operation completes. Is that correct?
It does both, without the PR, though we guarantee that onComplete will be called exactly once but there can be a thread which is inside onComplete (when timeout occurs) and a separate thread invoking tryComplete. For DelayedShareFetch, prior this PR, a thread can be waiting in onComplete for lock which has already marked `completed` true in DelayedOperation but parallel thread in `tryComplete` is running, which acquires some partitions. Now the thread in tryComplete cannot invoke `onComplete` as `completed` is marked `true` in DelayedOperation, hence acquired partitions will be released. Then other thread which was waiting in onComplete for the lock, starts executing and releases the same acquired topic partitions again. This PR fixes this issue as well.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2100282893
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
return false;
}
+ // Attain lock prior completing the request.
+ lock.lock();
Review Comment:
The default implemenation of Lock is over ReentrantLock itself in DelayedOperation and elsewhere, abstracted over Lock API in DelayedOperation. Are you suggesting to make it more tighter and use ReentrantLock explicitly?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2104086816
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
Review Comment:
> and change forceComplete() to return void
Though I agree that now if forceComplete is invoked by tryComplete then it will return true but tryComplete still need to return boolean hence all places where we return the value from tryComplete based on forceComplete has to be changed and also requires explicit `return true` from all the places. I am of the opinion to not do this.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "junrao (via GitHub)" <gi...@apache.org>.
junrao commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2101385805
##########
core/src/main/java/kafka/server/share/DelayedShareFetch.java:
##########
@@ -191,26 +191,23 @@ public void onExpiration() {
* Complete the share fetch operation by fetching records for all partitions in the share fetch request irrespective
* of whether they have any acquired records. This is called when the fetch operation is forced to complete either
* because records can be acquired for some partitions or due to MaxWaitMs timeout.
+ * <p>
+ * On operation timeout, onComplete is invoked, last try occurs to acquire partitions and read
+ * from log, if acquired. The fetch will only happen from local log and not remote storage, on
+ * operation expiration.
Review Comment:
For better consistency, should we remove released partitions from `partitionsAcquired` in `releasePartitionLocks()`? It seems that if we had done that, we wouldn't get into the situation of releasing the lock more than once.
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
Review Comment:
An implication of this change is that when forceComplete() is called inside `tryComplete`, it always returns true. Currently, we have multiple places that check the return value of forceComplete() inside `tryComplete`. Should we adjust those?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2101981917
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
+ if (completed) {
Review Comment:
Ok, so are we saying that first execution of forceComplete from tryComplete will return true? And as the operation is marked completed hence no further execution of tryComplete can trigger, which makes all executions of forceComplete within tryComplete always returns true?
I have removed the check in DelayedShareFetch.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "apoorvmittal10 (via GitHub)" <gi...@apache.org>.
apoorvmittal10 commented on code in PR #19759:
URL: https://github.com/apache/kafka/pull/19759#discussion_r2104086816
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedOperation.java:
##########
@@ -68,24 +67,36 @@ public DelayedOperation(long delayMs, Lock lock) {
* Return true iff the operation is completed by the caller: note that
* concurrent threads can try to complete the same operation, but only
* the first thread will succeed in completing the operation and return
- * true, others will still return false
+ * true, others will still return false.
*/
public boolean forceComplete() {
- if (completed.compareAndSet(false, true)) {
- // cancel the timeout timer
- cancel();
- onComplete();
- return true;
- } else {
+ // Do not proceed if the operation is already completed.
Review Comment:
> and change forceComplete() to return void
Though I agree that now if forceComplete is invoked by tryComplete then it will return true but tryComplete still need to return boolean hence all places where we return the value from tryComplete based on forceComplete has to be changed and also requires explicit `return true` from all the places. I am of the opinion to not do this. Or if you think we should then shall we take it as a separate PR for just refactor?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19312: Avoiding concurrent execution of onComplete and tryComplete [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #19759:
URL: https://github.com/apache/kafka/pull/19759#issuecomment-2892046630
> The onComplete method in DelayedOperation is guaranteed to run only
once, either by tryComplete or onExpiration.
`onExpiration`? or `forceComplete`?
> if
onComplete is already invoked by another thread then execution of
tryComplete is not required.
Excuse me, how to address it? do you plan to check `isCompleted` before executing `tryComplete`?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org