RE: Perform streaming logical transactions by background workers and parallel apply
Wei Wang (Fujitsu) <wangw.fnst@fujitsu.com>
Attachments
- v34-0001-Perform-streaming-logical-transactions-by-parall.patch (application/octet-stream) patch v34-0001
- v34-0002-Test-streaming-parallel-option-in-tap-test.patch (application/octet-stream) patch v34-0002
- v34-0003-Add-some-checks-before-using-parallel-apply-work.patch (application/octet-stream) patch v34-0003
- v34-0004-Retry-to-apply-streaming-xact-only-in-apply-work.patch (application/octet-stream) patch v34-0004
- v34-0005-Add-a-main_worker_pid-to-pg_stat_subscription.patch (application/octet-stream) patch v34-0005
On Thur, Sep 22, 2022 at 16:08 PM Kuroda, Hayato/黒田 隼人 <kuroda.hayato@fujitsu.com> wrote:
> Dear Wang,
>
> Thanks for updating the patch! Followings are comments for v33-0001.
Thanks for your comments.
> ===
> libpqwalreceiver.c
>
> 01. inclusion
>
> ```
> +#include "catalog/pg_subscription.h"
> ```
>
> We don't have to include it because the analysis of parameters is done at caller.
>
> ===
> launcher.c
Improved.
> 02. logicalrep_worker_launch()
>
> ```
> + /*
> + * Return silently if the number of parallel apply workers reached the
> + * limit per subscription.
> + */
> + if (is_subworker && nparallelapplyworkers >=
> max_parallel_apply_workers_per_subscription)
> ```
>
> a.
> I felt that it might be kind if we output some debug messages.
>
> b.
> The if statement seems to be more than 80 characters. You can move to new
> line around "nparallelapplyworkers >= ...".
Improved.
> ===
> applyparallelworker.c
>
> 03. declaration
>
> ```
> +/*
> + * Is there a message pending in parallel apply worker which we need to
> + * receive?
> + */
> +volatile bool ParallelApplyMessagePending = false;
> ```
>
> I checked other flags that are set by signal handlers, their datatype seemed to
> be sig_atomic_t.
> Is there any reasons that you use normal bool? It should be changed if not.
Improved.
> 04. HandleParallelApplyMessages()
>
> ```
> + if (winfo->error_mq_handle == NULL)
> + continue;
> ```
>
> a.
> I was not sure when the cell should be cleaned. Currently we clean up
> ParallelApplyWorkersList() only in the parallel_apply_start_worker(),
> but we have chances to remove such a cell like HandleParallelApplyMessages()
> or HandleParallelApplyMessage(). How do you think?
>
> b.
> Comments should be added even if we keep this, like "exited worker, skipped".
>
> ```
> + else
> + ereport(ERROR,
> +
> (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> + errmsg("lost connection to the leader apply worker")));
> ```
>
> c.
> This function is called on the leader apply worker, so the hint should be "lost
> connection to the parallel apply worker".
=>b.
Added the following comment according to your suggestion.
`Skip if worker has exited`
=>c.
Fixed.
> ===
> worker.c
>
> 07. handle_streamed_transaction()
>
> ```
> + * For non-streamed transactions, returns false;
> ```
>
> "returns false;" -> "returns false"
Improved. I changed the semicolon to a period
> apply_handle_commit_prepared(), apply_handle_abort_prepared()
>
> These functions are not expected that parallel worker calls
> so I think Assert() should be added.
I am not sure if this modification is necessary since we do not modify the
non-streamed transaction related message like "COMMIT PREPARED" or "ROLLBACK
PREPARED".
> 08. UpdateWorkerStats()
>
> ```
> -static void
> +void
> UpdateWorkerStats(XLogRecPtr last_lsn, TimestampTz send_time, bool reply)
> ```
>
> This function is called only in worker.c, should be static.
>
> 09. subscription_change_cb()
>
> ```
> -static void
> +void
> subscription_change_cb(Datum arg, int cacheid, uint32 hashvalue)
> ```
>
> This function is called only in worker.c, should be static.
Improved.
> 10. InitializeApplyWorker()
>
> ```
> +/*
> + * Initialize the database connection, in-memory subscription and necessary
> + * config options.
> + */
> void
> -ApplyWorkerMain(Datum main_arg)
> +InitializeApplyWorker(void)
> ```
>
> Some comments should be added about this is a common part of leader and
> parallel apply worker.
Added the following comment:
`The common initialization for leader apply worker and parallel apply worker.`
> ===
> logicalrepworker.h
>
> 11. declaration
>
> ```
> extern PGDLLIMPORT volatile bool ParallelApplyMessagePending;
> ```
>
> Please refer above comment.
>
> ===
> guc_tables.c
Improved.
Also rebased the patch set based on the changes in HEAD (26f7802).
Attach the new patch set.
Regards,
Wang wei
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix invalid memory access during the shutdown of the parallel apply worker.
- 3d144c6c8602 16.0 landed
-
Fix assertion failure in apply worker.
- de63f8dadee4 16.0 landed
-
Use elog to report unexpected action in handle_streamed_transaction().
- 781ac42d43ab 16.0 landed
-
Use appropriate wait event when sending data in the apply worker.
- d9d7fe68d35e 16.0 landed
-
Allow the logical_replication_mode to be used on the subscriber.
- 9f2213a7c575 16.0 landed
-
Rename GUC logical_decoding_mode to logical_replication_mode.
- 1e8b61735cfb 16.0 landed
-
Display the leader apply worker's PID for parallel apply workers.
- d540a02a724b 16.0 landed
-
Improve the code to decide and process the apply action.
- c981d9145dea 16.0 landed
-
Document the newly added wait events added by commit 216a784829.
- cd06ccd78fcf 16.0 landed
-
Perform apply of large transactions by parallel workers.
- 216a784829c2 16.0 landed
-
Wake up a subscription's replication worker processes after DDL.
- c6e1f62e2cee 16.0 cited
-
Add copyright notices to meson files
- 8284cf5f746f 16.0 cited
-
Better document logical replication parameters
- a8500750ca0a 16.0 cited
-
Add a common function to generate the origin name.
- 776e1c8a5d14 16.0 cited
-
Harmonize parameter names in storage and AM code.
- bfcf1b34805f 16.0 cited
-
Avoid using list_length() to test for empty list.
- efd0c16becbf 16.0 cited
-
Improve two comments related to a boolean DefElem's value
- 8445f5a21d40 16.0 cited
-
Fix partition table's REPLICA IDENTITY checking on the subscriber.
- 26b3455afaa9 15.0 cited
-
Fix data inconsistency between publisher and subscriber.
- b7658c24c7c1 15.0 cited
-
Fix cache look-up failures while applying changes in logical replication.
- 5a97b1325453 15.0 cited