Skip to content

persist: coalesce source frontier downgrades during hydration - #37313

Merged
antiguru merged 3 commits into
mainfrom
claude/pr-recreation-main-tj71ah
Jul 6, 2026
Merged

antiguru merged 3 commits into
mainfrom
claude/pr-recreation-main-tj71ah

Conversation

@antiguru

@antiguru antiguru commented Jun 26, 2026

Copy link
Copy Markdown
Member

Motivation

Hydrating an index with retained history replays the source's whole batch
history. For a collection written at ~1/s whose batches stay unmerged (the
held-back since blocks compaction), that is one progress round per persist
batch, and each round triggers an arrangement-maintenance pass on every
replica. Hundreds of thousands of rounds make hydration slow.

What this does

While catching up to the shard upper observed at hydration time, the persist
source withholds per-batch progress and forwards it in larger, byte-bounded
steps. This collapses a long historical replay from one progress round per
persist batch into a handful of steps. Emitted parts keep their real
timestamps, so only the frontier granularity changes, not the data. Once the
source reaches the hydration-time upper (it is live), tracking snaps back to
per-batch so consumers relying on tight frontier tracking, such as
persist_sink, are unaffected in steady state.

Gated by the new dyncfg persist_source_hydration_frontier_coalesce_bytes
(default 0 = disabled).

Relationship to antiguru#180

This recreates the frontier-coalescing feature on the current async persist
source operator, without the underlying deasync refactor
that the original
change was built on top of. In the async operator the "forward progress"
action is cap_set.downgrade(...); coalescing holds that downgrade back while
parts continue to flow at their real timestamps. The forward/coalesce decision
is factored into should_forward_progress.

Tests

  • test_frontier_coalesce_decision checks the round reduction directly
    (disabled forwards once per batch; a budget larger than the replay forwards
    once; a mid budget lands strictly between), independent of timely's progress
    batching.
  • test_shard_source_hydration_frontier_coalesce hydrates an index over 64
    unmerged single-timestamp batches (compaction disabled, mirroring a held-back
    since) and asserts that coalescing on and off both emit parts through the
    final timestamp without stalling.

Generated by Claude Code

@antiguru
antiguru marked this pull request as ready for review June 26, 2026 11:33
@antiguru
antiguru requested review from a team as code owners June 26, 2026 11:33

@def- def- 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.

Test changes lgtm, nightly triggered: https://buildkite.com/materialize/nightly/builds/16905 No other concerns Edit: Test failures seem unrelated

Comment thread src/persist-client/src/operators/shard_source.rs Outdated
Comment thread src/persist-client/src/operators/shard_source.rs Outdated
claude added 3 commits July 6, 2026 08:26
While catching up to the shard upper observed at hydration time, the
persist source withholds per-batch progress and forwards it in larger,
byte-bounded steps. This turns a long historical replay from one progress
round (and one downstream arrangement-maintenance pass) per persist batch
into a handful of steps. Emitted parts keep their real timestamps, so only
the frontier granularity changes, not the data. Gated by
persist_source_hydration_frontier_coalesce_bytes (default 0 = disabled);
tracking snaps back to per-batch once the source is live.

This recreates the frontier-coalescing feature on the async persist source
operator, without the underlying deasync refactor. The forward/coalesce
decision is factored into should_forward_progress and covered by tests:
test_frontier_coalesce_decision checks the round reduction directly, and
test_shard_source_hydration_frontier_coalesce hydrates an index over 64
unmerged single-timestamp batches and asserts both coalescing on and off
emit parts through the final timestamp without stalling.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015rYj64cXLGKvkpiYdpwKgZ
The lint_test_flags check requires every dyncfg to be known to the test
harnesses. Register persist_source_hydration_frontier_coalesce_bytes with
valid byte values (0 = disabled, plus 1/16/128 MiB) in FlipFlagsAction and
in get_variable_system_parameters.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015rYj64cXLGKvkpiYdpwKgZ
- Add ReadHandle::shared_upper mirroring WriteHandle::shared_upper, and use
  it in shard_source instead of reaching into machine.applier internals.
- Inline the trivial forward/coalesce decision at the call site and trim the
  surrounding commentary. The round-reduction test computes the same
  expression directly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015rYj64cXLGKvkpiYdpwKgZ
@antiguru
antiguru force-pushed the claude/pr-recreation-main-tj71ah branch from dd61581 to 572b75b Compare July 6, 2026 08:28
@antiguru
antiguru requested a review from petrosagg July 6, 2026 08:36
@antiguru
antiguru merged commit e5c79c7 into main Jul 6, 2026
127 checks passed
@antiguru
antiguru deleted the claude/pr-recreation-main-tj71ah branch July 6, 2026 09:52
@antiguru

antiguru commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

Thanks for the reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants