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 1qxrAh-003rOw-Cc for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Oct 2023 16:00: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 1qxrAg-0038vo-4c for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Oct 2023 16:00:50 +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 1qxrAf-0038vf-Qn for pgsql-hackers@lists.postgresql.org; Tue, 31 Oct 2023 16:00:49 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qxrAd-0040sn-89 for pgsql-hackers@postgresql.org; Tue, 31 Oct 2023 16:00:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2023062407; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=cFry5e/dKlt4rhxtiGevLNg/HFUYSBiYXoWzkfSEoCE=; b=hOz2h zj5kDJS6pC/3XO+8zt4U4Gy3wL/FHNaFfpmPBz1QZZKkKy/S2o08/YL/cCYQ5tPuyT6GX/Gd0XdkQ rGOCshKunXiJDs9xNQ1jHtd5KARi5RV8ge6FxYd43OezrilmPbuhAifTYU9QF+8dhMkGFBQo4BdO4 shud0Uyjr/dVCaDcNzBC3zbxS/sBSc4E/SERvVc4I/72Eaqu3Ox0ZBMYwqcLyGLUFi35AgU2zGcFv MP17SlejsRZq72qfkEacrT+lUv350nnnuTB0CeGWNz8NS2NamxFxEmuQEWEDbKtzcdgFO/EcroPiV rIR70xslScrXT2hg6fIZHSBUiPEVQ==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1qxrAU-004D4W-2b; Tue, 31 Oct 2023 12:00:38 -0400 Date: Tue, 31 Oct 2023 12:00:38 -0400 From: Bruce Momjian To: Bharath Rupireddy Cc: Wei Sun <936739278@qq.com>, pgsql-hackers Subject: Re: Add lasterrno setting for dir_existsfile() Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="26Bj5Xcg0cbDBh2g" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --26Bj5Xcg0cbDBh2g Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Aug 13, 2022 at 02:46:24PM +0530, Bharath Rupireddy wrote: > On Sat, Aug 13, 2022 at 4:34 AM Bruce Momjian wrote: > > > > On Fri, Aug 12, 2022 at 06:22:01PM -0400, Bruce Momjian wrote: > > > On Mon, Jan 10, 2022 at 12:19:28AM +0800, Wei Sun wrote: > > > > Hi, > > > > > > > > Some time ago,the following patch clean up error handling in pg_basebackup's > > > > walmethods.c. > > > > https://github.com/postgres/postgres/commit/248c3a9 > > > > > > > > This patch keep the error state in the DirectoryMethodData struct, > > > > in most functions, the lasterrno is set correctly, but in function > > > > dir_existsfile(), > > > > the lasterrno is not set when the file fails to open. > > > > > > > > If this is a correction omission, I think this patch can fix this. > > > > > > Looking at this, the function is used to check if something exists, and > > > return a boolean. I am not sure it is helpful to also return a ENOENT in > > > the lasterrno status field. It might be useful to set lasterrno if the > > > open fails and it is _not_ ENOENT. > > > > Thinking some more, how would you know to check lasterrno since exists > > and not exists are both valid outputs? > > I agree with Bruce here, ENOENT isn't a failure for open because it > says that file doesn't exist. > > If we have the policy like every syscall failure must be captured in > lasterrno and be reported by the callers accordingly, then the patch > (of course, with the change that doesn't set lasterrno when errno is > ENOENT) proposed makes sense to me. Right now, the callers of > existsfile() aren't caring for the errno though. Every other open() > syscall failure in walmethods.c is captured in lasterrno. > > Otherwise, adding a comment in dir_existsfile() on why aren't > capturing lasterrno might help and avoid future discussions around > this. I have applied the attached patch to master to explain why we don't set lasterrno. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you. --26Bj5Xcg0cbDBh2g Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="lasterro.diff" diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c index 2de11ce9b1..33cb85b849 100644 --- a/src/bin/pg_basebackup/walmethods.c +++ b/src/bin/pg_basebackup/walmethods.c @@ -594,6 +594,11 @@ dir_existsfile(WalWriteMethod *wwmethod, const char *pathname) fd = open(tmppath, O_RDONLY | PG_BINARY, 0); if (fd < 0) + + /* + * Skip setting dir_data->lasterrno here because we are only checking + * for existence. + */ return false; close(fd); return true; --26Bj5Xcg0cbDBh2g--