{"record":{"id":"54e9f29008e126e9","repo":"vitessio/vitess","slug":"no-primary-in-shard-v-v-54e9f2","errorCode":null,"errorMessage":"no primary in shard %v/%v","messagePattern":"no primary in shard (.+?)/(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/permissions.go","lineNumber":68,"sourceCode":"\t\ter.RecordError(err)\n\t\treturn\n\t}\n\n\tlog.Info(fmt.Sprintf(\"Diffing permissions for %v\", topoproto.TabletAliasString(alias)))\n\ttmutils.DiffPermissions(topoproto.TabletAliasString(primaryAlias), primaryPermissions, topoproto.TabletAliasString(alias), replicaPermissions, er)\n}\n\n// ValidatePermissionsShard validates all the permissions are the same\n// in a shard\nfunc (wr *Wrangler) ValidatePermissionsShard(ctx context.Context, keyspace, shard string) error {\n\tsi, err := wr.ts.GetShard(ctx, keyspace, shard)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// get permissions from the primary, or error\n\tif !si.HasPrimary() {\n\t\treturn fmt.Errorf(\"no primary in shard %v/%v\", keyspace, shard)\n\t}\n\tlog.Info(fmt.Sprintf(\"Gathering permissions for primary %v\", topoproto.TabletAliasString(si.PrimaryAlias)))\n\tprimaryPermissions, err := wr.GetPermissions(ctx, si.PrimaryAlias)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// read all the aliases in the shard, that is all tablets that are\n\t// replicating from the primary\n\taliases, err := wr.ts.FindAllTabletAliasesInShard(ctx, keyspace, shard)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// then diff all of them, except primary\n\ter := concurrency.AllErrorRecorder{}\n\twg := sync.WaitGroup{}\n\tfor _, alias := range aliases {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/permissions.go#L50-L86","documentation":"ValidatePermissionsShard validates that all tablets in a shard share consistent permissions by comparing against the primary's permissions. If the shard has no primary (HasPrimary() is false in the topo), validation cannot proceed and this error is reported.","triggerScenarios":"Running `vtctldclient ValidatePermissionsShard <keyspace>/<shard>` or ValidatePermissionsKeyspace against a shard whose ShardInfo lacks PrimaryAlias — e.g. no elected primary, primary just reparented and topo not updated, or a shard of an externally-managed keyspace.","commonSituations":"Auditing permissions after a failed reparent; shard with only replica/rdonly tablets; stale topo after primary deletion.","solutions":["Elect a primary: `vtctldclient PlannedReparentShard <keyspace>/<shard> --new-primary=<alias>`","Confirm with `vtctldclient GetShard <keyspace>/<shard>` that PrimaryAlias is set, then re-run validation","If the shard genuinely should not have a primary, skip validation for that shard"],"exampleFix":"// before\nvtctldclient ValidatePermissionsShard commerce/0   # no primary\n// after\nvtctldclient PlannedReparentShard commerce/0 --new-primary=zone1-101\nvtctldclient ValidatePermissionsShard commerce/0","handlingStrategy":"validation","validationCode":"si, err := ts.GetShard(ctx, keyspace, shard)\nif err != nil { return err }\nif !si.HasPrimary() {\n    return fmt.Errorf(\"cannot validate permissions: no primary in %s/%s\", keyspace, shard)\n}","typeGuard":"func hasPrimary(si *topo.ShardInfo) bool { return si != nil && si.HasPrimary() }","tryCatchPattern":"if err := wr.ValidatePermissionsShard(ctx, keyspace, shard); err != nil {\n    if strings.Contains(err.Error(), \"no primary in shard\") {\n        // reparent the shard or skip it in the validation loop\n    }\n}","preventionTips":["Ensure every shard has an elected primary before running permission validation","Use PlannedReparentShard / EmergencyReparentShard to restore primaries after failures","Filter out primary-less shards in keyspace-wide validation loops"],"tags":["vitess","wrangler","topology","permissions"],"backgroundTag":"shard-missing-primary","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}