databendlabs/databend · error

marked key is not a GenericKV state entry at line

Error message

marked key is not a GenericKV state entry at line {}: {}

What it means

Raised by `dependency_keys` when a marked key IS present in `key_to_state` but the state line it points to is not a `StateKind::GenericKV` variant. The dependency extraction logic only knows how to parse GenericKV entries, so any other state kind at that position is rejected with the line number and display key in the message. This guards against extracting dependency data from an unexpected state entry shape.

Solutions

  1. Check the state line at the reported line number to see which `StateKind` it actually holds.
  2. Verify the mark-queue producer only enqueues keys that correspond to GenericKV entries.
  3. If the tool must support additional state kinds, extend `dependency_keys` to handle them instead of bailing.
  4. Re-generate or re-parse the snapshot with a matching tool/meta version to rule out format drift.
Defensive patterns

Strategy: type-guard

Validate before calling

// Rust: check the state kind before extracting dependencies
fn is_generic_kv(line: &StateLine) -> bool {
    matches!(line.kind, StateKind::GenericKV { .. })
}

Type guard

fn as_generic_kv(line: &StateLine) -> Option<&KvValue> {
    match &line.kind {
        StateKind::GenericKV { value, .. } => Some(value),
        _ => None,
    }
}

Try / catch

match tool.drain_mark_queue() {
    Ok(deps) => deps,
    Err(e) if e.to_string().contains("is not a GenericKV state entry") => {
        eprintln!("unexpected state kind for a marked key: {e}");
        return Err(e.into());
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: `drain_mark_queue` marks a key whose indexed state line holds a non-GenericKV `StateKind` (e.g. another state entry type), then `dependency_keys` attempts to destructure `GenericKV { value, .. }` and bails.

Common situations: Meta snapshots where a key that is normally a GenericKV row appears as a different state kind after a meta-service version upgrade or format change; bugs where the mark queue enqueues keys belonging to non-KV state entries.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/meta/process/src/filter_tenant.rs:604

        let Some(indices) = self.expires_by_key.get(key).cloned() else {
            return Ok(());
        };

        let reason = reason.into();
        for index in indices {
            self.mark_line_by_index(index, decision, reason.clone())?;
        }

        Ok(())
    }

    fn dependency_keys(&self, key: &str) -> anyhow::Result<Vec<DependencyKey>> {
        let Some(index) = self.key_to_state.get(key).copied() else {
            anyhow::bail!("marked key is missing from state index: {key}");
        };

        let StateKind::GenericKV { value, .. } = &self.state_lines[index].kind else {
            anyhow::bail!(
                "marked key is not a GenericKV state entry at line {}: {}",
                self.state_lines[index].line_no,
                self.state_lines[index].display_key()
            );
        };
        let data = &value.data;

        let mut out = DependencyKeySet::default();
        let segments = split_key(key);

        match segments.as_slice() {
            ["__fd_database", _tenant, _db_name] => {
                let db_id = decode_json_u64(key, data)?;
                self.add_database_id_keys(db_id, &mut out);
            }
            ["__fd_db_id_list", _tenant, _db_name] => {
                let ids = decode_as::<DbIdList>(key, data)?;
                for db_id in ids.id_list {

View on GitHub (pinned to 288d84d76e)