databendlabs/databend · error

Failed to convert RaftStoreEntry to SMEntry

Error message

Failed to convert RaftStoreEntry to SMEntry: {}

What it means

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.

Solutions

  1. Regenerate the dump from a compatible source version and re-run the import
  2. Inspect the offending JSON line (the line number appears in context) for corruption or manual edits
  3. Verify the source export was produced by `metactl --export` with matching tree naming ('state_machine/')
  4. If a specific entry type is not supported, upgrade metactl to a version whose converter handles it
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check each dump line parses as the expected shape
for line in dump.lines() {
    if line.starts_with("\"state_machine/") {
        serde_json::from_str::<serde_json::Value>(line)
            .expect("dump line is not valid JSON");
    }
}

Try / catch

match import_v004(path) {
    Err(e) if e.to_string().contains("Failed to convert RaftStoreEntry to SMEntry") => {
        eprintln!("dump incompatible/corrupted at a state_machine entry: {e}; re-export from source");
    }
    Err(e) => return Err(e),
    Ok(()) => {}
}

Prevention

When it happens

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

Common situations: 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.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at src/meta/control/src/import_v004.rs:76

    let snapshot_store: SnapshotStore<SP> = SnapshotStore::new(raft_config.clone());
    let writer = snapshot_store.new_writer()?;
    let (tx, join_handle) = writer.spawn_writer_thread("import_v004");

    let sys_data_holder = Arc::new(Mutex::new(SysData::default()));

    let mut converter = SMEntryV002ToV004 {
        sys_data: sys_data_holder.clone(),
    };

    for line in lines {
        let l = line?;
        let (tree_name, kv_entry): (String, RaftStoreEntry) = serde_json::from_str(&l)?;

        if tree_name.starts_with("state_machine/") {
            // Write to snapshot
            let sm_entry: SMEntry = kv_entry.try_into().map_err(|err_str| {
                anyhow::anyhow!("Failed to convert RaftStoreEntry to SMEntry: {}", err_str)
            })?;

            let kv = converter.sm_entry_to_rotbl_kv(sm_entry)?;
            if let Some(kv) = kv {
                tx.send(WriteEntry::Data(kv)).await?;
            }
        } else {
            let kv_entry = kv_entry.upgrade();
            if let RaftStoreEntry::DataHeader { .. } = kv_entry {
                // Data header is not stored in V004 RaftLog
                continue;
            }
            raft_log_importer.import_raft_store_entry(kv_entry)?;
        }

        n += 1;
    }

View on GitHub (pinned to 288d84d76e)