Skip to content

Commit 8fc8b65

Browse files
committed
Some comments about our new atexit handling.
1 parent b6b6a8b commit 8fc8b65

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

bin/pg_repack.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ static char *
243243
utoa(unsigned int value, char *buffer)
244244
{
245245
sprintf(buffer, "%u", value);
246+
/* XXX: originally, we would just return buffer here without
247+
* the pgut_strdup(). But repack_cleanup_callback() seems to
248+
* depend on getting back a freshly strdup'd copy of buffer,
249+
* not sure why. So now we are leaking a tiny bit of memory
250+
* with each utoa() call.
251+
*/
246252
return pgut_strdup(buffer);
247253
}
248254

@@ -900,6 +906,13 @@ rebuild_indexes(const repack_table *table)
900906

901907
ret = select(max_fd + 1, &input_mask, NULL, NULL, &timeout);
902908
#endif
909+
/* XXX: the errno != EINTR check means we won't bail
910+
* out on SIGINT. We should probably just remove this
911+
* check, though it seems we also need to fix up
912+
* the on_interrupt handling for workers' index
913+
* builds (those PGconns don't seem to have c->cancel
914+
* set, so we don't cancel the in-progress builds).
915+
*/
903916
if (ret < 0 && errno != EINTR)
904917
elog(ERROR, "poll() failed: %d, %d", ret, errno);
905918

@@ -1703,8 +1716,12 @@ repack_cleanup_callback(bool fatal, void *userdata)
17031716
if(fatal)
17041717
{
17051718
params[0] = utoa(target_table, buffer);
1706-
params[1] = utoa(temp_obj_num, buffer);
1719+
params[1] = utoa(temp_obj_num, buffer);
17071720

1721+
/* testing PQstatus() of connection and conn2, as we do
1722+
* in repack_cleanup(), doesn't seem to work here,
1723+
* so just use an unconditional reconnect().
1724+
*/
17081725
reconnect(ERROR);
17091726
command("SELECT repack.repack_drop($1, $2)", 2, params);
17101727
temp_obj_num = 0; /* reset temporary object counter after cleanup */

lib/repack.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,11 @@ repack_drop(PG_FUNCTION_ARGS)
944944
/* connect to SPI manager */
945945
repack_init();
946946

947-
/* drop log table */
948-
if(numobj > 0)
947+
/* drop log table: must be done before dropping the pk type,
948+
* since the log table is dependent on the pk type. (That's
949+
* why we check numobj > 1 here.)
950+
*/
951+
if (numobj > 1)
949952
{
950953
execute_with_format(
951954
SPI_OK_UTILITY,
@@ -955,7 +958,7 @@ repack_drop(PG_FUNCTION_ARGS)
955958
}
956959

957960
/* drop type for pk type */
958-
if(numobj > 0)
961+
if (numobj > 0)
959962
{
960963
execute_with_format(
961964
SPI_OK_UTILITY,
@@ -968,7 +971,7 @@ repack_drop(PG_FUNCTION_ARGS)
968971
* drop repack trigger: We have already dropped the trigger in normal
969972
* cases, but it can be left on error.
970973
*/
971-
if(numobj > 0)
974+
if (numobj > 0)
972975
{
973976
execute_with_format(
974977
SPI_OK_UTILITY,
@@ -991,7 +994,7 @@ repack_drop(PG_FUNCTION_ARGS)
991994
#endif
992995

993996
/* drop temp table */
994-
if(numobj > 0)
997+
if (numobj > 0)
995998
{
996999
execute_with_format(
9971000
SPI_OK_UTILITY,

0 commit comments

Comments
 (0)