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

PlannedReparent: create a new context for calling UndoDemoteMaster #5841

Merged
merged 1 commit into from
Feb 24, 2020

Conversation

deepthi
Copy link
Member

@deepthi deepthi commented Feb 21, 2020

If the calling context for PRS expires during the time that PRS is running and we have already demoted the old master, we attempt to undo the demotion.
There's clearly a bug in https://github.com/vitessio/vitess/blob/master/go/vt/wrangler/reparent.go#L609:

		if err != nil || (ctx.Err() != nil && ctx.Err() == context.DeadlineExceeded) {
			// If we fail to promote the new master, try to roll back to the
			// original master before aborting.
			undoCtx, undoCancel := context.WithTimeout(ctx, *topo.RemoteOperationTimeout)
			defer undoCancel()

We are using the original context to call UndoDemoteMaster (or rather as the base for a new context) and we don't know if that context is valid any longer.
We can fix this by using the background context to call UndoDemoteMaster.

cc @zmagg

Signed-off-by: deepthi deepthi@planetscale.com

@rafael
Copy link
Member

rafael commented Feb 21, 2020

However, this does not guarantee that it will get called because, remember, the original context used for calling PRS has already expired so execution of PRS might terminate at any point.

@deepthi could you clarify this? This is not obvious to me. I think if you pass a fresh context to wr.tmc.UndoDemoteMaster and this is called in a synchronous context, I don't see how execution of PRS might terminate before finishing the undo.

go/vt/wrangler/reparent.go Outdated Show resolved Hide resolved
@deepthi
Copy link
Member Author

deepthi commented Feb 21, 2020

However, this does not guarantee that it will get called because, remember, the original context used for calling PRS has already expired so execution of PRS might terminate at any point.

@deepthi could you clarify this? This is not obvious to me. I think if you pass a fresh context to wr.tmc.UndoDemoteMaster and this is called in a synchronous context, I don't see how execution of PRS might terminate before finishing the undo.

When run using vtctlclient, the call to PRS is itself an RPC to vtctld and its context is the one passed all the way through. Things are different if you use vtctl instead.
I think you are right.. so all we need is a 1-line fix.

@deepthi deepthi marked this pull request as ready for review February 21, 2020 23:23
Copy link
Member

@enisoc enisoc left a comment

Choose a reason for hiding this comment

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

LGTM

…oteMaster

Signed-off-by: deepthi <deepthi@planetscale.com>
@deepthi deepthi merged commit 1aeb13e into vitessio:master Feb 24, 2020
@deepthi deepthi deleted the ds-prs-new-ctx-for-undo branch February 24, 2020 23:17
ajm188 pushed a commit to tinyspeck/vitess that referenced this pull request Mar 11, 2020
…undo

PlannedReparent: create a new context for calling UndoDemoteMaster
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