RE: [PATCH] Reuse Workers and Replication Slots during Logical Replication
Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
From: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
To: 'Melih Mutlu' <m.melihmutlu@gmail.com>
Cc: Peter Smith <smithpb2250@gmail.com>, Melanie Plageman <melanieplageman@gmail.com>, "Wei Wang (Fujitsu)" <wangw.fnst@fujitsu.com>, "Yu Shi (Fujitsu)" <shiy.fnst@fujitsu.com>, Amit Kapila <amit.kapila16@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>, shveta malik <shveta.malik@gmail.com>
Date: 2023-07-06T09:47:40Z
Lists: pgsql-hackers
Attachments
- N2.log (application/octet-stream)
- test.sh (application/octet-stream)
- v16-0001-Refactor-to-split-Apply-and-Tablesync-Workers.patch (application/octet-stream) patch v16-0001
- v16-0002-Reuse-Tablesync-Workers.patch (application/octet-stream) patch v16-0002
- v16-0003-reuse-connection-when-tablesync-workers-change-t.patch (application/octet-stream) patch v16-0003
- v16-0004-Add-replication-protocol-cmd-to-create-a-snapsho.patch (application/octet-stream) patch v16-0004
- v16-0005-Reuse-Replication-Slot-and-Origin-in-Tablesync.patch (application/octet-stream) patch v16-0005
Dear Melih,
> Thanks for the 0003 patch. But it did not work for me. Can you create
> a subscription successfully with patch 0003 applied?
> I get the following error: " ERROR: table copy could not start
> transaction on publisher: another command is already in progress".
You got the ERROR when all the patches (0001-0005) were applied, right?
I have focused on 0001 and 0002 only, so I missed something.
If it was not correct, please attach the logfile and test script what you did.
As you might know, the error is output when the worker executs walrcv_endstreaming()
before doing walrcv_startstreaming().
> I think streaming needs to be ended before moving to another table. So
> I changed the patch a little bit
Your modification seemed not correct. I applied only first three patches (0001-0003), and
executed attached script. Then I got following error on subscriber (attached as N2.log):
> ERROR: could not send end-of-streaming message to primary: no COPY in progress
IIUC the tablesync worker has been already stopped streaming without your modification.
Please see process_syncing_tables_for_sync():
```
if (MyLogicalRepWorker->relstate == SUBREL_STATE_CATCHUP &&
current_lsn >= MyLogicalRepWorker->relstate_lsn)
{
TimeLineID tli;
char syncslotname[NAMEDATALEN] = {0};
char originname[NAMEDATALEN] = {0};
MyLogicalRepWorker->relstate = SUBREL_STATE_SYNCDONE;
...
/*
* End streaming so that LogRepWorkerWalRcvConn can be used to drop
* the slot.
*/
walrcv_endstreaming(LogRepWorkerWalRcvConn, &tli);
```
This means that following changes should not be in the 0003, should be at 0005.
PSA fixed patches.
```
+ /*
+ * If it's already connected to the publisher, end streaming before using
+ * the same connection for another iteration
+ */
+ if (LogRepWorkerWalRcvConn != NULL)
+ {
+ TimeLineID tli;
+ walrcv_endstreaming(LogRepWorkerWalRcvConn, &tli);
+ }
```
Besides, cfbot could not apply your patch set [1]. According to the log, the
bot tried to apply 0004 and 0005 first and got error. IIUC you should assign
same version number within the same mail, like v16-0001, v16-0002,....
[1]: http://cfbot.cputube.org/patch_43_3784.log
Best Regards,
Hayato Kuroda
FUJITSU LIMITED
Commits
-
Refactor to split Apply and Tablesync Workers code.
- 02c1b64fb15c 17.0 landed
-
Fix possible logical replication crash.
- e7e7da2f8d57 16.0 cited