{"record":{"id":"d9f4d860d43abeb1","repo":"databendlabs/databend","slug":"marked-key-is-not-a-generickv-state-entry-at-line","errorCode":null,"errorMessage":"marked key is not a GenericKV state entry at line {}: {}","messagePattern":"marked key is not a GenericKV state entry at line (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/meta/process/src/filter_tenant.rs","lineNumber":604,"sourceCode":"        let Some(indices) = self.expires_by_key.get(key).cloned() else {\n            return Ok(());\n        };\n\n        let reason = reason.into();\n        for index in indices {\n            self.mark_line_by_index(index, decision, reason.clone())?;\n        }\n\n        Ok(())\n    }\n\n    fn dependency_keys(&self, key: &str) -> anyhow::Result<Vec<DependencyKey>> {\n        let Some(index) = self.key_to_state.get(key).copied() else {\n            anyhow::bail!(\"marked key is missing from state index: {key}\");\n        };\n\n        let StateKind::GenericKV { value, .. } = &self.state_lines[index].kind else {\n            anyhow::bail!(\n                \"marked key is not a GenericKV state entry at line {}: {}\",\n                self.state_lines[index].line_no,\n                self.state_lines[index].display_key()\n            );\n        };\n        let data = &value.data;\n\n        let mut out = DependencyKeySet::default();\n        let segments = split_key(key);\n\n        match segments.as_slice() {\n            [\"__fd_database\", _tenant, _db_name] => {\n                let db_id = decode_json_u64(key, data)?;\n                self.add_database_id_keys(db_id, &mut out);\n            }\n            [\"__fd_db_id_list\", _tenant, _db_name] => {\n                let ids = decode_as::<DbIdList>(key, data)?;\n                for db_id in ids.id_list {","sourceCodeStart":586,"sourceCodeEnd":622,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/meta/process/src/filter_tenant.rs#L586-L622","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Check the state line at the reported line number to see which `StateKind` it actually holds.","Verify the mark-queue producer only enqueues keys that correspond to GenericKV entries.","If the tool must support additional state kinds, extend `dependency_keys` to handle them instead of bailing.","Re-generate or re-parse the snapshot with a matching tool/meta version to rule out format drift."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Rust: check the state kind before extracting dependencies\nfn is_generic_kv(line: &StateLine) -> bool {\n    matches!(line.kind, StateKind::GenericKV { .. })\n}","typeGuard":"fn as_generic_kv(line: &StateLine) -> Option<&KvValue> {\n    match &line.kind {\n        StateKind::GenericKV { value, .. } => Some(value),\n        _ => None,\n    }\n}","tryCatchPattern":"match tool.drain_mark_queue() {\n    Ok(deps) => deps,\n    Err(e) if e.to_string().contains(\"is not a GenericKV state entry\") => {\n        eprintln!(\"unexpected state kind for a marked key: {e}\");\n        return Err(e.into());\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Only enqueue keys known to map to GenericKV rows","Handle meta format upgrades by re-parsing with a matching tool version","Inspect snapshot state kinds when migrating between meta versions"],"tags":["internal-invariant","meta","state-kind","generic-kv"],"backgroundTag":"internal-invariant-violation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}