-
Notifications
You must be signed in to change notification settings - Fork 937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Incorrect Calculation of Cumulative Demand in Duplicator #6150
Conversation
Motivation: The cumulative demand in a duplicator is mistakenly calculated, causing it to reach the maximum value incorrectly. Modifications: - Corrected the calculation logic for cumulative demand in the duplicator. Result: - The cumulative demand in a duplicator is correctly calculated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -658,7 +658,7 @@ public void request(long n) { | |||
return; | |||
} | |||
|
|||
accumulateDemand(n); | |||
cumulativeDemand = LongMath.saturatedAdd(cumulativeDemand, n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question) Shouldn’t we take multi-threaded race conditions into account? I might not have a complete understanding of DownstreamSubscription
’s threading model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it okay because cumulativeDemand
is calculated by the thread who calls the subscription.request()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. If subscription.request()
should be sequentically called, is it safe to remove the following lines? It seems like requestedDemand
is always less than cumulativeDemand
in doRequestDemand()
. If I'm wrong, may I know when it could happen?
armeria/core/src/main/java/com/linecorp/armeria/common/stream/DefaultStreamMessageDuplicator.java
Lines 338 to 340 in eb7e451
if (cumulativeDemand <= requestedDemand) { | |
return; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subscription.request() should be sequentically called
This is for one child stream message.
processor.requestDemand(cumulativeDemand);
can be called from multiple child stream messages. Let's say there are two child stream messages and the first one request 10 and the second requests 1, then the condition will be true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. Everything makes sense now.
Motivation:
The cumulative demand in a duplicator is mistakenly calculated, causing it to reach the maximum value incorrectly.
Modifications:
Result: