11#[ cfg( feature = "unstable-bolt-protocol-impl-v2" ) ]
22use {
33 crate :: connection:: { ConnectionInfo , Routing } ,
4- crate :: graph:: ConnectionPoolManager :: Routed ,
54 crate :: routing:: { ClusterRoutingTableProvider , RoutedConnectionManager } ,
65 crate :: summary:: ResultSummary ,
76 log:: debug,
87 std:: sync:: Arc ,
98} ;
109
1110use crate :: config:: ImpersonateUser ;
12- use crate :: graph:: ConnectionPoolManager :: Direct ;
1311use crate :: pool:: ManagedConnection ;
1412use crate :: query:: RetryableQuery ;
1513use crate :: retry:: Retry ;
1614use crate :: RunResult ;
17- use crate :: { config:: { Config , ConfigBuilder , Database , LiveConfig } , errors:: Result , pool:: { create_pool, ConnectionPool } , query:: Query , stream:: DetachedRowStream , txn:: Txn , Operation } ;
15+ use crate :: {
16+ config:: { Config , ConfigBuilder , Database , LiveConfig } ,
17+ errors:: Result ,
18+ pool:: { create_pool, ConnectionPool } ,
19+ query:: Query ,
20+ stream:: DetachedRowStream ,
21+ txn:: Txn ,
22+ Operation ,
23+ } ;
1824#[ cfg( feature = "unstable-bolt-protocol-impl-v2" ) ]
1925use crate :: {
2026 session:: { Session , SessionConfig } ,
@@ -41,16 +47,18 @@ impl ConnectionPoolManager {
4147 ) -> Result < ManagedConnection > {
4248 match self {
4349 #[ cfg( feature = "unstable-bolt-protocol-impl-v2" ) ]
44- Routed ( manager) => manager. get ( operation, db, imp_user, bookmarks) . await ,
45- Direct ( pool) => pool. get ( ) . await . map_err ( crate :: Error :: from) ,
50+ ConnectionPoolManager :: Routed ( manager) => {
51+ manager. get ( operation, db, imp_user, bookmarks) . await
52+ }
53+ ConnectionPoolManager :: Direct ( pool) => pool. get ( ) . await . map_err ( crate :: Error :: from) ,
4654 }
4755 }
4856
4957 fn backoff ( & self ) -> ExponentialBuilder {
5058 match self {
5159 #[ cfg( feature = "unstable-bolt-protocol-impl-v2" ) ]
52- Routed ( manager) => manager. backoff ( ) ,
53- Direct ( pool) => pool. manager ( ) . backoff ( ) ,
60+ ConnectionPoolManager :: Routed ( manager) => manager. backoff ( ) ,
61+ ConnectionPoolManager :: Direct ( pool) => pool. manager ( ) . backoff ( ) ,
5462 }
5563 }
5664}
@@ -84,7 +92,7 @@ impl Graph {
8492 ) ?;
8593 if matches ! ( info. init. routing, Routing :: Yes ( _) ) {
8694 debug ! ( "Routing enabled, creating a routed connection manager" ) ;
87- let pool = Routed ( RoutedConnectionManager :: new (
95+ let pool = ConnectionPoolManager :: Routed ( RoutedConnectionManager :: new (
8896 & config,
8997 Arc :: new ( ClusterRoutingTableProvider :: new ( config. clone ( ) ) ) ,
9098 ) ?) ;
@@ -93,7 +101,7 @@ impl Graph {
93101 pool,
94102 } )
95103 } else {
96- let pool = Direct ( create_pool ( & config) ?) ;
104+ let pool = ConnectionPoolManager :: Direct ( create_pool ( & config) ?) ;
97105 Ok ( Graph {
98106 config : config. into_live_config ( ) ,
99107 pool,
@@ -102,7 +110,7 @@ impl Graph {
102110 }
103111 #[ cfg( not( feature = "unstable-bolt-protocol-impl-v2" ) ) ]
104112 {
105- let pool = Direct ( create_pool ( & config) ?) ;
113+ let pool = ConnectionPoolManager :: Direct ( create_pool ( & config) ?) ;
106114 Ok ( Graph {
107115 config : config. into_live_config ( ) ,
108116 pool,
@@ -194,7 +202,7 @@ impl Graph {
194202 {
195203 Txn :: new (
196204 db,
197- fetch_size. or ( Some ( self . config . fetch_size ) ) . unwrap ( ) ,
205+ fetch_size. unwrap_or ( self . config . fetch_size ) ,
198206 connection,
199207 operation,
200208 imp_user,
@@ -247,14 +255,26 @@ impl Graph {
247255 db : impl Into < Database > ,
248256 q : impl Into < Query > ,
249257 ) -> Result < ResultSummary > {
250- self . impl_run_on ( Some ( db. into ( ) ) , self . config . imp_user . clone ( ) , & [ ] , Some ( self . config . fetch_size ) , q. into ( ) )
251- . await
258+ self . impl_run_on (
259+ Some ( db. into ( ) ) ,
260+ self . config . imp_user . clone ( ) ,
261+ & [ ] ,
262+ Some ( self . config . fetch_size ) ,
263+ q. into ( ) ,
264+ )
265+ . await
252266 }
253267
254268 #[ cfg( not( feature = "unstable-bolt-protocol-impl-v2" ) ) ]
255269 pub async fn run_on ( & self , db : impl Into < Database > , q : impl Into < Query > ) -> Result < ( ) > {
256- self . impl_run_on ( Some ( db. into ( ) ) , self . config . imp_user . clone ( ) , & [ ] , Some ( self . config . fetch_size ) , q. into ( ) )
257- . await
270+ self . impl_run_on (
271+ Some ( db. into ( ) ) ,
272+ self . config . imp_user . clone ( ) ,
273+ & [ ] ,
274+ Some ( self . config . fetch_size ) ,
275+ q. into ( ) ,
276+ )
277+ . await
258278 }
259279
260280 #[ allow( unused_variables) ]
@@ -284,40 +304,20 @@ impl Graph {
284304 . await ;
285305
286306 match result {
287- Ok ( result) => {
288- #[ cfg( feature = "unstable-bolt-protocol-impl-v2" ) ]
289- {
290- if let Some ( bookmark) = result. bookmark . as_deref ( ) {
291- match & self . pool {
292- Routed ( routed) => {
293- routed. add_bookmark ( bookmark) . await ;
294- }
295- Direct ( _) => { }
296- }
297- } else if query. is_read ( ) {
298- match & self . pool {
299- Routed ( routed) => {
300- debug ! ( "No bookmark received after a read operation, discarding all bookmarks" ) ;
301- routed. clear_bookmarks ( ) . await ;
302- }
303- Direct ( _) => { }
304- }
305- }
306- }
307- Ok ( result)
308- }
307+ Ok ( result) => Ok ( result) ,
309308 Err ( e) => Err ( e. into_inner ( ) ) ,
310309 }
311310 }
312311
313- /// Executes a READ query on the configured database and returns a [`DetachedRowStream`]
312+ /// Executes a READ|WRITE query on the configured database and returns a [`DetachedRowStream`]
314313 ///
315314 /// This operation retires the query on certain failures.
316315 /// All errors with the `Transient` error class as well as a few other error classes are considered retryable.
317316 /// This includes errors during a leader election or when the transaction resources on the server (memory, handles, ...) are exhausted.
318317 /// Retries happen with an exponential backoff until a retry delay exceeds 60s, at which point the query fails with the last error as it would without any retry.
319318 pub async fn execute ( & self , q : impl Into < Query > ) -> Result < DetachedRowStream > {
320319 self . impl_execute_on (
320+ Operation :: Write ,
321321 self . config . db . clone ( ) ,
322322 self . config . imp_user . clone ( ) ,
323323 & [ ] ,
@@ -335,6 +335,7 @@ impl Graph {
335335 /// Retries happen with an exponential backoff until a retry delay exceeds 60s, at which point the query fails with the last error as it would without any retry.
336336 pub async fn execute_read ( & self , q : impl Into < Query > ) -> Result < DetachedRowStream > {
337337 self . impl_execute_on (
338+ Operation :: Read ,
338339 self . config . db . clone ( ) ,
339340 self . config . imp_user . clone ( ) ,
340341 & [ ] ,
@@ -353,11 +354,19 @@ impl Graph {
353354 #[ cfg( feature = "unstable-bolt-protocol-impl-v2" ) ]
354355 pub async fn execute_on (
355356 & self ,
357+ operation : Operation ,
356358 db : impl Into < Database > ,
357359 q : impl Into < Query > ,
358360 ) -> Result < DetachedRowStream > {
359- self . impl_execute_on ( Some ( db. into ( ) ) , self . config . imp_user . clone ( ) , & [ ] , Some ( self . config . fetch_size ) , q. into ( ) )
360- . await
361+ self . impl_execute_on (
362+ operation,
363+ Some ( db. into ( ) ) ,
364+ self . config . imp_user . clone ( ) ,
365+ & [ ] ,
366+ Some ( self . config . fetch_size ) ,
367+ q. into ( ) ,
368+ )
369+ . await
361370 }
362371
363372 /// Executes a query on the provided database and returns a [`DetachedRowStream`]
@@ -372,6 +381,7 @@ impl Graph {
372381 q : impl Into < Query > ,
373382 ) -> Result < DetachedRowStream > {
374383 self . impl_execute_on (
384+ Operation :: Write ,
375385 Some ( db. into ( ) ) ,
376386 self . config . imp_user . clone ( ) ,
377387 & [ ] ,
@@ -384,6 +394,7 @@ impl Graph {
384394 #[ allow( unused_variables) ]
385395 pub ( crate ) async fn impl_execute_on (
386396 & self ,
397+ operation : Operation ,
387398 db : Option < Database > ,
388399 imp_user : Option < ImpersonateUser > ,
389400 bookmarks : & [ String ] ,
@@ -393,7 +404,7 @@ impl Graph {
393404 let query = query. into_retryable (
394405 db,
395406 imp_user,
396- Operation :: Read ,
407+ operation ,
397408 & self . pool ,
398409 fetch_size. or ( Some ( self . config . fetch_size ) ) ,
399410 bookmarks,
@@ -439,7 +450,7 @@ impl Graph {
439450 . config
440451 . db
441452 . clone ( )
442- . map_or ( Ok ( Some ( "" . into ( ) ) ) , |db| Ok ( Some ( db. into ( ) ) ) ) ,
453+ . map_or ( Ok ( Some ( "" . into ( ) ) ) , |db| Ok ( Some ( db) ) ) ,
443454 }
444455 }
445456}
0 commit comments