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 1rUM7s-00AODv-OQ for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jan 2024 07:32:17 +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 1rUM7r-00CG0g-QM for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jan 2024 07:32:15 +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 1rUM7r-00CG0Y-E8 for pgsql-hackers@lists.postgresql.org; Mon, 29 Jan 2024 07:32:15 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rUM7n-004Iaf-UI for pgsql-hackers@lists.postgresql.org; Mon, 29 Jan 2024 07:32:14 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1d8f3acc758so878325ad.1 for ; Sun, 28 Jan 2024 23:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706513529; x=1707118329; darn=lists.postgresql.org; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=ZNRI7whjt4H/ednM0EIeWfK5UrRv+o1IzNPy7bRIj3E=; b=YnCK/TTuy+1N7GZOJi4fh1K8BHPx1tVnxfz5S8GdnEjNHgymrgx/5FsMkKdhe91bv2 eHrtAojO/9zDyqQh/qdPCm3pw3ICVgD5oRfU76078FuALRz4jQVv437wDndsc0ACQSax mKjD2MWblMr2TZaTzYbY7na8UcBh4ubxN/EET1jbWFOs9V87eEJcTBSEUjjv+hPxlCWy h5thaQSNQPni8F6AoyWDUadMjfQxGIm6WUxciC/3UK1hSnLcCaK1sNViJoYqDlCPCHFx NOHm+v1i2AqeKaCe4orQCU+Qw5xtFigYvAb1CjInoDXi56wKUpXwr/hMpzaK1ht8Dihp QFhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706513529; x=1707118329; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ZNRI7whjt4H/ednM0EIeWfK5UrRv+o1IzNPy7bRIj3E=; b=HDOQSUEj4BUTdeSqnRvj9ru7HOUJJMZuF9lWiIe7uPBpMPrtnxT13U351BYn6NlQzF eLIabb+V4fOE4+/EHKwkePcsMybfSTUoLu2LVgFldRvFBxbKg0GhvFYReaBlsNgHc21L wkidFWPgqiqzdgTS3tk285Q1UUmJT1Z2bEekYtxxmaIpGkzzOcd9Zc5GU4SVrJk3PnGP QdzSE6ZSOIjsf7Bz9lhH2lq06PknLbW+71aIVA6h2eTeFpajRe7RaZwHu+QJ6TSV3eVO fYHjgu8aQn58oXkTauHDVlQLGNBN2BKu6S3LrM6GfszI3GKaSCvEvjWHLkCFNpO4n0cd pgJQ== X-Gm-Message-State: AOJu0Yw13DZwQhPQPGYDlyXjeG/MydD1VcuwNzPnBs6pGu1LfTapyu4f LjuOpJtMFfPjgYDc0rzugWqofRiMOtuOFSftrUV8OpJ3FKfJEDjh X-Google-Smtp-Source: AGHT+IEGId3T17zB/rT6yqD5gpznYMKUS2y3OslbQPBikhBUk0TEFQaL0eolPuL/qzNbIvpD6bTe+g== X-Received: by 2002:a17:902:c411:b0:1d8:f07f:a3be with SMTP id k17-20020a170902c41100b001d8f07fa3bemr607037plk.1.1706513529262; Sun, 28 Jan 2024 23:32:09 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id o5-20020a170902e00500b001d8d7323ea2sm1674133plo.74.2024.01.28.23.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 23:32:08 -0800 (PST) Date: Mon, 29 Jan 2024 16:32:06 +0900 (JST) Message-Id: <20240129.163206.738744107103873975.horikyota.ntt@gmail.com> To: hlinnaka@iki.fi Cc: masao.fujii@gmail.com, andres@anarazel.de, michael@paquier.xyz, pgsql-hackers@lists.postgresql.org Subject: Re: Network failure may prevent promotion From: Kyotaro Horiguchi In-Reply-To: References: <20240123.172410.1596193222420636986.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 27.2 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Mon_Jan_29_16_32_06_2024_387)--" Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----Next_Part(Mon_Jan_29_16_32_06_2024_387)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Thank you fixing the issue. At Tue, 23 Jan 2024 11:43:43 +0200, Heikki Linnakangas wrote i n > There's an existing AmWalReceiverProcess() macro too. Let's use that. Mmm. I sought an Is* function becuase "IsLogicalWorker()" is placed on the previous line. Our convention regarding those functions (macros) and variables seems inconsistent. However, I can't say for sure that we should unify all of them. > (See also > https://www.postgresql.org/message-id/f3ecd4cb-85ee-4e54-8278-5fabfb3a4ed0%40iki.fi > for refactoring in this area) > > Here's a patch set summarizing the changes so far. They should be > squashed, but I kept them separate for now to help with review: > > 1. revert the revert of 728f86fec6. > 2. your walrcv_shutdown_deblocking_v2-2.patch > 3. Also replace libpqrcv_PQexec() and libpqrcv_PQgetResult() with the > wrappers from libpq-be-fe-helpers.h Both replacements look fine. I didn't find another instance of similar code. > 4. Replace IsWalReceiver() with AmWalReceiverProcess() Just look fine. > >> - pqsignal(SIGTERM, SignalHandlerForShutdownRequest); /* request > >> - shutdown */ > >> + pqsignal(SIGTERM, WalRcvShutdownSignalHandler); /* request shutdown > >> */ > >> > >> Can't we just use die(), instead? > > There was a comment explaining the problems associated with exiting > > within a signal handler; > > - * Currently, only SIGTERM is of interest. We can't just exit(1) within > > - * the > > - * SIGTERM signal handler, because the signal might arrive in the middle > > - * of > > - * some critical operation, like while we're holding a spinlock. > > - * Instead, the > > And I think we should keep the considerations it suggests. The patch > > removes the comment itself, but it does so because it implements our > > standard process exit procedure, which incorporates points suggested > > by the now-removed comment. > > die() doesn't call exit(1). Unless DoingCommandRead is set, but it > never is in the walreceiver. It looks just like the new > WalRcvShutdownSignalHandler() function. Am I missing something? Ugh.. Doesn't the name 'die()' suggest exit()? I agree that die() can be used instad. > Hmm, but doesn't bgworker_die() have that problem with exit(1)ing in > the signal handler? I noticed that but ignored for this time. > I also wonder if we should replace SignalHandlerForShutdownRequest() > completely with die(), in all processes? The difference is that > SignalHandlerForShutdownRequest() uses ShutdownRequestPending, while > die() uses ProcDiePending && InterruptPending to indicate that the > signal was received. Or do some of the processes want to check for > ShutdownRequestPending only at specific places, and don't want to get > terminated at the any random CHECK_FOR_INTERRUPTS()? At least, pg_log_backend_memory_context() causes a call to ProcessInterrupts via "ereport(LOG_SERVER_ONLY" which can lead to an exit due to ProcDiePending. In this regard, checkpointer clearly requires the distinction. Rather than merely consolidating the notification variables and striving to annihilate CFI calls in the execution path, I believe we need a shutdown mechanism that CFI doesn't react to. However, as for the method to achieve this, whether we should keep the notification variables separate as they are now, or whether it would be better to introduce a variable that causes CFI to ignore ProcDiePending, is a matter I think is open to discussion. Attached patches are the rebased version of v3 (0003 is updated) and additional 0005 that makes use of die() instead of walreceiver's custom function. regards. -- Kyotaro Horiguchi NTT Open Source Software Center ----Next_Part(Mon_Jan_29_16_32_06_2024_387)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="v4-0001-Revert-Revert-libpqwalreceiver-Convert-to-libpq-b.patch"