MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / consumer_loop

Function consumer_loop

nodedb/src/event/consumer.rs:122–354  ·  view source on GitHub ↗

The main consumer loop.

(config: ConsumerConfig, metrics: Arc<CoreMetrics>)

Source from the content-addressed store, hash-verified

120
121/// The main consumer loop.
122async fn consumer_loop(config: ConsumerConfig, metrics: Arc<CoreMetrics>) {
123 let ConsumerConfig {
124 mut rx,
125 mut shutdown,
126 wal,
127 watermark_store,
128 shared_state,
129 trigger_dlq,
130 cdc_router,
131 num_cores,
132 slab_account,
133 } = config;
134
135 let core_id = rx.core_id();
136 let mut mode = ConsumerMode::Normal;
137 let mut last_sequence: u64 = 0;
138 let mut last_lsn = Lsn::ZERO;
139 let mut dirty_watermark = false;
140 let mut last_watermark_flush = tokio::time::Instant::now();
141 let mut retry_queue = TriggerRetryQueue::new();
142 let mut last_retry_poll = tokio::time::Instant::now();
143
144 // Load persisted watermark.
145 match watermark_store.load(core_id) {
146 Ok(lsn) => {
147 last_lsn = lsn;
148 debug!(core_id, lsn = lsn.as_u64(), "loaded watermark");
149 }
150 Err(e) => {
151 warn!(core_id, error = %e, "failed to load watermark, starting from ZERO");
152 }
153 }
154
155 debug!(core_id, "event plane consumer started");
156 let mut wal_retry_count: u32 = 0;
157 let mut empty_polls: u32 = 0;
158
159 loop {
160 if *shutdown.borrow() {
161 if dirty_watermark {
162 flush_watermark(&watermark_store, core_id, last_lsn);
163 }
164 debug!(core_id, "event plane consumer shutting down");
165 break;
166 }
167
168 match mode {
169 ConsumerMode::Normal => {
170 let events = drain_ring_buffer(
171 &mut rx,
172 &metrics,
173 core_id,
174 &mut last_sequence,
175 &mut last_lsn,
176 );
177 let batch_count = events.len();
178
179 if batch_count > 0 {

Callers 1

spawn_consumerFunction · 0.85

Calls 15

nowFunction · 0.85
flush_watermarkFunction · 0.85
drain_ring_bufferFunction · 0.85
process_normal_batchFunction · 0.85
process_retry_queueFunction · 0.85
maybe_flush_watermarkFunction · 0.85
replay_wal_mmapFunction · 0.85
replay_wal_to_eventsFunction · 0.85
record_eventFunction · 0.85
dispatch_eventFunction · 0.85
drain_and_skip_staleFunction · 0.85
borrowMethod · 0.80

Tested by

no test coverage detected