Skip to content
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

Merged
merged 2 commits into from
Mar 12, 2025

Conversation

minwoox
Copy link
Contributor

@minwoox minwoox commented Mar 10, 2025

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.

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.
@minwoox minwoox added the defect label Mar 10, 2025
@minwoox minwoox added this to the 1.32.1 milestone Mar 10, 2025
Copy link
Contributor

@ikhoon ikhoon left a 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);
Copy link
Contributor

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.

Copy link
Contributor Author

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()?

Copy link
Contributor

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?

if (cumulativeDemand <= requestedDemand) {
return;
}

Copy link
Contributor Author

@minwoox minwoox Mar 12, 2025

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.

Copy link
Contributor

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.

@minwoox minwoox merged commit 8150425 into line:main Mar 12, 2025
14 checks passed
@minwoox minwoox deleted the fix_cumulativeDemand branch March 12, 2025 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants