Skip to content

Commit 8b8a79f

Browse files
committed
Merge branch 'release_2_4' into issue_66
2 parents 2c39666 + 4fd6ba1 commit 8b8a79f

File tree

6 files changed

+58
-139
lines changed

6 files changed

+58
-139
lines changed

src/backup.c

+26-44
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void *backup_files(void *arg);
8383
static void do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool backup_logs);
8484

8585
static void pg_start_backup(const char *label, bool smooth, pgBackup *backup,
86-
PGNodeInfo *nodeInfo, PGconn *backup_conn, PGconn *master_conn);
86+
PGNodeInfo *nodeInfo, PGconn *conn);
8787
static void pg_switch_wal(PGconn *conn);
8888
static void pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn, PGNodeInfo *nodeInfo);
8989
static int checkpoint_timeout(PGconn *backup_conn);
@@ -149,9 +149,6 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
149149
parray *external_dirs = NULL;
150150
parray *database_map = NULL;
151151

152-
PGconn *master_conn = NULL;
153-
PGconn *pg_startbackup_conn = NULL;
154-
155152
/* used for multitimeline incremental backup */
156153
parray *tli_list = NULL;
157154

@@ -168,13 +165,34 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
168165
check_external_for_tablespaces(external_dirs, backup_conn);
169166
}
170167

168+
/* Clear ptrack files for not PTRACK backups */
169+
if (current.backup_mode != BACKUP_MODE_DIFF_PTRACK && nodeInfo->is_ptrack_enable)
170+
pg_ptrack_clear(backup_conn, nodeInfo->ptrack_version_num);
171+
172+
/* notify start of backup to PostgreSQL server */
173+
time2iso(label, lengthof(label), current.start_time);
174+
strncat(label, " with pg_probackup", lengthof(label) -
175+
strlen(" with pg_probackup"));
176+
177+
/* Call pg_start_backup function in PostgreSQL connect */
178+
pg_start_backup(label, smooth_checkpoint, &current, nodeInfo, backup_conn);
179+
171180
/* Obtain current timeline */
172181
#if PG_VERSION_NUM >= 90600
173182
current.tli = get_current_timeline(backup_conn);
174183
#else
175184
current.tli = get_current_timeline_from_control(false);
176185
#endif
177186

187+
/* In PAGE mode or in ARCHIVE wal-mode wait for current segment */
188+
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE ||!stream_wal)
189+
/*
190+
* Do not wait start_lsn for stream backup.
191+
* Because WAL streaming will start after pg_start_backup() in stream
192+
* mode.
193+
*/
194+
wait_wal_lsn(current.start_lsn, true, current.tli, false, true, ERROR, false);
195+
178196
/*
179197
* In incremental backup mode ensure that already-validated
180198
* backup on current timeline exists and get its filelist.
@@ -252,29 +270,6 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
252270
}
253271
}
254272

255-
/* Clear ptrack files for FULL and PAGE backup */
256-
if (current.backup_mode != BACKUP_MODE_DIFF_PTRACK && nodeInfo->is_ptrack_enable)
257-
pg_ptrack_clear(backup_conn, nodeInfo->ptrack_version_num);
258-
259-
/* notify start of backup to PostgreSQL server */
260-
time2iso(label, lengthof(label), current.start_time);
261-
strncat(label, " with pg_probackup", lengthof(label) -
262-
strlen(" with pg_probackup"));
263-
264-
/* Create connection to master server needed to call pg_start_backup */
265-
if (current.from_replica && exclusive_backup)
266-
{
267-
master_conn = pgut_connect(instance_config.master_conn_opt.pghost,
268-
instance_config.master_conn_opt.pgport,
269-
instance_config.master_conn_opt.pgdatabase,
270-
instance_config.master_conn_opt.pguser);
271-
pg_startbackup_conn = master_conn;
272-
}
273-
else
274-
pg_startbackup_conn = backup_conn;
275-
276-
pg_start_backup(label, smooth_checkpoint, &current, nodeInfo, backup_conn, pg_startbackup_conn);
277-
278273
/* For incremental backup check that start_lsn is not from the past
279274
* Though it will not save us if PostgreSQL instance is actually
280275
* restored STREAM backup.
@@ -342,7 +337,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
342337
* Get database_map (name to oid) for use in partial restore feature.
343338
* It's possible that we fail and database_map will be NULL.
344339
*/
345-
database_map = get_database_map(pg_startbackup_conn);
340+
database_map = get_database_map(backup_conn);
346341

347342
/*
348343
* Append to backup list all files and directories
@@ -571,7 +566,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
571566
}
572567

573568
/* Notify end of backup */
574-
pg_stop_backup(&current, pg_startbackup_conn, nodeInfo);
569+
pg_stop_backup(&current, backup_conn, nodeInfo);
575570

576571
/* In case of backup from replica >= 9.6 we must fix minRecPoint,
577572
* First we must find pg_control in backup_files_list.
@@ -1101,19 +1096,15 @@ confirm_block_size(PGconn *conn, const char *name, int blcksz)
11011096
*/
11021097
static void
11031098
pg_start_backup(const char *label, bool smooth, pgBackup *backup,
1104-
PGNodeInfo *nodeInfo, PGconn *backup_conn, PGconn *pg_startbackup_conn)
1099+
PGNodeInfo *nodeInfo, PGconn *conn)
11051100
{
11061101
PGresult *res;
11071102
const char *params[2];
11081103
uint32 lsn_hi;
11091104
uint32 lsn_lo;
1110-
PGconn *conn;
11111105

11121106
params[0] = label;
11131107

1114-
/* For 9.5 replica we call pg_start_backup() on master */
1115-
conn = pg_startbackup_conn;
1116-
11171108
/* 2nd argument is 'fast'*/
11181109
params[1] = smooth ? "false" : "true";
11191110
if (!exclusive_backup)
@@ -1132,7 +1123,7 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
11321123
* is necessary to call pg_stop_backup() in backup_cleanup().
11331124
*/
11341125
backup_in_progress = true;
1135-
pgut_atexit_push(backup_stopbackup_callback, pg_startbackup_conn);
1126+
pgut_atexit_push(backup_stopbackup_callback, conn);
11361127

11371128
/* Extract timeline and LSN from results of pg_start_backup() */
11381129
XLogDataFromLSN(PQgetvalue(res, 0, 0), &lsn_hi, &lsn_lo);
@@ -1152,15 +1143,6 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
11521143
* (because in 9.5 only superuser can switch WAL)
11531144
*/
11541145
pg_switch_wal(conn);
1155-
1156-
/* In PAGE mode or in ARCHIVE wal-mode wait for current segment */
1157-
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE ||!stream_wal)
1158-
/*
1159-
* Do not wait start_lsn for stream backup.
1160-
* Because WAL streaming will start after pg_start_backup() in stream
1161-
* mode.
1162-
*/
1163-
wait_wal_lsn(backup->start_lsn, true, backup->tli, false, true, ERROR, false);
11641146
}
11651147

