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

Function run_apply_loop

nodedb/src/control/distributed_applier/apply_loop.rs:98–274  ·  view source on GitHub ↗

Run the background loop that applies committed Raft entries to the local Data Plane. This task reads from the apply channel, deserializes each entry, dispatches the write to the Data Plane via SPSC, and notifies proposers.

(
    mut apply_rx: mpsc::Receiver<ApplyBatch>,
    state: Arc<SharedState>,
    tracker: Arc<ProposeTracker>,
    calvin_read_result_senders: Arc<
        std::sync::Mutex<std::collections::BTreeMap<

Source from the content-addressed store, hash-verified

96/// This task reads from the apply channel, deserializes each entry, dispatches
97/// the write to the Data Plane via SPSC, and notifies proposers.
98pub async fn run_apply_loop(
99 mut apply_rx: mpsc::Receiver<ApplyBatch>,
100 state: Arc<SharedState>,
101 tracker: Arc<ProposeTracker>,
102 calvin_read_result_senders: Arc<
103 std::sync::Mutex<std::collections::BTreeMap<u32, mpsc::Sender<ReadResultEvent>>>,
104 >,
105) {
106 while let Some(batch) = apply_rx.recv().await {
107 for entry in &batch.entries {
108 // Extract idempotency key once at the top so every
109 // tracker.complete on this entry can pass it. Returns 0
110 // for unparseable / pre-key entries; the tracker treats
111 // 0 as "no key" (no mismatch detection).
112 let applied_key = ReplicatedEntry::from_bytes(&entry.data)
113 .map(|e| e.idempotency_key)
114 .unwrap_or(0);
115
116 // ── Array CRDT variants — handled on the Control Plane, bypass Data Plane ──
117 if let Some(replicated) = ReplicatedEntry::from_bytes(&entry.data) {
118 let target_vshard = replicated.vshard_id;
119 match replicated.write {
120 ReplicatedWrite::ArrayOp {
121 ref array,
122 ref op_bytes,
123 ..
124 } => {
125 apply_array_op(
126 &state,
127 &tracker,
128 batch.group_id,
129 entry.index,
130 applied_key,
131 array,
132 op_bytes,
133 )
134 .await;
135 continue;
136 }
137 ReplicatedWrite::ArraySchema {
138 ref array,
139 ref snapshot_payload,
140 schema_hlc_bytes,
141 } => {
142 apply_array_schema(
143 &state,
144 &tracker,
145 batch.group_id,
146 entry.index,
147 applied_key,
148 crate::control::array_sync::raft_apply::ArraySchemaPayload {
149 array,
150 snapshot_payload,
151 schema_hlc_bytes,
152 },
153 );
154 continue;
155 }

Callers

nothing calls this directly

Calls 11

apply_array_opFunction · 0.85
apply_array_schemaFunction · 0.85
from_replicated_entryFunction · 0.85
build_requestFunction · 0.85
dispatch_and_awaitFunction · 0.85
lockMethod · 0.80
try_sendMethod · 0.80
recvMethod · 0.45
completeMethod · 0.45
getMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected