{"record":{"id":"9304762ee022d6f7","repo":"vitessio/vitess","slug":"tabletexternallyreparented-failed-on-primary-v","errorCode":null,"errorMessage":"TabletExternallyReparented failed on primary %v: %v","messagePattern":"TabletExternallyReparented failed on primary (.+?): (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtcombo/tablet_map.go","lineNumber":133,"sourceCode":"\t\tAlias: alias,\n\t\tPortMap: map[string]int32{\n\t\t\t\"vt\":   int32(8000 + uid),\n\t\t\t\"grpc\": int32(9000 + uid),\n\t\t},\n\t\tKeyspace:       keyspace,\n\t\tShard:          shard,\n\t\tKeyRange:       kr,\n\t\tType:           initTabletType,\n\t\tDbNameOverride: dbname,\n\t}\n\tif err := tm.Start(tablet, nil); err != nil {\n\t\treturn err\n\t}\n\n\tif tabletType == topodatapb.TabletType_PRIMARY {\n\t\t// Semi-sync has to be set to false, since we have 1 single backing MySQL\n\t\tif err := tm.ChangeType(ctx, topodatapb.TabletType_PRIMARY /* semi-sync */, false); err != nil {\n\t\t\treturn fmt.Errorf(\"TabletExternallyReparented failed on primary %v: %v\", topoproto.TabletAliasString(alias), err)\n\t\t}\n\t}\n\tcontroller.AddStatusHeader()\n\tcontroller.AddStatusPart()\n\ttabletMap[uid] = &comboTablet{\n\t\talias:      alias,\n\t\tkeyspace:   keyspace,\n\t\tshard:      shard,\n\t\ttabletType: tabletType,\n\t\tdbname:     dbname,\n\t\tuid:        uid,\n\n\t\tqsc: controller,\n\t\ttm:  tm,\n\t}\n\treturn nil\n}\n","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtcombo/tablet_map.go#L115-L151","documentation":"In vtcombo (vitess local/test combo), CreateTablet promotes a tablet to PRIMARY by calling tm.ChangeType(ctx, TabletType_PRIMARY, semi-sync=false). Failure is wrapped as 'TabletExternallyReparented failed on primary'. It signals the tablet manager could not switch the tablet's MySQL/tablet state to primary.","triggerScenarios":"Creating a tablet with type PRIMARY in vtcombo when tm.ChangeType fails: backing mysqld not running/healthy, tablet manager RPC failure, or semi-sync configuration conflict on the single shared MySQL instance.","commonSituations":"Local vitess (vitess-local) environment where mysqld for the tablet isn't up yet or crashed; another tablet already claims primary on the shard; mysqlctl startup still in progress when CreateTablet runs.","solutions":["Check mysqld status for the tablet uid (ps/logs under $VTDATAROOT/vt_0000000001/) and ensure it is fully started before creating a PRIMARY tablet.","Inspect the tablet's tabletmanager logs for the underlying ChangeType error and address it (e.g. replication not configured, semi-sync plugin issues).","Re-run vtcombo/tablet creation after cleanup (vtctldclient DeleteTablet or removing the topo entry) if a stale primary exists."],"exampleFix":"// before (create PRIMARY tablet before mysqld ready)\nCreateTablet(ctx, ts, tmc, cell, uid, topodatapb.TabletType_PRIMARY)\n// after\nwaitForMysqld(uid) // ensure mysqld is healthy first\nCreateTablet(ctx, ts, tmc, cell, uid, topodatapb.TabletType_PRIMARY)","handlingStrategy":"retry","validationCode":"// Go: ensure mysqld is up before creating a PRIMARY tablet\nif err := mysqlctl.WaitForMysqld(ctx, tabletDir, uid, 30*time.Second); err != nil {\n    return fmt.Errorf(\"mysqld not ready for uid %d: %w\", uid, err)\n}","typeGuard":null,"tryCatchPattern":"if err := CreateTablet(...); err != nil {\n    if strings.Contains(err.Error(), \"TabletExternallyReparented failed\") {\n        // check tablet logs; wait for mysqld; retry with backoff\n    }\n}","preventionTips":["Start mysqld fully before promoting the tablet to PRIMARY in local environments.","Avoid creating multiple PRIMARY tablets for the same shard.","Capture tablet manager logs on failure to identify the underlying ChangeType error."],"tags":["vtcombo","tablet","primary","replication"],"backgroundTag":"tablet-promotion-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}