Skip to content

compute: barrier discipline for MV sink shared batches - #37617

Draft
antiguru wants to merge 3 commits into
MaterializeInc:mainfrom
antiguru:pr-35411-barrier
Draft

compute: barrier discipline for MV sink shared batches#37617
antiguru wants to merge 3 commits into
MaterializeInc:mainfrom
antiguru:pr-35411-barrier

Conversation

@antiguru

Copy link
Copy Markdown
Member

Stacked on #37591 (shared-batches sink port) — review the last commit only; the earlier commits are #37591 and will drop out once it merges and this rebases onto main.

Best-effort shared batches coalesce only workers whose builder handles overlap in time, so a process still writes ~1.4 parts per append. This adds an opt-in barrier so the process-local workers agree on exactly one batch per interval.

Each of workers_per_process local workers reports once per batch id — a write, or a skip (note_skip from the Timely supersede path). The batch finishes only after all report, delivered to the last worker that wrote (always holds a capability). The wait is unbounded, no timeout — there is no cross-worker clock to justify one; completion rests on every local worker reporting once, and teardown aborts the write tasks. Per process, so a multi-process replica coalesces to one batch per process, combined into a single compare_and_append by the append operator.

Gated behind enable_compute_sync_mv_sink_shared_batches_barrier, default off, not randomized across the CI suite (unbounded wait). Measured on an 8-worker replica: parts per append ~1.4 → 1.0, a further ~30% off blob PUTs.

An adversarial review found the barrier core sound (exactly-once reporting, deliverer-holds-capability, push-before-finish, lost-wakeup, multi-process all hold); remaining low-severity items (teardown blob leak, stall→OOM amplifier, pending_skips cleanup) are noted for follow-up and cluster around the no-timeout design.

@antiguru
antiguru force-pushed the pr-35411-barrier branch 3 times, most recently from 3bded7d to 9bcafc1 Compare August 26, 2026 08:41
bkirwi and others added 3 commits August 26, 2026 13:19
`SharedBatches` hands out a `SharedBatchBuilder` per batch id. Handles for
the same id feed one process-global builder task, so the workers running in
one process contribute their parts to a single, larger batch instead of each
writing its own small one. The last handle to `finish` receives the batch;
the others receive `None`.

`BatchBuilder::add_part` accepts a pre-encoded part and concatenates parts
until they reach the blob target size, which is what lets the shared builder
accept work from several workers without re-encoding it. Building a batch
now goes through `PersistClient::batch_builder` rather than a `WriteHandle`,
so a shared builder needs no writer registration of its own.

Co-authored-by: Moritz Hoffmann <mh@materialize.com>
Wire the shared-batch builder into the sync (v2) materialized-view sink so
the workers in one process coalesce their parts for a given batch interval
into a single, larger batch instead of each writing its own small batch.

All workers building an interval share the batch description broadcast by the
mint operator, so they share a batch id and their parts land in one
process-global shared batch. Only the last worker to finish receives that
batch; the rest get nothing, which maps to the empty-batch response the write
operator already handles. Every worker still finishes its builder even when it
pushed no data, since any one of them may be the last holder responsible for
delivering all workers' parts.

The behavior is gated behind the new enable_compute_sync_mv_sink_shared_batches
dyncfg, default off. The prior per-worker path is retained unchanged for the
off case. Measured locally on an 8-worker replica with a churning view: blob
PUTs down ~67% and consensus state-diff bytes down ~54%, at unchanged consensus
command count.

Adds a testdrive test asserting the view equals the equivalent one-shot
aggregation across a multi-worker cluster with churn, enables the flag in the
CI system-parameter defaults, and registers it with parallel-workload's flag
flipper.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Builds on the shared-batches sink work (its PR): best-effort coalescing only
merges workers whose builder handles overlap in time, so a process still writes
~1.4 parts per append. Add an opt-in barrier that makes the process-local
workers agree on a single batch per interval.

Each of the workers_per_process local workers reports exactly once per batch id:
a write (SharedBatchBuilder::finish) or, when it supersedes the description
without writing, a skip (SharedBatches::note_skip from the Timely thread). The
shared batch is finished only after every participant reports, and delivered to
the last worker that actually wrote, which always holds an output capability.

The wait is unbounded on purpose. There is no cross-worker clock, so a timeout
would have nothing to reason about. Completion rests on every process-local
worker reporting once per batch id; in steady state every broadcast description
is eventually written or superseded by every local worker, so the barrier
converges, and teardown is handled by aborting the write tasks. The batch is
finished only after all participants have pushed, so no push can race a finished
builder.

The barrier is per process: SharedBatches is process-local, so a multi-process
replica coalesces to one batch per process, which the append operator already
combines into a single compare_and_append.

Gated behind enable_compute_sync_mv_sink_shared_batches_barrier, default off, and
not randomized across the CI suite (the unbounded wait is too risky for that);
covered by the shared-batches testdrive (single- and multi-process) and the
parallel-workload flag flipper. Measured on an 8-worker replica: parts per append
drop from ~1.4 to 1.0, cutting blob PUTs a further ~30%.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants