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 1pHciR-0006s4-MX for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Jan 2023 03:32:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pHciQ-0002aT-JN for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Jan 2023 03:32:50 +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 1pHciQ-0002aK-Ak for pgsql-hackers@lists.postgresql.org; Tue, 17 Jan 2023 03:32:50 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pHciN-0006fT-Vm for pgsql-hackers@lists.postgresql.org; Tue, 17 Jan 2023 03:32:49 +0000 Received: by mail-lj1-x235.google.com with SMTP id e16so5013408ljn.3 for ; Mon, 16 Jan 2023 19:32:47 -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=o1FYQuQszLF/Jq5HixmQ0zWL7T/BaI6In7kzJCZy6wQ=; b=SN4V2k07YJ3/1TX/N6xqo+O4qkjSddVh7PayBZ+32qXVsZzu/6e+7vjYs6SClWrW5X 6k3f+RFoL6xdwref5f0cKFeLoPf1nb2aYXb8GNIcyOSWKSv8u5UM2AKw2lxo00bOhR05 C7P3J4nxHukxF5XoSA47/T8CQjpFKWZM2Hlx3x4ima7Q8kl760KvAN8a7JdKRxEsXQ/S KsutIoVEtWqpJUlDNo9RBIai0eXjswBQ+zB4h99uD58unVdTXXdEVUb3FJUJ/jDJ1NUo TlI0UIBHZM8q1gTrpix9CtBqf2XHopafNsKyUD7pGjKWtCbfM7HQgLzc3P7HPJYFuHs2 8tXA== 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=o1FYQuQszLF/Jq5HixmQ0zWL7T/BaI6In7kzJCZy6wQ=; b=N9bm84TI2sE8Loz2DBKF8RFdoSmWSLL3A14d2WContuG/zwCWNBMrwxyiDKmf2iopQ bTJ5OjghrDZWWklMSFimbfi2x525ZKHAhRvs2H9APw0KPxDaEwyyZXyx5M8Ui4WweAmC MbC72/x2BNl03IShIqzZpECNsbhc/EHpsm7S1ablFxdthEIZ63ZyVlaf7UDFfkPpQyIb 8fQWZaNoSrecLyFvQhO1jzpe8WzOdoW4+ChREPdfZbAACbTN6JLpwpAOLAmmkotAhFN4 j6xCJ47nsxO9kW2lJG6QbDYC72E/5+CPfUZZyCAWcsaG1H5I9GhnI/tZawpW2PeHNRKz ehFw== X-Gm-Message-State: AFqh2kp2+uyhD+hfdX43SuWK/ojY+HsmXHQHfsaULP9v2ONmgRHCvibf fOmxgxJwxSxMq0JnYantdnezbDUrlXIwgYcBGgE= X-Google-Smtp-Source: AMrXdXsJJUNP0u6LCG0pLT0hjFBxNDA4WyyNSjYbPmCgom+deBdXGLIXTjvP9msgWfemJVQp4vQekWiO577C7M/jRRI= X-Received: by 2002:a05:651c:2393:b0:289:aeab:7685 with SMTP id bk19-20020a05651c239300b00289aeab7685mr85979ljb.15.1673926365696; Mon, 16 Jan 2023 19:32:45 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Peter Smith Date: Tue, 17 Jan 2023 14:32:28 +1100 Message-ID: Subject: Re: Perform streaming logical transactions by background workers and parallel apply To: "houzj.fnst@fujitsu.com" Cc: Masahiko Sawada , shveta malik , "wangw.fnst@fujitsu.com" , "shiy.fnst@fujitsu.com" , PostgreSQL Hackers , Dilip Kumar , Amit Kapila Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jan 17, 2023 at 1:21 PM houzj.fnst@fujitsu.com wrote: > > On Tuesday, January 17, 2023 5:43 AM Peter Smith wrote: > > > > On Mon, Jan 16, 2023 at 5:41 PM Amit Kapila > > wrote: > > > > > > On Mon, Jan 16, 2023 at 10:24 AM Peter Smith > > wrote: > > > > > > > > 2. > > > > > > > > /* > > > > + * Return the pid of the leader apply worker if the given pid is > > > > +the pid of a > > > > + * parallel apply worker, otherwise return InvalidPid. > > > > + */ > > > > +pid_t > > > > +GetLeaderApplyWorkerPid(pid_t pid) > > > > +{ > > > > + int leader_pid = InvalidPid; > > > > + int i; > > > > + > > > > + LWLockAcquire(LogicalRepWorkerLock, LW_SHARED); > > > > + > > > > + for (i = 0; i < max_logical_replication_workers; i++) { > > > > + LogicalRepWorker *w = &LogicalRepCtx->workers[i]; > > > > + > > > > + if (isParallelApplyWorker(w) && w->proc && pid == w->proc->pid) { > > > > + leader_pid = w->leader_pid; break; } } > > > > + > > > > + LWLockRelease(LogicalRepWorkerLock); > > > > + > > > > + return leader_pid; > > > > +} > > > > > > > > 2a. > > > > IIUC the IsParallelApplyWorker macro does nothing except check that > > > > the leader_pid is not InvalidPid anyway, so AFAIK this algorithm > > > > does not benefit from using this macro because we will want to > > > > return InvalidPid anyway if the given pid matches. > > > > > > > > So the inner condition can just say: > > > > > > > > if (w->proc && w->proc->pid == pid) > > > > { > > > > leader_pid = w->leader_pid; > > > > break; > > > > } > > > > > > > > > > Yeah, this should also work but I feel the current one is explicit and > > > more clear. > > > > OK. > > > > But, I have one last comment about this function -- I saw there are already > > other functions that iterate max_logical_replication_workers like this looking > > for things: > > - logicalrep_worker_find > > - logicalrep_workers_find > > - logicalrep_worker_launch > > - logicalrep_sync_worker_count > > > > So I felt this new function (currently called GetLeaderApplyWorkerPid) ought > > to be named similarly to those ones. e.g. call it something like > > "logicalrep_worker_find_pa_leader_pid". > > > > I am not sure we can use the name, because currently all the API name in launcher that > used by other module(not related to subscription) are like > AxxBxx style(see the functions in logicallauncher.h). > logicalrep_worker_xxx style functions are currently only declared in > worker_internal.h. > OK. I didn't know there was another header convention that you were following. In that case, it is fine to leave the name as-is. ------ Kind Regards, Peter Smith. Fujitsu Australia