(self: Arc<Self>, mut shutdown_rx: watch::Receiver<bool>)
| 876 | } |
| 877 | |
| 878 | async fn lease_coordinator(self: Arc<Self>, mut shutdown_rx: watch::Receiver<bool>) { |
| 879 | use lease::{LEASE_ACQUIRE_INTERVAL, LEASE_TTL, ReconcilerLease}; |
| 880 | |
| 881 | let lease = ReconcilerLease::new(self.store.clone(), self.replica_id.clone(), LEASE_TTL); |
| 882 | info!(replica = %lease.replica_id(), "reconciler lease coordinator started"); |
| 883 | |
| 884 | loop { |
| 885 | if *shutdown_rx.borrow() { |
| 886 | break; |
| 887 | } |
| 888 | |
| 889 | match lease.acquire_or_steal().await { |
| 890 | Ok(guard) => { |
| 891 | info!(replica = %lease.replica_id(), "acquired reconciler lease"); |
| 892 | self.run_as_holder(&lease, guard, &mut shutdown_rx).await; |
| 893 | } |
| 894 | Err(e) => { |
| 895 | debug!( |
| 896 | replica = %lease.replica_id(), |
| 897 | error = %e, |
| 898 | "reconciler lease acquisition attempt failed" |
| 899 | ); |
| 900 | tokio::select! { |
| 901 | () = tokio::time::sleep(LEASE_ACQUIRE_INTERVAL) => {} |
| 902 | _ = shutdown_rx.changed() => { |
| 903 | if *shutdown_rx.borrow() { |
| 904 | break; |
| 905 | } |
| 906 | } |
| 907 | } |
| 908 | } |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | info!(replica = %lease.replica_id(), "reconciler lease coordinator stopped"); |
| 913 | } |
| 914 | |
| 915 | async fn run_as_holder( |
| 916 | self: &Arc<Self>, |
no test coverage detected