postgresql/src
Amit Kapila 88f488319b Make the tablesync worker's replication origin drop logic robust.
In commit f6c5edb8ab, we started to drop the replication origin slots
before tablesync worker exits to avoid consuming more slots than required.
We were dropping the replication origin in the same transaction where we
were marking the tablesync state as SYNCDONE. Now, if there is any error
after we have dropped the origin but before we commit the containing
transaction, the in-memory state of replication progress won't be rolled
back. Due to this, after the restart, tablesync worker can start streaming
from the wrong location and can apply the already processed transaction.

To fix this, we need to opportunistically drop the origin after marking
the tablesync state as SYNCDONE. Even, if the tablesync worker fails to
remove the replication origin before exit, the apply worker ensures to
clean it up afterward.

Reported by Tom Lane as per buildfarm.
Diagnosed-by: Masahiko Sawada
Author: Hou Zhijie
Reviewed-By: Masahiko Sawada, Amit Kapila
Discussion: https://postgr.es/m/20220714115155.GA5439@depesz.com
Discussion: https://postgr.es/m/CAD21AoAw0Oofi4kiDpJBOwpYyBBBkJj=sLUOn4Gd2GjUAKG-fw@mail.gmail.com
2022-09-12 12:40:57 +05:30
..
backend Make the tablesync worker's replication origin drop logic robust. 2022-09-12 12:40:57 +05:30
bin Assorted examples of expanded type-safer palloc/pg_malloc API 2022-09-12 08:45:03 +02:00
common Assorted examples of expanded type-safer palloc/pg_malloc API 2022-09-12 08:45:03 +02:00
fe_utils Clean up inconsistent use of fflush(). 2022-08-29 13:55:41 -04:00
include Expand palloc/pg_malloc API for more type safety 2022-09-12 08:45:03 +02:00
interfaces Fix possible omission of variable storage markers in ECPG. 2022-09-09 15:34:04 -04:00
makefiles aix: No need to use mkldexport when we want to export all symbols 2022-09-09 19:11:49 -07:00
pl Bump minimum version of Bison to 2.3 2022-09-09 12:31:41 +07:00
port Cleanup more code and comments related to Windows NT4 (XP days) 2022-08-30 09:52:58 +09:00
template Move darwin sysroot determination into separate file 2022-09-01 16:54:19 -07:00
test Choose FK name correctly during partition attachment 2022-09-08 13:17:02 +02:00
timezone Expand the use of get_dirent_type(), shaving a few calls to stat()/lstat() 2022-09-02 16:58:06 +09:00
tools Bump minimum version of Flex to 2.5.35 2022-09-09 12:55:23 +07:00
tutorial Update copyright for 2022 2022-01-07 19:04:57 -05:00
.gitignore
DEVELOPERS
Makefile Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00
Makefile.global.in Remove unused configure variable. 2022-08-18 11:22:13 -04:00
Makefile.shlib aix: No need to use mkldexport when we want to export all symbols 2022-09-09 19:11:49 -07:00
nls-global.mk Fix for make unportability 2022-07-13 09:15:01 +02:00