From ebd78b3a71c99ae36d934f844c36296407e3e23e Mon Sep 17 00:00:00 2001 From: Corey Huinker Date: Wed, 19 Nov 2025 19:50:05 -0500 Subject: [PATCH v3 5/5] handle ParallelSlotGetIdle() inside run_vacuum_command() --- src/bin/scripts/vacuuming.c | 41 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/bin/scripts/vacuuming.c b/src/bin/scripts/vacuuming.c index 14d843bed10..5bd7ade62a1 100644 --- a/src/bin/scripts/vacuuming.c +++ b/src/bin/scripts/vacuuming.c @@ -43,7 +43,7 @@ static SimpleStringList *retrieve_objects(PGconn *conn, static void free_retrieved_objects(SimpleStringList *list); static void prepare_vacuum_command(int serverVersion, PQExpBuffer sql, vacuumingOptions *vacopts, const char *table); -static void run_vacuum_command(ParallelSlot *free_slot, const char *sql, +static bool run_vacuum_command(ParallelSlotArray *sa, const char *sql, bool echo, bool dry_run, const char *table); /* @@ -362,7 +362,6 @@ vacuum_one_database(ConnParams *cparams, do { const char *tabname = cell->val; - ParallelSlot *free_slot; if (CancelRequested) { @@ -370,19 +369,14 @@ vacuum_one_database(ConnParams *cparams, goto finish; } - free_slot = ParallelSlotsGetIdle(sa, NULL); - if (!free_slot) + prepare_vacuum_command(serverVersion, &sql, vacopts, tabname); + + if (!run_vacuum_command(sa, sql.data, echo, vacopts->dry_run, tabname)) { ret = EXIT_FAILURE; goto finish; } - prepare_vacuum_command(serverVersion, &sql, - vacopts, tabname); - - run_vacuum_command(free_slot, sql.data, - echo, vacopts->dry_run, tabname); - cell = cell->next; } while (cell != NULL); @@ -396,16 +390,13 @@ vacuum_one_database(ConnParams *cparams, if (vacopts->mode == MODE_VACUUM && vacopts->skip_database_stats) { const char *cmd = "VACUUM (ONLY_DATABASE_STATS);"; - ParallelSlot *free_slot = ParallelSlotsGetIdle(sa, NULL); - if (!free_slot) + if (!run_vacuum_command(sa, cmd, echo, vacopts->dry_run, NULL)) { ret = EXIT_FAILURE; goto finish; } - run_vacuum_command(free_slot, cmd, echo, vacopts->dry_run, NULL); - if (!ParallelSlotsWaitCompletion(sa)) ret = EXIT_FAILURE; /* error already reported by handler */ } @@ -995,24 +986,29 @@ prepare_vacuum_command(int serverVersion, PQExpBuffer sql, * * Any errors during command execution are reported to stderr. */ -static void -run_vacuum_command(ParallelSlot *free_slot, const char *sql, bool echo, +static bool +run_vacuum_command(ParallelSlotArray *sa, const char *sql, bool echo, bool dry_run, const char *table) + { + ParallelSlot *free_slot; bool status; - PGconn *conn = free_slot->connection; + PGconn *conn; if (dry_run) { /* - * Print the command that we would have run in a real run, - * the immediately mark the unused slot as free again. + * Print the command that we would have run in a real run. */ printf("not executed: %s\n", sql); - free_slot->inUse = false; - return; + return true; } + free_slot = ParallelSlotsGetIdle(sa, NULL); + + if (!free_slot) + return false; + /* * Execute the vacuum. All errors are handled in processQueryResult * through ParallelSlotsGetIdle. @@ -1022,6 +1018,7 @@ run_vacuum_command(ParallelSlot *free_slot, const char *sql, bool echo, if (echo) printf("%s\n", sql); + conn = free_slot->connection; status = PQsendQuery(conn, sql) == 1; if (!status) @@ -1037,6 +1034,8 @@ run_vacuum_command(ParallelSlot *free_slot, const char *sql, bool echo, PQdb(conn), PQerrorMessage(conn)); } } + + return true; } /* -- 2.51.1