use super::FlushPoint;
use crate::RaftTypeConfig;
use crate::Vote;
use crate::core::io_flush_tracking::AppliedProgress;
use crate::core::io_flush_tracking::CommitProgress;
use crate::core::io_flush_tracking::LogProgress;
use crate::core::io_flush_tracking::SnapshotProgress;
use crate::core::io_flush_tracking::VoteProgress;
use crate::core::io_flush_tracking::sender::IoProgressSender;
use crate::type_config::TypeConfigExt;
use crate::type_config::alias::LogIdOf;
use crate::type_config::alias::WatchReceiverOf;
pub(crate) struct IoProgressWatcher<C>
where C: RaftTypeConfig
{
log: WatchReceiverOf<C, Option<FlushPoint<C>>>,
vote: WatchReceiverOf<C, Option<Vote<C::LeaderId>>>,
commit: WatchReceiverOf<C, Option<LogIdOf<C>>>,
snapshot: WatchReceiverOf<C, Option<LogIdOf<C>>>,
apply: WatchReceiverOf<C, Option<LogIdOf<C>>>,
}
impl<C> IoProgressWatcher<C>
where C: RaftTypeConfig
{
pub(crate) fn new() -> (IoProgressSender<C>, Self) {
let (log_tx, log) = C::watch_channel(None);
let (vote_tx, vote) = C::watch_channel(None);
let (commit_tx, commit) = C::watch_channel(None);
let (snapshot_tx, snapshot) = C::watch_channel(None);
let (apply_tx, apply) = C::watch_channel(None);
let sender = IoProgressSender {
log_tx,
vote_tx,
commit_tx,
snapshot_tx,
apply_tx,
};
let watcher = Self {
log,
vote,
commit,
snapshot,
apply,
};
(sender, watcher)
}
pub(crate) fn log_progress(&self) -> LogProgress<C> {
LogProgress::new(self.log.clone())
}
pub(crate) fn vote_progress(&self) -> VoteProgress<C> {
VoteProgress::new(self.vote.clone())
}
pub(crate) fn commit_progress(&self) -> CommitProgress<C> {
CommitProgress::new(self.commit.clone())
}
pub(crate) fn snapshot_progress(&self) -> SnapshotProgress<C> {
SnapshotProgress::new(self.snapshot.clone())
}
pub(crate) fn apply_progress(&self) -> AppliedProgress<C> {
AppliedProgress::new(self.apply.clone())
}
}