Skip to content

catalog: skip consolidation on syncs that apply no updates - #39482

Merged
ggevay merged 2 commits into
MaterializeInc:mainfrom
ggevay:gabor/sql-750-takeover-fence-livelock
Oct 2, 2026
Merged

ggevay merged 2 commits into
MaterializeInc:mainfrom
ggevay:gabor/sql-750-takeover-fence-livelock

Conversation

@ggevay

@ggevay ggevay commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
  • Change. sync_inner consolidates the in-memory snapshot only when the sync applied updates. A sync that applied none starts from a consolidated snapshot, so the skipped pass was a no-op.
  • Why. The 0dt takeover's fence loop (open_inner) syncs before each compare-and-append against the serving leader's upper, which the leader advances on every group commit, at least once per second. The opening handle's snapshot still holds the full audit log, 7.4M entries on the largest production catalog. Each sync spent about 1.1 s consolidating, so every attempt lost the race. One cutover waited 3 h 11 min, with about 1,700 failed attempts.
  • History. Since [catalog] fix quadratic consolidation during catalog sync #36217 (v26.22.0), every sync ended with a full consolidation. Before it, a sync that applied nothing did none. This change restores that for syncs that apply nothing and keeps [catalog] fix quadratic consolidation during catalog sync #36217's fix for syncs across many timestamps.
  • Test. test_persist_sync_of_upper_progress_skips_consolidation in src/catalog/tests/open.rs checks that a sync over upper-only progress does not consolidate, while a sync that applies a committed item does. It fails on main.
  • Local race check (not committed). With 300k audit events and a leader advancing the upper every 20 ms, main never fenced within 60 s (783 upper-mismatch retries). With this change the fence lands on the first attempt, also at a 1 ms tick.
  • Not covered. Syncs that apply updates, for example DDL during the takeover, still consolidate the full snapshot including the audit log.

Closes: SQL-750

🤖 Generated with Claude Code

@ggevay
ggevay force-pushed the gabor/sql-750-takeover-fence-livelock branch from 2ae92dc to c1bc0b5 Compare October 2, 2026 13:39
`sync_inner` consolidated the whole in-memory snapshot after every sync,
even when the sync only observed upper progress. The 0dt takeover's fence
loop syncs before each compare-and-append, and the opening handle's
snapshot still holds the full audit log. Once that consolidation outlasts
the interval between the serving leader's upper advances, every fence
attempt loses the race.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ggevay
ggevay force-pushed the gabor/sql-750-takeover-fence-livelock branch from c1bc0b5 to ca78ba2 Compare October 2, 2026 14:03
@ggevay
ggevay marked this pull request as ready for review October 2, 2026 14:44
@ggevay
ggevay requested a review from a team as a code owner October 2, 2026 14:44
@ggevay
ggevay requested a review from aljoscha October 2, 2026 14:45
@ggevay ggevay added the A-ADAPTER Topics related to the ADAPTER layer label Oct 2, 2026

@aljoscha aljoscha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent change! I had a nit about the comment being overly verbose

Comment thread src/catalog/src/durable/persist.rs Outdated
assert_eq!(updates, BTreeMap::new(), "all updates should be applied");
// Always consolidate at the end to ensure the snapshot is clean.
self.consolidate();
// A sync that applied no updates finds the snapshot consolidated: every successful

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello bot: maybe "Only consolidate when there are actual updates." is enough here. I need to parse all this crap this whole comment that refers to other places in the code that will probably rot. 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, applied!

@ggevay
ggevay enabled auto-merge (squash) October 2, 2026 14:55
@ggevay
ggevay merged commit 9d7e829 into MaterializeInc:main Oct 2, 2026
84 checks passed
@bosconi bosconi mentioned this pull request Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ADAPTER Topics related to the ADAPTER layer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants