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 bug: incorrectly defined storeToken using uint in warmup flow control #218

Merged
merged 2 commits into from
Sep 1, 2020

Conversation

louyuting
Copy link
Collaborator

@louyuting louyuting commented Aug 31, 2020

Describe what this PR does / why we need it

storedTokens *uint64

Define storedTokens as uint64 might cause bug.

if currentValue := atomic.AddUint64(d.storedTokens, uint64(0-passQps)); currentValue < 0 {

Does this pull request fix one issue?

Describe how you did it

Describe how to verify it

Special notes for reviews

@codecov-commenter
Copy link

codecov-commenter commented Aug 31, 2020

Codecov Report

Merging #218 into master will decrease coverage by 0.03%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #218      +/-   ##
==========================================
- Coverage   42.58%   42.54%   -0.04%     
==========================================
  Files          82       82              
  Lines        4405     4409       +4     
==========================================
  Hits         1876     1876              
- Misses       2289     2293       +4     
  Partials      240      240              
Impacted Files Coverage Δ
core/flow/rule_manager.go 53.78% <0.00%> (-0.83%) ⬇️
core/flow/tc_warm_up.go 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 36a09c5...4048032. Read the comment docs.

@louyuting louyuting requested a review from sczyh30 August 31, 2020 14:05
@louyuting louyuting added this to the 0.6.0 milestone Aug 31, 2020
@@ -41,64 +41,67 @@ func NewWarmUpTrafficShapingCalculator(rule *FlowRule) *WarmUpTrafficShapingCalc
maxToken: maxToken,
slope: slope,
threshold: rule.Count,
storedTokens: new(uint64),
lastFilledTime: new(uint64),
storedTokens: 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is 0 and no assignment is required。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just an explicit declaration

aboveToken := restToken - d.warningToken
warningQps := math.Nextafter(1.0/(float64(aboveToken)*d.slope+1.0/d.threshold), math.MaxFloat64)
restToken := atomic.LoadInt64(&c.storedTokens)
if restToken < 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no situation where the restToken is less than 0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might have;

if atomic.CompareAndSwapInt64(&c.storedTokens, oldValue, newValue) {
		if currentValue := atomic.AddUint64(d.storedTokens, uint64(0-passQps)); currentValue < 0 {			if currentValue := atomic.AddInt64(&c.storedTokens, int64(-passQps)); currentValue < 0 {

In concurrency, after currentValue := atomic.AddInt64(&c.storedTokens, int64(-passQps)); might cause storedTokens is less than 0;

@louyuting louyuting added kind/bug Something isn't working to-review PRs to review labels Aug 31, 2020
Copy link
Member

@sczyh30 sczyh30 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sczyh30 sczyh30 merged commit 1a987a8 into alibaba:master Sep 1, 2020
@sczyh30
Copy link
Member

sczyh30 commented Sep 1, 2020

Thanks!

@sczyh30 sczyh30 removed the to-review PRs to review label Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants