Re: pg_replication_origin_drop API potential race condition

2021-02-09 Thread Amit Kapila
On Tue, Feb 9, 2021 at 5:53 PM Alvaro Herrera wrote: > > On 2021-Feb-09, Amit Kapila wrote: > > > On Tue, Feb 9, 2021 at 4:16 PM Alvaro Herrera > > wrote: > > > > By all means let's get the bug fixed. > > > > I am planning to push this in HEAD only as there is no user reported > > problem and th

Re: pg_replication_origin_drop API potential race condition

2021-02-09 Thread Alvaro Herrera
On 2021-Feb-09, Amit Kapila wrote: > On Tue, Feb 9, 2021 at 4:16 PM Alvaro Herrera wrote: > > By all means let's get the bug fixed. > > I am planning to push this in HEAD only as there is no user reported > problem and this is actually more about giving correct information to > the user rather

Re: pg_replication_origin_drop API potential race condition

2021-02-09 Thread Amit Kapila
On Tue, Feb 9, 2021 at 4:16 PM Alvaro Herrera wrote: > > On 2021-Feb-09, Amit Kapila wrote: > > > Now, we can do this optimization if we want but I am not sure if > > origin_drop would be a frequent enough operation that we add such an > > optimization. For now, I have added a note in the comments

Re: pg_replication_origin_drop API potential race condition

2021-02-09 Thread Alvaro Herrera
On 2021-Feb-09, Amit Kapila wrote: > > IIUC, you are suggesting to use lock for the particular origin instead > > of locking the corresponding catalog table in functions > > pg_replication_origin_advance and replorigin_drop_by_name. Right. > I think it won't be that straightforward as we don't h

Re: pg_replication_origin_drop API potential race condition

