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 1pFp8P-0003Ci-EM for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Jan 2023 04:24:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pFp8N-00027G-6y for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Jan 2023 04:24:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pFp8M-000277-Iy for pgsql-hackers@lists.postgresql.org; Thu, 12 Jan 2023 04:24:10 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pFp8J-0004N2-TD for pgsql-hackers@lists.postgresql.org; Thu, 12 Jan 2023 04:24:09 +0000 Received: by mail-lf1-x135.google.com with SMTP id y25so26657438lfa.9 for ; Wed, 11 Jan 2023 20:24:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=imigMUpAmg1UkuhBQ9owGQRLZHgtf60lhtj0ZNJoZIU=; b=hFS6XjagW38mMc/kvU8b9UZMbbg22i6R/p0DorcwPBp4oG6BOveBB5RvuzAedCb78T 7ZQIsdmlJbgTL+V6cZt0IIx92g7ukXAtS/HOG8S2SWBNfTfeckgZlh5lTzBtO+UiWBwT moAw9Hu6CaPeTI9fo9z9Y8fzYG2ftYZxqOFdZ+/2kjdWFJu2l1SFSMWIud6DvkEyaU6k bBS8BPg6N3x99CfCRJ3EHbJvle/YKIbHHx9bXh8gF2NIIyjYkyoGGH05GlXZmfv62dWX q1NxJIf/DFZ1KiHyiZTwx+ere1ESCMr9hn70ma1H7QIIRqotb6tMEgFFvGGmqjZaDedU zhag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=imigMUpAmg1UkuhBQ9owGQRLZHgtf60lhtj0ZNJoZIU=; b=E2XhrKW4si4MkesI730fTRoIxWmo9TuLt0EuTUcCXtvsG+4aemXkUU1Y4knqPFp7Ao vNhsHJ1wZkcx3yXM2vqo/KWnvLb0iJlT0UOJqdQ0JnaeBdtEujgaw6doud+ByivuHi2p ktgYS/JCIY707TXjgpBtpk0jc+LqFB5blFXKkr7hEqgVtqvUbXWpuDgP5p4n/6yUxFV0 E83jZWUYhEqJItyuffy2VdzGXuo5/nUvs3ONjutmy27UXPHKQDpi0H6G89caWkbNqZJe cZQkCKfSWfuorXJgOfnCI+qwoWCL2eS2i/7xs+USu83y4CxEnmcBbaLRa7fqM0lm/R1m Unsg== X-Gm-Message-State: AFqh2krgZvK0DuJ3yLuTmyrQEICeb3/sHa2odWIBSbOhIMGqpQ3Maix9 AlORyjkXYR0JXHHV8dkD+DxRJPxrFGt9VaTsAQE= X-Google-Smtp-Source: AMrXdXutYf3SgpAttLkXIQ3MWwd1+rlyPFFNOok65aPG4Eq+iOELmWerFELLqK8jSSTlPfeQheSAGkuOchoWo3vvbBY= X-Received: by 2002:a05:6512:398d:b0:4cc:93e6:5ebb with SMTP id j13-20020a056512398d00b004cc93e65ebbmr464021lfu.585.1673497446129; Wed, 11 Jan 2023 20:24:06 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Peter Smith Date: Thu, 12 Jan 2023 15:23:49 +1100 Message-ID: Subject: Re: Perform streaming logical transactions by background workers and parallel apply To: "houzj.fnst@fujitsu.com" Cc: Amit Kapila , Masahiko Sawada , "wangw.fnst@fujitsu.com" , "shiy.fnst@fujitsu.com" , PostgreSQL Hackers , Dilip Kumar Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, here are some review comments for patch v78-0001. =3D=3D=3D=3D=3D=3D General 1. (terminology) AFAIK everywhere until now we=E2=80=99ve been referring everywhere (docs/comments/code) to the parent apply worker as the "leader apply worker". Not the "main apply worker". Not the "apply leader worker". Not any other variations... From this POV I think the worker member "apply_leader_pid" would be better named "leader_apply_pid", but I see that this was already committed to HEAD differently. Maybe it is not possible (or you don't want) to change that internal member name but IMO at least all the new code and docs should try to be using consistent terminology (e.g. leader_apply_XXX) where possible. =3D=3D=3D=3D=3D=3D Commit message 2. main_worker_pid is Process ID of the leader apply worker, if this process i= s a apply parallel worker. NULL if this process is a leader apply worker or a synchronization worker. IIUC, this text is just cut/paste from the monitoring.sgml. In a review comment below I suggest some changes to that text, so then this commit message should also change to be the same. ~~ 3. The new column can make it easier to distinguish leader apply worker and ap= ply parallel worker which is also similar to the 'leader_pid' column in pg_stat_activity. SUGGESTION The new column makes it easier to distinguish parallel apply workers from other kinds of workers. It is implemented this way to be similar to the 'leader_pid' column in pg_stat_activity. =3D=3D=3D=3D=3D=3D doc/src/sgml/logical-replication.sgml 4. + being synchronized. Moreover, if the streaming transaction is applied i= n + parallel, there will be additional workers. SUGGESTION there will be additional workers -> there may be additional parallel apply workers =3D=3D=3D=3D=3D=3D doc/src/sgml/monitoring.sgml 5. pg_stat_subscription @@ -3198,11 +3198,22 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i + apply_leader_pid integer + + + Process ID of the leader apply worker, if this process is a apply + parallel worker. NULL if this process is a leader apply worker or a + synchronization worker. + + + + + relid oid OID of the relation that the worker is synchronizing; null for the - main apply worker + main apply worker and the parallel apply worker 5a. (Same as general comment #1 about terminology) "apply_leader_pid" --> "leader_apply_pid" ~~ 5b. The current text feels awkward. I see it was copied from the similar text of 'pg_stat_activity' but perhaps it can be simplified a bit. SUGGESTION Process ID of the leader apply worker if this process is a parallel apply worker; otherwise NULL. ~~ 5c. BEFORE null for the main apply worker and the parallel apply worker AFTER null for the leader apply worker and parallel apply workers ~~ 5c. relid oid OID of the relation that the worker is synchronizing; null for the - main apply worker + main apply worker and the parallel apply worker main apply worker -> leader apply worker ~~~ 6. @@ -3212,7 +3223,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i Last write-ahead log location received, the initial value of - this field being 0 + this field being 0; null for the parallel apply worker BEFORE null for the parallel apply worker AFTER null for parallel apply workers ~~~ 7. @@ -3221,7 +3232,8 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i last_msg_send_time timestamp with time zone - Send time of last message received from origin WAL sender + Send time of last message received from origin WAL sender; null for= the + parallel apply worker (same as #6) BEFORE null for the parallel apply worker AFTER null for parallel apply workers ~~~ 8. @@ -3230,7 +3242,8 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i last_msg_receipt_time timestamp with time zone - Receipt time of last message received from origin WAL sender + Receipt time of last message received from origin WAL sender; null = for + the parallel apply worker (same as #6) BEFORE null for the parallel apply worker AFTER null for parallel apply workers ~~~ 9. @@ -3239,7 +3252,8 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i latest_end_lsn pg_lsn - Last write-ahead log location reported to origin WAL sender + Last write-ahead log location reported to origin WAL sender; null f= or + the parallel apply worker (same as #6) BEFORE null for the parallel apply worker AFTER null for parallel apply workers ~~~ 10. @@ -3249,7 +3263,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i Time of last write-ahead log location reported to origin WAL - sender + sender; null for the parallel apply worker (same as #6) BEFORE null for the parallel apply worker AFTER null for parallel apply workers =3D=3D=3D=3D=3D=3D src/backend/catalog/system_views.sql 11. @@ -949,6 +949,7 @@ CREATE VIEW pg_stat_subscription AS su.oid AS subid, su.subname, st.pid, + st.apply_leader_pid, st.relid, st.received_lsn, st.last_msg_send_time, (Same as general comment #1 about terminology) "apply_leader_pid" --> "leader_apply_pid" =3D=3D=3D=3D=3D=3D src/backend/replication/logical/launcher.c 12. + if (worker.apply_leader_pid =3D=3D InvalidPid) nulls[3] =3D true; else - values[3] =3D LSNGetDatum(worker.last_lsn); - if (worker.last_send_time =3D=3D 0) + values[3] =3D Int32GetDatum(worker.apply_leader_pid); + 12a. (Same as general comment #1 about terminology) "apply_leader_pid" --> "leader_apply_pid" ~~ 12b. I wondered if here the code should be using the isParallelApplyWorker(worker) macro here for readability. e.g. if (isParallelApplyWorker(worker)) values[3] =3D Int32GetDatum(worker.apply_leader_pid); else nulls[3] =3D true; =3D=3D=3D=3D=3D=3D src/include/catalog/pg_proc.dat 13. + proallargtypes =3D> '{oid,oid,oid,int4,int4,pg_lsn,timestamptz,timestamptz,pg_lsn,timestamptz}'= , + proargmodes =3D> '{i,o,o,o,o,o,o,o,o,o}', + proargnames =3D> '{subid,subid,relid,pid,apply_leader_pid,received_lsn,last_msg_send_time,la= st_msg_receipt_time,latest_end_lsn,latest_end_time}', (Same as general comment #1 about terminology) "apply_leader_pid" --> "leader_apply_pid" =3D=3D=3D=3D=3D=3D src/test/regress/expected/rules.out 14. @@ -2094,6 +2094,7 @@ pg_stat_ssl| SELECT s.pid, pg_stat_subscription| SELECT su.oid AS subid, su.subname, st.pid, + st.apply_leader_pid, st.relid, st.received_lsn, st.last_msg_send_time, @@ -2101,7 +2102,7 @@ pg_stat_subscription| SELECT su.oid AS subid, st.latest_end_lsn, st.latest_end_time FROM (pg_subscription su - LEFT JOIN pg_stat_get_subscription(NULL::oid) st(subid, relid, pid, received_lsn, last_msg_send_time, last_msg_receipt_time, latest_end_lsn, latest_end_time) ON ((st.subid =3D su.oid))); + LEFT JOIN pg_stat_get_subscription(NULL::oid) st(subid, relid, pid, apply_leader_pid, received_lsn, last_msg_send_time, last_msg_receipt_time, latest_end_lsn, latest_end_time) ON ((st.subid =3D su.oid))); pg_stat_subscription_stats| SELECT ss.subid, s.subname, ss.apply_error_count, (Same comment as elsewhere) "apply_leader_pid" --> "leader_apply_pid" ------ Kind Regards, Peter Smith. Fujitsu Australia