Skip to content

feat(resharding): use binary protocol for replication#1016

Open
meskill wants to merge 1 commit into
mainfrom
feat/replication-binary
Open

feat(resharding): use binary protocol for replication#1016
meskill wants to merge 1 commit into
mainfrom
feat/replication-binary

Conversation

@meskill
Copy link
Copy Markdown
Contributor

@meskill meskill commented May 28, 2026

Use binary protocol for replication slot if resharding_copy_format set to binary.

Performance benefits are minimal, guess mostly because of the current sequential streaming handling in replication (send -> wait for reply for every event).

I managed to get some improvements on benchmarks only with toxiproxy in case of limited bandwidth
image

otherwise no difference

@meskill meskill force-pushed the feat/replication-binary branch from 36b0194 to a025a14 Compare May 28, 2026 10:00
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 97.72727% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...src/net/messages/replication/logical/tuple_data.rs 96.92% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Collaborator

@levkk levkk left a comment

Choose a reason for hiding this comment

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

Cool! It should be a bit faster but maybe the cost of decoding the WAL is too high to matter.

let query = Query::new(format!(
r#"START_REPLICATION SLOT "{}" LOGICAL {} ("proto_version" '4', origin 'any', "publication_names" '"{}"')"#,
self.name, self.lsn, self.publication
r#"START_REPLICATION SLOT "{}" LOGICAL {} ("proto_version" '4', origin 'any', "publication_names" '"{}"', "binary" '{}')"#,
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 know we're not passing user input, but seeing format! instead of prepared statements still makes me wince 😅

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The logical replication protocol doesn't support prepared statements.

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.

RIP

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.

Looking at it again I don't even know why my brain parsed this as a SQL query.
IgnoreMeTheVentureBrosGIF

.collect::<Vec<_>>();
Bind::new_params(name, &params)
.unzip();
Bind::new_params_codes(name, &params, &codes)
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.

Not entirely relevant to this PR since you didn't add this function, but this smells like we should use a builder

@levkk
Copy link
Copy Markdown
Collaborator

levkk commented May 28, 2026

Speaking of sync streaming ...we should definitely work on that - push queries without waiting for replies. There isn't any downside afaik, and we can always error-out if we eventually receive an error.

Basically have two tokio task loops run side by side:

  1. Send queries
  2. Receive replies and check for errors, send error via mpsc to parent

I bet this would make replication super quick.

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.

3 participants