{"record":{"id":"11ddee5455a7d686","repo":"vitessio/vitess","slug":"tablet-v-initreplica-failed-v","errorCode":null,"errorMessage":"tablet %v InitReplica failed: %v","messagePattern":"tablet (.+?) InitReplica failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/grpcvtctldserver/server.go","lineNumber":2980,"sourceCode":"\twgReplicas := sync.WaitGroup{}\n\tvar primaryErr error\n\tfor alias, tabletInfo := range tabletMap {\n\t\tif alias == primaryElectTabletAliasStr {\n\t\t\twgPrimary.Add(1)\n\t\t\tgo func(alias string, tabletInfo *topo.TabletInfo) {\n\t\t\t\tdefer wgPrimary.Done()\n\t\t\t\tlogger.Infof(\"populating reparent journal on new primary %v\", alias)\n\t\t\t\tprimaryErr = tmc.PopulateReparentJournal(replCtx, tabletInfo.Tablet, now,\n\t\t\t\t\tinitShardPrimaryOperation,\n\t\t\t\t\treq.PrimaryElectTabletAlias, rp)\n\t\t\t}(alias, tabletInfo)\n\t\t} else {\n\t\t\twgReplicas.Add(1)\n\t\t\tgo func(alias string, tabletInfo *topo.TabletInfo) {\n\t\t\t\tdefer wgReplicas.Done()\n\t\t\t\tlogger.Infof(\"initializing replica %v\", alias)\n\t\t\t\tif err := tmc.InitReplica(replCtx, tabletInfo.Tablet, req.PrimaryElectTabletAlias, rp, now, policy.IsReplicaSemiSync(durability, primaryElectTabletInfo.Tablet, tabletInfo.Tablet)); err != nil {\n\t\t\t\t\trec.RecordError(fmt.Errorf(\"tablet %v InitReplica failed: %v\", alias, err))\n\t\t\t\t}\n\t\t\t}(alias, tabletInfo)\n\t\t}\n\t}\n\n\t// After the primary is done, we can update the shard record\n\t// (note with semi-sync, it also means at least one replica is done).\n\twgPrimary.Wait()\n\tif primaryErr != nil {\n\t\t// The primary failed, there is no way the\n\t\t// replicas will work.  So we cancel them all.\n\t\tlogger.Warningf(\"primary failed to PopulateReparentJournal, canceling replicas\")\n\t\treplCancel()\n\t\twgReplicas.Wait()\n\t\treturn fmt.Errorf(\"failed to PopulateReparentJournal on primary: %v\", primaryErr)\n\t}\n\tif !topoproto.TabletAliasEqual(shardInfo.PrimaryAlias, req.PrimaryElectTabletAlias) {\n\t\tif _, err := s.ts.UpdateShardFields(ctx, req.Keyspace, req.Shard, func(si *topo.ShardInfo) error {","sourceCodeStart":2962,"sourceCodeEnd":2998,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/server.go#L2962-L2998","documentation":"When re-initializing replicas to point at the new primary, the InitReplica RPC to a tablet failed. Each failing replica is recorded and reported; the shard record may still have been updated to the new primary, so remaining replicas need fixing.","triggerScenarios":"InitShardPrimary loop calling tmc.InitReplica on each replica — tablet down, mysql replication cannot be started, or wrong primary alias passed.","commonSituations":"A replica is in a bad replication state (e.g. old primary still claiming); tablet agent unreachable; durability/semi-sync policy prevents starting replication against the new primary.","solutions":["Check the reported tablet's vttablet/mysqld logs and fix replication (START REPLICA, reset then retry)","Run `vtctldclient InitReplica`-equivalent (ReparentTablet) on the failing tablet individually","Confirm the tablet is serving from the right keyspace/shard and not deprecated/scraped","If unrecoverable, Scrap and re-provision the tablet"],"exampleFix":"// before: replica can't connect to new primary\nreplica> SHOW REPLICA STATUS;  # wrong master host\n// after: point replica at the new primary manually then retry\nreplica> CHANGE REPLICATION SOURCE TO SOURCE_HOST='<new-primary>', ...;\nreplica> START REPLICA;","handlingStrategy":"retry","validationCode":"// pre-flight: every replica must be reachable and not scraped\nfor _, t := range shardTablets {\n    if t.Type == topodatapb.TabletType_SCRAP { continue }\n    if err := pingTablet(ctx, t); err != nil {\n        return fmt.Errorf(\"replica %s unhealthy: %w\", t.Alias, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"// collect failing replicas and remediate individually\nif strings.Contains(err.Error(), \"InitReplica failed\") {\n    for _, alias := range parseFailedAliases(err) {\n        repointReplicaManually(ctx, alias, newPrimary)\n    }\n}","preventionTips":["Keep replication healthy (monitor Seconds_Behind_Source) to ease failovers","Fix semi-sync settings on replicas before reparenting","Repair or scrap dead tablets immediately","Practice reparents in staging to catch replica-init issues"],"tags":["vtctld","reparent","replication","replica"],"backgroundTag":"init-replica-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}