Skip to content

feat: write several LTX files in one call, with Postgres and S3 - #58

Merged
marcopiraccini merged 6 commits into
mainfrom
feat/pg-write-ltx-files-only
Dec 2, 2026
Merged

marcopiraccini merged 6 commits into
mainfrom
feat/pg-write-ltx-files-only

Conversation

@marcopiraccini

@marcopiraccini marcopiraccini commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

PgReplicaClient.writeLtxFiles() and S3ReplicaClient.writeLtxFiles() write several LTX files, of one replica or of several, in one call, and return one result for each file. They are meant for many small files which are ready at the same time.

With Postgres the files go in one transaction: one commit for all, with fencing checked for each replica. A failure of the transaction rejects the call with PgWriteLtxFilesError, which tells whether nothing was written or the outcome is unknown.

S3 has no transaction: the replicas are written in parallel (concurrency, 16 by default), the files of a replica in order, and a fenced replica is checked against its generation once, after its last file. The files of a call must use one S3 client, and the files of a replica one generation, fixed when the call begins.

With both, a file which is not written takes the later files of its replica with it, so a replica never gets a hole in its history.

Measured with Postgres only, syncing after every write: about 4% more writes a second (534 against 497 and 514 with 16 writes in flight, 740 against 710 with 64), which is close to the difference between two runs. S3 is not measured.

Tests cover both backends: several replicas in one call, superseded replicas, files left out and the ones after them, failed uploads and commits, and for S3 the generation changing during the call.

…the later files of its replica

A commit whose answer is lost can still become visible after a look for
its files, and a file of the same size does not prove it is the one which
was written: the outcome is unknown whenever the failure comes with the
commit, and the files are not looked for.

A file of a superseded client left the later files of the same replica
in the batch, from a current client, to be written after it: they are
left out too.
…left out

A file too short to be one marked its replica before the transaction, and
the files before it were then left out with it. Only the files after it
are; the files left out for their generation are tracked apart.
…that nothing was written

The tables which cannot be created rejected the call with a raw error,
and so did a header which is not one. The first is rolled-back, as
nothing was written; the second leaves its file out, as a file too short
to hold a header does.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this needs to added to S3 backend as well

@marcopiraccini marcopiraccini changed the title feat(pg): write several LTX files in one transaction feat: write several LTX files in one call, with Postgres and S3 Dec 2, 2026

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@marcopiraccini
marcopiraccini merged commit f5ebfb0 into main Dec 2, 2026
19 checks passed
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