Re: Possible race condition in pg_mkdir_p()? - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Possible race condition in pg_mkdir_p()?
Date
Msg-id 20190730080434.GA1644@paquier.xyz
Whole thread Raw
In response to Re: Possible race condition in pg_mkdir_p()?  (Ning Yu <nyu@pivotal.io>)
Responses Re: Possible race condition in pg_mkdir_p()?  (Ning Yu <nyu@pivotal.io>)
List pgsql-hackers
On Tue, Jul 23, 2019 at 02:54:20PM +0800, Ning Yu wrote:
> MakePGDirectory() is also called in TablespaceCreateDbspace(), EEXIST is
> considered as non-error for parent directories, however as it considers
> EEXIST as a failure for the last level of the path so the logic is
> still correct,

So the complains here are about two things:
- In some code paths calling mkdir, we don't care about the fact that
EEXIST can happen for something else than a folder.  This could be a
problem if we have conflicts in the backend related to the naming of
the files/folders created.  I find a bit surprising to not perform
the sanity checks in MakePGDirectory() in your patch.  What of all the
existing callers of this routine?
- pg_mkdir_p is pretty bad at detecting problems with concurrent
creation of parent directories, leading to random failures where these
should not happen.

I may be missing something, but your patch does not actually fix
problem 2, no?  Trying to do an initdb with a set of N folders using
the same parent folders not created still results in random failures.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: POC: Cleaning up orphaned files using undo logs
Next
From: Dilip Kumar
Date:
Subject: Re: POC: Cleaning up orphaned files using undo logs