{"record":{"id":"b6b963dd10f174b6","repo":"vitessio/vitess","slug":"shard-v-v-is-still-serving-cannot-delete-it-us","errorCode":null,"errorMessage":"shard %v/%v is still serving, cannot delete it, use even_if_serving flag if needed","messagePattern":"shard (.+?)/(.+?) is still serving, cannot delete it, use even_if_serving flag if needed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/shard.go","lineNumber":75,"sourceCode":"\t// Read the Shard object. If it's not there, try to clean up\n\t// the topology anyway.\n\tshardInfo, err := wr.ts.GetShard(ctx, keyspace, shard)\n\tif err != nil {\n\t\tif topo.IsErrType(err, topo.NoNode) {\n\t\t\twr.Logger().Infof(\"Shard %v/%v doesn't seem to exist, cleaning up any potential leftover\", keyspace, shard)\n\t\t\treturn wr.ts.DeleteShard(ctx, keyspace, shard)\n\t\t}\n\t\treturn err\n\t}\n\n\tservingCells, err := wr.ts.GetShardServingCells(ctx, shardInfo)\n\tif err != nil {\n\t\treturn err\n\t}\n\t// Check the Serving map for the shard, we don't want to\n\t// remove a serving shard if not absolutely sure.\n\tif !evenIfServing && len(servingCells) > 0 {\n\t\treturn fmt.Errorf(\"shard %v/%v is still serving, cannot delete it, use even_if_serving flag if needed\", keyspace, shard)\n\t}\n\n\tcells, err := wr.ts.GetCellInfoNames(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Go through all the cells.\n\tfor _, cell := range cells {\n\t\tvar aliases []*topodatapb.TabletAlias\n\n\t\t// Get the ShardReplication object for that cell. Try\n\t\t// to find all tablets that may belong to our shard.\n\t\tsri, err := wr.ts.GetShardReplication(ctx, cell, keyspace, shard)\n\t\tswitch {\n\t\tcase topo.IsErrType(err, topo.NoNode):\n\t\t\t// No ShardReplication object. It means the\n\t\t\t// topo is inconsistent. Let's read all the","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/shard.go#L57-L93","documentation":"DeleteShard refuses to delete a shard whose Serving map still lists it in at least one cell, unless the caller passes evenIfServing. This is a safety guard: deleting a shard that vtgates are still routing traffic to would cause immediate query failures.","triggerScenarios":"vtctldclient DeleteShard is run on a shard still marked serving in one or more cells without the --even_if_serving flag.","commonSituations":"Cleaning up after a reshard where the new shards weren't fully switched over; accidentally targeting a still-live shard; stale serving entries after traffic moved but the topo wasn't refreshed.","solutions":["Confirm no vtgate traffic uses the shard, then rerun with the even_if_serving flag.","If traffic already moved, rebuild/refresh the serving graph so the shard is no longer marked serving.","Double-check keyspace/shard names - a typo may target a live shard."],"exampleFix":"// before\nvtctldclient DeleteShard customer/0\n// after (verified no traffic)\nvtctldclient DeleteShard --even_if_serving customer/0","handlingStrategy":"validation","validationCode":"shardInfo, err := ts.GetShard(ctx, keyspace, shard)\nif err == nil {\n    for cell, serving := range shardInfo.ServingCells() /* or check serving map */ {\n        if serving && !evenIfServing {\n            return fmt.Errorf(\"shard %s/%s still serving in %s\", keyspace, shard, cell)\n        }\n    }\n}","typeGuard":"func isServing(servingCells []string) bool { return len(servingCells) > 0 }","tryCatchPattern":"err := wr.DeleteShard(ctx, keyspace, shard, evenIfServing, recursive)\nif err != nil && strings.Contains(err.Error(), \"is still serving\") {\n    // confirm traffic moved, rerun with evenIfServing=true\n}","preventionTips":["Verify the vtgate serving graph shows the shard as non-serving before deletion.","Use even_if_serving only after explicit confirmation of no traffic.","Double-check keyspace/shard names before destructive ops."],"tags":["go","topology","shard","serving","safety-guard"],"backgroundTag":"shard-still-serving","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}