Skip to main content

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 operator.
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 the scope containing this channel.
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    /// The type of data on the channel, as a string.
95    pub typ: String,
96}
97
98#[derive(Debug, Clone)]
99/// Send or receive of progress information.
100pub struct TimelyProgressEvent<T> {
101    /// `true` if the event is a send, and `false` if it is a receive.
102    pub is_send: bool,
103    /// Source worker index.
104    pub source: usize,
105    /// Communication channel identifier
106    pub channel: usize,
107    /// Message sequence number.
108    pub seq_no: usize,
109    /// Global identifier of the operator reporting progress.
110    pub identifier: usize,
111    /// List of message updates, containing Target descriptor, timestamp as string, and delta.
112    pub messages: Vec<(usize, usize, T, i64)>,
113    /// List of capability updates, containing Source descriptor, timestamp as string, and delta.
114    pub internal: Vec<(usize, usize, T, i64)>,
115}
116
117#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
118/// External progress pushed onto an operator
119pub struct PushProgressEvent {
120    /// Worker-unique operator identifier
121    pub op_id: usize,
122}
123
124#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
125/// Message send or receive event
126pub struct MessagesEvent {
127    /// `true` if send event, `false` if receive event.
128    pub is_send: bool,
129    /// Channel identifier
130    pub channel: usize,
131    /// Source worker index.
132    pub source: usize,
133    /// Target worker index.
134    pub target: usize,
135    /// Message sequence number.
136    pub seq_no: usize,
137    /// Number of typed records in the message.
138    pub record_count: i64,
139}
140
141/// Records the starting and stopping of an operator.
142#[derive(Serialize, Deserialize, Columnar, Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
143pub enum StartStop {
144    /// Operator starts.
145    Start,
146    /// Operator stops.
147    Stop,
148}
149
150#[derive(Serialize, Deserialize, Columnar, Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
151/// Operator start or stop.
152pub struct ScheduleEvent {
153    /// Worker-unique identifier for the operator, linkable to the identifiers in [`OperatesEvent`].
154    pub id: usize,
155    /// `Start` if the operator is starting, `Stop` if it is stopping.
156    /// activity is true if it looks like some useful work was performed during this call (data was
157    /// read or written, notifications were requested / delivered)
158    pub start_stop: StartStop,
159}
160
161impl ScheduleEvent {
162    /// Creates a new start scheduling event.
163    pub fn start(id: usize) -> Self { ScheduleEvent { id, start_stop: StartStop::Start } }
164    /// Creates a new stop scheduling event and reports whether work occurred.
165    pub fn stop(id: usize) -> Self { ScheduleEvent { id, start_stop: StartStop::Stop } }
166}
167
168#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
169/// Operator shutdown.
170pub struct ShutdownEvent {
171    /// Worker-unique identifier for the operator, linkable to the identifiers in [`OperatesEvent`].
172    pub id: usize,
173}
174
175#[derive(Serialize, Deserialize, Columnar, Debug, PartialEq, Eq, Hash, Clone, Copy)]
176/// Identifier of the worker that generated a log line
177pub struct TimelySetup {
178    /// Worker index
179    pub index: usize,
180}
181
182#[derive(Serialize, Deserialize, Columnar, Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
183/// Kind of communication channel
184pub enum CommChannelKind {
185    /// Communication channel carrying progress information
186    Progress,
187    /// Communication channel carrying data
188    Data,
189}
190
191#[derive(Serialize, Deserialize, Columnar, Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
192/// Event on a communication channel
193pub struct CommChannelsEvent {
194    /// Communication channel identifier
195    pub identifier: usize,
196    /// Kind of communication channel (progress / data)
197    pub kind: CommChannelKind,
198}
199
200/// Records the starting and stopping of an operator.
201#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
202pub enum ParkEvent {
203    /// Worker parks.
204    Park(Option<Duration>),
205    /// Worker unparks.
206    Unpark,
207}
208
209impl ParkEvent {
210    /// Creates a new park event from the supplied duration.
211    pub fn park(duration: Option<Duration>) -> Self { ParkEvent::Park(duration) }
212    /// Creates a new unpark event.
213    pub fn unpark() -> Self { ParkEvent::Unpark }
214}
215
216#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
217/// An event in a timely worker
218pub enum TimelyEvent {
219    /// Operator creation.
220    Operates(OperatesEvent),
221    /// Channel creation.
222    Channels(ChannelsEvent),
223    /// Progress propagation (reasoning).
224    PushProgress(PushProgressEvent),
225    /// Message send or receive.
226    Messages(MessagesEvent),
227    /// Operator start or stop.
228    Schedule(ScheduleEvent),
229    /// Operator shutdown.
230    Shutdown(ShutdownEvent),
231    /// Communication channel event.
232    CommChannels(CommChannelsEvent),
233    /// Park event.
234    Park(ParkEvent),
235    /// Unstructured event.
236    Text(String),
237}
238
239impl From<OperatesEvent> for TimelyEvent {
240    fn from(v: OperatesEvent) -> TimelyEvent { TimelyEvent::Operates(v) }
241}
242
243impl From<ChannelsEvent> for TimelyEvent {
244    fn from(v: ChannelsEvent) -> TimelyEvent { TimelyEvent::Channels(v) }
245}
246
247impl From<PushProgressEvent> for TimelyEvent {
248    fn from(v: PushProgressEvent) -> TimelyEvent { TimelyEvent::PushProgress(v) }
249}
250
251impl From<MessagesEvent> for TimelyEvent {
252    fn from(v: MessagesEvent) -> TimelyEvent { TimelyEvent::Messages(v) }
253}
254
255impl From<ScheduleEvent> for TimelyEvent {
256    fn from(v: ScheduleEvent) -> TimelyEvent { TimelyEvent::Schedule(v) }
257}
258
259impl From<ShutdownEvent> for TimelyEvent {
260    fn from(v: ShutdownEvent) -> TimelyEvent { TimelyEvent::Shutdown(v) }
261}
262
263impl From<CommChannelsEvent> for TimelyEvent {
264    fn from(v: CommChannelsEvent) -> TimelyEvent { TimelyEvent::CommChannels(v) }
265}
266
267impl From<ParkEvent> for TimelyEvent {
268    fn from(v: ParkEvent) -> TimelyEvent { TimelyEvent::Park(v) }
269}