Skip to content

Is it possible to install a snapshot built by the client, outside of the state machine? #1333

Open
@maackle

Description

@maackle

First of all, thank you for the great work on openraft, it has been really wonderful to work with :)

I am trying something unusual. I'm trying to use openraft in a situation where the client knows how to create snapshots, but the raft state machine does not. In my use case, essentially, the state machine logic lives in the client (in a JS library), not in the Rust raft implementation.

Thus, I would like clients to be able to instruct the raft leader to purge logs, install a constructed snapshot and propagate that. The client would be responsible for ensuring that the snapshot represents the logs up to that point.

I have no problem getting the leader to install the snapshot and purge its logs, but I am not seeing it replicate the new snapshot to the members. This is what I'm asking about: how can I get the cluster to fully accept this external snapshot as the current state?

I have tried the following, but only the leader updates its state:

        raft.with_state_machine(
            move |s: &mut Arc<StateMachineStore<memstore::TypeConfig>>| {
                async move {
                    s.clone()
                        .install_snapshot(&meta.clone(), snapshot)
                        .await
                        .unwrap();
                    // s.build_snapshot().await.unwrap();
                }
                .boxed()
            },
        )
        .await
        .unwrap()
        .unwrap();

        let trigger = raft.trigger();
        trigger
            .purge_log(smd.last_applied.map(|l| l.index).unwrap_or_default())
            .await
            .unwrap();
        trigger.snapshot().await.unwrap();
        trigger.heartbeat().await.unwrap();

Is it possible?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions