@@ -198,23 +198,27 @@ pub trait AsWorker : Scheduler {
198
198
/// The next worker-unique identifier to be allocated.
199
199
fn peek_identifier ( & self ) -> usize ;
200
200
/// Provides access to named logging streams.
201
- fn log_register ( & self ) -> :: std:: cell:: RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > ;
201
+ fn log_register ( & self ) -> Option < :: std:: cell:: RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > > ;
202
202
/// Provides access to the timely logging stream.
203
- fn logging ( & self ) -> Option < crate :: logging:: TimelyLogger > { self . log_register ( ) . get ( "timely" ) }
203
+ fn logging ( & self ) -> Option < crate :: logging:: TimelyLogger > { self . log_register ( ) . and_then ( |l| l . get ( "timely" ) ) }
204
204
}
205
205
206
206
/// A `Worker` is the entry point to a timely dataflow computation. It wraps a `Allocate`,
207
207
/// and has a list of dataflows that it manages.
208
208
pub struct Worker < A : Allocate > {
209
209
config : Config ,
210
- timer : Instant ,
210
+ /// An optional instant from which the start of the computation should be reckoned.
211
+ ///
212
+ /// If this is set to none, system time-based functionality will be unavailable or work badly.
213
+ /// For example, logging will be unavailable, and activation after a delay will be unavailable.
214
+ timer : Option < Instant > ,
211
215
paths : Rc < RefCell < HashMap < usize , Rc < [ usize ] > > > > ,
212
216
allocator : Rc < RefCell < A > > ,
213
217
identifiers : Rc < RefCell < usize > > ,
214
218
// dataflows: Rc<RefCell<Vec<Wrapper>>>,
215
219
dataflows : Rc < RefCell < HashMap < usize , Wrapper > > > ,
216
220
dataflow_counter : Rc < RefCell < usize > > ,
217
- logging : Rc < RefCell < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > > ,
221
+ logging : Option < Rc < RefCell < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > > > ,
218
222
219
223
activations : Rc < RefCell < Activations > > ,
220
224
active_dataflows : Vec < usize > ,
@@ -245,7 +249,7 @@ impl<A: Allocate> AsWorker for Worker<A> {
245
249
246
250
fn new_identifier ( & mut self ) -> usize { self . new_identifier ( ) }
247
251
fn peek_identifier ( & self ) -> usize { self . peek_identifier ( ) }
248
- fn log_register ( & self ) -> RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > {
252
+ fn log_register ( & self ) -> Option < RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > > {
249
253
self . log_register ( )
250
254
}
251
255
}
@@ -258,8 +262,7 @@ impl<A: Allocate> Scheduler for Worker<A> {
258
262
259
263
impl < A : Allocate > Worker < A > {
260
264
/// Allocates a new `Worker` bound to a channel allocator.
261
- pub fn new ( config : Config , c : A ) -> Worker < A > {
262
- let now = Instant :: now ( ) ;
265
+ pub fn new ( config : Config , c : A , now : Option < std:: time:: Instant > ) -> Worker < A > {
263
266
let index = c. index ( ) ;
264
267
Worker {
265
268
config,
@@ -269,7 +272,7 @@ impl<A: Allocate> Worker<A> {
269
272
identifiers : Default :: default ( ) ,
270
273
dataflows : Default :: default ( ) ,
271
274
dataflow_counter : Default :: default ( ) ,
272
- logging : Rc :: new ( RefCell :: new ( crate :: logging_core:: Registry :: new ( now, index) ) ) ,
275
+ logging : now . map ( |now| Rc :: new ( RefCell :: new ( crate :: logging_core:: Registry :: new ( now, index) ) ) ) ,
273
276
activations : Rc :: new ( RefCell :: new ( Activations :: new ( now) ) ) ,
274
277
active_dataflows : Default :: default ( ) ,
275
278
temp_channel_ids : Default :: default ( ) ,
@@ -405,7 +408,7 @@ impl<A: Allocate> Worker<A> {
405
408
}
406
409
407
410
// Clean up, indicate if dataflows remain.
408
- self . logging . borrow_mut ( ) . flush ( ) ;
411
+ self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) . flush ( ) ) ;
409
412
self . allocator . borrow_mut ( ) . release ( ) ;
410
413
!self . dataflows . borrow ( ) . is_empty ( )
411
414
}
@@ -476,7 +479,7 @@ impl<A: Allocate> Worker<A> {
476
479
///
477
480
/// let index = worker.index();
478
481
/// let peers = worker.peers();
479
- /// let timer = worker.timer();
482
+ /// let timer = worker.timer().unwrap() ;
480
483
///
481
484
/// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
482
485
///
@@ -491,7 +494,7 @@ impl<A: Allocate> Worker<A> {
491
494
///
492
495
/// let index = worker.index();
493
496
/// let peers = worker.peers();
494
- /// let timer = worker.timer();
497
+ /// let timer = worker.timer().unwrap() ;
495
498
///
496
499
/// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
497
500
///
@@ -507,13 +510,13 @@ impl<A: Allocate> Worker<A> {
507
510
///
508
511
/// let index = worker.index();
509
512
/// let peers = worker.peers();
510
- /// let timer = worker.timer();
513
+ /// let timer = worker.timer().unwrap() ;
511
514
///
512
515
/// println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);
513
516
///
514
517
/// });
515
518
/// ```
516
- pub fn timer ( & self ) -> Instant { self . timer }
519
+ pub fn timer ( & self ) -> Option < Instant > { self . timer }
517
520
518
521
/// Allocate a new worker-unique identifier.
519
522
///
@@ -537,13 +540,14 @@ impl<A: Allocate> Worker<A> {
537
540
/// timely::execute_from_args(::std::env::args(), |worker| {
538
541
///
539
542
/// worker.log_register()
543
+ /// .unwrap()
540
544
/// .insert::<timely::logging::TimelyEvent,_>("timely", |time, data|
541
545
/// println!("{:?}\t{:?}", time, data)
542
546
/// );
543
547
/// });
544
548
/// ```
545
- pub fn log_register ( & self ) -> :: std:: cell:: RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > {
546
- self . logging . borrow_mut ( )
549
+ pub fn log_register ( & self ) -> Option < :: std:: cell:: RefMut < crate :: logging_core:: Registry < crate :: logging:: WorkerIdentifier > > > {
550
+ self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) )
547
551
}
548
552
549
553
/// Construct a new dataflow.
@@ -566,7 +570,7 @@ impl<A: Allocate> Worker<A> {
566
570
T : Refines < ( ) > ,
567
571
F : FnOnce ( & mut Child < Self , T > ) ->R ,
568
572
{
569
- let logging = self . logging . borrow_mut ( ) . get ( "timely" ) ;
573
+ let logging = self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) ) . and_then ( |l| l . get ( "timely" ) ) ;
570
574
self . dataflow_core ( "Dataflow" , logging, Box :: new ( ( ) ) , |_, child| func ( child) )
571
575
}
572
576
@@ -590,7 +594,7 @@ impl<A: Allocate> Worker<A> {
590
594
T : Refines < ( ) > ,
591
595
F : FnOnce ( & mut Child < Self , T > ) ->R ,
592
596
{
593
- let logging = self . logging . borrow_mut ( ) . get ( "timely" ) ;
597
+ let logging = self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) ) . and_then ( |l| l . get ( "timely" ) ) ;
594
598
self . dataflow_core ( name, logging, Box :: new ( ( ) ) , |_, child| func ( child) )
595
599
}
596
600
@@ -629,7 +633,7 @@ impl<A: Allocate> Worker<A> {
629
633
let addr = vec ! [ dataflow_index] . into ( ) ;
630
634
let identifier = self . new_identifier ( ) ;
631
635
632
- let progress_logging = self . logging . borrow_mut ( ) . get ( "timely/progress" ) ;
636
+ let progress_logging = self . logging . as_ref ( ) . map ( |l| l . borrow_mut ( ) ) . and_then ( |l| l . get ( "timely/progress" ) ) ;
633
637
let subscope = SubgraphBuilder :: new_from ( addr, logging. clone ( ) , progress_logging. clone ( ) , name) ;
634
638
let subscope = RefCell :: new ( subscope) ;
635
639
0 commit comments