{"record":{"id":"42c04941f02dc1f9","repo":"vitessio/vitess","slug":"cannot-delete-shard-v-v-w","errorCode":null,"errorMessage":"cannot delete shard %v/%v: %w","messagePattern":"cannot delete shard (.+?)/(.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/grpcvtctldserver/server.go","lineNumber":1188,"sourceCode":"\t\treturn nil, err\n\t}\n\n\tif len(shards) > 0 {\n\t\tif !req.Recursive {\n\t\t\terr = vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, \"keyspace %v still has %d shards; use Recursive=true or remove them manually\", req.Keyspace, len(shards))\n\t\t\treturn nil, err\n\t\t}\n\n\t\tlog.Info(fmt.Sprintf(\"Deleting all %d shards (and their tablets) in keyspace %v\", len(shards), req.Keyspace))\n\t\trecursive := true\n\t\tevenIfServing := true\n\t\tforce := req.Force\n\n\t\tfor _, shard := range shards {\n\t\t\tlog.Info(fmt.Sprintf(\"Recursively deleting shard %v/%v\", req.Keyspace, shard))\n\t\t\terr = deleteShard(ctx, s.ts, req.Keyspace, shard, recursive, evenIfServing, force)\n\t\t\tif err != nil {\n\t\t\t\terr = fmt.Errorf(\"cannot delete shard %v/%v: %w\", req.Keyspace, shard, err)\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\t}\n\n\tcells, err := s.ts.GetKnownCells(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tfor _, cell := range cells {\n\t\tif err := s.ts.DeleteKeyspaceReplication(ctx, cell, req.Keyspace); err != nil && !topo.IsErrType(err, topo.NoNode) {\n\t\t\tlog.Warn(fmt.Sprintf(\"Cannot delete KeyspaceReplication in cell %v for %v: %v\", cell, req.Keyspace, err))\n\t\t}\n\n\t\tif err := s.ts.DeleteSrvKeyspace(ctx, cell, req.Keyspace); err != nil && !topo.IsErrType(err, topo.NoNode) {\n\t\t\tlog.Warn(fmt.Sprintf(\"Cannot delete SrvKeyspace in cell %v for %v: %v\", cell, req.Keyspace, err))\n\t\t}","sourceCodeStart":1170,"sourceCodeEnd":1206,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/server.go#L1170-L1206","documentation":"DeleteKeyspace deletes each shard in the keyspace via deleteShard before removing the keyspace record itself. If any shard deletion fails, the operation aborts and the error is wrapped as 'cannot delete shard <keyspace>/<shard>: <cause>', leaving remaining shards and the keyspace untouched.","triggerScenarios":"Deleting a keyspace whose shards cannot be removed: shard still has tablets (non-recursive delete), shard is serving (evenIfServing false), or the topo shard delete call fails.","commonSituations":"Keyspace still hosts tablets because reparenting/decommission was incomplete; recursive flag omitted; leftover serving checks; topo connectivity failures mid-delete.","solutions":["Read the wrapped cause: if tablets remain, drain/remove tablets first or pass Recursive=true","Pass EvenIfServing=true only if you intend to delete a serving shard","Verify all tablets are removed (GetTablets filtered by keyspace) before retrying","After shards are cleaned, retry DeleteKeyspace"],"exampleFix":"// before\nclient.DeleteKeyspace(ctx, req)\n// after\nreq.Recursive = true\nclient.DeleteKeyspace(ctx, req)","handlingStrategy":"validation","validationCode":"tablets, err := client.GetTablets(ctx, keyspace)\nif len(tablets) > 0 {\n    return fmt.Errorf(\"keyspace still hosts %d tablets; drain first\", len(tablets))\n}","typeGuard":null,"tryCatchPattern":"_, err := client.DeleteKeyspace(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"cannot delete shard\") {\n    // read wrapped cause; remove tablets or pass Recursive=true\n}","preventionTips":["Drain and remove all tablets before deleting a keyspace","Set Recursive=true when you intend to delete non-empty shards","Only use EvenIfServing=true deliberately","Verify shard cleanup with GetShard after deletion"],"tags":["vitess","keyspace","shard","deletion"],"backgroundTag":"shard-delete-blocked","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}