@@ -2,6 +2,7 @@ use crate::connection::{Connection, ConnectionInfo};
2
2
use crate :: pool:: ManagedConnection ;
3
3
use crate :: routing:: connection_registry:: { BoltServer , ConnectionRegistry } ;
4
4
use crate :: routing:: load_balancing:: LoadBalancingStrategy ;
5
+ use crate :: routing:: RoundRobinStrategy ;
5
6
#[ cfg( feature = "unstable-bolt-protocol-impl-v2" ) ]
6
7
use crate :: routing:: { RouteBuilder , RoutingTable } ;
7
8
use crate :: { Config , Error , Operation } ;
@@ -14,19 +15,16 @@ use std::time::Duration;
14
15
#[ derive( Clone ) ]
15
16
pub struct RoutedConnectionManager {
16
17
load_balancing_strategy : Arc < dyn LoadBalancingStrategy > ,
17
- registry : Arc < ConnectionRegistry > ,
18
+ connection_registry : Arc < ConnectionRegistry > ,
18
19
#[ allow( dead_code) ]
19
20
bookmarks : Arc < Mutex < Vec < String > > > ,
20
21
backoff : Arc < ExponentialBackoff > ,
21
22
config : Config ,
22
23
}
23
24
24
25
impl RoutedConnectionManager {
25
- pub async fn new (
26
- config : & Config ,
27
- load_balancing_strategy : Arc < dyn LoadBalancingStrategy > ,
28
- ) -> Result < Self , Error > {
29
- let registry = Arc :: new ( ConnectionRegistry :: new ( config) . await ?) ;
26
+ pub async fn new ( config : & Config ) -> Result < Self , Error > {
27
+ let registry = Arc :: new ( ConnectionRegistry :: new ( config) ) ;
30
28
let backoff = Arc :: new (
31
29
ExponentialBackoffBuilder :: new ( )
32
30
. with_initial_interval ( Duration :: from_millis ( 1 ) )
@@ -37,8 +35,8 @@ impl RoutedConnectionManager {
37
35
) ;
38
36
39
37
Ok ( RoutedConnectionManager {
40
- load_balancing_strategy,
41
- registry,
38
+ load_balancing_strategy : Arc :: new ( RoundRobinStrategy :: default ( ) ) ,
39
+ connection_registry : registry,
42
40
bookmarks : Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ,
43
41
backoff,
44
42
config : config. clone ( ) ,
@@ -70,7 +68,7 @@ impl RoutedConnectionManager {
70
68
) -> Result < ManagedConnection , Error > {
71
69
// We probably need to do this in a more efficient way, since this will block the request of a connection
72
70
// while we refresh the routing table. We should probably have a separate thread that refreshes the routing
73
- self . registry
71
+ self . connection_registry
74
72
. update_if_expired ( || self . refresh_routing_table ( ) )
75
73
. await ?;
76
74
@@ -80,15 +78,15 @@ impl RoutedConnectionManager {
80
78
_ => self . select_reader ( ) ,
81
79
} {
82
80
debug ! ( "requesting connection for server: {:?}" , server) ;
83
- if let Some ( pool) = self . registry . get_pool ( & server) {
81
+ if let Some ( pool) = self . connection_registry . get_pool ( & server) {
84
82
match pool. get ( ) . await {
85
83
Ok ( connection) => return Ok ( connection) ,
86
84
Err ( e) => {
87
85
error ! (
88
86
"Failed to get connection from pool for server `{}`: {}" ,
89
87
server. address, e
90
88
) ;
91
- self . registry . mark_unavailable ( & server) ;
89
+ self . connection_registry . mark_unavailable ( & server) ;
92
90
continue ;
93
91
}
94
92
}
@@ -115,11 +113,11 @@ impl RoutedConnectionManager {
115
113
116
114
fn select_reader ( & self ) -> Option < BoltServer > {
117
115
self . load_balancing_strategy
118
- . select_reader ( & self . registry . servers ( ) )
116
+ . select_reader ( & self . connection_registry . servers ( ) )
119
117
}
120
118
121
119
fn select_writer ( & self ) -> Option < BoltServer > {
122
120
self . load_balancing_strategy
123
- . select_writer ( & self . registry . servers ( ) )
121
+ . select_writer ( & self . connection_registry . servers ( ) )
124
122
}
125
123
}
0 commit comments