11661148
/*

tests/archive.py

+9-20
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,6 @@ def test_replica_archive(self):
765765

766766
before = master.safe_psql("postgres", "SELECT * FROM t_heap")
767767

768-
master.safe_psql(
769-
"postgres",
770-
"CHECKPOINT")
771-
772768
self.wait_until_replica_catch_with_master(master, replica)
773769

774770
backup_id = self.backup_node(
@@ -864,10 +860,6 @@ def test_master_and_replica_parallel_archiving(self):
864860
"md5(repeat(i::text,10))::tsvector as tsvector "
865861
"from generate_series(0, 60000) i")
866862

867-
master.psql(
868-
"postgres",
869-
"CHECKPOINT")
870-
871863
backup_id = self.backup_node(
872864
backup_dir, 'replica', replica,
873865
options=[
@@ -977,10 +969,6 @@ def test_basic_master_and_replica_concurrent_archiving(self):
977969

978970
replica.promote()
979971

980-
replica.safe_psql(
981-
'postgres',
982-
'CHECKPOINT')
983-
984972
master.pgbench_init(scale=10)
985973
replica.pgbench_init(scale=10)
986974

@@ -1221,11 +1209,6 @@ def test_archive_catalog(self):
12211209
# create timeline t2
12221210
replica.promote()
12231211

1224-
# do checkpoint to increment timeline ID in pg_control
1225-
replica.safe_psql(
1226-
'postgres',
1227-
'CHECKPOINT')
1228-
12291212
# FULL backup replica
12301213
A1 = self.backup_node(
12311214
backup_dir, 'replica', replica)
@@ -1959,7 +1942,8 @@ def test_archive_pg_receivexlog_partial_handling(self):
19591942

19601943
replica.slow_start(replica=True)
19611944

1962-
node.safe_psql('postgres', 'CHECKPOINT')
1945+
# FULL
1946+
self.backup_node(backup_dir, 'replica', replica, options=['--stream'])
19631947

19641948
if self.get_version(replica) < 100000:
19651949
pg_receivexlog_path = self.get_bin_path('pg_receivexlog')
@@ -1981,14 +1965,18 @@ def test_archive_pg_receivexlog_partial_handling(self):
19811965
'Failed to start pg_receivexlog: {0}'.format(
19821966
pg_receivexlog.communicate()[1]))
19831967

1968+
replica.safe_psql(
1969+
'postgres',
1970+
'CHECKPOINT')
1971+
19841972
node.safe_psql(
19851973
"postgres",
19861974
"create table t_heap as select i as id, md5(i::text) as text, "
19871975
"md5(repeat(i::text,10))::tsvector as tsvector "
19881976
"from generate_series(0,1000000) i")
19891977

1990-
# FULL
1991-
self.backup_node(backup_dir, 'replica', replica, options=['--stream'])
1978+
# PAGE
1979+
self.backup_node(backup_dir, 'replica', replica, backup_type='page')
19921980

19931981
node.safe_psql(
19941982
"postgres",
@@ -2027,6 +2015,7 @@ def test_archive_pg_receivexlog_partial_handling(self):
20272015
pg_receivexlog.kill()
20282016
self.del_test_dir(module_name, fname)
20292017

2018+
@unittest.skip("skip")
20302019
def test_multi_timeline_recovery_prefetching(self):
20312020
""""""
20322021
fname = self.id().split('.')[3]

tests/backup.py

+12-16
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ def test_page_detect_corruption(self):
324324
node = self.make_simple_node(
325325
base_dir=os.path.join(module_name, fname, 'node'),
326326
set_replication=True,
327+
ptrack_enable=True,
327328
initdb_params=['--data-checksums'])
328329

329330
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
@@ -663,12 +664,10 @@ def test_backup_detect_invalid_block_header(self):
663664
"\n Output: {0} \n CMD: {1}".format(
664665
repr(self.output), self.cmd))
665666
except ProbackupException as e:
666-
self.assertTrue(
667-
'WARNING: page verification failed, '
668-
'calculated checksum' in e.message and
669-
'ERROR: query failed: ERROR: '
670-
'invalid page in block 1 of relation' in e.message and
671-
'ERROR: Data files transferring failed' in e.message,
667+
self.assertIn(
668+
'ERROR: Corruption detected in file "{0}", block 1: '
669+
'page header invalid, pd_lower'.format(heap_fullpath),
670+
e.message,
672671
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
673672
repr(e.message), self.cmd))
674673

@@ -806,12 +805,10 @@ def test_backup_detect_missing_permissions(self):
806805
"\n Output: {0} \n CMD: {1}".format(
807806
repr(self.output), self.cmd))
808807
except ProbackupException as e:
809-
self.assertTrue(
810-
'WARNING: page verification failed, '
811-
'calculated checksum' in e.message and
812-
'ERROR: query failed: ERROR: '
813-
'invalid page in block 1 of relation' in e.message and
814-
'ERROR: Data files transferring failed' in e.message,
808+
self.assertIn(
809+
'ERROR: Corruption detected in file "{0}", block 1: '
810+
'page header invalid, pd_lower'.format(heap_fullpath),
811+
e.message,
815812
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
816813
repr(e.message), self.cmd))
817814

@@ -1480,7 +1477,7 @@ def test_drop_rel_during_backup_ptrack(self):
14801477
node = self.make_simple_node(
14811478
base_dir=os.path.join(module_name, fname, 'node'),
14821479
set_replication=True,
1483-
ptrack_enable=True,
1480+
ptrack_enable=self.ptrack,
14841481
initdb_params=['--data-checksums'])
14851482

14861483
self.init_pb(backup_dir)
@@ -2131,9 +2128,8 @@ def test_backup_with_least_privileges_role(self):
21312128
"TO backup".format(fname))
21322129
else:
21332130
fnames = [
2134-
'pg_catalog.pg_ptrack_get_pagemapset(pg_lsn)',
2135-
'pg_catalog.pg_ptrack_control_lsn()',
2136-
'pg_catalog.pg_ptrack_get_block(oid, oid, oid, bigint)'
2131+
'pg_catalog.ptrack_get_pagemapset(pg_lsn)',
2132+
'pg_catalog.ptrack_init_lsn()'
21372133
]
21382134

21392135
for fname in fnames:

tests/ptrack.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3946,9 +3946,9 @@ def test_ptrack_pg_resetxlog(self):
39463946
repr(self.output), self.cmd)
39473947
)
39483948
except ProbackupException as e:
3949-
self.assertIn(
3950-
'ERROR: LSN from ptrack_control 0/0 differs from Start LSN of previous backup',
3951-
e.message,
3949+
self.assertTrue(
3950+
'ERROR: LSN from ptrack_control ' in e.message and
3951+
'differs from Start LSN of previous backup' in e.message,
39523952
'\n Unexpected Error Message: {0}\n'
39533953
' CMD: {1}'.format(repr(e.message), self.cmd))
39543954

0 commit comments

Comments
 (0)