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 1sQmxk-00Bdcj-Ai for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jul 2024 11:55:20 +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 1sQmxi-005BTW-Gv for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jul 2024 11:55:18 +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 1sQmxi-005BTK-70 for pgsql-hackers@lists.postgresql.org; Mon, 08 Jul 2024 11:55:18 +0000 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sQmxf-0012Mr-UI for pgsql-hackers@lists.postgresql.org; Mon, 08 Jul 2024 11:55:17 +0000 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3d9318a005eso328425b6e.1 for ; Mon, 08 Jul 2024 04:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720439713; x=1721044513; 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=epeRSHi6mC8mGt8BJ/p9sWqSupogTGOrQYUwH4FaAcI=; b=IDmkpVHGgcQ5HckHwJ7/Aev2/pDxq8/nn1qpsVkRDX3GcGtSJ+kpMbNR3qca6hlB+j Xof67+DB8n4hMMufYxRNrJLHjS6psu+cRvDanWXjLT1MrIIoNHFj7R+QUbHo0b5JHvJU VGPKq8GkFY2BC5kLXc9WQCgJy8TkIAc/riKrYazzrydkUEMKmcmVRxaaX8UOewqJY6VE DSvvClmWH7sypsap1HCZ7deO4W9n27TwL1OYlN5EOHPTxPq/Fe+WEqaMHTVt5HmolIeW S5FRMXUfmUHE7bgFVT+pRtXJHIG6v/cR6iLj1R76H9AGHB2+ltwOnL+YzbARk4sUpxUl Ws/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720439713; x=1721044513; 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=epeRSHi6mC8mGt8BJ/p9sWqSupogTGOrQYUwH4FaAcI=; b=idnmuQmhPjcslHsNCCWtip1xpJ1ORimDcbaUuggvPkv/WScErS6Nxfs5bTYAnGxb07 +zVSqgjNQ0I90dpQE9b4BPpcmax+Vx37fiJ7bu56/YGjfGiUNCnqaAwK3YDQMlvvmwyl 2s8I2wThzkpw19kZa1Mr+8YfszwgG9YrTjR31xpbzQ/CiCFX8uJsLelmV34d/eQILbPn GiiO1KudSMET8+uAp57/mHZfThLIf+18N2hPM6kUgJOByJa9Gw/1wxYj2DLnJpCHh6tn gFOJoKxVvzciRzRqbGmOu9RYB34u6x2ByBVVQEDBvwbo6zW2zvhzL9QIFPoGZ/kWe1X7 ukxA== X-Forwarded-Encrypted: i=1; AJvYcCV6izdboA8ZrWiySyKkWXOjiNncWAcQB7jrVFknFHaGUfI6CyBcTLYOf3/BsuLfSIhqcXvMu/V2PdO154u4wfCPsRoCF5TpBZrNGxLgHemCZ9Hi X-Gm-Message-State: AOJu0YwclEZwIhWWuQAGH8dhuvdOVMcwEExxReOc6u9DZmk7ZM4I88Pq q08UF6LlAUq6nGPKYTwOn+dGwLcna/CcfYv404u7rcylc59aK2d/mzFSwxmjUbgHmC9ZPbvsSfv 8KR5vzxVz+Vmx9RLGOnDBF+kK4jU= X-Google-Smtp-Source: AGHT+IF8DNO0NmZdQWEsqFS6AoEOUX+UbD+xglEwag9oSEW4KODFLrB8El5G9sYiIfN9cwChOkf+JdK+TkrLiDKuzrA= X-Received: by 2002:a05:6870:b48e:b0:259:8c21:e03 with SMTP id 586e51a60fabf-25e2bb89fedmr10125019fac.32.1720439712735; Mon, 08 Jul 2024 04:55:12 -0700 (PDT) MIME-Version: 1.0 References: <8fab8-65d74c80-1-2f28e880@39088166> <99df2-65d8d200-1-63c26880@172687752> In-Reply-To: From: Amit Kapila Date: Mon, 8 Jul 2024 17:25:01 +0530 Message-ID: Subject: Re: Slow catchup of 2PC (twophase) transactions on replica in LR To: "Hayato Kuroda (Fujitsu)" Cc: Vitaly Davydov , Ajin Cherian , Heikki Linnakangas , "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 Mon, Jul 8, 2024 at 12:34=E2=80=AFPM Hayato Kuroda (Fujitsu) wrote: > > > Another possible problem is related to my use case. I haven't reproduce= d this > > case, just some thoughts. I guess, when two_phase is ON, the PREPARE st= atement > > may be truncated from the WAL at checkpoint, but COMMIT PREPARED is sti= ll kept > > in the WAL. On catchup, I would ask the master to send transactions fro= m some > > restart LSN. I would like to get all such transactions competely, with = theirs > > bodies, not only COMMIT PREPARED messages. > > I don't think it is a real issue. WALs for prepared transactions will ret= ain > until they are committed/aborted. > When the two_phase is on and transactions are PREPAREd, they will not be > cleaned up from the memory (See ReorderBufferProcessTXN()). Then, RUNNIN= G_XACT > record leads to update the restart_lsn of the slot but it cannot be move = forward > because ReorderBufferGetOldestTXN() returns the prepared transaction (See > SnapBuildProcessRunningXacts()). restart_decoding_lsn of each transaction= , which > is a candidate of restart_lsn of the slot. is always behind the startpoin= t of > its txn. > I see that in 0003/0004, the patch first aborts pending prepared transactions, update's catalog, and then change slot's property via walrcv_alter_slot. What if there is any ERROR (say the remote node is not reachable or there is an error while updating the catalog) after we abort the pending prepared transaction? Won't we end up with lost prepared transactions in such a case? Few other comments: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The code to handle SUBOPT_TWOPHASE_COMMIT should be after failover option handling for the sake of code symmetry. Also, the checks should be in same order like first for slot_name, then enabled, then for PreventInTransactionBlock(), after those, we can have other checks for two_phase. If possible, we can move common checks in both failover and two_phase options into a common function. What should be the behavior if one tries to set slot_name to NONE and also tries to toggle two_pahse option? I feel both options together don't makes sense because there is no use in changing two_phase for some slot which we are disassociating the subscription from. The same could be said for the failover option as well, so if we agree with some different behavior here, we can follow the same for failover option as well. --=20 With Regards, Amit Kapila.