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 1otoKv-0001hW-DS for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Nov 2022 11:06:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1otoKr-0002LD-Qd for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Nov 2022 11:06:05 +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 1otoKr-0002L4-ED for pgsql-hackers@lists.postgresql.org; Sat, 12 Nov 2022 11:06:05 +0000 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1otoKk-00077M-Cb for pgsql-hackers@lists.postgresql.org; Sat, 12 Nov 2022 11:06:03 +0000 Received: by mail-yb1-xb32.google.com with SMTP id g127so8392516ybg.8 for ; Sat, 12 Nov 2022 03:05:58 -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=ULHgmBE1rD6ZJAeq66iZXkbwJ8sx/cFATaUvIezQ4oI=; b=IFHI2lMNlCiU2Bq+bWLT/E3MVfr3tt2Rrmx8TZJSv7tz6UuJkpY7zBwtNr+1FRNkNJ iusyQ0zXbu2MCknFpRpiid8wDLLTnrMyskkB1Es8JRP1YOj6bbhOKKQSP/wfKf4aAuIj GleDo4NQJHHpysMRIqMTQ/BFW3ZnQuMdflcywciBCGPuoK//LHLKlE/8J9hidTA/Ekwi BO983kTj850R7adAvehEbVj4muRwIrWEM1FaeWe+aYqnoI9FmIBEbFg9qrU/of/cO/Ay qNXx+Lmmj0jQj10HJJYAuDyVeokQfrusmHz2GS2pi+mgGmDaQuIPZ90tZI/YTgpKSTKD K0rA== 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=ULHgmBE1rD6ZJAeq66iZXkbwJ8sx/cFATaUvIezQ4oI=; b=D58pPQ3WbPC5TAjkAYrujVX2XhtPc+AbsMq2T9vBzklk5F2XRKe8aVElK4RlzqokcX Furs4RwC1wK25dAyBcVry20Mte2/q5ck/HdTnTsxU6bHY3CTXQStQ4eespGnpCnphpE6 ciWxc4AqZ353UdrNxM4U8fMrZyBMbSYW+CRrctLjSsnH10NGZn8A8LDqzWbfU6yjFZnH FpFL5XuLeI1nfky0A5VhEsDETVNPrKf6h4BsqQLzVvXcsjJVewvR1pauHRPRNaVJzYts +w0+UkVjhD2fSdzUKIwB4nZ/64A1OqdQPuA/8jqZQpDQAOApI4+8sS+kCLFedCJFOYFl VCKA== X-Gm-Message-State: ANoB5pmS/CKkO+gV5wWX9z2/il3w2x0VSCf5icPrpmq3iQynTcpj9Z5s VEuQOZ3sHtIDxPxbBY43gP68lRTlqv3Gdow64NQ= X-Google-Smtp-Source: AA0mqf6j8liFlFkdl+m7gPdY5ExLC6yoykR5x/5HflNzvp7s2tu4mTiDUw4Wr+yBIYocfHtbW/4fXyC/ULseUBKbpq0= X-Received: by 2002:a25:664a:0:b0:6dd:f09:cff6 with SMTP id z10-20020a25664a000000b006dd0f09cff6mr5315025ybm.170.1668251156917; Sat, 12 Nov 2022 03:05:56 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Sat, 12 Nov 2022 16:35:46 +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 Fri, Nov 11, 2022 at 2:12 PM houzj.fnst@fujitsu.com wrote: > Few comments on v46-0001: ====================== 1. +static void +apply_handle_stream_abort(StringInfo s) { ... + /* Send STREAM ABORT message to the parallel apply worker. */ + parallel_apply_send_data(winfo, s->len, s->data); + + if (abort_toplevel_transaction) + { + parallel_apply_unlock_stream(xid, AccessExclusiveLock); Shouldn't we need to release this lock before sending the message as we are doing for streap_prepare and stream_commit? If there is a reason for doing it differently here then let's add some comments for the same. 2. It seems once the patch makes the file state as busy (LEADER_FILESET_BUSY), it will only be accessible after the leader apply worker receives a transaction end message like stream_commit. Is my understanding correct? If yes, then why can't we make it accessible after the stream_stop message? Are you worried about the concurrency handling for reading and writing the file? If so, we can probably deal with it via some lock for reading and writing to file for each change. I think after this we may not need additional stream level lock/unlock in parallel_apply_spooled_messages. I understand that you probably want to keep the code simple so I am not suggesting changing it immediately but just wanted to know whether you have considered alternatives here. 3. Don't we need to release the transaction lock at stream_abort in parallel apply worker? I understand that we are not waiting for it in the leader worker but still parallel apply worker should release it if acquired at stream_start by it. 4. A minor comment change as below: diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 43f09b7e9a..c771851d1f 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -1851,6 +1851,9 @@ apply_handle_stream_abort(StringInfo s) parallel_apply_stream_abort(&abort_data); /* + * We need to wait after processing rollback to savepoint for the next set + * of changes. + * * By the time parallel apply worker is processing the changes in * the current streaming block, the leader apply worker may have * sent multiple streaming blocks. So, try to lock only if there -- With Regards, Amit Kapila.