Skip to content

Commit eb422a5

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

File tree

5 files changed

+53
-105
lines changed

5 files changed

+53
-105
lines changed

database/schema.md

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

324-
```
325-
psql# SELECT * FROM job_queue limit 1;
324+
Columns:
326325

327-
id request_id target backend benchmark_set collector_id created_at started_at completed_at status retry error
328-
--- ----------- -------- -------- ------------- -------------- --------------------------- --------------------------- --------------------------- --------- ------ --------
329-
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
330-
```
331-
>>>>>>> d0ed82ff (Feat; job_queue table definition & mark a request as complete if all jobs are finished)
326+
- **id** (`bigint` / `serial`): Primary-key identifier for the job row;
327+
auto-increments with each new job.
328+
- **request_id** (`bigint`): References the parent benchmark request that
329+
spawned this job.
330+
- **target** (`text NOT NULL`): Hardware/ISA the benchmarks must run on
331+
(e.g. AArch64, x86_64).
332+
- **backend** (`text NOT NULL`): Code generation backend the collector should
333+
test (e.g. llvm, cranelift).
334+
- **benchmark_set** (`int NOT NULL`): ID of the predefined benchmark suite to
335+
execute.
336+
- **collector_id** (`text`): Id of the collector that claimed the job
337+
(populated once the job is started).
338+
- **created_at** (`timestamptz NOT NULL`): Datetime when the job was queued.
339+
- **started_at** (`timestamptz`): Datetime when the collector actually began
340+
running the benchmarks; NULL until the job is claimed.
341+
- **completed_at** (`timestampt`): Datetime when the collector finished
342+
(successfully or otherwise); used to purge rows after ~30 days.
343+
- **status** (`text NOT NULL`): Current job state. `queued`, `in_progress`,
344+
`success`, or `failure`.
345+
- **retry** (`int NOT NULL`): Number of times the job has been re-queued after
346+
a failure; 0 on the first attempt.
347+
- **error** (`text`): Optional error message or stack trace from the last
348+
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
@@ -1053,6 +1053,7 @@ impl BenchmarkRequestIndex {
10531053
}
10541054

10551055
pub fn add_tag(&mut self, tag: &str) {
1056+
self.all.insert(tag.to_string());
10561057
self.completed.insert(tag.to_string());
10571058
}
10581059
}
@@ -1087,13 +1088,16 @@ impl fmt::Display for BenchmarkJobStatus {
10871088
}
10881089
}
10891090

1091+
#[derive(Debug, Clone, PartialEq)]
1092+
pub struct BenchmarkSet(u32);
1093+
10901094
#[derive(Debug, Clone, PartialEq)]
10911095
pub struct BenchmarkJob {
10921096
target: Target,
10931097
backend: CodegenBackend,
1094-
benchmark_set: u32,
1098+
benchmark_set: BenchmarkSet,
10951099
collector_id: String,
1096-
created_at: Option<DateTime<Utc>>,
1100+
created_at: DateTime<Utc>,
10971101
started_at: Option<DateTime<Utc>>,
10981102
completed_at: Option<DateTime<Utc>>,
10991103
status: BenchmarkJobStatus,
@@ -1106,14 +1110,15 @@ impl BenchmarkJob {
11061110
backend: CodegenBackend,
11071111
benchmark_set: u32,
11081112
collector_id: &str,
1113+
created_at: DateTime<Utc>,
11091114
status: BenchmarkJobStatus,
11101115
) -> Self {
11111116
BenchmarkJob {
11121117
target,
11131118
backend,
1114-
benchmark_set,
1119+
benchmark_set: BenchmarkSet(benchmark_set),
11151120
collector_id: collector_id.to_string(),
1116-
created_at: None,
1121+
created_at,
11171122
started_at: None,
11181123
completed_at: None,
11191124
status,

database/src/pool.rs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,10 @@ pub trait Connection: Send + Sync {
235235

236236
/// Try and mark the benchmark_request as completed. Will return `true` if
237237
/// it has been marked as completed else `false` meaning there was no change
238-
async fn try_mark_benchmark_request_as_completed(
238+
async fn mark_benchmark_request_as_completed(
239239
&self,
240240
benchmark_request: &mut BenchmarkRequest,
241241
) -> anyhow::Result<bool>;
242-
243-
/// Given a benchmark request get the id
244-
async fn get_benchmark_request_id(
245-
&self,
246-
benchmark_request: &BenchmarkRequest,
247-
) -> anyhow::Result<u32>;
248242
}
249243

250244
#[async_trait::async_trait]
@@ -762,6 +756,7 @@ mod tests {
762756
CodegenBackend::Llvm,
763757
3,
764758
"collector 1",
759+
Utc::now(),
765760
BenchmarkJobStatus::Queued,
766761
);
767762

@@ -782,6 +777,7 @@ mod tests {
782777
CodegenBackend::Llvm,
783778
3,
784779
"collector 1",
780+
Utc::now(),
785781
BenchmarkJobStatus::Queued,
786782
);
787783
let request = create_try(
@@ -825,20 +821,22 @@ mod tests {
825821
CodegenBackend::Llvm,
826822
1,
827823
"collector 1",
824+
Utc::now(),
828825
BenchmarkJobStatus::Success,
829826
);
830827
let job_2 = BenchmarkJob::new(
831828
Target::X86_64UnknownLinuxGnu,
832829
CodegenBackend::Llvm,
833830
2,
834831
"collector 2",
832+
Utc::now(),
835833
BenchmarkJobStatus::Success,
836834
);
837835

838836
db_insert_jobs(&*db, request_id, &[job_1, job_2]).await;
839837

840838
assert!(db
841-
.try_mark_benchmark_request_as_completed(&mut request)
839+
.mark_benchmark_request_as_completed(&mut request)
842840
.await
843841
.is_err());
844842

@@ -870,20 +868,22 @@ mod tests {
870868
CodegenBackend::Llvm,
871869
1,
872870
"collector 1",
871+
Utc::now(),
873872
BenchmarkJobStatus::Success,
874873
);
875874
let job_2 = BenchmarkJob::new(
876875
Target::X86_64UnknownLinuxGnu,
877876
CodegenBackend::Llvm,
878877
2,
879878
"collector 2",
879+
Utc::now(),
880880
BenchmarkJobStatus::Success,
881881
);
882882

883883
db_insert_jobs(&*db, request_id, &[job_1, job_2]).await;
884884

885885
assert!(db
886-
.try_mark_benchmark_request_as_completed(&mut request)
886+
.mark_benchmark_request_as_completed(&mut request)
887887
.await
888888
.is_err());
889889

@@ -916,20 +916,22 @@ mod tests {
916916
CodegenBackend::Llvm,
917917
1,
918918
"collector 1",
919+
Utc::now(),
919920
BenchmarkJobStatus::InProgress,
920921
);
921922
let job_2 = BenchmarkJob::new(
922923
Target::X86_64UnknownLinuxGnu,
923924
CodegenBackend::Llvm,
924925
2,
925926
"collector 2",
927+
Utc::now(),
926928
BenchmarkJobStatus::Success,
927929
);
928930

929931
db_insert_jobs(&*db, request_id, &[job_1, job_2]).await;
930932

931933
assert!(db
932-
.try_mark_benchmark_request_as_completed(&mut request)
934+
.mark_benchmark_request_as_completed(&mut request)
933935
.await
934936
.is_ok());
935937
assert_eq!(request.status(), BenchmarkRequestStatus::InProgress);
@@ -962,20 +964,22 @@ mod tests {
962964
CodegenBackend::Llvm,
963965
1,
964966
"collector 1",
967+
Utc::now(),
965968
BenchmarkJobStatus::Success,
966969
);
967970
let job_2 = BenchmarkJob::new(
968971
Target::X86_64UnknownLinuxGnu,
969972
CodegenBackend::Llvm,
970973
2,
971974
"collector 2",
975+
Utc::now(),
972976
BenchmarkJobStatus::Success,
973977
);
974978

975979
db_insert_jobs(&*db, request_id, &[job_1, job_2]).await;
976980

977981
assert!(db
978-
.try_mark_benchmark_request_as_completed(&mut request)
982+
.mark_benchmark_request_as_completed(&mut request)
979983
.await
980984
.is_ok());
981985
// The struct should have been mutated
@@ -987,28 +991,4 @@ mod tests {
987991
})
988992
.await;
989993
}
990-
991-
#[tokio::test]
992-
async fn get_benchmark_request_id() {
993-
run_postgres_test(|ctx| async {
994-
let db = ctx.db_client();
995-
let db = db.connection().await;
996-
let request = create_try(
997-
Some("s1"),
998-
Some("p1"),
999-
3,
1000-
Utc::now(),
1001-
BenchmarkRequestStatus::InProgress,
1002-
"",
1003-
"",
1004-
);
1005-
db.insert_benchmark_request(&request).await.unwrap();
1006-
1007-
let retrieved = db.get_benchmark_request_id(&request).await.unwrap();
1008-
assert_eq!(1, retrieved);
1009-
1010-
Ok(ctx)
1011-
})
1012-
.await;
1013-
}
1014994
}

database/src/pool/postgres.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::selector::CompileTestCase;
33
use crate::{
4-
<<<<<<< HEAD
5-
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkJobStatus,
6-
||||||| parent of d0ed82ff (Feat; job_queue table definition & mark a request as complete if all jobs are finished)
7-
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkRequest,
8-
BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkRequestType, CodegenBackend,
9-
CollectionId, Commit, CommitType, CompileBenchmark, Date, Index, Profile, QueuedCommit,
10-
Scenario, Target, BENCHMARK_REQUEST_MASTER_STR, BENCHMARK_REQUEST_RELEASE_STR,
11-
=======
12-
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkJob, BenchmarkJobStatus,
13-
>>>>>>> d0ed82ff (Feat; job_queue table definition & mark a request as complete if all jobs are finished)
144
BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkRequestType,
155
CodegenBackend, CollectionId, Commit, CommitType, CompileBenchmark, Date, Index, Profile,
166
QueuedCommit, Scenario, Target, BENCHMARK_REQUEST_MASTER_STR, BENCHMARK_REQUEST_RELEASE_STR,
@@ -1721,7 +1711,7 @@ where
17211711
.collect())
17221712
}
17231713

1724-
async fn try_mark_benchmark_request_as_completed(
1714+
async fn mark_benchmark_request_as_completed(
17251715
&self,
17261716
benchmark_request: &mut BenchmarkRequest,
17271717
) -> anyhow::Result<bool> {
@@ -1781,43 +1771,6 @@ where
17811771
Ok(false)
17821772
}
17831773
}
1784-
1785-
async fn get_benchmark_request_id(
1786-
&self,
1787-
benchmark_request: &BenchmarkRequest,
1788-
) -> anyhow::Result<u32> {
1789-
anyhow::ensure!(
1790-
benchmark_request.tag().is_some(),
1791-
"Benchmark request has no tag"
1792-
);
1793-
1794-
let row = self
1795-
.conn()
1796-
.query_opt(
1797-
"
1798-
SELECT
1799-
id
1800-
FROM
1801-
benchmark_request
1802-
WHERE
1803-
tag = $1
1804-
AND commit_type = $2
1805-
AND status = $3;",
1806-
&[
1807-
&benchmark_request.tag(),
1808-
&benchmark_request.commit_type,
1809-
&benchmark_request.status,
1810-
],
1811-
)
1812-
.await
1813-
.context("Failed to get id for benchmark_request")?;
1814-
1815-
if let Some(row) = row {
1816-
Ok(row.get::<_, i32>(0) as u32)
1817-
} else {
1818-
Ok(1)
1819-
}
1820-
}
18211774
}
18221775

