Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovr5t-0007KN-1f for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Nov 2022 02:27:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ovr5r-00009K-9E for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Nov 2022 02:27:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovr5q-0008Us-Sm for pgsql-hackers@lists.postgresql.org; Fri, 18 Nov 2022 02:27:02 +0000 Received: from mail-yb1-xb31.google.com ([2607:f8b0:4864:20::b31]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ovr5o-0000XI-3T for pgsql-hackers@lists.postgresql.org; Fri, 18 Nov 2022 02:27:02 +0000 Received: by mail-yb1-xb31.google.com with SMTP id z192so4182839yba.0 for ; Thu, 17 Nov 2022 18:26:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=XPNqVnmFrQhT+UNL5y7cSXMwNJYSwqvx5Q6U4J4ge/0=; b=BjAuqLmw/W6wUbFOriqniIUodtEuY0bBQVHYCRwQOQsiE5UFLGXFrbDFTRG8Gs73gf fw5AjARtpI79HziH5y0h9CTxP+F6zPARs1xVGU5HeGPEkGYSerFerWI6fIFFAIQALNye LR6wMZMjdcXGp3KtCCZxlMP2xF5NErdg3L6L7jeRhgDJPiYy17OX3T+P9Vt8yvhCIXls MpdNvlbcpcRlCrhVLpyAGK08HhON7WmfbWdcs/zDE5Kd4z5krZ/NzGi9/q9L2uAQGxrN e8ImJf6CBifnJ7ABakTEO8hdung0+qdYvD3XrN7FfWjBX9Gx6phzGff5IFz0eNrZtvC9 DwuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XPNqVnmFrQhT+UNL5y7cSXMwNJYSwqvx5Q6U4J4ge/0=; b=MaZERMKVooZ9uuRG3oARhdXAwE0ZDNtovlgNx9gqOnylAVkioD+nUC6aaj7Iy5a1Uz CAsQecdgM7dFHddrRMs7f+vWJcS0AldymNjwUaODUg9YGoLsgjJTF0c4TZfmyUVNMP0l OKjRCLg9wnSVn8OCTc++cLGyblE2+6KsogmRcAqUYvGJhn+MDJhhIarhkXGzNbgt+Sfv R/PacchT498MGWgdqVXDXhtiSJAqVIvVXGtdEpZem/3YkjjdRvX+o7SGM5xqwOBqBvj4 EL8kxHjLqNE+2YiYvXMinK8J4tMqlEBEiH8oFF0OHNrSCXt0JtQF2982+vLwV3cjYxEH iDkQ== X-Gm-Message-State: ANoB5plsMAEDS7KK0gi1NgGozRCrg2YxpM25nvDY0UrhDrVVvtVYi9Ga +VvpaRmrsQANsoAhqipe7WjnvMqChvXJ6rkD+xE= X-Google-Smtp-Source: AA0mqf7C8jENcOcWTwrjo1bMxDkLsR/7ZCMfEOqFiJArPBv0ndpzr6cnePZAmVamDbmyahYHcSwv1zS2MxYSSznjKqw= X-Received: by 2002:a05:6902:4e8:b0:6e6:c227:6afc with SMTP id w8-20020a05690204e800b006e6c2276afcmr4966588ybs.317.1668738417933; Thu, 17 Nov 2022 18:26:57 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Fri, 18 Nov 2022 07:56:45 +0530 Message-ID: Subject: Re: Perform streaming logical transactions by background workers and parallel apply To: "houzj.fnst@fujitsu.com" Cc: Masahiko Sawada , "wangw.fnst@fujitsu.com" , Peter Smith , Dilip Kumar , "shiy.fnst@fujitsu.com" , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Nov 16, 2022 at 1:50 PM houzj.fnst@fujitsu.com wrote: > > On Tuesday, November 15, 2022 7:58 PM houzj.fnst@fujitsu.com wrote: > > I noticed that I didn't add CHECK_FOR_INTERRUPTS while retrying send message. > So, attach the new version which adds that. Also attach the 0004 patch that > restarts logical replication with temporarily disabling the parallel apply if > failed to apply a transaction in parallel apply worker. > Few comments on v48-0001 ====================== 1. The variable name pending_message_count seems to indicate a number of pending messages but normally it is pending start/stop streams except for probably rollback to savepoint case. Shall we name it pending_stream_count and change the comments accordingly? 2. The variable name abort_toplevel_transaction seems unnecessarily long. Shall we rename it to toplevel_xact or something like that? 3. + /* + * Increment the number of messages waiting to be processed by + * parallel apply worker. + */ + if (!abort_toplevel_transaction) + pg_atomic_add_fetch_u32(&(winfo->shared->pending_message_count), 1); + else + pa_unlock_stream(xid, AccessExclusiveLock); It is better to explain here why different actions are required for subtransaction and transaction rather than the current comment. 4. + + if (abort_toplevel_transaction) + { + (void) pa_free_worker(winfo, xid); + } {} is not required here. 5. /* + * Although the lock can be automatically released during transaction + * rollback, but we still release the lock here as we may not in a + * transaction. + */ + pa_unlock_transaction(xid, AccessShareLock); + It is better to explain for which case (I think it is for empty xacts) it will be useful to release it explicitly. 6. + * + * XXX We can avoid sending pairs of the START/STOP messages to the parallel + * worker because unlike apply worker it will process only one transaction at a + * time. However, it is not clear whether any optimization is worthwhile + * because these messages are sent only when the logical_decoding_work_mem + * threshold is exceeded. */ static void apply_handle_stream_start(StringInfo s) I think this comment is no longer valid as now we need to wait for the next stream at stream_stop message and also need to acquire the lock in stream_start message. So, I think it is better to remove it unless I am missing something. 7. I am able to compile applyparallelworker.c by commenting few of the header includes. Please check if those are really required. #include "libpq/pqformat.h" #include "libpq/pqmq.h" //#include "mb/pg_wchar.h" #include "pgstat.h" #include "postmaster/interrupt.h" #include "replication/logicallauncher.h" //#include "replication/logicalworker.h" #include "replication/origin.h" //#include "replication/walreceiver.h" #include "replication/worker_internal.h" #include "storage/ipc.h" #include "storage/lmgr.h" //#include "storage/procarray.h" #include "tcop/tcopprot.h" #include "utils/inval.h" #include "utils/memutils.h" //#include "utils/resowner.h" #include "utils/syscache.h" 8. +/* + * Is there a message sent by parallel apply worker which we need to receive? + */ +volatile sig_atomic_t ParallelApplyMessagePending = false; This comment and variable are placed in applyparallelworker.c, so 'we' in the above sentence is not clear. I think you need to use leader apply worker instead. 9. +static ParallelApplyWorkerInfo *pa_get_free_worker(void); Will it be better if we name this function pa_get_available_worker()? -- With Regards, Amit Kapila.