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_is_live = event_db_is_live();
40 let index_db_is_live = index_db_is_live();
41 let follower_is_live =
42 live_follower_has_first_reached_tip() && immutable_follower_has_first_reached_tip();
43 debug!(
44 event_db_is_live,
45 index_db_is_live, follower_is_live, "Checking if service has started."
46 );
47 event_db_is_live && index_db_is_live && follower_is_live
48}
49
50pub(crate) fn event_db_is_live() -> bool {
54 LIVE_EVENT_DB.load(Acquire)
55}
56
57pub(crate) fn set_event_db_liveness(flag: bool) {
59 LIVE_EVENT_DB.store(flag, Release);
60}
61
62pub(crate) fn index_db_is_live() -> bool {
66 LIVE_INDEX_DB.load(Acquire)
67}
68
69pub(crate) fn set_index_db_liveness(flag: bool) {
71 LIVE_INDEX_DB.store(flag, Release);
72}
73
74pub(crate) fn immutable_follower_has_first_reached_tip() -> bool {
78 INITIAL_IMMUTABLE_FOLLOWER_TIP_REACHED.load(Acquire)
79}
80
81pub(crate) fn live_follower_has_first_reached_tip() -> bool {
85 INITIAL_LIVE_FOLLOWER_TIP_REACHED.load(Acquire)
86}
87
88pub(crate) fn set_follower_immutable_first_reached_tip() -> bool {
93 let prev_value = INITIAL_IMMUTABLE_FOLLOWER_TIP_REACHED.swap(true, Relaxed);
94 if !prev_value {
95 info!("Follower has reached IMMUTABLE TIP for the first time");
96 }
97 prev_value
98}
99
100pub(crate) fn set_follower_live_first_reached_tip() -> bool {
105 let prev_value = INITIAL_LIVE_FOLLOWER_TIP_REACHED.swap(true, Relaxed);
106 if !prev_value {
107 info!("Follower has reached LIVE TIP for the first time");
108 }
109 prev_value
110}