Skip to content

Commit

Permalink
chore: add client urls to member
Browse files Browse the repository at this point in the history
Signed-off-by: themanforfree <[email protected]>
  • Loading branch information
themanforfree committed Feb 17, 2024
1 parent ac27079 commit 9dfb7a2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion crates/curp/proto/common
Submodule common updated 1 files
+5 −4 src/curp-command.proto
21 changes: 11 additions & 10 deletions crates/curp/src/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ impl Member {
pub fn new(
id: ServerId,
name: impl Into<String>,
addrs: impl Into<Vec<String>>,
peer_urls: impl Into<Vec<String>>,
is_learner: bool,
) -> Self {
Self {
id,
name: name.into(),
addrs: addrs.into(),
peer_urls: peer_urls.into(),
client_urls: vec![], // TODO
is_learner,
}
}
Expand All @@ -57,8 +58,8 @@ impl Member {
/// Get member addresses
#[must_use]
#[inline]
pub fn addrs(&self) -> &[String] {
self.addrs.as_slice()
pub fn peer_urls(&self) -> &[String] {
self.peer_urls.as_slice()
}

/// Is learner or not
Expand Down Expand Up @@ -140,7 +141,7 @@ impl ClusterInfo {
.members
.into_iter()
.map(|mut member| {
if member.addrs() == self_addr {
if member.peer_urls() == self_addr {
member_id = member.id;
member.name = self_name.to_owned();
}
Expand Down Expand Up @@ -202,15 +203,15 @@ impl ClusterInfo {
.members
.get_mut(id)
.unwrap_or_else(|| unreachable!("member {} not found", id));
std::mem::swap(&mut addrs, &mut member.addrs);
std::mem::swap(&mut addrs, &mut member.peer_urls);
addrs
}

/// Get server addresses via server id
#[must_use]
#[inline]
pub fn addrs(&self, id: ServerId) -> Option<Vec<String>> {
self.members.get(&id).map(|t| t.addrs.clone())
self.members.get(&id).map(|t| t.peer_urls.clone())
}

/// Get the current member
Expand All @@ -227,7 +228,7 @@ impl ClusterInfo {
#[must_use]
#[inline]
pub fn self_addrs(&self) -> Vec<String> {
self.self_member().addrs.clone()
self.self_member().peer_urls.clone()
}

/// Get the current server id
Expand Down Expand Up @@ -329,7 +330,7 @@ impl ClusterInfo {
self.members
.iter()
.filter(|t| t.id != self.member_id)
.map(|t| (t.id, t.addrs.clone()))
.map(|t| (t.id, t.peer_urls.clone()))
.collect()
}

Expand All @@ -339,7 +340,7 @@ impl ClusterInfo {
pub fn all_members_addrs(&self) -> HashMap<ServerId, Vec<String>> {
self.members
.iter()
.map(|t| (t.id, t.addrs.clone()))
.map(|t| (t.id, t.peer_urls.clone()))
.collect()
}

Expand Down
2 changes: 1 addition & 1 deletion crates/curp/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl FetchClusterResponse {
pub(crate) fn into_members_addrs(self) -> HashMap<ServerId, Vec<String>> {
self.members
.into_iter()
.map(|member| (member.id, member.addrs))
.map(|member| (member.id, member.peer_urls)) // TODO
.collect()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/curp/src/server/raw_curp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ impl<C: Command, RC: RoleChange> RawCurp<C, RC> {
(
true,
(
removed_member.addrs,
removed_member.peer_urls,
removed_member.name,
removed_member.is_learner,
),
Expand Down
2 changes: 1 addition & 1 deletion crates/curp/tests/it/common/curp_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl CurpGroup {
let members = cluster_res_base
.members
.into_iter()
.map(|m| Member::new(m.id, m.name, m.addrs, m.is_learner))
.map(|m| Member::new(m.id, m.name, m.peer_urls, m.is_learner))
.collect();
let cluster_res = curp::rpc::FetchClusterResponse {
leader_id: cluster_res_base.leader_id,
Expand Down
4 changes: 2 additions & 2 deletions crates/curp/tests/it/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ async fn propose_update_node_should_success() {
let members = client.propose_conf_change(changes).await.unwrap();
assert_eq!(members.len(), 5);
let member = members.iter().find(|m| m.id == node_id);
assert!(member.is_some_and(|m| m.addrs == ["new_addr"]));
assert!(member.is_some_and(|m| m.peer_urls == ["new_addr"]));
}

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -439,7 +439,7 @@ async fn propose_conf_change_to_follower() {
let members = client.propose_conf_change(changes).await.unwrap();
assert_eq!(members.len(), 5);
let member = members.iter().find(|m| m.id == node_id);
assert!(member.is_some_and(|m| m.addrs == ["new_addr"]));
assert!(member.is_some_and(|m| m.peer_urls == ["new_addr"]));
}

async fn check_new_node(is_learner: bool) {
Expand Down
14 changes: 7 additions & 7 deletions crates/xline/src/server/cluster_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ impl ClusterServer {
.await?
.into_iter()
.map(|member| Member {
id: member.id(),
name: member.name().to_owned(),
peer_ur_ls: member.addrs().to_vec(),
client_ur_ls: member.addrs().to_vec(),
is_learner: member.is_learner(),
id: member.id,
name: member.name.clone(),
peer_ur_ls: member.peer_urls.clone(),
client_ur_ls: member.client_urls.clone(),
is_learner: member.is_learner,
})
.collect())
}
Expand Down Expand Up @@ -132,8 +132,8 @@ impl Cluster for ClusterServer {
.map(|member| Member {
id: member.id,
name: member.name,
peer_ur_ls: member.addrs.clone(),
client_ur_ls: member.addrs,
peer_ur_ls: member.peer_urls,
client_ur_ls: member.client_urls,
is_learner: member.is_learner,
})
.collect(),
Expand Down

0 comments on commit 9dfb7a2

Please sign in to comment.