pub type WorkerIdentifier = usize;
pub type TimelyEventBuilder = CapacityContainerBuilder<Vec<(Duration, TimelyEvent)>>;
pub type TimelyLogger = crate::logging_core::TypedLogger<TimelyEventBuilder, TimelyEvent>;
pub type TimelyProgressEventBuilder<T> = CapacityContainerBuilder<Vec<(Duration, TimelyProgressEvent<T>)>>;
pub type TimelyProgressLogger<T> = crate::logging_core::Logger<TimelyProgressEventBuilder<T>>;
pub type TimelySummaryEventBuilder<TS> = CapacityContainerBuilder<Vec<(Duration, OperatesSummaryEvent<TS>)>>;
pub type TimelySummaryLogger<TS> = crate::logging_core::Logger<TimelySummaryEventBuilder<TS>>;
use std::time::Duration;
use columnar::Columnar;
use serde::{Deserialize, Serialize};
use crate::Container;
use crate::container::CapacityContainerBuilder;
use crate::dataflow::operators::capture::{Event, EventPusher};
pub struct BatchLogger<P, C> where P: EventPusher<Duration, C> {
time: Duration,
event_pusher: P,
_phantom: ::std::marker::PhantomData<C>,
}
impl<P, C> BatchLogger<P, C> where P: EventPusher<Duration, C>, C: Container {
pub fn new(event_pusher: P) -> Self {
BatchLogger {
time: Default::default(),
event_pusher,
_phantom: ::std::marker::PhantomData,
}
}
pub fn publish_batch(&mut self, &time: &Duration, data: &mut Option<C>) {
if let Some(data) = data {
self.event_pusher.push(Event::Messages(self.time, std::mem::take(data)));
}
if self.time < time {
let new_frontier = time;
let old_frontier = self.time;
self.event_pusher.push(Event::Progress(vec![(new_frontier, 1), (old_frontier, -1)]));
}
self.time = time;
}
}
impl<P, C> Drop for BatchLogger<P, C> where P: EventPusher<Duration, C> {
fn drop(&mut self) {
self.event_pusher.push(Event::Progress(vec![(self.time, -1)]));
}
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct OperatesEvent {
pub id: usize,
pub addr: Vec<usize>,
pub name: String,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Eq, PartialEq)]
pub struct OperatesSummaryEvent<TS> {
pub id: usize,
pub summary: Vec<Vec<crate::progress::Antichain<TS>>>,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct ChannelsEvent {
pub id: usize,
pub scope_addr: Vec<usize>,
pub source: (usize, usize),
pub target: (usize, usize),
}
#[derive(Debug, Clone)]
pub struct TimelyProgressEvent<T> {
pub is_send: bool,
pub source: usize,
pub channel: usize,
pub seq_no: usize,
pub identifier: usize,
pub messages: Vec<(usize, usize, T, i64)>,
pub internal: Vec<(usize, usize, T, i64)>,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct PushProgressEvent {
pub op_id: usize,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct MessagesEvent {
pub is_send: bool,
pub channel: usize,
pub source: usize,
pub target: usize,
pub seq_no: usize,
pub length: usize,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
pub enum StartStop {
Start,
Stop,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct ScheduleEvent {
pub id: usize,
pub start_stop: StartStop,
}
impl ScheduleEvent {
pub fn start(id: usize) -> Self { ScheduleEvent { id, start_stop: StartStop::Start } }
pub fn stop(id: usize) -> Self { ScheduleEvent { id, start_stop: StartStop::Stop } }
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct ShutdownEvent {
pub id: usize,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct ApplicationEvent {
pub id: usize,
pub is_start: bool,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct GuardedMessageEvent {
pub is_start: bool,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct GuardedProgressEvent {
pub is_start: bool,
}
#[derive(Serialize, Deserialize, Columnar, Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub struct TimelySetup {
pub index: usize,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub enum CommChannelKind {
Progress,
Data,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct CommChannelsEvent {
pub identifier: usize,
pub kind: CommChannelKind,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct InputEvent {
pub start_stop: StartStop,
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
pub enum ParkEvent {
Park(Option<Duration>),
Unpark,
}
impl ParkEvent {
pub fn park(duration: Option<Duration>) -> Self { ParkEvent::Park(duration) }
pub fn unpark() -> Self { ParkEvent::Unpark }
}
#[derive(Serialize, Deserialize, Columnar, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub enum TimelyEvent {
Operates(OperatesEvent),
Channels(ChannelsEvent),
PushProgress(PushProgressEvent),
Messages(MessagesEvent),
Schedule(ScheduleEvent),
Shutdown(ShutdownEvent),
Application(ApplicationEvent),
GuardedMessage(GuardedMessageEvent),
GuardedProgress(GuardedProgressEvent),
CommChannels(CommChannelsEvent),
Input(InputEvent),
Park(ParkEvent),
Text(String),
}
impl From<OperatesEvent> for TimelyEvent {
fn from(v: OperatesEvent) -> TimelyEvent { TimelyEvent::Operates(v) }
}
impl From<ChannelsEvent> for TimelyEvent {
fn from(v: ChannelsEvent) -> TimelyEvent { TimelyEvent::Channels(v) }
}
impl From<PushProgressEvent> for TimelyEvent {
fn from(v: PushProgressEvent) -> TimelyEvent { TimelyEvent::PushProgress(v) }
}
impl From<MessagesEvent> for TimelyEvent {
fn from(v: MessagesEvent) -> TimelyEvent { TimelyEvent::Messages(v) }
}
impl From<ScheduleEvent> for TimelyEvent {
fn from(v: ScheduleEvent) -> TimelyEvent { TimelyEvent::Schedule(v) }
}
impl From<ShutdownEvent> for TimelyEvent {
fn from(v: ShutdownEvent) -> TimelyEvent { TimelyEvent::Shutdown(v) }
}
impl From<ApplicationEvent> for TimelyEvent {
fn from(v: ApplicationEvent) -> TimelyEvent { TimelyEvent::Application(v) }
}
impl From<GuardedMessageEvent> for TimelyEvent {
fn from(v: GuardedMessageEvent) -> TimelyEvent { TimelyEvent::GuardedMessage(v) }
}
impl From<GuardedProgressEvent> for TimelyEvent {
fn from(v: GuardedProgressEvent) -> TimelyEvent { TimelyEvent::GuardedProgress(v) }
}
impl From<CommChannelsEvent> for TimelyEvent {
fn from(v: CommChannelsEvent) -> TimelyEvent { TimelyEvent::CommChannels(v) }
}
impl From<InputEvent> for TimelyEvent {
fn from(v: InputEvent) -> TimelyEvent { TimelyEvent::Input(v) }
}
impl From<ParkEvent> for TimelyEvent {
fn from(v: ParkEvent) -> TimelyEvent { TimelyEvent::Park(v) }
}