Skip to content

feat(node,store): compress existing cached blocks - #6853

Draft
MoonBoi9001 wants to merge 18 commits into
mb9/compress-new-blocksfrom
mb9/compress-existing-blocks
Draft

MoonBoi9001 wants to merge 18 commits into
mb9/compress-new-blocksfrom
mb9/compress-existing-blocks

Conversation

@MoonBoi9001

@MoonBoi9001 MoonBoi9001 commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

TL;DR

Adds graphman chain compress-blocks, which compresses blocks already in a chain's block cache while the chain stays in use.

Motivation

#6851 only compresses blocks as they are written, so an existing cache keeps its uncompressed blocks until they are deleted. The alternative, truncating the cache and letting graph-node fetch blocks again, costs an RPC call for every block a subgraph needs and slows indexing while the cache refills; converting in place needs no RPC calls.

Summary

  • compress-blocks <chain> run copies the blocks into a new compressed table at a limited rate (--max-rate, 20 MB/s by default), keeps it up to date with changes, and swaps the tables at the end; --no-swap stops before the swap.
  • An interrupted run continues where it stopped; status shows progress and abort undoes an unfinished run.
  • drop-old deletes the uncompressed table after the swap.

Important

Until drop-old runs, the chain needs disk space for a second copy of its blocks, at about half their current size.

@MoonBoi9001
MoonBoi9001 added this pull request to stack #6852 December 1, 2026 10:28
@MoonBoi9001
MoonBoi9001 marked this pull request as ready for review December 1, 2026 10:48
@MoonBoi9001
MoonBoi9001 marked this pull request as draft December 1, 2026 10:57
@MoonBoi9001
MoonBoi9001 marked this pull request as ready for review December 1, 2026 16:56
@MoonBoi9001
MoonBoi9001 force-pushed the mb9/compress-existing-blocks branch from 880cfc3 to 297477c Compare December 1, 2026 17:24
@MoonBoi9001
MoonBoi9001 marked this pull request as draft December 1, 2026 17:48
@MoonBoi9001
MoonBoi9001 force-pushed the mb9/compress-existing-blocks branch from 297477c to 0c67d4d Compare December 2, 2026 17:20
Nodes can store new blocks compressed, but blocks already in the cache stay as they were. Add
graphman chain compress-blocks run and status, which rewrite them in place in batches while the
chain is in use, keep any block a node changes meanwhile, and resume where a run stopped.
Rewritten blocks leave old versions behind, and autovacuum waits until a fifth of a table is
dead. Run VACUUM every 1 GiB or so on its own connection, stop it when anyone waits over a
second for a lock on the table, and pause if the table still grows more than that allows.
The block_compression setting only affects new blocks. Explain how compress-blocks run and
status rewrite the cached ones, what they need, what they cost in WAL, time and disk, and how
to undo them.
Compressing cached blocks had its own copy of the code that adds the column for compressed
blocks. Use the chain store's instead, so both share one lock timeout, backoff and column state.
Each batch locked the table first and read why a lock failed through a server-side trick, and a
run waited for anti-wraparound autovacuum. Give every statement a 2 second lock timeout instead,
so the run stops with an error rather than make others queue behind it, and drop the rest.
A run that could not convert some blocks, or gave up on blocks that stayed locked, still ended
as if it succeeded. Count both in its progress, show them in status, and end with an error
that says how many blocks were left and why.
A run created a table for its progress in the chain's schema when it started. Create one table
for all chains in a database migration instead, and say how to apply it when graphman finds it
missing, since graphman does not run migrations itself.
The pause for a table that grows too much allowed only twice what is rewritten between VACUUMs,
so uncompressing blocks always paused. Also allow the bytes new values add over old ones, read
after Postgres stores them, and count a batch that runs past the VACUUM interval.
A compress run stopped by Ctrl-C, an error while watching its VACUUM or a dead process left that
VACUUM running on the server. Cancel it in each case, have the server check that we are still
there, and close a dropped run's connections so that its lock goes with them.
A limit on the table's size stood in for this, its pause never ended, and it tripped on undos,
small blocks and busy chains. After each VACUUM, stop with an error when the dead rows it left
outnumber the blocks rewritten since the VACUUM before; running the command again continues.
Adding the column reused the node's code, which hides errors and backs off for up to an hour, so
a run by a user who does not own the table paused forever. The run now checks the owner first,
and gets the real error back, trying for about a minute before it stops with it.
After Ctrl-C, cancelling the VACUUM and releasing the lock had no time limit, and later presses
were ignored, so a dead database left graphman hanging for about 15 minutes. Cleaning up now
stops after 30s or on a second Ctrl-C, closing the connection so the server releases the lock.
When VACUUM gave way to others and cancelling it failed, the run returned at once and left the
VACUUM to the server's client check. It now waits up to 10s for it, as the other paths do.
The disk room that compress-blocks needs is given in multiples of --vacuum-every, so say what it
is by default: the larger of 1 GiB and the size of the TOAST table's index.
@MoonBoi9001
MoonBoi9001 force-pushed the mb9/compress-existing-blocks branch from 0c67d4d to d2375e5 Compare December 4, 2026 01:02
A batch covered at most 100 block numbers, so where numbers are sparse it held about 1 block and
a run rewrote about 90 blocks a second. Batches now take the next blocks by count, up to 10,000
and 32 MiB as stored, and always take every block of the numbers they cover.
A run read, compressed and wrote each batch in turn on 1 connection, waiting on the disk each
time. Workers now write batches at once on connections of their own, and the saved progress
stops before the first batch not yet written. The WAL limit now covers the server's WAL overall.
graphman ran compress-blocks on 1 connection. --jobs sets how many connections write batches at
once; graphman raises --pool-size to fit them, and the docs explain both.
graphman raises --pool-size for compress-blocks run so that every job gets a connection. That
choice now sits in a function of its own, and a test checks it for several option values.

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.

1 participant