Repository navigation
One event for every lifecycle hook, and the last silent disagreement from #27 - #31
Merged
Merged
Conversation
The last of the three settings issue #27 found that could disagree without anyone noticing. A timestamp or date key renders its bounds with no offset, so reading one back means resolving it in some timezone, and only the zone it was written under gives the same instant. With neither the provider's ddl_timezone nor a table's boundaries to say what that was, the server's session default decides and is_partition_closed can answer hours early or late, silently. It now says so, once it has the literal in hand and can see there is a question -- a timestamptz bound carries its offset and never triggers it, and neither does a zone the caller pinned either way. is_naive_timestamp_literal lives beside the parser that already knows these shapes. The roadmap records the other half of #27: giving the three name-only hooks the same PartitionInfo their siblings get, which breaks every hook at call time and so waits for the next major, with DropPartition.bounds carrying the information through the plan until then.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Three of the six phases were handed a rich object and three a bare string. A before_drop that archived a partition got a name and nothing else -- and could not look the rest up either, because DETACH clears relpartbound, so by drop time the database no longer records where the partition sat. The split was an accident of how the phases grew, and it showed: the config a hook needs was passed to create hooks only, and an audit or metrics hook could not be written at all except as six identical delegating methods. Every hook method now takes one PartitionEvent: the phase, the config, the partition, the window it covers, and the planned operation -- with the reason it is in the plan and the size the policy measured. Where the window cannot be known it is None rather than guessed. on_event is new and fires for every phase in addition to the method named for it, so the cross-cutting cases are one method that a later phase extends rather than breaks. The two executor entry points and the two service methods that took a bare table name now take the config the event is built from, which is what every other entry point already took. This breaks every hook written against 1.0, in a minor version, deliberately: the library is days old and has no dependants to protect, and the alternative was carrying the split until a major. Because a runtime-checkable protocol only asks whether an attribute exists, an unported hook would otherwise be accepted at wiring time and fail at its first call, mid-run, after some DDL had committed -- so hook signatures are read when the service is constructed and a 1.0-shaped method is refused there, naming the class, the method and what to move to. The changelog carries the before/after table. Refs #27.
An interrupt is not swallowed while reading a boundary literal, and a hook method whose signature cannot be read is left alone rather than guessed at. Both are one line of defensive code each and neither had a test.
A partition retention released is re-attached when its window is wanted again -- retention grew, or create-ahead reached back to it -- and that transition happened silently. Anything derived from the partition while it was out of the tree, an export or a cold copy, goes stale the moment it returns, and no hook was told. before_attach fires once its subtree is complete and before it takes rows, so raising there leaves the relation detached for the next run to plan again; after_attach fires when it is live. Both carry the same event as every other phase, with the AttachPartition operation and its reattach reason on it. Four other phases were considered and left out. A maintenance start and finish would force the event's partition to be optional, weakening every phase that has one, to save a caller two lines around maintain(). Per-bucket calls would break the rule that a hook fires once per lifecycle unit -- an export wants the whole week, not one call per hash bucket -- and the plan already carries every operation for anyone who wants that fidelity. A failure callback would observe what result.issues already reports and cannot influence. Row-movement progress is a different concern with a different shape. None of them is closed off: a phase is now an enum value and a no-op on the base class.
Signature validation had a false positive and a false negative. A hook using functools.singledispatchmethod reports (self, event) even when bound, so judging by arity alone refused a hook written exactly right; a method taking no event at all passed and failed at its first call. Both are gone: a leading self or cls is dropped, then the signature is asked whether it can be called with one event, which accepts (event), (*args) and (event, extra=None) alike. on_event now runs before the method named for the phase. It used to run after, so a before_* hook that refused an operation by raising left an audit trail with nothing in it -- the one case an audit hook most wants recorded. An attach is counted before after_attach fires, as a creation already was, so a failing notification no longer makes the result disagree with the database. (detach and drop have the same shape and count after their hook; that is 1.0 behaviour and needs the tally to move into the executor's own methods, so it is left for its own change.) The three event builders take the config: DEFAULT bounds say nothing about the parent's method -- every method may have one -- and were reported as RANGE, so a DEFAULT member of a LIST root lied about its parent. _parent_method now answers None where the bounds do not say and the configured root decides. The attach event also names how the partition will divide its own children, which it knew from the operation and threw away. is_naive_timestamp_literal no longer reads reduced ISO forms as timestamps: "2024-01", "2024-W01" and "2024-001" are values a text or encoded key really has, and they were drawing a timezone warning meant for real timestamps. Docs: the ported hook example in the agent page still called the old parameter, three places still showed the table-name argument these methods no longer take, and the README example annotated a type it did not import. Four integration call sites were still passing a table name where the config now goes -- they only worked because no hooks were registered there. Refs #27.
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.
Closes the rest of #27. Four commits, smallest first.
1. The last silent disagreement (
fix:)Of the three settings that had to agree across the repository and the metadata provider, the marker prefix is now refused when it disagrees and the codec/timezone pair can be handed over as
boundaries=config.time_boundaries. What remained was the case where nobody says anything: atimestampordatekey renders its bounds with no offset, so reading one back resolves it in some zone, and only the zone it was written under gives the same instant. With noddl_timezoneand noboundaries, the server's session default decides andis_partition_closedcan answer hours early or late without a sound. It now warns, and only where there is a real question:2026-02-01 00:00:002026-02-01 00:00:00+002026-02-01 00:00:00ddl_timezone=…2026-02-01 00:00:00boundaries=…MAXVALUE, an integer2. One event for every hook (
feat:) — breakingThree of the six phases were handed a
PartitionInfoand three a bare string. Abefore_dropthat archives a partition got a name and nothing else — and could not look the rest up either:DETACHclearsrelpartbound, so by drop time the database no longer records where the partition sat. The split was an accident of how the phases grew, and it showed twice more: the config was passed to create hooks only, and an audit or metrics hook could not be written except as six identical delegating methods.Every hook method now takes one
PartitionEvent:phaseconfigpartitionPartitionInfo: name, bounds, OID,subpartition_typewindowNonefor a member of a rootHASHorLIST, or when the name does not decodeoperationreason,detail,oid,size_bytes,row_estimate,detached_attable_nameconfigso the two cannot drifton_eventis new: it fires for every phase in addition to the method named for it, so an audit trail is one method that a later phase extends rather than breaks.Also breaking, in the same area:
PlanExecutor.detach_single_partition/drop_single_partitionandPartitionLifecycleService.detach_old_partitions/drop_detached_partitionstake the config the event is built from, which is what every other entry point already took.3. Two more phases (
feat:)A partition retention released is re-attached when its window is wanted again — retention grew, or create-ahead reached back to it — and that transition happened silently. An export taken while it was detached goes stale the moment it returns, and no hook was told.
before_attachfires once its subtree is complete and before it takes rows (raising leaves it detached for the next run);after_attachfires when it is live.Four other phases were considered and left out, and the reasons are in the commit message: a maintenance start/finish would force
partitionto be optional and saves a caller two lines; per-bucket calls would break the once-per-lifecycle-unit rule the plan already covers better; a failure callback observes whatresult.issuesreports and cannot influence it; row-movement progress is a different concern with a different shape. None is closed off — a phase is now an enum value plus a no-op on the base class.Why break in a minor
Semver says 2.0.0. The library is days old with nothing depending on it, and the alternative was carrying the split until a major — years, for an API that is wrong now. The changelog says exactly this and carries the before/after table for each method. Note for whoever cuts the release: the commits are deliberately
feat:and notfeat!:, or release-please would take this to 2.0.0.Failing loudly instead of at 3am
A runtime-checkable protocol only asks whether an attribute exists, so an unported hook would be accepted at wiring time and raise at its first call — mid-run, after some DDL had committed. Hook signatures are now read when the service is constructed, and a 1.0-shaped method is refused there, naming the class, the method and the shape to move to. Anything whose signature cannot be read (mocks,
*args, C callables) is left alone rather than guessed at.Checks
ruff,mypy, 2 515 unit tests and the whole integration suite (536) green locally on PostgreSQL 17, and in CI on 15, 16 and 17; the docs site builds. Migration table in the changelog; archiving guide, recipes, README and the agent page are ported.