From e8763897237137263424fc860e98cd876d67a1a6 Mon Sep 17 00:00:00 2001 From: David Lutterkort Date: Tue, 4 Jun 2024 10:14:21 -0700 Subject: [PATCH 1/2] store: Better error message for missing template during grafting --- store/postgres/src/dynds/private.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/store/postgres/src/dynds/private.rs b/store/postgres/src/dynds/private.rs index 5cf340c274d..e8e7f4ce992 100644 --- a/store/postgres/src/dynds/private.rs +++ b/store/postgres/src/dynds/private.rs @@ -9,7 +9,7 @@ use diesel::{ }; use graph::{ - anyhow::Context, + anyhow::{anyhow, Context}, components::store::{write, StoredDynamicDataSource}, constraint_violation, data_source::CausalityRegion, @@ -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!( From 33be1a7952147ed7aecdc180d35118a00406b80d Mon Sep 17 00:00:00 2001 From: David Lutterkort Date: Tue, 4 Jun 2024 11:51:21 -0700 Subject: [PATCH 2/2] store: Perform private data source copy in its own transaction Fixes https://github.com/graphprotocol/graph-node/issues/5465 --- store/postgres/src/copy.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/store/postgres/src/copy.rs b/store/postgres/src/copy.rs index 8fc97c3a038..97fb3998c06 100644 --- a/store/postgres/src/copy.rs +++ b/store/postgres/src/copy.rs @@ -748,15 +748,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(()) }