Skip to content

SS-492 - storage: let PostgreSQL exports progress independently during a snapshot - #39479

Merged
martykulma merged 3 commits into
maz-pg-concurrent-replicationfrom
maz-pg-per-export-progress
Oct 14, 2026
Merged

martykulma merged 3 commits into
maz-pg-concurrent-replicationfrom
maz-pg-per-export-progress

Conversation

@martykulma

@martykulma martykulma commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Every export's frontier stays at the minimum until the last table's COPY finishes. Adding one large table to a source therefore still stalls ingestion for every table already hydrated in that source.

Description

With storage_persist_sink_description_lookahead nonzero, each export's port holds the minimum capability only while that export still has snapshot data to emit or a pending rewind.

  • Exports that are not being snapshotted drop their snapshot capabilities up front, so they advance with the replication stream.
  • A snapshotted export releases its snapshot capability as soon as its own copy finishes on each worker.
  • The replication operator downgrades every port without a pending rewind at each yield point.

With the lookahead at zero, all ports advance together, so behavior matches #39419.

The replication operator now reads the setting as well. The two operators read it independently at startup, and parallel-workload rolls the lookahead through zero and nonzero values, so a change can land between those two reads and leave the operators in different modes within one dataflow. That is benign in both directions. With only the snapshot operator concurrent, the replication operator holds every port until the rewinds resolve and then releases them all. With only the replication operator concurrent, it still waits for the rewind input to close, which the serial snapshot operator does after the copy.

Verification

The mzcompose default sets the lookahead, so the existing mzcompose-based PostgreSQL source tests exercise per-export progress. #39420 adds targeted coverage.

🤖 Generated with Claude Code

@martykulma
martykulma added this pull request to stack #39480 October 2, 2026 11:39
@martykulma martykulma changed the title storage: let PostgreSQL exports progress independently during a snapshot SS-492 - storage: let PostgreSQL exports progress independently during a snapshot Oct 2, 2026
@linear-code

linear-code Bot commented Oct 2, 2026

Copy link
Copy Markdown

SS-492

@martykulma
martykulma force-pushed the maz-pg-per-export-progress branch from 8536d9c to 21d9143 Compare October 7, 2026 00:38
@martykulma
martykulma force-pushed the maz-pg-per-export-progress branch from 21d9143 to 6fc87ee Compare October 7, 2026 13:45
@martykulma
martykulma marked this pull request as ready for review October 7, 2026 14:20
@martykulma
martykulma requested a review from a team as a code owner October 7, 2026 14:20
@martykulma
martykulma force-pushed the maz-pg-per-export-progress branch from 6fc87ee to b465c30 Compare October 7, 2026 17:01
@martykulma
martykulma force-pushed the maz-pg-per-export-progress branch 2 times, most recently from c39f0c9 to 7e6aab2 Compare October 9, 2026 02:37
@martykulma
martykulma force-pushed the maz-pg-per-export-progress branch 3 times, most recently from 721d91c to c1edc45 Compare October 9, 2026 14:51

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

Looks good to me overall, some more nitty small requests that don't change the logic.

let mut data_outputs = SharedFuel::new(data_outputs);
let concurrent_replication = !STORAGE_PERSIST_SINK_DESCRIPTION_LOOKAHEAD
.get(config.config.config_set())
.is_zero();

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.

Is there a risk of a race here where one part of the full rendered source saw a different value for this flag? Wondering if we should pull the config value up higher and wire down the flag lower.

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.

this is addressed, moved this out of the async operator

let mut builder = AsyncOperatorBuilder::new(op_name, scope.clone());

// Read at render time, matching the value the persist sink reads in the same dataflow build.
// A read in the async body can observe an `UpdateConfiguration` sequenced after this dataflow's

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.

nit: stylistically I'd pref just wiring down a shared boolean if it's less than lets say three layers of functions between the nearest common ancestor. I buy that this is correct, but it feels complex.

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.

Fair. I avoid adding parameters when I can derive from the existing inputs cheaply. The shared boolean pushes render to 9 parameters, and it sets a pattern for future flags that just keeps growing that input list.

I'm down with refactoring this down the road since it definitely seems like we can group some things together.

.await;
if concurrent_replication {
data_cap_sets[output_index] = CapabilitySet::new();
}

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.

