diff options
author | Robert Haas <rhaas@postgresql.org> | 2021-03-11 13:17:46 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2021-03-11 13:17:46 -0500 |
commit | f71519e545a34ece0a27c8bb1a2b6e197d323163 (patch) | |
tree | 63c81c1ec99bcc7e7f616dc960a53004c7285e65 /src/bin/scripts/reindexdb.c | |
parent | 2c0cefcd18161549e9e8b103f46c0f65fca84d99 (diff) | |
download | postgresql-f71519e545a34ece0a27c8bb1a2b6e197d323163.tar.gz postgresql-f71519e545a34ece0a27c8bb1a2b6e197d323163.zip |
Refactor and generalize the ParallelSlot machinery.
Create a wrapper object, ParallelSlotArray, to encapsulate the
number of slots and the slot array itself, plus some other relevant
bits of information. This reduces the number of parameters we have
to pass around all over the place.
Allow for a ParallelSlotArray to contain slots connected to
different databases within a single cluster. The current clients
of this mechanism don't need this, but it is expected to be used
by future patches.
Defer connecting to databases until we actually need the connection
for something. This is a slight behavior change for vacuumdb and
reindexdb. If you specify a number of jobs that is larger than the
number of objects, the extra connections will now not be used.
But, on the other hand, if you specify a number of jobs that is
so large that it's going to fail, the failure would previously have
happened before any operations were actually started, and now it
won't.
Mark Dilger, reviewed by me.
Discussion: http://postgr.es/m/12ED3DA8-25F0-4B68-937D-D907CFBF08E7@enterprisedb.com
Discussion: http://postgr.es/m/BA592F2D-F928-46FF-9516-2B827F067F57@enterprisedb.com
Diffstat (limited to 'src/bin/scripts/reindexdb.c')
-rw-r--r-- | src/bin/scripts/reindexdb.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index cf281762431..fc0681538a9 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -36,7 +36,7 @@ static SimpleStringList *get_parallel_object_list(PGconn *conn, ReindexType type, SimpleStringList *user_list, bool echo); -static void reindex_one_database(const ConnParams *cparams, ReindexType type, +static void reindex_one_database(ConnParams *cparams, ReindexType type, SimpleStringList *user_list, const char *progname, bool echo, bool verbose, bool concurrently, @@ -330,7 +330,7 @@ main(int argc, char *argv[]) } static void -reindex_one_database(const ConnParams *cparams, ReindexType type, +reindex_one_database(ConnParams *cparams, ReindexType type, SimpleStringList *user_list, const char *progname, bool echo, bool verbose, bool concurrently, int concurrentCons, @@ -341,7 +341,7 @@ reindex_one_database(const ConnParams *cparams, ReindexType type, bool parallel = concurrentCons > 1; SimpleStringList *process_list = user_list; ReindexType process_type = type; - ParallelSlot *slots; + ParallelSlotArray *sa; bool failed = false; int items_count = 0; @@ -461,7 +461,8 @@ reindex_one_database(const ConnParams *cparams, ReindexType type, Assert(process_list != NULL); - slots = ParallelSlotsSetup(cparams, progname, echo, conn, concurrentCons); + sa = ParallelSlotsSetup(concurrentCons, cparams, progname, echo, NULL); + ParallelSlotsAdoptConn(sa, conn); cell = process_list->head; do @@ -475,7 +476,7 @@ reindex_one_database(const ConnParams *cparams, ReindexType type, goto finish; } - free_slot = ParallelSlotsGetIdle(slots, concurrentCons); + free_slot = ParallelSlotsGetIdle(sa, NULL); if (!free_slot) { failed = true; @@ -489,7 +490,7 @@ reindex_one_database(const ConnParams *cparams, ReindexType type, cell = cell->next; } while (cell != NULL); - if (!ParallelSlotsWaitCompletion(slots, concurrentCons)) + if (!ParallelSlotsWaitCompletion(sa)) failed = true; finish: @@ -499,8 +500,8 @@ finish: pg_free(process_list); } - ParallelSlotsTerminate(slots, concurrentCons); - pfree(slots); + ParallelSlotsTerminate(sa); + pfree(sa); if (failed) exit(1); |