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

Commit 7bfa7fd

Browse files
knizhnikkelvich
authored andcommitted
PGPRO-1238 fix recovery of prepared tranasctions in minor node
1 parent e13a96f commit 7bfa7fd

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

multimaster.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,8 +1707,27 @@ static void MtmBroadcastPollMessage(MtmTransState* ts)
17071707

17081708
if (nparts == 1)
17091709
{
1710-
/* we were in major mode and there nobody to ask about status */
1711-
MtmFinishPreparedTransaction(ts, true);
1710+
int refereeWinnerId = MtmRefereeReadSaved();
1711+
if (MtmMajorNode || refereeWinnerId == MtmNodeId)
1712+
{
1713+
MTM_ELOG(LOG, "%s node commits prepared transaction %s", MtmMajorNode ? "Major" : "Winner", ts->gid);
1714+
/* we were in major mode and there nobody to ask about status */
1715+
MtmFinishPreparedTransaction(ts, true);
1716+
}
1717+
else
1718+
{
1719+
int coordinator = 0;
1720+
sscanf(ts->gid, "MTM-%d", &coordinator);
1721+
if (coordinator == MtmNodeId && ts->status == TRANSACTION_STATUS_IN_PROGRESS) {
1722+
/* it is always safe to rollback self transaction which was not precommitted: it can not be committed anywhere else */
1723+
MTM_ELOG(LOG, "Coordinator node rollback not precommitted transaction %s", ts->gid);
1724+
MtmFinishPreparedTransaction(ts, false);
1725+
}
1726+
else
1727+
{
1728+
MTM_ELOG(WARNING, "Doesn't know waht to do with transaction prepared transaction %s", ts->gid);
1729+
}
1730+
}
17121731
return;
17131732
}
17141733

state.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ char const* const MtmEventMnem[] =
3131

3232
static int MtmRefereeGetWinner(void);
3333
static bool MtmRefereeClearWinner(void);
34-
static int MtmRefereeReadSaved(void);
3534

3635
static bool mtm_state_initialized;
3736

@@ -586,7 +585,7 @@ MtmRefereeHasLocalTable()
586585
return OidIsValid(rel_oid);
587586
}
588587

589-
static int
588+
int
590589
MtmRefereeReadSaved(void)
591590
{
592591
int winner = -1;

state.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ extern void MtmOnNodeDisconnect(int nodeId);
3030
extern void MtmOnNodeConnect(int nodeId);
3131
extern void MtmReconnectNode(int nodeId);
3232

33+
extern int MtmRefereeReadSaved(void);
34+
3335
extern void MtmRefreshClusterStatus(void);
3436

3537
extern int countZeroBits(nodemask_t mask, int nNodes);
3638

3739
extern MtmNodeStatus MtmGetCurrentStatus(void);
38-
extern nodemask_t MtmGetDisabledNodeMask(void);
40+
extern nodemask_t MtmGetDisabledNodeMask(void);

tests/makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
CXX=g++
2-
CXXFLAGS=-g -Wall -O0 -pthread
2+
CC=gcc
3+
CFLAGS=-g -Wall -O0 -pthread
34

4-
all: dtmbench dtmacid
5+
all: dtmbench dtmacid insert
56

67
dtmbench: dtmbench.cpp
7-
$(CXX) $(CXXFLAGS) -o dtmbench dtmbench.cpp -lpqxx -lpq
8+
$(CXX) $(CFLAGS) -o dtmbench dtmbench.cpp -lpqxx -lpq
89

910
dtmacid: dtmacid.cpp
10-
$(CXX) $(CXXFLAGS) -o dtmacid dtmacid.cpp -lpqxx -lpq
11+
$(CXX) $(CFLAGS) -o dtmacid dtmacid.cpp -lpqxx -lpq
12+
13+
insert: insert.c
14+
$(CC) $(CFLAGS) -o insert insert.c -lpq
1115

1216
clean:
1317
rm -f dtmbench dtmacid

0 commit comments

Comments
 (0)