Is there a way we can collapse these repetitive pre-continue data_cap_sets[output_index] = CapabilitySet::new();? One Idea I have would be moving the piece inside the for (&output_index, info) in outputs.iter() { into a function and then wrapping that in another function that looks structurally like:

fn handle_output_wrapping() {
    handle_output_existing();
    if concurrent_replication {
        data_cap_sets[output_index] = CapabilitySet::new();
    }
}

fn handle_output_existing() {
    // all existing logic (replace continues with returns).
}

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.

If I understand correctly, wouldn't handle_output_existing be different in each case? Wouldn't we have to break them all up in to function (or pass them as FnMut)?

Replacing:

    if concurrent_replication {
        data_cap_sets[output_index] = CapabilitySet::new();
    }

with this is simpler to read, but not by much:

drop_caps_if_concurrent(data_cap_sets, output_index);

@peterdukelarsen peterdukelarsen Oct 13, 2026 •

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.

I'm not sure we're on the same page. I was recommending putting the entirety of the existing code in the for loop into a function. Then slotting in the new code for capability dropping in a wrapping function.

Definitely wasn't trying to recommend something so narrow as changing:

    if concurrent_replication {
        data_cap_sets[output_index] = CapabilitySet::new();
    }

to:

drop_caps_if_concurrent(data_cap_sets, output_index);

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.

ah, gotcha! hmm.. there's probably close to 10 local variables that then need to be passed into the function, and that's a mess on its own.

An alternative is to do an async block, but this is a little weird because you have to return a result from it.

let copied = async {
    if let Err(err) = verify_schema(oid, info, &upstream_info) {
        // give the error
        return Ok(());
    }
    let Some(ctid_range) = worker_ctid_range(&config, block_count, oid) else {
        return Ok(());
    };
    // COPY
    Ok::<_, TransientError>(())
}.await;
copied?;
if concurrent_replication {
    data_cap_sets[output_index] = CapabilitySet::new();
}

That's worth it if we're planning to add more exit paths, but honestly, I don't think that's the case.

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.

I tried to rewrite this morning (11 parameters as is). A few of them were derived from existing structs, so I adjusted. Should be ok now (at least no clippy exception).

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.

Looks great to me now, thank you!!

@martykulma martykulma left a comment

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 for the review!

let mut builder = AsyncOperatorBuilder::new(op_name, scope.clone());

// Read at render time, matching the value the persist sink reads in the same dataflow build.
// A read in the async body can observe an `UpdateConfiguration` sequenced after this dataflow's

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.

Fair. I avoid adding parameters when I can derive from the existing inputs cheaply. The shared boolean pushes render to 9 parameters, and it sets a pattern for future flags that just keeps growing that input list.

I'm down with refactoring this down the road since it definitely seems like we can group some things together.

.await;
if concurrent_replication {
data_cap_sets[output_index] = CapabilitySet::new();
}

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.

If I understand correctly, wouldn't handle_output_existing be different in each case? Wouldn't we have to break them all up in to function (or pass them as FnMut)?

Replacing:

    if concurrent_replication {
        data_cap_sets[output_index] = CapabilitySet::new();
    }

with this is simpler to read, but not by much:

drop_caps_if_concurrent(data_cap_sets, output_index);

martykulma and others added 3 commits October 14, 2026 11:06
With `storage_persist_sink_description_lookahead` > 0, each export's
port holds the minimum capability only while that export has snapshot
data or a pending rewind. Exports that are not snapshotting advance with
the replication stream, and a snapshotted export is released as soon as
its own copy finishes.

Co-Authored-By: Claude <noreply@anthropic.com>
@martykulma
martykulma force-pushed the maz-pg-per-export-progress branch from 5457141 to 0694adc Compare October 14, 2026 15:06
@martykulma
martykulma merged commit 653e079 into main Oct 14, 2026
83 checks passed
@martykulma
martykulma deleted the maz-pg-per-export-progress branch October 14, 2026 16:40
martykulma added a commit that referenced this pull request Oct 14, 2026
…pshot (#39419)

### Motivation

Today a PostgreSQL source snapshots all of its tables before it reads
any of the replication stream. This PR lets the replication operator
read the stream while the snapshot runs. #39479 then lets each export's
frontier advance on its own.

### Description

All new behavior is keyed off
`storage_persist_sink_description_lookahead` being nonzero. That dyncfg
already controls whether the persist sink groups a snapshotting export's
updates into one batch, and it defaults to zero in production and to 5s
in mzcompose. Concurrent replication is what makes a snapshot accumulate
many timestamps, and reading the stream concurrently without the
grouping keeps one batch builder per timestamp resident until each
reaches the blob target size. The two are therefore one setting rather
than a separate flag.

With a nonzero lookahead, the snapshot operator emits its rewind
requests as soon as the snapshot LSN is known, before any table is
copied. The replication operator then reads the stream while tables are
copied. Every export still advances together, so replication data is
staged in the dataflow until the snapshot completes. This trades cluster
memory during hydration for progress on the replication stream.

With the lookahead at zero, rewinds are emitted after the copy
completes, as before.

The snapshot operator reads the setting once, since the early and the
late emission must not both happen or both be skipped. Only the snapshot
operator reads it in this PR, so a change takes effect for snapshots
that start afterwards. parallel-workload already rolls the lookahead
through zero and nonzero values.

The persist sink logs the resolved lookahead per export at dataflow
build time, so a hydration's logs show whether grouping and concurrent
replication are on.

### Verification

The mzcompose default sets the lookahead to 5s, so the existing
mzcompose-based PostgreSQL source tests exercise the early rewind path.
#39420 adds targeted coverage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <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