@@ -228,10 +228,11 @@ impl ExecutingGraph {
228
228
pub unsafe fn init_schedule_queue (
229
229
locker : & StateLockGuard ,
230
230
capacity : usize ,
231
+ graph : & Arc < RunningGraph > ,
231
232
) -> Result < ScheduleQueue > {
232
233
let mut schedule_queue = ScheduleQueue :: with_capacity ( capacity) ;
233
234
for sink_index in locker. graph . externals ( Direction :: Outgoing ) {
234
- ExecutingGraph :: schedule_queue ( locker, sink_index, & mut schedule_queue) ?;
235
+ ExecutingGraph :: schedule_queue ( locker, sink_index, & mut schedule_queue, graph ) ?;
235
236
}
236
237
237
238
Ok ( schedule_queue)
@@ -244,6 +245,7 @@ impl ExecutingGraph {
244
245
locker : & StateLockGuard ,
245
246
index : NodeIndex ,
246
247
schedule_queue : & mut ScheduleQueue ,
248
+ graph : & Arc < RunningGraph > ,
247
249
) -> Result < ( ) > {
248
250
let mut need_schedule_nodes = VecDeque :: new ( ) ;
249
251
let mut need_schedule_edges = VecDeque :: new ( ) ;
@@ -304,11 +306,17 @@ impl ExecutingGraph {
304
306
}
305
307
Event :: NeedData | Event :: NeedConsume => State :: Idle ,
306
308
Event :: Sync => {
307
- schedule_queue. push_sync ( node. processor . clone ( ) ) ;
309
+ schedule_queue. push_sync ( ProcessorWrapper {
310
+ processor : node. processor . clone ( ) ,
311
+ graph : graph. clone ( ) ,
312
+ } ) ;
308
313
State :: Processing
309
314
}
310
315
Event :: Async => {
311
- schedule_queue. push_async ( node. processor . clone ( ) ) ;
316
+ schedule_queue. push_async ( ProcessorWrapper {
317
+ processor : node. processor . clone ( ) ,
318
+ graph : graph. clone ( ) ,
319
+ } ) ;
312
320
State :: Processing
313
321
}
314
322
} ;
@@ -322,9 +330,15 @@ impl ExecutingGraph {
322
330
}
323
331
}
324
332
333
+ #[ derive( Clone ) ]
334
+ pub struct ProcessorWrapper {
335
+ pub processor : ProcessorPtr ,
336
+ pub graph : Arc < RunningGraph > ,
337
+ }
338
+
325
339
pub struct ScheduleQueue {
326
- pub sync_queue : VecDeque < ProcessorPtr > ,
327
- pub async_queue : VecDeque < ProcessorPtr > ,
340
+ pub sync_queue : VecDeque < ProcessorWrapper > ,
341
+ pub async_queue : VecDeque < ProcessorWrapper > ,
328
342
}
329
343
330
344
impl ScheduleQueue {
@@ -336,25 +350,15 @@ impl ScheduleQueue {
336
350
}
337
351
338
352
#[ inline]
339
- pub fn push_sync ( & mut self , processor : ProcessorPtr ) {
353
+ pub fn push_sync ( & mut self , processor : ProcessorWrapper ) {
340
354
self . sync_queue . push_back ( processor) ;
341
355
}
342
356
343
357
#[ inline]
344
- pub fn push_async ( & mut self , processor : ProcessorPtr ) {
358
+ pub fn push_async ( & mut self , processor : ProcessorWrapper ) {
345
359
self . async_queue . push_back ( processor) ;
346
360
}
347
361
348
- pub fn schedule_tail ( mut self , global : & ExecutorTasksQueue , ctx : & mut ExecutorWorkerContext ) {
349
- let mut tasks = VecDeque :: with_capacity ( self . sync_queue . len ( ) ) ;
350
-
351
- while let Some ( processor) = self . sync_queue . pop_front ( ) {
352
- tasks. push_back ( ExecutorTask :: Sync ( processor) ) ;
353
- }
354
-
355
- global. push_tasks ( ctx, tasks)
356
- }
357
-
358
362
pub fn schedule (
359
363
mut self ,
360
364
global : & Arc < ExecutorTasksQueue > ,
@@ -384,7 +388,7 @@ impl ScheduleQueue {
384
388
}
385
389
386
390
pub fn schedule_async_task (
387
- proc : ProcessorPtr ,
391
+ proc : ProcessorWrapper ,
388
392
query_id : Arc < String > ,
389
393
executor : & Arc < PipelineExecutor > ,
390
394
wakeup_worker_id : usize ,
@@ -394,18 +398,20 @@ impl ScheduleQueue {
394
398
unsafe {
395
399
workers_condvar. inc_active_async_worker ( ) ;
396
400
let weak_executor = Arc :: downgrade ( executor) ;
397
- let node_profile = executor. graph . get_node_profile ( proc. id ( ) ) . clone ( ) ;
398
- let process_future = proc. async_process ( ) ;
401
+ let graph = proc. graph ;
402
+ let node_profile = executor. graph . get_node_profile ( proc. processor . id ( ) ) . clone ( ) ;
403
+ let process_future = proc. processor . async_process ( ) ;
399
404
executor. async_runtime . spawn (
400
405
query_id. as_ref ( ) . clone ( ) ,
401
406
TrackedFuture :: create ( ProcessorAsyncTask :: create (
402
407
query_id,
403
408
wakeup_worker_id,
404
- proc. clone ( ) ,
409
+ proc. processor . clone ( ) ,
405
410
global_queue,
406
411
workers_condvar,
407
412
weak_executor,
408
413
node_profile,
414
+ graph,
409
415
process_future,
410
416
) )
411
417
. in_span ( Span :: enter_with_local_parent ( std:: any:: type_name :: <
@@ -420,36 +426,46 @@ impl ScheduleQueue {
420
426
ctx. set_task ( ExecutorTask :: Sync ( processor) ) ;
421
427
}
422
428
}
429
+
430
+ pub fn schedule_tail ( mut self , global : & ExecutorTasksQueue , ctx : & mut ExecutorWorkerContext ) {
431
+ let mut tasks = VecDeque :: with_capacity ( self . sync_queue . len ( ) ) ;
432
+
433
+ while let Some ( processor) = self . sync_queue . pop_front ( ) {
434
+ tasks. push_back ( ExecutorTask :: Sync ( processor) ) ;
435
+ }
436
+
437
+ global. push_tasks ( ctx, tasks)
438
+ }
423
439
}
424
440
425
441
pub struct RunningGraph ( ExecutingGraph ) ;
426
442
427
443
impl RunningGraph {
428
- pub fn create ( pipeline : Pipeline ) -> Result < RunningGraph > {
444
+ pub fn create ( pipeline : Pipeline ) -> Result < Arc < RunningGraph > > {
429
445
let graph_state = ExecutingGraph :: create ( pipeline) ?;
430
446
debug ! ( "Create running graph:{:?}" , graph_state) ;
431
- Ok ( RunningGraph ( graph_state) )
447
+ Ok ( Arc :: new ( RunningGraph ( graph_state) ) )
432
448
}
433
449
434
- pub fn from_pipelines ( pipelines : Vec < Pipeline > ) -> Result < RunningGraph > {
450
+ pub fn from_pipelines ( pipelines : Vec < Pipeline > ) -> Result < Arc < RunningGraph > > {
435
451
let graph_state = ExecutingGraph :: from_pipelines ( pipelines) ?;
436
452
debug ! ( "Create running graph:{:?}" , graph_state) ;
437
- Ok ( RunningGraph ( graph_state) )
453
+ Ok ( Arc :: new ( RunningGraph ( graph_state) ) )
438
454
}
439
455
440
456
/// # Safety
441
457
///
442
458
/// Method is thread unsafe and require thread safe call
443
- pub unsafe fn init_schedule_queue ( & self , capacity : usize ) -> Result < ScheduleQueue > {
444
- ExecutingGraph :: init_schedule_queue ( & self . 0 , capacity)
459
+ pub unsafe fn init_schedule_queue ( self : Arc < Self > , capacity : usize ) -> Result < ScheduleQueue > {
460
+ ExecutingGraph :: init_schedule_queue ( & self . 0 , capacity, & self )
445
461
}
446
462
447
463
/// # Safety
448
464
///
449
465
/// Method is thread unsafe and require thread safe call
450
- pub unsafe fn schedule_queue ( & self , node_index : NodeIndex ) -> Result < ScheduleQueue > {
466
+ pub unsafe fn schedule_queue ( self : Arc < Self > , node_index : NodeIndex ) -> Result < ScheduleQueue > {
451
467
let mut schedule_queue = ScheduleQueue :: with_capacity ( 0 ) ;
452
- ExecutingGraph :: schedule_queue ( & self . 0 , node_index, & mut schedule_queue) ?;
468
+ ExecutingGraph :: schedule_queue ( & self . 0 , node_index, & mut schedule_queue, & self ) ?;
453
469
Ok ( schedule_queue)
454
470
}
455
471
@@ -627,15 +643,15 @@ impl Debug for ScheduleQueue {
627
643
628
644
for item in & self . sync_queue {
629
645
sync_queue. push ( QueueItem {
630
- id : item. id ( ) . index ( ) ,
631
- name : item. name ( ) . to_string ( ) ,
646
+ id : item. processor . id ( ) . index ( ) ,
647
+ name : item. processor . name ( ) . to_string ( ) ,
632
648
} )
633
649
}
634
650
635
651
for item in & self . async_queue {
636
652
async_queue. push ( QueueItem {
637
- id : item. id ( ) . index ( ) ,
638
- name : item. name ( ) . to_string ( ) ,
653
+ id : item. processor . id ( ) . index ( ) ,
654
+ name : item. processor . name ( ) . to_string ( ) ,
639
655
} )
640
656
}
641
657
0 commit comments