Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1reaym-00CF4T-7d for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Feb 2024 13:25:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1reayk-00DYJQ-GM for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Feb 2024 13:25:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1reayk-00DYJI-7A for pgsql-hackers@lists.postgresql.org; Mon, 26 Feb 2024 13:25:10 +0000 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1reayi-001ARQ-5O for pgsql-hackers@lists.postgresql.org; Mon, 26 Feb 2024 13:25:10 +0000 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-22034c323a3so37860fac.0 for ; Mon, 26 Feb 2024 05:25:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708953906; x=1709558706; darn=lists.postgresql.org; 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=ck/DZ6ck0CMLC8zCEMkq0RL9PaX+ruifQvcByj6S6ww=; b=e72/1qMDJ7Fr/1HdHv1Tqfl95wzajCUNp2L9Eq1a+mqRYOMXsE7vu/wo5gWT9ROJ15 WNQ3kwAJgBrA0sFBUDKxIqO22KxfJ8x7LY/8DyzDHYmTsu/AO4dF3+sUccN+sXS/lxBi s9XnForcEJDm0/vvMPJSH3ihc3KwyPCc9NSq3QrbsLlIZiEw7L3wKXPiasGWDN9fnxKT DuB4oUdXoTpn43Dfwa5hgzyg8qRi7ol7IqjSzMCIBVygdWBzZnHuVH5J2Q4UYj7EdaSb JoclKnED9vhUtq7VSN4QsSnsYItMOXPa54eLDDUVsIWCaiSkTw1qLV+K68AQv5yF3qGA zh0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708953906; x=1709558706; 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=ck/DZ6ck0CMLC8zCEMkq0RL9PaX+ruifQvcByj6S6ww=; b=QbkzrnwV4MC6z+MUZIsUf9du8cUJdX+Vnrh04hb6fR1JNzWi8cXOcfBcu97hFWltI9 81T4q1Ma8kOhOGIJYfVErfQ7gxb+vQLnAorl7gxBiDq17Trmobc3+10aR/Zgr2d97ozd CkmeLvxIEfOmBOaAxf8sefdG51ZIDDL5B937BTMPcUlGbSdu/orFOEpAKd1ucHNu35s0 Je0FOM8xn2yGuf0WpVJa1fRx/oWLnrk22tcVUo5jDG+1lIob1pa3rw9TDd+b6KUZQrre xdTpKF4SXrHJ1olybKX0+BftRLuPa3jHm6NT6DJTax6TKv9vA1dzP9HAGE5l1CW/bFAG D1Ig== X-Gm-Message-State: AOJu0Yzf54IUC71fhIxt7pFaCXHlnCU1cVfM4MHEwegnZ6MnnbCz993H Sls2k51tZFVwZ7YEL/oY4U/fluL1y97X7Th2X5jTfZZKv8W8ErwyeXxXO3r/U4pSxsha0Kdr2wX JBQivsOhl5gibXK28cQjvNp6Yx2Ya5JfG0OCxUA== X-Google-Smtp-Source: AGHT+IGVVF427ScqG0VwAYu0x1ddNOhplJ8FbKWIewkEwgTNKN58TphdRTApC291bwiSvSRg/3GcXETyIvVwZJMEvCg= X-Received: by 2002:a05:6870:c347:b0:21e:b2ee:75a4 with SMTP id e7-20020a056870c34700b0021eb2ee75a4mr8158915oak.15.1708953906452; Mon, 26 Feb 2024 05:25:06 -0800 (PST) MIME-Version: 1.0 References: <8fab8-65d74c80-1-2f28e880@39088166> <99df2-65d8d200-1-63c26880@172687752> In-Reply-To: <99df2-65d8d200-1-63c26880@172687752> From: Amit Kapila Date: Mon, 26 Feb 2024 18:54:55 +0530 Message-ID: Subject: Re: Slow catchup of 2PC (twophase) transactions on replica in LR To: =?UTF-8?B?0JTQsNCy0YvQtNC+0LIg0JLQuNGC0LDQu9C40Lk=?= Cc: pgsql-hackers@lists.postgresql.org 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 On Fri, Feb 23, 2024 at 10:41=E2=80=AFPM =D0=94=D0=B0=D0=B2=D1=8B=D0=B4=D0= =BE=D0=B2 =D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9 wrote: > > Amit Kapila wrote: > > I don't see we do anything specific for 2PC transactions to make them beh= ave differently than regular transactions with respect to synchronous_commi= t setting. What makes you think so? Can you pin point the code you are refe= rring to? > > Yes, sure. The function RecordTransactionCommitPrepared is called on prep= ared transaction commit (twophase.c). It calls XLogFlush unconditionally. T= he function RecordTransactionCommit (for regular transactions, xact.c) call= s XLogFlush if synchronous_commit > OFF, otherwise it calls XLogSetAsyncXac= tLSN. > > There is some comment in RecordTransactionCommitPrepared (by Bruce Momjia= n) that shows that async commit is not supported yet: > /* > * We don't currently try to sleep before flush here ... nor is there any > * support for async commit of a prepared xact (the very idea is probably > * a contradiction) > */ > /* Flush XLOG to disk */ > XLogFlush(recptr); > It seems this comment is added in the commit 4a78cdeb where we added async commit support. I think the reason is probably that when the WAL record for prepared is already flushed then what will be the idea of async commit here? > Right, I think for this we need to implement parallel apply. > > Yes, parallel apply is a good point. But, I believe, it will not work if = asynchronous commit is not supported. You have only one receiver process wh= ich should dispatch incoming messages to parallel workers. I guess, you wil= l never reach such rate of parallel execution on replica as on the master w= ith multiple backends. > > > Can you be a bit more specific about what exactly you have in mind to ach= ieve the above solutions? > > My proposal is to implement async commit for 2PC transactions as it is fo= r regular transactions. It should significantly speedup the catchup process= . Then, think how to apply in parallel, which is much diffcult to do. The c= urrent problem is to get 2PC state from the WAL on commit prepared. At this= moment, the WAL is not flushed yet, commit function waits until WAL with 2= PC state is to be flushed. I just tried to do it in my sandbox and found su= ch a problem. Inability to get 2PC state from unflushed WAL stops me right = now. I think about possible solutions. > At commit prepared, it seems we read prepare's WAL record, right? If so, it is not clear to me do you see a problem with a flush of commit_prepared or reading WAL for prepared or both of these. --=20 With Regards, Amit Kapila.