@@ -201,23 +201,33 @@ 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 > > ;
205+ /// Acquires a logger by name, if the log register exists and the name is registered.
206+ ///
207+ /// For a more precise understanding of why a result is `None` one can use the direct functions.
208+ fn logger_for < CB : timely_container:: ContainerBuilder > ( & self , name : & str ) -> Option < timely_logging:: Logger < CB > > {
209+ self . log_register ( ) . and_then ( |l| l. get ( name) )
210+ }
205211 /// Provides access to the timely logging stream.
206- fn logging ( & self ) -> Option < crate :: logging:: TimelyLogger > { self . log_register ( ) . get ( "timely" ) . map ( Into :: into) }
212+ fn logging ( & self ) -> Option < crate :: logging:: TimelyLogger > { self . logger_for ( "timely" ) . map ( Into :: into) }
207213}
208214
209215/// A `Worker` is the entry point to a timely dataflow computation. It wraps a `Allocate`,
210216/// and has a list of dataflows that it manages.
211217pub struct Worker < A : Allocate > {
212218 config : Config ,
213- timer : Instant ,
219+ /// An optional instant from which the start of the computation should be reckoned.
220+ ///
221+ /// If this is set to none, system time-based functionality will be unavailable or work badly.
222+ /// For example, logging will be unavailable, and activation after a delay will be unavailable.
223+ timer : Option < Instant > ,
214224 paths : Rc < RefCell < HashMap < usize , Rc < [ usize ] > > > > ,
215225 allocator : Rc < RefCell < A > > ,
216226 identifiers : Rc < RefCell < usize > > ,
217227 // dataflows: Rc<RefCell<Vec<Wrapper>>>,
218228 dataflows : Rc < RefCell < HashMap < usize , Wrapper > > > ,
219229 dataflow_counter : Rc < RefCell < usize > > ,
220- logging : Rc < RefCell < crate :: logging_core:: Registry > > ,
230+ logging : Option < Rc < RefCell < crate :: logging_core:: Registry > > > ,
221231
222232 activations : Rc < RefCell < Activations > > ,
223233 active_dataflows : Vec < usize > ,
@@ -255,7 +265,7 @@ impl<A: Allocate> AsWorker for Worker<A> {
255265
256266 fn new_identifier ( & mut self ) -> usize { self . new_identifier ( ) }
257267 fn peek_identifier ( & self ) -> usize { self . peek_identifier ( ) }
258- fn log_register ( & self ) -> RefMut < crate :: logging_core:: Registry > {
268+ fn log_register ( & self ) -> Option < RefMut < crate :: logging_core:: Registry > > {
259269 self . log_register ( )
260270 }
261271}
@@ -268,8 +278,7 @@ impl<A: Allocate> Scheduler for Worker<A> {
268278
269279impl < A : Allocate > Worker < A > {
270280 /// Allocates a new `Worker` bound to a channel allocator.
271- pub fn new ( config : Config , c : A ) -> Worker < A > {
272- let now = Instant :: now ( ) ;
281+ pub fn new ( config : Config , c : A , now : Option < std:: time:: Instant > ) -> Worker < A > {
273282 Worker {
274283 config,
275284 timer : now,
@@ -278,7 +287,7 @@ impl<A: Allocate> Worker<A> {
278287 identifiers : Default :: default ( ) ,
279288 dataflows : Default :: default ( ) ,
280289 dataflow_counter : Default :: default ( ) ,
281- logging : Rc :: new ( RefCell :: new ( crate :: logging_core:: Registry :: new ( now) ) ) ,
290+ logging : now . map ( |now| Rc :: new ( RefCell :: new ( crate :: logging_core:: Registry :: new ( now) ) ) ) ,
282291 activations : Rc :: new ( RefCell :: new ( Activations :: new ( now) ) ) ,
283292 active_dataflows : Default :: default ( ) ,
284293 temp_channel_ids : Default :: default ( ) ,
@@ -414,7 +423,7 @@ impl<A: Allocate> Worker<A> {
414423 }
415424
416425 // Clean up, indicate if dataflows remain.
417- self . logging . borrow_mut ( ) . flush ( ) ;
426+ self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) . flush ( ) ) ;
418427 self . allocator . borrow_mut ( ) . release ( ) ;
419428 !self . dataflows . borrow ( ) . is_empty ( )
420429 }
@@ -485,7 +494,7 @@ impl<A: Allocate> Worker<A> {
485494 ///
486495 /// let index = worker.index();
487496 /// let peers = worker.peers();
488- /// let timer = worker.timer();
497+ /// let timer = worker.timer().unwrap() ;
489498 ///
490499 /// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
491500 ///
@@ -500,7 +509,7 @@ impl<A: Allocate> Worker<A> {
500509 ///
501510 /// let index = worker.index();
502511 /// let peers = worker.peers();
503- /// let timer = worker.timer();
512+ /// let timer = worker.timer().unwrap() ;
504513 ///
505514 /// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
506515 ///
@@ -516,13 +525,13 @@ impl<A: Allocate> Worker<A> {
516525 ///
517526 /// let index = worker.index();
518527 /// let peers = worker.peers();
519- /// let timer = worker.timer();
528+ /// let timer = worker.timer().unwrap() ;
520529 ///
521530 /// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
522531 ///
523532 /// });
524533 /// ```
525- pub fn timer ( & self ) -> Instant { self . timer }
534+ pub fn timer ( & self ) -> Option < Instant > { self . timer }
526535
527536 /// Allocate a new worker-unique identifier.
528537 ///
@@ -546,13 +555,14 @@ impl<A: Allocate> Worker<A> {
546555 /// timely::execute_from_args(::std::env::args(), |worker| {
547556 ///
548557 /// worker.log_register()
558+ /// .unwrap()
549559 /// .insert::<timely::logging::TimelyEventBuilder,_>("timely", |time, data|
550560 /// println!("{:?}\t{:?}", time, data)
551561 /// );
552562 /// });
553563 /// ```
554- pub fn log_register ( & self ) -> :: std:: cell:: RefMut < crate :: logging_core:: Registry > {
555- self . logging . borrow_mut ( )
564+ pub fn log_register ( & self ) -> Option < :: std:: cell:: RefMut < crate :: logging_core:: Registry > > {
565+ self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) )
556566 }
557567
558568 /// Construct a new dataflow.
@@ -575,8 +585,7 @@ impl<A: Allocate> Worker<A> {
575585 T : Refines < ( ) > ,
576586 F : FnOnce ( & mut Child < Self , T > ) ->R ,
577587 {
578- let logging = self . logging . borrow_mut ( ) . get ( "timely" ) . map ( Into :: into) ;
579- self . dataflow_core ( "Dataflow" , logging, Box :: new ( ( ) ) , |_, child| func ( child) )
588+ self . dataflow_core ( "Dataflow" , self . logging ( ) , Box :: new ( ( ) ) , |_, child| func ( child) )
580589 }
581590
582591 /// Construct a new dataflow with a (purely cosmetic) name.
@@ -599,8 +608,7 @@ impl<A: Allocate> Worker<A> {
599608 T : Refines < ( ) > ,
600609 F : FnOnce ( & mut Child < Self , T > ) ->R ,
601610 {
602- let logging = self . logging . borrow_mut ( ) . get ( "timely" ) . map ( Into :: into) ;
603- self . dataflow_core ( name, logging, Box :: new ( ( ) ) , |_, child| func ( child) )
611+ self . dataflow_core ( name, self . logging ( ) , Box :: new ( ( ) ) , |_, child| func ( child) )
604612 }
605613
606614 /// Construct a new dataflow with specific configurations.
@@ -639,8 +647,8 @@ impl<A: Allocate> Worker<A> {
639647 let identifier = self . new_identifier ( ) ;
640648
641649 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}" ) ) ;
650+ let progress_logging = self . logger_for ( & format ! ( "timely/progress/{}" , type_name ) ) ;
651+ let summary_logging = self . logger_for ( & format ! ( "timely/summary/{}" , type_name ) ) ;
644652 let subscope = SubgraphBuilder :: new_from ( addr, identifier, logging. clone ( ) , summary_logging, name) ;
645653 let subscope = RefCell :: new ( subscope) ;
646654
@@ -735,7 +743,7 @@ impl<A: Allocate> Clone for Worker<A> {
735743 identifiers : Rc :: clone ( & self . identifiers ) ,
736744 dataflows : Rc :: clone ( & self . dataflows ) ,
737745 dataflow_counter : Rc :: clone ( & self . dataflow_counter ) ,
738- logging : Rc :: clone ( & self . logging ) ,
746+ logging : self . logging . clone ( ) ,
739747 activations : Rc :: clone ( & self . activations ) ,
740748 active_dataflows : Vec :: new ( ) ,
741749 temp_channel_ids : Rc :: clone ( & self . temp_channel_ids ) ,
0 commit comments