Skip to content

Commit

Permalink
*: update kvproto
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
  • Loading branch information
BusyJay committed Apr 3, 2020
1 parent 5433c34 commit 72822f8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -38,3 +38,4 @@ fuzz-incremental/
/db/
/last_tikv.toml
/raft/
*.log
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/raftstore/src/store/fsm/store.rs
Expand Up @@ -2067,7 +2067,7 @@ impl<'a, T: Transport, C: PdClient> StoreFsmDelegate<'a, T, C> {
}
let exist_dr = mode.status.get_dr_autosync();
let dr = status.get_dr_autosync();
if exist_dr.recover_id == dr.recover_id && exist_dr.state == dr.state {
if exist_dr.state_id == dr.state_id && exist_dr.state == dr.state {
return;
}
}
Expand Down
27 changes: 13 additions & 14 deletions components/raftstore/src/store/peer.rs
Expand Up @@ -246,7 +246,7 @@ pub struct Peer {

/// Time of the last attempt to wake up inactive leader.
pub bcast_wake_up_time: Option<UtilInstant>,
pub recover_id: u64,
pub replication_mode_version: u64,
}

impl Peer {
Expand Down Expand Up @@ -326,7 +326,7 @@ impl Peer {
peer_stat: PeerStat::default(),
catch_up_logs: None,
bcast_wake_up_time: None,
recover_id: 0,
replication_mode_version: 0,
};

// If this region has only one peer and I am the one, campaign directly.
Expand All @@ -340,12 +340,13 @@ impl Peer {
pub fn init_commit_group(&mut self, mode: &mut ReplicationMode) {
debug!("init commit group"; "mode" => ?mode, "regioni_id" => self.region_id, "peer_id" => self.peer.id);
if mode.status.mode == ReplicateStatusMode::Majority {
self.replication_mode_version = 0;
return;
}
if self.get_store().region().get_peers().is_empty() {
return;
}
self.recover_id = mode.status.get_dr_autosync().recover_id;
self.replication_mode_version = mode.status.get_dr_autosync().state_id;
if mode.status.get_dr_autosync().state == DrAutoSyncState::Async {
return;
}
Expand All @@ -359,9 +360,10 @@ impl Peer {
debug!("switch commit group"; "mode" => ?mode, "regioni_id" => self.region_id, "peer_id" => self.peer.id);
let mut guard = mode.lock().unwrap();
let clear = if guard.status.mode == ReplicateStatusMode::Majority {
self.replication_mode_version = 0;
true
} else {
self.recover_id = guard.status.get_dr_autosync().recover_id;
self.replication_mode_version = guard.status.get_dr_autosync().state_id;
guard.status.get_dr_autosync().state == DrAutoSyncState::Async
};
if clear {
Expand Down Expand Up @@ -2551,19 +2553,16 @@ impl Peer {
}

fn region_replicate_status(&mut self) -> Option<RegionReplicateStatus> {
if self.recover_id == 0 {
if self.replication_mode_version == 0 {
return None;
}
let mut status = RegionReplicateStatus::default();
status.recover_id = self.recover_id;
if self
.raft_group
.raft
.check_group_commit_consistent()
.unwrap_or(false)
{
status.state = RegionReplicateStatusState::IntegrityOverLabel;
}
status.state_id = self.replication_mode_version;
status.state = match self.raft_group.raft.check_group_commit_consistent() {
Some(true) => RegionReplicateStatusState::IntegrityOverLabel,
Some(false) => RegionReplicateStatusState::Majority,
None => RegionReplicateStatusState::Unknown,
};
Some(status)
}

Expand Down
6 changes: 3 additions & 3 deletions components/test_raftstore/src/pd.rs
Expand Up @@ -1000,15 +1000,15 @@ impl TestPdClient {
let mut status = ReplicateStatus::default();
status.mode = ReplicateStatusMode::DrAutosync;
status.mut_dr_autosync().label_key = label_key.to_owned();
status.mut_dr_autosync().recover_id = 1;
status.mut_dr_autosync().state_id = 1;
self.cluster.wl().replication_status = Some(status);
}

pub fn switch_replication_mode(&self, state: DrAutoSyncState) {
let mut cluster = self.cluster.wl();
let status = cluster.replication_status.as_mut().unwrap();
let dr = status.mut_dr_autosync();
dr.recover_id += 1;
let mut dr = status.mut_dr_autosync();
dr.state_id += 1;
dr.state = state;
}

Expand Down
10 changes: 5 additions & 5 deletions tests/integrations/raftstore/test_commit_algorithm.rs
Expand Up @@ -60,7 +60,7 @@ fn test_integrity_over_first_label() {
must_get_equal(&cluster.get_engine(1), b"k1", b"v1");
thread::sleep(Duration::from_millis(100));
let state = cluster.pd_client.region_replicate_status(region.get_id());
assert_eq!(state.recover_id, 1);
assert_eq!(state.state_id, 1);
assert_eq!(state.state, RegionReplicateStatusState::IntegrityOverLabel);

cluster.clear_send_filters();
Expand All @@ -84,7 +84,7 @@ fn test_integrity_over_first_label() {
);
must_get_none(&cluster.get_engine(1), b"k2");
let state = cluster.pd_client.region_replicate_status(region.get_id());
assert_eq!(state.recover_id, 1);
assert_eq!(state.state_id, 1);
assert_eq!(state.state, RegionReplicateStatusState::IntegrityOverLabel);

cluster
Expand All @@ -94,7 +94,7 @@ fn test_integrity_over_first_label() {
must_get_equal(&cluster.get_engine(1), b"k2", b"v2");
thread::sleep(Duration::from_millis(100));
let state = cluster.pd_client.region_replicate_status(region.get_id());
assert_eq!(state.recover_id, 2);
assert_eq!(state.state_id, 2);
assert_eq!(state.state, RegionReplicateStatusState::Majority);

cluster
Expand All @@ -120,14 +120,14 @@ fn test_integrity_over_first_label() {
);
must_get_none(&cluster.get_engine(1), b"k3");
let state = cluster.pd_client.region_replicate_status(region.get_id());
assert_eq!(state.recover_id, 3);
assert_eq!(state.state_id, 3);
assert_eq!(state.state, RegionReplicateStatusState::Majority);

cluster.clear_send_filters();
must_get_equal(&cluster.get_engine(1), b"k3", b"v3");
thread::sleep(Duration::from_millis(100));
let state = cluster.pd_client.region_replicate_status(region.get_id());
assert_eq!(state.recover_id, 3);
assert_eq!(state.state_id, 3);
assert_eq!(state.state, RegionReplicateStatusState::IntegrityOverLabel);
}

Expand Down

0 comments on commit 72822f8

Please sign in to comment.