{"record":{"id":"8f3aa5c92322daef","repo":"vitessio/vitess","slug":"shard-s-s-has-no-primary","errorCode":null,"errorMessage":"shard %s/%s has no primary","messagePattern":"shard (.+?)/(.+?) has no primary","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/clone.go","lineNumber":89,"sourceCode":"}\n\n// CloneFromDonor clones data from the specified donor tablet using MySQL CLONE REMOTE and returns the GTID position of the cloned data. If mycnf is non-nil, CloneFromDonor may use it to restart mysqld locally when CLONE completes but MySQL cannot restart itself.\nfunc CloneFromDonor(ctx context.Context, topoServer *topo.Server, mysqld MysqlDaemon, mycnf *Mycnf, keyspace, shard string) (replication.Position, error) {\n\tvar donorAlias *topodatapb.TabletAlias\n\tvar err error\n\n\tswitch {\n\tcase cloneFromPrimary && cloneFromTablet != \"\":\n\t\treturn replication.Position{}, errors.New(\"--clone-from-primary and --clone-from-tablet are mutually exclusive\")\n\tcase cloneFromPrimary:\n\t\t// Look up the primary tablet from topology.\n\t\tlog.Info(fmt.Sprintf(\"Looking up primary tablet for shard %s/%s for use as CLONE REMOTE donor\", keyspace, shard))\n\t\tsi, err := topoServer.GetShard(ctx, keyspace, shard)\n\t\tif err != nil {\n\t\t\treturn replication.Position{}, fmt.Errorf(\"failed to get shard %s/%s: %v\", keyspace, shard, err)\n\t\t}\n\t\tif topoproto.TabletAliasIsZero(si.PrimaryAlias) {\n\t\t\treturn replication.Position{}, fmt.Errorf(\"shard %s/%s has no primary\", keyspace, shard)\n\t\t}\n\t\tdonorAlias = si.PrimaryAlias\n\t\tlog.Info(fmt.Sprintf(\"Found primary tablet %s for use as CLONE REMOTE donor\", topoproto.TabletAliasString(donorAlias)))\n\tcase cloneFromTablet != \"\":\n\t\t// Parse the explicit donor tablet alias.\n\t\tlog.Info(fmt.Sprintf(\"Using tablet %s for use as CLONE REMOTE donor\", cloneFromTablet))\n\t\tdonorAlias, err = topoproto.ParseTabletAlias(cloneFromTablet)\n\t\tif err != nil {\n\t\t\treturn replication.Position{}, fmt.Errorf(\"invalid tablet alias %q: %v\", cloneFromTablet, err)\n\t\t}\n\tdefault:\n\t\treturn replication.Position{}, errors.New(\"no donor specified\")\n\t}\n\n\t// Get donor tablet info from topology.\n\tdonorTablet, err := topoServer.GetTablet(ctx, donorAlias)\n\tif err != nil {\n\t\treturn replication.Position{}, fmt.Errorf(\"failed to get tablet %s from topology: %v\", topoproto.TabletAliasString(donorAlias), err)","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/clone.go#L71-L107","documentation":"Returned by mysqlctl clone logic when the specified shard in the given keyspace has no primary tablet assigned, so there is no source to clone from.","triggerScenarios":"CloneFromDonor with --clone-from-primary on a shard with no primary (e.g., during resharding setup, after primary failure before failover, or a fresh shard with no tablets).","commonSituations":"Mid-failout/failover window, orphan shard, Principaled shard not yet elected, user targeting wrong shard that is intentionally empty.","solutions":["Check the shard with `vtctldclient GetShard <keyspace>/<shard>` — wait for or trigger primary election (PlannedReparentShard / EmergencyReparentShard).","Choose a specific donor with --clone-from-tablet instead of --clone-from-primary.","Ensure a tablet is started and promoted to primary for that shard.","Verify you are targeting the correct keyspace/shard."],"exampleFix":"// before\nvttablet --clone-from-primary ...\n// after\nvttablet --clone-from-tablet zone1-0000000100 ...","handlingStrategy":"validation","validationCode":"shardInfo, _ := topoServer.GetShard(ctx, keyspace, shard)\nif shardInfo == nil || shardInfo.PrimaryAlias == nil || shardInfo.PrimaryAlias.Uid == 0 {\n\treturn errors.New(\"shard has no primary; use --clone-from-tablet instead\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"has no primary\") {\n\t// fall back to --clone-from-tablet with a known replica\n}","preventionTips":["Ensure a primary is elected before restores","Use --clone-from-tablet when primary availability is uncertain"],"tags":["topology","clone","primary","shard"],"backgroundTag":"shard-has-no-primary","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}