Skip to content

Commit

Permalink
store: Better error message for missing template during grafting (#5464)
Browse files Browse the repository at this point in the history
* store: Better error message for missing template during grafting

* store: Perform private data source copy in its own transaction

Fixes #5465
  • Loading branch information
lutter committed Jul 8, 2024
1 parent 553b8f9 commit cd806e5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
20 changes: 13 additions & 7 deletions store/postgres/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,15 +750,21 @@ impl Connection {
self.conn.transaction(|conn| f(conn))
}

/// Copy private data sources if the source uses a schema version that
/// has a private data sources table. The copying is done in its own
/// transaction.
fn copy_private_data_sources(&mut self, state: &CopyState) -> Result<(), StoreError> {
if state.src.site.schema_version.private_data_sources() {
DataSourcesTable::new(state.src.site.namespace.clone()).copy_to(
&mut self.conn,
&DataSourcesTable::new(state.dst.site.namespace.clone()),
state.target_block.number,
&self.src_manifest_idx_and_name,
&self.dst_manifest_idx_and_name,
)?;
let conn = &mut self.conn;
conn.transaction(|conn| {
DataSourcesTable::new(state.src.site.namespace.clone()).copy_to(
conn,
&DataSourcesTable::new(state.dst.site.namespace.clone()),
state.target_block.number,
&self.src_manifest_idx_and_name,
&self.dst_manifest_idx_and_name,
)
})?;
}
Ok(())
}
Expand Down
18 changes: 15 additions & 3 deletions store/postgres/src/dynds/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use diesel::{
};

use graph::{
anyhow::Context,
anyhow::{anyhow, Context},
components::store::{write, StoredDynamicDataSource},
constraint_violation,
data_source::CausalityRegion,
Expand Down Expand Up @@ -258,12 +258,24 @@ impl DataSourcesTable {
let name = &src_manifest_idx_and_name
.iter()
.find(|(idx, _)| idx == &src_manifest_idx)
.context("manifest_idx not found in src")?
.with_context(|| {
anyhow!(
"the source {} does not have a template with index {}",
self.namespace,
src_manifest_idx
)
})?
.1;
let dst_manifest_idx = dst_manifest_idx_and_name
.iter()
.find(|(_, n)| n == name)
.context("name not found in dst")?
.with_context(|| {
anyhow!(
"the destination {} is missing a template with name {}. The source {} created one at block {:?}",
dst.namespace,
name, self.namespace, block_range.0
)
})?
.0;

let query = format!(
Expand Down

0 comments on commit cd806e5

Please sign in to comment.