Skip to content

Commit f7f9747

Browse files
committed
PR Feedback; remove get_request_id(), reformat schema description, benchmark set made into a a struct
1 parent 00603e2 commit f7f9747

File tree

6 files changed

+52
-93
lines changed

6 files changed

+52
-93
lines changed

database/schema.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,28 @@ collector which benchmarks it should execute. The jobs will be kept in the
303303
table for ~30 days after being completed, so that we can quickly figure out
304304
what master parent jobs we need to backfill when handling try builds.
305305

306-
```
307-
psql# SELECT * FROM job_queue limit 1;
306+
Columns:
308307

309-
id request_id target backend benchmark_set collector_id created_at started_at completed_at status retry error
310-
--- ----------- -------- -------- ------------- -------------- --------------------------- --------------------------- --------------------------- --------- ------ --------
311-
23 7 AArch64 llvm 5 collector-1 2025-07-10 09:00:00.123+00 2025-07-10 09:05:02.456+00 2025-07-10 09:15:17.890+00 complete 0
312-
```
308+
- **id** (`bigint` / `serial`): Primary-key identifier for the job row;
309+
auto-increments with each new job.
310+
- **request_id** (`bigint`): References the parent benchmark request that
311+
spawned this job.
312+
- **target** (`text NOT NULL`): Hardware/ISA the benchmarks must run on
313+
(e.g. AArch64, x86_64).
314+
- **backend** (`text NOT NULL`): Code generation backend the collector should
315+
test (e.g. llvm, cranelift).
316+
- **benchmark_set** (`int NOT NULL`): ID of the predefined benchmark suite to
317+
execute.
318+
- **collector_id** (`text`): Id of the collector that claimed the job
319+
(populated once the job is started).
320+
- **created_at** (`timestamptz NOT NULL`): Datetime when the job was queued.
321+
- **started_at** (`timestamptz`): Datetime when the collector actually began
322+
running the benchmarks; NULL until the job is claimed.
323+
- **completed_at** (`timestampt`): Datetime when the collector finished
324+
(successfully or otherwise); used to purge rows after ~30 days.
325+
- **status** (`text NOT NULL`): Current job state. `queued`, `in_progress`,
326+
`success`, or `failure`.
327+
- **retry** (`int NOT NULL`): Number of times the job has been re-queued after
328+
a failure; 0 on the first attempt.
329+
- **error** (`text`): Optional error message or stack trace from the last
330+
failed run; NULL when the job succeeded.

database/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ impl BenchmarkRequestIndex {
10151015
}
10161016

10171017
pub fn add_tag(&mut self, tag: &str) {
1018+
self.all.insert(tag.to_string());
10181019
self.completed.insert(tag.to_string());
10191020
}
10201021
}
@@ -1049,13 +1050,16 @@ impl fmt::Display for BenchmarkJobStatus {
10491050
}
10501051
}
10511052

