@@ -201,23 +201,33 @@ pub trait AsWorker : Scheduler {
201
201
/// The next worker-unique identifier to be allocated.
202
202
fn peek_identifier ( & self ) -> usize ;
203
203
/// 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
+ }
205
211
/// 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) }
207
213
}
208
214
209
215
/// A `Worker` is the entry point to a timely dataflow computation. It wraps a `Allocate`,
210
216
/// and has a list of dataflows that it manages.
211
217
pub struct Worker < A : Allocate > {
212
218
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 > ,
214
224
paths : Rc < RefCell < HashMap < usize , Rc < [ usize ] > > > > ,
215
225
allocator : Rc < RefCell < A > > ,
216
226
identifiers : Rc < RefCell < usize > > ,
217
227
// dataflows: Rc<RefCell<Vec<Wrapper>>>,
218
228
dataflows : Rc < RefCell < HashMap < usize , Wrapper > > > ,
219
229
dataflow_counter : Rc < RefCell < usize > > ,
220
- logging : Rc < RefCell < crate :: logging_core:: Registry > > ,
230
+ logging : Option < Rc < RefCell < crate :: logging_core:: Registry > > > ,
221
231
222
232
activations : Rc < RefCell < Activations > > ,
223
233
active_dataflows : Vec < usize > ,
@@ -255,7 +265,7 @@ impl<A: Allocate> AsWorker for Worker<A> {
255
265
256
266
fn new_identifier ( & mut self ) -> usize { self . new_identifier ( ) }
257
267
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 > > {
259
269
self . log_register ( )
260
270
}
261
271
}
@@ -268,8 +278,7 @@ impl<A: Allocate> Scheduler for Worker<A> {
268
278
269
279
impl < A : Allocate > Worker < A > {
270
280
/// 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 > {
273
282
Worker {
274
283
config,
275
284
timer : now,
@@ -278,7 +287,7 @@ impl<A: Allocate> Worker<A> {
278
287
identifiers : Default :: default ( ) ,
279
288
dataflows : Default :: default ( ) ,
280
289
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) ) ) ) ,
282
291
activations : Rc :: new ( RefCell :: new ( Activations :: new ( now) ) ) ,
283
292
active_dataflows : Default :: default ( ) ,
284
293
temp_channel_ids : Default :: default ( ) ,
@@ -414,7 +423,7 @@ impl<A: Allocate> Worker<A> {
414
423
}
415
424
416
425
// Clean up, indicate if dataflows remain.
417
- self . logging . borrow_mut ( ) . flush ( ) ;
426
+ self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) . flush ( ) ) ;
418
427
self . allocator . borrow_mut ( ) . release ( ) ;
419
428
!self . dataflows . borrow ( ) . is_empty ( )
420
429
}
@@ -485,7 +494,7 @@ impl<A: Allocate> Worker<A> {
485
494
///
486
495
/// let index = worker.index();
487
496
/// let peers = worker.peers();
488
- /// let timer = worker.timer();
497
+ /// let timer = worker.timer().unwrap() ;
489
498
///
490
499
/// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
491
500
///
@@ -500,7 +509,7 @@ impl<A: Allocate> Worker<A> {
500
509
///
501
510
/// let index = worker.index();
502
511
/// let peers = worker.peers();
503
- /// let timer = worker.timer();
512
+ /// let timer = worker.timer().unwrap() ;
504
513
///
505
514
/// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
506
515
///
@@ -516,13 +525,13 @@ impl<A: Allocate> Worker<A> {
516
525
///
517
526
/// let index = worker.index();
518
527
/// let peers = worker.peers();
519
- /// let timer = worker.timer();
528
+ /// let timer = worker.timer().unwrap() ;
520
529
///
521
530
/// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
522
531
///
523
532
/// });
524
533
/// ```
525
- pub fn timer ( & self ) -> Instant { self . timer }
534
+ pub fn timer ( & self ) -> Option < Instant > { self . timer }
526
535
527
536
/// Allocate a new worker-unique identifier.
528
537
///
@@ -546,13 +555,14 @@ impl<A: Allocate> Worker<A> {
546
555
/// timely::execute_from_args(::std::env::args(), |worker| {
547
556
///
548
557
/// worker.log_register()
558
+ /// .unwrap()
549
559
/// .insert::<timely::logging::TimelyEventBuilder,_>("timely", |time, data|
550
560
/// println!("{:?}\t{:?}", time, data)
551
561
/// );
552
562
/// });
553
563
/// ```
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 ( ) )
556
566
}
557
567
558
568
/// Construct a new dataflow.
@@ -575,8 +585,7 @@ impl<A: Allocate> Worker<A> {
575
585
T : Refines < ( ) > ,
576
586
F : FnOnce ( & mut Child < Self , T > ) ->R ,
577
587
{
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) )
580
589
}
581
590
582
591
/// Construct a new dataflow with a (purely cosmetic) name.
@@ -599,8 +608,7 @@ impl<A: Allocate> Worker<A> {
599
608
T : Refines < ( ) > ,
600
609
F : FnOnce ( & mut Child < Self , T > ) ->R ,
601
610
{
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) )
604
612
}
605
613
606
614
/// Construct a new dataflow with specific configurations.
@@ -639,8 +647,8 @@ impl<A: Allocate> Worker<A> {
639
647
let identifier = self . new_identifier ( ) ;
640
648
641
649
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 ) ) ;
644
652
let subscope = SubgraphBuilder :: new_from ( addr, identifier, logging. clone ( ) , summary_logging, name) ;
645
653
let subscope = RefCell :: new ( subscope) ;
646
654
@@ -735,7 +743,7 @@ impl<A: Allocate> Clone for Worker<A> {
735
743
identifiers : Rc :: clone ( & self . identifiers ) ,
736
744
dataflows : Rc :: clone ( & self . dataflows ) ,
737
745
dataflow_counter : Rc :: clone ( & self . dataflow_counter ) ,
738
- logging : Rc :: clone ( & self . logging ) ,
746
+ logging : self . logging . clone ( ) ,
739
747
activations : Rc :: clone ( & self . activations ) ,
740
748
active_dataflows : Vec :: new ( ) ,
741
749
temp_channel_ids : Rc :: clone ( & self . temp_channel_ids ) ,
0 commit comments