cat_gateway/service/utilities/health/
start.rs1use std::sync::atomic::{
4 AtomicBool,
5 Ordering::{Acquire, Relaxed, Release},
6};
7
8use tracing::{debug, info};
9
10static STARTED: AtomicBool = AtomicBool::new(false);
12
13static LIVE_INDEX_DB: AtomicBool = AtomicBool::new(false);
15
16static LIVE_EVENT_DB: AtomicBool = AtomicBool::new(false);
18
19static INITIAL_IMMUTABLE_FOLLOWER_TIP_REACHED: AtomicBool = AtomicBool::new(false);
22
23static INITIAL_LIVE_FOLLOWER_TIP_REACHED: AtomicBool = AtomicBool::new(false);
26
27pub(crate) fn service_has_started() -> bool {
29 STARTED.load(Acquire)
30}
31
32pub(crate) fn set_to_started() {
34 STARTED.store(true, Release);
35}
36
37pub(crate) fn condition_for_started() -> bool {
39 let event_db = event_db_is_live();
40 let index_db = index_db_is_live();
41 let follower =
42 live_follower_has_first_reached_tip() && immutable_follower_has_first_reached_tip();
43 debug!("Checking if service has started. Event DB: {event_db}, Index DB: {index_db}, Follower: {follower}");
44 event_db && index_db && follower
45}
46
47pub(crate) fn event_db_is_live() -> bool {
51 LIVE_EVENT_DB.load(Acquire)
52}
53
54pub(crate) fn set_event_db_liveness(flag: bool) {
56 LIVE_EVENT_DB.store(flag, Release);
57}
58
59pub(crate) fn index_db_is_live() -> bool {
63 LIVE_INDEX_DB.load(Acquire)
64}
65
66pub(crate) fn set_index_db_liveness(flag: bool) {
68 LIVE_INDEX_DB.store(flag, Release);
69}
70
71pub(crate) fn immutable_follower_has_first_reached_tip() -> bool {
75 INITIAL_IMMUTABLE_FOLLOWER_TIP_REACHED.load(Acquire)
76}
77
78pub(crate) fn live_follower_has_first_reached_tip() -> bool {
82 INITIAL_LIVE_FOLLOWER_TIP_REACHED.load(Acquire)
83}
84
85pub(crate) fn set_follower_immutable_first_reached_tip() -> bool {
90 let prev_value = INITIAL_IMMUTABLE_FOLLOWER_TIP_REACHED.swap(true, Relaxed);
91 if !prev_value {
92 info!("Follower has reached IMMUTABLE TIP for the first time");
93 }
94 prev_value
95}
96
97pub(crate) fn set_follower_live_first_reached_tip() -> bool {
102 let prev_value = INITIAL_LIVE_FOLLOWER_TIP_REACHED.swap(true, Relaxed);
103 if !prev_value {
104 info!("Follower has reached LIVE TIP for the first time");
105 }
106 prev_value
107}