-
Notifications
You must be signed in to change notification settings - Fork 159
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
Non-blocking RaftStateMachine::apply()
#1156
Comments
👋 Thanks for opening this issue! Get help or engage by:
|
I think that we actually don't need the callback. Rather, we should pass the receiver of the client reply to the caller of We have two issues to solve:
The first one can be solved by a watch-like channel where the newest log ID accepted by quorum is published, so the SM task can loop on it. The latter one is more problematic. Ideally, we'd have the However, the async fn sm_task() -> Result<(), ...> {
let mut current_log_id = ...;
loop {
let next_quorum_log_id = log_id.await;
let stream = (current_log_id..next_quorum_log_id).iter().as_stream()
.zip(log_reader.get_logs(current_log_id..next_quorum_log_id).await)
.zip(responder_channel.take(next_quorum_log_id - current_log_id).await);
sm.apply(stream).await?;
current_log_id = next_quorum_log_id;
}
} Where What do you think? |
Makes sense. The callback in my proposed snippet could include a struct Callback {
to_client: Option<Responder>,
to_raft_core: Option<mpsc::Sender>, // Optional because RaftCore does not need to be informed for every log.
}
pub trait RaftStateMachineV2<C> {
async fn apply<I>(&mut self, entries: I) -> Result<Vec<C::R>, StorageError<C>>
where
I: IntoIterator<Item = (C::Entry, Callback)> + OptionalSend,
I::IntoIter: OptionalSend; Currently, the This current approach seems sufficient for upgrading the state machine, as far as I know. A This approach won't have the how to trigger applying further entries problem, right? What say you? |
Sure, that's also OK. But, the applied log ID doesn't have to be sent for each entry processed in the BTW, But again, do we need to notify |
RaftCore could be notified only by the last applied entry in a batch. This is done by set all of the
Yes.
As the usage of |
Originally posted by @schreter in #1154 (review)
Allows
apply()
to return before the IO completion, and when the IO completes, call the callbackCallback.completed()
to informRaftCore
about the result.Callback.complete()
should also be responsible to send back the result to client.The text was updated successfully, but these errors were encountered: