{"record":{"id":"cc06e12058504a6c","repo":"vitessio/vitess","slug":"createshard-v-v-failed-v","errorCode":null,"errorMessage":"CreateShard(%v:%v) failed: %v","messagePattern":"CreateShard\\((.+?):(.+?)\\) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtcombo/tablet_map.go","lineNumber":339,"sourceCode":"\tsrvTopoCounts *stats.CountersWithSingleLabel,\n) (uint32, error) {\n\tkeyspace := kpb.Name\n\n\t// create a regular keyspace\n\tif err := ts.CreateKeyspace(ctx, keyspace, &topodatapb.Keyspace{}); err != nil {\n\t\treturn 0, fmt.Errorf(\"CreateKeyspace(%v) failed: %v\", keyspace, err)\n\t}\n\n\t// make sure a valid vschema has been loaded\n\tif err := ts.EnsureVSchema(ctx, keyspace); err != nil {\n\t\treturn 0, fmt.Errorf(\"EnsureVSchema(%v) failed: %v\", keyspace, err)\n\t}\n\n\t// iterate through the shards\n\tfor _, spb := range kpb.Shards {\n\t\tshard := spb.Name\n\t\tif err := ts.CreateShard(ctx, keyspace, shard); err != nil {\n\t\t\treturn 0, fmt.Errorf(\"CreateShard(%v:%v) failed: %v\", keyspace, shard, err)\n\t\t}\n\n\t\tfor _, cell := range tpb.Cells {\n\t\t\tdbname := spb.DbNameOverride\n\t\t\tif dbname == \"\" {\n\t\t\t\tdbname = fmt.Sprintf(\"vt_%v_%v\", keyspace, shard)\n\t\t\t}\n\n\t\t\treplicas := int(kpb.ReplicaCount)\n\t\t\tif replicas == 0 {\n\t\t\t\t// 2 replicas in order to ensure the primary cell has a primary and a replica\n\t\t\t\treplicas = 2\n\t\t\t}\n\t\t\trdonlys := int(kpb.RdonlyCount)\n\t\t\tif rdonlys == 0 {\n\t\t\t\trdonlys = 1\n\t\t\t}\n","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtcombo/tablet_map.go#L321-L357","documentation":"CreateKs creates each shard in the keyspace via ts.CreateShard; topo-level failures are wrapped as 'CreateShard(<keyspace>:<shard>) failed'. Like CreateKeyspace failure, it indicates the shard record could not be created in the topo server.","triggerScenarios":"CreateKs iterating kpb.Shards where ts.CreateShard(ctx, keyspace, shard) errors: shard already exists, topo server unreachable, or invalid shard name/keyrange.","commonSituations":"Re-running initialization against a topo that already has the shard; invalid shard names (e.g. bad hex keyrange like '-80' vs '80-'); concurrent creation of the same shard by another process; etcd/zk outage.","solutions":["Check if the shard already exists (vtctldclient GetShard <ks>/<shard>) and skip or clean up before re-running.","Validate shard names in the Keyspace proto are well-formed keyranges (e.g. '-', '-80', '80-', 'c0-') for sharded keyspaces.","Verify topo server health and permissions, then retry CreateKs after removing partial keyspace state."],"exampleFix":"// before (duplicate shard create)\nCreateShard(ctx, \"commerce\", \"0\") // already exists\n// after\nif _, err := ts.GetShard(ctx, \"commerce\", \"0\"); err != nil {\n    CreateShard(ctx, \"commerce\", \"0\")\n}","handlingStrategy":"try-catch","validationCode":"// Go: skip existing shards\nif _, err := ts.GetShard(ctx, keyspace, shard); err == nil {\n    continue // shard already exists\n}","typeGuard":null,"tryCatchPattern":"if _, err := CreateKs(...); err != nil {\n    if strings.Contains(err.Error(), \"CreateShard\") {\n        // check shard name validity and pre-existing shard; clean partial state before retry\n    }\n}","preventionTips":["Validate shard names/keyranges in the Keyspace proto before calling CreateKs.","Make shard creation idempotent by checking GetShard first.","Clean partial keyspace state (DeleteKeyspace) before re-running failed init scripts."],"tags":["vtcombo","shard","topology"],"backgroundTag":"shard-creation-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}