18231776
fn parse_artifact_id(ty: &str, sha: &str, date: Option<DateTime<Utc>>) -> ArtifactId {

database/src/pool/sqlite.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::selector::CompileTestCase;
33
use crate::{
4-
ArtifactCollection, ArtifactId, Benchmark, BenchmarkJob, BenchmarkRequest,
5-
BenchmarkRequestIndex, BenchmarkRequestStatus, CodegenBackend, CollectionId, Commit,
6-
CommitType, CompileBenchmark, Date, Profile, Target,
4+
ArtifactCollection, ArtifactId, Benchmark, BenchmarkRequest, BenchmarkRequestIndex,
5+
BenchmarkRequestStatus, CodegenBackend, CollectionId, Commit, CommitType, CompileBenchmark,
6+
Date, Profile, Target,
77
};
88
use crate::{ArtifactIdNumber, Index, QueuedCommit};
99
use chrono::{DateTime, TimeZone, Utc};
@@ -1331,19 +1331,12 @@ impl Connection for SqliteConnection {
13311331
.collect::<Result<_, _>>()?)
13321332
}
13331333

1334-
async fn try_mark_benchmark_request_as_completed(
1334+
async fn mark_benchmark_request_as_completed(
13351335
&self,
13361336
_benchmark_request: &mut BenchmarkRequest,
13371337
) -> anyhow::Result<bool> {
13381338
no_queue_implementation_abort!()
13391339
}
1340-
1341-
async fn get_benchmark_request_id(
1342-
&self,
1343-
_benchmark_request: &BenchmarkRequest,
1344-
) -> anyhow::Result<u32> {
1345-
no_queue_implementation_abort!()
1346-
}
13471340
}
13481341

13491342
fn parse_artifact_id(ty: &str, sha: &str, date: Option<i64>) -> ArtifactId {

0 commit comments

Comments
 (0)