Age Owner TLA Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * parallel_slot.h
4 : * Parallel support for bin/scripts/
5 : *
6 : * Copyright (c) 2003-2023, PostgreSQL Global Development Group
7 : *
8 : * src/include/fe_utils/parallel_slot.h
9 : *
10 : *-------------------------------------------------------------------------
11 : */
12 : #ifndef PARALLEL_SLOT_H
13 : #define PARALLEL_SLOT_H
14 :
15 : #include "fe_utils/connect_utils.h"
16 : #include "libpq-fe.h"
17 :
18 : typedef bool (*ParallelSlotResultHandler) (PGresult *res, PGconn *conn,
19 : void *context);
20 :
21 : typedef struct ParallelSlot
22 : {
23 : PGconn *connection; /* One connection */
24 : bool inUse; /* Is the slot being used? */
25 :
26 : /*
27 : * Prior to issuing a command or query on 'connection', a handler callback
28 : * function may optionally be registered to be invoked to process the
29 : * results, and context information may optionally be registered for use
30 : * by the handler. If unset, these fields should be NULL.
31 : */
32 : ParallelSlotResultHandler handler;
33 : void *handler_context;
34 : } ParallelSlot;
35 :
36 : typedef struct ParallelSlotArray
37 : {
38 : int numslots;
39 : ConnParams *cparams;
40 : const char *progname;
41 : bool echo;
42 : const char *initcmd;
43 : ParallelSlot slots[FLEXIBLE_ARRAY_MEMBER];
44 : } ParallelSlotArray;
45 :
46 : static inline void
793 rhaas 47 CBC 8432 : ParallelSlotSetHandler(ParallelSlot *slot, ParallelSlotResultHandler handler,
48 : void *context)
49 : {
50 8432 : slot->handler = handler;
51 8432 : slot->handler_context = context;
52 8432 : }
53 :
54 : static inline void
55 8426 : ParallelSlotClearHandler(ParallelSlot *slot)
56 : {
57 8426 : slot->handler = NULL;
58 8426 : slot->handler_context = NULL;
59 8426 : }
60 :
61 : extern ParallelSlot *ParallelSlotsGetIdle(ParallelSlotArray *sa,
62 : const char *dbname);
63 :
64 : extern ParallelSlotArray *ParallelSlotsSetup(int numslots, ConnParams *cparams,
65 : const char *progname, bool echo,
66 : const char *initcmd);
67 :
68 : extern void ParallelSlotsAdoptConn(ParallelSlotArray *sa, PGconn *conn);
69 :
70 : extern void ParallelSlotsTerminate(ParallelSlotArray *sa);
71 :
72 : extern bool ParallelSlotsWaitCompletion(ParallelSlotArray *sa);
73 :
74 : extern bool TableCommandResultHandler(PGresult *res, PGconn *conn,
75 : void *context);
76 :
77 : #endif /* PARALLEL_SLOT_H */
|