Skip to content

Migrate production spines to Arc batches for cross-thread arrangement sharing#37743

Draft
antiguru wants to merge 4 commits into
mainfrom
claude/spines-differential-arc-j93mho
Draft

Migrate production spines to Arc batches for cross-thread arrangement sharing#37743
antiguru wants to merge 4 commits into
mainfrom
claude/spines-differential-arc-j93mho

Conversation

@antiguru

@antiguru antiguru commented Jul 20, 2026

Copy link
Copy Markdown
Member

Motivation

CPU-bound index/MV maintenance and latency-sensitive reads share the same worker threads today, so a peek can stall behind a large merge. Isolating reads from maintenance requires arrangement batches to be readable across thread boundaries, which means moving spine batches from Rc to Arc.

This PR is the RcArc migration only. The architecture it serves is described in the design PR #37747 (two-runtime compute + shared arrangements). The differential-dataflow primitive it depends on is TimelyDataflow/differential-dataflow#807.

This is a draft pending #807 landing upstream, and a benchmark pass.

Description

  • Send + Sync assertions in mz-row-spine confirm the batch contents (lgalloc regions, CompactBytes, columnation stacks) are already thread-safe, so only the reference-count wrapper needs to change.
  • Spine typedefs migrated RcArc: RowRowSpine, RowValSpine, RowSpine, ValRowSpine and their builders in mz-row-spine, and ColValSpine, ColKeySpine in mz-compute typedefs, now use Arc/ArcBuilder. ErrSpine and the generic spines are aliases of these and follow.
  • Consumers that named the wrapper directly: the arrangement-size logger in mz-compute held batches by Rc weak reference and now uses Arc (the trace-box handle stays Rc, as it should); the storage sink switched from the stock OrdValSpine to the Arc-backed ArcOrdValSpine.
  • Dependency: differential-dataflow/differential-dogs3 are patched via [patch.crates-io] to the branch behind Arc-backed spines for cross-thread arrangement sharing TimelyDataflow/differential-dataflow#807, which carries arc_blanket_impls/ArcBuilder. Prototype plumbing until that PR is released.

The change is a minimal, mechanical RcArc swap. The batch layout, containers, and operator logic are untouched. No design docs live here — those moved to #37747.

Verification

  • mz-row-spine, mz-compute, and mz-storage cargo check clean against the Arc-backed differential fork.
  • mz-row-spine tests pass, including a new compile-time batches_are_send_sync assertion over the production Row/Timestamp/Diff layouts, which now covers the real spines rather than only their contents.
  • The differential-dataflow primitive has its own cross-thread snapshot and cross-dataflow import tests in Arc-backed spines for cross-thread arrangement sharing TimelyDataflow/differential-dataflow#807.

Performance: the switch adds atomic reference counting, which occurs per batch clone/drop (a handful per merge/import), never per record, so the hot cursor/merge paths are unaffected. A benchmark comparison is worth running before this leaves draft.

🤖 Generated with Claude Code

@antiguru
antiguru force-pushed the claude/spines-differential-arc-j93mho branch 2 times, most recently from dbf08aa to 798aa48 Compare July 20, 2026 08:30
claude added 4 commits July 20, 2026 14:06
Batches shared across threads, for example behind an Arc to serve reads
from outside the worker that maintains the trace, require their contents
to be Send + Sync. This already holds for all row-spine batch types
because the backing containers bottom out in Vecs, lgalloc regions, and
CompactBytes. Add a compile-time assertion so it stays that way.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwFQJa3HSy8oGJZ3X9uGZx
Switch Materialize's spine typedefs to Arc'd batches so arrangements can be
read across thread boundaries, the prerequisite for sharing a trace between
adjacent timely runtimes.

- mz-row-spine: RowRowSpine, RowValSpine, RowSpine, ValRowSpine and their
  builders move from Rc/RcBuilder to Arc/ArcBuilder. ErrSpine and the generic
  spines are aliases of these and follow.
- mz-compute typedefs: ColValSpine, ColKeySpine and builders likewise.
- The arrangement-size logger held batches by Rc weak reference; it now uses
  Arc. The storage sink's stock OrdValSpine builder alias is renamed.

The batch contents (lgalloc regions, CompactBytes, columnation stacks) were
already Send + Sync, asserted in mz-row-spine, so only the wrapper changes.

differential-dataflow is patched to the fork carrying arc_blanket_impls and
ArcBuilder via a sibling-checkout path patch. This is prototype plumbing until
an upstream release carries those, at which point the patch repoints at a git
rev or drops.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwFQJa3HSy8oGJZ3X9uGZx
The stock differential OrdValSpine is Rc-backed. The sink trace uses the
Arc-backed ArcOrdValSpine variant so its batches match the Arc migration of
the other production spines.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwFQJa3HSy8oGJZ3X9uGZx
Repoint the [patch.crates-io] entry for differential-dataflow and
differential-dogs3 from the local sibling checkout to the fork branch
(antiguru/differential-dataflow, the Arc-batches PR). Prototype plumbing until
that lands upstream and a released version carries arc_blanket_impls.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwFQJa3HSy8oGJZ3X9uGZx
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