{"record":{"id":"78d772351eecc8d0","repo":"vitessio/vitess","slug":"createkeyspace-v-failed-v","errorCode":null,"errorMessage":"CreateKeyspace(%v) failed: %v","messagePattern":"CreateKeyspace\\((.+?)\\) failed: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtcombo/tablet_map.go","lineNumber":327,"sourceCode":"func CreateKs(\n\tctx context.Context,\n\tenv *vtenv.Environment,\n\tts *topo.Server,\n\ttpb *vttestpb.VTTestTopology,\n\tmysqld mysqlctl.MysqlDaemon,\n\tdbcfgs *dbconfigs.DBConfigs,\n\tschemaDir string,\n\tkpb *vttestpb.Keyspace,\n\tensureDatabase bool,\n\tuid uint32,\n\twr *wrangler.Wrangler,\n\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)","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtcombo/tablet_map.go#L309-L345","documentation":"vtcombo's CreateKs creates a keyspace in the topo via ts.CreateKeyspace; any topo error is wrapped as 'CreateKeyspace(<name>) failed'. This is the vtctld CreateKeyspace path inside the combo process, so failures reflect topo-level keyspacespace problems.","triggerScenarios":"Calling CreateKs (from InitTabletMap or vtctld gRPC handler) when ts.CreateKeyspace errors: keyspace already exists (duplicate create), topo unavailable, or write permission/serialization error.","commonSituations":"Re-running an init script that creates an existing keyspace; etcd/zk timeouts; race between two components creating the same keyspace concurrently.","solutions":["Check whether the keyspace already exists (vtctldclient GetKeyspace) and skip creation or use a different name.","Verify topo server health and credentials; retry on transient topo errors.","If retrying creation, ensure prior partial state is cleaned up (DeleteKeyspace) before re-running CreateKs."],"exampleFix":"// before\nCreateKs(ctx, ts, ..., &keyspacepb.Keyspace{Name: \"commerce\"}) // second call\n// after\nif _, err := ts.GetKeyspace(ctx, \"commerce\"); err != nil {\n    CreateKs(ctx, ts, ..., &keyspacepb.Keyspace{Name: \"commerce\"})\n}","handlingStrategy":"try-catch","validationCode":"// Go: check existence before creating\nif _, err := ts.GetKeyspace(ctx, keyspace); err == nil {\n    return 0, nil // already exists; skip creation\n}","typeGuard":null,"tryCatchPattern":"if _, err := CreateKs(...); err != nil {\n    if strings.Contains(err.Error(), \"CreateKeyspace\") && topo.IsTopoException(err) /* e.g. node exists */ {\n        // keyspace already exists; treat as success or clean up first\n    }\n}","preventionTips":["Make keyspace creation idempotent: check-then-create or tolerate already-exists errors.","Serialize keyspace creation across processes to avoid races.","Verify topo health before batch keyspace setup scripts."],"tags":["vtcombo","keyspace","topology"],"backgroundTag":"keyspace-creation-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}