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

getdozer / dozer / 4315007357

pending completion
4315007357

push

github

GitHub
fix: Sink should only be built after all source checkpoints are checked (#1112)

280 of 280 new or added lines in 24 files covered. (100.0%)

28292 of 38914 relevant lines covered (72.7%)

64132.7 hits per line

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

77.54
/dozer-core/src/executor.rs
1
use crate::builder_dag::{BuilderDag, NodeKind};
2
use crate::dag_metadata::DagMetadata;
3
use crate::dag_schemas::DagSchemas;
4
use crate::errors::ExecutionError;
5
use crate::Dag;
6

7
use daggy::petgraph::visit::IntoNodeIdentifiers;
8
use dozer_types::node::NodeHandle;
9
use dozer_types::types::Operation;
10

11
use crate::epoch::Epoch;
12
use std::collections::hash_map::Entry;
13
use std::collections::HashMap;
14
use std::fmt::Debug;
15
use std::panic::panic_any;
16
use std::path::PathBuf;
17
use std::sync::atomic::AtomicBool;
18
use std::sync::Arc;
19
use std::thread::JoinHandle;
20
use std::thread::{self, Builder};
21
use std::time::Duration;
22

23
#[derive(Clone)]
×
24
pub struct ExecutorOptions {
25
    pub commit_sz: u32,
26
    pub channel_buffer_sz: usize,
27
    pub commit_time_threshold: Duration,
28

29
    pub max_map_size: usize,
30
}
31

32
impl Default for ExecutorOptions {
33
    fn default() -> Self {
330✔
34
        Self {
330✔
35
            commit_sz: 10_000,
330✔
36
            channel_buffer_sz: 20_000,
330✔
37
            commit_time_threshold: Duration::from_millis(50),
330✔
38
            max_map_size: 1024 * 1024 * 1024 * 1024,
330✔
39
        }
330✔
40
    }
330✔
41
}
42

43
#[derive(Clone, Debug, PartialEq, Eq)]
1,661✔
44
pub(crate) enum InputPortState {
45
    Open,
46
    Terminated,
47
}
48

49
#[derive(Clone, Debug, PartialEq, Eq)]
83,248✔
50
pub enum ExecutorOperation {
51
    Op { op: Operation },
52
    Commit { epoch: Epoch },
53
    Terminate,
54
    SnapshottingDone {},
55
}
56

57
mod execution_dag;
58
mod name;
59
mod node;
60
mod processor_node;
61
mod receiver_loop;
62
mod sink_node;
63
mod source_node;
64

65
use node::Node;
66
use processor_node::ProcessorNode;
67
use sink_node::SinkNode;
68

69
use self::execution_dag::ExecutionDag;
70
use self::source_node::{create_source_nodes, SourceListenerNode, SourceSenderNode};
71

72
pub struct DagExecutor {
73
    builder_dag: BuilderDag,
74
    options: ExecutorOptions,
75
}
76

77
pub struct DagExecutorJoinHandle {
78
    join_handles: HashMap<NodeHandle, JoinHandle<()>>,
79
}
80

81
impl DagExecutor {
×
82
    pub fn new<T: Clone + Debug>(
223✔
83
        dag: Dag<T>,
223✔
84
        path: PathBuf,
223✔
85
        options: ExecutorOptions,
223✔
86
    ) -> Result<Self, ExecutionError> {
223✔
87
        let dag_schemas = DagSchemas::new(dag)?;
223✔
88
        let builder_dag = BuilderDag::new(dag_schemas, path, options.max_map_size)?;
223✔
89

×
90
        Ok(Self {
219✔
91
            builder_dag,
219✔
92
            options,
219✔
93
        })
219✔
94
    }
221✔
95

×
96
    pub fn validate<T: Clone + Debug>(dag: Dag<T>, path: PathBuf) -> Result<(), ExecutionError> {
8✔
97
        let dag_schemas = DagSchemas::new(dag)?;
8✔
98
        DagMetadata::new(dag_schemas, path)?;
8✔
99
        Ok(())
8✔
100
    }
8✔
101

×
102
    pub fn start(self, running: Arc<AtomicBool>) -> Result<DagExecutorJoinHandle, ExecutionError> {
332✔
103
        // Construct execution dag.
×
104
        let mut execution_dag =
332✔
105
            ExecutionDag::new(self.builder_dag, self.options.channel_buffer_sz)?;
332✔
106
        let node_indexes = execution_dag.graph().node_identifiers().collect::<Vec<_>>();
332✔
107

332✔
108
        // Start the threads.
332✔
109
        let mut join_handles = HashMap::new();
332✔
110
        for node_index in node_indexes {
2,027✔
111
            let node = execution_dag.graph()[node_index]
1,695✔
112
                .as_ref()
1,695✔
113
                .expect("We created all nodes");
1,695✔
114
            let node_handle = node.handle.clone();
1,695✔
115
            match &node.kind {
1,695✔
116
                NodeKind::Source(_, _) => {
×
117
                    let (source_sender_node, source_listener_node) = create_source_nodes(
342✔
118
                        &mut execution_dag,
342✔
119
                        node_index,
342✔
120
                        &self.options,
342✔
121
                        running.clone(),
342✔
122
                    );
342✔
123
                    join_handles.insert(
342✔
124
                        node_handle,
342✔
125
                        start_source(source_sender_node, source_listener_node)?,
342✔
126
                    );
×
127
                }
×
128
                NodeKind::Processor(_) => {
×
129
                    let processor_node = ProcessorNode::new(&mut execution_dag, node_index);
1,017✔
130
                    join_handles.insert(node_handle, start_processor(processor_node)?);
1,017✔
131
                }
×
132
                NodeKind::Sink(_) => {
×
133
                    let sink_node = SinkNode::new(&mut execution_dag, node_index);
336✔
134
                    join_handles.insert(node_handle, start_sink(sink_node)?);
336✔
135
                }
136
            }
×
137
        }
×
138

×
139
        Ok(DagExecutorJoinHandle { join_handles })
332✔
140
    }
332✔
141
}
×
142

×
143
impl DagExecutorJoinHandle {
×
144
    pub fn join(mut self) -> Result<(), ExecutionError> {
331✔
145
        let handles: Vec<NodeHandle> = self.join_handles.iter().map(|e| e.0.clone()).collect();
1,692✔
146

×
147
        loop {
×
148
            for handle in &handles {
8,870✔
149
                if let Entry::Occupied(entry) = self.join_handles.entry(handle.clone()) {
7,373✔
150
                    if entry.get().is_finished() {
7,157✔
151
                        if let Err(e) = entry.remove().join() {
1,680✔
152
                            panic_any(e);
5✔
153
                        }
1,675✔
154
                    }
5,477✔
155
                }
216✔
156
            }
×
157

×
158
            if self.join_handles.is_empty() {
1,497✔
159
                return Ok(());
326✔
160
            }
1,171✔
161

1,171✔
162
            thread::sleep(Duration::from_millis(250));
1,171✔
163
        }
164
    }
326✔
165
}
×
166

×
167
fn start_source(
342✔
168
    source_sender: SourceSenderNode,
342✔
169
    source_listener: SourceListenerNode,
342✔
170
) -> Result<JoinHandle<()>, ExecutionError> {
342✔
171
    let handle = source_sender.handle().clone();
342✔
172

×
173
    let _st_handle = Builder::new()
342✔
174
        .name(format!("{handle}-sender"))
342✔
175
        .spawn(move || match source_sender.run() {
342✔
176
            Ok(_) => {}
335✔
177
            // Channel disconnection means the source listener has quit.
×
178
            // Maybe it quit gracefully so we don't need to panic.
×
179
            Err(ExecutionError::CannotSendToChannel) => {}
6✔
180
            // Other errors result in panic.
×
181
            Err(e) => std::panic::panic_any(e),
1✔
182
        })?;
342✔
183

×
184
    Ok(Builder::new()
342✔
185
        .name(format!("{handle}-listener"))
342✔
186
        .spawn(move || {
342✔
187
            if let Err(e) = source_listener.run() {
342✔
188
                std::panic::panic_any(e);
5✔
189
            }
337✔
190
        })?)
342✔
191
}
342✔
192

×
193
fn start_processor(processor: ProcessorNode) -> Result<JoinHandle<()>, ExecutionError> {
1,017✔
194
    Ok(Builder::new()
1,017✔
195
        .name(processor.handle().to_string())
1,017✔
196
        .spawn(move || {
1,017✔
197
            if let Err(e) = processor.run() {
1,017✔
198
                std::panic::panic_any(e);
7✔
199
            }
1,010✔
200
        })?)
1,017✔
201
}
1,017✔
202

×
203
fn start_sink(sink: SinkNode) -> Result<JoinHandle<()>, ExecutionError> {
336✔
204
    Ok(Builder::new().name(sink.handle().to_string()).spawn(|| {
336✔
205
        if let Err(e) = sink.run() {
336✔
206
            std::panic::panic_any(e);
5✔
207
        }
331✔
208
    })?)
336✔
209
}
336✔
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