@@ -6,9 +6,7 @@ use crate::{
6
6
DsState , EncryptionContext , IOState , IOop , JobId , Message , RawReadResponse ,
7
7
ReconcileIO , ReconcileIOState , RegionDefinitionStatus , RegionMetadata ,
8
8
} ;
9
- use crucible_common:: {
10
- x509:: TLSContext , ExtentId , NegotiationError , VerboseTimeout ,
11
- } ;
9
+ use crucible_common:: { x509:: TLSContext , NegotiationError , VerboseTimeout } ;
12
10
use crucible_protocol:: {
13
11
MessageWriter , ReconciliationId , CRUCIBLE_MESSAGE_VERSION ,
14
12
} ;
@@ -809,29 +807,16 @@ impl DownstairsClient {
809
807
self . state = DsState :: Active ;
810
808
}
811
809
812
- /// Checks whether the given job should be sent
813
- ///
814
- /// Returns an [`EnqueueResult`] indicating how the caller should handle the
815
- /// packet.
810
+ /// Applies an [`EnqueueResult`] for the given job
816
811
///
817
812
/// If the job should be skipped, then it is added to `self.skipped_jobs`.
818
813
/// `self.io_state_job_count` is updated with the incoming job state.
819
- #[ must_use]
820
- pub ( crate ) fn enqueue (
814
+ pub ( crate ) fn apply_enqueue_result (
821
815
& mut self ,
822
816
ds_id : JobId ,
823
817
io : & IOop ,
824
- last_repair_extent : Option < ExtentId > ,
825
- ) -> EnqueueResult {
826
- // If a downstairs is faulted or ready for repair, we can move
827
- // that job directly to IOState::Skipped
828
- // If a downstairs is in repair, then we need to see if this
829
- // IO is on a repaired extent or not. If an IO spans extents
830
- // where some are repaired and some are not, then this IO had
831
- // better have the dependencies already set to reflect the
832
- // requirement that a repair IO will need to finish first.
833
- let should_send = self . should_send ( io, last_repair_extent) ;
834
-
818
+ should_send : EnqueueResult ,
819
+ ) {
835
820
// Update our set of skipped jobs if we're not sending this one
836
821
if matches ! ( should_send, EnqueueResult :: Skip ) {
837
822
self . skipped_jobs . insert ( ds_id) ;
@@ -841,20 +826,11 @@ impl DownstairsClient {
841
826
let state = should_send. state ( ) ;
842
827
self . io_state_job_count [ & state] += 1 ;
843
828
self . io_state_byte_count [ & state] += io. job_bytes ( ) ;
844
-
845
- should_send
846
829
}
847
830
848
- /// Checks whether the given job should be sent or skipped
849
- ///
850
- /// Returns an [`EnqueueResult`] indicating how the caller should handle the
851
- /// packet.
831
+ /// Checks whether the client is accepting IO
852
832
#[ must_use]
853
- fn should_send (
854
- & self ,
855
- io : & IOop ,
856
- last_repair_extent : Option < ExtentId > ,
857
- ) -> EnqueueResult {
833
+ pub fn should_send ( & self ) -> ShouldSendResult {
858
834
match self . state {
859
835
// We never send jobs if we're in certain inactive states
860
836
DsState :: Connecting {
@@ -863,7 +839,7 @@ impl DownstairsClient {
863
839
} if self . cfg . read_only => {
864
840
// Read only upstairs can connect with just a single downstairs
865
841
// ready, we skip jobs on the other downstairs till they connect.
866
- EnqueueResult :: Skip
842
+ ShouldSendResult :: Skip
867
843
}
868
844
DsState :: Connecting {
869
845
mode : ConnectionMode :: Faulted | ConnectionMode :: Replaced ,
@@ -874,34 +850,22 @@ impl DownstairsClient {
874
850
| ClientStopReason :: Disabled
875
851
| ClientStopReason :: Replacing
876
852
| ClientStopReason :: NegotiationFailed ( ..) ,
877
- ) => EnqueueResult :: Skip ,
878
-
879
- // We conditionally send jobs if we're in live-repair, depending on
880
- // the current extent.
881
- DsState :: LiveRepair => {
882
- // Pick the latest repair limit that's relevant for this
883
- // downstairs. This is either the extent under repair (if
884
- // there are no reserved repair jobs), or the last extent
885
- // for which we have reserved a repair job ID; either way, the
886
- // caller has provided it to us.
887
- if io. send_io_live_repair ( last_repair_extent) {
888
- EnqueueResult :: Send
889
- } else {
890
- EnqueueResult :: Skip
891
- }
892
- }
893
-
894
- // Send jobs if the client is active or offline
895
- //
896
- // Sending jobs to an offline client seems counter-intuitive, but it
897
- // means that those jobs are marked as InProgress, so they aren't
898
- // cleared out by a subsequent flush (so we'll be able to bring that
899
- // client back into compliance by replaying jobs).
900
- DsState :: Active => EnqueueResult :: Send ,
853
+ ) => ShouldSendResult :: Skip ,
854
+
855
+ // Send jobs if the client is active or in live-repair. The caller
856
+ // is responsible for checking whether live-repair jobs should be
857
+ // skipped, and this happens outside of this function
858
+ DsState :: Active => ShouldSendResult :: Send ,
859
+ DsState :: LiveRepair => ShouldSendResult :: CheckLiveRepair ,
860
+
861
+ // Holding jobs for an offline client means that those jobs are
862
+ // marked as InProgress, so they aren't cleared out by a subsequent
863
+ // flush (so we'll be able to bring that client back into compliance
864
+ // by replaying jobs).
901
865
DsState :: Connecting {
902
866
mode : ConnectionMode :: Offline ,
903
867
..
904
- } => EnqueueResult :: Hold ,
868
+ } => ShouldSendResult :: Hold ,
905
869
906
870
DsState :: Stopping ( ClientStopReason :: Deactivated )
907
871
| DsState :: Connecting {
@@ -2046,6 +2010,7 @@ pub(crate) enum NegotiationResult {
2046
2010
}
2047
2011
2048
2012
/// Result value from [`DownstairsClient::enqueue`]
2013
+ #[ derive( Copy , Clone ) ]
2049
2014
pub ( crate ) enum EnqueueResult {
2050
2015
/// The given job should be marked as in progress and sent
2051
2016
Send ,
@@ -2061,6 +2026,20 @@ pub(crate) enum EnqueueResult {
2061
2026
Skip ,
2062
2027
}
2063
2028
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
+
2039
+ /// The caller should check against our active live-repair extent
2040
+ CheckLiveRepair ,
2041
+ }
2042
+
2064
2043
impl EnqueueResult {
2065
2044
pub ( crate ) fn state ( & self ) -> IOState {
2066
2045
match self {
0 commit comments