Skip to content

Commit 356ad6c

Browse files
committed
Return the corresponding compiler artifact ID from dequeue_benchmark_job
1 parent bfb937d commit 356ad6c

File tree

5 files changed

+75
-45
lines changed

5 files changed

+75
-45
lines changed

database/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,16 +1120,16 @@ impl BenchmarkJob {
11201120
self.id
11211121
}
11221122

1123-
pub fn target(&self) -> &Target {
1124-
&self.target
1123+
pub fn target(&self) -> Target {
1124+
self.target
11251125
}
11261126

1127-
pub fn backend(&self) -> &CodegenBackend {
1128-
&self.backend
1127+
pub fn backend(&self) -> CodegenBackend {
1128+
self.backend
11291129
}
11301130

1131-
pub fn profile(&self) -> &Profile {
1132-
&self.profile
1131+
pub fn profile(&self) -> Profile {
1132+
self.profile
11331133
}
11341134

11351135
pub fn request_tag(&self) -> &str {

database/src/pool.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,14 @@ pub trait Connection: Send + Sync {
251251
) -> anyhow::Result<Option<CollectorConfig>>;
252252

253253
/// Dequeues a single job for the given collector, target and benchmark set.
254+
/// Also returns detailed information about the compiler artifact that should be benchmarked
255+
/// in the job.
254256
async fn dequeue_benchmark_job(
255257
&self,
256258
collector_name: &str,
257259
target: Target,
258260
benchmark_set: BenchmarkSet,
259-
) -> anyhow::Result<Option<BenchmarkJob>>;
261+
) -> anyhow::Result<Option<(BenchmarkJob, ArtifactId)>>;
260262

261263
/// Try and mark the benchmark_request as completed. Will return `true` if
262264
/// it has been marked as completed else `false` meaning there was no change
@@ -839,12 +841,10 @@ mod tests {
839841
let db = ctx.db_client().connection().await;
840842
let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap();
841843

842-
let insert_result = db
844+
let collector_config = db
843845
.add_collector_config("collector-1", Target::X86_64UnknownLinuxGnu, 1, true)
844-
.await;
845-
assert!(insert_result.is_ok());
846-
847-
let collector_config = insert_result.unwrap();
846+
.await
847+
.unwrap();
848848

849849
let benchmark_request =
850850
BenchmarkRequest::create_master("sha-1", "parent-sha-1", 42, time);
@@ -855,32 +855,28 @@ mod tests {
855855
.unwrap();
856856

857857
// Now we can insert the job
858-
let enqueue_result = db
859-
.enqueue_benchmark_job(
860-
benchmark_request.tag().unwrap(),
861-
Target::X86_64UnknownLinuxGnu,
862-
CodegenBackend::Llvm,
863-
Profile::Opt,
864-
1u32,
865-
)
866-
.await;
867-
assert!(enqueue_result.is_ok());
858+
db.enqueue_benchmark_job(
859+
benchmark_request.tag().unwrap(),
860+
Target::X86_64UnknownLinuxGnu,
861+
CodegenBackend::Llvm,
862+
Profile::Opt,
863+
1u32,
864+
)
865+
.await
866+
.unwrap();
868867

869-
let benchmark_job = db
868+
let (benchmark_job, artifact_id) = db
870869
.dequeue_benchmark_job(
871870
collector_config.name(),
872871
collector_config.target(),
873872
collector_config.benchmark_set(),
874873
)
875-
.await;
876-
assert!(benchmark_job.is_ok());
877-
878-
let benchmark_job = benchmark_job.unwrap();
879-
assert!(benchmark_job.is_some());
874+
.await
875+
.unwrap()
876+
.unwrap();
880877

881878
// Ensure the properties of the job match both the request and the
882879
// collector configuration
883-
let benchmark_job = benchmark_job.unwrap();
884880
assert_eq!(
885881
benchmark_job.request_tag(),
886882
benchmark_request.tag().unwrap()
@@ -894,6 +890,15 @@ mod tests {
894890
collector_config.name(),
895891
);
896892

893+
assert_eq!(
894+
artifact_id,
895+
ArtifactId::Commit(Commit {
896+
sha: "sha-1".to_string(),
897+
date: Date(time),
898+
r#type: CommitType::Master,
899+
})
900+
);
901+
897902
Ok(ctx)
898903
})
899904
.await;

database/src/pool/postgres.rs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ where
18371837
collector_name: &str,
18381838
target: Target,
18391839
benchmark_set: BenchmarkSet,
1840-
) -> anyhow::Result<Option<BenchmarkJob>> {
1840+
) -> anyhow::Result<Option<(BenchmarkJob, ArtifactId)>> {
18411841
// We take the oldest job from the job_queue matching the benchmark_set,
18421842
// target and status of 'queued'
18431843
let row_opt = self
@@ -1857,7 +1857,7 @@ where
18571857
BY created_at
18581858
LIMIT 1
18591859
FOR UPDATE SKIP LOCKED
1860-
), updated_queue AS (
1860+
), updated AS (
18611861
UPDATE
18621862
job_queue
18631863
SET
@@ -1868,19 +1868,20 @@ where
18681868
picked
18691869
WHERE
18701870
job_queue.id = picked.id
1871-
RETURNING
1872-
job_queue.id,
1873-
job_queue.backend,
1874-
job_queue.profile,
1875-
job_queue.request_tag,
1876-
job_queue.created_at,
1877-
job_queue.started_at,
1878-
job_queue.retry
1871+
RETURNING *
18791872
)
18801873
SELECT
1881-
*
1882-
FROM
1883-
updated_queue;",
1874+
updated.id,
1875+
updated.backend,
1876+
updated.profile,
1877+
updated.request_tag,
1878+
updated.created_at,
1879+
updated.started_at,
1880+
updated.retry,
1881+
br.commit_type,
1882+
br.commit_date
1883+
FROM updated
1884+
JOIN benchmark_request as br ON br.tag = updated.request_tag;",
18841885
&[
18851886
&BENCHMARK_JOB_STATUS_QUEUED_STR,
18861887
&target,
@@ -1911,7 +1912,31 @@ where
19111912
},
19121913
retry: row.get::<_, i32>(6) as u32,
19131914
};
1914-
Ok(Some(job))
1915+
let commit_type = row.get::<_, &str>(7);
1916+
let commit_date = row.get::<_, Option<DateTime<Utc>>>(8);
1917+
1918+
let commit_date = Date(commit_date.ok_or_else(|| {
1919+
anyhow::anyhow!("Dequeuing job for a benchmark request without commit date")
1920+
})?);
1921+
let artifact_id = match commit_type {
1922+
BENCHMARK_REQUEST_TRY_STR => ArtifactId::Commit(Commit {
1923+
sha: job.request_tag.clone(),
1924+
date: commit_date,
1925+
r#type: CommitType::Try,
1926+
}),
1927+
BENCHMARK_REQUEST_MASTER_STR => ArtifactId::Commit(Commit {
1928+
sha: job.request_tag.clone(),
1929+
date: commit_date,
1930+
r#type: CommitType::Master,
1931+
}),
1932+
BENCHMARK_REQUEST_RELEASE_STR => ArtifactId::Tag(job.request_tag.clone()),
1933+
_ => panic!(
1934+
"Invalid commit type {commit_type} for benchmark request {}",
1935+
job.request_tag
1936+
),
1937+
};
1938+
1939+
Ok(Some((job, artifact_id)))
19151940
}
19161941
}
19171942
}

database/src/pool/sqlite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ impl Connection for SqliteConnection {
13441344
_collector_name: &str,
13451345
_target: Target,
13461346
_benchmark_set: BenchmarkSet,
1347-
) -> anyhow::Result<Option<BenchmarkJob>> {
1347+
) -> anyhow::Result<Option<(BenchmarkJob, ArtifactId)>> {
13481348
no_queue_implementation_abort!()
13491349
}
13501350

site/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async fn main() {
4343
let artifacts = res.index.load().artifacts().count();
4444
if commits + artifacts == 0 {
4545
eprintln!("Loading complete but no data identified; exiting.");
46-
std::process::exit(1);
46+
// std::process::exit(1);
4747
}
4848
eprintln!("Loading complete; found {} artifacts", commits + artifacts);
4949
eprintln!(

0 commit comments

Comments
 (0)