@@ -103,33 +103,37 @@ impl TokenAwarePolicy {
103103
104104 result
105105 }
106+
107+ pub ( crate ) fn replicas_for_token (
108+ token : & Token ,
109+ statement : & Statement ,
110+ cluster : & ClusterData ,
111+ ) -> Vec < Arc < Node > > {
112+ let keyspace = statement. keyspace . and_then ( |k| cluster. keyspaces . get ( k) ) ;
113+
114+ let strategy = keyspace. map ( |k| & k. strategy ) ;
115+
116+ match strategy {
117+ Some ( Strategy :: SimpleStrategy { replication_factor } ) => {
118+ Self :: simple_strategy_replicas ( cluster, token, * replication_factor)
119+ }
120+ Some ( Strategy :: NetworkTopologyStrategy {
121+ datacenter_repfactors,
122+ } ) => Self :: network_topology_strategy_replicas ( cluster, token, datacenter_repfactors) ,
123+ _ => {
124+ // default to simple strategy with replication factor = 1
125+ let replication_factor = 1 ;
126+ Self :: simple_strategy_replicas ( cluster, token, replication_factor)
127+ }
128+ }
129+ }
106130}
107131
108132impl LoadBalancingPolicy for TokenAwarePolicy {
109133 fn plan < ' a > ( & self , statement : & Statement , cluster : & ' a ClusterData ) -> Plan < ' a > {
110134 match statement. token {
111135 Some ( token) => {
112- let keyspace = statement. keyspace . and_then ( |k| cluster. keyspaces . get ( k) ) ;
113-
114- let strategy = keyspace. map ( |k| & k. strategy ) ;
115-
116- let replicas = match strategy {
117- Some ( Strategy :: SimpleStrategy { replication_factor } ) => {
118- Self :: simple_strategy_replicas ( cluster, & token, * replication_factor)
119- }
120- Some ( Strategy :: NetworkTopologyStrategy {
121- datacenter_repfactors,
122- } ) => Self :: network_topology_strategy_replicas (
123- cluster,
124- & token,
125- datacenter_repfactors,
126- ) ,
127- _ => {
128- // default to simple strategy with replication factor = 1
129- let replication_factor = 1 ;
130- Self :: simple_strategy_replicas ( cluster, & token, replication_factor)
131- }
132- } ;
136+ let replicas = Self :: replicas_for_token ( & token, statement, cluster) ;
133137 trace ! (
134138 token = token. value,
135139 replicas = replicas
0 commit comments