Skip to content

Commit 83e5763

Browse files
committed
pg_createsubscriber: Remove some code bloat in the atexit() callback
This commit adjusts some code added by e117cfb in the atexit() callback of pg_createsubscriber.c, in charge of performing post-failure cleanup actions. The code loops over all the databases specified, and it is changed here to rely on a single LogicalRepInfo for each database rather than always using LogicalRepInfos, simplifying its logic. Author: Peter Smith <smithpb2250@gmail.com> Discussion: https://postgr.es/m/CAHut+PtdBSVi4iH7BObDVwDNVwOpn+H3fezOBdSTtENx+rhNMw@mail.gmail.com
1 parent 771ba90 commit 83e5763

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/bin/pg_basebackup/pg_createsubscriber.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,19 @@ cleanup_objects_atexit(void)
184184

185185
for (int i = 0; i < num_dbs; i++)
186186
{
187-
if (dbinfos.dbinfo[i].made_publication || dbinfos.dbinfo[i].made_replslot)
187+
struct LogicalRepInfo *dbinfo = &dbinfos.dbinfo[i];
188+
189+
if (dbinfo->made_publication || dbinfo->made_replslot)
188190
{
189191
PGconn *conn;
190192

191-
conn = connect_database(dbinfos.dbinfo[i].pubconninfo, false);
193+
conn = connect_database(dbinfo->pubconninfo, false);
192194
if (conn != NULL)
193195
{
194-
if (dbinfos.dbinfo[i].made_publication)
195-
drop_publication(conn, &dbinfos.dbinfo[i]);
196-
if (dbinfos.dbinfo[i].made_replslot)
197-
drop_replication_slot(conn, &dbinfos.dbinfo[i], dbinfos.dbinfo[i].replslotname);
196+
if (dbinfo->made_publication)
197+
drop_publication(conn, dbinfo);
198+
if (dbinfo->made_replslot)
199+
drop_replication_slot(conn, dbinfo, dbinfo->replslotname);
198200
disconnect_database(conn, false);
199201
}
200202
else
@@ -204,18 +206,18 @@ cleanup_objects_atexit(void)
204206
* that some objects were left on primary and should be
205207
* removed before trying again.
206208
*/
207-
if (dbinfos.dbinfo[i].made_publication)
209+
if (dbinfo->made_publication)
208210
{
209211
pg_log_warning("publication \"%s\" created in database \"%s\" on primary was left behind",
210-
dbinfos.dbinfo[i].pubname,
211-
dbinfos.dbinfo[i].dbname);
212+
dbinfo->pubname,
213+
dbinfo->dbname);
212214
pg_log_warning_hint("Drop this publication before trying again.");
213215
}
214-
if (dbinfos.dbinfo[i].made_replslot)
216+
if (dbinfo->made_replslot)
215217
{
216218
pg_log_warning("replication slot \"%s\" created in database \"%s\" on primary was left behind",
217-
dbinfos.dbinfo[i].replslotname,
218-
dbinfos.dbinfo[i].dbname);
219+
dbinfo->replslotname,
220+
dbinfo->dbname);
219221
pg_log_warning_hint("Drop this replication slot soon to avoid retention of WAL files.");
220222
}
221223
}

0 commit comments

Comments
 (0)