@@ -201,23 +201,27 @@ pub trait AsWorker : Scheduler {
201201 /// Allocates a new worker-unique identifier.
202202 fn new_identifier ( & mut self ) -> usize ;
203203 /// Provides access to named logging streams.
204- fn log_register ( & self ) -> :: std:: cell:: RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > ;
204+ fn log_register ( & self ) -> Option < :: std:: cell:: RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > > ;
205205 /// Provides access to the timely logging stream.
206- fn logging ( & self ) -> Option < crate :: logging:: TimelyLogger > { self . log_register ( ) . get ( "timely" ) }
206+ fn logging ( & self ) -> Option < crate :: logging:: TimelyLogger > { self . log_register ( ) . and_then ( |l| l . get ( "timely" ) ) }
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 , Vec < 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 < crate :: logging:: WorkerIdentifier > > > ,
224+ logging : Option < Rc < RefCell < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > > > ,
221225
222226 activations : Rc < RefCell < Activations > > ,
223227 active_dataflows : Vec < usize > ,
@@ -247,7 +251,7 @@ impl<A: Allocate> AsWorker for Worker<A> {
247251 }
248252
249253 fn new_identifier ( & mut self ) -> usize { self . new_identifier ( ) }
250- fn log_register ( & self ) -> RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > {
254+ fn log_register ( & self ) -> Option < RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > > {
251255 self . log_register ( )
252256 }
253257}
@@ -260,8 +264,7 @@ impl<A: Allocate> Scheduler for Worker<A> {
260264
261265impl < A : Allocate > Worker < A > {
262266 /// Allocates a new `Worker` bound to a channel allocator.
263- pub fn new ( config : Config , c : A ) -> Worker < A > {
264- let now = Instant :: now ( ) ;
267+ pub fn new ( config : Config , c : A , now : Option < std:: time:: Instant > ) -> Worker < A > {
265268 let index = c. index ( ) ;
266269 Worker {
267270 config,
@@ -271,7 +274,7 @@ impl<A: Allocate> Worker<A> {
271274 identifiers : Default :: default ( ) ,
272275 dataflows : Default :: default ( ) ,
273276 dataflow_counter : Default :: default ( ) ,
274- logging : Rc :: new ( RefCell :: new ( crate :: logging_core:: Registry :: new ( now, index) ) ) ,
277+ logging : now . map ( |now| Rc :: new ( RefCell :: new ( crate :: logging_core:: Registry :: new ( now, index) ) ) ) ,
275278 activations : Rc :: new ( RefCell :: new ( Activations :: new ( now) ) ) ,
276279 active_dataflows : Default :: default ( ) ,
277280 temp_channel_ids : Default :: default ( ) ,
@@ -407,7 +410,7 @@ impl<A: Allocate> Worker<A> {
407410 }
408411
409412 // Clean up, indicate if dataflows remain.
410- self . logging . borrow_mut ( ) . flush ( ) ;
413+ self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) . flush ( ) ) ;
411414 self . allocator . borrow_mut ( ) . release ( ) ;
412415 !self . dataflows . borrow ( ) . is_empty ( )
413416 }
@@ -478,7 +481,7 @@ impl<A: Allocate> Worker<A> {
478481 ///
479482 /// let index = worker.index();
480483 /// let peers = worker.peers();
481- /// let timer = worker.timer();
484+ /// let timer = worker.timer().unwrap() ;
482485 ///
483486 /// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
484487 ///
@@ -493,7 +496,7 @@ impl<A: Allocate> Worker<A> {
493496 ///
494497 /// let index = worker.index();
495498 /// let peers = worker.peers();
496- /// let timer = worker.timer();
499+ /// let timer = worker.timer().unwrap() ;
497500 ///
498501 /// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
499502 ///
@@ -509,13 +512,13 @@ impl<A: Allocate> Worker<A> {
509512 ///
510513 /// let index = worker.index();
511514 /// let peers = worker.peers();
512- /// let timer = worker.timer();
515+ /// let timer = worker.timer().unwrap() ;
513516 ///
514517 /// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
515518 ///
516519 /// });
517520 /// ```
518- pub fn timer ( & self ) -> Instant { self . timer }
521+ pub fn timer ( & self ) -> Option < Instant > { self . timer }
519522
520523 /// Allocate a new worker-unique identifier.
521524 ///
@@ -534,13 +537,14 @@ impl<A: Allocate> Worker<A> {
534537 /// timely::execute_from_args(::std::env::args(), |worker| {
535538 ///
536539 /// worker.log_register()
540+ /// .unwrap()
537541 /// .insert::<timely::logging::TimelyEvent,_>("timely", |time, data|
538542 /// println!("{:?}\t{:?}", time, data)
539543 /// );
540544 /// });
541545 /// ```
542- pub fn log_register ( & self ) -> :: std:: cell:: RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > {
543- self . logging . borrow_mut ( )
546+ pub fn log_register ( & self ) -> Option < :: std:: cell:: RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > > {
547+ self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) )
544548 }
545549
546550 /// Construct a new dataflow.
@@ -563,7 +567,7 @@ impl<A: Allocate> Worker<A> {
563567 T : Refines < ( ) > ,
564568 F : FnOnce ( & mut Child < Self , T > ) ->R ,
565569 {
566- let logging = self . logging . borrow_mut ( ) . get ( "timely" ) ;
570+ let logging = self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) ) . and_then ( |l| l . get ( "timely" ) ) ;
567571 self . dataflow_core ( "Dataflow" , logging, Box :: new ( ( ) ) , |_, child| func ( child) )
568572 }
569573
@@ -587,7 +591,7 @@ impl<A: Allocate> Worker<A> {
587591 T : Refines < ( ) > ,
588592 F : FnOnce ( & mut Child < Self , T > ) ->R ,
589593 {
590- let logging = self . logging . borrow_mut ( ) . get ( "timely" ) ;
594+ let logging = self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) ) . and_then ( |l| l . get ( "timely" ) ) ;
591595 self . dataflow_core ( name, logging, Box :: new ( ( ) ) , |_, child| func ( child) )
592596 }
593597
@@ -626,7 +630,7 @@ impl<A: Allocate> Worker<A> {
626630 let dataflow_index = self . allocate_dataflow_index ( ) ;
627631 let identifier = self . new_identifier ( ) ;
628632
629- let progress_logging = self . logging . borrow_mut ( ) . get ( "timely/progress" ) ;
633+ let progress_logging = self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) ) . and_then ( |l| l . get ( "timely/progress" ) ) ;
630634 let subscope = SubgraphBuilder :: new_from ( dataflow_index, addr, logging. clone ( ) , progress_logging. clone ( ) , name) ;
631635 let subscope = RefCell :: new ( subscope) ;
632636
0 commit comments