Repository navigation
Clearing the last retention or tiering window removes the table TTL it set - #222
Merged
Merged
Conversation
…t set When a table's composed TTL is empty (no namespace override and no global LOOM_RETENTION_* / LOOM_TIERING_* window), compute_alters skips it, and apply issued nothing, so the TTL from an earlier pass stayed on the table and kept deleting rows. apply now walks every managed table and issues ALTER TABLE ... REMOVE TTL when the table has no desired TTL but still carries one. None of the managed tables has a schema TTL, so the removal restores the schema default. A failed system.tables read defers the removal to the next pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… test pins that no managed table has a schema TTL Also keeps the TTL read private, logs each branch's change from the branch, and covers a removal deferred behind unfinished mutations. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… runs set-then-clear on loom.audit_log The stub-based apply tests read each table through _DiffCH, so a table without a window takes the no-TTL branch, not the lookup-failure one. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…h KeptCH So both passes run on real ClickHouse for every table, including the loom.memory coalesce TTL; the schema check reads schema.sql from ROOT. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
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.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
Setting a namespace's
retention_daysorwarm_daysback to 0, or removing the lastLOOM_RETENTION_<TABLE>_DAYS/LOOM_TIERING_<TABLE>_WARM_DAYSsetting, now removes the table TTL. Before this fix the old TTL stayed on the table and kept deleting rows.Why
Failing case: with no global window, namespace
ns1registersretention_days=30. The reconcile pass sets amultiIfTTL onloom.memoryand the six other managed tables. The owner then setsretention_days=0("keep forever"). On the next passcompute_altersfinds no desired TTL for any table and returns an empty plan,applylogs "schema defaults apply" and issues nothing. Nothing inserver/ever issuedREMOVE TTL, so the 30-day TTL stayed on every table andns1's rows kept being dropped at merges. The same happens when an operator removes the last global retention or tiering setting. This breaks "Loom deletes only what its writer asked to delete".Pattern: the reconcile loop only emitted "set" statements and had no statement for an empty desired state, so the last applied state stayed in force.
Fix:
applynow walks every managed table. A table with a composed clause takes the existing compare-then-MODIFY TTLpath. A table without one reads its current TTL fromsystem.tables.engine_full(the readcurrent_ttl_matchesalready did, nowcurrent_ttl). If the table still carries a TTL,applyissuesALTER TABLE <t> REMOVE TTL, with the same unfinished-mutation deferral. None of the seven managed tables has a TTL inschemas/schema.sql, so removing the TTL restores the schema default and does not strip a schema-defined one.Scope and risk
Touches
server/storage/retention_overrides.pyonly, plus two doc paragraphs.REMOVE TTLchanges only metadata. It deletes nothing and rewrites no part. If thesystem.tablesread fails for a table that should have no TTL, the removal is skipped and retried on the next pass, becauseREMOVE TTLon a table without a TTL is an error. Every pass now readssystem.tablesonce per managed table, seven point reads. Before, it read only the tables that had a planned clause. If an operator added a TTL by hand to one of these seven tables, the leader now removes it when no Loom window is set, just as it already replaced such a TTL whenever a window was set.Compatibility, rollout and rollback
Tests
tests/unit/test_retention_overrides.py::test_clearing_the_last_override_removes_the_ttl_it_leftfailed before the fix (0 ALTERs issued) and passes now, withREMOVE TTLsent to exactly the tables that still carry a TTL.test_a_table_ttl_is_not_removed_when_its_lookup_failscovers the deferral when the read fails.test_apply_zero_state_issues_no_alter_on_tables_without_ttlchecks that no ALTER is sent when no table has a TTL.test_a_ttl_removal_waits_for_unfinished_mutationscovers the mutation-queue deferral on the removal path.test_a_ttl_an_overlapping_pass_removed_first_is_not_an_errorcovers two overlapping passes.test_no_managed_table_has_a_schema_ttlfails if a migration gives one of the seven tables a schema TTL, which this removal would strip.test_a_cleared_window_removes_the_ttl_on_real_tablesruns on clickhouse-local (skipped without the binary). It creates the seven managed tables fromschemas/schema.sql, applies a namespace window, clears it, and checks that every table has a TTL after the first pass and none after the second. A secondREMOVE TTLfails withCode: 36 ... Table doesn't have any table TTL expression, cannot remove, the text the overlap handling matches.make format lint typecheck,tests/unit/test_retention_overrides.py,test_run_retention.py,test_clickhouse_mutation_inventory.py,test_public_copy.pyandtest_doc_links.pypass.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. I checked the schema for TTLs on the managed tables and traced the reconcile path end to end.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code