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 1rGd4q-00GGyc-GX for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Dec 2023 10:48:24 +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 1rGd4p-005PJZ-2p for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Dec 2023 10:48:23 +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 1rGd4o-005PHt-KZ for pgsql-hackers@lists.postgresql.org; Fri, 22 Dec 2023 10:48:22 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rGd4l-00BePx-HH for pgsql-hackers@postgresql.org; Fri, 22 Dec 2023 10:48:21 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3368abe1093so1130326f8f.2 for ; Fri, 22 Dec 2023 02:48:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703242097; x=1703846897; 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=c+SOtIhtj1cqU/L/DsCba6WqUJVo9ZsEAO5WAsidxvo=; b=PVNTlFUqTMHbDikXy2AaApSJP5XXTkgORb8f527iHg65v+X9pA0citlIK9Z764CVcM ESfz5Z2Ebk55hRsh4d3SZxLVrTfJUKAZsut6eg52xx+uqbxhFNA4DpFfux3NTJ7FDbcB c4x6NTaLEelVamcvG+4ZcbFuSg76/3UPFizvXo3rtBymcEObUTHF81N59GQQUff0vBpW cDpK+y5y28vdsfHuuAvaN/rPKZNGJXCSFnhmmx2IYznPq6R8BR8M72N8j5a33QzZQHuc VzEM0K+uG+GqG8/RygEz7tAcMfRC9BKyTVg7dKWF0eXHfd92LY6zHmlIXk+DJwYrSdjB mq0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703242097; x=1703846897; 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=c+SOtIhtj1cqU/L/DsCba6WqUJVo9ZsEAO5WAsidxvo=; b=pua9ua05yexFRs5vM1ottWHnSJec7ICHS8KAf6jrSPOx55CnLyp8mvl7ao6wtYguDs z2tXu/glK3L5uNhMygY1BztgaoNDpJ1tOoFJXPXnDHQ7KUq9R2svbqv9x6AGm0rchhxJ gnKrYTUI9PqDND1K/nrSKWu23dID9kLaJeTqH+fe+QG5Ltzlagzdach7boITO9h4wq3A YNFCF7vIUUchsBF5TEb/t01UYhmRY+fvLfkgWy1uNV7N5DWHf3YIxdzfAcbQB3VQcVMS dwc5Tjj1oZw/2UlVfOEWm339ubb5V30vUOmE50lG0JMf4K6N55SZZfLtV9UEOlNNTuiX nqJw== X-Gm-Message-State: AOJu0YzC6rFKq/5N3/j+COz17K4dPOwuJjpNrKiz0Ba4mlvX5DLLWz8n vAY4+Pkaa3QDewWiMKfFCBQDKht6l3YfRXGq6cI= X-Google-Smtp-Source: AGHT+IEBd29nOOSQPmYBzFEy5pNo9ctbhWmljS6d3H0HdHW8nqcV4TbClI18o5fedQ/peHmO9mIWdEA4h1kChKkXjd8= X-Received: by 2002:a5d:698d:0:b0:336:615e:9365 with SMTP id g13-20020a5d698d000000b00336615e9365mr601918wru.105.1703242097218; Fri, 22 Dec 2023 02:48:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Fri, 22 Dec 2023 16:18:05 +0530 Message-ID: Subject: Re: Synchronizing slots from primary to standby To: "Hayato Kuroda (Fujitsu)" Cc: "Zhijie Hou (Fujitsu)" , Amit Kapila , Peter Smith , "Drouvot, Bertrand" , Nisha Moond , Bharath Rupireddy , Peter Eisentraut , Bruce Momjian , Ashutosh Sharma , Andres Freund , pgsql-hackers , Ajin Cherian , Alvaro Herrera , shveta malik 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, Dec 21, 2023 at 6:37=E2=80=AFPM Hayato Kuroda (Fujitsu) wrote: > > Dear Shveta, > > Thanks for updating the patch! Here is my comments for v52-0002. Thanks for the feedback Kuroda-san. I have addressed these in v53. > ~~~~~ > system-views.sgml > > 01. > > ``` > + > + > + > + sync_state char > + > + > + Defines slot synchronization state. This is meaningful on the phys= ical > + standby which has configured =3D true. > + Possible values are: > + > + > + n =3D none for user created slots, > ... > ``` > > Hmm. I'm not sure why we must show a single character to a user. I'm OK f= or > pg_subscription.srsubstate because it is a "catalog" - the actual value w= ould be > recorded in the heap. But pg_replication_slot is just a view so that we c= an replace > internal representations to other strings. E.g., pg_replication_slots.wal= _status. > How about using {none, initialized, ready} or something? Done. > ~~~~~ > postmaster.c > > 02. bgworker_should_start_now > > ``` > + if (start_time =3D=3D BgWorkerStart_ConsistentState_HotStand= by && > + pmState !=3D PM_RUN) > + return true; > ``` > > I'm not sure the second condition is really needed. The line will be exec= uted when > pmState is PM_HOT_STANDBY. Is there a possibility that pmState is changed= around here? 'case PM_RUN:' is a fall-through and thus we need to have this second condition under 'case PM_HOT_STANDBY' for BgWorkerStart_ConsistentState_HotStandby to avoid the worker getting started on non-standby. > ~~~~~ > libpqwalreceiver.c > > 03. PQWalReceiverFunctions > > ``` > + .walrcv_get_dbname_from_conninfo =3D libpqrcv_get_dbname_from_connin= fo, > ``` > > Just to confirm - is there a rule for ordering? No, I think. I am not aware of any. > ~~~~~ > slotsync.c > > 04. SlotSyncWorkerCtx > > ``` > typedef struct SlotSyncWorkerCtx > { > pid_t pid; > slock_t mutex; > } SlotSyncWorkerCtx; > > SlotSyncWorkerCtx *SlotSyncWorker =3D NULL; > ``` > > Per other files like launcher.c, should we use a name like "SlotSyncWorke= rCtxStruct"? Modified. > 05. SlotSyncWorkerRegister() > > Your coding will work well, but there is another approach which validates > slotsync parameters here. In this case, the postmaster should exit ASAP. = This can > notify that there are some wrong settings to users earlier. Thought? I think the postmaster should not exit. IMO, slot-sync worker being a child process of postmaster, should not control start or exit of postmaster. The worker should only exit itself if slot-sync GUCs are not set. Have you seen any other case where postmaster exits if any of its bgworker processes has invalid GUCs? > 06. wait_for_primary_slot_catchup > > ``` > + CHECK_FOR_INTERRUPTS(); > + > + /* Handle any termination request if any */ > + ProcessSlotSyncInterrupts(wrconn); > ``` > > ProcessSlotSyncInterrupts() also has CHECK_FOR_INTERRUPTS(), so no need t= o call. yes, removed. > 07. wait_for_primary_slot_catchup > > ``` > + /* > + * XXX: Is waiting for 2 seconds before retrying enough or more = or > + * less? > + */ > + rc =3D WaitLatch(MyLatch, > + WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, > + 2000L, > + WAIT_EVENT_REPL_SLOTSYNC_PRIMARY_CATCHUP); > + > + ResetLatch(MyLatch); > + > + /* Emergency bailout if postmaster has died */ > + if (rc & WL_POSTMASTER_DEATH) > + proc_exit(1); > ``` > > Is there any reasons not to use WL_EXIT_ON_PM_DEATH event? If not, you ca= n use. I think we should use WL_EXIT_ON_PM_DEATH. Corrected now. > 08. synchronize_slots > > ``` > + SpinLockAcquire(&WalRcv->mutex); > + if (!WalRcv || > + (WalRcv->slotname[0] =3D=3D '\0') || > + XLogRecPtrIsInvalid(WalRcv->latestWalEnd)) > + { > ... > ``` > > Assuming that WalRcv is still NULL. In this case, does the first SpinLock= Acquire() > lead a segmentation fault? It may. Thanks for pointing this out. Modified. > 09. synchronize_slots > > ``` > + elog(DEBUG2, "slot sync worker's query:%s \n", s.data); > ``` > > The query is not dynamical one, so I think no need to print even if the d= ebug > mode. Okay. Removed. > 10. synchronize_one_slot > > IIUC, this function can synchronize slots even if the used plugin on prim= ary is > not installed on the secondary server. If the slot is created by the slot= sync > worker, users will recognize it after the server is promoted and the deco= de is > starting. I felt it is not good specification. Can we detect in the valid= ation > phase? Noted the concern. Let me review more on this. I will revert back. > ~~~~~ > not the source code > > 11. > > I tested the typical case - promoting a publisher from a below diagram. > A physical replication slot "physical" was specified as standby_slot_name= s. > > ``` > node A (primary) --> node B (secondary) > | > | > node C (subscriber) > ``` > > And after the promoting, below lines were periodically output on logfiles= for > node B and C. > > ``` > WARNING: replication slot "physical" specified in parameter "standby_slo= t_names" does not exist, ignoring > ``` It seems like you have set standby_slot_names on the standby, that is why promoted standby is emitting this warning. It is not recommended to set it on standby as it is the primary GUC. Having said that, I understand that even on primary, we may get this repeated warning if standby_slot_names is not set correctly. This WARNING is intentional, as the user should know that this setting is wrong. So I am not sure if we should suppress this. I would like to know what others think on this. > Do you have idea to suppress the warning? IIUC it is a normal behavior of= the > walsender so that we cannot avoid the periodical outputs. > > The steps of the test was as follows: > > 1. stop the node A via pg_ctl stop > 2. promota the node B via pg_ctl promote > 3. change the connection string of the subscription via ALTER SUBSCRIPTIO= N ... CONNECTION ... > thanks Shveta