Skip to content

Commit

Permalink
Separate ClientFaultReason type
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Nov 25, 2024
1 parent 3c2fb04 commit f4efafd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
46 changes: 26 additions & 20 deletions upstairs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,12 @@ impl DownstairsClient {
) {
let new_state = match self.state {
DsState::Active | DsState::Offline
if matches!(reason, ClientStopReason::IneligibleForReplay) =>
if matches!(
reason,
ClientStopReason::Fault(
ClientFaultReason::IneligibleForReplay
)
) =>
{
DsState::Faulted
}
Expand Down Expand Up @@ -1195,10 +1200,10 @@ impl DownstairsClient {
pub(crate) fn fault(
&mut self,
up_state: &UpstairsState,
reason: ClientStopReason,
reason: ClientFaultReason,
) {
self.checked_state_transition(up_state, DsState::Faulted);
self.halt_io_task(reason);
self.halt_io_task(reason.into());
}

/// Finishes an in-progress live repair, setting our state to `Active`
Expand Down Expand Up @@ -2194,36 +2199,37 @@ pub(crate) enum ClientStopReason {
/// Reconcile failed and we're restarting
FailedReconcile,

/// Received an error from some IO
IOError,

/// Negotiation message received out of order
BadNegotiationOrder,

/// Negotiation says that we are incompatible
Incompatible,

/// Live-repair failed
FailedLiveRepair,
/// The upstairs has requested that we deactivate
Deactivated,

/// Too many jobs in the queue
TooManyOutstandingJobs,
/// We have explicitly faulted the client
Fault(ClientFaultReason),
}

/// Too many bytes in the queue
/// Subset of [`ClientStopReason`] for faulting a client
#[derive(Debug)]
pub(crate) enum ClientFaultReason {
IOError,
FailedLiveRepair,
TooManyOutstandingJobs,
TooManyOutstandingBytes,
OfflineDeactivated,
IneligibleForReplay,

/// The upstairs has requested that we deactivate
Deactivated,

/// The test suite has requested a fault
#[cfg(test)]
RequestedFault,
}

/// The upstairs has requested that we deactivate when we were offline
OfflineDeactivated,

/// The Upstairs has dropped jobs that would be needed for replay
IneligibleForReplay,
impl From<ClientFaultReason> for ClientStopReason {
fn from(f: ClientFaultReason) -> ClientStopReason {
ClientStopReason::Fault(f)
}
}

/// Response received from the I/O task
Expand Down
27 changes: 15 additions & 12 deletions upstairs/src/downstairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use std::{

use crate::{
cdt,
client::{ClientAction, ClientStopReason, DownstairsClient, EnqueueResult},
client::{
ClientAction, ClientFaultReason, ClientStopReason, DownstairsClient,
EnqueueResult,
},
guest::GuestBlockRes,
io_limits::{IOLimitGuard, IOLimits},
live_repair::ExtentInfo,
Expand Down Expand Up @@ -724,7 +727,7 @@ impl Downstairs {
self.fault_client(
client_id,
up_state,
ClientStopReason::OfflineDeactivated,
ClientFaultReason::OfflineDeactivated,
);
return false;
}
Expand Down Expand Up @@ -2621,20 +2624,20 @@ impl Downstairs {
self.log,
"downstairs failed, too many outstanding jobs {work_count}"
);
Some(ClientStopReason::TooManyOutstandingJobs)
Some(ClientFaultReason::TooManyOutstandingJobs)
} else if byte_count as u64 > crate::IO_OUTSTANDING_MAX_BYTES {
warn!(
self.log,
"downstairs failed, too many outstanding bytes {byte_count}"
);
Some(ClientStopReason::TooManyOutstandingBytes)
Some(ClientFaultReason::TooManyOutstandingBytes)
} else if !self.can_replay {
// XXX can this actually happen?
warn!(
self.log,
"downstairs became ineligible for replay while offline"
);
Some(ClientStopReason::IneligibleForReplay)
Some(ClientFaultReason::IneligibleForReplay)
} else {
None
};
Expand All @@ -2649,7 +2652,7 @@ impl Downstairs {
&mut self,
client_id: ClientId,
up_state: &UpstairsState,
err: ClientStopReason,
err: ClientFaultReason,
) {
self.skip_all_jobs(client_id);
self.clients[client_id].fault(up_state, err);
Expand Down Expand Up @@ -2713,7 +2716,7 @@ impl Downstairs {
self.fault_client(
i,
up_state,
ClientStopReason::FailedLiveRepair,
ClientFaultReason::FailedLiveRepair,
);
}
DsState::LiveRepairReady => {
Expand Down Expand Up @@ -3385,7 +3388,7 @@ impl Downstairs {
self.fault_client(
client_id,
up_state,
ClientStopReason::IOError,
ClientFaultReason::IOError,
);
}
}
Expand Down Expand Up @@ -4331,7 +4334,7 @@ struct DownstairsBackpressureConfig {

#[cfg(test)]
pub(crate) mod test {
use super::{ClientStopReason, Downstairs, PendingJob};
use super::{ClientFaultReason, Downstairs, PendingJob};
use crate::{
downstairs::{LiveRepairData, LiveRepairState, ReconcileData},
live_repair::ExtentInfo,
Expand Down Expand Up @@ -9616,7 +9619,7 @@ pub(crate) mod test {
ds.fault_client(
to_repair,
&UpstairsState::Active,
ClientStopReason::RequestedFault,
ClientFaultReason::RequestedFault,
);
ds.clients[to_repair].checked_state_transition(
&UpstairsState::Active,
Expand Down Expand Up @@ -9785,7 +9788,7 @@ pub(crate) mod test {
ds.fault_client(
to_repair,
&UpstairsState::Active,
ClientStopReason::RequestedFault,
ClientFaultReason::RequestedFault,
);
ds.clients[to_repair].checked_state_transition(
&UpstairsState::Active,
Expand Down Expand Up @@ -9941,7 +9944,7 @@ pub(crate) mod test {
ds.fault_client(
to_repair,
&UpstairsState::Active,
ClientStopReason::RequestedFault,
ClientFaultReason::RequestedFault,
);
ds.clients[to_repair].checked_state_transition(
&UpstairsState::Active,
Expand Down
2 changes: 1 addition & 1 deletion upstairs/src/upstairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ impl Upstairs {
self.downstairs.fault_client(
client_id,
&self.state,
crate::client::ClientStopReason::RequestedFault,
crate::client::ClientFaultReason::RequestedFault,
);
done.send_ok(());
}
Expand Down

0 comments on commit f4efafd

Please sign in to comment.