1
1
use crate :: {
2
2
metrics:: { self , record_metric, Endpoint , HasLabelsCore , Outcome } ,
3
- request_database:: { Handle , How } ,
3
+ request_database:: Handle ,
4
4
server_axum:: api_orchestrator_integration_impls:: * ,
5
5
} ;
6
6
@@ -389,12 +389,6 @@ async fn handle_core(
389
389
resp = rx. recv( ) => {
390
390
let resp = resp. expect( "The rx should never close as we have a tx" ) ;
391
391
392
- if let Ok ( MessageResponse :: ExecuteEnd { meta, .. } ) = & resp {
393
- if let Some ( ( _, _, Some ( db_id) ) ) = active_executions. get( & meta. sequence_number) {
394
- db. attempt_end_request( * db_id, How :: Complete ) . await ;
395
- }
396
- }
397
-
398
392
let success = resp. is_ok( ) ;
399
393
let resp = resp. unwrap_or_else( error_to_response) ;
400
394
let resp = response_to_message( resp) ;
@@ -443,7 +437,7 @@ async fn handle_core(
443
437
_ = active_execution_gc_interval. tick( ) => {
444
438
active_executions = mem:: take( & mut active_executions)
445
439
. into_iter( )
446
- . filter( |( _id, ( _, tx, _ ) ) | tx. as_ref( ) . map_or( false , |tx| !tx. is_closed( ) ) )
440
+ . filter( |( _id, ( _, tx) ) | tx. as_ref( ) . map_or( false , |tx| !tx. is_closed( ) ) )
447
441
. collect( ) ;
448
442
} ,
449
443
@@ -464,12 +458,6 @@ async fn handle_core(
464
458
}
465
459
}
466
460
467
- for ( _, ( _, _, db_id) ) in active_executions {
468
- if let Some ( db_id) = db_id {
469
- db. attempt_end_request ( db_id, How :: Abandoned ) . await ;
470
- }
471
- }
472
-
473
461
drop ( ( tx, rx, socket) ) ;
474
462
if let Err ( e) = manager. shutdown ( ) . await {
475
463
error ! ( "Could not shut down the Coordinator: {e:?}" ) ;
@@ -516,11 +504,7 @@ fn response_to_message(response: MessageResponse) -> Message {
516
504
Message :: Text ( resp)
517
505
}
518
506
519
- type ActiveExecutionInfo = (
520
- CancellationToken ,
521
- Option < mpsc:: Sender < String > > ,
522
- Option < crate :: request_database:: Id > ,
523
- ) ;
507
+ type ActiveExecutionInfo = ( CancellationToken , Option < mpsc:: Sender < String > > ) ;
524
508
525
509
async fn handle_msg (
526
510
txt : String ,
@@ -538,22 +522,31 @@ async fn handle_msg(
538
522
let token = CancellationToken :: new ( ) ;
539
523
let ( execution_tx, execution_rx) = mpsc:: channel ( 8 ) ;
540
524
541
- let id = db. attempt_start_request ( "ws.Execute" , & txt) . await ;
525
+ let guard = db. clone ( ) . start_with_guard ( "ws.Execute" , & txt) . await ;
542
526
543
- active_executions. insert (
544
- meta. sequence_number ,
545
- ( token. clone ( ) , Some ( execution_tx) , id) ,
546
- ) ;
527
+ active_executions. insert ( meta. sequence_number , ( token. clone ( ) , Some ( execution_tx) ) ) ;
547
528
548
529
// TODO: Should a single execute / build / etc. session have a timeout of some kind?
549
530
let spawned = manager
550
531
. spawn ( {
551
532
let tx = tx. clone ( ) ;
552
533
let meta = meta. clone ( ) ;
553
- |coordinator| {
554
- handle_execute ( token, execution_rx, tx, coordinator, payload, meta. clone ( ) )
555
- . context ( StreamingExecuteSnafu )
556
- . map_err ( |e| ( e, Some ( meta) ) )
534
+ |coordinator| async {
535
+ let r = handle_execute (
536
+ token,
537
+ execution_rx,
538
+ tx,
539
+ coordinator,
540
+ payload,
541
+ meta. clone ( ) ,
542
+ )
543
+ . context ( StreamingExecuteSnafu )
544
+ . map_err ( |e| ( e, Some ( meta) ) )
545
+ . await ;
546
+
547
+ guard. complete_now ( ) ;
548
+
549
+ r
557
550
}
558
551
} )
559
552
. await
@@ -565,8 +558,7 @@ async fn handle_msg(
565
558
}
566
559
567
560
Ok ( ExecuteStdin { payload, meta } ) => {
568
- let Some ( ( _, Some ( execution_tx) , _) ) = active_executions. get ( & meta. sequence_number )
569
- else {
561
+ let Some ( ( _, Some ( execution_tx) ) ) = active_executions. get ( & meta. sequence_number ) else {
570
562
warn ! ( "Received stdin for an execution that is no longer active" ) ;
571
563
return ;
572
564
} ;
@@ -582,8 +574,7 @@ async fn handle_msg(
582
574
}
583
575
584
576
Ok ( ExecuteStdinClose { meta } ) => {
585
- let Some ( ( _, execution_tx, _) ) = active_executions. get_mut ( & meta. sequence_number )
586
- else {
577
+ let Some ( ( _, execution_tx) ) = active_executions. get_mut ( & meta. sequence_number ) else {
587
578
warn ! ( "Received stdin close for an execution that is no longer active" ) ;
588
579
return ;
589
580
} ;
@@ -592,7 +583,7 @@ async fn handle_msg(
592
583
}
593
584
594
585
Ok ( ExecuteKill { meta } ) => {
595
- let Some ( ( token, _, _ ) ) = active_executions. get ( & meta. sequence_number ) else {
586
+ let Some ( ( token, _) ) = active_executions. get ( & meta. sequence_number ) else {
596
587
warn ! ( "Received kill for an execution that is no longer active" ) ;
597
588
return ;
598
589
} ;
0 commit comments