Skip to content

Commit ec452e8

Browse files
author
Zoran Cvetkov
committed
return the old VID generation for ols subgraphs
1 parent 16b47d4 commit ec452e8

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

store/postgres/src/relational/prune.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ use graph::{
1717
};
1818
use itertools::Itertools;
1919

20-
use crate::{catalog, copy::AdaptiveBatchSize, deployment, relational::Table};
20+
use crate::{
21+
catalog,
22+
copy::AdaptiveBatchSize,
23+
deployment,
24+
relational::{Table, VID_COLUMN},
25+
};
2126

2227
use super::{Catalog, Layout, Namespace};
2328

@@ -68,6 +73,7 @@ struct TablePair {
6873
// has the same name as `src` but is in a different namespace
6974
dst: Arc<Table>,
7075
src_nsp: Namespace,
76+
dst_nsp: Namespace,
7177
}
7278

7379
impl TablePair {
@@ -94,7 +100,12 @@ impl TablePair {
94100
}
95101
conn.batch_execute(&query)?;
96102

97-
Ok(TablePair { src, dst, src_nsp })
103+
Ok(TablePair {
104+
src,
105+
dst,
106+
src_nsp,
107+
dst_nsp,
108+
})
98109
}
99110

100111
/// Copy all entity versions visible between `earliest_block` and
@@ -228,6 +239,12 @@ impl TablePair {
228239
let src_qname = &self.src.qualified_name;
229240
let dst_qname = &self.dst.qualified_name;
230241
let src_nsp = &self.src_nsp;
242+
let dst_nsp = &self.dst_nsp;
243+
244+
let vid_seq = format!("{}_{VID_COLUMN}_seq", self.src.name);
245+
246+
let old_vid_form = !self.src.object.new_vid_form();
247+
231248
let mut query = String::new();
232249

233250
// What we are about to do would get blocked by autovacuum on our
@@ -237,6 +254,15 @@ impl TablePair {
237254
"src" => src_nsp.as_str(), "error" => e.to_string());
238255
}
239256

257+
// Make sure the vid sequence
258+
// continues from where it was
259+
if old_vid_form {
260+
writeln!(
261+
query,
262+
"select setval('{dst_nsp}.{vid_seq}', nextval('{src_nsp}.{vid_seq}'));"
263+
)?;
264+
}
265+
240266
writeln!(query, "drop table {src_qname};")?;
241267
writeln!(query, "alter table {dst_qname} set schema {src_nsp}")?;
242268
conn.transaction(|conn| conn.batch_execute(&query))?;

store/postgres/src/relational_queries.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5096,6 +5096,8 @@ impl<'a> QueryFragment<Pg> for CopyEntityBatchQuery<'a> {
50965096
fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
50975097
out.unsafe_to_cache_prepared();
50985098

5099+
let new_vid_form = self.src.object.new_vid_form();
5100+
50995101
// Construct a query
51005102
// insert into {dst}({columns})
51015103
// select {columns} from {src}
@@ -5116,7 +5118,9 @@ impl<'a> QueryFragment<Pg> for CopyEntityBatchQuery<'a> {
51165118
out.push_sql(", ");
51175119
out.push_sql(CAUSALITY_REGION_COLUMN);
51185120
};
5119-
out.push_sql(", vid");
5121+
if new_vid_form {
5122+
out.push_sql(", vid");
5123+
}
51205124

51215125
out.push_sql(")\nselect ");
51225126
for column in &self.columns {
@@ -5182,7 +5186,9 @@ impl<'a> QueryFragment<Pg> for CopyEntityBatchQuery<'a> {
51825186
));
51835187
}
51845188
}
5185-
out.push_sql(", vid");
5189+
if new_vid_form {
5190+
out.push_sql(", vid");
5191+
}
51865192

51875193
out.push_sql(" from ");
51885194
out.push_sql(self.src.qualified_name.as_str());

0 commit comments

Comments
 (0)