Skip to content

spock_apply: do not send local LSN as publisher feedback on sync-standby#491

Open
ibrarahmad wants to merge 3 commits into
v5_STABLEfrom
SPOC-576
Open

spock_apply: do not send local LSN as publisher feedback on sync-standby#491
ibrarahmad wants to merge 3 commits into
v5_STABLEfrom
SPOC-576

Conversation

@ibrarahmad
Copy link
Copy Markdown
Contributor

The synchronous-standby hold queue stored the subscriber's local XactLastCommitEnd in RemoteSyncPosition.recvpos and later sent it to the publisher as the slot's confirmed flush position. The two LSNs belong to different WAL streams, so the publisher wrote a meaningless value into confirmed_flush_lsn -- typically far ahead of its own pg_current_wal_lsn. After a CNPG failover the promoted standby resumed from that bogus LSN, the publisher waited until its own WAL caught up, then started streaming from there. Every commit between the real origin position and the bogus LSN was silently dropped.

Split RemoteSyncPosition into local_commit_lsn (gating) and remote_recvpos / remote_writepos / remote_flushpos (feedback). append_feedback_position now takes both LSNs explicitly. get_feedback_position gates the release on local_commit_lsn <= WalSndCtl->lsn[SYNC_REP_WAIT_FLUSH] and returns the remote positions, so the publisher sees values from its own WAL stream.

The synchronous-standby hold queue stored the subscriber's local
XactLastCommitEnd in RemoteSyncPosition.recvpos and later sent it to
the publisher as the slot's confirmed flush position. The two LSNs
belong to different WAL streams, so the publisher wrote a meaningless
value into confirmed_flush_lsn -- typically far ahead of its own
pg_current_wal_lsn. After a CNPG failover the promoted standby
resumed from that bogus LSN, the publisher waited until its own WAL
caught up, then started streaming from there. Every commit between
the real origin position and the bogus LSN was silently dropped.

Split RemoteSyncPosition into local_commit_lsn (gating) and
remote_recvpos / remote_writepos / remote_flushpos (feedback).
append_feedback_position now takes both LSNs explicitly.
get_feedback_position gates the release on local_commit_lsn <=
WalSndCtl->lsn[SYNC_REP_WAIT_FLUSH] and returns the remote positions,
so the publisher sees values from its own WAL stream.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 64972948-414b-4a6c-8e8a-37ecd432a8c5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch SPOC-576

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Jun 3, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown
Member

@mason-sharp mason-sharp left a comment

Choose a reason for hiding this comment

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

Can you also add a test?

Comment thread src/spock_apply.c Outdated
Comment thread src/spock_apply.c Outdated
@mason-sharp mason-sharp requested a review from rasifr June 3, 2026 22:22
Drop the trailing paragraph and sentence that described the pre-fix
behaviour in the comments before append_feedback_position() and
get_feedback_position(); they belong in the commit message, not the
source.  Add tests/tap/t/020_sync_standby_feedback_lsn.pl, which
attaches a synchronous physical standby to the subscriber and asserts
the publisher's confirmed_flush_lsn never exceeds its own
pg_current_wal_lsn.
Comment thread tests/tap/t/020_sync_standby_feedback_lsn.pl
Promote the subscriber's sync standby after the publisher commits and
assert every publisher row is present on the new primary.  The
original bug surfaced as silently dropped writes after promotion; the
LSN symptom check alone does not exercise that path.
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