Re: [PATCH] Use access() to check file existence in GetNewRelFileNode().

Lists: Postg스포츠 토토 사이트SQL
From: Paul Guo <paulguo(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH] Use access() to check file existence in GetNewRelFileNode().
Date: 2018-05-17 08:09:27
Message-ID: CABQrizcUtiHaquxK=d4etBX8GF9kbZB50Nt1gO9_aN-e9SptyQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg무지개 토토SQL

Previous code uses BasicOpenFile() + close().

access() should be faster than BasicOpenFile()+close() and access()
should be more correct since BasicOpenFile() could fail for various
cases (e.g. due to file permission, etc) even the file exists.

access() is supported on Linux/Unix. I do not have a Windows dev
environment, but MSDN tells me that access() is supported on Windows also
and there have been access() call in the workspace, so I assume there is no
portability issue.

Thanks.

Attachment Content-Type Size
0001-Use-access-to-check-file-existence-in-GetNewRelFileN.patch application/octet-stream 1.3 KB

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Paul Guo <paulguo(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Use access() to check file existence in GetNewRelFileNode().
Date: 2018-05-17 09:09:50
Message-ID: 20180517090950.GB9938@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg롤 토토SQL :

On Thu, May 17, 2018 at 04:09:27PM +0800, Paul Guo wrote:
> Previous code uses BasicOpenFile() + close().
>
> access() should be faster than BasicOpenFile()+close() and access()
> should be more correct since BasicOpenFile() could fail for various
> cases (e.g. due to file permission, etc) even the file exists.

Failing because of file permissions would be correct. There have been
cases in the past, particularly on Windows, where anti-virus softwares
wildly scan files, causing EACCES on various points of the data folder.

> access() is supported on Linux/Unix. I do not have a Windows dev
> environment, but MSDN tells me that access() is supported on Windows also
> and there have been access() call in the workspace, so I assume there is no
> portability issue.

Yes, access() is spread already in the core code.

- fd = BasicOpenFile(rpath, O_RDONLY | PG_BINARY);

- if (fd >= 0)
+ if (access(rpath, F_OK) == 0)

What you are looking for here is R_OK, no?
--
Michael


From: Paul Guo <paulguo(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Use access() to check file existence in GetNewRelFileNode().
Date: 2018-05-17 09:23:28
Message-ID: CABQrizfczjNhAY1+bMLZCrSLFE24w=UOYNYW5ovzsadmDnBZKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg스포츠 토토 베트맨SQL

F_OK seems to be better than R_OK because we want to check file existence
(not read permission) before creating the relation file with the path
later.

2018-05-17 17:09 GMT+08:00 Michael Paquier <michael(at)paquier(dot)xyz>:

> On Thu, May 17, 2018 at 04:09:27PM +0800, Paul Guo wrote:
> > Previous code uses BasicOpenFile() + close().
> >
> > access() should be faster than BasicOpenFile()+close() and access()
> > should be more correct since BasicOpenFile() could fail for various
> > cases (e.g. due to file permission, etc) even the file exists.
>
> Failing because of file permissions would be correct. There have been
> cases in the past, particularly on Windows, where anti-virus softwares
> wildly scan files, causing EACCES on various points of the data folder.
>
> > access() is supported on Linux/Unix. I do not have a Windows dev
> > environment, but MSDN tells me that access() is supported on Windows also
> > and there have been access() call in the workspace, so I assume there is
> no
> > portability issue.
>
> Yes, access() is spread already in the core code.
>
> - fd = BasicOpenFile(rpath, O_RDONLY | PG_BINARY);
>
> - if (fd >= 0)
> + if (access(rpath, F_OK) == 0)
>
> What you are looking for here is R_OK, no?
> --
> Michael
>


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Paul Guo <paulguo(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Use access() to check file existence in GetNewRelFileNode().
Date: 2018-05-17 13:18:16
Message-ID: 20180517131816.GE9938@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, May 17, 2018 at 05:23:28PM +0800, Paul Guo wrote:
> F_OK seems to be better than R_OK because we want to check file existence
> (not read permission) before creating the relation file with the path
> later.

Please do not top-post, this breaks the discussion logic of the thread.

Perhaps Tom remembers why things have been done this way in 721e537. At
the end, on second-thoughts, the current coding looks a bit
over-engineered as there is no check for any error codes other than
ENOENT so using only F_OK would be OK. Note that access cannot complain
about EPERM at least on Linux, so you'd want to actually modify this
comment block.

You should also add this patch to the next commit fest, development of
v11 is done and it is a stabilization period now, so no new patches are
merged. Here is where you can register the patch:
https://commitfest.postgresql.org/18/
--
Michael


From: Paul Guo <paulguo(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Use access() to check file existence in GetNewRelFileNode().
Date: 2018-05-18 06:42:08
Message-ID: CABQrizdbarF1NZ7tYbv7R=iM1S5zkAiUG28CuLBfM3jbuSBkpw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg스포츠 토토 사이트SQL

2018-05-17 21:18 GMT+08:00 Michael Paquier <michael(at)paquier(dot)xyz>:

> On Thu, May 17, 2018 at 05:23:28PM +0800, Paul Guo wrote:
> > F_OK seems to be better than R_OK because we want to check file existence
> > (not read permission) before creating the relation file with the path
> > later.
>
> Please do not top-post, this breaks the discussion logic of the thread.
>
> Perhaps Tom remembers why things have been done this way in 721e537. At
> the end, on second-thoughts, the current coding looks a bit
> over-engineered as there is no check for any error codes other than
> ENOENT so using only F_OK would be OK. Note that access cannot complain
> about EPERM at least on Linux, so you'd want to actually modify this
> comment block.

Thanks. Agreed. Attached is the new patch.

> You should also add this patch to the next commit fest, development of
> v11 is done and it is a stabilization period now, so no new patches are
> merged. Here is where you can register the patch:
> https://commitfest.postgresql.org/18/

Submitted.

-Paul

> --
> Michael
>

Attachment Content-Type Size
0001-Use-access-to-check-file-existence-in-GetNewRelFileN.v2.patch application/octet-stream 2.1 KB

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Paul Guo <paulguo(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Use access() to check file existence in GetNewRelFileNode().
Date: 2018-05-18 14:04:14
Message-ID: 20180518140414.GB1384@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, May 18, 2018 at 02:42:08PM +0800, Paul Guo wrote:
> 2018-05-17 21:18 GMT+08:00 Michael Paquier <michael(at)paquier(dot)xyz>:
>> You should also add this patch to the next commit fest, development of
>> v11 is done and it is a stabilization period now, so no new patches are
>> merged. Here is where you can register the patch:
>> https://commitfest.postgresql.org/18/
>
> Submitted.

Thanks.
--
Michael


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>, Paul Guo <paulguo(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Use access() to check file existence in GetNewRelFileNode().
Date: 2018-07-06 20:52:14
Message-ID: ed76ef1e-da06-397b-397b-2e97f4d86346@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg토토 베이SQL

On 18.05.18 16:04, Michael Paquier wrote:
> On Fri, May 18, 2018 at 02:42:08PM +0800, Paul Guo wrote:
>> 2018-05-17 21:18 GMT+08:00 Michael Paquier <michael(at)paquier(dot)xyz>:
>>> You should also add this patch to the next commit fest, development of
>>> v11 is done and it is a stabilization period now, so no new patches are
>>> merged. Here is where you can register the patch:
>>> https://commitfest.postgresql.org/18/
>>
>> Submitted.

This patch looks sensible to me. We also use access() elsewhere in the
backend to test for file existence.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Paul Guo <paulguo(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Use access() to check file existence in GetNewRelFileNode().
Date: 2018-07-08 10:00:46
Message-ID: 20180708100046.GC1467@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jul 06, 2018 at 10:52:14PM +0200, Peter Eisentraut wrote:
> This patch looks sensible to me. We also use access() elsewhere in the
> backend to test for file existence.

Yes, the patch made sense when I looked at it, and it still does, so
committed.
--
Michael