@@ -112,6 +112,24 @@ struct ClientTaskHandle {
112
112
client_stop_tx : Option < oneshot:: Sender < ClientStopReason > > ,
113
113
}
114
114
115
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
116
+ pub struct ConnectionId ( pub u64 ) ;
117
+
118
+ impl std:: fmt:: Display for ConnectionId {
119
+ fn fmt (
120
+ & self ,
121
+ f : & mut std:: fmt:: Formatter < ' _ > ,
122
+ ) -> Result < ( ) , std:: fmt:: Error > {
123
+ self . 0 . fmt ( f)
124
+ }
125
+ }
126
+
127
+ impl ConnectionId {
128
+ fn update ( & mut self ) {
129
+ self . 0 += 1 ;
130
+ }
131
+ }
132
+
115
133
/// Per-client data
116
134
///
117
135
/// This data structure contains client-specific state and manages communication
@@ -195,6 +213,9 @@ pub(crate) struct DownstairsClient {
195
213
196
214
/// State for startup negotiation
197
215
negotiation_state : NegotiationState ,
216
+
217
+ /// Session ID for a clients connection to a downstairs.
218
+ connection_id : ConnectionId ,
198
219
}
199
220
200
221
impl DownstairsClient {
@@ -231,6 +252,7 @@ impl DownstairsClient {
231
252
region_metadata : None ,
232
253
repair_info : None ,
233
254
io_state_count : ClientIOStateCount :: new ( ) ,
255
+ connection_id : ConnectionId ( 0 ) ,
234
256
}
235
257
}
236
258
@@ -267,6 +289,7 @@ impl DownstairsClient {
267
289
region_metadata : None ,
268
290
repair_info : None ,
269
291
io_state_count : ClientIOStateCount :: new ( ) ,
292
+ connection_id : ConnectionId ( 0 ) ,
270
293
}
271
294
}
272
295
@@ -604,6 +627,7 @@ impl DownstairsClient {
604
627
self . state = DsState :: New ;
605
628
}
606
629
630
+ self . connection_id . update ( ) ;
607
631
// Restart with a short delay
608
632
self . start_task ( true , auto_promote) ;
609
633
}
@@ -2185,13 +2209,13 @@ impl DownstairsClient {
2185
2209
( self . io_state_count . new + self . io_state_count . in_progress ) as usize
2186
2210
}
2187
2211
2188
- /// Returns a unique ID for the current connect , or `None`
2212
+ /// Returns a unique ID for the current connection , or `None`
2189
2213
///
2190
2214
/// This can be used to disambiguate between messages returned from
2191
2215
/// different connections to the same Downstairs.
2192
- pub ( crate ) fn get_connection_id ( & self ) -> Option < u64 > {
2216
+ pub ( crate ) fn get_connection_id ( & self ) -> Option < ConnectionId > {
2193
2217
if self . client_task . client_stop_tx . is_some ( ) {
2194
- Some ( self . stats . connected as u64 )
2218
+ Some ( self . connection_id )
2195
2219
} else {
2196
2220
None
2197
2221
}
0 commit comments