timely/
logging.rs

1//! Traits, implementations, and macros related to logging timely events.
2
3/// Type alias for logging timely events.
4pub type WorkerIdentifier = usize;
5/// Container builder for timely dataflow system events.
6pub type TimelyEventBuilder = CapacityContainerBuilder<Vec<(Duration, TimelyEvent)>>;
7/// Logger for timely dataflow system events.
8pub type TimelyLogger = crate::logging_core::TypedLogger<TimelyEventBuilder, TimelyEvent>;
9/// Container builder for timely dataflow progress events.
10pub type TimelyProgressEventBuilder<T> = CapacityContainerBuilder<Vec<(Duration, TimelyProgressEvent<T>)>>;
11/// Logger for timely dataflow progress events (the "timely/progress/*" log streams).
12pub type TimelyProgressLogger<T> = crate::logging_core::Logger<TimelyProgressEventBuilder<T>>;
13/// Container builder for timely dataflow operator summary events.
14pub type TimelySummaryEventBuilder<TS> = CapacityContainerBuilder<Vec<(Duration, OperatesSummaryEvent<TS>)>>;
15/// Logger for timely dataflow operator summary events (the "timely/summary/*" log streams).
16pub type TimelySummaryLogger<TS> = crate::logging_core::Logger<TimelySummaryEventBuilder<TS>>;
17
18use std::time::Duration;
19use columnar::Columnar;
20use serde::{Deserialize, Serialize};
21
22use crate::Container;
23use crate::container::CapacityContainerBuilder;
24use crate::dataflow::operators::capture::{Event, EventPusher};
25use crate::progress::operate::Connectivity;
26
27/// Logs events as a timely stream, with progress statements.
28pub struct BatchLogger<P, C> where P: EventPusher<Duration, C> {
29    time: Duration,
30    event_pusher: P,
31    _phantom: ::std::marker::PhantomData<C>,
32}
33
34impl<P, C> BatchLogger<P, C> where P: EventPusher<Duration, C>, C: Container {
35    /// Creates a new batch logger.
36    pub fn new(event_pusher: P) -> Self {
37        BatchLogger {
38            time: Default::default(),
39            event_pusher,
40            _phantom: ::std::marker::PhantomData,
41        }
42    }
43    /// Publishes a batch of logged events and advances the capability.
44    pub fn publish_batch(&mut self, &time: &Duration, data: &mut Option<C>) {
45        if let Some(data) = data {
46            self.event_pusher.push(Event::Messages(self.time, std::mem::take(data)));
47        }
48        if self.time < time {
49            let new_frontier = time;
50            let old_frontier = self.time;
51            self.event_pusher.push(Event::Progress(vec![(new_frontier, 1), (old_frontier, -1)]));
52        }
53        self.time = time;
54    }
55}
56impl<P, C> Drop for BatchLogger<P, C> where P: EventPusher<Duration, C> {
57    fn drop(&mut self) {
58        self.event_pusher.push(Event::Progress(vec![(self.time, -1)]));
59    }
60}
61
62#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
63/// The creation of an `Operate` implementor.
64pub struct OperatesEvent {
65    /// Worker-unique identifier for the operator.
66    pub id: usize,
67    /// Sequence of nested scope identifiers indicating the path from the root to this instance.
68    pub addr: Vec<usize>,
69    /// A helpful name.
70    pub name: String,
71}
72
73
74#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Eq, PartialEq)]
75/// The summary of internal connectivity of an `Operate` implementor.
76pub struct OperatesSummaryEvent<TS> {
77    /// Worker-unique identifier for the operator.
78    pub id: usize,
79    /// Timestamp action summaries for (input, output) pairs.
80    pub summary: Connectivity<TS>,
81}
82
83#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
84/// The creation of a channel between operators.
85pub struct ChannelsEvent {
86    /// Worker-unique identifier for the channel
87    pub id: usize,
88    /// Sequence of nested scope identifiers indicating the path from the root to this instance.
89    pub scope_addr: Vec<usize>,
90    /// Source descriptor, indicating operator index and output port.
91    pub source: (usize, usize),
92    /// Target descriptor, indicating operator index and input port.
93    pub target: (usize, usize),
94}
95
96#[derive(Debug, Clone)]
97/// Send or receive of progress information.
98pub struct TimelyProgressEvent<T> {
99    /// `true` if the event is a send, and `false` if it is a receive.
100    pub is_send: bool,
101    /// Source worker index.
102    pub source: usize,
103    /// Communication channel identifier
104    pub channel: usize,
105    /// Message sequence number.
106    pub seq_no: usize,
107    /// Global identifier of the operator reporting progress.
108    pub identifier: usize,
109    /// List of message updates, containing Target descriptor, timestamp as string, and delta.
110    pub messages: Vec<(usize, usize, T, i64)>,
111    /// List of capability updates, containing Source descriptor, timestamp as string, and delta.
112    pub internal: Vec<(usize, usize, T, i64)>,
113}
114
115#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
116/// External progress pushed onto an operator
117pub struct PushProgressEvent {
118    /// Worker-unique operator identifier
119    pub op_id: usize,
120}
121
122#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
123/// Message send or receive event
124pub struct MessagesEvent {
125    /// `true` if send event, `false` if receive event.
126    pub is_send: bool,
127    /// Channel identifier
128    pub channel: usize,
129    /// Source worker index.
130    pub source: usize,
131    /// Target worker index.
132    pub target: usize,
133    /// Message sequence number.
134    pub seq_no: usize,
135    /// Number of typed records in the message.
136    pub length: usize,
137}
138
139/// Records the starting and stopping of an operator.
140#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
141pub enum StartStop {
142    /// Operator starts.
143    Start,
144    /// Operator stops.
145    Stop,
146}
147
148#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
149/// Operator start or stop.
150pub struct ScheduleEvent {
151    /// Worker-unique identifier for the operator, linkable to the identifiers in [`OperatesEvent`].
152    pub id: usize,
153    /// `Start` if the operator is starting, `Stop` if it is stopping.
154    /// activity is true if it looks like some useful work was performed during this call (data was
155    /// read or written, notifications were requested / delivered)
156    pub start_stop: StartStop,
157}
158
159impl ScheduleEvent {
160    /// Creates a new start scheduling event.
161    pub fn start(id: usize) -> Self { ScheduleEvent { id, start_stop: StartStop::Start } }
162    /// Creates a new stop scheduling event and reports whether work occurred.
163    pub fn stop(id: usize) -> Self { ScheduleEvent { id, start_stop: StartStop::Stop } }
164}
165
166#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
167/// Operator shutdown.
168pub struct ShutdownEvent {
169    /// Worker-unique identifier for the operator, linkable to the identifiers in [`OperatesEvent`].
170    pub id: usize,
171}
172
173#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
174/// Application-defined code start or stop
175pub struct ApplicationEvent {
176    /// Unique event type identifier
177    pub id: usize,
178    /// `true` when activity begins, `false` when it stops
179    pub is_start: bool,
180}
181
182#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
183/// Application-defined code start or stop
184pub struct GuardedMessageEvent {
185    /// `true` when activity begins, `false` when it stops
186    pub is_start: bool,
187}
188
189#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
190/// Application-defined code start or stop
191pub struct GuardedProgressEvent {
192    /// `true` when activity begins, `false` when it stops
193    pub is_start: bool,
194}
195
196#[derive(Serialize, Deserialize, Columnar, Debug, PartialEq, Eq, Hash, Clone, Copy)]
197/// Identifier of the worker that generated a log line
198pub struct TimelySetup {
199    /// Worker index
200    pub index: usize,
201}
202
203#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
204/// Kind of communication channel
205pub enum CommChannelKind {
206    /// Communication channel carrying progress information
207    Progress,
208    /// Communication channel carrying data
209    Data,
210}
211
212#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
213/// Event on a communication channel
214pub struct CommChannelsEvent {
215    /// Communication channel identifier
216    pub identifier: usize,
217    /// Kind of communication channel (progress / data)
218    pub kind: CommChannelKind,
219}
220
221#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
222/// Input logic start/stop
223pub struct InputEvent {
224    /// True when activity begins, false when it stops
225    pub start_stop: StartStop,
226}
227
228/// Records the starting and stopping of an operator.
229#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
230pub enum ParkEvent {
231    /// Worker parks.
232    Park(Option<Duration>),
233    /// Worker unparks.
234    Unpark,
235}
236
237impl ParkEvent {
238    /// Creates a new park event from the supplied duration.
239    pub fn park(duration: Option<Duration>) -> Self { ParkEvent::Park(duration) }
240    /// Creates a new unpark event.
241    pub fn unpark() -> Self { ParkEvent::Unpark }
242}
243
244#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
245/// An event in a timely worker
246pub enum TimelyEvent {
247    /// Operator creation.
248    Operates(OperatesEvent),
249    /// Channel creation.
250    Channels(ChannelsEvent),
251    /// Progress propagation (reasoning).
252    PushProgress(PushProgressEvent),
253    /// Message send or receive.
254    Messages(MessagesEvent),
255    /// Operator start or stop.
256    Schedule(ScheduleEvent),
257    /// Operator shutdown.
258    Shutdown(ShutdownEvent),
259    /// No clue.
260    Application(ApplicationEvent),
261    /// Per-message computation.
262    GuardedMessage(GuardedMessageEvent),
263    /// Per-notification computation.
264    GuardedProgress(GuardedProgressEvent),
265    /// Communication channel event.
266    CommChannels(CommChannelsEvent),
267    /// Input event.
268    Input(InputEvent),
269    /// Park event.
270    Park(ParkEvent),
271    /// Unstructured event.
272    Text(String),
273}
274
275impl From<OperatesEvent> for TimelyEvent {
276    fn from(v: OperatesEvent) -> TimelyEvent { TimelyEvent::Operates(v) }
277}
278
279impl From<ChannelsEvent> for TimelyEvent {
280    fn from(v: ChannelsEvent) -> TimelyEvent { TimelyEvent::Channels(v) }
281}
282
283impl From<PushProgressEvent> for TimelyEvent {
284    fn from(v: PushProgressEvent) -> TimelyEvent { TimelyEvent::PushProgress(v) }
285}
286
287impl From<MessagesEvent> for TimelyEvent {
288    fn from(v: MessagesEvent) -> TimelyEvent { TimelyEvent::Messages(v) }
289}
290
291impl From<ScheduleEvent> for TimelyEvent {
292    fn from(v: ScheduleEvent) -> TimelyEvent { TimelyEvent::Schedule(v) }
293}
294
295impl From<ShutdownEvent> for TimelyEvent {
296    fn from(v: ShutdownEvent) -> TimelyEvent { TimelyEvent::Shutdown(v) }
297}
298
299impl From<ApplicationEvent> for TimelyEvent {
300    fn from(v: ApplicationEvent) -> TimelyEvent { TimelyEvent::Application(v) }
301}
302
303impl From<GuardedMessageEvent> for TimelyEvent {
304    fn from(v: GuardedMessageEvent) -> TimelyEvent { TimelyEvent::GuardedMessage(v) }
305}
306
307impl From<GuardedProgressEvent> for TimelyEvent {
308    fn from(v: GuardedProgressEvent) -> TimelyEvent { TimelyEvent::GuardedProgress(v) }
309}
310
311impl From<CommChannelsEvent> for TimelyEvent {
312    fn from(v: CommChannelsEvent) -> TimelyEvent { TimelyEvent::CommChannels(v) }
313}
314
315impl From<InputEvent> for TimelyEvent {
316    fn from(v: InputEvent) -> TimelyEvent { TimelyEvent::Input(v) }
317}
318
319impl From<ParkEvent> for TimelyEvent {
320    fn from(v: ParkEvent) -> TimelyEvent { TimelyEvent::Park(v) }
321}