{"record":{"id":"017bede0689b74d8","repo":"databendlabs/databend","slug":"failed-to-load-zipf-load-generator","errorCode":null,"errorMessage":"Failed to load zipf_load_generator: {}","messagePattern":"Failed to load zipf_load_generator: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/meta/control/src/lua_support.rs","lineNumber":482,"sourceCode":"    // Register a monotonic millisecond clock for timing and benchmarks. The\n    // epoch is this environment's setup time; only differences between calls are\n    // meaningful. `Instant` guarantees the value never goes backwards.\n    let start = std::time::Instant::now();\n    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","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/meta/control/src/lua_support.rs#L464-L500","documentation":"`setup_lua_environment` evaluates the embedded `ZIPF_LOAD_GENERATOR` Lua source with `lua.load(...).eval::<Table>()` to expose `metactl.ZipfGenerator`. This error wraps any failure to compile or evaluate that Lua chunk, or to convert its result into a `Table` (e.g. the chunk returned a non-table value).","triggerScenarios":"Evaluating the built-in ZIPF_LOAD_GENERATOR source fails during `setup_lua_environment` — a Lua syntax error in the embedded constant, a runtime error while the chunk executes, or the chunk evaluating to something that is not a table.","commonSituations":"An edited/truncated ZIPF_LOAD_GENERATOR constant after a code change, an mlua Lua-version incompatibility with Lua syntax used in the constant (e.g. Lua 5.1 vs 5.4 features), or the chunk's `return` statement being altered so it no longer yields a table.","solutions":["Read the inner error: if it is a syntax error, check recent changes to the ZIPF_LOAD_GENERATOR constant in this crate.","Confirm the chunk ends with `return` of the ZipfGenerator table so `.eval::<Table>()` succeeds.","Verify the mlua Lua version feature (lua54/lua51/vendored) supports the syntax used in the constant.","Reproduce by evaluating the constant standalone with the same Lua version to isolate the failing line."],"exampleFix":"// before (chunk no longer returns a table)\nlocal ZipfGenerator = {}\nfunction ZipfGenerator:new(n, a) ... end\n// after\nlocal ZipfGenerator = {}\nfunction ZipfGenerator:new(n, a) ... end\nreturn ZipfGenerator","handlingStrategy":"validation","validationCode":"// sanity-check the embedded chunk in CI (Rust test)\nlet t: mlua::Table = lua.load(ZIPF_LOAD_GENERATOR).eval()?;\nassert!(t.get::<_, mlua::Function>(\"new\").is_ok());","typeGuard":null,"tryCatchPattern":"match setup_lua_environment(&lua) {\n    Err(e) if e.to_string().contains(\"Failed to load zipf_load_generator\") => {\n        // embedded Lua source broken: fail fast, surface inner syntax/runtime error\n    }\n    other => other?,\n}","preventionTips":["Add a unit test that evals ZIPF_LOAD_GENERATOR and asserts it returns a table with `new`.","Keep the chunk ending in `return <table>` so eval::<Table>() always succeeds.","Run the chunk under the exact Lua version feature (e.g. lua54) used by mlua in CI.","Review any edit to the constant as you would regular code."],"tags":["lua","mlua","embedded-script","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"}