@@ -5,9 +5,10 @@ use crate::{
5
5
BenchmarkJobConclusion , BenchmarkJobStatus , BenchmarkRequest , BenchmarkRequestIndex ,
6
6
BenchmarkRequestStatus , BenchmarkRequestType , BenchmarkRequestWithErrors , BenchmarkSet ,
7
7
CodegenBackend , CollectionId , CollectorConfig , Commit , CommitType , CompileBenchmark , Date ,
8
- Index , Profile , QueuedCommit , Scenario , Target , BENCHMARK_JOB_STATUS_FAILURE_STR ,
9
- BENCHMARK_JOB_STATUS_IN_PROGRESS_STR , BENCHMARK_JOB_STATUS_QUEUED_STR ,
10
- BENCHMARK_JOB_STATUS_SUCCESS_STR , BENCHMARK_REQUEST_MASTER_STR , BENCHMARK_REQUEST_RELEASE_STR ,
8
+ Index , PendingBenchmarkRequests , Profile , QueuedCommit , Scenario , Target ,
9
+ BENCHMARK_JOB_STATUS_FAILURE_STR , BENCHMARK_JOB_STATUS_IN_PROGRESS_STR ,
10
+ BENCHMARK_JOB_STATUS_QUEUED_STR , BENCHMARK_JOB_STATUS_SUCCESS_STR ,
11
+ BENCHMARK_REQUEST_MASTER_STR , BENCHMARK_REQUEST_RELEASE_STR ,
11
12
BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR , BENCHMARK_REQUEST_STATUS_COMPLETED_STR ,
12
13
BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR , BENCHMARK_REQUEST_STATUS_WAITING_FOR_ARTIFACTS_STR ,
13
14
BENCHMARK_REQUEST_TRY_STR ,
@@ -500,6 +501,7 @@ pub struct CachedStatements {
500
501
get_compile_test_cases_with_measurements : Statement ,
501
502
get_last_n_completed_requests_with_errors : Statement ,
502
503
get_jobs_of_in_progress_benchmark_requests : Statement ,
504
+ load_pending_benchmark_requests : Statement ,
503
505
}
504
506
505
507
pub struct PostgresTransaction < ' a > {
@@ -683,7 +685,7 @@ impl PostgresConnection {
683
685
where aid = $1
684
686
" ) . await . unwrap ( ) ,
685
687
load_benchmark_request_index : conn. prepare ( "
686
- SELECT tag, status
688
+ SELECT tag
687
689
FROM benchmark_request
688
690
WHERE tag IS NOT NULL
689
691
" ) . await . unwrap ( ) ,
@@ -751,6 +753,18 @@ impl PostgresConnection {
751
753
-- Only get the jobs of in_progress requests
752
754
SELECT * FROM job_queue INNER JOIN requests ON job_queue.request_tag = requests.tag
753
755
" ) ) . await . unwrap ( ) ,
756
+ // Load pending benchmark requests, along with information whether their parent is
757
+ // completed or not
758
+ load_pending_benchmark_requests : conn. prepare ( & format ! ( "
759
+ WITH pending AS (
760
+ SELECT {BENCHMARK_REQUEST_COLUMNS}
761
+ FROM benchmark_request AS req
762
+ WHERE status IN ('{BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR}', '{BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR}')
763
+ )
764
+ SELECT (parent.status = '{BENCHMARK_REQUEST_STATUS_COMPLETED_STR}') AS parent_done, pending.*
765
+ FROM pending
766
+ LEFT JOIN benchmark_request as parent ON parent.tag = pending.parent_sha
767
+ " ) ) . await . unwrap ( ) ,
754
768
} ) ,
755
769
conn,
756
770
}
@@ -809,7 +823,7 @@ where
809
823
None => Date ( Utc . with_ymd_and_hms ( 2001 , 1 , 1 , 0 , 0 , 0 ) . unwrap ( ) ) ,
810
824
}
811
825
} ,
812
- r#type : CommitType :: from_str ( & row. get :: < _ , String > ( 3 ) ) . unwrap ( )
826
+ r#type : CommitType :: from_str ( & row. get :: < _ , String > ( 3 ) ) . unwrap ( ) ,
813
827
} ,
814
828
)
815
829
} )
@@ -1188,13 +1202,13 @@ where
1188
1202
Some ( aid) => aid. get :: < _ , i32 > ( 0 ) as u32 ,
1189
1203
None => {
1190
1204
self . conn ( )
1191
- . query_opt ( "insert into artifact (name, date, type) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING RETURNING id" , & [
1192
- & info. name ,
1193
- & info. date ,
1194
- & info. kind ,
1195
- ] )
1196
- . await
1197
- . unwrap ( ) ;
1205
+ . query_opt ( "insert into artifact (name, date, type) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING RETURNING id" , & [
1206
+ & info. name ,
1207
+ & info. date ,
1208
+ & info. kind ,
1209
+ ] )
1210
+ . await
1211
+ . unwrap ( ) ;
1198
1212
self . conn ( )
1199
1213
. query_one ( "select id from artifact where name = $1" , & [ & info. name ] )
1200
1214
. await
@@ -1623,18 +1637,11 @@ where
1623
1637
. await
1624
1638
. context ( "Cannot load benchmark request index" ) ?;
1625
1639
1626
- let mut all = HashSet :: with_capacity ( requests. len ( ) ) ;
1627
- let mut completed = HashSet :: with_capacity ( requests. len ( ) ) ;
1628
- for request in requests {
1629
- let tag = request. get :: < _ , String > ( 0 ) ;
1630
- let status = request. get :: < _ , & str > ( 1 ) ;
1631
-
1632
- if status == BENCHMARK_REQUEST_STATUS_COMPLETED_STR {
1633
- completed. insert ( tag. clone ( ) ) ;
1634
- }
1635
- all. insert ( tag) ;
1636
- }
1637
- Ok ( BenchmarkRequestIndex { all, completed } )
1640
+ let all = requests
1641
+ . into_iter ( )
1642
+ . map ( |row| row. get :: < _ , String > ( 0 ) )
1643
+ . collect ( ) ;
1644
+ Ok ( BenchmarkRequestIndex { all } )
1638
1645
}
1639
1646
1640
1647
async fn update_benchmark_request_status (
@@ -1705,25 +1712,30 @@ where
1705
1712
Ok ( ( ) )
1706
1713
}
1707
1714
1708
- async fn load_pending_benchmark_requests ( & self ) -> anyhow:: Result < Vec < BenchmarkRequest > > {
1709
- let query = format ! (
1710
- r#"
1711
- SELECT {BENCHMARK_REQUEST_COLUMNS}
1712
- FROM benchmark_request
1713
- WHERE status IN('{BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR}', '{BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR}')"#
1714
- ) ;
1715
-
1715
+ async fn load_pending_benchmark_requests ( & self ) -> anyhow:: Result < PendingBenchmarkRequests > {
1716
1716
let rows = self
1717
1717
. conn ( )
1718
- . query ( & query , & [ ] )
1718
+ . query ( & self . statements ( ) . load_pending_benchmark_requests , & [ ] )
1719
1719
. await
1720
1720
. context ( "Failed to get pending benchmark requests" ) ?;
1721
1721
1722
- let requests = rows
1723
- . into_iter ( )
1724
- . map ( |it| row_to_benchmark_request ( & it, None ) )
1725
- . collect ( ) ;
1726
- Ok ( requests)
1722
+ let mut completed_parent_tags = HashSet :: new ( ) ;
1723
+ let mut requests = Vec :: with_capacity ( rows. len ( ) ) ;
1724
+ for row in rows {
1725
+ let parent_done = row. get :: < _ , Option < bool > > ( 0 ) ;
1726
+ let request = row_to_benchmark_request ( & row, Some ( 1 ) ) ;
1727
+ if let Some ( true ) = parent_done {
1728
+ if let Some ( parent) = request. parent_sha ( ) {
1729
+ completed_parent_tags. insert ( parent. to_string ( ) ) ;
1730
+ }
1731
+ }
1732
+ requests. push ( request) ;
1733
+ }
1734
+
1735
+ Ok ( PendingBenchmarkRequests {
1736
+ requests,
1737
+ completed_parent_tags,
1738
+ } )
1727
1739
}
1728
1740
1729
1741
async fn enqueue_benchmark_job (
0 commit comments