@@ -201,23 +201,27 @@ pub trait AsWorker : Scheduler {
201201 /// The next worker-unique identifier to be allocated.
202202 fn peek_identifier ( & self ) -> usize ;
203203 /// Provides access to named logging streams.
204- fn log_register ( & self ) -> :: std:: cell:: RefMut < crate :: logging_core:: Registry > ;
204+ fn log_register ( & self ) -> Option < :: std:: cell:: RefMut < crate :: logging_core:: Registry > > ;
205205 /// Provides access to the timely logging stream.
206- fn logging ( & self ) -> Option < crate :: logging:: TimelyLogger > { self . log_register ( ) . get ( "timely" ) . map ( Into :: into) }
206+ fn logging ( & self ) -> Option < crate :: logging:: TimelyLogger > { self . log_register ( ) . and_then ( |l| l . get ( "timely" ) . map ( Into :: into) ) }
207207}
208208
209209/// A `Worker` is the entry point to a timely dataflow computation. It wraps a `Allocate`,
210210/// and has a list of dataflows that it manages.
211211pub struct Worker < A : Allocate > {
212212 config : Config ,
213- timer : Instant ,
213+ /// An optional instant from which the start of the computation should be reckoned.
214+ ///
215+ /// If this is set to none, system time-based functionality will be unavailable or work badly.
216+ /// For example, logging will be unavailable, and activation after a delay will be unavailable.
217+ timer : Option < Instant > ,
214218 paths : Rc < RefCell < HashMap < usize , Rc < [ usize ] > > > > ,
215219 allocator : Rc < RefCell < A > > ,
216220 identifiers : Rc < RefCell < usize > > ,
217221 // dataflows: Rc<RefCell<Vec<Wrapper>>>,
218222 dataflows : Rc < RefCell < HashMap < usize , Wrapper > > > ,
219223 dataflow_counter : Rc < RefCell < usize > > ,
220- logging : Rc < RefCell < crate :: logging_core:: Registry > > ,
224+ logging : Option < Rc < RefCell < crate :: logging_core:: Registry > > > ,
221225
222226 activations : Rc < RefCell < Activations > > ,
223227 active_dataflows : Vec < usize > ,
@@ -255,7 +259,7 @@ impl<A: Allocate> AsWorker for Worker<A> {
255259
256260 fn new_identifier ( & mut self ) -> usize { self . new_identifier ( ) }
257261 fn peek_identifier ( & self ) -> usize { self . peek_identifier ( ) }
258- fn log_register ( & self ) -> RefMut < crate :: logging_core:: Registry > {
262+ fn log_register ( & self ) -> Option < RefMut < crate :: logging_core:: Registry > > {
259263 self . log_register ( )
260264 }
261265}
@@ -268,8 +272,7 @@ impl<A: Allocate> Scheduler for Worker<A> {
268272
269273impl < A : Allocate > Worker < A > {
270274 /// Allocates a new `Worker` bound to a channel allocator.
271- pub fn new ( config : Config , c : A ) -> Worker < A > {
272- let now = Instant :: now ( ) ;
275+ pub fn new ( config : Config , c : A , now : Option < std:: time:: Instant > ) -> Worker < A > {
273276 Worker {
274277 config,
275278 timer : now,
@@ -278,7 +281,7 @@ impl<A: Allocate> Worker<A> {
278281 identifiers : Default :: default ( ) ,
279282 dataflows : Default :: default ( ) ,
280283 dataflow_counter : Default :: default ( ) ,
281- logging : Rc :: new ( RefCell :: new ( crate :: logging_core:: Registry :: new ( now) ) ) ,
284+ logging : now . map ( |now| Rc :: new ( RefCell :: new ( crate :: logging_core:: Registry :: new ( now) ) ) ) ,
282285 activations : Rc :: new ( RefCell :: new ( Activations :: new ( now) ) ) ,
283286 active_dataflows : Default :: default ( ) ,
284287 temp_channel_ids : Default :: default ( ) ,
@@ -414,7 +417,7 @@ impl<A: Allocate> Worker<A> {
414417 }
415418
416419 // Clean up, indicate if dataflows remain.
417- self . logging . borrow_mut ( ) . flush ( ) ;
420+ self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) . flush ( ) ) ;
418421 self . allocator . borrow_mut ( ) . release ( ) ;
419422 !self . dataflows . borrow ( ) . is_empty ( )
420423 }
@@ -485,7 +488,7 @@ impl<A: Allocate> Worker<A> {
485488 ///
486489 /// let index = worker.index();
487490 /// let peers = worker.peers();
488- /// let timer = worker.timer();
491+ /// let timer = worker.timer().unwrap() ;
489492 ///
490493 /// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
491494 ///
@@ -500,7 +503,7 @@ impl<A: Allocate> Worker<A> {
500503 ///
501504 /// let index = worker.index();
502505 /// let peers = worker.peers();
503- /// let timer = worker.timer();
506+ /// let timer = worker.timer().unwrap() ;
504507 ///
505508 /// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
506509 ///
@@ -516,13 +519,13 @@ impl<A: Allocate> Worker<A> {
516519 ///
517520 /// let index = worker.index();
518521 /// let peers = worker.peers();
519- /// let timer = worker.timer();
522+ /// let timer = worker.timer().unwrap() ;
520523 ///
521524 /// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
522525 ///
523526 /// });
524527 /// ```
525- pub fn timer ( & self ) -> Instant { self . timer }
528+ pub fn timer ( & self ) -> Option < Instant > { self . timer }
526529
527530 /// Allocate a new worker-unique identifier.
528531 ///
@@ -546,13 +549,14 @@ impl<A: Allocate> Worker<A> {
546549 /// timely::execute_from_args(::std::env::args(), |worker| {
547550 ///
548551 /// worker.log_register()
552+ /// .unwrap()
549553 /// .insert::<timely::logging::TimelyEventBuilder,_>("timely", |time, data|
550554 /// println!("{:?}\t{:?}", time, data)
551555 /// );
552556 /// });
553557 /// ```
554- pub fn log_register ( & self ) -> :: std:: cell:: RefMut < crate :: logging_core:: Registry > {
555- self . logging . borrow_mut ( )
558+ pub fn log_register ( & self ) -> Option < :: std:: cell:: RefMut < crate :: logging_core:: Registry > > {
559+ self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) )
556560 }
557561
558562 /// Construct a new dataflow.
@@ -575,7 +579,7 @@ impl<A: Allocate> Worker<A> {
575579 T : Refines < ( ) > ,
576580 F : FnOnce ( & mut Child < Self , T > ) ->R ,
577581 {
578- let logging = self . logging . borrow_mut ( ) . get ( "timely" ) . map ( Into :: into) ;
582+ let logging = self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) ) . and_then ( |l| l . get ( "timely" ) . map ( Into :: into) ) ;
579583 self . dataflow_core ( "Dataflow" , logging, Box :: new ( ( ) ) , |_, child| func ( child) )
580584 }
581585
@@ -599,7 +603,7 @@ impl<A: Allocate> Worker<A> {
599603 T : Refines < ( ) > ,
600604 F : FnOnce ( & mut Child < Self , T > ) ->R ,
601605 {
602- let logging = self . logging . borrow_mut ( ) . get ( "timely" ) . map ( Into :: into) ;
606+ let logging = self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) ) . and_then ( |l| l . get ( "timely" ) . map ( Into :: into) ) ;
603607 self . dataflow_core ( name, logging, Box :: new ( ( ) ) , |_, child| func ( child) )
604608 }
605609
@@ -639,8 +643,8 @@ impl<A: Allocate> Worker<A> {
639643 let identifier = self . new_identifier ( ) ;
640644
641645 let type_name = std:: any:: type_name :: < T > ( ) ;
642- let progress_logging = self . logging . borrow_mut ( ) . get ( & format ! ( "timely/progress/{type_name}" ) ) ;
643- let summary_logging = self . logging . borrow_mut ( ) . get ( & format ! ( "timely/summary/{type_name}" ) ) ;
646+ let progress_logging = self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) ) . and_then ( |l| l . get ( & format ! ( "timely/progress/{}" , type_name ) ) . map ( Into :: into ) ) ;
647+ let summary_logging = self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) ) . and_then ( |l| l . get ( & format ! ( "timely/summary/{}" , type_name ) ) . map ( Into :: into ) ) ;
644648 let subscope = SubgraphBuilder :: new_from ( addr, identifier, logging. clone ( ) , summary_logging, name) ;
645649 let subscope = RefCell :: new ( subscope) ;
646650
@@ -735,7 +739,7 @@ impl<A: Allocate> Clone for Worker<A> {
735739 identifiers : Rc :: clone ( & self . identifiers ) ,
736740 dataflows : Rc :: clone ( & self . dataflows ) ,
737741 dataflow_counter : Rc :: clone ( & self . dataflow_counter ) ,
738- logging : Rc :: clone ( & self . logging ) ,
742+ logging : self . logging . clone ( ) ,
739743 activations : Rc :: clone ( & self . activations ) ,
740744 active_dataflows : Vec :: new ( ) ,
741745 temp_channel_ids : Rc :: clone ( & self . temp_channel_ids ) ,
0 commit comments