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 1oxpzP-0000LR-H1 for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Nov 2022 13:40:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oxpzO-0002Cf-EL for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Nov 2022 13:40:34 +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 1oxpzO-0002CW-4h for pgsql-hackers@lists.postgresql.org; Wed, 23 Nov 2022 13:40:34 +0000 Received: from mail-yb1-xb2b.google.com ([2607:f8b0:4864:20::b2b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oxpzL-00056R-51 for pgsql-hackers@lists.postgresql.org; Wed, 23 Nov 2022 13:40:33 +0000 Received: by mail-yb1-xb2b.google.com with SMTP id n189so8450131yba.8 for ; Wed, 23 Nov 2022 05:40:31 -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=icz3rg4jA0wG2RWk+6l/i5+sZyrNcRZMoQbS8RfcUIw=; b=oVorm3GswN7Qgsw2IkWKu0+jwcCquMk2a3jCec5Q/e+mJlvOKRyYiFdLD3c9e22A56 hF9Otx7/DsbVaM/89CgSogZqihfUWAoIBc8lH9WleOWecSYvo5Ku3/A+CsEkSI+DrCLS FIZ/O+MDDO5bphGK4dCvWrMUdSaUoLMl8lRmmj008UpK5VMN45BMwXViLPqPdMKAn2e8 P+41+YALxvffz4h3ITzYD4rJFR8YExaegAvrbID669QROr6vULbEzgu7hoaQI2uqzwQO 4K7P+droqY/CcztwcPTMrLSea1tiW/O9RWUh9oWcDiuvq5r3GkBWqHiMep71s+6x6A/J WrpQ== 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=icz3rg4jA0wG2RWk+6l/i5+sZyrNcRZMoQbS8RfcUIw=; b=4mL/CNV0ONvNh/MUA+ZGVI36uUgkRq11wQa4+Au+7FDOT513UoT44OXu8+cOajT/Yj SEEuBsSfqvmiUq3g4QMKoGxm/ctD3ULXLRMxqGUuZyWrmnSSmirIUOCatK0nfZIysoF3 BanMQnoIm/tRgtBoRAlJ1gWwNFH41ri5dc/w4TEQMSy3ZOiukpEiED804gWBONpX4vhY T+rDJ4TBcWevv73md3ZU4hHfsmKQLzs+bCsyQRMWqoy7IkYCMK5/mqsEcRCHcON7jFJ0 ooJ1ffUR9iPKrPnKESPLzi8dnwf4Orv1a/29IvYDXH9VUcFOx9R6fPS+fSRvVLIC59fe hTbQ== X-Gm-Message-State: ANoB5plbE+e4AcNcWomzyS4ZmnY8tpjiAu08KfYPC3aEd8I1rs+7Rozw re6G1tYdUVr0Lkc70scCA/ynwaxk5/625mg/m0M= X-Google-Smtp-Source: AA0mqf7ApTM0FyPpLq0eUNhkpiaMbb0E//eel7DsAZpm3gTZAxv1dvyykCk9MhdCRhL2IScQiuuU0wpjNL275HbWTig= X-Received: by 2002:a25:868d:0:b0:6de:1e6f:85c7 with SMTP id z13-20020a25868d000000b006de1e6f85c7mr26360773ybk.495.1669210830265; Wed, 23 Nov 2022 05:40:30 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Wed, 23 Nov 2022 19:10:17 +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 Tue, Nov 22, 2022 at 7:30 AM houzj.fnst@fujitsu.com wrote: > Few minor comments and questions: ============================ 1. +static void +LogicalParallelApplyLoop(shm_mq_handle *mqh) { + for (;;) + { + void *data; + Size len; + + ProcessParallelApplyInterrupts(); ... ... + if (rc & WL_LATCH_SET) + { + ResetLatch(MyLatch); + ProcessParallelApplyInterrupts(); + } ... } Why ProcessParallelApplyInterrupts() is called twice in LogicalParallelApplyLoop()? 2. + * This scenario is similar to the first case but TX-1 and TX-2 are executed by + * two parallel apply workers (PA-1 and PA-2 respectively). In this scenario, + * PA-2 is waiting for PA-1 to complete its transaction while PA-1 is waiting + * for subsequent input from LA. Also, LA is waiting for PA-2 to complete its + * transaction in order to preserve the commit order. There is a deadlock among + * three processes. + * ... ... + * + * LA (waiting to acquire the local transaction lock) -> PA-1 (waiting to + * acquire the lock on the unique index) -> PA-2 (waiting to acquire the lock + * on the remote transaction) -> LA + * Isn't the order of PA-1 and PA-2 different in the second paragraph as compared to the first one. 3. + * Deadlock-detection + * ------------------ It may be better to keep the title of this section as Locking Considerations. 4. In the section mentioned in Point 3, it would be better to separately explain why we need session-level locks instead of transaction level. 5. Add the below comments in the code: diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c index 9385afb6d2..56f00defcf 100644 --- a/src/backend/replication/logical/applyparallelworker.c +++ b/src/backend/replication/logical/applyparallelworker.c @@ -431,6 +431,9 @@ pa_free_worker_info(ParallelApplyWorkerInfo *winfo) if (winfo->dsm_seg != NULL) dsm_detach(winfo->dsm_seg); + /* + * Ensure this worker information won't be reused during worker allocation. + */ ParallelApplyWorkersList = list_delete_ptr(ParallelApplyWorkersList, winfo); @@ -762,6 +765,10 @@ HandleParallelApplyMessage(ParallelApplyWorkerInfo *winfo, StringInfo msg) */ error_context_stack = apply_error_context_stack; + /* + * The actual error must be already reported by parallel apply + * worker. + */ ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("parallel apply worker exited abnormally"), -- With Regards, Amit Kapila.