Skip to content

Commit e323d9d

Browse files
author
Amit Kapila
committed
Don't retreat slot's confirmed_flush LSN.
Prevent moving the confirmed_flush backwards, as this could lead to data duplication issues caused by replicating already replicated changes. This can happen when a client acknowledges an LSN it doesn't have to do anything for, and thus didn't store persistently. After a restart, the client can send the prior LSN that it stored persistently as an acknowledgement, but we need to ignore such an LSN to avoid retreating confirm_flush LSN. Diagnosed-by: Zhijie Hou <houzj.fnst@fujitsu.com> Author: shveta malik <shveta.malik@gmail.com> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com> Tested-by: Nisha Moond <nisha.moond412@gmail.com> Backpatch-through: 13 Discussion: https://postgr.es/m/CAJpy0uDZ29P=BYB1JDWMCh-6wXaNqMwG1u1mB4=10Ly0x7HhwQ@mail.gmail.com Discussion: https://postgr.es/m/OS0PR01MB57164AB5716AF2E477D53F6F9489A@OS0PR01MB5716.jpnprd01.prod.outlook.com
1 parent 9bc2d37 commit e323d9d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/backend/replication/logical/logical.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,19 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
10371037

10381038
SpinLockAcquire(&MyReplicationSlot->mutex);
10391039

1040-
MyReplicationSlot->data.confirmed_flush = lsn;
1040+
/*
1041+
* Prevent moving the confirmed_flush backwards, as this could lead to
1042+
* data duplication issues caused by replicating already replicated
1043+
* changes.
1044+
*
1045+
* This can happen when a client acknowledges an LSN it doesn't have
1046+
* to do anything for, and thus didn't store persistently. After a
1047+
* restart, the client can send the prior LSN that it stored
1048+
* persistently as an acknowledgement, but we need to ignore such an
1049+
* LSN. See similar case handling in CreateDecodingContext.
1050+
*/
1051+
if (lsn > MyReplicationSlot->data.confirmed_flush)
1052+
MyReplicationSlot->data.confirmed_flush = lsn;
10411053

10421054
/* if we're past the location required for bumping xmin, do so */
10431055
if (MyReplicationSlot->candidate_xmin_lsn != InvalidXLogRecPtr &&
@@ -1102,7 +1114,14 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
11021114
else
11031115
{
11041116
SpinLockAcquire(&MyReplicationSlot->mutex);
1105-
MyReplicationSlot->data.confirmed_flush = lsn;
1117+
1118+
/*
1119+
* Prevent moving the confirmed_flush backwards. See comments above
1120+
* for the details.
1121+
*/
1122+
if (lsn > MyReplicationSlot->data.confirmed_flush)
1123+
MyReplicationSlot->data.confirmed_flush = lsn;
1124+
11061125
SpinLockRelease(&MyReplicationSlot->mutex);
11071126
}
11081127
}

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