{"record":{"id":"7babca8e85dcafeb","repo":"vitessio/vitess","slug":"creating-this-tablet-would-override-old-primary-v","errorCode":null,"errorMessage":"creating this tablet would override old primary %v in shard %v/%v, use allow_master_override flag","messagePattern":"creating this tablet would override old primary (.+?) in shard (.+?)/(.+?), use allow_master_override flag","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/topo/tablet.go","lineNumber":623,"sourceCode":"\t\t// create the parent keyspace and shard if needed\n\t\tsi, err = ts.GetOrCreateShard(ctx, tablet.Keyspace, tablet.Shard)\n\t} else {\n\t\tsi, err = ts.GetShard(ctx, tablet.Keyspace, tablet.Shard)\n\t\tif IsErrType(err, NoNode) {\n\t\t\treturn errors.New(\"missing parent shard, use -parent option to create it, or CreateKeyspace / CreateShard\")\n\t\t}\n\t}\n\n\t// get the shard, checks a couple things\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot get (or create) shard %v/%v: %v\", tablet.Keyspace, tablet.Shard, err)\n\t}\n\tif !key.KeyRangeEqual(si.KeyRange, tablet.KeyRange) {\n\t\treturn fmt.Errorf(\"shard %v/%v has a different KeyRange: %v != %v\", tablet.Keyspace, tablet.Shard, si.KeyRange, tablet.KeyRange)\n\t}\n\tif tablet.Type == topodatapb.TabletType_PRIMARY && si.HasPrimary() && !topoproto.TabletAliasEqual(si.PrimaryAlias, tablet.Alias) && !allowPrimaryOverride {\n\t\t// InitTablet is deprecated, so the flag has not been renamed\n\t\treturn fmt.Errorf(\"creating this tablet would override old primary %v in shard %v/%v, use allow_master_override flag\", topoproto.TabletAliasString(si.PrimaryAlias), tablet.Keyspace, tablet.Shard)\n\t}\n\n\tif tablet.Type == topodatapb.TabletType_PRIMARY {\n\t\t// we update primary_term_start_time even if the primary hasn't changed\n\t\t// because that means a new primary term with the same primary\n\t\ttablet.PrimaryTermStartTime = protoutil.TimeToProto(time.Now())\n\t}\n\n\terr = ts.CreateTablet(ctx, tablet)\n\tif IsErrType(err, NodeExists) && allowUpdate {\n\t\t// Try to update then\n\t\toldTablet, err := ts.GetTablet(ctx, tablet.Alias)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed reading existing tablet %v: %v\", topoproto.TabletAliasString(tablet.Alias), err)\n\t\t}\n\n\t\t// Check we have the same keyspace / shard, and if not,\n\t\t// require the allowDifferentShard flag.","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/topo/tablet.go#L605-L641","documentation":"When registering a PRIMARY tablet, InitTablet refuses to silently replace an existing primary in the shard record. This error is thrown when the shard already has a primary whose alias differs from the tablet being registered and allowPrimaryOverride is false. It protects against two primaries being recorded in one shard.","triggerScenarios":"Calling InitTablet with tablet.Type == PRIMARY while the shard record's PrimaryAlias points at a different tablet and allowPrimaryOverride (legacy allow_master_override) is not set — typically during manual tablet startup or an unplanned promotion via InitTablet instead of PlannerReparentShard/ElectNewPrimary.","commonSituations":"Restarting a former primary after a failover promoted another tablet (the topo still lists the new primary); running vttablet -init with primary type on a shard that already has a primary; DR/failover drills done by hand instead of via vtctld reparent commands; stale topo state after a network partition during a previous promotion.","solutions":["If a failover already happened, do not re-register the old primary as PRIMARY: restart it as REPLICA (`vttablet ... -init_tablet_type REPLICA`) or run `vtctldclient RebuildKeyspaceGraph` after fixing its type.","Use the proper reparent workflow (`PlannerReparentShard` / `EmergencyReparentShard`) to change primaries instead of InitTablet.","If overriding is genuinely intended (e.g. disaster recovery of the topo record), pass allow_master_override/allowPrimaryOverride=true, after confirming the old primary alias is truly defunct.","Verify current shard state with `vtctldclient GetShard <keyspace>/<shard>` before any manual primary registration."],"exampleFix":"// before (former primary restarting as PRIMARY, new primary exists)\nvttablet -init_tablet_type PRIMARY ...   // would override old primary\n// after: come back as replica, or failover properly\nvttablet -init_tablet_type REPLICA ...\n# or, for a true takeover:\nvtctldclient EmergencyReparentShard commerce/-","handlingStrategy":"validation","validationCode":"// Check shard primary state before registering a PRIMARY tablet\nsi, _ := ts.GetShard(ctx, keyspace, shard)\nif tablet.Type == topodatapb.TabletType_PRIMARY && si.HasPrimary() &&\n    !topoproto.TabletAliasEqual(si.PrimaryAlias, tablet.Alias) {\n    return fmt.Errorf(\"shard already has primary %s; use reparent workflow\",\n        topoproto.TabletAliasString(si.PrimaryAlias))\n}","typeGuard":"func shardPrimaryConflict(si *topo.ShardInfo, t *topodatapb.Tablet) bool {\n    return t.Type == topodatapb.TabletType_PRIMARY && si.HasPrimary() &&\n        !topoproto.TabletAliasEqual(si.PrimaryAlias, t.Alias)\n}","tryCatchPattern":"if err := topotools.InitTablet(ctx, ts, false, tablet, cp); err != nil {\n    if strings.Contains(err.Error(), \"would override old primary\") {\n        // a promotion already happened; restart this tablet as REPLICA\n        return fmt.Errorf(\"restart tablet with -init_tablet_type REPLICA or run EmergencyReparentShard: %w\", err)\n    }\n    return err\n}","preventionTips":["Never change primaries via InitTablet; use PlannerReparentShard/EmergencyReparentShard.","Restart failed-over former primaries as REPLICA, not with their old PRIMARY type.","Inspect `vtctldclient GetShard` before any manual primary registration.","Reserve allow_master_override for deliberate disaster-recovery repairs with verified state."],"tags":["topo","tablet","primary","failover"],"backgroundTag":"primary-conflict","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}