-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmessaging.h
168 lines (150 loc) · 3.9 KB
/
messaging.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*****************************************************************************
*
* Messaging
*
*****************************************************************************/
#ifndef MESSAGING_H
#define MESSAGING_H
#include "global_tx.h"
#include "state.h"
/*
* All messages are stamped with MtmMessageTag that should came before the rest
* of the message. That is used upon receival as typecasting criterion.
*/
typedef enum
{
T_MtmPrepareResponse = 0,
T_Mtm2AResponse,
T_MtmTxRequest,
T_MtmTxStatusResponse,
T_MtmHeartbeat,
T_MtmGenVoteRequest,
T_MtmGenVoteResponse
} MtmMessageTag;
typedef struct MtmMessage
{
MtmMessageTag tag;
} MtmMessage;
#define messageTag(msgptr) (((const MtmMessage *)(msgptr))->tag)
/* Response to PREPARE by apply worker */
typedef struct
{
MtmMessageTag tag;
int node_id;
/* for PREPARE we care only about, well, prepare success */
bool prepared;
int32 errcode;
const char *errmsg;
TransactionId xid; /* identifies the message */
} MtmPrepareResponse;
/*
* Response to 2A msg by apply worker or by replier (during resolving).
* This could be named just 2B, ha.
* It is also abused for COMMIT PREPARED ack (with .status = GTXCommitted).
*/
typedef struct
{
MtmMessageTag tag;
int node_id;
/*
* Our prevVote in terms of the Part-Time Parliament paper. Actually there
* is no need to carry the decree (status) itself, ballot (term) is
* enough, but it is kept for convenience.
*/
GlobalTxStatus status;
GlobalTxTerm accepted_term;
int32 errcode;
const char *errmsg;
const char *gid; /* identifies the message */
} Mtm2AResponse;
/*
* Response on MtmLastTermRequest request, holds last proposal value.
*/
typedef struct
{
MtmMessageTag tag;
GlobalTxTerm term;
} MtmLastTermResponse;
/*
* Request to change transaction state. This messages are duplicate of
* corresponding WAL records, but we need them during transaction resolution
* upon recovery as WAL receiver may be blocked by a transaction that we
* are actually resolving.
*
* Sent from mtm-resolver to mtm-status worker.
*/
typedef enum
{
MTReq_Abort = 0,
MTReq_Commit,
MTReq_Precommit, /* 2a with value commit */
MTReq_Preabort, /* 2a with value abort */
MTReq_Status /* 1a */
} MtmTxRequestValue;
typedef struct
{
MtmMessageTag tag;
MtmTxRequestValue type;
GlobalTxTerm term;
const char *gid;
int coordinator;
uint64 gen_num;
XLogRecPtr coordinator_end_lsn; /* matters for 1a */
} MtmTxRequest;
extern char const * const MtmTxRequestValueMnem[];
/*
* Status response, phase 1b of paxos on a given transaction result.
* Sent from mtm-status to mtm-resolver worker.
*/
typedef struct
{
MtmMessageTag tag;
int node_id;
GTxState state;
const char *gid;
} MtmTxStatusResponse;
/*
* Data sent in dmq heartbeats.
*/
typedef struct
{
MtmMessageTag tag;
MtmGeneration current_gen;
uint64 donors; /* xxx nodemask_t */
uint64 last_online_in;
uint64 connected_mask; /* xxx nodemask_t */
} MtmHeartbeat;
/*
* Request to vote for new generation.
*/
typedef struct
{
MtmMessageTag tag;
MtmGeneration gen;
} MtmGenVoteRequest;
/*
* Reply to new generation vote request.
*/
typedef struct
{
MtmMessageTag tag;
uint64 gen_num; /* identifies the message */
uint8 vote_ok;
/* last_online_in of replier on the moment of voting, determines donors */
uint64 last_online_in;
/*
* if vote_ok is false this might be a valid gen number showing that
* replier couldn't vote because its last_vote is higher.
*/
uint64 last_vote_num;
/*
* curr gen donors of the responder and its donors. Sometimes we wish to
* send it along with refusal to vote, see HandleGenVoteRequest.
*/
MtmGeneration curr_gen;
uint64_t curr_gen_donors;
} MtmGenVoteResponse;
StringInfo MtmMessagePack(MtmMessage *anymsg);
MtmMessage *MtmMessageUnpack(StringInfo s);
char *MtmMesageToString(MtmMessage *anymsg);
#endif /* MESSAGING_H */