Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite5ed873

Browse files
Fix a possibility of logical replication slot's restart_lsn going backwards.
Previously LogicalIncreaseRestartDecodingForSlot() accidentallyaccepted any LSN as the candidate_lsn and candidate_valid after therestart_lsn of the replication slot was updated, so it potentiallycaused the restart_lsn to move backwards.A scenario where this could happen in logical replication is: after alogical replication restart, based on previous candidate_lsn andcandidate_valid values in memory, the restart_lsn advances uponreceiving a subscriber acknowledgment. Then, logical decoding restartsfrom an older point, setting candidate_lsn and candidate_valid basedon an old RUNNING_XACTS record. Subsequent subscriber acknowledgmentsthen update the restart_lsn to an LSN older than the current value.In the reported case, after WAL files were removed by a checkpoint,the retreated restart_lsn prevented logical replication fromrestarting due to missing WAL segments.This change essentially modifies the 'if' condition to 'else if'condition within the function. The previous code had an asymmetry inthis regard compared to LogicalIncreaseXminForSlot(), which doesalmost the same thing for different fields.The WAL removal issue was reported by Hubert Depesz Lubaczewski.Backpatch to all supported versions, since the bug exists since 9.4where logical decoding was introduced.Reviewed-by: Tomas Vondra, Ashutosh Bapat, Amit KapilaDiscussion:https://postgr.es/m/Yz2hivgyjS1RfMKs%40depesz.comDiscussion:https://postgr.es/m/85fff40e-148b-4e86-b921-b4b846289132%40vondra.meBackpatch-through: 13
1 parentb69bdce commite5ed873

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

‎src/backend/replication/logical/logical.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,7 @@ LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart
17741774
/* don't overwrite if have a newer restart lsn */
17751775
if (restart_lsn <=slot->data.restart_lsn)
17761776
{
1777+
SpinLockRelease(&slot->mutex);
17771778
}
17781779

17791780
/*
@@ -1784,6 +1785,7 @@ LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart
17841785
{
17851786
slot->candidate_restart_valid=current_lsn;
17861787
slot->candidate_restart_lsn=restart_lsn;
1788+
SpinLockRelease(&slot->mutex);
17871789

17881790
/* our candidate can directly be used */
17891791
updated_lsn= true;
@@ -1794,7 +1796,7 @@ LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart
17941796
* might never end up updating if the receiver acks too slowly. A missed
17951797
* value here will just cause some extra effort after reconnecting.
17961798
*/
1797-
if (slot->candidate_restart_valid==InvalidXLogRecPtr)
1799+
elseif (slot->candidate_restart_valid==InvalidXLogRecPtr)
17981800
{
17991801
slot->candidate_restart_valid=current_lsn;
18001802
slot->candidate_restart_lsn=restart_lsn;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp