{"record":{"id":"a4062087481963a4","repo":"vitessio/vitess","slug":"cannot-delete-tablet-v-w","errorCode":null,"errorMessage":"cannot delete tablet %v: %w","messagePattern":"cannot delete tablet (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/grpcvtctldserver/topo.go","lineNumber":200,"sourceCode":"\t\t}\n\n\t\tlog.Info(fmt.Sprintf(\"Deleting all %d tablets in shard %v/%v cell %v\", len(tabletMap), keyspace, shard, cell))\n\t\tfor alias, tablet := range tabletMap {\n\t\t\t// We don't care about updating the ShardReplication object, because\n\t\t\t// later we're going to delete the entire object.\n\t\t\tlog.Info(fmt.Sprintf(\"Deleting tablet %v\", alias))\n\t\t\tif err := ts.DeleteTablet(ctx, tablet.Alias); err != nil && !topo.IsErrType(err, topo.NoNode) {\n\t\t\t\t// We don't want to continue if a DeleteTablet fails for any\n\t\t\t\t// reason other than a missing tablet (in which case it's just\n\t\t\t\t// topo server inconsistency, which we can ignore). If we were\n\t\t\t\t// to continue and delete the replication graph, the tablet\n\t\t\t\t// record would become orphaned, since we'd no longer know that\n\t\t\t\t// it belongs to this shard.\n\t\t\t\t//\n\t\t\t\t// If the problem is temporary, or resolved externally,\n\t\t\t\t// re-running DeleteShard will skip over tablets that were\n\t\t\t\t// already deleted.\n\t\t\t\treturn fmt.Errorf(\"cannot delete tablet %v: %w\", alias, err)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc deleteTablet(ctx context.Context, ts *topo.Server, alias *topodatapb.TabletAlias, allowPrimary bool) (err error) {\n\tspan, ctx := trace.NewSpan(ctx, \"VtctldServer.deleteTablet\")\n\tdefer span.Finish()\n\n\tspan.Annotate(\"tablet_alias\", topoproto.TabletAliasString(alias))\n\tspan.Annotate(\"allow_primary\", allowPrimary)\n\n\ttablet, err := ts.GetTablet(ctx, alias)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/topo.go#L182-L218","documentation":"deleteShardCell wraps a per-tablet DeleteTablet failure. If a tablet cannot be deleted (other than a transient-case handled internally), shard deletion aborts for that cell so tablet records are never orphaned from the shard.","triggerScenarios":"During DeleteShard, ts.DeleteTablet(ctx, alias) fails for a tablet still referenced by the shard/replication graph, or a topo error occurs while deleting the tablet record.","commonSituations":"Tablet still running and holding topo locks; replication graph references the tablet; stale tablet record whose underlying vttablet process still exists; topo write error mid-deletion.","solutions":["Stop/scrap the vttablet process(es) for the named alias, then re-run DeleteShard (it skips already-deleted tablets)","Use vtctldclient DeleteTablet --allow_primary/--recursive on the offending tablet first","Check replication graph references: vtctldclient GetShardReplication <cell> <keyspace/shard> and repair","Retry once the temporary topo error resolves"],"exampleFix":"// before\nvtctldclient DeleteShard --recursive ks/shard  # cannot delete tablet cell-0000010100\n// after\nvtctldclient DeleteTablet --allow_primary cell-0000010100\nvtctldclient DeleteShard --recursive ks/shard","handlingStrategy":"validation","validationCode":"// Ensure tablets are scrap-able before shard deletion\nfor _, t := range tablets {\n\tif t.Type == topodatapb.TabletType_PRIMARY {\n\t\treturn fmt.Errorf(\"tablet %s still primary; demote/delete first\", topoproto.TabletAliasString(t.Alias))\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := vtctldClient.DeleteShard(ctx, ks, shard); err != nil {\n\tvar alias string\n\tif n, _ := fmt.Sscanf(err.Error(), \"cannot delete tablet %s\", &alias); n == 1 {\n\t\t_ = vtctldClient.DeleteTablet(ctx, alias) // clean the blocker, retry\n\t}\n}","preventionTips":["Scrap/stop vttablets before deleting their shard","Delete primaries explicitly with --allow_primary first","Keep replication graph consistent (repair tools)"],"tags":["topo","vtctld","tablet-lifecycle"],"backgroundTag":"tablet-delete-blocked","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}