{"record":{"id":"f02430f483d0fa86","repo":"databendlabs/databend","slug":"failed-to-register-metactl-namespace","errorCode":null,"errorMessage":"Failed to register metactl namespace: {}","messagePattern":"Failed to register metactl namespace: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/meta/control/src/lua_support.rs","lineNumber":491,"sourceCode":"        .set(\"now_ms\", now_ms_fn)\n        .map_err(|e| anyhow::anyhow!(\"Failed to register now_ms function: {}\", e))?;\n\n    // Register the Zipf load generator. The module returns the `ZipfGenerator`\n    // table, exposed as `metactl.ZipfGenerator` so any script can call\n    // `metactl.ZipfGenerator:new(num_keys, alpha)` directly.\n    let zipf_generator = lua\n        .load(ZIPF_LOAD_GENERATOR)\n        .eval::<Table>()\n        .map_err(|e| anyhow::anyhow!(\"Failed to load zipf_load_generator: {}\", e))?;\n\n    metactl_table\n        .set(\"ZipfGenerator\", zipf_generator)\n        .map_err(|e| anyhow::anyhow!(\"Failed to register ZipfGenerator: {}\", e))?;\n\n    // Set the metactl table as a global\n    lua.globals()\n        .set(\"metactl\", metactl_table)\n        .map_err(|e| anyhow::anyhow!(\"Failed to register metactl namespace: {}\", e))?;\n\n    // Load lua_util functions (which registers to_string in metactl namespace)\n    lua.load(LUA_UTIL)\n        .exec()\n        .map_err(|e| anyhow::anyhow!(\"Failed to load lua_util functions: {}\", e))?;\n\n    Ok(())\n}\n\npub fn new_grpc_client(\n    addresses: Vec<String>,\n) -> Result<Arc<ClientHandle<DatabendRuntime>>, CreationError> {\n    eprintln!(\n        \"Using gRPC API address: {}\",\n        serde_json::to_string(&addresses).unwrap()\n    );\n    MetaGrpcClient::try_create(\n        addresses,","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/meta/control/src/lua_support.rs#L473-L509","documentation":"After all members are registered, the `metactl` table itself is assigned as a global with `lua.globals().set(\"metactl\", metactl_table)`. If mlua fails to store the table into the globals table, the error is wrapped as `Failed to register metactl namespace` and setup aborts.","triggerScenarios":"`lua.globals().set(\"metactl\", metactl_table)` returning an mlua error during `setup_lua_environment`, before `LUA_UTIL` is loaded.","commonSituations":"Lua stack/memory exhaustion, a globals table that has been locked or replaced by sandboxing code, or values from a mismatched Lua instance.","solutions":["Inspect the inner mlua error; memory/stack errors mean the Lua instance should be recreated.","Check that no earlier script enabled a sandbox/readonly-globals mode that blocks `globals().set`.","Ensure `metactl_table` was created in the same Lua instance whose globals are being set.","Increase or drop custom MemoryLimits; if still failing, report the inner error against mlua."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match setup_lua_environment(&lua) {\n    Err(e) if e.to_string().contains(\"Failed to register metactl namespace\") => {\n        // sandbox/globals or state problem: rebuild environment\n    }\n    other => other?,\n}","preventionTips":["Do not enable global-locking/sandbox scripts before this registration runs.","Keep all registration on the same Lua instance.","Avoid restrictive MemoryLimits.","Preserve the inner mlua error for diagnosis."],"tags":["lua","mlua","runtime-setup","rust"],"backgroundTag":"module-init-failed","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}