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 1rwh7L-003Td0-EL for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Apr 2024 11:36:51 +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 1rwh7J-003GSo-09 for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Apr 2024 11:36:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rwh7I-003GSe-HP for pgsql-hackers@lists.postgresql.org; Tue, 16 Apr 2024 11:36:48 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rwh7B-0037yD-BF for pgsql-hackers@postgresql.org; Tue, 16 Apr 2024 11:36:47 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-346b96f1483so2249842f8f.1 for ; Tue, 16 Apr 2024 04:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713267400; x=1713872200; darn=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=jDATmvw/uLJQ3jSXV39eRmgIqXc3awjxyKjaUAH8oWM=; b=TYzdd+hEqP+3xr1XkpJ8VjD2I1pVDprt7dvT87H61TWS0Shi8S2n1Lz+yALBMy6L3q RSBfJsDCq4wmw8ubZiqJ33F2vX59ryv/mxRKRyg4QreGzLwagCZW7Hjw3uBDI0WXTwQM mOj6vmHbdllvCr+LphzXGZZc+bQb5leAZRHCBZCRSr3Q8IqRKa9yMlZcc4C1gvk/aAju j9SRAmg/h3CSX34X0iLFgecsNrO92c+3mj2H4mYiQezqflU4N0NbIeR6dp34fxELMDHn S3UCL+J6NKX4DKtckyQ6HhwRp0Tc2FKzVcbtVMnEVwpD2kw5XivweixJBrNfXsh31qPN Q6OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713267400; x=1713872200; 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=jDATmvw/uLJQ3jSXV39eRmgIqXc3awjxyKjaUAH8oWM=; b=QHE75+qLIShWe+drYqTLcpLG5Pi9wRcnXQrLjIWgF0UUkZ7Gprq137TEAn6cMnMH1v stbu5UY2R7Ekwn9Xw04z3lCH3acDSEF4eSIYD45jJoxmbZWQPRjZtVmX0BvqQ8hyArhK UgFXw8fdR25rljLFnoKkW7AMqe1TxTxYJVHRwEKSmmE1B81b6O/Q0S108XVc6n2KOojD fxmVY3JDxVn+VlWTq4pnxHBMgvBu4fV8L3aJGocftYkaFlwUtoDa2tzJ31P3tGHNqaZA Qp5hUfQMQgUB+SIgpXi+lH+1nt6RcGldoiiIwgCy0dxHI9ea45uw0KtfKN6iVtkPG5b8 H9mg== X-Forwarded-Encrypted: i=1; AJvYcCWxfima35ypbfsgqGfK8g19d1F4Qu8ghSirqTDz7UKISlUpUEkYGTN4jxysMeVvyIZdkds3Pc66JtAzuPyKZpzg245kJQ5fg8hmkpVM X-Gm-Message-State: AOJu0YxeK31nrQpgcD2sJQCa+qb2CD9ko4Xlfib0hpA35Gtrb9nu/BQ0 DC2/vzrIpdix1lQrAqJzvgZxKU3Mpqe3WyOhCqu6yWR3ZmUSbRzZpr8sMob0TTRBO3UTlb0gylM 2rE2knwwu/t/EN2xoHq+HWRBFBRo= X-Google-Smtp-Source: AGHT+IGPkKDc1kAgT5xPqQ8/rIS9y31sZGiBq4E341YyGMrD/6lTUkTcXzYqdmlHnwqFverrtx4trheLfm9UCfFy/dc= X-Received: by 2002:adf:e64a:0:b0:346:f935:e828 with SMTP id b10-20020adfe64a000000b00346f935e828mr1345058wrn.5.1713267399533; Tue, 16 Apr 2024 04:36:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Tue, 16 Apr 2024 17:06:28 +0530 Message-ID: Subject: Re: Disallow changing slot's failover option in transaction block To: "Hayato Kuroda (Fujitsu)" Cc: "Zhijie Hou (Fujitsu)" , Amit Kapila , pgsql-hackers , shveta malik , "Drouvot, Bertrand" 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 Tue, Apr 16, 2024 at 1:45=E2=80=AFPM Hayato Kuroda (Fujitsu) wrote: > > Dear Hou, > > > Kuroda-San reported an issue off-list that: > > > > If user execute ALTER SUBSCRIPTION SET (failover) command inside a txn = block > > and rollback, only the subscription option change can be rolled back, w= hile the > > replication slot's failover change is preserved. > > > > This is because ALTER SUBSCRIPTION SET (failover) command internally > > executes > > the replication command ALTER_REPLICATION_SLOT to change the replicatio= n > > slot's > > failover property, but this replication command execution cannot be > > rollback. > > > > To fix it, I think we can prevent user from executing ALTER SUBSCRIPTIO= N set > > (failover) inside a txn block, which is also consistent to the ALTER > > SUBSCRIPTION REFRESH/DROP SUBSCRIPTION command. Attach a small > > patch to address this. > > Thanks for posting the patch, the fix is same as my expectation. > Also, should we add the restriction to the doc? I feel [1] can be updated= . +1. Similar to ALTER SUB, CREATE SUB also needs to be fixed. This is because we call alter_replication_slot in CREATE SUB as well, for the case when slot_name is provided and create_slot=3Dfalse. But the tricky part is we call alter_replication_slot() when creating subscription for both failover=3Dtrue and false. That means if we want to fix it on the similar line of ALTER SUB, we have to disallow user from executing the CREATE SUBSCRIPTION (slot_name =3D xx) in a txn block, which seems to break some existing use cases. (previously, user can execute such a command inside a txn block). So, we need to think if there are better ways to fix it. After discussion with Hou-San offlist, here are some ideas: 1. do not alter replication slot's failover option when CREATE SUBSCRIPTION WITH failover=3Dfalse. This means we alter replication slot only when failover is set to true. And thus we can disallow CREATE SUB WITH (slot_name =3Dxx, failover=3Dtrue, create_slot=3Dfalse) inside a txn block. This option allows user to run CREATE-SUB(create_slot=3Dfalse) with failover=3Dfalse in txn block like earlier. But on the downside, it makes the behavior inconsistent for otherwise simpler option like failover, i.e. with failover=3Dtrue, CREATE SUB is not allowed in txn block while with failover=3Dfalse, it is allowed. It makes it slightly complex to be understood by user. 2. let's not disallow CREATE SUB in txn block as earlier, just don't perform internal alter-failover during CREATE SUB for existing slots(create_slot=3Dfalse, slot_name=3Dxx) i.e. when create_slot is false, we will ignore failover parameter of CREATE SUB and it is user's responsibility to set it appropriately using ALTER SUB cmd. For create_slot=3Dtrue, the behaviour of CREATE-SUB remains same as earlier. This option does not add new restriction for CREATE SUB wrt txn block. In context of failover with create_slot=3Dfalse, we already have a similar restriction (documented one) for ALTER SUB, i.e. with 'ALTER SUBSCRIPTION SET(slot_name =3D new)', user needs to alter the new slot's failover by himself. CREAT SUB can also be documented in similar way. This seems simpler to be understood considering existing ALTER SUB's behavior as well. Plus, this will make CREATE-SUB code slightly simpler and thus easily manageable. 3. add a alter_slot option for CREATE SUBSCRIPTION, we can only alter the slot's failover if alter_slot=3Dtrue. And so we can disallow CREATE SUB WITH (slot_name =3Dxx, alter_slot=3Dtrue) inside a txn block. This seems a clean way, as everything will be as per user's consent based on alter_slot parameter. But on the downside, this will need introducing additional parameter and also adding new restriction of running CREATE-sub in txn block for a specific case. 4. Don't alter replication in subscription DDLs. Instead, try to alter replication slot's failover in the apply worker. This means we need to execute alter_replication_slot each time before starting streaming in the apply worker. This does not seem appealing to execute alter_replication_slot everytime the apply worker starts. But if others think it as a better option, it can be further analyzed. Currently, our preference is option 2, as that looks a clean solution and also aligns with ALTER-SUB behavior which is already documented. Thoughts? -------------------------------- Note that we could not refer to the design of two_phase here, because two_phase can be considered as a streaming option, so it's fine to change the two_phase along with START_REPLICATION command. (the two_phase is not changed in subscription DDLs, but get changed in START_REPLICATION command). But the failover is closely related to a replication slot itself. -------------------------------- Thanks Shveta