diff options
author | Amit Kapila <akapila@postgresql.org> | 2022-03-30 07:41:05 +0530 |
---|---|---|
committer | Amit Kapila <akapila@postgresql.org> | 2022-03-30 07:41:05 +0530 |
commit | d5a9d86d8ffcadc52ff3729cd00fbd83bc38643c (patch) | |
tree | 2b5497206cf558509284df8817bd350e4d27dbb1 /src/test | |
parent | ad4f2c47de440cdd5d58cf9ffea09afa0da04d6c (diff) | |
download | postgresql-d5a9d86d8ffcadc52ff3729cd00fbd83bc38643c.tar.gz postgresql-d5a9d86d8ffcadc52ff3729cd00fbd83bc38643c.zip |
Skip empty transactions for logical replication.
The current logical replication behavior is to send every transaction to
subscriber even if the transaction is empty. This can happen because
transaction doesn't contain changes from the selected publications or all
the changes got filtered. It is a waste of CPU cycles and network
bandwidth to build/transmit these empty transactions.
This patch addresses the above problem by postponing the BEGIN message
until the first change is sent. While processing a COMMIT message, if
there was no other change for that transaction, do not send the COMMIT
message. This allows us to skip sending BEGIN/COMMIT messages for empty
transactions.
When skipping empty transactions in synchronous replication mode, we send
a keepalive message to avoid delaying such transactions.
Author: Ajin Cherian, Hou Zhijie, Euler Taveira
Reviewed-by: Peter Smith, Takamichi Osumi, Shi Yu, Masahiko Sawada, Greg Nancarrow, Vignesh C, Amit Kapila
Discussion: https://postgr.es/m/CAMkU=1yohp9-dv48FLoSPrMqYEyyS5ZWkaZGD41RJr10xiNo_Q@mail.gmail.com
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/subscription/t/001_rep_changes.pl | 28 | ||||
-rw-r--r-- | src/test/subscription/t/020_messages.pl | 5 |
2 files changed, 30 insertions, 3 deletions
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl index eca1c633359..d35a133f154 100644 --- a/src/test/subscription/t/001_rep_changes.pl +++ b/src/test/subscription/t/001_rep_changes.pl @@ -473,6 +473,34 @@ $node_publisher->safe_psql('postgres', "INSERT INTO tab_full VALUES(0)"); $node_publisher->wait_for_catchup('tap_sub'); +# Check that we don't send BEGIN and COMMIT because of empty transaction +# optimization. We have to look for the DEBUG1 log messages about that, so +# temporarily bump up the log verbosity. +$node_publisher->append_conf('postgresql.conf', "log_min_messages = debug1"); +$node_publisher->reload; + +# Note that the current location of the log file is not grabbed immediately +# after reloading the configuration, but after sending one SQL command to +# the node so that we are sure that the reloading has taken effect. +$log_location = -s $node_publisher->logfile; + +$node_publisher->safe_psql('postgres', "INSERT INTO tab_notrep VALUES (11)"); + +$node_publisher->wait_for_catchup('tap_sub'); + +$logfile = slurp_file($node_publisher->logfile, $log_location); +ok( $logfile =~ + qr/skipped replication of an empty transaction with XID/, + 'empty transaction is skipped'); + +$result = $node_subscriber->safe_psql('postgres', + "SELECT count(*) FROM tab_notrep"); +is($result, qq(0), 'check non-replicated table is empty on subscriber'); + +$node_publisher->append_conf('postgresql.conf', + "log_min_messages = warning"); +$node_publisher->reload; + # note that data are different on provider and subscriber $result = $node_subscriber->safe_psql('postgres', "SELECT count(*), min(a), max(a) FROM tab_ins"); diff --git a/src/test/subscription/t/020_messages.pl b/src/test/subscription/t/020_messages.pl index b5045ff3c43..d21d929c2d8 100644 --- a/src/test/subscription/t/020_messages.pl +++ b/src/test/subscription/t/020_messages.pl @@ -87,9 +87,8 @@ $result = $node_publisher->safe_psql( 'publication_names', 'tap_pub') )); -# 66 67 == B C == BEGIN COMMIT -is( $result, qq(66 -67), +# no message and no BEGIN and COMMIT because of empty transaction optimization +is($result, qq(), 'option messages defaults to false so message (M) is not available on slot' ); |