{"record":{"id":"a4ae67b2716aa9f3","repo":"vitessio/vitess","slug":"no-primary-found-for-shard","errorCode":null,"errorMessage":"no primary found for shard","messagePattern":"no primary found for shard","errorType":"error_code","errorClass":"ErrNoShardPrimary","httpStatus":null,"severity":"critical","filePath":"go/vt/vtctl/workflow/vexec/vexec.go","lineNumber":54,"sourceCode":")\n\nconst (\n\t// VExecTableQualifier is the qualifier that all tables supported by vexec\n\t// are prefixed by.\n\tVExecTableQualifier = \"_vt\"\n\n\t// VReplicationLogTableName is the unqualified name of the vreplication_log\n\t// table supported by vexec.\n\tVReplicationLogTableName = \"vreplication_log\"\n\t// VReplicationTableName is the unqualified name of the vreplication table\n\t// supported by vexec.\n\tVReplicationTableName = \"vreplication\"\n)\n\nvar ( // Topo lookup errors.\n\t// ErrNoShardPrimary occurs when a shard is found with no serving\n\t// primary.\n\tErrNoShardPrimary = errors.New(\"no primary found for shard\")\n\t// ErrNoShardsForKeyspace occurs when attempting to run a vexec on an empty\n\t// keyspace.\n\tErrNoShardsForKeyspace = errors.New(\"no shards found in keyspace\")\n)\n\nvar ( // Query parsing and planning errors.\n\t// ErrUnsupportedQuery occurs when attempting to run an unsupported query\n\t// through vexec.\n\tErrUnsupportedQuery = errors.New(\"query not supported by vexec\")\n\t// ErrUnsupportedTable occurs when attempting to run vexec on an unsupported\n\t// table. At the time of writing, this occurs when attempting to query any\n\t// table other than _vt.vreplication.\n\tErrUnsupportedTable = errors.New(\"table not supported by vexec\")\n)\n\n// VExec provides the main interface to planning and executing vexec queries\n// (normally, queries on tables in the `_vt` database). It currently supports\n// some limited vreplication queries; this set of supported behavior will expand","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/vexec/vexec.go#L36-L72","documentation":"ErrNoShardPrimary is raised during vexec initialization when a shard in the target keyspace has no serving primary tablet. VExec must send its statements to each shard's primary, so a primary-less shard makes the operation impossible. It is a sentinel used by initialize().","triggerScenarios":"Running VExec (e.g. MoveTables vexec-based cleanup or workflow commands touching _vt tables) while some shard in the keyspace has no PRIMARY tablet in serving state — primary down, primary demoted without a new election, or topo serving graph stale.","commonSituations":"After an emergency failover where the primary never got rebuilt, during manual repair of replication, or in degraded shards where vtctldclient PluralType replays never completed.","solutions":["Restore a primary for the shard (Elect/planned rebalance or InitializeShardPrimary) and verify it is SERVING in topology","Run RefreshState on the shard's tablets so the serving graph no longer lists a primary-less shard","Retry the vexec/workflow command once all shards report a primary"],"exampleFix":"# before: shard -80 has no primary\nvtctldclient Workflow --keyspace customer --workflow sales Stop\n# ErrNoShardPrimary: no primary found for shard\n# after\nvtctldclient PluralType -80 <new-replica> ; vtctldclient InitializeShardPrimary customer -80 <alias>\nvtctldclient Workflow --keyspace customer --workflow sales Stop","handlingStrategy":"validation","validationCode":"for _, shard := range shardNames {\n    si, err := ts.TopoServer().GetShard(ctx, keyspace, shard)\n    if err != nil || si.PrimaryAlias == nil {\n        return fmt.Errorf(\"shard %s/%s has no primary; cannot run vexec\", keyspace, shard)\n    }\n}","typeGuard":"func shardHasPrimary(si *topodatapb.ShardInfo) bool {\n    return si != nil && si.PrimaryAlias != nil\n}","tryCatchPattern":"if err := vexec.Execute(ctx); err != nil {\n    if errors.Is(err, workflow.ErrNoShardPrimary) {\n        return fmt.Errorf(\"elect a primary for all shards and retry: %w\", err)\n    }\n    return err\n}","preventionTips":["Run ERS/PRS checks after failovers to ensure every shard has a serving primary","Include a no-primary pre-check in automation that triggers vexec","Alert on shards with nil PrimaryAlias in the topo serving graph"],"tags":["vreplication","vexec","topology"],"backgroundTag":"no-primary-in-shard","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}