Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ede692

Browse files
author
Amit Kapila
committed
Fix the race condition in the test added by 7c99dc5.
After executing ALTER SUBSCRIPTION tap_sub SET PUBLICATION, we did not wait for the new walsender process to restart. As a result, an INSERT executed immediately after the ALTER could be decoded and skipped, considering it is not part of any subscribed publication. And, the old apply worker could also confirm the LSN of such an INSERT. This could cause the replication to resume from a point after the INSERT. In such cases, we miss the expected warning about the missing publication. To fix this, ensure the walsender has restarted before continuing after ALTER SUBSCRIPTION. Reported-by: Tom Lane as per CI Author: vignesh C <[email protected]> Reviewed-by: Xuneng Zhou <[email protected]> Reviewed-by: Amit Kapila <[email protected]> Discussion: https://postgr.es/m/[email protected]
1 parent dbf42b8 commit 8ede692

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/test/subscription/t/024_add_drop_pub.pl

+11
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,21 @@
9191
$node_publisher->safe_psql('postgres', "CREATE TABLE tab_3 (a int)");
9292
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_3 (a int)");
9393

94+
my $oldpid = $node_publisher->safe_psql('postgres',
95+
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
96+
);
97+
9498
# Set the subscription with a missing publication
9599
$node_subscriber->safe_psql('postgres',
96100
"ALTER SUBSCRIPTION tap_sub SET PUBLICATION tap_pub_3");
97101

102+
# Wait for the walsender to restart after altering the subscription
103+
$node_publisher->poll_query_until('postgres',
104+
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
105+
)
106+
or die
107+
"Timed out while waiting for apply worker to restart after altering the subscription";
108+
98109
my $offset = -s $node_publisher->logfile;
99110

100111
$node_publisher->safe_psql('postgres',"INSERT INTO tab_3 values(1)");

0 commit comments

Comments
 (0)