Repository navigation
feat: find and attach the partitions a stopped backfill left unattached - #85
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
AlexeyShalaev
force-pushed
the
fix/find-and-finish-stranded-windows
branch
from
September 29, 2026 16:00
0df8440 to
c83b45c
Compare
A backfill moves a window's rows out of DEFAULT into a partition it attaches last. If the process died between the two, the rows sat in a table no query through the parent sees, DEFAULT held nothing to bring a later backfill back to the window, and plan and validate said all was well. plan now reports such a table as unattached_rows (WARNING), and partition_data attaches it once DEFAULT is drained, through the path a window out of DEFAULT takes. A table counts only when its name is the very name the scheme gives a window under this root, checked both ways, so metrics_remote__2025_01 beside metrics is not taken for January; its rows are read only after that, so a table that merely shares the prefix is never read and needs no grant. A table under a window's name holding rows outside that window was not left by a backfill; partition_data reports it and leaves it as it is rather than raising the check violation ATTACH gives. get_unattached_tables(table_name) is a method of PartitionMetadataProvider in both mirrors: the tables in the root's schema named under it, attached to nothing and unmarked. It is its own query rather than part of get_actual_tree, so list_partitions and get_default_partition do not pay for it. ActualTree.unattached and UnattachedTable carry what it found. Closes #76
AlexeyShalaev
force-pushed
the
fix/find-and-finish-stranded-windows
branch
from
September 29, 2026 16:03
c83b45c to
f57ee1d
Compare
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 #76. The other half, #83, already moves the rows back when an attach fails; this one is for a process that never gets to fail.
The problem
A backfill creates a window's partition, moves the window's rows into it from DEFAULT, and attaches it last. If the process dies after the move and before the attach, the rows are in that table and nowhere else. The next
backfillprobes DEFAULT for the oldest key, finds nothing of that window, and never looks at it again, whileplanandvalidateboth say the table is fine. On 1.6.3:The design
Finding them.
PartitionMetadataProvider.get_unattached_tables(table_name): tables in the root's schema whose names begin with the root's, attached to nothing and carrying no orphan marker. The schema comes fromto_regclass, so a configuration without an explicit schema works. It is a query of its own, not part ofget_actual_tree, becauselist_partitionsandget_default_partitionare built on that and have no use for it. It reads no rows.Deciding which are partitions.
unattached_window(config, relname)is the one rule, used by the inspector, the planner and the backfill: the name must read back as a window and be the very name the scheme gives that window under this root. Reading back alone is not enough. The integration suite's foreign-leaf tests havemetrics_…_remote__2025_01besidemetrics_…, which the month pattern happily reads as January; with a one-way check the backfill would have created an empty January partition to "finish" it. Only after a table passes is its first row asked for (get_leading_key_minimum), so a table that merely shares the prefix, the pre-migration copy say, is never read and needs no grant.Reporting. The planner reports each such table holding rows as
unattached_rows, a WARNING:plan --checkexits 3 andapplycarries it inresult.issues. It stays quiet for a window the same plan creates anyway, because the executor already attaches a table it finds under a name it creates.Finishing. Once DEFAULT is drained,
partition_datatakes the next such window and runs it through the path a window out of DEFAULT takes.plan_for(window)gives the create, the executor finds the table under that name and completes and attaches it, and the fill has nothing to move. The same scenario on this branch:A table under a window's name whose rows do not fit that window was not left by a backfill, since a fill only ever moves a window's own rows.
ATTACHrefuses it, andpartition_datareports that and leaves the table as it is instead of raising.What I rejected
validate, as the issue suggested.validateis the CI check, the document against the table's shape, and it runs no planner; putting production data state into it would fail CI for the wrong reason.plan --checkis where this belongs, and exits 3.apply. A table under a window name without a marker is the library's by the rule the executor already applies to windows it wants, but for a past window the natural fix is the command that fills windows, andbackfillis what the finding points to.__and the root's name. Numeric schemes take a configurablename_suffix, so the only reliable judge of what is a partition name is the scheme itself.Public surface
get_unattached_tablesis an addition to the metadata protocol in both mirrors, likecurrent_timein 1.6.0: a provider written from scratch gains one method.UnattachedTableandActualTree.unattachedare new, andFindingReason.UNATTACHED_ROWSis a new reason. Hencefeat:and 1.7.0. Docs: the findings reference, troubleshooting, the interruption table inconcepts/execution.md, the backfill steps,extending.md, the API cheatsheet andagents.md.Verified
unattached_tablesreads only window-named tables and skips a non-RANGE root; the provider's rows and parameters;partition_datafinishing a stranded window once DEFAULT is drained, and completing when there is noneplan, attached bypartition_datawith all 25 rows visible, gone from the next plan, and a__archivetable beside it is neither reported nor touched. The foreign-leaf tests caught the one-way name check before it shipped. New as well: a table under March's name holding February's rows is reported by the backfill and left alone. CI's first run caught my own test data using a zone-dependent literal on the UTC+14 server; with explicit UTC instants the whole suite passes locally underPacific/Kiritimati/Etc/GMT+12too (571), and the old literal fails there, so the setting was really in effectmypy pg_partsmith, ruff, and the docs build are clean