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

Commit 670cb78

Browse files
knizhnikkelvich
authored andcommitted
Rewrite 2pc support
1 parent 75b1bbc commit 670cb78

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

multimaster.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError);
126126
static void MtmVoteForTransaction(MtmTransState* ts);
127127

128128
static HTAB* xid2state;
129-
static HTAB* git2xid;
129+
static HTAB* gid2xid;
130130
static MtmCurrentTrans dtmTx;
131131
static MtmState* dtm;
132132

@@ -529,7 +529,6 @@ MtmBeginTransaction(MtmCurrentTrans* x)
529529
elog(ERROR, "Multimaster node is not online: current status %s", MtmNodeStatusMnem[dtm->status]);
530530
}
531531
x->containsDML = false;
532-
x->isPrepared = false;
533532
x->snapshot = MtmAssignCSN();
534533
x->gtid.xid = InvalidTransactionId;
535534
x->gid[0] = '\0';
@@ -541,7 +540,8 @@ MtmBeginTransaction(MtmCurrentTrans* x)
541540
}
542541

543542
/*
544-
* Prepare transaction for two-phase commit
543+
* Prepare transaction for two-phase commit.
544+
* This code is executed by PRE_PREPARE hook before PREPARE message is sent to replicas by logical replication
545545
*/
546546
MtmPrePrepareTransaction(MtmCurrentTrans* x)
547547
{
@@ -575,7 +575,6 @@ MtmPrePrepareTransaction(MtmCurrentTrans* x)
575575
ts->gtid = x->gtid;
576576
ts->procno = MyProc->pgprocno;
577577
ts->nVotes = 0;
578-
ts->voteCompleted = false;
579578

580579
x->isPrepared = true;
581580
x->csn = csn;

multimaster.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ typedef struct MtmTransState
8484
finally should be nNodes-1 */
8585
int procno; /* pgprocno of transaction coordinator waiting for responses from replicas,
8686
used to notify coordinator by arbiter */
87-
bool voteCompleted; /* Responses necessary to make a decision are received by coordinator of transaction */
8887
int nSubxids; /* Number of subtransanctions */
8988
struct MtmTransState* nextVoting; /* Next element in L1-list of voting transactions. */
9089
struct MtmTransState* next; /* Next element in L1 list of all finished transaction present in xid2state hash */
91-
TransactionId xids[1]; /* transaction ID at replicas: varying size MtmNodes */
9290
} MtmTransState;
9391

9492
typedef struct

pglogical_apply.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ process_remote_commit(StringInfo in)
499499
CommitTransactionCommand();
500500
StartTransactionCommand();
501501
/* PREPARE itself */
502-
MtmSetCurrentTransactionGid(gid);
502+
MtmSetCurrentTransactionGID(gid);
503503
PrepareTransactionBlock(gid);
504504
CommitTransactionCommand();
505505
break;
@@ -519,7 +519,7 @@ process_remote_commit(StringInfo in)
519519
{
520520
gid = pq_getmsgstring(in);
521521
StartTransactionCommand();
522-
MtmSetCurrentTransactionGid(gid);
522+
MtmSetCurrentTransactionGID(gid);
523523
FinishPreparedTransaction(gid, false);
524524
CommitTransactionCommand();
525525
break;

pglogical_proto.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ pglogical_write_begin(StringInfo out, PGLogicalOutputData *data,
122122

123123

124124
static csn_t
125-
MtmGetCSN(TransactionId xid)
125+
MtmGetCSN(PGLogicalProtoMM* mm, TransactionId xid)
126126
{
127127
MtmTransState* ts;
128128
csn_t csn;
129129
MtmLock(LW_SHARED);
130-
ts = (MtmTransState*)hash_search(xid2state, &xid, HASH_FIND, NULL);
130+
ts = (MtmTransState*)hash_search(mm->xid2state, &xid, HASH_FIND, NULL);
131131
Assert(ts != NULL);
132132
csn = ts->csn;
133133
MtmUnlock();
@@ -171,7 +171,7 @@ pglogical_write_commit(StringInfo out, PGLogicalOutputData *data,
171171
pq_sendint64(out, txn->commit_time);
172172

173173
if (txn->xact_action == XLOG_XACT_COMMIT_PREPARED) {
174-
pq_sendint64(out, MtmGetCSN(txn->xid));
174+
pq_sendint64(out, MtmGetCSN(mm, txn->xid));
175175
}
176176
if (txn->xact_action == XLOG_XACT_PREPARE ||
177177
txn->xact_action == XLOG_XACT_COMMIT_PREPARED ||

0 commit comments

Comments
 (0)