Skip to content

Commit 96dfdea

Browse files
committed
finally it is working
1 parent 4c3a428 commit 96dfdea

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

src/backend/access/transam/twophase.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
16031603
* writes to xlog and files (as it was already done).
16041604
*/
16051605
void
1606-
XlogRedoFinishPrepared(TransactionId xid)
1606+
XlogRedoFinishPrepared(TransactionId xid, bool isCommit)
16071607
{
16081608
int i;
16091609
char *buf;
@@ -1655,6 +1655,7 @@ XlogRedoFinishPrepared(TransactionId xid)
16551655

16561656
bufptr = buf + MAXALIGN(sizeof(TwoPhaseFileHeader));
16571657
children = (TransactionId *) bufptr;
1658+
bufptr += MAXALIGN(hdr->gidlen);
16581659
bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId));
16591660
bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileNode));
16601661
bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileNode));
@@ -1672,14 +1673,15 @@ XlogRedoFinishPrepared(TransactionId xid)
16721673

16731674
/*
16741675
* 2REVIEWER: I assume that we can skip invalidation callbacks here,
1675-
* aren't we?
1676+
* as they were executed in xact_redo_commit().
16761677
*/
16771678

16781679
/* And release locks */
1679-
if (true)
1680+
if (isCommit)
16801681
ProcessRecords(bufptr, xid, twophase_postcommit_callbacks);
16811682
else
16821683
ProcessRecords(bufptr, xid, twophase_postabort_callbacks);
1684+
16831685
PredicateLockTwoPhaseFinish(xid, true);
16841686
RemoveGXact(gxact);
16851687
MyLockedGxact = NULL;

src/backend/access/transam/xact.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5573,7 +5573,7 @@ xact_redo(XLogReaderState *record)
55735573
Assert(TransactionIdIsValid(parsed.twophase_xid));
55745574
xact_redo_commit(&parsed, parsed.twophase_xid,
55755575
record->EndRecPtr, XLogRecGetOrigin(record));
5576-
XlogRedoFinishPrepared(parsed.twophase_xid);
5576+
XlogRedoFinishPrepared(parsed.twophase_xid, true);
55775577
}
55785578
}
55795579
else if (info == XLOG_XACT_ABORT || info == XLOG_XACT_ABORT_PREPARED)
@@ -5593,7 +5593,7 @@ xact_redo(XLogReaderState *record)
55935593
{
55945594
Assert(TransactionIdIsValid(parsed.twophase_xid));
55955595
xact_redo_abort(&parsed, parsed.twophase_xid);
5596-
XlogRedoFinishPrepared(parsed.twophase_xid);
5596+
XlogRedoFinishPrepared(parsed.twophase_xid, false);
55975597
}
55985598
}
55995599
else if (info == XLOG_XACT_PREPARE)

src/include/access/twophase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ extern void CheckPointTwoPhase(XLogRecPtr redo_horizon);
5757

5858
extern void FinishPreparedTransaction(const char *gid, bool isCommit);
5959

60-
extern void XlogRedoFinishPrepared(TransactionId xid);
60+
extern void XlogRedoFinishPrepared(TransactionId xid, bool isCommit);
6161
#endif /* TWOPHASE_H */

src/test/recovery/t/006_twophase.pl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ sub PostgresNode::psql_fails {
4040
));
4141
$node_master->restart;
4242

43+
my $psql_out = '';
44+
4345
###############################################################################
4446
# Check that we can commit and abort after soft restart.
4547
# Here checkpoint happens before shutdown and no WAL replay will not occur
@@ -116,6 +118,7 @@ sub PostgresNode::psql_fails {
116118
-- didn't cleanup proc, gxact and locks on commit.
117119
prepare transaction 'x';",
118120
"Check that WAL replay will cleanup it's memory state");
121+
$node_master->psql('postgres', "commit prepared 'x'");
119122

120123
###############################################################################
121124
# Check that we can commit while running active sync slave and that there is no
@@ -128,8 +131,8 @@ sub PostgresNode::psql_fails {
128131
prepare transaction 'x';
129132
commit prepared 'x';
130133
");
131-
my $result = $node_slave->psql('postgres', "select * from pg_prepared_xacts;");
132-
is($result, "", "Check that WAL replay will cleanup it's memory state on slave");
134+
$node_slave->psql('postgres', "select count(*) from pg_prepared_xacts;", stdout => \$psql_out);
135+
is($psql_out, '0', "Check that WAL replay will cleanup it's memory state on slave");
133136

134137
###############################################################################
135138
# The same as in previous case, but let's force checkpoint on slave between
@@ -143,8 +146,8 @@ sub PostgresNode::psql_fails {
143146
");
144147
$node_slave->psql('postgres',"checkpoint;");
145148
$node_master->psql('postgres', "commit prepared 'x';");
146-
$result = $node_slave->psql('postgres', "select * from pg_prepared_xacts;");
147-
is($result, "", "Check that WAL replay will cleanup it's memory state on slave after checkpoint");
149+
$node_slave->psql('postgres', "select count(*) from pg_prepared_xacts;", stdout => \$psql_out);
150+
is($psql_out, '0', "Check that WAL replay will cleanup it's memory state on slave after checkpoint");
148151

149152
###############################################################################
150153
# Check that we can commit transaction on promoted slave.
@@ -183,8 +186,8 @@ sub PostgresNode::psql_fails {
183186
$node_slave->restart;
184187
$node_slave->promote;
185188
$node_slave->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true");
186-
my $prepared_count = $node_slave->psql('postgres',"select count(*) from pg_prepared_xacts");
187-
is($prepared_count, '1', "Check that we restore prepared xacts after slave soft restart while master is down.");
189+
$node_slave->psql('postgres',"select count(*) from pg_prepared_xacts", stdout => \$psql_out);
190+
is($psql_out, '1', "Check that we restore prepared xacts after slave soft restart while master is down.");
188191

189192
# restore state
190193
($node_master, $node_slave) = ($node_slave, $node_master);
@@ -210,8 +213,8 @@ sub PostgresNode::psql_fails {
210213
$node_slave->start;
211214
$node_slave->promote;
212215
$node_slave->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true");
213-
$prepared_count = $node_slave->psql('postgres',"select count(*) from pg_prepared_xacts");
214-
is($prepared_count, '1', "Check that we restore prepared xacts after slave hard restart while master is down.");
216+
$node_slave->psql('postgres',"select count(*) from pg_prepared_xacts", stdout => \$psql_out);
217+
is($psql_out, '1', "Check that we restore prepared xacts after slave hard restart while master is down.");
215218

216219
# restore state
217220
($node_master, $node_slave) = ($node_slave, $node_master);

0 commit comments

Comments
 (0)