{"record":{"id":"c1c82717f02b4b07","repo":"vitessio/vitess","slug":"shard-v-v-has-no-primary-c1c827","errorCode":null,"errorMessage":"shard %v/%v has no primary","messagePattern":"shard (.+?)/(.+?) has no primary","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/split.go","lineNumber":89,"sourceCode":"\t\t}\n\n\t\tsi.SourceShards = sourceShards\n\t\treturn nil\n\t})\n\treturn err\n}\n\n// WaitForFilteredReplication will wait until the Filtered Replication process has finished.\nfunc (wr *Wrangler) WaitForFilteredReplication(ctx context.Context, keyspace, shard string, maxDelay time.Duration) error {\n\tshardInfo, err := wr.TopoServer().GetShard(ctx, keyspace, shard)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(shardInfo.SourceShards) == 0 {\n\t\treturn fmt.Errorf(\"shard %v/%v has no source shard\", keyspace, shard)\n\t}\n\tif !shardInfo.HasPrimary() {\n\t\treturn fmt.Errorf(\"shard %v/%v has no primary\", keyspace, shard)\n\t}\n\talias := shardInfo.PrimaryAlias\n\ttabletInfo, err := wr.TopoServer().GetTablet(ctx, alias)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Always run an explicit healthcheck first to make sure we don't see any outdated values.\n\t// This is especially true for tests and automation where there is no pause of multiple seconds\n\t// between commands and the periodic healthcheck did not run again yet.\n\tif err := wr.TabletManagerClient().RunHealthCheck(ctx, tabletInfo.Tablet); err != nil {\n\t\treturn fmt.Errorf(\"failed to run explicit healthcheck on tablet: %v err: %v\", tabletInfo, err)\n\t}\n\n\tconn, err := tabletconn.GetDialer()(ctx, tabletInfo.Tablet, grpcclient.FailFast(false))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot connect to tablet %v: %v\", alias, err)\n\t}","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/split.go#L71-L107","documentation":"WaitForFilteredReplication reads replication lag from the shard's primary tablet, addressed via the shard record's PrimaryAlias. If the shard record has no primary (PrimaryAlias unset), lag cannot be measured and the call fails.","triggerScenarios":"Calling WaitForFilteredReplication on a destination shard whose record lacks a primary — e.g. InitShardPrimary was never run on the new shard, or the primary was lost and the record cleared.","commonSituations":"Reshard workflow creating a new shard but primary election/InitShardPrimary not completed yet; running wait before tablets in the new shard were started and promoted.","solutions":["Complete primary initialization: `vtctldclient InitShardPrimary <keyspace/shard> <tablet-alias>` (or let the workflow's planned rebalance/primary election finish).","Check `vtctldclient GetShard <keyspace>/<shard>` — primary_alias must be set — then re-run the wait.","If the shard is genuinely headless (no primary intended), WaitForFilteredReplication cannot be used for it."],"exampleFix":"// before\nvtctldclient WaitForFilteredReplication customer/0 30s\n// error: shard customer/0 has no primary\n// after\nvtctldclient InitShardPrimary customer/0 zone1-101\nvtctldclient WaitForFilteredReplication customer/0 30s","handlingStrategy":"validation","validationCode":"// Before waiting, ensure the shard has a primary\nshardInfo, _ := vtctldclientGetShard(keyspace, shard)\nif shardInfo.PrimaryAlias == nil || shardInfo.PrimaryAlias.Uid == 0 {\n    // run InitShardPrimary first\n    fmt.Printf(\"%s/%s has no primary; run InitShardPrimary\\n\", keyspace, shard)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Complete InitShardPrimary on new shards before waiting for filtered replication","Check primary_alias in GetShard output as a pipeline precondition","Never assume a freshly created shard has a primary"],"tags":["filtered-replication","resharding","primary","topo"],"backgroundTag":"no-primary-tablet","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}