Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5485d9f

Browse files
committed
dmq integration: tag-based logger
1 parent 5be559f commit 5485d9f

File tree

7 files changed

+273
-103
lines changed

7 files changed

+273
-103
lines changed

commit.c

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
/*----------------------------------------------------------------------------
2+
*
3+
* commit.c
4+
* Replace ordinary commit with 3PC.
5+
*
6+
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
*----------------------------------------------------------------------------
10+
*/
11+
112
#include "postgres.h"
213
#include "multimaster.h"
314
#include "storage/proc.h"
415
#include "utils/guc.h"
516
#include "miscadmin.h"
617
#include "commands/dbcommands.h"
718

19+
#include "logger.h"
20+
821
static Oid MtmDatabaseId;
922
static bool DmqSubscribed;
1023
static int sender_to_node[MTM_MAX_NODES];
@@ -19,9 +32,6 @@ static bool GatherPrepares(MtmCurrentTrans* x, nodemask_t participantsMask,
1932
static void GatherPrecommits(MtmCurrentTrans* x, nodemask_t participantsMask);
2033

2134

22-
23-
24-
2535
void
2636
MtmXactCallback2(XactEvent event, void *arg)
2737
{
@@ -77,7 +87,7 @@ MtmPrePrepareTransaction(MtmCurrentTrans* x)
7787
MtmDatabaseId = get_database_oid(MtmDatabaseName, false);
7888

7989
if (MtmDatabaseId != MyDatabaseId)
80-
MTM_ELOG(ERROR,
90+
mtm_log(ERROR,
8191
"Refusing to work. Multimaster configured to work with database '%s'",
8292
MtmDatabaseName);
8393

@@ -132,7 +142,8 @@ MtmTwoPhaseCommit(MtmCurrentTrans* x)
132142
ret = PrepareTransactionBlock(gid);
133143
if (!ret)
134144
{
135-
MTM_ELOG(WARNING, "Failed to prepare transaction %s (%llu)", gid, (long64)x->xid);
145+
mtm_log(MtmTxFinish, "%s prepared", gid);
146+
mtm_log(WARNING, "Failed to prepare transaction %s", gid);
136147
return false;
137148
}
138149
CommitTransactionCommand();
@@ -142,15 +153,18 @@ MtmTwoPhaseCommit(MtmCurrentTrans* x)
142153
{
143154
dmq_stream_unsubscribe(stream);
144155
FinishPreparedTransaction(gid, false, false);
145-
MTM_ELOG(ERROR, "Failed to prepare transaction %s at node %d",
156+
mtm_log(MtmTxFinish, "%s aborted", gid);
157+
mtm_log(ERROR, "Failed to prepare transaction %s at node %d",
146158
gid, failed_at);
147159
}
148160

149161
SetPreparedTransactionState(gid, MULTIMASTER_PRECOMMITTED);
162+
mtm_log(MtmTxFinish, "%s precommittted", gid);
150163
GatherPrecommits(x, participantsMask);
151164

152165
StartTransactionCommand();
153166
FinishPreparedTransaction(gid, true, false);
167+
mtm_log(MtmTxFinish, "%s committted", gid);
154168

155169
dmq_stream_unsubscribe(stream);
156170

@@ -173,17 +187,16 @@ GatherPrepares(MtmCurrentTrans* x, nodemask_t participantsMask, int *failed_at)
173187
dmq_pop(&sender_id, &buffer, participantsMask);
174188
msg = (MtmArbiterMessage *) buffer.data;
175189

176-
// elog(LOG, "GatherPrepares: got %s from node%d", msg->gid, sender_to_node[sender_id]);
177-
// ereport(LOG,
178-
// (errmsg("GatherPrepares: got %s from node%d",
179-
// msg->gid, sender_to_node[sender_id]),
180-
// errhidestmt(true)));
181-
182190
Assert(msg->node == sender_to_node[sender_id]);
183191
Assert(msg->code == MSG_PREPARED || msg->code == MSG_ABORTED);
184192
Assert(msg->dxid == x->xid);
185193
Assert(BIT_CHECK(participantsMask, sender_to_node[sender_id] - 1));
186194

195+
mtm_log(MtmTxTrace,
196+
"GatherPrepares: got '%s' for %s from node%d",
197+
msg->code == MSG_PREPARED ? "ok" : "failed",
198+
msg->gid, sender_to_node[sender_id]);
199+
187200
BIT_CLEAR(participantsMask, sender_to_node[sender_id] - 1);
188201

189202
if (msg->code == MSG_ABORTED)
@@ -210,13 +223,15 @@ GatherPrecommits(MtmCurrentTrans* x, nodemask_t participantsMask)
210223
dmq_pop(&sender_id, &buffer, participantsMask);
211224
msg = (MtmArbiterMessage *) buffer.data;
212225

213-
// elog(LOG, "GatherPrecommits: got %s from node%d", msg->gid, sender_to_node[sender_id]);
214-
215226
Assert(msg->node == sender_to_node[sender_id]);
216227
Assert(msg->code == MSG_PRECOMMITTED);
217228
Assert(msg->dxid == x->xid);
218229
Assert(BIT_CHECK(participantsMask, sender_to_node[sender_id] - 1));
219230

231+
mtm_log(MtmTxTrace,
232+
"GatherPrecommits: got 'ok' for %s from node%d",
233+
msg->gid, sender_to_node[sender_id]);
234+
220235
BIT_CLEAR(participantsMask, sender_to_node[sender_id] - 1);
221236
}
222237
}

0 commit comments

Comments
 (0)