Skip to content

graph: keep a batch's valid blocks when an append is refused - #6800

Open
lx3133584 wants to merge 1 commit into
graphprotocol:masterfrom
lx3133584:fix/write-batch-keeps-valid-blocks
Open

lx3133584 wants to merge 1 commit into
graphprotocol:masterfrom
lx3133584:fix/write-batch-keeps-valid-blocks

Conversation

@lx3133584

@lx3133584 lx3133584 commented Nov 25, 2026 •

Copy link
Copy Markdown

Batch::append_inner moved block_ptr, block_times and firehose_cursor onto self before appending the row groups, and only mods.append can refuse the batch. A refused append therefore left the batch pointing at the block it had rejected while holding only the changes of the blocks before it. append then set self.error, and the write queue refuses to write a batch that carries one (store/postgres/src/writable.rs, Request::Write), so the valid blocks were dropped and the failure poisoned the queue.

A failed deployment's head depended on the batching settings rather than on its data:

setting head after the failing block
batching on start of the batch
GRAPH_STORE_WRITE_BATCH_DURATION=0 the block before the failure

That is what #6793 reports, and it is why a graft whose base fails a few blocks after the graft block never reaches it when batching is on.

Fix

The row groups go first, before any other field moves:

self.mods.append(batch.mods)?;
self.block_ptr = batch.block_ptr;
self.block_times.append(&mut batch.block_times);
self.firehose_cursor = batch.firehose_cursor;

With nothing half-applied, a refused append leaves the batch exactly as it was, so there is no indeterminate state for self.error to guard against. append no longer records the error and the batch stays writable: writing it afterwards records the blocks that were valid, and the head stops where the failure did. The error still reaches the caller, which reports the failure as before.

Batch::append has one caller (writable.rs, Queue::push_write), and after this change Batch::error is written only by rollup.rs, which is a different failure.

Testing

failed_append_keeps_the_block_pointer builds two batches and appends an immutable insert across blocks 1 and 2, which append_row refuses. It asserts the pointer stays on block 1 and that the batch carries no error. Both assertions fail on the previous code: the pointer reads 2, and the batch carries the error that would have poisoned the queue.

  • cargo test -p graph --lib store::write — 9 passed
  • cargo test -p graph --lib — 538 passed, 3 failed. The three are components::link_resolver::ipfs::*, which dial 127.0.0.1:5001; there is no IPFS here, and they do not touch store::write.
  • cargo test --workspace --exclude graph-tests — the command just test-unit runs, so the whole workspace and every target. 4 crates pass; gnd's gnd_test fails 6 of 7, all at pgtemp's run_db.rs with Failed to start initdb. Is it installed and on your path? — the test harness starts a throwaway PostgreSQL and this machine has the client library but not the server binaries. It fails before reaching any code.
  • cargo check -p graph-store-postgres — clean, so the crate that consumes Batch still compiles
  • cargo fmt --all — no change
  • cargo clippy --all-targets — no warnings, the same command just lint runs
  • cargo check --release — clean, every crate in the workspace, the same command just check --release runs

Not run: the integration tests, which need PostgreSQL on 5432, IPFS on 5001 and Anvil on 3021.

Fixes #6793

`Batch::append_inner` moved `block_ptr`, `block_times` and `firehose_cursor`
onto `self` before appending the row groups, and only `mods.append` can refuse
the batch. A refused append therefore left the batch pointing at the block it
had rejected while holding only the changes of the blocks before it. `append`
then set `self.error`, and the write queue refuses to write a batch that
carries one, so the valid blocks were dropped and the failure poisoned the
queue. A failed deployment's head depended on the batching settings rather
than on its data: with batching on it stayed at the start of the batch, with
`GRAPH_STORE_WRITE_BATCH_DURATION=0` it reached the block before the failure.

The row groups now go first, before any other field moves, so a refused
append leaves the batch exactly as it was. With nothing half-applied there is
no indeterminate state to guard against, so `append` no longer records the
error and the batch stays writable: writing it afterwards records the blocks
that were valid and the head stops where the failure did.

The test appends an immutable insert across two blocks, which `append_row`
refuses, and asserts the pointer stays on the first block and that the batch
carries no error. Both assertions fail without the change.

Signed-off-by: Liang Xu <24490353+lx3133584@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write batch: a failed append drops the batch's earlier valid blocks, so a failed deployment's head depends on batching settings

1 participant