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

first version of changes to avoid accidental worker state update during worker recovery #408

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

rasamala83
Copy link
Collaborator

No description provided.

@rasamala83 rasamala83 marked this pull request as draft December 16, 2024 11:39
Copy link
Collaborator

@shtiencode shtiencode left a comment

Choose a reason for hiding this comment

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

Replying on limited defined states allowed during recover (at the duration of workerclient.isUnderRecover may be able to simplify the set state change. Please take a look.

@@ -831,6 +831,7 @@ func (crd *Coordinator) dispatchRequest(request *netstring.Netstring) error {
// donot return a stranded worker. recover inserts a good worker back to pool.
//
if err == ErrSaturationKill {
logger.GetLogger().Log(logger.Info, "trigger recovery as part of ErrSaturationKill")
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the logging is desired, might as well add the worker id.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed this comment

if worker.Status == status {
return
}
if worker.isUnderRecovery == 1 && !callFromRecovery {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If by design a worker's state can only be either init, quce or fnsh, I think it may be feasible and simpler to discard any other state to be set as long as worker.isUnderRecovery is 1 since it is the first thing done after entering workerclient Recover().

lib/workerclient.go Outdated Show resolved Hide resolved
@@ -966,17 +995,23 @@ func (worker *WorkerClient) Write(ns *netstring.Netstring, nsCount uint16) error

// setState updates the worker state
func (worker *WorkerClient) setState(status HeraWorkerStatus) {
if worker.Status == status {
currentStatus := worker.Status
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this explictly done..
What happens if worker.Status value changes..?
Shouldn't we use the reflected value in comparison?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to avoid the race-condition on worker.Status value change. Currently we are not locking entire SetState operation.
So there is possibility of worker.Status value can change between worker.Status == status check to Contains(validStateTransitionMap[worker.Status ], status). To avoid it we are using local variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants