@@ -2,7 +2,11 @@ pub(super) mod server;
22
33use std:: {
44 collections:: { HashMap , HashSet } ,
5- sync:: { Arc , Weak } ,
5+ sync:: {
6+ atomic:: { AtomicBool , Ordering } ,
7+ Arc ,
8+ Weak ,
9+ } ,
610 time:: Duration ,
711} ;
812
@@ -47,6 +51,7 @@ pub(crate) struct WeakTopology {
4751/// manager and the client options.
4852#[ derive( Clone , Debug ) ]
4953struct Common {
54+ is_alive : Arc < AtomicBool > ,
5055 message_manager : TopologyMessageManager ,
5156 options : ClientOptions ,
5257}
@@ -71,6 +76,7 @@ impl Topology {
7176 let description = TopologyDescription :: new_from_hosts ( hosts. clone ( ) ) ;
7277
7378 let common = Common {
79+ is_alive : Arc :: new ( AtomicBool :: new ( true ) ) ,
7480 message_manager : TopologyMessageManager :: new ( ) ,
7581 options : ClientOptions :: new_srv ( ) ,
7682 } ;
@@ -106,6 +112,7 @@ impl Topology {
106112 let hosts: Vec < _ > = options. hosts . drain ( ..) . collect ( ) ;
107113
108114 let common = Common {
115+ is_alive : Arc :: new ( AtomicBool :: new ( true ) ) ,
109116 message_manager : TopologyMessageManager :: new ( ) ,
110117 options : options. clone ( ) ,
111118 } ;
@@ -132,6 +139,10 @@ impl Topology {
132139 Ok ( topology)
133140 }
134141
142+ pub ( crate ) fn mark_closed ( & self ) {
143+ self . common . is_alive . store ( false , Ordering :: SeqCst ) ;
144+ }
145+
135146 /// Gets the addresses of the servers in the cluster.
136147 #[ cfg( test) ]
137148 pub ( super ) async fn servers ( & self ) -> HashSet < StreamAddress > {
@@ -360,6 +371,10 @@ impl WeakTopology {
360371 } )
361372 }
362373
374+ pub ( crate ) fn is_alive ( & self ) -> bool {
375+ self . common . is_alive . load ( Ordering :: SeqCst )
376+ }
377+
363378 pub ( crate ) fn client_options ( & self ) -> & ClientOptions {
364379 & self . common . options
365380 }
0 commit comments