databendlabs/databend · error

Failed to register ZipfGenerator

Error message

Failed to register ZipfGenerator: {}

What it means

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.

Solutions

  1. Check the inner mlua error; recreate the Lua state for memory/stack failures.
  2. Ensure `zipf_generator` and `metactl_table` were produced by the same `Lua` instance.
  3. Raise or remove custom MemoryLimits on the Lua runtime if memory errors appear.
  4. If reproducible on a clean state, capture the inner error and report/upgrade mlua.
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = setup_lua_environment(&lua) {
    if e.to_string().contains("Failed to register ZipfGenerator") {
        // rebuild Lua state; inspect inner mlua error
    }
}

Prevention

When it happens

Trigger: `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).

Common situations: Lua stack or memory exhaustion in the shared runtime, or value/table belonging to a different Lua instance than the target table.

Related errors


AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11). Data as JSON: /api/errors/a39db0294eedab7c. Report an issue: GitHub.

Appendix: source

Thrown at src/meta/control/src/lua_support.rs:486

    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(())
}

pub fn new_grpc_client(
    addresses: Vec<String>,
) -> Result<Arc<ClientHandle<DatabendRuntime>>, CreationError> {
    eprintln!(

View on GitHub (pinned to 288d84d76e)