databendlabs/databend · error
Failed to load zipf_load_generator
Error message
Failed to load zipf_load_generator: {} What it means
`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).
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.
Example fix
// before (chunk no longer returns a table)
local ZipfGenerator = {}
function ZipfGenerator:new(n, a) ... end
// after
local ZipfGenerator = {}
function ZipfGenerator:new(n, a) ... end
return ZipfGenerator Defensive patterns
Strategy: validation
Validate before calling
// sanity-check the embedded chunk in CI (Rust test)
let t: mlua::Table = lua.load(ZIPF_LOAD_GENERATOR).eval()?;
assert!(t.get::<_, mlua::Function>("new").is_ok()); Try / catch
match setup_lua_environment(&lua) {
Err(e) if e.to_string().contains("Failed to load zipf_load_generator") => {
// embedded Lua source broken: fail fast, surface inner syntax/runtime error
}
other => other?,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to load lua_util functions
- Failed to create now_ms function
- Failed to create sleep function
- Failed to create spawn function
- Failed to register metactl namespace
AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11).
Data as JSON: /api/errors/017bede0689b74d8.
Report an issue: GitHub.
Appendix: source
Thrown at src/meta/control/src/lua_support.rs:482
// Register a monotonic millisecond clock for timing and benchmarks. The
// epoch is this environment's setup time; only differences between calls are
// meaningful. `Instant` guarantees the value never goes backwards.
let start = std::time::Instant::now();
let now_ms_fn = lua
.create_function(move |_lua, ()| Ok(start.elapsed().as_secs_f64() * 1000.0))
.map_err(|e| anyhow::anyhow!("Failed to create now_ms function: {}", e))?;
metactl_table
.set("now_ms", now_ms_fn)
.map_err(|e| anyhow::anyhow!("Failed to register now_ms function: {}", e))?;
// Register the Zipf load generator. The module returns the `ZipfGenerator`
// table, exposed as `metactl.ZipfGenerator` so any script can call
// `metactl.ZipfGenerator:new(num_keys, alpha)` directly.
let zipf_generator = lua
.load(ZIPF_LOAD_GENERATOR)
.eval::<Table>()
.map_err(|e| anyhow::anyhow!("Failed to load zipf_load_generator: {}", e))?;
metactl_table
.set("ZipfGenerator", zipf_generator)
.map_err(|e| anyhow::anyhow!("Failed to register ZipfGenerator: {}", e))?;
// Set the metactl table as a global
lua.globals()
.set("metactl", metactl_table)
.map_err(|e| anyhow::anyhow!("Failed to register metactl namespace: {}", e))?;
// Load lua_util functions (which registers to_string in metactl namespace)
lua.load(LUA_UTIL)
.exec()
.map_err(|e| anyhow::anyhow!("Failed to load lua_util functions: {}", e))?;
Ok(())
}
View on GitHub (pinned to 288d84d76e)