1
1
#ifndef __MULTIMASTER_H__
2
2
#define __MULTIMASTER_H__
3
3
4
+ #include "postgres.h"
5
+
4
6
#include "bytebuf.h"
5
7
#include "bgwpool.h"
6
8
#include "bkb.h"
7
9
8
- #include "access/clog.h"
9
- #include "pglogical_output/hooks.h"
10
- #include "commands/vacuum.h"
11
- #include "libpq-fe.h"
10
+ #include "storage/lwlock.h"
12
11
13
12
#include "dmq.h"
14
13
#include "mm.h"
15
-
16
- #ifndef DEBUG_LEVEL
17
- #define DEBUG_LEVEL 0
18
- #endif
19
-
20
-
21
- #define MTM_TAG "[MTM] "
22
- #define MTM_ELOG (level ,fmt ,...) elog(level, MTM_TAG fmt, ## __VA_ARGS__)
23
- #define MTM_ERRMSG (fmt ,...) errmsg(MTM_TAG fmt, ## __VA_ARGS__)
24
-
25
- #if DEBUG_LEVEL == 0
26
- #define MTM_LOG1 (fmt , ...) ereport(LOG, \
27
- (errmsg("[MTM] " fmt, ## __VA_ARGS__), \
28
- errhidestmt(true), errhidecontext(true)))
29
-
30
- #define MTM_LOG2 (fmt , ...)
31
- #define MTM_LOG3 (fmt , ...)
32
- #define MTM_LOG4 (fmt , ...)
33
- #elif DEBUG_LEVEL == 1
34
- #define MTM_LOG1 (fmt , ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
35
- #define MTM_LOG2 (fmt , ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
36
- #define MTM_LOG3 (fmt , ...)
37
- #define MTM_LOG4 (fmt , ...)
38
- #elif DEBUG_LEVEL == 2
39
- #define MTM_LOG1 (fmt , ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
40
- #define MTM_LOG2 (fmt , ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
41
- #define MTM_LOG3 (fmt , ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
42
- #define MTM_LOG4 (fmt , ...)
43
- #elif DEBUG_LEVEL >= 3
44
- #define MTM_LOG1 (fmt , ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
45
- #define MTM_LOG2 (fmt , ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
46
- #define MTM_LOG3 (fmt , ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
47
- #define MTM_LOG4 (fmt , ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
48
- #endif
49
-
50
- // #define MTM_TXFINISH 1
51
-
52
- #ifndef MTM_TXFINISH
53
- #define TXFINISH (fmt , ...)
54
- #else
55
- #define TXFINISH (fmt , ...) elog(LOG, MTM_TAG "[TXFINISH] " fmt, ## __VA_ARGS__)
56
- #endif
57
-
58
- // #define MTM_TRACE 1
59
-
60
- #ifndef MTM_TRACE
61
- #define MTM_TXTRACE (tx , event , ...)
62
- #else
63
- #define MTM_TXTRACE (tx , event , ...) \
64
- elog(LOG, MTM_TAG "%s, %lld, %u " event "\n", tx->gid, (long long)MtmGetSystemTime(), MyProcPid, ## __VA_ARGS__)
65
- #endif
14
+ #include "resolver.h"
66
15
67
16
#define MULTIMASTER_NAME "multimaster"
68
17
#define MULTIMASTER_SLOT_PATTERN "mtm_slot_%d"
86
35
#define USEC_TO_MSEC (t ) ((t)/1000)
87
36
#define MSEC_TO_USEC (t ) ((timestamp_t)(t)*1000)
88
37
89
- #define Natts_mtm_ddl_log 2
90
- #define Anum_mtm_ddl_log_issued 1
91
- #define Anum_mtm_ddl_log_query 2
92
-
93
- #define Natts_mtm_trans_state 15
94
- #define Natts_mtm_nodes_state 17
95
- #define Natts_mtm_cluster_state 20
96
38
97
39
typedef ulong64 lsn_t ;
98
40
#define INVALID_LSN InvalidXLogRecPtr
@@ -103,20 +45,6 @@ typedef ulong64 lsn_t;
103
45
104
46
#define MTM_MAX_NODES 16
105
47
106
- typedef enum
107
- {
108
- MtmTxUnknown = (1 <<0 ),
109
- MtmTxNotFound = (1 <<1 ),
110
- MtmTxInProgress = (1 <<2 ),
111
- MtmTxPrepared = (1 <<3 ),
112
- MtmTxPreCommited = (1 <<4 ),
113
- MtmTxPreAborted = (1 <<5 ),
114
- MtmTxCommited = (1 <<6 ),
115
- MtmTxAborted = (1 <<7 )
116
- } MtmTxState ;
117
-
118
- typedef int MtmTxStateMask ;
119
-
120
48
typedef enum
121
49
{
122
50
PGLOGICAL_COMMIT ,
@@ -153,23 +81,13 @@ typedef enum
153
81
MTM_ONLINE /* Ready to receive client's queries */
154
82
} MtmNodeStatus ;
155
83
156
- typedef enum
157
- {
158
- REPLMODE_EXIT , /* receiver should exit */
159
- REPLMODE_RECOVERED , /* recovery of receiver node is completed so drop old slot and restart replication from the current position in WAL */
160
- REPLMODE_RECOVERY , /* perform recovery of the node by applying all data from the slot from specified point */
161
- REPLMODE_CREATE_NEW , /* destination node is recovered: drop old slot and restart from roveredLsn position */
162
- REPLMODE_OPEN_EXISTED /* normal mode: use existed slot or create new one and start receiving data from it from the remembered position */
163
- } MtmReplicationMode ;
164
-
165
84
typedef struct
166
85
{
167
86
MtmMessageCode code ; /* Message code: MSG_PREPARE, MSG_PRECOMMIT, MSG_COMMIT, MSG_ABORT,... */
168
87
MtmTxState state ;
169
88
int node ; /* Sender node ID */
170
89
TransactionId dxid ; /* Transaction ID at destination node */
171
90
TransactionId sxid ; /* Transaction ID at sender node */
172
- XidStatus status ; /* Transaction status */
173
91
nodemask_t connectivityMask ; /* Connectivity bitmask at the sender of message */
174
92
pgid_t gid ; /* Global transaction identifier */
175
93
} MtmArbiterMessage ;
@@ -223,28 +141,9 @@ typedef struct
223
141
int nAllNodes ; /* Total number of nodes */
224
142
int recoveryCount ; /* Number of completed recoveries */
225
143
int donorNodeId ; /* Cluster node from which this node was populated */
226
- lsn_t recoveredLSN ; /* LSN at the moment of recovery completion */
227
144
MtmNodeInfo nodes [1 ]; /* [Mtm->nAllNodes]: per-node data */
228
145
} MtmState ;
229
146
230
- typedef struct MtmFlushPosition
231
- {
232
- dlist_node node ;
233
- int node_id ;
234
- lsn_t local_end ;
235
- lsn_t remote_end ;
236
- } MtmFlushPosition ;
237
-
238
- typedef struct
239
- {
240
- int magic ;
241
- bool is_recovery ;
242
- } MtmDecoderPrivate ;
243
-
244
- extern char const * const MtmNodeStatusMnem [];
245
- extern char const * const MtmTxnStatusMnem [];
246
- extern char const * const MtmMessageKindMnem [];
247
-
248
147
extern MtmState * Mtm ;
249
148
250
149
extern int MtmReplicationNodeId ;
@@ -260,8 +159,7 @@ extern bool MtmMajorNode;
260
159
extern bool MtmBackgroundWorker ;
261
160
extern char * MtmRefereeConnStr ;
262
161
263
- extern void MtmXactCallback2 (XactEvent event , void * arg );
264
- extern void MtmMonitorInitialize (void );
162
+ extern void MtmXactCallback2 (XactEvent event , void * arg );
265
163
extern bool MtmIsUserTransaction (void );
266
164
extern void MtmGenerateGid (char * gid , TransactionId xid );
267
165
extern int MtmGidParseNodeId (const char * gid );
@@ -270,55 +168,23 @@ extern TransactionId MtmGidParseXid(const char* gid);
270
168
extern void MtmWaitForExtensionCreation (void );
271
169
extern void erase_option_from_connstr (const char * option , char * connstr );
272
170
273
- extern void ResolverMain (void );
274
- extern void ResolverInit (void );
275
- extern void ResolveTransactionsForNode (int node_id );
276
- extern void ResolveAllTransactions (void );
277
- extern char * MtmTxStateMnem (MtmTxState state );
278
-
279
- extern void MtmStartReceivers (void );
280
- extern void MtmStartReceiver (int nodeId , bool dynamic );
281
-
282
- extern MtmReplicationMode MtmGetReplicationMode (int nodeId );
283
- extern void MtmExecutor (void * work , size_t size );
284
-
285
-
286
-
287
171
extern void MtmLock (LWLockMode mode );
288
172
extern void MtmUnlock (void );
289
173
extern void MtmLockNode (int nodeId , LWLockMode mode );
290
174
extern bool MtmTryLockNode (int nodeId , LWLockMode mode );
291
175
extern void MtmUnlockNode (int nodeId );
292
176
293
- extern void MtmStopNode (int nodeId , bool dropSlot );
294
- extern void MtmRecoverNode (int nodeId );
295
- extern void MtmResumeNode (int nodeId );
296
-
297
177
extern void MtmSleep (timestamp_t interval );
298
178
299
179
extern void MtmSetCurrentTransactionGID (char const * gid , int node_id );
300
180
extern void MtmSetCurrentTransactionCSN (void );
301
181
extern TransactionId MtmGetCurrentTransactionId (void );
302
182
extern void MtmResetTransaction (void );
303
183
304
- extern void MtmUpdateNodeConnectionInfo (MtmConnectionInfo * conn , char const * connStr );
305
-
306
- extern void MtmHandleApplyError (void );
307
-
308
- extern void MtmUpdateLsnMapping (int nodeId , lsn_t endLsn );
309
- extern lsn_t MtmGetFlushPosition (int nodeId );
310
-
311
-
312
- extern void MtmReleaseRecoverySlot (int nodeId );
313
184
extern PGconn * PQconnectdb_safe (const char * conninfo , int timeout );
314
- extern void MtmBeginSession (int nodeId );
315
- extern void MtmEndSession (int nodeId , bool unlock );
316
-
317
- extern bool MtmFilterTransaction (char * record , int size );
318
185
319
186
extern void MtmInitMessage (MtmArbiterMessage * msg , MtmMessageCode code );
320
187
321
- extern void MtmRefereeInitialize (void );
322
188
extern void MtmUpdateControlFile (void );
323
189
324
190
extern void MtmCheckSlots (void );
0 commit comments