{"record":{"id":"a39db0294eedab7c","repo":"databendlabs/databend","slug":"failed-to-register-zipfgenerator","errorCode":null,"errorMessage":"Failed to register ZipfGenerator: {}","messagePattern":"Failed to register ZipfGenerator: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/meta/control/src/lua_support.rs","lineNumber":486,"sourceCode":"    let now_ms_fn = lua\n        .create_function(move |_lua, ()| Ok(start.elapsed().as_secs_f64() * 1000.0))\n        .map_err(|e| anyhow::anyhow!(\"Failed to create now_ms function: {}\", e))?;\n\n    metactl_table\n        .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!(","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/meta/control/src/lua_support.rs#L468-L504","documentation":"Once evaluated, the ZipfGenerator table is stored into `metactl` via `Table::set`. If mlua cannot push or store that table value, the error is wrapped as `Failed to register ZipfGenerator` and Lua environment setup fails.","triggerScenarios":"`metactl_table.set(\"ZipfGenerator\", zipf_generator)` returning an mlua error during `setup_lua_environment` (any `run_lua_script`/`run_lua_script_with_result` call or its tests).","commonSituations":"Lua stack or memory exhaustion in the shared runtime, or value/table belonging to a different Lua instance than the target table.","solutions":["Check the inner mlua error; recreate the Lua state for memory/stack failures.","Ensure `zipf_generator` and `metactl_table` were produced by the same `Lua` instance.","Raise or remove custom MemoryLimits on the Lua runtime if memory errors appear.","If reproducible on a clean state, capture the inner error and report/upgrade mlua."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = setup_lua_environment(&lua) {\n    if e.to_string().contains(\"Failed to register ZipfGenerator\") {\n        // rebuild Lua state; inspect inner mlua error\n    }\n}","preventionTips":["Use one Lua instance for chunk evaluation and table registration.","Avoid tight MemoryLimits on the runtime.","Rebuild the Lua state after any fatal script error.","Keep the full mlua error chain in logs."],"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"}