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 1sPKgv-0046Cf-TD for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jul 2024 11:31:58 +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 1sPKgt-00Gcuv-UP for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jul 2024 11:31:56 +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 1sPKgt-00Gcum-Iz for pgsql-hackers@lists.postgresql.org; Thu, 04 Jul 2024 11:31:56 +0000 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sPKgs-000Nd2-KX for pgsql-hackers@lists.postgresql.org; Thu, 04 Jul 2024 11:31:55 +0000 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3d853e31de8so311160b6e.2 for ; Thu, 04 Jul 2024 04:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720092712; x=1720697512; 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=1nOjRkbisRPS+ke0JWEOOttdiKgIyDUnWO72BsvxNxM=; b=kjQUHMFQQO1LhL7dt4qJwW0PmwUCbgZayEqL2tJa8Ok9d/Q9VFMvn76/qdGOShsKUO buHxKX899Ki/Xl7DoK1Bsg+K5s4vNMkFUJx5GfO8gYVAbfViV745KtjCiH0F8AyGsFuh QvZAuf4NwC0+5tXTj/kOvAeYOsKMixsrX0d6x98u7uXYw0SilcQdJeiMU5Cb0BEbCyvy ev4XTsMcwjBbgwV3CEAodtaAYW9bb8Qaix2bQl3GwLMOXNsG2Bcilb2EwffEXlz8r6pS Xv+ITF1QpDs2fFPDaKs6pX3LB1+zJZFRoO+x9FrkNP6eTtxvyI3kctLiO4lSU6Ay3yDC gYHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720092712; x=1720697512; 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=1nOjRkbisRPS+ke0JWEOOttdiKgIyDUnWO72BsvxNxM=; b=Uc8bp72PY2Ylp0lK+MTS5XpHWd6RtcI7+gxtjmdWZGXz3GlxDYFykFQx9TVcpKP75c mQurLH4fTjJWZ8FlH1FVwXmPesRFN1+pIxCJIfer6+pXjLiKdcrFmUYAK+zlPBwEdKHw K03tTJEi07CFD2hMbR6VJYgH8jI9COhj8N0MQrC/cpP8GUxjlkr5WZkxxtl4vROeSyrb ZrO8vYb/4U10Z8FsduLy/mDCWsx4PVmN7RsjRc70hxK+7q/yBt8C1PTxvYRLFstl80a2 wRc2owzetS/d2U+BdQ4YkIL0ocFbyNE2WqcKG1Oa5RB7DU/s5PBWLBNEKtGXJ6O8nZ8n hr4g== X-Forwarded-Encrypted: i=1; AJvYcCUa1ArzYjGs/mr12NpSn4LoyfBUhd9VV3kyfdKDP0FOaJnwJ0gwW5YBI6c05B1mL85E+1ik9cCW29jS3gM9FaHCER5dSPUKO95wxdun5VbsC13o X-Gm-Message-State: AOJu0Yz7jSh+8ivYSCZ3vFPCym5jlCgdzp3hcVD4PQ2Kb795XEBFA3xL uRvWtRubVvtf+yhftK9cu3l7nKENO2w3jGrhalSUGd566s/U/VQinzDwtaWDR3gZxfA/sFY8ppc ZHfU7C1ISOA9G/QH8LfDfeKCnaGE= X-Google-Smtp-Source: AGHT+IGqUOsgLRVGpRfFejCqdev7X5QvL47RcZJHnu4lwq7LDwbvJhr75pNOrJ6EuMIDgQ9XuE6rhWmXIqWHfC9DfcI= X-Received: by 2002:a05:6870:e2cf:b0:25e:1c7c:3df8 with SMTP id 586e51a60fabf-25e2b8d9c0amr1060481fac.10.1720092712258; Thu, 04 Jul 2024 04:31:52 -0700 (PDT) MIME-Version: 1.0 References: <8fab8-65d74c80-1-2f28e880@39088166> <99df2-65d8d200-1-63c26880@172687752> In-Reply-To: From: Amit Kapila Date: Thu, 4 Jul 2024 17:01:40 +0530 Message-ID: Subject: Re: Slow catchup of 2PC (twophase) transactions on replica in LR To: "Hayato Kuroda (Fujitsu)" Cc: Ajin Cherian , =?UTF-8?B?0JTQsNCy0YvQtNC+0LIg0JLQuNGC0LDQu9C40Lk=?= , 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 Thu, Jul 4, 2024 at 1:34=E2=80=AFPM Hayato Kuroda (Fujitsu) wrote: > > > > > > > It succeeds if force_alter is also expressly set. Prepared transactio= ns will be > > > aborted at that time. > > > > > > ``` > > > subscriber=3D# ALTER SUBSCRIPTION sub SET (two_phase =3D off, force_a= lter =3D > > on); > > > ALTER SUBSCRIPTION > > > > > > > Isn't it better to give a Notice when force_alter option leads to the > > rollback of already prepared transactions? > > Indeed. I think this can be added for 0003. For now, it says like: > > ``` > postgres=3D# ALTER SUBSCRIPTION sub SET (TWO_PHASE =3D off, FORCE_ALTER = =3D on); > WARNING: requested altering to two_phase =3D false but there are prepare= d transactions done by the subscription > DETAIL: Such transactions are being rollbacked. > ALTER SUBSCRIPTION > Is it possible to get a NOTICE instead of a WARNING? > > > I have another question on the latest 0001 patch: > > + /* > > + * Stop all the subscription workers, just in case. > > + * Workers may still survive even if the subscription is > > + * disabled. > > + */ > > + logicalrep_workers_stop(subid); > > > > In which case the workers will survive when the subscription is disable= d? > > I think both normal and tablesync worker can survive, because ALTER SUBSC= RIPTION > DISABLE command does not send signal to workers. It just change the syste= m catalog. > logicalrep_workers_stop() is added to ensure all workers are stopped. > > Actually, earlier version (-v3) did not have a mechanism but they sometim= es got > assertion failures in maybe_reread_subscription(). This was because the s= urvived > workers read pg_subscription catalog and failed below assertion: > > ``` > /* two-phase cannot be altered while the worker exists */ > Assert(newsub->twophasestate =3D=3D MySubscription->twophasestate= ); > ``` > But that is not a good reason for this operation to stop workers first. Instead, we should prohibit this operation if any worker is present. The reason is that there is always a chance that if any worker is alive, it can prepare a new transaction after we have checked for the presence of any prepared transactions. Comments: =3D=3D=3D=3D=3D=3D=3D=3D=3D 1. There is no need to do something remarkable regarding + * the "false" to "true" case; the backend process alters + * subtwophase to LOGICALREP_TWOPHASE_STATE_PENDING once. + * After the subscription is enabled, a new logical + * replication worker requests to change the two_phase + * option of its slot from pending to true when the + * initial data synchronization is done. The code path is + * the same as the case in which two_phase is initially + * set to true. The patch has some funny characters in the above comment at the places highlighted by me. It seems you have copied from some editor that has inserted such characters. 2. /* * Do not allow toggling of two_phase option. Doing so could cause * missing of transactions and lead to an inconsistent replica. * See comments atop worker.c * * Note: Unsupported twophase indicates that this call originated * from AlterSubscription. */ if (!IsSet(supported_opts, SUBOPT_TWOPHASE_COMMIT)) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("unrecognized subscription parameter: \"%s\"", defel->defname))); This part of the code must either be removed or converted to an assert. 3. The tests added in 099_twophase_added.pl should be part of 021_twophase.= pl --=20 With Regards, Amit Kapila.