Skip to content

Support replication origin advance for xid-less commits#54

Draft
GremSnoort wants to merge 1 commit intopatches17from
xidless-commit-replorigin-advance
Draft

Support replication origin advance for xid-less commits#54
GremSnoort wants to merge 1 commit intopatches17from
xidless-commit-replorigin-advance

Conversation

@GremSnoort
Copy link
Copy Markdown
Contributor

Summary

This patch adds a transaction-level integration point to PostgreSQL commit machinery to support correct replication origin advancement for top-level transactions that reach commit without a heap XID but still have a durable local commit LSN.

The immediate motivation is fixing logical replication failures observed with storage engines that use a non-heap-XID commit model, such as OrioleDB.

Problem

PostgreSQL currently assumes the following model:

  • if a transaction has a top-level heap xid, its durable commit point is known through the regular commit WAL path
  • if a transaction has no top-level heap xid, it is effectively treated as outside the ordinary commit/origin path

That assumption is too narrow for storage engines that can:

  • commit without assigning a top-level heap xid
  • still produce a real durable commit effect
  • still have a valid local commit LSN in PostgreSQL WAL space

OrioleDB is one such case.

As a result, a logical replication apply worker can successfully apply changes and reach commit, but if the transaction has no top-level heap xid, PostgreSQL does not treat it as a participant in normal replication-origin advancement.

This breaks restart/replay correctness for subscriber-side logical apply.

Root Cause

RecordTransactionCommit() currently ties replication-origin advancement to the ordinary heap-XID commit path.

Conceptually:

  • markXidCommitted == true
    • regular commit WAL path exists
    • commit LSN is known
    • replication origin is advanced normally
  • markXidCommitted == false
    • no regular commit record is produced
    • no generic way exists for PostgreSQL to ask whether the transaction still has a durable local commit point
    • replication origin is not advanced through the same commit/origin protocol

This means PostgreSQL currently has no general abstraction for:

  • xid-less top-level transaction
  • with durable commit effect
  • with valid local commit LSN
  • requiring correct replication-origin handling

Solution

Introduce a new transaction-level hook: get_xidless_commit_lsn_hook.

Its contract is narrow:

  • it is consulted only from RecordTransactionCommit()
  • only for top-level transactions that reach commit without a heap xid
  • if the extension can provide a durable local commit LSN for the current transaction, it returns that LSN

This lets PostgreSQL remain the owner of commit/origin policy, while allowing a storage engine to provide the missing durable anchor.

Add a transaction-level hook that lets an extension provide a durable local
commit LSN for a top-level transaction that reaches commit without a heap XID.

Use that LSN in RecordTransactionCommit() to advance replication origin from
the no-XID path, and propagate it through the rest of the commit tail for
flush, async commit tracking, synchronous replication wait, and
XactLastCommitEnd.

This keeps commit/origin policy in core PostgreSQL while allowing storage
engines with xid-less commit paths to participate through a narrow hook.
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.

1 participant