Skip to content

Commit ef5ef89

Browse files
committed
some more tests for Prescan and StandbyRecover
1 parent ef2c90a commit ef5ef89

File tree

3 files changed

+185
-63
lines changed

3 files changed

+185
-63
lines changed

reinit.sh

Lines changed: 174 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -41,75 +41,75 @@ reinit_slave() {
4141
make install > /dev/null
4242

4343

44-
cat <<MSG
45-
###############################################################################
46-
# Check that we can commit after soft restart.
47-
# Here checkpoint happens before shutdown and no WAL replay will not occur
48-
# during start. So code should re-create memory state from files.
49-
###############################################################################
50-
MSG
44+
# cat <<MSG
45+
# ###############################################################################
46+
# # Check that we can commit after soft restart.
47+
# # Here checkpoint happens before shutdown and no WAL replay will not occur
48+
# # during start. So code should re-create memory state from files.
49+
# ###############################################################################
50+
# MSG
5151

52-
pkill -9 postgres
53-
reinit_master >> /dev/null
54-
psql <<SQL
55-
begin;
56-
insert into t values (42);
57-
prepare transaction 'x';
58-
SQL
59-
./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile restart
60-
psql <<SQL
61-
commit prepared 'x';
62-
SQL
52+
# pkill -9 postgres
53+
# reinit_master >> /dev/null
54+
# psql <<SQL
55+
# begin;
56+
# insert into t values (42);
57+
# prepare transaction 'x';
58+
# SQL
59+
# ./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile restart
60+
# psql <<SQL
61+
# commit prepared 'x';
62+
# SQL
6363

6464

6565

66-
cat <<MSG
67-
###############################################################################
68-
# Check that we can commit after hard restart.
69-
# On startup WAL replay will re-create memory for global transactions that
70-
# happend after last checkpoint and stored. After that
71-
###############################################################################
72-
MSG
66+
# cat <<MSG
67+
# ###############################################################################
68+
# # Check that we can commit after hard restart.
69+
# # On startup WAL replay will re-create memory for global transactions that
70+
# # happend after last checkpoint and stored. After that
71+
# ###############################################################################
72+
# MSG
7373

74-
pkill -9 postgres
75-
reinit_master >> /dev/null
76-
psql <<SQL
77-
begin;
78-
insert into t values (42);
79-
prepare transaction 'x';
80-
SQL
81-
pkill -9 postgres
82-
./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile start
83-
psql <<SQL
84-
commit prepared 'x';
85-
SQL
74+
# pkill -9 postgres
75+
# reinit_master >> /dev/null
76+
# psql <<SQL
77+
# begin;
78+
# insert into t values (42);
79+
# prepare transaction 'x';
80+
# SQL
81+
# pkill -9 postgres
82+
# ./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile start
83+
# psql <<SQL
84+
# commit prepared 'x';
85+
# SQL
8686

8787

88-
cat <<MSG
89-
###############################################################################
90-
# Check that WAL replay will delete memory state for commited 2pc tx.
91-
###############################################################################
92-
MSG
88+
# cat <<MSG
89+
# ###############################################################################
90+
# # Check that WAL replay will cleanup it's memory state and release locks while
91+
# # replaying commit.
92+
# ###############################################################################
93+
# MSG
9394

94-
pkill -9 postgres
95-
reinit_master >> /dev/null
96-
psql <<SQL
97-
begin;
98-
insert into t values (42);
99-
prepare transaction 'x';
100-
commit prepared 'x';
101-
SQL
102-
pkill -9 postgres
103-
./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile start
104-
# ./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile restart
105-
psql <<SQL
106-
begin;
107-
insert into t values (42);
95+
# pkill -9 postgres
96+
# reinit_master >> /dev/null
97+
# psql <<SQL
98+
# begin;
99+
# insert into t values (42);
100+
# prepare transaction 'x';
101+
# commit prepared 'x';
102+
# SQL
103+
# pkill -9 postgres
104+
# ./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile start
105+
# psql <<SQL
106+
# begin;
107+
# insert into t values (42);
108108

109-
-- This prepare can fail due to 2pc identifier conflict if replay
110-
-- didn't clean proc and gxact on commit.
111-
prepare transaction 'x';
112-
SQL
109+
# -- This prepare can fail due to 2pc identifier or locks conflict if replay
110+
# -- didn't clean proc, gxact and locks on commit.
111+
# prepare transaction 'x';
112+
# SQL
113113

114114

115115

@@ -127,27 +127,140 @@ SQL
127127
# begin;
128128
# insert into t values (42);
129129
# prepare transaction 'x';
130+
# commit prepared 'x';
130131
# SQL
132+
# echo "Following list should be empty:"
133+
# psql -tc 'select * from pg_prepared_xacts;' -p 5433
134+
135+
136+
# cat <<MSG
137+
# ###############################################################################
138+
# # The same as in previous case, but let's force checkpoint on slave between
139+
# # prepare and commit.
140+
# ###############################################################################
141+
# MSG
142+
131143
# pkill -9 postgres
132-
# ./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile start
144+
# reinit_master >> /dev/null
145+
# reinit_slave >> /dev/null
146+
# psql <<SQL
147+
# begin;
148+
# insert into t values (42);
149+
# prepare transaction 'x';
150+
# SQL
151+
# psql -p 5433 <<SQL
152+
# checkpoint;
153+
# SQL
133154
# psql <<SQL
134155
# commit prepared 'x';
135156
# SQL
136157
# echo "Following list should be empty:"
137158
# psql -tc 'select * from pg_prepared_xacts;' -p 5433
138159

139160

161+
# cat <<MSG
162+
# ###############################################################################
163+
# # Check that we can commit transaction on promoted slave.
164+
# ###############################################################################
165+
# MSG
140166

167+
# pkill -9 postgres
168+
# reinit_master >> /dev/null
169+
# reinit_slave >> /dev/null
170+
# psql <<SQL
171+
# begin;
172+
# insert into t values (42);
173+
# prepare transaction 'x';
174+
# SQL
175+
# kill -9 `cat install/data/postmaster.pid | head -n 1`
176+
# ./install/bin/pg_ctl promote -D ./install/data_slave
177+
# sleep 1 # is there a clever way to wait for promotion?
178+
# psql -p 5433 <<SQL
179+
# commit prepared 'x';
180+
# SQL
141181

142182

183+
# cat <<MSG
184+
# ###############################################################################
185+
# # Check StandbyRecoverPreparedTransactions
186+
# ###############################################################################
187+
# MSG
143188

189+
# pkill -9 postgres
190+
# reinit_master
191+
# reinit_slave
192+
# psql <<SQL
193+
# begin;
194+
# insert into t values (42);
195+
# savepoint s1;
196+
# insert into t values (43);
197+
# prepare transaction 'x';
198+
# insert into t values (100);
199+
# SQL
200+
# # kill -9 `cat install/data_slave/postmaster.pid | head -n 1`
201+
# # sleep 1
202+
# ./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile stop
203+
# # ./install/bin/pg_ctl -w -D ./install/data_slave -l ./install/data_slave/logfile restart
204+
# # ./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile start
205+
# ./install/bin/pg_ctl promote -D ./install/data_slave
206+
# sleep 6 # is there a clever way to wait for promotion?
207+
# psql -p5433 <<SQL
208+
# commit prepared 'x';
209+
# SQL
144210

145211

146212

147213

214+
cat <<MSG
215+
###############################################################################
216+
# Check that we can commit after soft restart.
217+
# Here checkpoint happens before shutdown and no WAL replay will not occur
218+
# during start. So code should re-create memory state from files.
219+
###############################################################################
220+
MSG
221+
222+
pkill -9 postgres
223+
reinit_master >> /dev/null
224+
psql <<SQL
225+
begin;
226+
insert into t values (42);
227+
savepoint s1;
228+
insert into t values (43);
229+
prepare transaction 'x';
230+
insert into t values (100);
231+
SQL
232+
./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile restart
233+
psql <<SQL
234+
commit prepared 'x';
235+
SQL
148236

149237

150238

239+
cat <<MSG
240+
###############################################################################
241+
# Check that we can commit after hard restart.
242+
# On startup WAL replay will re-create memory for global transactions that
243+
# happend after last checkpoint and stored. After that
244+
###############################################################################
245+
MSG
246+
247+
pkill -9 postgres
248+
reinit_master >> /dev/null
249+
psql <<SQL
250+
begin;
251+
insert into t values (42);
252+
savepoint s1;
253+
insert into t values (43);
254+
select txid_current();
255+
prepare transaction 'x';
256+
SQL
257+
pkill -9 postgres
258+
./install/bin/pg_ctl -w -D ./install/data -l ./install/data/logfile start
259+
psql <<SQL
260+
select txid_current();
261+
insert into t values (44);
262+
commit prepared 'x';
263+
SQL
151264

152265

153266

src/backend/access/transam/twophase.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
17151715
int nxids = 0;
17161716
int allocsize = 0;
17171717

1718-
fprintf(stderr, "===(%u) PrescanPreparedTransactions called\n", getpid());
1718+
fprintf(stderr, "===(%u) PrescanPreparedTransactions called. result = %u\n", getpid(), result);
17191719

17201720
cldir = AllocateDir(TWOPHASE_DIR);
17211721
while ((clde = ReadDir(cldir, TWOPHASE_DIR)) != NULL)
@@ -1831,6 +1831,7 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
18311831
*nxids_p = nxids;
18321832
}
18331833

