Skip to content

Commit 21a03f8

Browse files
committed
Split "check reconciliation state" from "start reconciliation"
1 parent 8dfdf95 commit 21a03f8

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

upstairs/src/downstairs.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ impl LiveRepairData {
272272
}
273273
}
274274

275+
#[derive(Debug)]
276+
pub(crate) struct CollateData {
277+
max_flush: u64,
278+
max_gen: u64,
279+
}
280+
275281
#[derive(Debug)]
276282
pub(crate) struct ReconcileData {
277283
/// An ID uniquely identifying this reconciliation
@@ -862,27 +868,15 @@ impl Downstairs {
862868
///
863869
/// Returns `true` if repair is needed, `false` otherwise
864870
pub(crate) fn collate(&mut self) -> Result<bool, NegotiationError> {
865-
let r = self.collate_inner();
866-
if r.is_err() {
867-
// If we failed to begin the repair, then assert that nothing has
868-
// changed and everything is empty.
869-
assert!(self.ds_active.is_empty());
870-
assert!(self.reconcile.is_none());
871-
872-
for c in self.clients.iter() {
873-
assert_eq!(
874-
c.state(),
875-
DsState::Connecting {
876-
state: NegotiationState::WaitQuorum,
877-
mode: ConnectionMode::New
878-
}
879-
);
880-
}
881-
}
882-
r
871+
let r = self.check_region_metadata()?;
872+
Ok(self.start_reconciliation(r))
883873
}
884874

885-
fn collate_inner(&mut self) -> Result<bool, NegotiationError> {
875+
/// Checks that region metadata is valid
876+
///
877+
/// # Panics
878+
/// If no regions are in `NegotiationState::WaitQuorum`
879+
fn check_region_metadata(&self) -> Result<CollateData, NegotiationError> {
886880
/*
887881
* Show some (or all if small) of the info from each region.
888882
*
@@ -961,6 +955,14 @@ impl Downstairs {
961955
);
962956
}
963957

958+
Ok(CollateData { max_flush, max_gen })
959+
}
960+
961+
/// Begins reconciliation, using the given collation data
962+
#[must_use]
963+
fn start_reconciliation(&mut self, data: CollateData) -> bool {
964+
let CollateData { max_flush, max_gen } = data;
965+
964966
/*
965967
* Set the next flush ID so we have if we need to repair.
966968
*/
@@ -995,10 +997,10 @@ impl Downstairs {
995997
self.reconcile = Some(reconcile);
996998
self.reconcile_repaired = 0;
997999

998-
Ok(true)
1000+
true
9991001
} else {
10001002
info!(self.log, "All extents match");
1001-
Ok(false)
1003+
false
10021004
}
10031005
}
10041006

0 commit comments

Comments
 (0)