Skip to content

Commit

Permalink
Remove separate auto_promote, which is deterministic from up_state
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Nov 1, 2024
1 parent f4d1be9 commit 57097ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
26 changes: 14 additions & 12 deletions upstairs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,23 +548,25 @@ impl DownstairsClient {
///
/// # Panics
/// If `self.client_task` is not `None`, or `self.target_addr` is `None`
pub(crate) fn reinitialize(
&mut self,
up_state: &UpstairsState,
auto_promote: bool,
) {
pub(crate) fn reinitialize(&mut self, up_state: &UpstairsState) {
// Clear this Downstair's repair address, and let the YesItsMe set it.
// This works if this Downstairs is new, reconnecting, or was replaced
// entirely; the repair address could have changed in any of these
// cases.
self.repair_addr = None;
self.needs_replay = false;

if auto_promote {
self.promote_state = Some(PromoteState::Waiting);
} else {
self.promote_state = None;
}
// If the upstairs is already active (or trying to go active), then the
// downstairs should automatically call PromoteToActive when it reaches
// the relevant state.
self.promote_state = match up_state {
UpstairsState::Active | UpstairsState::GoActive(..) => {
Some(PromoteState::Waiting)
}
UpstairsState::Initializing
| UpstairsState::Deactivating { .. } => None,
};

self.negotiation_state = NegotiationState::Start;

let current = &self.state;
Expand Down Expand Up @@ -595,8 +597,8 @@ impl DownstairsClient {

self.connection_id.update();

// Restart with a short delay
self.start_task(true, auto_promote);
// Restart with a short delay, connecting if we're auto-promoting
self.start_task(true, self.promote_state.is_some());
}

/// Sets the `needs_replay` flag
Expand Down
3 changes: 1 addition & 2 deletions upstairs/src/downstairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ impl Downstairs {
pub(crate) fn reinitialize(
&mut self,
client_id: ClientId,
auto_promote: bool,
up_state: &UpstairsState,
) {
// If the IO task stops on its own, then under certain circumstances,
Expand All @@ -522,7 +521,7 @@ impl Downstairs {

// Restart the IO task for that specific client, transitioning to a new
// state.
self.clients[client_id].reinitialize(up_state, auto_promote);
self.clients[client_id].reinitialize(up_state);

for i in ClientId::iter() {
// Clear per-client delay, because we're starting a new session
Expand Down
11 changes: 1 addition & 10 deletions upstairs/src/upstairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2008,17 +2008,8 @@ impl Upstairs {
self.downstairs
.notify_nexus_of_client_task_stopped(client_id, reason);

// If the upstairs is already active (or trying to go active), then the
// downstairs should automatically call PromoteToActive when it reaches
// the relevant state.
let auto_promote = match self.state {
UpstairsState::Active | UpstairsState::GoActive(..) => true,
UpstairsState::Initializing
| UpstairsState::Deactivating { .. } => false,
};

self.downstairs
.reinitialize(client_id, auto_promote, &self.state);
.reinitialize(client_id, &self.state);
}

/// Sets both guest and per-client backpressure
Expand Down

0 comments on commit 57097ed

Please sign in to comment.