{"record":{"id":"114ba069e2c67477","repo":"vitessio/vitess","slug":"register-a-registered-key","errorCode":null,"errorMessage":"register a registered key: ","messagePattern":"register a registered key: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/schemamanager/schemamanager.go","lineNumber":141,"sourceCode":"\t\treturn execResult, err\n\t}\n\n\texecResult = executor.Execute(ctx, sqls)\n\n\tif err := controller.OnExecutorComplete(ctx, execResult); err != nil {\n\t\treturn execResult, err\n\t}\n\tif execResult.ExecutorErr != \"\" || len(execResult.FailedShards) > 0 {\n\t\tout, _ := json.MarshalIndent(execResult, \"\", \"  \")\n\t\treturn execResult, fmt.Errorf(\"schema change failed, ExecuteResult: %v\", string(out))\n\t}\n\treturn execResult, nil\n}\n\n// RegisterControllerFactory register a control factory.\nfunc RegisterControllerFactory(name string, factory ControllerFactory) {\n\tif _, ok := controllerFactories[name]; ok {\n\t\tpanic(\"register a registered key: \" + name)\n\t}\n\tcontrollerFactories[name] = factory\n}\n\n// GetControllerFactory gets a ControllerFactory.\nfunc GetControllerFactory(name string) (ControllerFactory, error) {\n\tfactory, ok := controllerFactories[name]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"there is no data sourcer factory with name: %s\", name)\n\t}\n\treturn factory, nil\n}\n","sourceCodeStart":123,"sourceCodeEnd":154,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/schemamanager/schemamanager.go#L123-L154","documentation":"RegisterControllerFactory registers a schema-manager controller factory under a name in a global map. Registering the same name twice would silently overwrite the existing factory, so it panics to surface the conflict.","triggerScenarios":"Calling schemamanager.RegisterControllerFactory twice with the same controller name — typically two init() functions in different packages both registering e.g. 'online' or a custom controller under an existing name.","commonSituations":"Importing two packages that each register a controller factory under the same name; a plugin/library registering a name that collides with vitess built-ins.","solutions":["Use a unique controller name for custom factories","Remove the duplicate registration or the redundant import causing the second init() to run","Register built-in names only once (they are already registered by the schemamanager package init)"],"exampleFix":"// before\nRegisterControllerFactory(\"online\", myFactory) // collides with built-in\n// after\nRegisterControllerFactory(\"mycompany-online\", myFactory)","handlingStrategy":"validation","validationCode":"var registered sync.Map\nfunc registerFactoryOnce(name string, f ControllerFactory) { registered.LoadOrStore(name, f) } // dedupe before RegisterControllerFactory","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Namespace custom controller names (company/feature prefix)","Avoid importing packages with colliding init() registrations","Register built-in names only via the schemamanager package"],"tags":["go","panic","schema-manager","duplicate-registration"],"backgroundTag":"duplicate-key-registration","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}