1053+
#[derive(Debug, Clone, PartialEq)]
1054+
pub struct BenchmarkSet(u32);
1055+
10521056
#[derive(Debug, Clone, PartialEq)]
10531057
pub struct BenchmarkJob {
10541058
target: Target,
10551059
backend: CodegenBackend,
1056-
benchmark_set: u32,
1060+
benchmark_set: BenchmarkSet,
10571061
collector_id: String,
1058-
created_at: Option<DateTime<Utc>>,
1062+
created_at: DateTime<Utc>,
10591063
started_at: Option<DateTime<Utc>>,
10601064
completed_at: Option<DateTime<Utc>>,
10611065
status: BenchmarkJobStatus,
@@ -1068,14 +1072,15 @@ impl BenchmarkJob {
10681072
backend: CodegenBackend,
10691073
benchmark_set: u32,
10701074
collector_id: &str,
1075+
created_at: DateTime<Utc>,
10711076
status: BenchmarkJobStatus,
10721077
) -> Self {
10731078
BenchmarkJob {
10741079
target,
10751080
backend,
1076-
benchmark_set,
1081+
benchmark_set: BenchmarkSet(benchmark_set),
10771082
collector_id: collector_id.to_string(),
1078-
created_at: None,
1083+
created_at,
10791084
started_at: None,
10801085
completed_at: None,
10811086
status,

database/src/pool.rs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,11 @@ pub trait Connection: Send + Sync {
213213

214214
/// Try and mark the benchmark_request as completed. Will return `true` if
215215
/// it has been marked as completed else `false` meaning there was no change
216-
async fn try_mark_benchmark_request_as_completed(
216+
async fn mark_benchmark_request_as_completed(
217217
&self,
218218
benchmark_request: &mut BenchmarkRequest,
219219
) -> anyhow::Result<bool>;
220220

221-
/// Given a benchmark request get the id
222-
async fn get_benchmark_request_id(
223-
&self,
224-
benchmark_request: &BenchmarkRequest,
225-
) -> anyhow::Result<u32>;
226-
227221
/// Insert a benchmark job into the `job_queue`
228222
async fn insert_benchmark_job(
229223
&self,
@@ -653,6 +647,7 @@ mod tests {
653647
CodegenBackend::Llvm,
654648
3,
655649
"collector 1",
650+
Utc::now(),
656651
BenchmarkJobStatus::Queued,
657652
);
658653

@@ -673,6 +668,7 @@ mod tests {
673668
CodegenBackend::Llvm,
674669
3,
675670
"collector 1",
671+
Utc::now(),
676672
BenchmarkJobStatus::Queued,
677673
);
678674
let request = create_try(
@@ -716,20 +712,22 @@ mod tests {
716712
CodegenBackend::Llvm,
717713
1,
718714
"collector 1",
715+
Utc::now(),
719716
BenchmarkJobStatus::Success,
720717
);
721718
let job_2 = BenchmarkJob::new(
722719
Target::X86_64UnknownLinuxGnu,
723720
CodegenBackend::Llvm,
724721
2,
725722
"collector 2",
723+
Utc::now(),
726724
BenchmarkJobStatus::Success,
727725
);
728726

729727
db_insert_jobs(&*db, request_id, &[job_1, job_2]).await;
730728

731729
assert!(db
732-
.try_mark_benchmark_request_as_completed(&mut request)
730+
.mark_benchmark_request_as_completed(&mut request)
733731
.await
734732
.is_err());
735733

@@ -761,20 +759,22 @@ mod tests {
761759
CodegenBackend::Llvm,
762760
1,
763761
"collector 1",
762+
Utc::now(),
764763
BenchmarkJobStatus::Success,
765764
);
766765
let job_2 = BenchmarkJob::new(
767766
Target::X86_64UnknownLinuxGnu,
768767
CodegenBackend::Llvm,
769768
2,
770769
"collector 2",
770+
Utc::now(),
771771
BenchmarkJobStatus::Success,
772772
);
773773

774774
db_insert_jobs(&*db, request_id, &[job_1, job_2]).await;
775775

776776
assert!(db
777-
.try_mark_benchmark_request_as_completed(&mut request)
777+
.mark_benchmark_request_as_completed(&mut request)
778778
.await
779779
.is_err());
780780

@@ -807,20 +807,22 @@ mod tests {
807807
CodegenBackend::Llvm,
808808
1,
809809
"collector 1",
810+
Utc::now(),
810811
BenchmarkJobStatus::InProgress,
811812
);
812813
let job_2 = BenchmarkJob::new(
813814
Target::X86_64UnknownLinuxGnu,
814815
CodegenBackend::Llvm,
815816
2,
816817
"collector 2",
818+
Utc::now(),
817819
BenchmarkJobStatus::Success,
818820
);
819821

820822
db_insert_jobs(&*db, request_id, &[job_1, job_2]).await;
821823

822824
assert!(db
823-
.try_mark_benchmark_request_as_completed(&mut request)
825+
.mark_benchmark_request_as_completed(&mut request)
824826
.await
825827
.is_ok());
826828
assert_eq!(request.status(), BenchmarkRequestStatus::InProgress);
@@ -853,20 +855,22 @@ mod tests {
853855
CodegenBackend::Llvm,
854856
1,
855857
"collector 1",
858+
Utc::now(),
856859
BenchmarkJobStatus::Success,
857860
);
858861
let job_2 = BenchmarkJob::new(
859862
Target::X86_64UnknownLinuxGnu,
860863
CodegenBackend::Llvm,
861864
2,
862865
"collector 2",
866+
Utc::now(),
863867
BenchmarkJobStatus::Success,
864868
);
865869

866870
db_insert_jobs(&*db, request_id, &[job_1, job_2]).await;
867871

868872
assert!(db
869-
.try_mark_benchmark_request_as_completed(&mut request)
873+
.mark_benchmark_request_as_completed(&mut request)
870874
.await
871875
.is_ok());
872876
// The struct should have been mutated
@@ -878,28 +882,4 @@ mod tests {
878882
})
879883
.await;
880884
}
881-
882-
#[tokio::test]
883-
async fn get_benchmark_request_id() {
884-
run_postgres_test(|ctx| async {
885-
let db = ctx.db_client();
886-
let db = db.connection().await;
887-
let request = create_try(
888-
Some("s1"),
889-
Some("p1"),
890-
3,
891-
Utc::now(),
892-
BenchmarkRequestStatus::InProgress,
893-
"",
894-
"",
895-
);
896-
db.insert_benchmark_request(&request).await.unwrap();
897-
898-
let retrieved = db.get_benchmark_request_id(&request).await.unwrap();
899-
assert_eq!(1, retrieved);
900-
901-
Ok(ctx)
902-
})
903-
.await;
904-
}
905885
}

database/src/pool/postgres.rs

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ where
16161616
Ok(requests)
16171617
}
16181618

1619-
async fn try_mark_benchmark_request_as_completed(
1619+
async fn mark_benchmark_request_as_completed(
16201620
&self,
16211621
benchmark_request: &mut BenchmarkRequest,
16221622
) -> anyhow::Result<bool> {
@@ -1677,43 +1677,6 @@ where
16771677
}
16781678
}
16791679

1680-
async fn get_benchmark_request_id(
1681-
&self,
1682-
benchmark_request: &BenchmarkRequest,
1683-
) -> anyhow::Result<u32> {
1684-
anyhow::ensure!(
1685-
benchmark_request.tag().is_some(),
1686-
"Benchmark request has no tag"
1687-
);
1688-
1689-
let row = self
1690-
.conn()
1691-
.query_opt(
1692-
"
1693-
SELECT
1694-
id
1695-
FROM
1696-
benchmark_request
1697-
WHERE
1698-
tag = $1
1699-
AND commit_type = $2
1700-
AND status = $3;",
1701-
&[
1702-
&benchmark_request.tag(),
1703-
&benchmark_request.commit_type,
1704-
&benchmark_request.status,
1705-
],
1706-
)
1707-
.await
1708-
.context("Failed to get id for benchmark_request")?;
1709-
1710-
if let Some(row) = row {
1711-
Ok(row.get::<_, i32>(0) as u32)
1712-
} else {
1713-
Ok(1)
1714-
}
1715-
}
1716-
17171680
async fn insert_benchmark_job(
17181681
&self,
17191682
request_id: u32,
@@ -1735,7 +1698,7 @@ where
17351698
&(request_id as i32),
17361699
&benchmark_job.target,
17371700
&benchmark_job.backend,
1738-
&(benchmark_job.benchmark_set as i32),
1701+
&(benchmark_job.benchmark_set.0 as i32),
17391702
&benchmark_job.collector_id,
17401703
&benchmark_job.status,
17411704
],

database/src/pool/sqlite.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,20 +1297,13 @@ impl Connection for SqliteConnection {
12971297
no_queue_implementation_abort!()
12981298
}
12991299

1300-
async fn try_mark_benchmark_request_as_completed(
1300+
async fn mark_benchmark_request_as_completed(
13011301
&self,
13021302
_benchmark_request: &mut BenchmarkRequest,
13031303
) -> anyhow::Result<bool> {
13041304
no_queue_implementation_abort!()
13051305
}
13061306

1307-
async fn get_benchmark_request_id(
1308-
&self,
1309-
_benchmark_request: &BenchmarkRequest,
1310-
) -> anyhow::Result<u32> {
1311-
no_queue_implementation_abort!()
1312-
}
1313-
13141307
async fn insert_benchmark_job(
13151308
&self,
13161309
_benchmark_request_id: u32,

site/src/job_queue/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ async fn enqueue_next_job(
189189
// .await?;
190190
break;
191191
} else if conn
192-
.try_mark_benchmark_request_as_completed(&mut request)
192+
.mark_benchmark_request_as_completed(&mut request)
193193
.await?
194194
{
195195
index.add_tag(request.tag().unwrap());

0 commit comments

Comments
 (0)