diff options
author | Robert Haas <rhaas@postgresql.org> | 2021-02-05 16:08:45 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2021-02-05 16:08:45 -0500 |
commit | 418611c84d004f45d92bcaa3f8e100385d96cd41 (patch) | |
tree | fc7727b5a72d57a5f1bc655e023d5ae51d6cf1ea /src/include/fe_utils/parallel_slot.h | |
parent | e955bd4b6c2bcdbd253837f6cf4c7520b98e69d4 (diff) | |
download | postgresql-418611c84d004f45d92bcaa3f8e100385d96cd41.tar.gz postgresql-418611c84d004f45d92bcaa3f8e100385d96cd41.zip |
Generalize parallel slot result handling.
Instead of having a hard-coded behavior that we ignore missing
tables and report all other errors, let the caller decide what
to do by setting a callback.
Mark Dilger, reviewed and somewhat revised by me. The larger patch
series of which this is a part has also had review from Peter
Geoghegan, Andres Freund, Álvaro Herrera, Michael Paquier, and Amul
Sul, but I don't know whether any of them have reviewed this bit
specifically.
Discussion: http://postgr.es/m/12ED3DA8-25F0-4B68-937D-D907CFBF08E7@enterprisedb.com
Discussion: http://postgr.es/m/5F743835-3399-419C-8324-2D424237E999@enterprisedb.com
Discussion: http://postgr.es/m/70655DF3-33CE-4527-9A4D-DDEB582B6BA0@enterprisedb.com
Diffstat (limited to 'src/include/fe_utils/parallel_slot.h')
-rw-r--r-- | src/include/fe_utils/parallel_slot.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/include/fe_utils/parallel_slot.h b/src/include/fe_utils/parallel_slot.h index 99eeb3328d6..8902f8d4f48 100644 --- a/src/include/fe_utils/parallel_slot.h +++ b/src/include/fe_utils/parallel_slot.h @@ -15,12 +15,39 @@ #include "fe_utils/connect_utils.h" #include "libpq-fe.h" +typedef bool (*ParallelSlotResultHandler) (PGresult *res, PGconn *conn, + void *context); + typedef struct ParallelSlot { PGconn *connection; /* One connection */ bool isFree; /* Is it known to be idle? */ + + /* + * Prior to issuing a command or query on 'connection', a handler callback + * function may optionally be registered to be invoked to process the + * results, and context information may optionally be registered for use + * by the handler. If unset, these fields should be NULL. + */ + ParallelSlotResultHandler handler; + void *handler_context; } ParallelSlot; +static inline void +ParallelSlotSetHandler(ParallelSlot *slot, ParallelSlotResultHandler handler, + void *context) +{ + slot->handler = handler; + slot->handler_context = context; +} + +static inline void +ParallelSlotClearHandler(ParallelSlot *slot) +{ + slot->handler = NULL; + slot->handler_context = NULL; +} + extern ParallelSlot *ParallelSlotsGetIdle(ParallelSlot *slots, int numslots); extern ParallelSlot *ParallelSlotsSetup(const ConnParams *cparams, @@ -31,5 +58,7 @@ extern void ParallelSlotsTerminate(ParallelSlot *slots, int numslots); extern bool ParallelSlotsWaitCompletion(ParallelSlot *slots, int numslots); +extern bool TableCommandResultHandler(PGresult *res, PGconn *conn, + void *context); #endif /* PARALLEL_SLOT_H */ |