Lists: | pgsql-hackers |
---|
From: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Use atexit() in initdb and pg_basebackup |
Date: | 2018-12-29 15:12:39 |
Message-ID: | [email protected] |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Lists: | pgsql-hackers |
initdb and pg_basebackup can use atexit() to register cleanup actions
instead of requiring the use of custom exit_nicely() etc. Patches attached.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachment | Content-Type | Size |
---|---|---|
0001-pg_basebackup-Use-atexit.patch | text/plain | 23.4 KB |
0002-initdb-Use-atexit.patch | text/plain | 9.5 KB |
From: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Use atexit() in initdb and pg_basebackup |
Date: | 2019-01-04 19:35:51 |
Message-ID: | [email protected] |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2018-Dec-29, Peter Eisentraut wrote:
> @@ -387,6 +388,7 @@ StreamLog(void)
> if (!conn)
> /* Error message already written in GetConnection() */
> return;
> + atexit(disconnect_atexit);
>
> if (!CheckServerVersionForStreaming(conn))
> {
Seems you're registering the atexit cb twice here; you should only do so
in the first "!conn" block.
It would be nicer to be able to call atexit() in GetConnection() instead
of at each callsite, but that would require a place to save each conn
struct into, which is probably more work than warranted.
> @@ -3438,5 +3437,8 @@ main(int argc, char *argv[])
>
> destroyPQExpBuffer(start_db_cmd);
>
> + /* prevent cleanup */
> + made_new_pgdata = found_existing_pgdata = made_new_xlogdir = found_existing_xlogdir = false;
> +
> return 0;
> }
This is a bit ugly, but meh.
Other than the first point, LGTM.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From: | Michael Paquier <michael(at)paquier(dot)xyz> |
---|---|
To: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
Cc: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Use atexit() in initdb and pg_basebackup |
Date: | 2019-01-05 01:23:36 |
Message-ID: | [email protected] |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Fri, Jan 04, 2019 at 04:35:51PM -0300, Alvaro Herrera wrote:
> On 2018-Dec-29, Peter Eisentraut wrote:
>> @@ -3438,5 +3437,8 @@ main(int argc, char *argv[])
>>
>> destroyPQExpBuffer(start_db_cmd);
>>
>> + /* prevent cleanup */
>> + made_new_pgdata = found_existing_pgdata = made_new_xlogdir = found_existing_xlogdir = false;
>> +
>> return 0;
>> }
>
> This is a bit ugly, but meh.
>
> Other than the first point, LGTM.
Re-meuh (French version). That's partially a problem of this patch
because all those flags get reset. I think that it would be cleaner
to replace all those boolean flags with just a simple bits16 or such,
making the flag cleanup reset way cleaner, and less error-prone if
more flag types are added in the future.
--
Michael
From: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Use atexit() in initdb and pg_basebackup |
Date: | 2019-01-05 14:44:11 |
Message-ID: | [email protected] |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 04/01/2019 20:35, Alvaro Herrera wrote:
> Seems you're registering the atexit cb twice here; you should only do so
> in the first "!conn" block.
OK, fixed.
>> @@ -3438,5 +3437,8 @@ main(int argc, char *argv[])
>>
>> destroyPQExpBuffer(start_db_cmd);
>>
>> + /* prevent cleanup */
>> + made_new_pgdata = found_existing_pgdata = made_new_xlogdir = found_existing_xlogdir = false;
>> +
>> return 0;
>> }
>
> This is a bit ugly, but meh.
Yeah. Actually, we already have a solution of this in pg_basebackup,
with a bool success variable. I rewrote it like that. At least it's
better for uniformity.
I also added an atexit() conversion in isolationtester. It's mostly the
same thing.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachment | Content-Type | Size |
---|---|---|
v2-0001-pg_basebackup-Use-atexit.patch | text/plain | 23.1 KB |
v2-0002-initdb-Use-atexit.patch | text/plain | 9.8 KB |
v2-0003-isolationtester-Use-atexit.patch | text/plain | 5.2 KB |
From: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Use atexit() in initdb and pg_basebackup |
Date: | 2019-01-05 15:42:47 |
Message-ID: | [email protected] |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2019-Jan-05, Peter Eisentraut wrote:
> On 04/01/2019 20:35, Alvaro Herrera wrote:
> >> + /* prevent cleanup */
> >> + made_new_pgdata = found_existing_pgdata = made_new_xlogdir = found_existing_xlogdir = false;
> >> +
> >> return 0;
> >> }
> >
> > This is a bit ugly, but meh.
>
> Yeah. Actually, we already have a solution of this in pg_basebackup,
> with a bool success variable. I rewrote it like that. At least it's
> better for uniformity.
Ah, yeah, much better, LGTM.
> I also added an atexit() conversion in isolationtester. It's mostly the
> same thing.
LGTM in a quick eyeball.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Use atexit() in initdb and pg_basebackup |
Date: | 2019-01-07 15:37:28 |
Message-ID: | [email protected] |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 05/01/2019 16:42, Alvaro Herrera wrote:
>> Yeah. Actually, we already have a solution of this in pg_basebackup,
>> with a bool success variable. I rewrote it like that. At least it's
>> better for uniformity.
>
> Ah, yeah, much better, LGTM.
>
>> I also added an atexit() conversion in isolationtester. It's mostly the
>> same thing.
>
> LGTM in a quick eyeball.
committed
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services