Repository navigation
Keep the hash chain valid across retention - #79
Open
WiktorB2004 wants to merge 8 commits into
Open
WiktorB2004 wants to merge 8 commits into
WiktorB2004 wants to merge 8 commits into
Conversation
4 of 6 tasks
A retire block now names its table, partition and streams, and the seal range, count, rows and digest of the partition's segments sealed before it. verify accepts it only when that matches the chain; a segment sealed after it is SEGMENT_MISSING once the partition is gone, and ERASED_RECEIPT_RETIRED needs the record's segment to be covered.
For drop_expired: the chain is checked whole, the other partitions are taken as present, and scrub counts are left out.
With integrity on, drop_expired seals, verifies the expired partitions (verify_before_drop, on by default) and writes a retire block before each detach, on a second connection. A partition with unsealed rows, a failed verify, a lock not granted (55P03) or a pending sibling detach (55000) is kept and reported in the result's skipped list. Without integrity nothing changes.
With integrity on and an empty block table, nothing has been sealed, so drop_expired drops as it does without integrity. A block table with blocks but no genesis is still refused.
drop_expired with integrity takes a second connection from the engine. A pool with no free one now raises PartitionError naming that need, instead of waiting for pool_timeout. A pool that shares one connection is refused the same way.
The check after a detach read the blocks after the retire block again for every partition. The Retirer now keeps the segments and retire blocks of the expired partitions from one incremental scan.
A partition left detached by a drop refused with 55P03, another drop error, or a crash after the detach was never dropped. drop_expired now finds these tables as health does, and drops the expired ones whose retire block is valid and still covers them. One without a valid retire block is kept and reported as not_retired.
WiktorB2004
force-pushed
the
add-integrity-verify
branch
from
November 27, 2026 02:37
a095ff8 to
139e4bc
Compare
WiktorB2004
force-pushed
the
add-integrity-retention
branch
from
November 27, 2026 02:37
9f876d7 to
9bb6864
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #71. Builds on #78.
With integrity on,
drop_expired()now records each partition it drops in the hash chain, soverify()can tell a retired partition from a missing one.Before the first detach,
drop_expired()seals the finished transactions. It then verifies the expired partitions (verify_before_drop=Trueby default). This work runs on a second connection fromconnection.engineand is committed before any detach. Before each detach it appends aretireblock. The block is written under the sealer's lock, hashed like every other block, and committed. It is inserted withON CONFLICT (retired_partition) WHERE retired_partition IS NOT NULL DO NOTHING, so a retried or finalized detach adds no second block. An empty partition gets one too.A retire block is now bound to the chain. It names the partition, its table and streams, and the seal range, count, rows and digest of the partition's segments sealed before it.
verify()accepts it only when that matches the chain. A segment sealed after the retire block isSEGMENT_MISSINGonce the partition is gone.ERASED_RECEIPT_RETIREDneeds the record's segment to be covered by the retire block.RETIRED_EARLYchecks every stream of the partition.drop_expired()keeps an expired partition and reports it in the result's newskippedlist when:verifyfinds a failure in it, or in the chain itself;55P03(lock not granted withinlock_timeout) or55000(a sibling's detach is pending);not_retired).An expired partition left detached by an earlier call (a drop refused with
55P03or another error, or a crash after the detach) is dropped by the next call when its retire block is valid and still covers it.No partition is dropped without a retire block. A crash after the retire block and before the detach leaves a partition that still verifies clean. A crash after the detach and before the drop leaves a detached table, which
verifyreports asDETACHED_PARTITION.Before the chain is started (the block table is empty),
drop_expired()behaves as without integrity. A block table with blocks but no genesis is refused.The second connection is taken from the pool of
connection.engine. A pool with no free connection for it raisesPartitionErrorat once, not afterpool_timeout. The verify runs once before the drops, so a sealed row changed in place after it is dropped with its partition; the docstring says so.The result is still a
listof the dropped names, now aDroppedPartitionssubclass withskipped. Without integrity,drop_expired()behaves as before: it uses no second connection, skips nothing and raisesPartitionLockTimeoutErroras it used to.Integrity stays private: nothing is exported and there are no docs pages. The new parameters and fields say "Private for now".
Test plan
uv run pytestpasses locally, including the PostgreSQL tests intests/dbAUDIT_TEST_PG_IMAGE=postgres:14) as well as the default imageruff check,ruff format --checkandmypypassCHANGELOG.mdUnreleasedbullet if callers should noticeThe docstrings are updated. There are no docs pages or changelog entry, because integrity is still private.