Skip to content

Commit 56486a6

Browse files
committed
Fix: Error After change_membership: assertion failed: value > prev: #584
Problem: Error After change_membership: `assertion failed: value > prev`, when changing membership by converting a learner to a voter. Because the replication streams are re-spawned, thus progress reverts to zero. Then a reverted progress causes the panic. Solution: When re-spawning replications, remember the previous progress. - Fix: #584
1 parent ee134c0 commit 56486a6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

openraft/src/core/raft_core.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ impl<C: RaftTypeConfig, N: RaftNetworkFactory<C>, S: RaftStorage<C>> RaftCore<C,
994994
pub(crate) async fn spawn_replication_stream(
995995
&mut self,
996996
target: C::NodeId,
997+
matched: Option<LogId<C::NodeId>>,
997998
) -> Result<ReplicationStream<C::NodeId>, N::ConnectionError> {
998999
let target_node = self.engine.state.membership_state.effective.get_node(&target);
9991000
let membership_log_id = self.engine.state.membership_state.effective.log_id;
@@ -1007,6 +1008,7 @@ impl<C: RaftTypeConfig, N: RaftNetworkFactory<C>, S: RaftStorage<C>> RaftCore<C,
10071008
self.config.clone(),
10081009
self.engine.state.last_log_id(),
10091010
self.engine.state.committed,
1011+
matched,
10101012
network,
10111013
self.storage.get_log_reader().await,
10121014
self.tx_api.clone(),
@@ -1611,9 +1613,8 @@ impl<C: RaftTypeConfig, N: RaftNetworkFactory<C>, S: RaftStorage<C>> RaftRuntime
16111613
Command::UpdateReplicationStreams { targets } => {
16121614
self.remove_all_replication().await;
16131615

1614-
// TODO: use _matched to initialize replication
1615-
for (node_id, _matched) in targets.iter() {
1616-
match self.spawn_replication_stream(*node_id).await {
1616+
for (node_id, matched) in targets.iter() {
1617+
match self.spawn_replication_stream(*node_id, *matched).await {
16171618
Ok(state) => {
16181619
if let Some(l) = &mut self.leader_data {
16191620
l.nodes.insert(*node_id, state);

openraft/src/replication/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ impl<C: RaftTypeConfig, N: RaftNetworkFactory<C>, S: RaftStorage<C>> Replication
140140
config: Arc<Config>,
141141
last_log: Option<LogId<C::NodeId>>,
142142
committed: Option<LogId<C::NodeId>>,
143+
matched: Option<LogId<C::NodeId>>,
143144
network: N::Network,
144145
log_reader: S::LogReader,
145146
raft_core_tx: mpsc::UnboundedSender<RaftMsg<C, N, S>>,
@@ -158,7 +159,7 @@ impl<C: RaftTypeConfig, N: RaftNetworkFactory<C>, S: RaftStorage<C>> Replication
158159
config,
159160
target_repl_state: TargetReplState::LineRate,
160161
committed,
161-
matched: None,
162+
matched,
162163
max_possible_matched_index: last_log.index(),
163164
raft_core_tx,
164165
repl_rx,

0 commit comments

Comments
 (0)