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

Add an API that blocks until logs replay is done if save_committed() is implemented #1249

Closed
SteveLauC opened this issue Sep 20, 2024 · 5 comments

Comments

@SteveLauC
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

Hi, I would like to know is there any API that can be used to wait for a node to replay its logs upon restart. This is something a user can implement with committed_id (RaftState.committed) and applied_id (RaftStateMachine.applied), but maybe we can add it if it is a common request (Well, it does not seem to be as searching for "replay log" gives me nothing😁)

Describe the solution you'd like

We can:

  1. Get the committed log index
  2. Then wait for the applied log index to become greater than or equal to it

Describe alternatives you've considered

I have noticed the Raft::ensure_linearizable() method, which does something similar under the hood, but considering that it invokes Raft::get_read_log_id(), looks like it is only suitable for the leader node.

Additional context

No

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

Raft::new() will block until all committed log entries applied, if committed_log_id is saved:
https://github.com/datafuselabs/openraft/blob/5d75cf21f71b083b2b8acd8ffdd8993c1bfce36f/openraft/src/storage/helper.rs#L97

@schreter
Copy link
Collaborator

We did it by simply awaiting until the node becomes the leader in a separate task and then await until applied index reaches the committed index (via the watch on Raft state). Only then it's clear that the (leader's) log is replayed and we can serve further requests.

This is basically the same that @SteveLauC describes above. Is there something wrong with this approach?

Also, if the restarted node became a follower, then no one really cares how far the apply went, since it can't really serve requests anyway. And, if the leader dies and the follower becomes leader, again, the leader awaiting task on the former follower now leader will get notified and the process repeats on the follower. But, we don't need to wait until Raft::new() applies all the entries - we shouldn't wait there either, IMHO.

@drmingdrmer
Copy link
Member

  • Get the committed log index
  • Then wait for the applied log index to become greater than or equal to it

This approach aligns with my suggestion. Currently, only the caller of client_write() that proposes the log entry is notified of its completion. This notification occurs when client_write() returns, indicating the entry has been applied.

@SteveLauC
Copy link
Collaborator Author

Thanks for the replys, also thanks for the code link so that I can dig it further, close as the feature is not needed.

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

3 participants