Skip to content

About the execution order of compact and create_snapshot #28

Description

@yufan022

Hi @PsiACE , thanks for your contribution.

i'm reading the code of this repository, and i have a question about here:

riteraft/src/raft_node.rs

Lines 479 to 488 in 56d53b4

if let Ok(cs) = self.apply_conf_change(&change) {
let last_applied = self.raft.raft_log.applied;
let snapshot = self.store.snapshot().await?;
{
let store = self.mut_store();
store.set_conf_state(&cs)?;
store.compact(last_applied)?;
store.create_snapshot(snapshot)?;
}
}

In my understanding, it should be ensured that the snapshot is successfully created before executing compact to clean up older raft-logs to ensure safety.

However, I see that the code executes the compact before executing the create_snapshot. Would this cause some issues if compact is executed first but the snapshot creation fails? Is my concern reasonable?

store.compact(last_applied)?; // already clean the older logs
store.create_snapshot(snapshot)?; // but create_snapshot failed

Is it a better choice to create_snapshot before executing compact?

store.create_snapshot(snapshot)?;
store.compact(last_applied)?; // only create_snapshot success, then clean the older logs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions