Skip to content

Commit fcb49f8

Browse files
Migrate to i32 for artifact ids
This mitigates non-consecutive allocation by postgres, hopefully giving us at least a few more years before #773 is actually a problem.
1 parent ec92a78 commit fcb49f8

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

database/src/bin/export-to-sqlite.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Table for Pstat {
6868
statement
6969
.execute(params![
7070
row.get::<_, i32>(0),
71-
row.get::<_, i16>(1),
71+
row.get::<_, i32>(1),
7272
row.get::<_, i32>(2),
7373
row.get::<_, f64>(3),
7474
])
@@ -115,7 +115,7 @@ impl Table for Error {
115115
statement
116116
.execute(params![
117117
row.get::<_, i32>(0),
118-
row.get::<_, i16>(1),
118+
row.get::<_, i32>(1),
119119
row.get::<_, &str>(2),
120120
])
121121
.unwrap();
@@ -163,7 +163,7 @@ impl Table for Artifact {
163163
fn execute(statement: &mut rusqlite::Statement, row: Row) {
164164
statement
165165
.execute(params![
166-
row.get::<_, i16>(0),
166+
row.get::<_, i32>(0),
167167
row.get::<_, &str>(1),
168168
row.get::<_, Option<chrono::DateTime<chrono::Utc>>>(2)
169169
.map(|d| d.timestamp()),
@@ -249,7 +249,7 @@ impl Table for SelfProfileQuery {
249249
statement
250250
.execute(params![
251251
row.get::<_, i32>(0),
252-
row.get::<_, i16>(1),
252+
row.get::<_, i32>(1),
253253
row.get::<_, i32>(2),
254254
row.get::<_, i64>(3),
255255
row.get::<_, i64>(4),

database/src/pool/postgres.rs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ static MIGRATIONS: &[&str] = &[
192192
PRIMARY KEY(aid, cid, crate)
193193
);
194194
"#,
195+
r#"alter table artifact alter column id set data type integer;"#,
196+
r#"
197+
alter table artifact_collection_duration alter column aid set data type integer;
198+
alter table collector_progress alter column aid set data type integer;
199+
alter table error alter column aid set data type integer;
200+
alter table pstat alter column aid set data type integer;
201+
alter table raw_self_profile alter column aid set data type integer;
202+
alter table rustc_compilation alter column aid set data type integer;
203+
alter table self_profile_query alter column aid set data type integer;
204+
"#,
195205
];
196206

197207
#[async_trait::async_trait]
@@ -456,7 +466,7 @@ where
456466
self.conn()
457467
.execute(
458468
&self.statements().record_duration,
459-
&[&(artifact.0 as i16), &(duration.as_secs() as i32)],
469+
&[&(artifact.0 as i32), &(duration.as_secs() as i32)],
460470
)
461471
.await
462472
.unwrap();
@@ -475,7 +485,7 @@ where
475485
.into_iter()
476486
.map(|row| {
477487
(
478-
row.get::<_, i16>(0) as u32,
488+
row.get::<_, i32>(0) as u32,
479489
Commit {
480490
sha: row.get::<_, String>(1).as_str().into(),
481491
date: {
@@ -497,7 +507,7 @@ where
497507
.into_iter()
498508
.map(|row| {
499509
(
500-
row.get::<_, i16>(0) as u32,
510+
row.get::<_, i32>(0) as u32,
501511
row.get::<_, String>(1).as_str().into(),
502512
)
503513
})
@@ -599,7 +609,7 @@ where
599609
.conn()
600610
.query_opt(
601611
&self.statements().get_self_profile_query,
602-
&[&(series as i32), &(cid.0 as i16)],
612+
&[&(series as i32), &(cid.0 as i32)],
603613
)
604614
.await
605615
.unwrap()?;
@@ -625,7 +635,7 @@ where
625635
.conn()
626636
.query(
627637
&self.statements().get_self_profile,
628-
&[&crate_, &profile, &cache, &(cid.0 as i16)],
638+
&[&crate_, &profile, &cache, &(cid.0 as i32)],
629639
)
630640
.await
631641
.unwrap();
@@ -651,7 +661,7 @@ where
651661
async fn get_error(&self, cid: crate::ArtifactIdNumber) -> HashMap<String, Option<String>> {
652662
let rows = self
653663
.conn()
654-
.query(&self.statements().get_error, &[&(cid.0 as i16)])
664+
.query(&self.statements().get_error, &[&(cid.0 as i32)])
655665
.await
656666
.unwrap();
657667
rows.into_iter()
@@ -771,7 +781,7 @@ where
771781
self.conn()
772782
.execute(
773783
&self.statements().insert_pstat,
774-
&[&sid, &(artifact.0 as i16), &(collection.0 as i32), &value],
784+
&[&sid, &(artifact.0 as i32), &(collection.0 as i32), &value],
775785
)
776786
.await
777787
.unwrap();
@@ -788,7 +798,7 @@ where
788798
.execute(
789799
&self.statements().insert_rustc,
790800
&[
791-
&(artifact.0 as i16),
801+
&(artifact.0 as i32),
792802
&(collection.0 as i32),
793803
&krate,
794804
&(value.as_nanos() as i64),
@@ -821,14 +831,14 @@ where
821831
.await
822832
.unwrap();
823833
if let Some(row) = aid {
824-
return ArtifactIdNumber(row.get::<_, i16>(0) as u32);
834+
return ArtifactIdNumber(row.get::<_, i32>(0) as u32);
825835
}
826836
ArtifactIdNumber(
827837
self.conn()
828838
.query_one("select id from artifact where name = $1", &[&name])
829839
.await
830840
.unwrap()
831-
.get::<_, i16>(0) as u32,
841+
.get::<_, i32>(0) as u32,
832842
)
833843
}
834844

@@ -869,7 +879,7 @@ where
869879
&self.statements().insert_self_profile_query,
870880
&[
871881
&(sid as i32),
872-
&(artifact.0 as i16),
882+
&(artifact.0 as i32),
873883
&(collection.0 as i32),
874884
&i64::try_from(qd.self_time.as_nanos()).unwrap(),
875885
&i64::try_from(qd.blocked_time.as_nanos()).unwrap(),
@@ -903,7 +913,7 @@ where
903913
self.conn()
904914
.execute(
905915
"insert into error (series, aid, error) VALUES ($1, $2, $3)",
906-
&[&sid, &(artifact.0 as i16), &error],
916+
&[&sid, &(artifact.0 as i32), &error],
907917
)
908918
.await
909919
.unwrap();
@@ -947,7 +957,7 @@ where
947957
.execute(
948958
"insert into collector_progress(aid, step) VALUES ($1, $2)
949959
ON CONFLICT DO NOTHING",
950-
&[&(aid.0 as i16), &step],
960+
&[&(aid.0 as i32), &step],
951961
)
952962
.await
953963
.unwrap();
@@ -960,7 +970,7 @@ where
960970
.execute(
961971
"update collector_progress set start_time = statement_timestamp() \
962972
where aid = $1 and step = $2 and end_time is null;",
963-
&[&(aid.0 as i16), &step],
973+
&[&(aid.0 as i32), &step],
964974
)
965975
.await
966976
.unwrap()
@@ -972,7 +982,7 @@ where
972982
.execute(
973983
"update collector_progress set end_time = statement_timestamp() \
974984
where aid = $1 and step = $2 and start_time is not null and end_time is null;",
975-
&[&(aid.0 as i16), &step],
985+
&[&(aid.0 as i32), &step],
976986
)
977987
.await
978988
.unwrap()
@@ -992,7 +1002,7 @@ where
9921002
.unwrap();
9931003
let aids = rows
9941004
.into_iter()
995-
.map(|row| row.get::<_, i16>(0))
1005+
.map(|row| row.get::<_, i32>(0))
9961006
.collect::<Vec<_>>();
9971007

9981008
let mut artifacts = Vec::new();
@@ -1036,7 +1046,7 @@ where
10361046

10371047
let steps = self
10381048
.conn()
1039-
.query(&self.statements().in_progress_steps, &[&(aid.0 as i16)])
1049+
.query(&self.statements().in_progress_steps, &[&(aid.0 as i32)])
10401050
.await
10411051
.unwrap();
10421052

@@ -1095,7 +1105,7 @@ where
10951105
let cache = cache.to_string();
10961106
self.conn().execute(
10971107
"insert into raw_self_profile (aid, cid, crate, profile, cache) VALUES ($1, $2, $3, $4, $5)",
1098-
&[&(artifact.0 as i16), &collection.0, &krate, &profile, &cache],
1108+
&[&(artifact.0 as i32), &collection.0, &krate, &profile, &cache],
10991109
).await.unwrap();
11001110
}
11011111
async fn list_self_profile(
@@ -1127,7 +1137,7 @@ where
11271137
.await
11281138
.unwrap()
11291139
.into_iter()
1130-
.map(|r| (ArtifactIdNumber(r.get::<_, i16>(0) as u32), r.get(1)))
1140+
.map(|r| (ArtifactIdNumber(r.get::<_, i32>(0) as u32), r.get(1)))
11311141
.collect()
11321142
}
11331143

@@ -1146,13 +1156,13 @@ where
11461156
.conn()
11471157
.query(
11481158
&self.statements().get_rustc_compilation,
1149-
&[&aids.iter().map(|v| v.0 as i16).collect::<Vec<_>>()],
1159+
&[&aids.iter().map(|v| v.0 as i32).collect::<Vec<_>>()],
11501160
)
11511161
.await
11521162
.unwrap();
11531163

11541164
for row in rows {
1155-
let aid = ArtifactIdNumber(row.get::<_, i16>(0) as u32);
1165+
let aid = ArtifactIdNumber(row.get::<_, i32>(0) as u32);
11561166
let krate = row.get::<_, String>(1);
11571167
let min_duration = row.get::<_, i64>(2);
11581168

0 commit comments

Comments
 (0)