{"record":{"id":"1dae09324d6117ac","repo":"vitessio/vitess","slug":"database-not-found","errorCode":null,"errorMessage":"database not found","messagePattern":"database not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtcombo/tablet_map.go","lineNumber":279,"sourceCode":"\t\t\t}\n\t\t\terr = ts.DeleteTablet(ctx, tablet.alias)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\n\tvar ks *vttestpb.Keyspace\n\tindex := 0\n\tfor _, keyspace := range tpb.Keyspaces {\n\t\tif keyspace.Name == ksName {\n\t\t\tks = keyspace\n\t\t\tbreak\n\t\t}\n\t\tindex++\n\t}\n\tif ks == nil {\n\t\treturn errors.New(\"database not found\")\n\t}\n\n\tconn, err := mysqld.GetDbaConnection(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer conn.Close()\n\tfor _, shard := range ks.Shards {\n\t\tq := fmt.Sprintf(\"DROP DATABASE IF EXISTS `vt_%s_%s`\", ksName, shard.GetName())\n\t\tif _, err = conn.ExecuteFetch(q, 1, false); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif err := ts.DeleteShard(ctx, ksName, shard.GetName()); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tif err = ts.DeleteKeyspace(ctx, ksName); err != nil {","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtcombo/tablet_map.go#L261-L297","documentation":"vtcombo's DeleteKs returns \"database not found\" when the requested keyspace is not present in vtcombo's in-memory tablet/keyspace map after scanning for a match. vtcombo (used in local test clusters like vitessloader) holds a limited set of keyspaces, so deleting an unknown one yields this plain error. It is a lookup failure before any MySQL work is done.","triggerScenarios":"Calling DeleteKs with a keyspace name that was never created in the vtcombo process; deleting a keyspace twice; a race where another actor already removed the keyspace from the map.","commonSituations":"Test teardown scripts deleting keyspaces that failed to be created; typos in keyspace names in local dev setups; concurrent test cleanup.","solutions":["Verify the keyspace exists (list keyspaces) before calling DeleteKs","Fix the keyspace name in the caller","Treat the error as idempotent cleanup success if double-delete is expected"],"exampleFix":"// before\nerr := tm.DeleteKs(ctx, \"commerce\", false)\n// after\nif _, err := ts.GetServingNamespaces(ctx); err == nil { /* optionally check ks exists */ }\nif ksExists(topo, \"commerce\") { err = tm.DeleteKs(ctx, \"commerce\", false) }","handlingStrategy":"validation","validationCode":"exists, err := ksExistsInVtcombo(topo, \"commerce\")\nif err != nil { return err }\nif !exists { /* skip DeleteKs or fail fast */ }","typeGuard":"func isDatabaseNotFound(err error) bool { return err != nil && err.Error() == \"database not found\" }","tryCatchPattern":"err := tm.DeleteKs(ctx, ks, false)\nif err != nil && strings.Contains(err.Error(), \"database not found\") {\n    // treat as already-deleted (idempotent cleanup)\n    return nil\n}","preventionTips":["List keyspaces before deleting in cleanup scripts","Guard against double deletes","Verify keyspace names against created fixtures"],"tags":["vtcombo","keyspace","local-cluster"],"backgroundTag":"keyspace-not-found","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}