Skip to content

Commit

Permalink
change cluster_up bool to check state instead
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonHartley committed Feb 5, 2024
1 parent 65d768e commit d403725
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions coerce/src/remote/cluster/singleton/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ impl<A: Actor> State<A> {
matches!(self, Self::Running { .. } | Self::Starting { .. })
}

pub fn is_joining(&self) -> bool {
matches!(self, Self::Joining { .. })
}

pub fn get_actor(&self) -> Option<LocalActorRef<A>> {
match &self {
Self::Running { actor_ref } | Self::Stopping { actor_ref, .. } => {
Expand Down Expand Up @@ -311,11 +315,9 @@ impl<F: SingletonFactory> Handler<Receive<SystemTopic>> for Manager<F> {
}

ClusterEvent::LeaderChanged(leader) => {
if !self.cluster_up {
return;
if !self.state.is_joining() {
self.on_leader_changed(*leader, ctx).await;
}

self.on_leader_changed(*leader, ctx).await;
}

ClusterEvent::NodeAdded(node) => {
Expand All @@ -336,7 +338,7 @@ impl<F: SingletonFactory> Handler<Receive<SystemTopic>> for Manager<F> {
ClusterEvent::NodeRemoved(node) => {
self.managers.remove(&node.id);

if self.cluster_up {
if !self.state.is_joining() {
if let State::Starting { acknowledged_nodes } = &mut self.state {
acknowledged_nodes.remove(&node.id);

Expand Down
2 changes: 1 addition & 1 deletion coerce/src/remote/cluster/singleton/manager/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<F: SingletonFactory> Handler<GetStatus> for Manager<F> {
);

let singleton_state = match &self.state {
State::Joining {..} => SingletonState::Joining,
State::Joining { .. } => SingletonState::Joining,
State::Idle => SingletonState::Idle,
State::Starting { .. } => SingletonState::Starting,
State::Running { .. } => SingletonState::Running,
Expand Down

0 comments on commit d403725

Please sign in to comment.