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

getdozer / dozer / 4302087115

pending completion
4302087115

push

github

GitHub
chore: Move `SnapshottingDone` out of `Operation` so processors don't have to know it.(#1103)

364 of 364 new or added lines in 33 files covered. (100.0%)

28623 of 40224 relevant lines covered (71.16%)

56785.21 hits per line

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

83.33
/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,671✔
44
pub(crate) enum InputPortState {
45
    Open,
46
    Terminated,
47
}
48

49
#[derive(Clone, Debug, PartialEq, Eq)]
84,327✔
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
            let node_handle = node.handle.clone();
1,695✔
113
            match &node.kind.as_ref().expect("We created all nodes") {
1,695✔
114
                NodeKind::Source(_, _) => {
×
115
                    let (source_sender_node, source_listener_node) = create_source_nodes(
342✔
116
                        &mut execution_dag,
342✔
117
                        node_index,
342✔
118
                        &self.options,
342✔
119
                        running.clone(),
342✔
120
                    );
342✔
121
                    join_handles.insert(
342✔
122
                        node_handle,
342✔
123
                        start_source(source_sender_node, source_listener_node)?,
342✔
124
                    );
125
                }
126
                NodeKind::Processor(_) => {
×
127
                    let processor_node = ProcessorNode::new(&mut execution_dag, node_index);
1,017✔
128
                    join_handles.insert(node_handle, start_processor(processor_node)?);
1,017✔
129
                }
130
                NodeKind::Sink(_) => {
×
131
                    let sink_node = SinkNode::new(&mut execution_dag, node_index);
336✔
132
                    join_handles.insert(node_handle, start_sink(sink_node)?);
336✔
133
                }
134
            }
135
        }
136

×
137
        Ok(DagExecutorJoinHandle { join_handles })
332✔
138
    }
332✔
139
}
140

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

145
        loop {
×
146
            for handle in &handles {
8,713✔
147
                if let Entry::Occupied(entry) = self.join_handles.entry(handle.clone()) {
7,252✔
148
                    if entry.get().is_finished() {
7,024✔
149
                        if let Err(e) = entry.remove().join() {
1,680✔
150
                            panic_any(e);
5✔
151
                        }
1,675✔
152
                    }
5,344✔
153
                }
228✔
154
            }
155

×
156
            if self.join_handles.is_empty() {
1,461✔
157
                return Ok(());
326✔
158
            }
1,135✔
159

1,135✔
160
            thread::sleep(Duration::from_millis(250));
1,135✔
161
        }
×
162
    }
326✔
163
}
164

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

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

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

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

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