Re: Introduce wait_for_subscription_sync for TAP tests
Amit Kapila <amit.kapila16@gmail.com>
From: Amit Kapila <amit.kapila16@gmail.com>
To: Masahiko Sawada <sawada.mshk@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-07-26T05:01:15Z
Lists: pgsql-hackers
On Tue, Jul 26, 2022 at 7:07 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
>
> Hi,
>
> In tap tests for logical replication, we have the following code in many places:
>
> $node_publisher->wait_for_catchup('tap_sub');
> my $synced_query =
> "SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT
> IN ('r', 's');";
> $node_subscriber->poll_query_until('postgres', $synced_query)
> or die "Timed out while waiting for subscriber to synchronize data";
>
> Also, we sometime forgot to check either one, like we fixed in commit
> 1f50918a6fb02207d151e7cb4aae4c36de9d827c.
>
> I think we can have a new function to wait for all subscriptions to
> synchronize data. The attached patch introduce a new function
> wait_for_subscription_sync(). With this function, we can replace the
> above code with this one function as follows:
>
> $node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub');
>
+1. This reduces quite some code in various tests and will make it
easier to write future tests.
Few comments/questions:
====================
1.
-$node_publisher->wait_for_catchup('mysub1');
-
-# Also wait for initial table sync to finish.
-my $synced_query =
- "SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT
IN ('r', 's');";
-$node_subscriber->poll_query_until('postgres', $synced_query)
- or die "Timed out while waiting for subscriber to synchronize data";
-
# Also wait for initial table sync to finish.
-$node_subscriber->poll_query_until('postgres', $synced_query)
- or die "Timed out while waiting for subscriber to synchronize data";
+$node_subscriber->wait_for_subscription_sync($node_publisher, 'mysub1');
It seems to me without your patch there is an extra poll in the above
test. If so, we can probably remove that in a separate patch?
2.
+ # wait for the replication to catchup if required.
+ if (defined($publisher))
+ {
+ croak 'subscription name must be specified' unless defined($subname);
+ $publisher->wait_for_catchup($subname, 'replay');
+ }
+
+ # then, wait for all table states to be ready.
+ print "Waiting for all subscriptions in \"$name\" to synchronize data\n";
+ my $query = qq[SELECT count(1) = 0
+ FROM pg_subscription_rel
+ WHERE srsubstate NOT IN ('r', 's');];
+ $self->poll_query_until($dbname, $query)
+ or croak "timed out waiting for subscriber to synchronize data";
In the tests, I noticed that a few places did wait_for_catchup after
the subscription check, and at other places, we did that check before
as you have it here. Ideally, I think wait_for_catchup should be after
confirming the initial sync is over as without initial sync, the
publisher node won't be completely in sync with the subscriber. What
do you think?
3. In the code quoted in the previous point, why did you pass the
second parameter as 'replay' when we have not used that in the tests
otherwise?
--
With Regards,
Amit Kapila.
Commits
-
Fix recovery_prefetch with low maintenance_io_concurrency.
- adb466150b44 16.0 cited
-
Drop replication origin slots before tablesync worker exits.
- f6c5edb8abca 16.0 cited
-
Back-Patch "Add wait_for_subscription_sync for TAP tests."
- 15014b823203 15.0 landed
- e082ef9c4282 14.6 landed
- 5afa63f0aed9 13.9 landed
- 036642abc9fb 12.13 landed
- 63903546e5d6 11.18 landed
- f01e16b1987e 10.23 landed
-
Add wait_for_subscription_sync for TAP tests.
- 0c20dd33db16 16.0 landed
-
Remove duplicated wait for subscription sync from 007_ddl.pl.
- 7bf91ec0f3b4 16.0 landed
- 572baf2b3e20 15.0 landed
-
Fix intermetent test failure in 028_row_filter.pl.
- 1f50918a6fb0 15.0 cited
-
Refactor subscription tests to use PostgresNode's wait_for_catchup
- bbd3363e128d 11.0 cited