-
Notifications
You must be signed in to change notification settings - Fork 52
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
[Do not merge] alternative approach to clear state when not leader anymore #75
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,19 +89,22 @@ func (s *scaler) compareScales(current, desired int32) { | |
if s.desiredScale > s.currentScale { | ||
// Scale up immediately. | ||
go s.scaleFunc(s.desiredScale, false) | ||
s.scaleDownStarted = false | ||
s.stopScaleDown() | ||
} else if s.desiredScale == s.currentScale { | ||
// Do nothing, schedule nothing. | ||
if s.scaleDownTimer != nil { | ||
s.scaleDownTimer.Stop() | ||
} | ||
s.scaleDownStarted = false | ||
s.stopScaleDown() | ||
} else { | ||
// Schedule a scale down. | ||
|
||
if s.scaleDownTimer == nil { | ||
s.scaleDownTimer = time.AfterFunc(s.scaleDownDelay, func() { | ||
if err := s.scaleFunc(s.desiredScale, false); err != nil { | ||
s.mtx.Lock() | ||
s.scaleDownStarted = false // mark completed already | ||
desiredScale, currentScale := s.desiredScale, s.currentScale | ||
s.mtx.Unlock() | ||
if desiredScale == -1 || desiredScale == currentScale { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s.desiredScale could only be
asking to improve my understanding, this is not feedback to your code or a request for any changes |
||
return | ||
} | ||
if err := s.scaleFunc(desiredScale, false); err != nil { | ||
log.Printf("task: run error: %v", err) | ||
} else { | ||
s.scaleDownStarted = false | ||
|
@@ -116,6 +119,21 @@ func (s *scaler) compareScales(current, desired int32) { | |
} | ||
} | ||
|
||
// Stop stops the scale down process for the scaler and unsets the desired scale | ||
func (s *scaler) Stop() { | ||
s.mtx.Lock() | ||
defer s.mtx.Unlock() | ||
s.stopScaleDown() | ||
s.desiredScale = -1 | ||
} | ||
|
||
func (s *scaler) stopScaleDown() { | ||
if s.scaleDownTimer != nil && s.scaleDownStarted { | ||
s.scaleDownTimer.Stop() | ||
} | ||
s.scaleDownStarted = false | ||
} | ||
|
||
type scale struct { | ||
Current, Min, Max int32 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
cleanup desired scale and downscale when instance is not leader anymore
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 think this would break scale from 0 in the proxy which should still be possible
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 think this would break the
h.Deployments.AtLeastOne(deploy)
call in the proxies that are not a leader.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.
nvm it won't break that since it's a different flow. Currently all stop does is to stop the scale down timer.