2021-02-08 Thread Amit Kapila
On Tue, Feb 9, 2021 at 9:27 AM Amit Kapila wrote: > > On Mon, Feb 8, 2021 at 11:30 PM Alvaro Herrera > wrote: > > > > > +void > > > +replorigin_drop_by_name(char *name, bool missing_ok, bool nowait) > > > +{ > > > + RepOriginId roident; > > > + Relationrel; > > > + > > > + As

Re: pg_replication_origin_drop API potential race condition

2021-02-08 Thread Amit Kapila
On Mon, Feb 8, 2021 at 11:30 PM Alvaro Herrera wrote: > > > +void > > +replorigin_drop_by_name(char *name, bool missing_ok, bool nowait) > > +{ > > + RepOriginId roident; > > + Relationrel; > > + > > + Assert(IsTransactionState()); > > + > > + /* > > + * To interlock a

Re: pg_replication_origin_drop API potential race condition

2021-02-08 Thread Alvaro Herrera
> +void > +replorigin_drop_by_name(char *name, bool missing_ok, bool nowait) > +{ > + RepOriginId roident; > + Relationrel; > + > + Assert(IsTransactionState()); > + > + /* > + * To interlock against concurrent drops, we hold ExclusiveLock on > + * pg_replication_o

Re: pg_replication_origin_drop API potential race condition

2021-02-08 Thread Euler Taveira
On Mon, Feb 8, 2021, at 3:23 AM, Amit Kapila wrote: > Fixed the problem as mentioned above in the attached. This new version looks good to me. -- Euler Taveira EDB https://www.enterprisedb.com/

Re: pg_replication_origin_drop API potential race condition

2021-02-07 Thread Amit Kapila
On Sat, Feb 6, 2021 at 5:47 PM Amit Kapila wrote: > > On Sat, Feb 6, 2021 at 3:26 PM Petr Jelinek wrote: > > > > On 06/02/2021 07:29, Amit Kapila wrote: > > > On Fri, Feb 5, 2021 at 6:45 PM Euler Taveira wrote: > > >> - replorigin_drop(roident, true); > > >> + replorigin_drop_by_name(name, false

Re: pg_replication_origin_drop API potential race condition

2021-02-06 Thread Amit Kapila
On Sat, Feb 6, 2021 at 3:26 PM Petr Jelinek wrote: > > On 06/02/2021 07:29, Amit Kapila wrote: > > On Fri, Feb 5, 2021 at 6:45 PM Euler Taveira wrote: > >> - replorigin_drop(roident, true); > >> + replorigin_drop_by_name(name, false /* missing_ok */ , true /* nowait */ > >> ); > >> > >> A modern

Re: pg_replication_origin_drop API potential race condition

2021-02-06 Thread Petr Jelinek
On 06/02/2021 07:29, Amit Kapila wrote: On Fri, Feb 5, 2021 at 6:45 PM Euler Taveira wrote: On Fri, Feb 5, 2021, at 4:01 AM, Amit Kapila wrote: I am not completely whether we should retire replorigin_drop or just keep it for backward compatibility? What do you think? Anybody else has any opini

Re: pg_replication_origin_drop API potential race condition

2021-02-05 Thread Amit Kapila
On Fri, Feb 5, 2021 at 6:45 PM Euler Taveira wrote: > > On Fri, Feb 5, 2021, at 4:01 AM, Amit Kapila wrote: > > I am not completely whether we should retire replorigin_drop or just > keep it for backward compatibility? What do you think? Anybody else > has any opinion? > > We could certainly keep

Re: pg_replication_origin_drop API potential race condition

2021-02-05 Thread Euler Taveira
On Fri, Feb 5, 2021, at 4:01 AM, Amit Kapila wrote: > I am not completely whether we should retire replorigin_drop or just > keep it for backward compatibility? What do you think? Anybody else > has any opinion? We could certainly keep some code for backward compatibility, however, we have to consi

Re: pg_replication_origin_drop API potential race condition

2021-02-05 Thread Amit Kapila
On Fri, Feb 5, 2021 at 1:50 PM Peter Smith wrote: > > On Fri, Feb 5, 2021 at 6:02 PM Amit Kapila wrote: > > > > On Fri, Feb 5, 2021 at 9:46 AM Peter Smith wrote: > > > > > > PSA patch updated per above suggestions. > > > > > > > Thanks, I have tested your patch and before the patch, I was gettin

Re: pg_replication_origin_drop API potential race condition

2021-02-05 Thread Peter Smith
On Fri, Feb 5, 2021 at 6:02 PM Amit Kapila wrote: > > On Fri, Feb 5, 2021 at 9:46 AM Peter Smith wrote: > > > > PSA patch updated per above suggestions. > > > > Thanks, I have tested your patch and before the patch, I was getting > errors like "tuple concurrently deleted" or "cache lookup failed

Re: pg_replication_origin_drop API potential race condition

2021-02-04 Thread Amit Kapila
On Fri, Feb 5, 2021 at 9:46 AM Peter Smith wrote: > > PSA patch updated per above suggestions. > Thanks, I have tested your patch and before the patch, I was getting errors like "tuple concurrently deleted" or "cache lookup failed for replication origin with oid 1" and after the patch, I am getti

Re: pg_replication_origin_drop API potential race condition

2021-02-04 Thread Peter Smith
On Thu, Feb 4, 2021 at 9:20 PM Amit Kapila wrote: > > On Thu, Feb 4, 2021 at 1:31 PM Peter Smith wrote: > > > > PSA a patch which I think implements what we are talking about. > > > > This doesn't seem correct to me. Have you tested that the patch > resolves the problem reported originally? Becau

Re: pg_replication_origin_drop API potential race condition

2021-02-04 Thread Amit Kapila
On Thu, Feb 4, 2021 at 1:31 PM Peter Smith wrote: > > PSA a patch which I think implements what we are talking about. > This doesn't seem correct to me. Have you tested that the patch resolves the problem reported originally? Because the lockmode (RowExclusiveLock) you have used in the patch will

Re: pg_replication_origin_drop API potential race condition

2021-02-04 Thread Peter Smith
On Thu, Feb 4, 2021 at 4:43 PM Amit Kapila wrote: > > On Thu, Feb 4, 2021 at 9:57 AM Peter Smith wrote: > > > > On Wed, Feb 3, 2021 at 11:17 PM Amit Kapila wrote: > > > > > > > > How about if we call replorigin_by_name() inside replorigin_drop after > > > acquiring the lock? Wouldn't that close

Re: pg_replication_origin_drop API potential race condition

2021-02-03 Thread Amit Kapila
On Thu, Feb 4, 2021 at 9:57 AM Peter Smith wrote: > > On Wed, Feb 3, 2021 at 11:17 PM Amit Kapila wrote: > > > > > How about if we call replorigin_by_name() inside replorigin_drop after > > acquiring the lock? Wouldn't that close this race condition? We are > > doing something similar for pg_repl

Re: pg_replication_origin_drop API potential race condition

2021-02-03 Thread Peter Smith
On Wed, Feb 3, 2021 at 11:17 PM Amit Kapila wrote: > > How about if we call replorigin_by_name() inside replorigin_drop after > acquiring the lock? Wouldn't that close this race condition? We are > doing something similar for pg_replication_origin_advance(). > Yes, that seems ok. I wonder if it

Re: pg_replication_origin_drop API potential race condition

2021-02-03 Thread Amit Kapila
On Wed, Jan 27, 2021 at 4:58 AM Peter Smith wrote: > > Hi Hackers. > > As discovered elsewhere [ak0125] there is a potential race condition > in the pg_replication_origin_drop API > > The current code of pg_replication_origin_drop looks like: > > roident = replorigin_by_name(name, false); > A