Skip to content

Commit

Permalink
Remove NodeStateSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
RNabel committed Aug 24, 2024
1 parent 277b8b7 commit 83f72ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
8 changes: 4 additions & 4 deletions chitchat-test/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ fn test_multiple_nodes() {
assert_eq!(info.live_nodes.len(), 5);
assert_eq!(info.dead_nodes.len(), 0);

assert!(info.cluster_state.node_state_snapshots.get(3).is_some());
assert!(info.cluster_state.node_states.get(3).is_some());
// Check that "some_key" we set on this local node (localhost:13001) is
// indeed set to be "some_value"
let node = info.cluster_state.node_state_snapshots.get(1).unwrap();
let versioned_value = node.node_state.get_versioned("some_key").unwrap();
let node_state = info.cluster_state.node_states.get(1).unwrap();
let versioned_value = node_state.get_versioned("some_key").unwrap();
assert_eq!(versioned_value.value, "some_value");
}

Expand All @@ -88,7 +88,7 @@ fn test_multiple_nodes_with_dns_resolution_for_seed() {
let _child_handles = setup_nodes(12_000, 5, 5, true);
// Check node states through api.
let info = get_node_info("http://127.0.0.1:12001").unwrap();
assert!(info.cluster_state.node_state_snapshots.get(3).is_some());
assert!(info.cluster_state.node_states.get(3).is_some());
assert_eq!(info.cluster_id, "testing");
assert_eq!(info.live_nodes.len(), 5);
assert_eq!(info.dead_nodes.len(), 0);
Expand Down
22 changes: 5 additions & 17 deletions chitchat/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,30 +793,17 @@ impl<'a> StaleNode<'a> {
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct NodeStateSnapshot {
pub chitchat_id: ChitchatId,
pub node_state: NodeState,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ClusterStateSnapshot {
pub node_state_snapshots: Vec<NodeStateSnapshot>,
pub node_states: Vec<NodeState>,
pub seed_addrs: HashSet<SocketAddr>,
}

impl From<&ClusterState> for ClusterStateSnapshot {
fn from(cluster_state: &ClusterState) -> Self {
let node_state_snapshots = cluster_state
.node_states
.iter()
.map(|(chitchat_id, node_state)| NodeStateSnapshot {
chitchat_id: chitchat_id.clone(),
node_state: node_state.clone(),
})
.collect();
let node_states = cluster_state.node_states.values().cloned().collect();
Self {
node_state_snapshots,
node_states,
seed_addrs: cluster_state.seed_addrs(),
}
}
Expand Down Expand Up @@ -1455,7 +1442,8 @@ mod tests {
node1_state.set_with_version("key_b".to_string(), "2".to_string(), 2); // 2

let node2_state = cluster_state.node_state_mut(&node2);
node2_state.set_with_version("key_c".to_string(), "3".to_string(), 2); // 2
node2_state.set_with_version("key_c".to_string(), "3".to_string(), 2);
// 2
}

{
Expand Down

0 comments on commit 83f72ad

Please sign in to comment.