@@ -6,6 +6,8 @@ pub type WorkerIdentifier = usize;
66pub type Logger < Event > = crate :: logging_core:: Logger < Event , WorkerIdentifier > ;
77/// Logger for timely dataflow system events.
88pub type TimelyLogger = Logger < TimelyEvent > ;
9+ /// Logger for timely dataflow progress events (the "timely/progress" log stream).
10+ pub type TimelyProgressLogger = Logger < TimelyProgressEvent > ;
911
1012use std:: time:: Duration ;
1113use crate :: dataflow:: operators:: capture:: { Event , EventPusher } ;
@@ -70,9 +72,63 @@ pub struct ChannelsEvent {
7072 pub target : ( usize , usize ) ,
7173}
7274
73- #[ derive( Serialize , Deserialize , Abomonation , Debug , Clone , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
75+ /// Encapsulates Any and Debug for dynamically typed timestamps in logs
76+ pub trait ProgressEventTimestamp : std:: fmt:: Debug + std:: any:: Any {
77+ /// Upcasts this `ProgressEventTimestamp` to `Any`.
78+ ///
79+ /// NOTE: This is required until https://github.com/rust-lang/rfcs/issues/2765 is fixed
80+ ///
81+ /// # Example
82+ /// ```rust
83+ /// let ts = vec![(0usize, 0usize, (23u64, 10u64), -4i64), (0usize, 0usize, (23u64, 11u64), 1i64)];
84+ /// let ts: &timely::logging::ProgressEventTimestampVec = &ts;
85+ /// for (n, p, t, d) in ts.iter() {
86+ /// print!("{:?}, ", (n, p, t.as_any().downcast_ref::<(u64, u64)>(), d));
87+ /// }
88+ /// println!();
89+ /// ```
90+ fn as_any ( & self ) -> & dyn std:: any:: Any ;
91+
92+ /// Returns the name of the concrete type of this object.
93+ ///
94+ /// # Note
95+ ///
96+ /// This is intended for diagnostic use. The exact contents and format of the
97+ /// string returned are not specified, other than being a best-effort
98+ /// description of the type. For example, amongst the strings
99+ /// that `type_name::<Option<String>>()` might return are `"Option<String>"` and
100+ /// `"std::option::Option<std::string::String>"`.
101+ fn type_name ( & self ) -> & ' static str ;
102+ }
103+ impl < T : crate :: Data + std:: fmt:: Debug + std:: any:: Any > ProgressEventTimestamp for T {
104+ fn as_any ( & self ) -> & dyn std:: any:: Any { self }
105+
106+ fn type_name ( & self ) -> & ' static str { std:: any:: type_name :: < T > ( ) }
107+ }
108+
109+ /// A vector of progress updates in logs
110+ ///
111+ /// This exists to support upcasting of the concrecte progress update vectors to
112+ /// `dyn ProgressEventTimestamp`. Doing so at the vector granularity allows us to
113+ /// use a single allocation for the entire vector (as opposed to a `Box` allocation
114+ /// for each dynamically typed element).
115+ pub trait ProgressEventTimestampVec : std:: fmt:: Debug + std:: any:: Any {
116+ /// Iterate over the contents of the vector
117+ fn iter < ' a > ( & ' a self ) -> Box < dyn Iterator < Item =( & ' a usize , & ' a usize , & ' a dyn ProgressEventTimestamp , & ' a i64 ) > +' a > ;
118+ }
119+
120+ impl < T : ProgressEventTimestamp > ProgressEventTimestampVec for Vec < ( usize , usize , T , i64 ) > {
121+ fn iter < ' a > ( & ' a self ) -> Box < dyn Iterator < Item =( & ' a usize , & ' a usize , & ' a dyn ProgressEventTimestamp , & ' a i64 ) > +' a > {
122+ Box :: new ( <[ ( usize , usize , T , i64 ) ] >:: iter ( & self [ ..] ) . map ( |( n, p, t, d) | {
123+ let t: & dyn ProgressEventTimestamp = t;
124+ ( n, p, t, d)
125+ } ) )
126+ }
127+ }
128+
129+ #[ derive( Debug ) ]
74130/// Send or receive of progress information.
75- pub struct ProgressEvent {
131+ pub struct TimelyProgressEvent {
76132 /// `true` if the event is a send, and `false` if it is a receive.
77133 pub is_send : bool ,
78134 /// Source worker index.
@@ -84,9 +140,9 @@ pub struct ProgressEvent {
84140 /// Sequence of nested scope identifiers indicating the path from the root to this instance.
85141 pub addr : Vec < usize > ,
86142 /// List of message updates, containing Target descriptor, timestamp as string, and delta.
87- pub messages : Vec < ( usize , usize , String , i64 ) > ,
143+ pub messages : Box < dyn ProgressEventTimestampVec > ,
88144 /// List of capability updates, containing Source descriptor, timestamp as string, and delta.
89- pub internal : Vec < ( usize , usize , String , i64 ) > ,
145+ pub internal : Box < dyn ProgressEventTimestampVec > ,
90146}
91147
92148#[ derive( Serialize , Deserialize , Abomonation , Debug , Clone , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
@@ -225,8 +281,6 @@ pub enum TimelyEvent {
225281 Operates ( OperatesEvent ) ,
226282 /// Channel creation.
227283 Channels ( ChannelsEvent ) ,
228- /// Progress message send or receive.
229- Progress ( ProgressEvent ) ,
230284 /// Progress propagation (reasoning).
231285 PushProgress ( PushProgressEvent ) ,
232286 /// Message send or receive.
@@ -259,10 +313,6 @@ impl From<ChannelsEvent> for TimelyEvent {
259313 fn from ( v : ChannelsEvent ) -> TimelyEvent { TimelyEvent :: Channels ( v) }
260314}
261315
262- impl From < ProgressEvent > for TimelyEvent {
263- fn from ( v : ProgressEvent ) -> TimelyEvent { TimelyEvent :: Progress ( v) }
264- }
265-
266316impl From < PushProgressEvent > for TimelyEvent {
267317 fn from ( v : PushProgressEvent ) -> TimelyEvent { TimelyEvent :: PushProgress ( v) }
268318}
0 commit comments