Skip to content

Commit eb4462b

Browse files
committed
store: Make write failurs easier to debug
1 parent 89cb4d2 commit eb4462b

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

graph/src/components/store/write.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,17 @@ impl<'a> WriteChunk<'a> {
933933
count: 0,
934934
}
935935
}
936+
937+
pub fn as_vec(&self) -> Vec<Self> {
938+
(0..self.len())
939+
.into_iter()
940+
.map(|position| WriteChunk {
941+
group: self.group,
942+
chunk_size: 1,
943+
position: self.position + position,
944+
})
945+
.collect()
946+
}
936947
}
937948

938949
impl<'a> IntoIterator for &WriteChunk<'a> {

store/postgres/src/relational.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -767,13 +767,18 @@ impl Layout {
767767
for chunk in group.write_chunks(chunk_size) {
768768
// Empty chunks would lead to invalid SQL
769769
if !chunk.is_empty() {
770-
InsertQuery::new(table, &chunk)?
771-
.execute(conn)
772-
.await
773-
.map_err(|e| {
774-
let (block, msg) = chunk_details(&chunk);
775-
StoreError::write_failure(e, table.object.as_str(), block, msg)
776-
})?;
770+
if let Err(_) = InsertQuery::new(table, &chunk)?.execute(conn).await {
771+
for single_chunk in chunk.as_vec() {
772+
InsertQuery::new(table, &single_chunk)?
773+
.execute(conn)
774+
.await
775+
.map_err(|e| {
776+
let (block, msg) = chunk_details(&single_chunk);
777+
let msg = format!("{}: offending row {:?}", msg, single_chunk);
778+
StoreError::write_failure(e, table.object.as_str(), block, msg)
779+
})?;
780+
}
781+
}
777782
}
778783
}
779784
Ok(())

0 commit comments

Comments
 (0)