Skip to content

Commit

Permalink
store: Make sure that copied errors have a unique id
Browse files Browse the repository at this point in the history
  • Loading branch information
lutter committed Apr 19, 2021
1 parent 9e2d1a7 commit 7c4e33e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion store/postgres/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,20 @@ pub(crate) fn copy_errors(
return Ok(count as usize);
}

// We calculate a new id since the subgraph_error table has an exclusion
// constraint on (id, block_range) and we need to make sure that newly
// inserted errors do not collide with existing ones. For new subgraph
// errors, we use a stable hash; for copied ones we just use an MD5.
//
// Longer term, we should get rid of the id column, since it is only
// needed to deduplicate error messages, which would be better achieved
// with a unique index
let query = format!(
"\
insert into subgraphs.subgraph_error(id,
subgraph_id, message, block_hash, handler, deterministic, block_range)
select e.id, $2 as subgraph_id, e.message, e.block_hash,
select md5($2 || e.message || coalesce(e.block_hash, 'nohash') || coalesce(e.handler, 'nohandler') || e.deterministic) as id,
$2 as subgraph_id, e.message, e.block_hash,
e.handler, e.deterministic, e.block_range
from {src_nsp}.subgraph_error e
where e.subgraph_id = $1
Expand Down

0 comments on commit 7c4e33e

Please sign in to comment.