aboutsummaryrefslogtreecommitdiff
path: root/src/include/fe_utils/parallel_slot.h
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2021-03-11 13:17:46 -0500
committerRobert Haas <rhaas@postgresql.org>2021-03-11 13:17:46 -0500
commitf71519e545a34ece0a27c8bb1a2b6e197d323163 (patch)
tree63c81c1ec99bcc7e7f616dc960a53004c7285e65 /src/include/fe_utils/parallel_slot.h
parent2c0cefcd18161549e9e8b103f46c0f65fca84d99 (diff)
downloadpostgresql-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/include/fe_utils/parallel_slot.h')
-rw-r--r--src/include/fe_utils/parallel_slot.h27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/include/fe_utils/parallel_slot.h b/src/include/fe_utils/parallel_slot.h
index 8902f8d4f48..b7e2b0a29b8 100644
--- a/src/include/fe_utils/parallel_slot.h
+++ b/src/include/fe_utils/parallel_slot.h
@@ -21,7 +21,7 @@ typedef bool (*ParallelSlotResultHandler) (PGresult *res, PGconn *conn,
typedef struct ParallelSlot
{
PGconn *connection; /* One connection */
- bool isFree; /* Is it known to be idle? */
+ bool inUse; /* Is the slot being used? */
/*
* Prior to issuing a command or query on 'connection', a handler callback
@@ -33,6 +33,16 @@ typedef struct ParallelSlot
void *handler_context;
} ParallelSlot;
+typedef struct ParallelSlotArray
+{
+ int numslots;
+ ConnParams *cparams;
+ const char *progname;
+ bool echo;
+ const char *initcmd;
+ ParallelSlot slots[FLEXIBLE_ARRAY_MEMBER];
+} ParallelSlotArray;
+
static inline void
ParallelSlotSetHandler(ParallelSlot *slot, ParallelSlotResultHandler handler,
void *context)
@@ -48,15 +58,18 @@ ParallelSlotClearHandler(ParallelSlot *slot)
slot->handler_context = NULL;
}
-extern ParallelSlot *ParallelSlotsGetIdle(ParallelSlot *slots, int numslots);
+extern ParallelSlot *ParallelSlotsGetIdle(ParallelSlotArray *slots,
+ const char *dbname);
+
+extern ParallelSlotArray *ParallelSlotsSetup(int numslots, ConnParams *cparams,
+ const char *progname, bool echo,
+ const char *initcmd);
-extern ParallelSlot *ParallelSlotsSetup(const ConnParams *cparams,
- const char *progname, bool echo,
- PGconn *conn, int numslots);
+extern void ParallelSlotsAdoptConn(ParallelSlotArray *sa, PGconn *conn);
-extern void ParallelSlotsTerminate(ParallelSlot *slots, int numslots);
+extern void ParallelSlotsTerminate(ParallelSlotArray *sa);
-extern bool ParallelSlotsWaitCompletion(ParallelSlot *slots, int numslots);
+extern bool ParallelSlotsWaitCompletion(ParallelSlotArray *sa);
extern bool TableCommandResultHandler(PGresult *res, PGconn *conn,
void *context);