Skip to content

Commit 3c758be

Browse files
committed
Change how errors are stored in the DB
Removes the `error_series` table, which was probably useless anyway, and adds a `benchmark` column to the `error` table instead. This will allow us to also store runtime errors in to the crate, e.g. under the name `runtime:foo`.
1 parent 9868f11 commit 3c758be

File tree

2 files changed

+49
-50
lines changed

2 files changed

+49
-50
lines changed

database/src/pool/postgres.rs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@ static MIGRATIONS: &[&str] = &[
229229
value double precision not null,
230230
PRIMARY KEY(series, aid, cid)
231231
);
232+
"#,
233+
r#"
234+
create table error_new(
235+
aid integer not null references artifact(id) on delete cascade on update cascade,
236+
benchmark text not null,
237+
error text not null,
238+
primary key(aid, benchmark)
239+
);
240+
insert into error_new(aid, benchmark, error)
241+
select aid, crate, error
242+
from error
243+
join error_series es on error.series = es.id;
244+
245+
drop table error;
246+
drop table error_series;
247+
alter table error_new rename to error;
232248
"#,
233249
];
234250

@@ -368,7 +384,7 @@ impl PostgresConnection {
368384
PostgresConnection {
369385
statements: Arc::new(CachedStatements {
370386
get_pstat: conn
371-
.prepare("
387+
.prepare("
372388
WITH aids AS (
373389
select aid, num from unnest($2::int[]) with ordinality aids(aid, num)
374390
),
@@ -432,8 +448,7 @@ impl PostgresConnection {
432448
)
433449
.await
434450
.unwrap(),
435-
get_error: conn.prepare("select crate, error from error_series
436-
inner join error on error.series = error_series.id and aid = $1").await.unwrap(),
451+
get_error: conn.prepare("select benchmark, error from error where aid = $1").await.unwrap(),
437452
select_self_query_series: conn.prepare("select id from self_profile_query_series where crate = $1 and profile = $2 and cache = $3 and query = $4").await.unwrap(),
438453
insert_self_query_series: conn.prepare("insert into self_profile_query_series (crate, profile, cache, query) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING RETURNING id").await.unwrap(),
439454
insert_pstat_series: conn.prepare("insert into pstat_series (crate, profile, cache, statistic) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING RETURNING id").await.unwrap(),
@@ -700,7 +715,7 @@ where
700715
&[&(pr as i32), &include, &exclude, &runs],
701716
)
702717
.await {
703-
log::error!("failed to queue_pr({}, {:?}, {:?}, {:?}): {:?}", pr, include, exclude, runs, e);
718+
log::error!("failed to queue_pr({}, {:?}, {:?}, {:?}): {:?}", pr, include, exclude, runs, e);
704719
}
705720
}
706721
async fn pr_attach_commit(
@@ -907,13 +922,13 @@ where
907922
Some(aid) => aid.get::<_, i32>(0) as u32,
908923
None => {
909924
self.conn()
910-
.query_opt("insert into artifact (name, date, type) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING RETURNING id", &[
911-
&name,
912-
&date,
913-
&ty,
914-
])
915-
.await
916-
.unwrap();
925+
.query_opt("insert into artifact (name, date, type) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING RETURNING id", &[
926+
&name,
927+
&date,
928+
&ty,
929+
])
930+
.await
931+
.unwrap();
917932
self.conn()
918933
.query_one("select id from artifact where name = $1", &[&name])
919934
.await
@@ -984,27 +999,10 @@ where
984999
}
9851000

9861001
async fn record_error(&self, artifact: ArtifactIdNumber, krate: &str, error: &str) {
987-
let sid = self
988-
.conn()
989-
.query_opt(
990-
"insert into error_series (crate) VALUES ($1) ON CONFLICT DO NOTHING RETURNING id",
991-
&[&krate],
992-
)
993-
.await
994-
.unwrap();
995-
let sid: i32 = match sid {
996-
Some(id) => id.get(0),
997-
None => self
998-
.conn()
999-
.query_one("select id from error_series where crate = $1", &[&krate])
1000-
.await
1001-
.unwrap()
1002-
.get(0),
1003-
};
10041002
self.conn()
10051003
.execute(
1006-
"insert into error (series, aid, error) VALUES ($1, $2, $3)",
1007-
&[&sid, &(artifact.0 as i32), &error],
1004+
"insert into error (benchmark, aid, error) VALUES ($1, $2, $3)",
1005+
&[&krate, &(artifact.0 as i32), &error],
10081006
)
10091007
.await
10101008
.unwrap();

database/src/pool/sqlite.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,24 @@ static MIGRATIONS: &[Migration] = &[
339339
);
340340
"#,
341341
),
342+
Migration::new(
343+
r#"
344+
create table error_new(
345+
aid integer references artifact(id) on delete cascade on update cascade,
346+
benchmark text not null,
347+
error text not null,
348+
primary key(aid, benchmark)
349+
);
350+
insert into error_new(aid, benchmark, error)
351+
select aid, crate, error
352+
from error
353+
join error_series es on error.series = es.id;
354+
355+
drop table error;
356+
drop table error_series;
357+
alter table error_new rename to error;
358+
"#,
359+
),
342360
];
343361

344362
#[async_trait::async_trait]
@@ -748,22 +766,8 @@ impl Connection for SqliteConnection {
748766
async fn record_error(&self, artifact: ArtifactIdNumber, krate: &str, error: &str) {
749767
self.raw_ref()
750768
.execute(
751-
"insert or ignore into error_series (crate) VALUES (?)",
752-
params![&krate,],
753-
)
754-
.unwrap();
755-
let sid: i32 = self
756-
.raw_ref()
757-
.query_row(
758-
"select id from error_series where crate = ?",
759-
params![&krate,],
760-
|r| r.get(0),
761-
)
762-
.unwrap();
763-
self.raw_ref()
764-
.execute(
765-
"insert into error (series, aid, error) VALUES (?, ?, ?)",
766-
params![&sid, &artifact.0, &error],
769+
"insert into error (benchmark, aid, error) VALUES (?, ?, ?)",
770+
params![krate, &artifact.0, &error],
767771
)
768772
.unwrap();
769773
}
@@ -907,10 +911,7 @@ impl Connection for SqliteConnection {
907911
}
908912
async fn get_error(&self, aid: crate::ArtifactIdNumber) -> HashMap<String, String> {
909913
self.raw_ref()
910-
.prepare_cached(
911-
"select crate, error from error_series
912-
inner join error on error.series = error_series.id and aid = ?",
913-
)
914+
.prepare_cached("select benchmark, error from error where aid = ?")
914915
.unwrap()
915916
.query_map(params![&aid.0], |row| Ok((row.get(0)?, row.get(1)?)))
916917
.unwrap()

0 commit comments

Comments
 (0)