Skip to content

PlannedReparent: create a new context for calling UndoDemoteMaster#5841

Merged
deepthi merged 1 commit intovitessio:masterfrom
planetscale:ds-prs-new-ctx-for-undo
Feb 24, 2020
Merged

PlannedReparent: create a new context for calling UndoDemoteMaster#5841
deepthi merged 1 commit intovitessio:masterfrom
planetscale:ds-prs-new-ctx-for-undo

Conversation

@deepthi
Copy link
Copy Markdown
Collaborator

@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

@deepthi deepthi requested review from enisoc, rafael and sougou February 21, 2020 20:14
@rafael
Copy link
Copy Markdown
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.

@deepthi
Copy link
Copy Markdown
Collaborator 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
@deepthi deepthi force-pushed the ds-prs-new-ctx-for-undo branch from 52220e1 to 1127303 Compare February 21, 2020 23:24
Copy link
Copy Markdown
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 force-pushed the ds-prs-new-ctx-for-undo branch from 1127303 to 056b18f Compare February 24, 2020 22:00
@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