Content-Length: 303675 | pFad | http://github.com/postgres/postgres/commit/9d1a6235960697b5dbc5e0b7d56d59c0a6de3b3d

0F Don't retreat slot's confirmed_flush LSN. · postgres/postgres@9d1a623 · GitHub
Skip to content

Commit 9d1a623

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 00652b3 commit 9d1a623

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
@@ -1753,7 +1753,19 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
17531753

17541754
SpinLockAcquire(&MyReplicationSlot->mutex);
17551755

1756-
MyReplicationSlot->data.confirmed_flush = lsn;
1756+
/*
1757+
* Prevent moving the confirmed_flush backwards, as this could lead to
1758+
* data duplication issues caused by replicating already replicated
1759+
* changes.
1760+
*
1761+
* This can happen when a client acknowledges an LSN it doesn't have
1762+
* to do anything for, and thus didn't store persistently. After a
1763+
* restart, the client can send the prior LSN that it stored
1764+
* persistently as an acknowledgement, but we need to ignore such an
1765+
* LSN. See similar case handling in CreateDecodingContext.
1766+
*/
1767+
if (lsn > MyReplicationSlot->data.confirmed_flush)
1768+
MyReplicationSlot->data.confirmed_flush = lsn;
17571769

17581770
/* if we're past the location required for bumping xmin, do so */
17591771
if (MyReplicationSlot->candidate_xmin_lsn != InvalidXLogRecPtr &&
@@ -1818,7 +1830,14 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
18181830
else
18191831
{
18201832
SpinLockAcquire(&MyReplicationSlot->mutex);
1821-
MyReplicationSlot->data.confirmed_flush = lsn;
1833+
1834+
/*
1835+
* Prevent moving the confirmed_flush backwards. See comments above
1836+
* for the details.
1837+
*/
1838+
if (lsn > MyReplicationSlot->data.confirmed_flush)
1839+
MyReplicationSlot->data.confirmed_flush = lsn;
1840+
18221841
SpinLockRelease(&MyReplicationSlot->mutex);
18231842
}
18241843
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgres/postgres/commit/9d1a6235960697b5dbc5e0b7d56d59c0a6de3b3d

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy