Skip to content

Commit fe7bbc4

Browse files
committed
Fix remote position tracking in logical replication
We need to set the origin remote position to end_lsn, not commit_lsn, as commit_lsn is the start of commit record, and we use the origin remote position as start position when restarting replication stream. If we'd use commit_lsn, we could request data that we already received from the remote server after a crash of a downstream server. Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
1 parent b38006e commit fe7bbc4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/backend/replication/logical/worker.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,6 @@ apply_handle_begin(StringInfo s)
421421

422422
logicalrep_read_begin(s, &begin_data);
423423

424-
replorigin_session_origin_timestamp = begin_data.committime;
425-
replorigin_session_origin_lsn = begin_data.final_lsn;
426-
427424
remote_final_lsn = begin_data.final_lsn;
428425

429426
in_remote_transaction = true;
@@ -443,14 +440,18 @@ apply_handle_commit(StringInfo s)
443440

444441
logicalrep_read_commit(s, &commit_data);
445442

446-
Assert(commit_data.commit_lsn == replorigin_session_origin_lsn);
447-
Assert(commit_data.committime == replorigin_session_origin_timestamp);
448-
449443
Assert(commit_data.commit_lsn == remote_final_lsn);
450444

451445
/* The synchronization worker runs in single transaction. */
452446
if (IsTransactionState() && !am_tablesync_worker())
453447
{
448+
/*
449+
* Update origin state so we can restart streaming from correct
450+
* position in case of crash.
451+
*/
452+
replorigin_session_origin_lsn = commit_data.end_lsn;
453+
replorigin_session_origin_timestamp = commit_data.committime;
454+
454455
CommitTransactionCommand();
455456

456457
store_flush_position(commit_data.end_lsn);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy