Skip to content

Commit 0eb7ca8

Browse files
committed
Better return semantics from should_send
1 parent 8f21faf commit 0eb7ca8

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

upstairs/src/client.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,7 @@ impl DownstairsClient {
829829
}
830830

831831
/// Checks whether the client is accepting IO
832-
#[must_use]
833-
pub fn should_send(&self) -> ShouldSendResult {
832+
pub fn should_send(&self) -> Result<EnqueueResult, ShouldSendError> {
834833
match self.state {
835834
// We never send jobs if we're in certain inactive states
836835
DsState::Connecting {
@@ -839,7 +838,7 @@ impl DownstairsClient {
839838
} if self.cfg.read_only => {
840839
// Read only upstairs can connect with just a single downstairs
841840
// ready, we skip jobs on the other downstairs till they connect.
842-
ShouldSendResult::Skip
841+
Ok(EnqueueResult::Skip)
843842
}
844843
DsState::Connecting {
845844
mode: ConnectionMode::Faulted | ConnectionMode::Replaced,
@@ -850,13 +849,13 @@ impl DownstairsClient {
850849
| ClientStopReason::Disabled
851850
| ClientStopReason::Replacing
852851
| ClientStopReason::NegotiationFailed(..),
853-
) => ShouldSendResult::Skip,
852+
) => Ok(EnqueueResult::Skip),
854853

855854
// Send jobs if the client is active or in live-repair. The caller
856855
// is responsible for checking whether live-repair jobs should be
857856
// skipped, and this happens outside of this function
858-
DsState::Active => ShouldSendResult::Send,
859-
DsState::LiveRepair => ShouldSendResult::CheckLiveRepair,
857+
DsState::Active => Ok(EnqueueResult::Send),
858+
DsState::LiveRepair => Err(ShouldSendError::InLiveRepair),
860859

861860
// Holding jobs for an offline client means that those jobs are
862861
// marked as InProgress, so they aren't cleared out by a subsequent
@@ -865,7 +864,7 @@ impl DownstairsClient {
865864
DsState::Connecting {
866865
mode: ConnectionMode::Offline,
867866
..
868-
} => ShouldSendResult::Hold,
867+
} => Ok(EnqueueResult::Hold),
869868

870869
DsState::Stopping(ClientStopReason::Deactivated)
871870
| DsState::Connecting {
@@ -2009,7 +2008,7 @@ pub(crate) enum NegotiationResult {
20092008
LiveRepair,
20102009
}
20112010

2012-
/// Result value from [`DownstairsClient::enqueue`]
2011+
/// Success value from [`DownstairsClient::should_send`]
20132012
#[derive(Copy, Clone)]
20142013
pub(crate) enum EnqueueResult {
20152014
/// The given job should be marked as in progress and sent
@@ -2026,18 +2025,11 @@ pub(crate) enum EnqueueResult {
20262025
Skip,
20272026
}
20282027

2029-
/// Result value from [`DownstairsClient::should_send`]
2030-
///
2031-
/// This is a superset of [`EnqueueResult`], which includes a value indicating
2032-
/// that the client is in live-repair and the caller should figure it out based
2033-
/// on the last active live-repair extent.
2034-
pub(crate) enum ShouldSendResult {
2035-
Send,
2036-
Hold,
2037-
Skip,
2038-
2028+
/// Error result from [`DownstairsClient::should_send`]
2029+
#[derive(Copy, Clone)]
2030+
pub(crate) enum ShouldSendError {
20392031
/// The caller should check against our active live-repair extent
2040-
CheckLiveRepair,
2032+
InLiveRepair,
20412033
}
20422034

20432035
impl EnqueueResult {

upstairs/src/downstairs.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
client::{
1212
ClientAction, ClientFaultReason, ClientNegotiationFailed,
1313
ClientRunResult, ClientStopReason, DownstairsClient, EnqueueResult,
14-
NegotiationState, ShouldSendResult,
14+
NegotiationState, ShouldSendError,
1515
},
1616
guest::GuestBlockRes,
1717
io_limits::{IOLimitGuard, IOLimits},
@@ -2288,14 +2288,9 @@ impl Downstairs {
22882288
// Send the job to each client!
22892289
let state = ClientData::from_fn(|cid| {
22902290
let client = &mut self.clients[cid];
2291-
// should_send -> ShouldSendResult
2292-
// (Send, Hold, Skip, CheckLiveRepair)
2293-
// then convert from that into EnqueueResult and apply it
22942291
let r = match client.should_send() {
2295-
ShouldSendResult::Send => EnqueueResult::Send,
2296-
ShouldSendResult::Hold => EnqueueResult::Hold,
2297-
ShouldSendResult::Skip => EnqueueResult::Skip,
2298-
ShouldSendResult::CheckLiveRepair => {
2292+
Ok(r) => r,
2293+
Err(ShouldSendError::InLiveRepair) => {
22992294
if io.send_io_live_repair(last_repair_extent) {
23002295
EnqueueResult::Send
23012296
} else {

0 commit comments

Comments
 (0)