pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Allow multiple xacts during table sync in logical replication.
13+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2021-02-15 d9b0767bec Fix the warnings introduced in commit ce0fdbfe97.
* pgsql: Allow multiple xacts during table sync in logical replication.
@ 2021-02-12 02:20 Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 13+ messages in thread
From: Amit Kapila @ 2021-02-12 02:20 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Allow multiple xacts during table sync in logical replication.
For the initial table data synchronization in logical replication, we use
a single transaction to copy the entire table and then synchronize the
position in the stream with the main apply worker.
There are multiple downsides of this approach: (a) We have to perform the
entire copy operation again if there is any error (network breakdown,
error in the database operation, etc.) while we synchronize the WAL
position between tablesync worker and apply worker; this will be onerous
especially for large copies, (b) Using a single transaction in the
synchronization-phase (where we can receive WAL from multiple
transactions) will have the risk of exceeding the CID limit, (c) The slot
will hold the WAL till the entire sync is complete because we never commit
till the end.
This patch solves all the above downsides by allowing multiple
transactions during the tablesync phase. The initial copy is done in a
single transaction and after that, we commit each transaction as we
receive. To allow recovery after any error or crash, we use a permanent
slot and origin to track the progress. The slot and origin will be removed
once we finish the synchronization of the table. We also remove slot and
origin of tablesync workers if the user performs DROP SUBSCRIPTION .. or
ALTER SUBSCRIPTION .. REFERESH and some of the table syncs are still not
finished.
The commands ALTER SUBSCRIPTION ... REFRESH PUBLICATION and
ALTER SUBSCRIPTION ... SET PUBLICATION ... with refresh option as true
cannot be executed inside a transaction block because they can now drop
the slots for which we have no provision to rollback.
This will also open up the path for logical replication of 2PC
transactions on the subscriber side. Previously, we can't do that because
of the requirement of maintaining a single transaction in tablesync
workers.
Bump catalog version due to change of state in the catalog
(pg_subscription_rel).
Author: Peter Smith, Amit Kapila, and Takamichi Osumi
Reviewed-by: Ajin Cherian, Petr Jelinek, Hou Zhijie and Amit Kapila
Discussion: https://postgr.es/m/CAA4eK1KHJxaZS-fod-0fey=0tq3=Gkn4ho=8N4-5HWiCfu0H1A@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ce0fdbfe9722867b7fad4d3ede9b6a6bfc51fb4e
Modified Files
--------------
doc/src/sgml/catalogs.sgml | 1 +
doc/src/sgml/logical-replication.sgml | 59 ++-
doc/src/sgml/ref/alter_subscription.sgml | 18 +
doc/src/sgml/ref/drop_subscription.sgml | 6 +-
src/backend/access/transam/xact.c | 11 -
src/backend/catalog/pg_subscription.c | 38 ++
src/backend/commands/subscriptioncmds.c | 467 ++++++++++++++++-----
.../libpqwalreceiver/libpqwalreceiver.c | 8 +
src/backend/replication/logical/launcher.c | 147 -------
src/backend/replication/logical/tablesync.c | 236 +++++++++--
src/backend/replication/logical/worker.c | 18 +-
src/backend/tcop/utility.c | 3 +-
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_subscription_rel.h | 2 +
src/include/commands/subscriptioncmds.h | 2 +-
src/include/replication/logicallauncher.h | 2 -
src/include/replication/slot.h | 3 +
src/include/replication/walreceiver.h | 1 +
src/include/replication/worker_internal.h | 3 +-
src/test/regress/expected/subscription.out | 21 +
src/test/regress/sql/subscription.sql | 22 +
src/test/subscription/t/004_sync.pl | 21 +-
src/tools/pgindent/typedefs.list | 2 +-
23 files changed, 767 insertions(+), 326 deletions(-)
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
@ 2021-02-12 02:53 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:20 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 2 replies; 13+ messages in thread
From: Amit Kapila @ 2021-02-12 02:53 UTC (permalink / raw)
To: Amit Kapila <akapila@postgresql.org>; +Cc: pgsql-committers <pgsql-committers@lists.postgresql.org>
On Fri, Feb 12, 2021 at 7:50 AM Amit Kapila <akapila@postgresql.org> wrote:
>
> Allow multiple xacts during table sync in logical replication.
>
I noticed one failure:
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=thorntail&dt=2021-02-12%2002%3A28%3A12
Checking the same.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
@ 2021-02-12 03:17 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:30 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
1 sibling, 1 reply; 13+ messages in thread
From: Tom Lane @ 2021-02-12 03:17 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Amit Kapila <akapila@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
Amit Kapila <amit.kapila16@gmail.com> writes:
> I noticed one failure:
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=thorntail&dt=2021-02-12%2002%3A28%3A12
> Checking the same.
I think thorntail runs with nondefault prevailing wal_level, might be
related.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-02-12 03:30 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 05:21 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 13+ messages in thread
From: Amit Kapila @ 2021-02-12 03:30 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Amit Kapila <akapila@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Fri, Feb 12, 2021 at 8:47 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Amit Kapila <amit.kapila16@gmail.com> writes:
> > I noticed one failure:
> > https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=thorntail&dt=2021-02-12%2002%3A28%3A12
> > Checking the same.
>
> I think thorntail runs with nondefault prevailing wal_level, might be
> related.
>
Right, it is due to max_wal_senders nondefault config parameter. I
think we need to slightly tweak the test so that we don't initially
try to connect, then enable the subscription later with different
command and then perform the rest of the commands.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:30 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
@ 2021-02-12 05:21 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 22:50 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 13+ messages in thread
From: Amit Kapila @ 2021-02-12 05:21 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Amit Kapila <akapila@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Fri, Feb 12, 2021 at 9:00 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Fri, Feb 12, 2021 at 8:47 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >
> > Amit Kapila <amit.kapila16@gmail.com> writes:
> > > I noticed one failure:
> > > https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=thorntail&dt=2021-02-12%2002%3A28%3A12
> > > Checking the same.
> >
> > I think thorntail runs with nondefault prevailing wal_level, might be
> > related.
> >
>
> Right, it is due to max_wal_senders nondefault config parameter. I
> think we need to slightly tweak the test so that we don't initially
> try to connect, then enable the subscription later with different
> command and then perform the rest of the commands.
>
I have pushed the fix for this and waiting for new results of
'thorntail'. In the meantime, I see another failure:
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=walleye&dt=2021-02-12%2003%3A15%3A43
select count(*) > 0 as ok from pg_ls_waldir();
- ok
-----
- t
-(1 row)
-
+ERROR: could not stat file "pg_wal/000000010000000000000072":
Permission denied
I see the exact same failure 66 days ago on the same machine:
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=walleye&dt=2020-12-07%2016%3A15%3A46
This doesn't look to be related to this commit and I am not sure why
it is failing occasionally, maybe due to some machine issues?
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:30 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 05:21 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
@ 2021-02-12 22:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 01:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 13+ messages in thread
From: Tom Lane @ 2021-02-12 22:50 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Amit Kapila <akapila@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
Various buildfarm members are complaining about this patch, eg
caiman | 2021-02-12 15:00:19 | tablesync.c:885:70: warning: argument 3 of type 'char[64]' with mismatched bound [-Warray-parameter=]
caiman | 2021-02-12 15:00:19 | tablesync.c:904:72: warning: argument 3 of type 'char[64]' with mismatched bound [-Warray-parameter=]
That's because of the inconsistency between
extern void ReplicationOriginNameForTablesync(Oid suboid, Oid relid, char *originname);
and
void
ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
char originname[NAMEDATALEN])
Don't do that. Quite aside from the inconsistency, this is pretty
darn unsafe coding technique, because there is exactly nothing
guaranteeing that the caller passes a buffer of the length the
function expects.
I'm not real sure that you could expect a compiler warning for that
even if you'd put the length declaration where callers could see it.
So personally I'd avoid hard-wiring NAMEDATALEN into this API at all,
and have the caller pass sizeof(its buffer) instead.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:30 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 05:21 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 22:50 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-02-13 01:17 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-13 02:27 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 04:01 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 2 replies; 13+ messages in thread
From: Amit Kapila @ 2021-02-13 01:17 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Amit Kapila <akapila@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Sat, Feb 13, 2021 at 4:20 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Don't do that. Quite aside from the inconsistency, this is pretty
> darn unsafe coding technique, because there is exactly nothing
> guaranteeing that the caller passes a buffer of the length the
> function expects.
>
> I'm not real sure that you could expect a compiler warning for that
> even if you'd put the length declaration where callers could see it.
> So personally I'd avoid hard-wiring NAMEDATALEN into this API at all,
> and have the caller pass sizeof(its buffer) instead.
>
Thanks for pointing it out. I'll look into this. BTW, how one can
check such reports, do one need to check all make logs for buildfarm
members?
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:30 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 05:21 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 22:50 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 01:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
@ 2021-02-13 02:27 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 13+ messages in thread
From: Tom Lane @ 2021-02-13 02:27 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Amit Kapila <akapila@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
Amit Kapila <amit.kapila16@gmail.com> writes:
> Thanks for pointing it out. I'll look into this. BTW, how one can
> check such reports, do one need to check all make logs for buildfarm
> members?
Yeah, I have a script that scans the most recent buildfarm runs for
compiler warnings. I run it every few weeks typically (it's not
terribly cheap). Today I was using it to look for complaints
about the 'no-sanitize' stuff, so I happened to notice these new
warnings from your patch.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:30 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 05:21 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 22:50 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 01:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
@ 2021-02-13 04:01 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-13 04:19 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 13+ messages in thread
From: Amit Kapila @ 2021-02-13 04:01 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; Peter Smith <smithpb2250@gmail.com>; +Cc: Amit Kapila <akapila@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Sat, Feb 13, 2021 at 6:47 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Sat, Feb 13, 2021 at 4:20 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >
> > Don't do that. Quite aside from the inconsistency, this is pretty
> > darn unsafe coding technique, because there is exactly nothing
> > guaranteeing that the caller passes a buffer of the length the
> > function expects.
> >
> > I'm not real sure that you could expect a compiler warning for that
> > even if you'd put the length declaration where callers could see it.
> > So personally I'd avoid hard-wiring NAMEDATALEN into this API at all,
> > and have the caller pass sizeof(its buffer) instead.
> >
>
> Thanks for pointing it out. I'll look into this.
>
Attached should fix the reported warnings but as I am not getting
those warnings on my system so can't confirm but otherwise, the patch
works as expected. I am planning to push this unless you or Peter have
any comments.
--
With Regards,
Amit Kapila.
Attachments:
fix_warnings_tblsync_1.patch (application/octet-stream, 6.8K) download
diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c
index 5cf874e..e5ae453 100644
--- a/src/backend/commands/subscriptioncmds.c
+++ b/src/backend/commands/subscriptioncmds.c
@@ -715,7 +715,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
* the origin might be already removed. For these reasons,
* passing missing_ok = true.
*/
- ReplicationOriginNameForTablesync(sub->oid, relid, originname);
+ ReplicationOriginNameForTablesync(sub->oid, relid, originname,
+ sizeof(originname));
replorigin_drop_by_name(originname, true, false);
}
@@ -749,7 +750,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
* dropped slots and fail. For these reasons, we allow
* missing_ok = true for the drop.
*/
- ReplicationSlotNameForTablesync(sub->oid, sub_remove_rels[off].relid, syncslotname);
+ ReplicationSlotNameForTablesync(sub->oid, sub_remove_rels[off].relid,
+ syncslotname, sizeof(syncslotname));
ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
}
}
@@ -1174,7 +1176,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
* worker so passing missing_ok = true. This can happen for the states
* before SUBREL_STATE_FINISHEDCOPY.
*/
- ReplicationOriginNameForTablesync(subid, relid, originname);
+ ReplicationOriginNameForTablesync(subid, relid, originname,
+ sizeof(originname));
replorigin_drop_by_name(originname, true, false);
}
@@ -1254,7 +1257,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
{
char syncslotname[NAMEDATALEN] = {0};
- ReplicationSlotNameForTablesync(subid, relid, syncslotname);
+ ReplicationSlotNameForTablesync(subid, relid, syncslotname,
+ sizeof(syncslotname));
ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
}
}
@@ -1532,7 +1536,8 @@ ReportSlotConnectionError(List *rstates, Oid subid, char *slotname, char *err)
{
char syncslotname[NAMEDATALEN] = {0};
- ReplicationSlotNameForTablesync(subid, relid, syncslotname);
+ ReplicationSlotNameForTablesync(subid, relid, syncslotname,
+ sizeof(syncslotname));
elog(WARNING, "could not drop tablesync replication slot \"%s\"",
syncslotname);
}
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 19cc804..7fd110c 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -314,7 +314,8 @@ process_syncing_tables_for_sync(XLogRecPtr current_lsn)
*/
ReplicationSlotNameForTablesync(MyLogicalRepWorker->subid,
MyLogicalRepWorker->relid,
- syncslotname);
+ syncslotname,
+ sizeof(syncslotname));
/*
* It is important to give an error if we are unable to drop the slot,
@@ -462,7 +463,8 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
*/
ReplicationOriginNameForTablesync(MyLogicalRepWorker->subid,
rstate->relid,
- originname);
+ originname,
+ sizeof(originname));
replorigin_drop_by_name(originname, true, false);
/*
@@ -872,7 +874,7 @@ copy_table(Relation rel)
* length of slot_name will be 50.
*
* The returned slot name is either:
- * - stored in the supplied buffer (syncslotname), or
+ * - stored in the supplied buffer (syncslotname) with the given size, or
* - palloc'ed in current memory context (if syncslotname = NULL).
*
* Note: We don't use the subscription slot name as part of tablesync slot name
@@ -882,15 +884,18 @@ copy_table(Relation rel)
*/
char *
ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
- char syncslotname[NAMEDATALEN])
+ char *syncslotname, int szslot)
{
if (syncslotname)
- sprintf(syncslotname, "pg_%u_sync_%u_" UINT64_FORMAT, suboid, relid,
- GetSystemIdentifier());
+ snprintf(syncslotname, szslot, "pg_%u_sync_%u_" UINT64_FORMAT, suboid,
+ relid, GetSystemIdentifier());
else
syncslotname = psprintf("pg_%u_sync_%u_" UINT64_FORMAT, suboid, relid,
GetSystemIdentifier());
+ /* Ensure slot name meets remote node constraints. */
+ Assert(strlen(syncslotname) < NAMEDATALEN - 1);
+
return syncslotname;
}
@@ -901,9 +906,9 @@ ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
*/
void
ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
- char originname[NAMEDATALEN])
+ char *originname, int szorgname)
{
- snprintf(originname, NAMEDATALEN, "pg_%u_%u", suboid, relid);
+ snprintf(originname, szorgname, "pg_%u_%u", suboid, relid);
}
/*
@@ -953,7 +958,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
/* Calculate the name of the tablesync slot. */
slotname = ReplicationSlotNameForTablesync(MySubscription->oid,
MyLogicalRepWorker->relid,
- NULL /* use palloc */ );
+ NULL,
+ 0);
/*
* Here we use the slot name instead of the subscription name as the
@@ -972,7 +978,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
/* Assign the origin tracking record name. */
ReplicationOriginNameForTablesync(MySubscription->oid,
MyLogicalRepWorker->relid,
- originname);
+ originname,
+ sizeof(originname));
if (MyLogicalRepWorker->relstate == SUBREL_STATE_DATASYNC)
{
diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h
index 5f52335..5317b6f 100644
--- a/src/include/replication/slot.h
+++ b/src/include/replication/slot.h
@@ -212,7 +212,7 @@ extern bool ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive);
extern void ReplicationSlotsDropDBSlots(Oid dboid);
extern void InvalidateObsoleteReplicationSlots(XLogSegNo oldestSegno);
extern ReplicationSlot *SearchNamedReplicationSlot(const char *name);
-extern char *ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname);
+extern char *ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname, int szslot);
extern void ReplicationSlotDropAtPubNode(WalReceiverConn *wrconn, char *slotname, bool missing_ok);
extern void StartupReplicationSlots(void);
diff --git a/src/include/replication/worker_internal.h b/src/include/replication/worker_internal.h
index 4a5adc2..1cac75e 100644
--- a/src/include/replication/worker_internal.h
+++ b/src/include/replication/worker_internal.h
@@ -82,7 +82,8 @@ extern void logicalrep_worker_wakeup_ptr(LogicalRepWorker *worker);
extern int logicalrep_sync_worker_count(Oid subid);
-extern void ReplicationOriginNameForTablesync(Oid suboid, Oid relid, char *originname);
+extern void ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
+ char *originname, int szorgname);
extern char *LogicalRepSyncTableStart(XLogRecPtr *origin_startpos);
void process_syncing_tables(XLogRecPtr current_lsn);
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:30 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 05:21 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 22:50 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 01:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-13 04:01 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
@ 2021-02-13 04:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 05:26 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 13+ messages in thread
From: Tom Lane @ 2021-02-13 04:19 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Peter Smith <smithpb2250@gmail.com>; Amit Kapila <akapila@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
Amit Kapila <amit.kapila16@gmail.com> writes:
> Attached should fix the reported warnings but as I am not getting
> those warnings on my system so can't confirm but otherwise, the patch
> works as expected. I am planning to push this unless you or Peter have
> any comments.
Personally I'd get rid of the option for ReplicationSlotNameForTablesync
to allocate the result buffer. There's only one caller using that,
so it's saving no code to have ReplicationSlotNameForTablesync do the
alloc rather than that one caller; and it seems mighty ugly/nonorthogonal
to have effectively two different APIs in one function.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:30 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 05:21 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 22:50 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 01:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-13 04:01 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-13 04:19 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-02-13 05:26 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-15 10:35 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 13+ messages in thread
From: Amit Kapila @ 2021-02-13 05:26 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Smith <smithpb2250@gmail.com>; Amit Kapila <akapila@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Sat, Feb 13, 2021 at 9:49 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Amit Kapila <amit.kapila16@gmail.com> writes:
> > Attached should fix the reported warnings but as I am not getting
> > those warnings on my system so can't confirm but otherwise, the patch
> > works as expected. I am planning to push this unless you or Peter have
> > any comments.
>
> Personally I'd get rid of the option for ReplicationSlotNameForTablesync
> to allocate the result buffer.
>
Sounds reasonable and the updated patch attached.
--
With Regards,
Amit Kapila.
Attachments:
fix_warnings_tblsync_2.patch (application/octet-stream, 7.1K) download
diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c
index 5cf874e0b4..e5ae4534ae 100644
--- a/src/backend/commands/subscriptioncmds.c
+++ b/src/backend/commands/subscriptioncmds.c
@@ -715,7 +715,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
* the origin might be already removed. For these reasons,
* passing missing_ok = true.
*/
- ReplicationOriginNameForTablesync(sub->oid, relid, originname);
+ ReplicationOriginNameForTablesync(sub->oid, relid, originname,
+ sizeof(originname));
replorigin_drop_by_name(originname, true, false);
}
@@ -749,7 +750,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
* dropped slots and fail. For these reasons, we allow
* missing_ok = true for the drop.
*/
- ReplicationSlotNameForTablesync(sub->oid, sub_remove_rels[off].relid, syncslotname);
+ ReplicationSlotNameForTablesync(sub->oid, sub_remove_rels[off].relid,
+ syncslotname, sizeof(syncslotname));
ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
}
}
@@ -1174,7 +1176,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
* worker so passing missing_ok = true. This can happen for the states
* before SUBREL_STATE_FINISHEDCOPY.
*/
- ReplicationOriginNameForTablesync(subid, relid, originname);
+ ReplicationOriginNameForTablesync(subid, relid, originname,
+ sizeof(originname));
replorigin_drop_by_name(originname, true, false);
}
@@ -1254,7 +1257,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
{
char syncslotname[NAMEDATALEN] = {0};
- ReplicationSlotNameForTablesync(subid, relid, syncslotname);
+ ReplicationSlotNameForTablesync(subid, relid, syncslotname,
+ sizeof(syncslotname));
ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
}
}
@@ -1532,7 +1536,8 @@ ReportSlotConnectionError(List *rstates, Oid subid, char *slotname, char *err)
{
char syncslotname[NAMEDATALEN] = {0};
- ReplicationSlotNameForTablesync(subid, relid, syncslotname);
+ ReplicationSlotNameForTablesync(subid, relid, syncslotname,
+ sizeof(syncslotname));
elog(WARNING, "could not drop tablesync replication slot \"%s\"",
syncslotname);
}
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 19cc804678..24a6ce5d8e 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -314,7 +314,8 @@ process_syncing_tables_for_sync(XLogRecPtr current_lsn)
*/
ReplicationSlotNameForTablesync(MyLogicalRepWorker->subid,
MyLogicalRepWorker->relid,
- syncslotname);
+ syncslotname,
+ sizeof(syncslotname));
/*
* It is important to give an error if we are unable to drop the slot,
@@ -462,7 +463,8 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
*/
ReplicationOriginNameForTablesync(MyLogicalRepWorker->subid,
rstate->relid,
- originname);
+ originname,
+ sizeof(originname));
replorigin_drop_by_name(originname, true, false);
/*
@@ -871,27 +873,20 @@ copy_table(Relation rel)
* pg_%u_sync_%u_UINT64_FORMAT (3 + 10 + 6 + 10 + 20 + '\0'), the maximum
* length of slot_name will be 50.
*
- * The returned slot name is either:
- * - stored in the supplied buffer (syncslotname), or
- * - palloc'ed in current memory context (if syncslotname = NULL).
+ * The returned slot name is stored in the supplied buffer (syncslotname) with
+ * the given size.
*
* Note: We don't use the subscription slot name as part of tablesync slot name
* because we are responsible for cleaning up these slots and it could become
* impossible to recalculate what name to cleanup if the subscription slot name
* had changed.
*/
-char *
+void
ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
- char syncslotname[NAMEDATALEN])
+ char *syncslotname, int szslot)
{
- if (syncslotname)
- sprintf(syncslotname, "pg_%u_sync_%u_" UINT64_FORMAT, suboid, relid,
- GetSystemIdentifier());
- else
- syncslotname = psprintf("pg_%u_sync_%u_" UINT64_FORMAT, suboid, relid,
- GetSystemIdentifier());
-
- return syncslotname;
+ snprintf(syncslotname, szslot, "pg_%u_sync_%u_" UINT64_FORMAT, suboid,
+ relid, GetSystemIdentifier());
}
/*
@@ -901,9 +896,9 @@ ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
*/
void
ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
- char originname[NAMEDATALEN])
+ char *originname, int szorgname)
{
- snprintf(originname, NAMEDATALEN, "pg_%u_%u", suboid, relid);
+ snprintf(originname, szorgname, "pg_%u_%u", suboid, relid);
}
/*
@@ -951,9 +946,11 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
}
/* Calculate the name of the tablesync slot. */
- slotname = ReplicationSlotNameForTablesync(MySubscription->oid,
- MyLogicalRepWorker->relid,
- NULL /* use palloc */ );
+ slotname = (char *) palloc(NAMEDATALEN);
+ ReplicationSlotNameForTablesync(MySubscription->oid,
+ MyLogicalRepWorker->relid,
+ slotname,
+ NAMEDATALEN);
/*
* Here we use the slot name instead of the subscription name as the
@@ -972,7 +969,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
/* Assign the origin tracking record name. */
ReplicationOriginNameForTablesync(MySubscription->oid,
MyLogicalRepWorker->relid,
- originname);
+ originname,
+ sizeof(originname));
if (MyLogicalRepWorker->relstate == SUBREL_STATE_DATASYNC)
{
diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h
index 5f52335f15..38a9a0b3fc 100644
--- a/src/include/replication/slot.h
+++ b/src/include/replication/slot.h
@@ -212,7 +212,7 @@ extern bool ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive);
extern void ReplicationSlotsDropDBSlots(Oid dboid);
extern void InvalidateObsoleteReplicationSlots(XLogSegNo oldestSegno);
extern ReplicationSlot *SearchNamedReplicationSlot(const char *name);
-extern char *ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname);
+extern void ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname, int szslot);
extern void ReplicationSlotDropAtPubNode(WalReceiverConn *wrconn, char *slotname, bool missing_ok);
extern void StartupReplicationSlots(void);
diff --git a/src/include/replication/worker_internal.h b/src/include/replication/worker_internal.h
index 4a5adc2fda..1cac75e5a9 100644
--- a/src/include/replication/worker_internal.h
+++ b/src/include/replication/worker_internal.h
@@ -82,7 +82,8 @@ extern void logicalrep_worker_wakeup_ptr(LogicalRepWorker *worker);
extern int logicalrep_sync_worker_count(Oid subid);
-extern void ReplicationOriginNameForTablesync(Oid suboid, Oid relid, char *originname);
+extern void ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
+ char *originname, int szorgname);
extern char *LogicalRepSyncTableStart(XLogRecPtr *origin_startpos);
void process_syncing_tables(XLogRecPtr current_lsn);
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:30 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 05:21 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 22:50 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 01:17 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-13 04:01 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
2021-02-13 04:19 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 05:26 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
@ 2021-02-15 10:35 ` Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 0 replies; 13+ messages in thread
From: Amit Kapila @ 2021-02-15 10:35 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Smith <smithpb2250@gmail.com>; Amit Kapila <akapila@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Sat, Feb 13, 2021 at 10:56 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Sat, Feb 13, 2021 at 9:49 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >
> > Amit Kapila <amit.kapila16@gmail.com> writes:
> > > Attached should fix the reported warnings but as I am not getting
> > > those warnings on my system so can't confirm but otherwise, the patch
> > > works as expected. I am planning to push this unless you or Peter have
> > > any comments.
> >
> > Personally I'd get rid of the option for ReplicationSlotNameForTablesync
> > to allocate the result buffer.
> >
>
> Sounds reasonable and the updated patch attached.
>
Pushed and I don't see those warnings on caiman.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: pgsql: Allow multiple xacts during table sync in logical replication.
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Re: pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <amit.kapila16@gmail.com>
@ 2021-02-12 03:20 ` Amit Kapila <amit.kapila16@gmail.com>
1 sibling, 0 replies; 13+ messages in thread
From: Amit Kapila @ 2021-02-12 03:20 UTC (permalink / raw)
To: Amit Kapila <akapila@postgresql.org>; +Cc: pgsql-committers <pgsql-committers@lists.postgresql.org>
On Fri, Feb 12, 2021 at 8:23 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Fri, Feb 12, 2021 at 7:50 AM Amit Kapila <akapila@postgresql.org> wrote:
> >
> > Allow multiple xacts during table sync in logical replication.
> >
>
> I noticed one failure:
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=thorntail&dt=2021-02-12%2002%3A28%3A12
>
> Checking the same.
>
I think I know the reason. It is because, in the test added by patch,
we are trying to connect to the publisher and
wal_level/max_wal_senders configuration is not suitable for it. I'll
look into changing the test.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 13+ messages in thread
end of thread, other threads:[~2021-02-15 10:35 UTC | newest]
Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-02-12 02:20 pgsql: Allow multiple xacts during table sync in logical replication. Amit Kapila <akapila@postgresql.org>
2021-02-12 02:53 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:17 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-02-12 03:30 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 05:21 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 22:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 01:17 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-13 02:27 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 04:01 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-13 04:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-02-13 05:26 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-15 10:35 ` Amit Kapila <amit.kapila16@gmail.com>
2021-02-12 03:20 ` Amit Kapila <amit.kapila16@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox