Skip to content

Commit

Permalink
add more fencing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
CAJan93 committed Dec 29, 2022
1 parent 89f02ff commit 671a5dd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/meta/src/rpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use std::net::SocketAddr;
use std::process;
use std::sync::Arc;
use std::time::Duration;

Expand Down Expand Up @@ -153,6 +154,21 @@ pub async fn rpc_serve_with_store<S: MetaStore>(
}
});

// separate fencing logic from the fencing logic introduced in elections.rs
// Will be triggered if leader looses leadership during election re-run
let fencing_leader_rx = leader_rx.clone();
tokio::spawn(async move {
let mut was_leader = false;
loop {
let (_, is_leader) = fencing_leader_rx.borrow().clone();
if was_leader {
tracing::error!("This node lost its leadership. Exiting node");
process::exit(0);
}
was_leader = is_leader;
}
});

let (svc_shutdown_tx, mut svc_shutdown_rx) = WatchChannel(());

let join_handle = tokio::spawn(async move {
Expand Down

0 comments on commit 671a5dd

Please sign in to comment.