Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What operations can run at the same time ? #1130

Closed
1 of 6 tasks
Gab-Menezes opened this issue Jun 11, 2024 · 3 comments
Closed
1 of 6 tasks

What operations can run at the same time ? #1130

Gab-Menezes opened this issue Jun 11, 2024 · 3 comments

Comments

@Gab-Menezes
Copy link

Gab-Menezes commented Jun 11, 2024

What kind of doc do you ask for?

  • Code comments.
  • Architecture design.
  • Algorithm explanation.
  • Guide.
  • Examples.

Describe the information you want
What operations can run simultanously ? I would specially like to know if RaftStateMachine::apply run at the same time as RaftStateMachine::install_snapshot or RaftSnapshotBuilder::build_snapshot.

Looking at the issues I found this one, #1121, so it seems that RaftStateMachine::install_snapshot and RaftSnapshotBuilder::build_snapshot can run at the same time.

If they can run at the same time, there is any rule to which should be prioritized ? I would imagine RaftStateMachine::install_snapshot, since it usually means that the Learner/Follower is lagging behind, but it's just a guess.

Also almost 2 years ago I oppened this issue, #507 (comment) and @drmingdrmer said:

* Currently installing a snapshot blocks the main task RaftCore, which means when installing a snapshot, nothing else can be done on a follower.

Is this still true ?

Describe the status of the current doc

  • Is there any doc yet?

    • Could not find
  • What other information should be added?

    • N/A
  • I'll open a pull request for it:)

Copy link

👋 Thanks for opening this issue!

Get help or engage by:

  • /help : to print help messages.
  • /assignme : to assign this issue to you.

@drmingdrmer
Copy link
Member

The operations involving writing, such as installing the state machine and applying a log, necessitate an exclusive reference to the state machine. This requirement is evident in the method signatures that use &mut self, indicating that these operations must be serialized. This serialization ensures that no other operations interfere or modify the state machine concurrently, maintaining the integrity and consistency of the state. The relevant sections in the source code can be explored further through these links:

https://github.com/datafuselabs/openraft/blob/5851fd69b4b06e9b14378b02cba59ed83c7a573c/openraft/src/storage/v2.rs#L237-L238
https://github.com/datafuselabs/openraft/blob/5851fd69b4b06e9b14378b02cba59ed83c7a573c/openraft/src/storage/v2.rs#L201

However, read operations like building a snapshot only require a snapshot view of the state machine. This snapshot view effectively creates a consistent point-in-time representation of the state machine, allowing it to be accessed concurrently with write operations. This concurrent accessibility is crucial for efficiency, especially in high-throughput environments.

Previously, in issue #1121, the snapshot building operation incorrectly used a mutex to block other write operations. The main issue was that the mutex wasn't held long enough, leading to potential race conditions.

All state-machine-related operations have moved to a separate task(in 0.9* and main), ensuring that such operations do not block the main task, RaftCore.

However, as of the latest published version (0.9*) and the main branch, operations related to the raft log are still executed within the RaftCore task. The major refactoring work to handle these operations asynchronously in separate tasks is an upcoming enhancement.

@Gab-Menezes
Copy link
Author

Ty for the explation, I will be closing the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants