pub(crate) fn new(
        metadata: Metadata,
        pool_config: &PoolConfig,
        known_peers: &HashMap<SocketAddr, Arc<Node>>,
        used_keyspace: &Option<VerifiedKeyspaceName>,
    ) -> Self {
        // Create new updated known_peers and ring
        let mut new_known_peers: HashMap<SocketAddr, Arc<Node>> =
            HashMap::with_capacity(metadata.peers.len());
        let mut ring: BTreeMap<Token, Arc<Node>> = BTreeMap::new();
        let mut datacenters: HashMap<String, Datacenter> = HashMap::new();
        let mut all_nodes: Vec<Arc<Node>> = Vec::with_capacity(metadata.peers.len());

        for peer in metadata.peers {
            // Take existing Arc<Node> if possible, otherwise create new one
            // Changing rack/datacenter but not ip address seems improbable
            // so we can just create new node and connections then
            let node: Arc<Node> = match known_peers.get(&peer.address) {
                Some(node) if node.datacenter == peer.datacenter && node.rack == peer.rack => {
                    node.clone()
                }
                _ => Arc::new(Node::new(
                    peer.address,
                    pool_config.clone(),
                    peer.datacenter,
                    peer.rack,
                    used_keyspace.clone(),
                )),
            };

            new_known_peers.insert(peer.address, node.clone());

            if let Some(dc) = &node.datacenter {
                match datacenters.get_mut(dc) {
                    Some(v) => v.nodes.push(node.clone()),
                    None => {
                        let v = Datacenter {
                            nodes: vec![node.clone()],
                            rack_count: 0,
                        };
                        datacenters.insert(dc.clone(), v);
                    }
                }
            }

            for token in peer.tokens {
                ring.insert(token, node.clone());
            }

            all_nodes.push(node);
        }

        Self::update_rack_count(&mut datacenters);

        ClusterData {
            known_peers: new_known_peers,
            ring,
            keyspaces: metadata.keyspaces,
            all_nodes,
            datacenters,
        }
    }
/// Creates new ClusterData using information about topology held in `metadata`.
/// Uses provided `known_peers` hashmap to recycle nodes if possible.
Creates new ClusterData using information about topology held in `metadata`.
Uses provided `known_peers` hashmap to recycle nodes if possible.
Creates new ClusterData using information about topology held in ` metadata ` . Uses provided ` known_peers ` hashmap to recycle nodes if possible .
pub(crate) fn new(
        metadata: Metadata,
        pool_config: &PoolConfig,
        known_peers: &HashMap<SocketAddr, Arc<Node>>,
        used_keyspace: &Option<VerifiedKeyspaceName>,
    ) -> Self {
        // Create new updated known_peers and ring
        let mut new_known_peers: HashMap<SocketAddr, Arc<Node>> =
            HashMap::with_capacity(metadata.peers.len());
        let mut ring: BTreeMap<Token, Arc<Node>> = BTreeMap::new();
        let mut datacenters: HashMap<String, Datacenter> = HashMap::new();
        let mut all_nodes: Vec<Arc<Node>> = Vec::with_capacity(metadata.peers.len());
        for peer in metadata.peers {
            // Take existing Arc<Node> if possible, otherwise create new one
            // Changing rack/datacenter but not ip address seems improbable
            // so we can just create new node and connections then
            let node: Arc<Node> = match known_peers.get(&peer.address) {
                Some(node) if node.datacenter == peer.datacenter && node.rack == peer.rack => {
                    node.clone()
                }
                _ => Arc::new(Node::new(
                    peer.address,
                    pool_config.clone(),
                    peer.datacenter,
                    peer.rack,
                    used_keyspace.clone(),
                )),
            };
            new_known_peers.insert(peer.address, node.clone());
            if let Some(dc) = &node.datacenter {
                match datacenters.get_mut(dc) {
                    Some(v) => v.nodes.push(node.clone()),
                    None => {
                        let v = Datacenter {
                            nodes: vec![node.clone()],
                            rack_count: 0,
                        };
                        datacenters.insert(dc.clone(), v);
                    }
                }
            }
            for token in peer.tokens {
                ring.insert(token, node.clone());
            }
            all_nodes.push(node);
        }
        Self::update_rack_count(&mut datacenters);
        ClusterData {
            known_peers: new_known_peers,
            ring,
            keyspaces: metadata.keyspaces,
            all_nodes,
            datacenters,
        }
    }
pub ( crate ) fn new ( metadata : Metadata , pool_config : & PoolConfig , known_peers : & HashMap < SocketAddr , Arc < Node > > , used_keyspace : & Option < VerifiedKeyspaceName > , ) -> Self { // Create new updated known_peers and ring let mut new_known_peers : HashMap < SocketAddr , Arc < Node > > = HashMap :: with_capacity ( metadata . peers . len ( ) ) ; let mut ring : BTreeMap < Token , Arc < Node > > = BTreeMap :: new ( ) ; let mut datacenters : HashMap < String , Datacenter > = HashMap :: new ( ) ; let mut all_nodes : Vec < Arc < Node > > = Vec :: with_capacity ( metadata . peers . len ( ) ) ; for peer in metadata . peers { // Take existing Arc<Node> if possible, otherwise create new one // Changing rack/datacenter but not ip address seems improbable // so we can just create new node and connections then let node : Arc < Node > = match known_peers . get ( & peer . address ) { Some ( node ) if node . datacenter == peer . datacenter && node . rack == peer . rack => { node . clone ( ) } _ => Arc :: new ( Node :: new ( peer . address , pool_config . clone ( ) , peer . datacenter , peer . rack , used_keyspace . clone ( ) , ) ) , } ; new_known_peers . insert ( peer . address , node . clone ( ) ) ; if let Some ( dc ) = & node . datacenter { match datacenters . get_mut ( dc ) { Some ( v ) => v . nodes . push ( node . clone ( ) ) , None => { let v = Datacenter { nodes : vec ! [ node clone ( ) ] , rack_count : 0 , } ; datacenters . insert ( dc . clone ( ) , v ) ; } } } for token in peer . tokens { ring . insert ( token , node . clone ( ) ) ; } all_nodes . push ( node ) ; } Self :: update_rack_count ( & mut datacenters ) ; ClusterData { known_peers : new_known_peers , ring , keyspaces : metadata . keyspaces , all_nodes , datacenters , } }
Creates new ClusterData using information about topology held in `metadata`.
Creates new ClusterData using information about topology held in ` metadata ` .
metadata
Metadata
pool_config
&PoolConfig
known_peers
&HashMap<SocketAddr, Arc<Node>>
used_keyspace
&Option<VerifiedKeyspaceName>
metadata
Metadata
pool_config
&PoolConfig
known_peers
&HashMap<SocketAddr, Arc<Node>>
used_keyspace
&Option<VerifiedKeyspaceName>