Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions graph/src/components/store/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,27 @@ impl RowGroup {
if self.immutable {
match row {
EntityModification::Insert { .. } => {
// Check if this is an attempt to overwrite an immutable
// entity. We allow overwriting immutable entities in
// the same block, but not across blocks; if such an
// attempt happens across two batches, it would result
// in a database constraint violation. This check is
// simply here to provide a friendlier error message and
// to raise the error earlier, before we actually write
// to the database
match self
.last_mod
.get(row.id())
.and_then(|&idx| self.rows.get(idx))
{
Some(prev) if prev.block() != row.block() => {
return Err(StoreError::Input(
format!("entity {} is immutable; inserting it at block {} is not possible as it was already inserted at block {}",
row.key(), row.block(), prev.block())));
}
_ => { /* nothing to check */ }
}

self.push_row(row);
}
EntityModification::Overwrite { .. } | EntityModification::Remove { .. } => {
Expand Down
14 changes: 14 additions & 0 deletions graph/src/schema/entity_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,17 @@ impl std::fmt::Debug for EntityKey {
)
}
}

impl std::fmt::Display for EntityKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.causality_region == CausalityRegion::ONCHAIN {
write!(f, "{}[{}]", self.entity_type, self.entity_id)
} else {
write!(
f,
"{}/{}[{}]",
self.entity_type, self.causality_region, self.entity_id
)
}
}
}
Loading