@@ -51,7 +51,7 @@ const DRIVER_VERSION: &str = env!("CARGO_PKG_VERSION");
51
51
pub ( crate ) struct LoadBalancingConfig {
52
52
pub ( crate ) token_awareness_enabled : bool ,
53
53
pub ( crate ) token_aware_shuffling_replicas_enabled : bool ,
54
- pub ( crate ) dc_awareness : Option < DcAwareness > ,
54
+ pub ( crate ) node_location_preference : NodeLocationPreference ,
55
55
pub ( crate ) latency_awareness_enabled : bool ,
56
56
pub ( crate ) latency_awareness_builder : LatencyAwarenessBuilder ,
57
57
}
@@ -65,10 +65,8 @@ impl LoadBalancingConfig {
65
65
builder =
66
66
builder. enable_shuffling_replicas ( self . token_aware_shuffling_replicas_enabled ) ;
67
67
}
68
- if let Some ( dc_awareness) = self . dc_awareness {
69
- builder = builder
70
- . prefer_datacenter ( dc_awareness. local_dc )
71
- . permit_dc_failover ( true )
68
+ if let NodeLocationPreference :: Datacenter { local_dc } = self . node_location_preference {
69
+ builder = builder. prefer_datacenter ( local_dc) . permit_dc_failover ( true )
72
70
}
73
71
if self . latency_awareness_enabled {
74
72
builder = builder. latency_awareness ( self . latency_awareness_builder ) ;
@@ -81,16 +79,17 @@ impl Default for LoadBalancingConfig {
81
79
Self {
82
80
token_awareness_enabled : true ,
83
81
token_aware_shuffling_replicas_enabled : true ,
84
- dc_awareness : None ,
82
+ node_location_preference : NodeLocationPreference :: Any ,
85
83
latency_awareness_enabled : false ,
86
84
latency_awareness_builder : Default :: default ( ) ,
87
85
}
88
86
}
89
87
}
90
88
91
89
#[ derive( Clone , Debug ) ]
92
- pub ( crate ) struct DcAwareness {
93
- pub ( crate ) local_dc : String ,
90
+ pub ( crate ) enum NodeLocationPreference {
91
+ Any ,
92
+ Datacenter { local_dc : String } ,
94
93
}
95
94
96
95
#[ derive( Clone ) ]
@@ -457,7 +456,7 @@ pub unsafe extern "C" fn cass_cluster_set_credentials_n(
457
456
#[ no_mangle]
458
457
pub unsafe extern "C" fn cass_cluster_set_load_balance_round_robin ( cluster_raw : * mut CassCluster ) {
459
458
let cluster = ptr_to_ref_mut ( cluster_raw) ;
460
- cluster. load_balancing_config . dc_awareness = None ;
459
+ cluster. load_balancing_config . node_location_preference = NodeLocationPreference :: Any ;
461
460
}
462
461
463
462
#[ no_mangle]
@@ -496,7 +495,8 @@ pub(crate) unsafe fn set_load_balance_dc_aware_n(
496
495
. unwrap ( )
497
496
. to_string ( ) ;
498
497
499
- load_balancing_config. dc_awareness = Some ( DcAwareness { local_dc } ) ;
498
+ load_balancing_config. node_location_preference =
499
+ NodeLocationPreference :: Datacenter { local_dc } ;
500
500
501
501
CassError :: CASS_OK
502
502
}
@@ -851,7 +851,10 @@ mod tests {
851
851
/* Test valid configurations */
852
852
let cluster = ptr_to_ref ( cluster_raw) ;
853
853
{
854
- assert_matches ! ( cluster. load_balancing_config. dc_awareness, None ) ;
854
+ assert_matches ! (
855
+ cluster. load_balancing_config. node_location_preference,
856
+ NodeLocationPreference :: Any
857
+ ) ;
855
858
assert ! ( cluster. load_balancing_config. token_awareness_enabled) ;
856
859
assert ! ( !cluster. load_balancing_config. latency_awareness_enabled) ;
857
860
}
@@ -878,8 +881,14 @@ mod tests {
878
881
40 ,
879
882
) ;
880
883
881
- let dc_awareness = cluster. load_balancing_config . dc_awareness . as_ref ( ) . unwrap ( ) ;
882
- assert_eq ! ( dc_awareness. local_dc, "eu" ) ;
884
+ let node_location_preference =
885
+ & cluster. load_balancing_config . node_location_preference ;
886
+ match node_location_preference {
887
+ NodeLocationPreference :: Datacenter { local_dc } => {
888
+ assert_eq ! ( local_dc, "eu" )
889
+ }
890
+ _ => panic ! ( "Expected preferred dc" ) ,
891
+ }
883
892
assert ! ( !cluster. load_balancing_config. token_awareness_enabled) ;
884
893
assert ! ( cluster. load_balancing_config. latency_awareness_enabled) ;
885
894
}
0 commit comments