1834+
fprintf(stderr, "===(%u) PrescanPreparedTransactions ended. result = %u\n", getpid(), result);
18341835
return result;
18351836
}
18361837

@@ -1852,7 +1853,7 @@ StandbyRecoverPreparedTransactions(bool overwriteOK)
18521853
DIR *cldir;
18531854
struct dirent *clde;
18541855

1855-
fprintf(stderr, "===(%u) StandbyRecoverPreparedTransactions called\n", getpid());
1856+
fprintf(stderr, "!===(%u) StandbyRecoverPreparedTransactions called, overwriteOK = %u\n", getpid(), (int)overwriteOK);
18561857

18571858
cldir = AllocateDir(TWOPHASE_DIR);
18581859
while ((clde = ReadDir(cldir, TWOPHASE_DIR)) != NULL)

src/backend/access/transam/xlog.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6042,6 +6042,8 @@ StartupXLOG(void)
60426042
{
60436043
List *tablespaces = NIL;
60446044

6045+
fprintf(stderr, "!= label file found\n");
6046+
60456047
/*
60466048
* Archive recovery was requested, and thanks to the backup label
60476049
* file, we know how far we need to replay to reach consistency. Enter
@@ -6125,6 +6127,8 @@ StartupXLOG(void)
61256127
}
61266128
else
61276129
{
6130+
fprintf(stderr, "!= no label file found\n");
6131+
61286132
/*
61296133
* If tablespace_map file is present without backup_label file, there
61306134
* is no use of such file. There is no harm in retaining it, but it
@@ -6575,6 +6579,8 @@ StartupXLOG(void)
65756579
StartupCLOG();
65766580
StartupSUBTRANS(oldestActiveXID);
65776581

6582+
fprintf(stderr, "!!!!!!!!!!!!!!! \n");
6583+
65786584
/*
65796585
* If we're beginning at a shutdown checkpoint, we know that
65806586
* nothing was running on the master at this point. So fake-up an
@@ -9236,6 +9242,8 @@ xlog_redo(XLogReaderState *record)
92369242
ereport(PANIC,
92379243
(errmsg("online backup was canceled, recovery cannot continue")));
92389244

9245+
fprintf(stderr, "!_!_!_!_!_!_!_!\n");
9246+
92399247
/*
92409248
* If we see a shutdown checkpoint, we know that nothing was running
92419249
* on the master at this point. So fake-up an empty running-xacts

0 commit comments

Comments
 (0)