Skip to content

Commit 4105133

Browse files
authored
Drop jobs from Offline downstairs. (#1157)
* Drop jobs from Offline downstairs. If we receive a job ACK from an offline downstairs, and that job has already been moved back to New, then discard it as we know the replay will resend it when the downstairs comes back. Added a connection_id field to the Client. Make a ConnectionId type Use the ConnectionId type.
1 parent 43dace9 commit 4105133

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

upstairs/src/client.rs

+27-3
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(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+
115133
/// Per-client data
116134
///
117135
/// This data structure contains client-specific state and manages communication
@@ -195,6 +213,9 @@ pub(crate) struct DownstairsClient {
195213

196214
/// State for startup negotiation
197215
negotiation_state: NegotiationState,
216+
217+
/// Session ID for a clients connection to a downstairs.
218+
connection_id: ConnectionId,
198219
}
199220

200221
impl DownstairsClient {
@@ -231,6 +252,7 @@ impl DownstairsClient {
231252
region_metadata: None,
232253
repair_info: None,
233254
io_state_count: ClientIOStateCount::new(),
255+
connection_id: ConnectionId(0),
234256
}
235257
}
236258

@@ -267,6 +289,7 @@ impl DownstairsClient {
267289
region_metadata: None,
268290
repair_info: None,
269291
io_state_count: ClientIOStateCount::new(),
292+
connection_id: ConnectionId(0),
270293
}
271294
}
272295

@@ -604,6 +627,7 @@ impl DownstairsClient {
604627
self.state = DsState::New;
605628
}
606629

630+
self.connection_id.update();
607631
// Restart with a short delay
608632
self.start_task(true, auto_promote);
609633
}
@@ -2185,13 +2209,13 @@ impl DownstairsClient {
21852209
(self.io_state_count.new + self.io_state_count.in_progress) as usize
21862210
}
21872211

2188-
/// Returns a unique ID for the current connect, or `None`
2212+
/// Returns a unique ID for the current connection, or `None`
21892213
///
21902214
/// This can be used to disambiguate between messages returned from
21912215
/// 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> {
21932217
if self.client_task.client_stop_tx.is_some() {
2194-
Some(self.stats.connected as u64)
2218+
Some(self.connection_id)
21952219
} else {
21962220
None
21972221
}

upstairs/src/deferred.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::sync::Arc;
44

55
use crate::{
6-
upstairs::UpstairsConfig, BlockContext, BlockReq, BlockRes, ClientId,
7-
ImpactedBlocks, Message, SerializedWrite,
6+
client::ConnectionId, upstairs::UpstairsConfig, BlockContext, BlockReq,
7+
BlockRes, ClientId, ImpactedBlocks, Message, SerializedWrite,
88
};
99
use bytes::{Bytes, BytesMut};
1010
use crucible_common::{integrity_hash, CrucibleError, RegionDefinition};
@@ -241,7 +241,7 @@ pub(crate) struct DeferredMessage {
241241
pub client_id: ClientId,
242242

243243
/// See `DeferredRead::connection_id`
244-
pub connection_id: u64,
244+
pub connection_id: ConnectionId,
245245
}
246246

247247
/// Standalone data structure which can perform decryption
@@ -255,7 +255,7 @@ pub(crate) struct DeferredRead {
255255
/// complete after we have disconnected from the client, which would make
256256
/// handling the decrypted value incorrect (because it may have been skipped
257257
/// or re-sent).
258-
pub connection_id: u64,
258+
pub connection_id: ConnectionId,
259259

260260
pub client_id: ClientId,
261261
pub cfg: Arc<UpstairsConfig>,

0 commit comments

Comments
 (0)