• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

getdozer / dozer / 3974477999

pending completion
3974477999

push

github

GitHub
fix: forbid duplicated cte names (#703)

27 of 27 new or added lines in 1 file covered. (100.0%)

22032 of 33231 relevant lines covered (66.3%)

42438.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/dozer-core/src/dag/executor/source_node.rs
1
use std::{
2
    collections::HashMap,
3
    path::Path,
4
    sync::{
5
        atomic::{AtomicBool, Ordering},
6
        Arc,
7
    },
8
    time::Duration,
9
};
10

11
use crossbeam::channel::{Receiver, RecvTimeoutError, Sender};
12
use dozer_types::log::debug;
13
use dozer_types::{
14
    internal_err,
15
    parking_lot::RwLock,
16
    types::{Operation, Schema},
17
};
18

19
use crate::dag::{
20
    channels::SourceChannelForwarder,
21
    dag::Edge,
22
    epoch::EpochManager,
23
    errors::ExecutionError::{self, InternalError},
24
    executor_utils::{create_ports_databases_and_fill_downstream_record_readers, init_component},
25
    forwarder::{SourceChannelManager, StateWriter},
26
    node::{NodeHandle, OutputPortDef, PortHandle, Source, SourceFactory},
27
    record_store::RecordReader,
28
};
29

30
use super::{node::Node, ExecutorOperation};
31

32
#[derive(Debug)]
×
33
struct InternalChannelSourceForwarder {
34
    sender: Sender<(PortHandle, u64, u64, Operation)>,
35
}
36

37
impl InternalChannelSourceForwarder {
38
    pub fn new(sender: Sender<(PortHandle, u64, u64, Operation)>) -> Self {
187✔
39
        Self { sender }
187✔
40
    }
187✔
41
}
42

43
impl SourceChannelForwarder for InternalChannelSourceForwarder {
44
    fn send(
3,517,918✔
45
        &mut self,
3,517,918✔
46
        txid: u64,
3,517,918✔
47
        seq_in_tx: u64,
3,517,918✔
48
        op: Operation,
3,517,918✔
49
        port: PortHandle,
3,517,918✔
50
    ) -> Result<(), ExecutionError> {
3,517,918✔
51
        internal_err!(self.sender.send((port, txid, seq_in_tx, op)))
10✔
52
    }
3,517,918✔
53
}
54

55
/// The sender half of a source in the execution DAG.
56
#[derive(Debug)]
×
57
pub struct SourceSenderNode {
58
    /// Node handle in description DAG.
59
    node_handle: NodeHandle,
60
    /// The source.
61
    source: Box<dyn Source>,
62
    /// Last checkpointed output data sequence number.
63
    last_checkpoint: (u64, u64),
64
    /// The forwarder that will be passed to the source for outputig data.
65
    forwarder: InternalChannelSourceForwarder,
66
    /// If the execution DAG should be running. Used for terminating the execution DAG.
67
    running: Arc<AtomicBool>,
68
}
69

70
impl SourceSenderNode {
71
    /// # Arguments
72
    ///
73
    /// - `node_handle`: Node handle in description DAG.
74
    /// - `source_factory`: Source factory in description DAG.
75
    /// - `output_schemas`: Output data schemas.
76
    /// - `last_checkpoint`: Last checkpointed output of this source.
77
    /// - `sender`: Channel to send data to.
78
    /// - `running`: If the execution DAG should still be running.
79
    pub fn new(
189✔
80
        node_handle: NodeHandle,
189✔
81
        source_factory: &dyn SourceFactory,
189✔
82
        output_schemas: HashMap<PortHandle, Schema>,
189✔
83
        last_checkpoint: (u64, u64),
189✔
84
        sender: Sender<(PortHandle, u64, u64, Operation)>,
189✔
85
        running: Arc<AtomicBool>,
189✔
86
    ) -> Result<Self, ExecutionError> {
189✔
87
        let source = source_factory.build(output_schemas)?;
189✔
88
        let forwarder = InternalChannelSourceForwarder::new(sender);
188✔
89
        Ok(Self {
188✔
90
            node_handle,
188✔
91
            source,
188✔
92
            last_checkpoint,
188✔
93
            forwarder,
188✔
94
            running,
188✔
95
        })
188✔
96
    }
189✔
97
}
98

99
impl Node for SourceSenderNode {
100
    fn run(mut self) -> Result<(), ExecutionError> {
187✔
101
        let result = self
187✔
102
            .source
187✔
103
            .start(&mut self.forwarder, Some(self.last_checkpoint));
187✔
104
        self.running.store(false, Ordering::SeqCst);
187✔
105
        debug!("[{}-sender] Quit", self.node_handle);
187✔
106
        result
187✔
107
    }
187✔
108
}
109

110
/// The listener part of a source in the execution DAG.
111
#[derive(Debug)]
×
112
pub struct SourceListenerNode {
113
    /// Node handle in description DAG.
114
    node_handle: NodeHandle,
115
    /// Output from corresponding source sender.
116
    receiver: Receiver<(PortHandle, u64, u64, Operation)>,
117
    /// Receiving timeout.
118
    timeout: Duration,
119
    /// If the execution DAG should be running. Used for determining if a `terminate` message should be sent.
120
    running: Arc<AtomicBool>,
121
    /// This node's output channel manager, for communicating to other sources to coordinate terminate and commit, forwarding data, writing metadata and writing port state.
122
    channel_manager: SourceChannelManager,
123
}
124

125
impl SourceListenerNode {
126
    /// # Arguments
127
    ///
128
    /// - `node_handle`: Node handle in description DAG.
129
    /// - `receiver`: Channel that the data comes in.
130
    /// - `timeout`: `Listener timeout. After this timeout, listener will check if commit or terminate need to happen.
131
    /// - `base_path`: Base path of persisted data for the last execution of the description DAG.
132
    /// - `output_ports`: Output port definition of the source in description DAG.
133
    /// - `record_readers`: Record readers of all stateful ports.
134
    /// - `senders`: Output channels from this processor.
135
    /// - `edges`: All edges in the description DAG, used for creating record readers for input ports which is connected to this processor's stateful output ports.
136
    /// - `running`: If the execution DAG should still be running.
137
    /// - `epoch_manager`: Used for coordinating commit and terminate between sources. Shared by all sources.
138
    /// - `output_schemas`: Output data schemas.
139
    #[allow(clippy::too_many_arguments)]
140
    pub(crate) fn new(
189✔
141
        node_handle: NodeHandle,
189✔
142
        receiver: Receiver<(PortHandle, u64, u64, Operation)>,
189✔
143
        timeout: Duration,
189✔
144
        base_path: &Path,
189✔
145
        output_ports: &[OutputPortDef],
189✔
146
        record_readers: Arc<
189✔
147
            RwLock<HashMap<NodeHandle, HashMap<PortHandle, Box<dyn RecordReader>>>>,
189✔
148
        >,
189✔
149
        senders: HashMap<PortHandle, Vec<Sender<ExecutorOperation>>>,
189✔
150
        edges: &[Edge],
189✔
151
        running: Arc<AtomicBool>,
189✔
152
        commit_sz: u32,
189✔
153
        max_duration_between_commits: Duration,
189✔
154
        epoch_manager: Arc<EpochManager>,
189✔
155
        output_schemas: HashMap<PortHandle, Schema>,
189✔
156
        start_seq: (u64, u64),
189✔
157
    ) -> Result<Self, ExecutionError> {
189✔
158
        let state_meta = init_component(&node_handle, base_path, |_| Ok(()))?;
189✔
159
        let (master_tx, port_databases) =
188✔
160
            create_ports_databases_and_fill_downstream_record_readers(
188✔
161
                &node_handle,
188✔
162
                edges,
188✔
163
                state_meta.env,
188✔
164
                output_ports,
188✔
165
                &mut record_readers.write(),
188✔
166
            )?;
188✔
167
        let channel_manager = SourceChannelManager::new(
188✔
168
            node_handle.clone(),
188✔
169
            senders,
188✔
170
            StateWriter::new(
188✔
171
                state_meta.meta_db,
188✔
172
                port_databases,
188✔
173
                master_tx,
188✔
174
                output_schemas,
188✔
175
            )?,
188✔
176
            true,
×
177
            commit_sz,
188✔
178
            max_duration_between_commits,
188✔
179
            epoch_manager,
188✔
180
            start_seq,
188✔
181
        );
188✔
182
        Ok(Self {
188✔
183
            node_handle,
188✔
184
            receiver,
188✔
185
            timeout,
188✔
186
            running,
188✔
187
            channel_manager,
188✔
188
        })
188✔
189
    }
189✔
190
}
191

192
impl SourceListenerNode {
×
193
    /// Returns if the node should terminate.
×
194
    fn send_and_trigger_commit_if_needed(
3,521,282✔
195
        &mut self,
3,521,282✔
196
        data: Option<(PortHandle, u64, u64, Operation)>,
3,521,282✔
197
    ) -> Result<bool, ExecutionError> {
3,521,282✔
198
        // First check if termination was requested.
3,521,282✔
199
        let terminating = !self.running.load(Ordering::SeqCst);
3,521,282✔
200
        // If this commit was not requested with termination at the start, we shouldn't terminate either.
×
201
        let terminating = match data {
3,521,282✔
202
            Some((port, txid, seq_in_tx, op)) => self
3,517,652✔
203
                .channel_manager
3,517,652✔
204
                .send_and_trigger_commit_if_needed(txid, seq_in_tx, op, port, terminating)?,
3,517,652✔
205
            None => self.channel_manager.trigger_commit_if_needed(terminating)?,
3,630✔
206
        };
×
207
        if terminating {
3,521,275✔
208
            self.channel_manager.terminate()?;
419✔
209
            debug!("[{}-listener] Quitting", &self.node_handle);
419✔
210
        }
3,520,856✔
211
        Ok(terminating)
3,521,035✔
212
    }
3,521,042✔
213
}
214

×
215
impl Node for SourceListenerNode {
×
216
    fn run(mut self) -> Result<(), ExecutionError> {
188✔
217
        loop {
3,521,019✔
218
            match self.receiver.recv_timeout(self.timeout) {
3,521,019✔
219
                Ok(data) => {
3,517,427✔
220
                    if self.send_and_trigger_commit_if_needed(Some(data))? {
3,517,427✔
221
                        return Ok(());
8✔
222
                    }
3,517,412✔
223
                }
×
224
                Err(e) => {
3,592✔
225
                    if self.send_and_trigger_commit_if_needed(None)? {
3,592✔
226
                        return Ok(());
171✔
227
                    }
3,421✔
228
                    // Channel disconnected but running flag not set to false, the source sender must have panicked.
3,421✔
229
                    if self.running.load(Ordering::SeqCst) && e == RecvTimeoutError::Disconnected {
3,421✔
230
                        return Err(ExecutionError::ChannelDisconnected);
2✔
231
                    }
3,419✔
232
                }
233
            }
×
234
        }
235
    }
188✔
236
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc