@@ -2,7 +2,11 @@ pub(super) mod server;
2
2
3
3
use std:: {
4
4
collections:: { HashMap , HashSet } ,
5
- sync:: { Arc , Weak } ,
5
+ sync:: {
6
+ atomic:: { AtomicBool , Ordering } ,
7
+ Arc ,
8
+ Weak ,
9
+ } ,
6
10
time:: Duration ,
7
11
} ;
8
12
@@ -47,6 +51,7 @@ pub(crate) struct WeakTopology {
47
51
/// manager and the client options.
48
52
#[ derive( Clone , Debug ) ]
49
53
struct Common {
54
+ is_alive : Arc < AtomicBool > ,
50
55
message_manager : TopologyMessageManager ,
51
56
options : ClientOptions ,
52
57
}
@@ -71,6 +76,7 @@ impl Topology {
71
76
let description = TopologyDescription :: new_from_hosts ( hosts. clone ( ) ) ;
72
77
73
78
let common = Common {
79
+ is_alive : Arc :: new ( AtomicBool :: new ( true ) ) ,
74
80
message_manager : TopologyMessageManager :: new ( ) ,
75
81
options : ClientOptions :: new_srv ( ) ,
76
82
} ;
@@ -106,6 +112,7 @@ impl Topology {
106
112
let hosts: Vec < _ > = options. hosts . drain ( ..) . collect ( ) ;
107
113
108
114
let common = Common {
115
+ is_alive : Arc :: new ( AtomicBool :: new ( true ) ) ,
109
116
message_manager : TopologyMessageManager :: new ( ) ,
110
117
options : options. clone ( ) ,
111
118
} ;
@@ -132,6 +139,10 @@ impl Topology {
132
139
Ok ( topology)
133
140
}
134
141
142
+ pub ( crate ) fn mark_closed ( & self ) {
143
+ self . common . is_alive . store ( false , Ordering :: SeqCst ) ;
144
+ }
145
+
135
146
/// Gets the addresses of the servers in the cluster.
136
147
#[ cfg( test) ]
137
148
pub ( super ) async fn servers ( & self ) -> HashSet < StreamAddress > {
@@ -360,6 +371,10 @@ impl WeakTopology {
360
371
} )
361
372
}
362
373
374
+ pub ( crate ) fn is_alive ( & self ) -> bool {
375
+ self . common . is_alive . load ( Ordering :: SeqCst )
376
+ }
377
+
363
378
pub ( crate ) fn client_options ( & self ) -> & ClientOptions {
364
379
& self . common . options
365
380
}
0 commit comments