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

Add VTOrc recovery for mismatch in tablet type #17870

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

GuptaManan100
Copy link
Member

Description

This PR fixes the issue described in #17710.

As the issue describes, the problem happens when the tablet we are trying to promote via InitPrimary (can also happen in PromoteReplica) times out when writing its tablet record to the topo-server.
If the topo-server write has succeeded, then the tablet is a primary according to the tablet records, but its internal state doesn't say that its a tablet. Therefore, it keeps publishing to the vtgates that it is a replica. This makes the vtgates think there is no primary tablet and they don't know where to route the queries.

Previously there was no way for VTOrc to detect this situation. It had fixed the mysql level settings by calling UndoDemotePrimary but the tablet continued to publish itself as a Replica type.

This PR introduces 2 changes to fix this issue -

  1. The tablets also return their display tablet type in FullStatus output. This information is used by VTOrc to realize that there is a mismatch between the tablet type in the topo record, and the tablet type that the primary thinks it is.
  2. UndoDemotePrimary also checks that the internal state of the tablet is of type Primary. If not, then it consults the tablet record and if it finds a mismatch then it promotes the tablet without changing the primary term start time.

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

…played type doesn't match the tablet record

Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
…ype doesn't match the tablet record

Signed-off-by: Manan Gupta <manan@planetscale.com>
…sues

Signed-off-by: Manan Gupta <manan@planetscale.com>
Copy link
Contributor

vitess-bot bot commented Feb 26, 2025

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Feb 26, 2025
@GuptaManan100 GuptaManan100 removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Feb 26, 2025
@github-actions github-actions bot added this to the v22.0.0 milestone Feb 26, 2025
Copy link

codecov bot commented Feb 26, 2025

Codecov Report

Attention: Patch coverage is 87.17949% with 5 lines in your changes missing coverage. Please review.

Project coverage is 67.46%. Comparing base (e6b1b5d) to head (38e5780).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vttablet/tabletmanager/rpc_replication.go 75.00% 3 Missing ⚠️
go/vt/vtorc/inst/instance_dao.go 75.00% 1 Missing ⚠️
go/vt/vtorc/logic/topology_recovery.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17870      +/-   ##
==========================================
- Coverage   67.48%   67.46%   -0.03%     
==========================================
  Files        1593     1594       +1     
  Lines      258891   259096     +205     
==========================================
+ Hits       174725   174804      +79     
- Misses      84166    84292     +126     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@timvaillancourt
Copy link
Contributor

timvaillancourt commented Feb 27, 2025

@GuptaManan100 this is a cool PR 👍

I wonder if vttablet periodically checking-for/fixing the incorrect tablet type itself would be more robust, in addition to the VTOrc recovery. I think VTOrc should be required in a cluster but this would be more resilient in some scenarios where VTOrc is unable to fix this for whatever crazy reason, one edge case I can think of is VTOrc not being present in every cell + network partition, but there are probably many cases

I suppose I'm thinking vttablet would periodically run logic similar to what you added here and VTOrc can trigger the same logic. What do you think?

@GuptaManan100
Copy link
Member Author

Hey @timvaillancourt

No I think I would still want VTOrc to make the call. Because changing tablet types are still a cluster event in some sense. Because changing type to primary (with a higher timestamp), is effectively doing a tablet promotion. (Check the test I've added too), and its better to let VTOrc handle it.

Specifically, if we see a newer primary tablet, then VTOrc might choose to run the NotConnectedToPrimary recovery instaed of PrimaryMismatch that I've added now. This additional context about the shard record, and whether another priary tablet with a higher timestamp exists, is something only VTOrc has, and adding it to vttablet would complicate things and also duplicate the roles.

@deepthi
Copy link
Member

deepthi commented Feb 28, 2025

How did this even happen? Did we run out the context clock?

			log.Errorf("Error changing type in topo record for tablet %s :- %v\nWill keep trying to read from the toposerver", topoproto.TabletAliasString(ts.tm.tabletAlias), err)
			// In case of a topo error, we aren't sure if the data has been written or not.
			// We must read the data again and verify whether the previous write succeeded or not.
			// The only way to guarantee safety is to keep retrying read until we succeed
			for {
				if ctx.Err() != nil {
					return fmt.Errorf("context canceled updating tablet_type for %s in the topo, please retry", ts.tm.tabletAlias)
				}
				ti, errInReading := ts.tm.TopoServer.GetTablet(ctx, ts.tm.tabletAlias)
				if errInReading != nil {
					<-time.After(100 * time.Millisecond)
					continue
				}
				if ti.Type == tabletType && proto.Equal(ti.PrimaryTermStartTime, PrimaryTermStartTime) {
					log.Infof("Tablet record in toposerver matches, continuing operation")
					break
				}
				log.Errorf("Tablet record read from toposerver does not match what we attempted to write, canceling operation")
				return err
			}
		}

Do you know whether a "context canceled ..." error was received?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Cluster management Component: VTorc Vitess Orchestrator integration Type: Bug Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Report: Failure in first call to PRS can lead to the cluster having no primary
3 participants