-
Notifications
You must be signed in to change notification settings - Fork 911
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
Handle errors when registering new queue readers #4055
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
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 |
---|---|---|
|
@@ -39,12 +39,13 @@ const ( | |
clearSliceThrottleDuration = 10 * time.Second | ||
) | ||
|
||
var _ Action = (*actionQueuePendingTask)(nil) | ||
|
||
type ( | ||
actionQueuePendingTask struct { | ||
attributes *AlertAttributesQueuePendingTaskCount | ||
monitor Monitor | ||
maxReaderCount int | ||
completionFn actionCompletionFn | ||
|
||
// state of the action, used when running the action | ||
tasksPerNamespace map[namespace.ID]int | ||
|
@@ -58,28 +59,28 @@ func newQueuePendingTaskAction( | |
attributes *AlertAttributesQueuePendingTaskCount, | ||
monitor Monitor, | ||
maxReaderCount int, | ||
completionFn actionCompletionFn, | ||
) Action { | ||
) *actionQueuePendingTask { | ||
return &actionQueuePendingTask{ | ||
attributes: attributes, | ||
monitor: monitor, | ||
maxReaderCount: maxReaderCount, | ||
completionFn: completionFn, | ||
} | ||
} | ||
|
||
func (a *actionQueuePendingTask) Run(readerGroup *ReaderGroup) { | ||
defer a.completionFn() | ||
func (a *actionQueuePendingTask) Name() string { | ||
return "queue-pending-task" | ||
} | ||
|
||
func (a *actionQueuePendingTask) Run(readerGroup *ReaderGroup) error { | ||
// first check if the alert is still valid | ||
if a.monitor.GetTotalPendingTaskCount() <= a.attributes.CiriticalPendingTaskCount { | ||
return | ||
return nil | ||
} | ||
|
||
// then try to shrink existing slices, which may reduce pending task count | ||
readers := readerGroup.Readers() | ||
if a.tryShrinkSlice(readers) { | ||
return | ||
return nil | ||
} | ||
|
||
// have to unload pending tasks to reduce pending task count | ||
|
@@ -88,7 +89,7 @@ func (a *actionQueuePendingTask) Run(readerGroup *ReaderGroup) { | |
a.findSliceToClear( | ||
int(float64(a.attributes.CiriticalPendingTaskCount) * targetLoadFactor), | ||
) | ||
a.splitAndClearSlice(readers, readerGroup) | ||
return a.splitAndClearSlice(readers, readerGroup) | ||
} | ||
|
||
func (a *actionQueuePendingTask) tryShrinkSlice( | ||
|
@@ -177,7 +178,11 @@ func (a *actionQueuePendingTask) findSliceToClear( | |
func (a *actionQueuePendingTask) splitAndClearSlice( | ||
readers map[int32]Reader, | ||
readerGroup *ReaderGroup, | ||
) { | ||
) error { | ||
if err := a.ensureNewReaders(readers, readerGroup); err != nil { | ||
return err | ||
} | ||
|
||
for readerID, reader := range readers { | ||
if readerID == int32(a.maxReaderCount)-1 { | ||
// we can't do further split, have to clear entire slice | ||
|
@@ -216,17 +221,49 @@ func (a *actionQueuePendingTask) splitAndClearSlice( | |
} | ||
|
||
nextReader, ok := readerGroup.ReaderByID(readerID + 1) | ||
if ok { | ||
nextReader.MergeSlices(splitSlices...) | ||
} else { | ||
nextReader = readerGroup.NewReader(readerID+1, splitSlices...) | ||
if !ok { | ||
// this should never happen, we already ensured all readers are created. | ||
// we have no choice but to put those slices back | ||
reader.MergeSlices(splitSlices...) | ||
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. write some noticeable logs, or even emit metric here? |
||
continue | ||
} | ||
|
||
nextReader.MergeSlices(splitSlices...) | ||
nextReader.Pause(clearSliceThrottleDuration) | ||
} | ||
|
||
// it's likely that after a split, slice range can be shrinked | ||
// as tasks blocking the min key from moving have been moved to another slice/reader | ||
for _, reader := range readers { | ||
reader.ShrinkSlices() | ||
// ShrinkSlices will be triggered as part of checkpointing process | ||
// see queueBase.handleAlert() and queueBase.checkpoint() | ||
return nil | ||
} | ||
|
||
func (a *actionQueuePendingTask) ensureNewReaders( | ||
readers map[int32]Reader, | ||
readerGroup *ReaderGroup, | ||
) error { | ||
for readerID, reader := range readers { | ||
if readerID == int32(a.maxReaderCount)-1 { | ||
// we won't perform split | ||
continue | ||
} | ||
|
||
needNewReader := false | ||
reader.WalkSlices(func(s Slice) { | ||
// namespaceToClearPerSlice contains all the slices | ||
// that needs to be split & cleared | ||
_, ok := a.namespaceToClearPerSlice[s] | ||
needNewReader = needNewReader || ok | ||
}) | ||
|
||
if !needNewReader { | ||
continue | ||
} | ||
|
||
_, err := readerGroup.GetOrCreateReader(readerID + 1) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
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
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.
please add comment to explain what this action is about, what alert is it react to, and how does it mitigate the alert.
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.
yeah I will send follow up PRs to comment and add tests for those actions.