{"record":{"id":"4ead7b17d24a7b05","repo":"databendlabs/databend","slug":"failed-to-convert-raftstoreentry-to-smentry","errorCode":null,"errorMessage":"Failed to convert RaftStoreEntry to SMEntry: {}","messagePattern":"Failed to convert RaftStoreEntry to SMEntry: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/meta/control/src/import_v004.rs","lineNumber":76,"sourceCode":"\n    let snapshot_store: SnapshotStore<SP> = SnapshotStore::new(raft_config.clone());\n    let writer = snapshot_store.new_writer()?;\n    let (tx, join_handle) = writer.spawn_writer_thread(\"import_v004\");\n\n    let sys_data_holder = Arc::new(Mutex::new(SysData::default()));\n\n    let mut converter = SMEntryV002ToV004 {\n        sys_data: sys_data_holder.clone(),\n    };\n\n    for line in lines {\n        let l = line?;\n        let (tree_name, kv_entry): (String, RaftStoreEntry) = serde_json::from_str(&l)?;\n\n        if tree_name.starts_with(\"state_machine/\") {\n            // Write to snapshot\n            let sm_entry: SMEntry = kv_entry.try_into().map_err(|err_str| {\n                anyhow::anyhow!(\"Failed to convert RaftStoreEntry to SMEntry: {}\", err_str)\n            })?;\n\n            let kv = converter.sm_entry_to_rotbl_kv(sm_entry)?;\n            if let Some(kv) = kv {\n                tx.send(WriteEntry::Data(kv)).await?;\n            }\n        } else {\n            let kv_entry = kv_entry.upgrade();\n            if let RaftStoreEntry::DataHeader { .. } = kv_entry {\n                // Data header is not stored in V004 RaftLog\n                continue;\n            }\n            raft_log_importer.import_raft_store_entry(kv_entry)?;\n        }\n\n        n += 1;\n    }\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/meta/control/src/import_v004.rs#L58-L94","documentation":"During v0.0.4 meta data import, each JSON line containing a state_machine/ tree entry is deserialized as a RaftStoreEntry and then converted into an SMEntry (snapshot write). If the TryFrom conversion fails (the raft log entry cannot be interpreted as a state-machine entry), the error string is wrapped and the import aborts.","triggerScenarios":"Importing a meta dump/export file where a line prefixed with tree name 'state_machine/' contains a RaftStoreEntry that fails conversion — e.g. corrupted or unexpected entry payload, or an export produced by a mismatched old version.","commonSituations":"Migrating very old databend-meta snapshot dumps (v0.0.4-era) forward; hand-edited or truncated dump files; version-skew between the exporting and importing metasrv versions.","solutions":["Regenerate the dump from a compatible source version and re-run the import","Inspect the offending JSON line (the line number appears in context) for corruption or manual edits","Verify the source export was produced by `metactl --export` with matching tree naming ('state_machine/')","If a specific entry type is not supported, upgrade metactl to a version whose converter handles it"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check each dump line parses as the expected shape\nfor line in dump.lines() {\n    if line.starts_with(\"\\\"state_machine/\") {\n        serde_json::from_str::<serde_json::Value>(line)\n            .expect(\"dump line is not valid JSON\");\n    }\n}","typeGuard":null,"tryCatchPattern":"match import_v004(path) {\n    Err(e) if e.to_string().contains(\"Failed to convert RaftStoreEntry to SMEntry\") => {\n        eprintln!(\"dump incompatible/corrupted at a state_machine entry: {e}; re-export from source\");\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}","preventionTips":["Never hand-edit exported dumps","Export and import with matching metactl versions","Keep dump files checksummed to detect truncation/corruption","Test the import on a scratch cluster before production migration"],"tags":["serialization","migration","metactl"],"backgroundTag":"incompatible-source-type","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"}