{"record":{"id":"9d6aa41ad027fd3d","repo":"vitessio/vitess","slug":"can-t-get-primary-tablet-record-v-v","errorCode":null,"errorMessage":"can't get primary tablet record %v: %v","messagePattern":"can't get primary tablet record (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/builtinbackupengine.go","lineNumber":1837,"sourceCode":"\n// ShouldStartMySQLAfterRestore signifies if this backup engine needs to restart MySQL once the restore is completed.\nfunc (be *BuiltinBackupEngine) ShouldStartMySQLAfterRestore() bool {\n\treturn true\n}\n\nfunc (be *BuiltinBackupEngine) Name() string { return builtinBackupEngineName }\n\nfunc getPrimaryPosition(ctx context.Context, tmc tmclient.TabletManagerClient, ts *topo.Server, keyspace, shard string) (replication.Position, error) {\n\tsi, err := ts.GetShard(ctx, keyspace, shard)\n\tif err != nil {\n\t\treturn replication.Position{}, vterrors.Wrap(err, \"can't read shard\")\n\t}\n\tif topoproto.TabletAliasIsZero(si.PrimaryAlias) {\n\t\treturn replication.Position{}, fmt.Errorf(\"shard %v/%v has no primary\", keyspace, shard)\n\t}\n\tti, err := ts.GetTablet(ctx, si.PrimaryAlias)\n\tif err != nil {\n\t\treturn replication.Position{}, fmt.Errorf(\"can't get primary tablet record %v: %v\", topoproto.TabletAliasString(si.PrimaryAlias), err)\n\t}\n\tposStr, err := tmc.PrimaryPosition(ctx, ti.Tablet)\n\tif err != nil {\n\t\treturn replication.Position{}, fmt.Errorf(\"can't get primary replication position: %v\", err)\n\t}\n\tpos, err := replication.DecodePosition(posStr)\n\tif err != nil {\n\t\treturn replication.Position{}, fmt.Errorf(\"can't decode primary replication position %q: %v\", posStr, err)\n\t}\n\treturn pos, nil\n}\n\nfunc init() {\n\tBackupRestoreEngineMap[builtinBackupEngineName] = &BuiltinBackupEngine{}\n}\n\n// closeWithRetry does just what it says. Retrying a close operation is important as\n// an error is most likely transient/ephemeral and leaving around open file descriptors","sourceCodeStart":1819,"sourceCodeEnd":1855,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/builtinbackupengine.go#L1819-L1855","documentation":"After finding the shard's PrimaryAlias, getPrimaryPosition fetches the full tablet record via ts.GetTablet. If that record cannot be read from the topo, this error wraps the alias and the underlying cause. It usually means the shard record points at a primary that no longer exists in the topo.","triggerScenarios":"ts.GetTablet(ctx, si.PrimaryAlias) fails because the primary tablet record was deleted from topo (e.g. tablet fully removed after failover) while the shard record still references the stale alias.","commonSituations":"Stale PrimaryAlias after a primary was deleted or rebuilt; topo backend inconsistency (etcd/zookeeper) after partial failover; typo'd cell in tablet record cleanup.","solutions":["Read the wrapped cause to see if it is a node-not-found from topo.","Inspect the shard record's PrimaryAlias and compare with actual tablets (vtctldclient GetTablets).","Run EmergencyReparentShard or re-initialize the shard so PrimaryAlias points to a live tablet.","Prune stale tablet records from the topo and re-run the operation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"si, _ := ts.GetShard(ctx, keyspace, shard)\nif _, err := ts.GetTablet(ctx, si.PrimaryAlias); err != nil {\n\t// stale PrimaryAlias: reparent or clean topo before proceeding\n}","typeGuard":null,"tryCatchPattern":"if _, err := getPrimaryPosition(ctx, tmc, ts, ks, shard); err != nil {\n\tif strings.Contains(err.Error(), \"can't get primary tablet record\") {\n\t\t// refresh shard record / run ERS to fix stale alias\n\t}\n}","preventionTips":["Delete tablet records and update shard aliases atomically during decommission.","Monitor for shards whose PrimaryAlias has no matching tablet record.","Run topo consistency checks regularly."],"tags":["topo","shard","stale-metadata"],"backgroundTag":"topo-record-not-found","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}