Skip to content

Commit 651b31c

Browse files
committed
Make a ConnectionId type
1 parent 0aa573e commit 651b31c

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

upstairs/src/client.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ struct ClientTaskHandle {
112112
client_stop_tx: Option<oneshot::Sender<ClientStopReason>>,
113113
}
114114

115+
#[derive(Debug)]
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+
115133
/// Per-client data
116134
///
117135
/// This data structure contains client-specific state and manages communication
@@ -197,7 +215,7 @@ pub(crate) struct DownstairsClient {
197215
negotiation_state: NegotiationState,
198216

199217
/// Session ID for a clients connection to a downstairs.
200-
connection_id: usize,
218+
connection_id: ConnectionId,
201219
}
202220

203221
impl DownstairsClient {
@@ -234,7 +252,7 @@ impl DownstairsClient {
234252
region_metadata: None,
235253
repair_info: None,
236254
io_state_count: ClientIOStateCount::new(),
237-
connection_id: 0,
255+
connection_id: ConnectionId(0),
238256
}
239257
}
240258

@@ -271,7 +289,7 @@ impl DownstairsClient {
271289
region_metadata: None,
272290
repair_info: None,
273291
io_state_count: ClientIOStateCount::new(),
274-
connection_id: 0,
292+
connection_id: ConnectionId(0),
275293
}
276294
}
277295

@@ -609,7 +627,7 @@ impl DownstairsClient {
609627
self.state = DsState::New;
610628
}
611629

612-
self.connection_id += 1;
630+
self.connection_id.update();
613631
// Restart with a short delay
614632
self.start_task(true, auto_promote);
615633
}
@@ -2197,7 +2215,7 @@ impl DownstairsClient {
21972215
/// different connections to the same Downstairs.
21982216
pub(crate) fn get_connection_id(&self) -> Option<u64> {
21992217
if self.client_task.client_stop_tx.is_some() {
2200-
Some(self.connection_id as u64)
2218+
Some(self.connection_id.0)
22012219
} else {
22022220
None
22032221
}

0 commit comments

Comments
 (0)