Skip to content

Commit 9a6aa45

Browse files
committed
Remove assert nVotes < nLiveNodes
1 parent c26f6e4 commit 9a6aa45

File tree

2 files changed

+49
-42
lines changed

2 files changed

+49
-42
lines changed

contrib/mmts/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ USER postgres
3131
ENV CFLAGS -O0
3232
WORKDIR /pg
3333

34-
ENV REBUILD 1
34+
ENV REBUILD 3
3535

3636
RUN cd /pg && \
3737
git clone https://github.com/postgrespro/postgres_cluster.git --depth 1 && \

contrib/mmts/arbiter.c

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -853,61 +853,68 @@ static void MtmTransReceiver(Datum arg)
853853
if (MtmIsCoordinator(ts)) {
854854
switch (msg->code) {
855855
case MSG_READY:
856-
Assert(ts->nVotes < Mtm->nLiveNodes);
857-
Mtm->nodes[msg->node-1].transDelay += MtmGetCurrentTime() - ts->csn;
858-
ts->xids[msg->node-1] = msg->sxid;
859-
860-
if ((~msg->disabledNodeMask & Mtm->disabledNodeMask) != 0) {
861-
/* Coordinator's disabled mask is wider than of this node: so reject such transaction to avoid
862-
commit on smaller subset of nodes */
863-
elog(WARNING, "Coordinator of distributed transaction see less nodes than node %d: %lx instead of %lx",
864-
msg->node, (long) Mtm->disabledNodeMask, (long) msg->disabledNodeMask);
856+
if (ts->nVotes >= Mtm->nLiveNodes) {
865857
MtmAbortTransaction(ts);
866-
}
867-
868-
if (++ts->nVotes == Mtm->nLiveNodes) {
869-
/* All nodes are finished their transactions */
870-
if (ts->status == TRANSACTION_STATUS_ABORTED) {
871-
MtmWakeUpBackend(ts);
872-
} else if (MtmUseDtm) {
873-
Assert(ts->status == TRANSACTION_STATUS_IN_PROGRESS);
874-
ts->nVotes = 1; /* I voted myself */
875-
MtmSendNotificationMessage(ts, MSG_PREPARE);
876-
} else {
877-
Assert(ts->status == TRANSACTION_STATUS_IN_PROGRESS);
878-
ts->status = TRANSACTION_STATUS_UNKNOWN;
879-
MtmWakeUpBackend(ts);
858+
MtmWakeUpBackend(ts);
859+
} else {
860+
Mtm->nodes[msg->node-1].transDelay += MtmGetCurrentTime() - ts->csn;
861+
ts->xids[msg->node-1] = msg->sxid;
862+
863+
if ((~msg->disabledNodeMask & Mtm->disabledNodeMask) != 0) {
864+
/* Coordinator's disabled mask is wider than of this node: so reject such transaction to avoid
865+
commit on smaller subset of nodes */
866+
elog(WARNING, "Coordinator of distributed transaction see less nodes than node %d: %lx instead of %lx",
867+
msg->node, (long) Mtm->disabledNodeMask, (long) msg->disabledNodeMask);
868+
MtmAbortTransaction(ts);
869+
}
870+
871+
if (++ts->nVotes == Mtm->nLiveNodes) {
872+
/* All nodes are finished their transactions */
873+
if (ts->status == TRANSACTION_STATUS_ABORTED) {
874+
MtmWakeUpBackend(ts);
875+
} else if (MtmUseDtm) {
876+
Assert(ts->status == TRANSACTION_STATUS_IN_PROGRESS);
877+
ts->nVotes = 1; /* I voted myself */
878+
MtmSendNotificationMessage(ts, MSG_PREPARE);
879+
} else {
880+
Assert(ts->status == TRANSACTION_STATUS_IN_PROGRESS);
881+
ts->status = TRANSACTION_STATUS_UNKNOWN;
882+
MtmWakeUpBackend(ts);
883+
}
880884
}
881885
}
882886
break;
883887
case MSG_ABORTED:
884-
Assert(ts->nVotes < Mtm->nLiveNodes);
885888
if (ts->status != TRANSACTION_STATUS_ABORTED) {
886889
Assert(ts->status == TRANSACTION_STATUS_IN_PROGRESS);
887890
MtmAbortTransaction(ts);
888891
}
889-
if (++ts->nVotes == Mtm->nLiveNodes) {
892+
if (++ts->nVotes >= Mtm->nLiveNodes) {
890893
MtmWakeUpBackend(ts);
891894
}
892895
break;
893896
case MSG_PREPARED:
894-
Assert(ts->nVotes < Mtm->nLiveNodes);
895-
if (ts->status != TRANSACTION_STATUS_ABORTED) {
896-
Assert(ts->status == TRANSACTION_STATUS_IN_PROGRESS);
897-
if (msg->csn > ts->csn) {
898-
ts->csn = msg->csn;
899-
MtmSyncClock(ts->csn);
900-
}
901-
if (++ts->nVotes == Mtm->nLiveNodes) {
902-
ts->csn = MtmAssignCSN();
903-
ts->status = TRANSACTION_STATUS_UNKNOWN;
904-
MtmWakeUpBackend(ts);
905-
}
897+
if (ts->nVotes >= Mtm->nLiveNodes) {
898+
MtmAbortTransaction(ts);
899+
MtmWakeUpBackend(ts);
906900
} else {
907-
if (++ts->nVotes == Mtm->nLiveNodes) {
908-
MtmWakeUpBackend(ts);
909-
}
910-
}
901+
if (ts->status != TRANSACTION_STATUS_ABORTED) {
902+
Assert(ts->status == TRANSACTION_STATUS_IN_PROGRESS);
903+
if (msg->csn > ts->csn) {
904+
ts->csn = msg->csn;
905+
MtmSyncClock(ts->csn);
906+
}
907+
if (++ts->nVotes == Mtm->nLiveNodes) {
908+
ts->csn = MtmAssignCSN();
909+
ts->status = TRANSACTION_STATUS_UNKNOWN;
910+
MtmWakeUpBackend(ts);
911+
}
912+
} else {
913+
if (++ts->nVotes == Mtm->nLiveNodes) {
914+
MtmWakeUpBackend(ts);
915+
}
916+
}
917+
}
911918
break;
912919
default:
913920
Assert(false);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy