Skip to content

Commit be07ee7

Browse files
committed
Merge branch 'master' into issue_310
2 parents 8eff099 + f4ab4b9 commit be07ee7

File tree

8 files changed

+196
-17
lines changed

8 files changed

+196
-17
lines changed

src/backup.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,8 +1574,13 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
15741574
*/
15751575
if (pg_stop_backup_is_sent && !in_cleanup)
15761576
{
1577+
int timeout = ARCHIVE_TIMEOUT_DEFAULT;
15771578
res = NULL;
15781579

1580+
/* kludge against some old bug in archive_timeout. TODO: remove in 3.0.0 */
1581+
if (instance_config.archive_timeout > 0)
1582+
timeout = instance_config.archive_timeout;
1583+
15791584
while (1)
15801585
{
15811586
if (!PQconsumeInput(conn))
@@ -1600,11 +1605,10 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
16001605
* If postgres haven't answered in archive_timeout seconds,
16011606
* send an interrupt.
16021607
*/
1603-
if (pg_stop_backup_timeout > instance_config.archive_timeout)
1608+
if (pg_stop_backup_timeout > timeout)
16041609
{
16051610
pgut_cancel(conn);
1606-
elog(ERROR, "pg_stop_backup doesn't answer in %d seconds, cancel it",
1607-
instance_config.archive_timeout);
1611+
elog(ERROR, "pg_stop_backup doesn't answer in %d seconds, cancel it", timeout);
16081612
}
16091613
}
16101614
else

src/catalog.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -973,17 +973,11 @@ catalog_get_backup_list(const char *instance_name, time_t requested_backup_id)
973973
continue;
974974
}
975975
parray_append(backups, backup);
976-
977-
if (errno && errno != ENOENT)
978-
{
979-
elog(WARNING, "cannot read data directory \"%s\": %s",
980-
data_ent->d_name, strerror(errno));
981-
goto err_proc;
982-
}
983976
}
977+
984978
if (errno)
985979
{
986-
elog(WARNING, "cannot read backup root directory \"%s\": %s",
980+
elog(WARNING, "Cannot read backup root directory \"%s\": %s",
987981
backup_instance_path, strerror(errno));
988982
goto err_proc;
989983
}

src/configure.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ do_set_config(bool missing_ok)
299299

300300
for (i = 0; instance_options[i].type; i++)
301301
{
302+
int rc = 0;
302303
ConfigOption *opt = &instance_options[i];
303304
char *value;
304305

@@ -319,13 +320,25 @@ do_set_config(bool missing_ok)
319320
}
320321

321322
if (strchr(value, ' '))
322-
fprintf(fp, "%s = '%s'\n", opt->lname, value);
323+
rc = fprintf(fp, "%s = '%s'\n", opt->lname, value);
323324
else
324-
fprintf(fp, "%s = %s\n", opt->lname, value);
325+
rc = fprintf(fp, "%s = %s\n", opt->lname, value);
326+
327+
if (rc < 0)
328+
elog(ERROR, "Cannot write to configuration file: \"%s\"", path_temp);
329+
325330
pfree(value);
326331
}
327332

328-
fclose(fp);
333+
if (ferror(fp) || fflush(fp))
334+
elog(ERROR, "Cannot write to configuration file: \"%s\"", path_temp);
335+
336+
if (fclose(fp))
337+
elog(ERROR, "Cannot close configuration file: \"%s\"", path_temp);
338+
339+
if (fio_sync(path_temp, FIO_LOCAL_HOST) != 0)
340+
elog(ERROR, "Failed to sync temp configuration file \"%s\": %s",
341+
path_temp, strerror(errno));
329342

330343
if (rename(path_temp, path) < 0)
331344
{

src/pg_probackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ typedef enum ShowFormat
306306
#define BYTES_INVALID (-1) /* file didn`t changed since previous backup, DELTA backup do not rely on it */
307307
#define FILE_NOT_FOUND (-2) /* file disappeared during backup */
308308
#define BLOCKNUM_INVALID (-1)
309-
#define PROGRAM_VERSION "2.4.10"
309+
#define PROGRAM_VERSION "2.4.11"
310310

311311
/* update when remote agent API or behaviour changes */
312312
#define AGENT_PROTOCOL_VERSION 20409

src/validate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,8 @@ validate_tablespace_map(pgBackup *backup)
716716
pgFile **tablespace_map = NULL;
717717
pg_crc32 crc;
718718
parray *files = get_backup_filelist(backup, true);
719+
bool use_crc32c = parse_program_version(backup->program_version) <= 20021 ||
720+
parse_program_version(backup->program_version) >= 20025;
719721

720722
parray_qsort(files, pgFileCompareRelPathWithExternal);
721723
join_path_components(map_path, backup->database_dir, PG_TABLESPACE_MAP_FILE);
@@ -738,7 +740,7 @@ validate_tablespace_map(pgBackup *backup)
738740
map_path, base36enc(backup->backup_id));
739741

740742
/* check tablespace map checksumms */
741-
crc = pgFileGetCRC(map_path, true, false);
743+
crc = pgFileGetCRC(map_path, use_crc32c, false);
742744

743745
if ((*tablespace_map)->crc != crc)
744746
elog(ERROR, "Invalid CRC of tablespace map file \"%s\" : %X. Expected %X, "

tests/archive.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,90 @@ def test_basic_master_and_replica_concurrent_archiving(self):
983983
# Clean after yourself
984984
self.del_test_dir(module_name, fname)
985985

986+
987+
# @unittest.expectedFailure
988+
# @unittest.skip("skip")
989+
def test_concurrent_archiving(self):
990+
"""
991+
Concurrent archiving from master, replica and cascade replica
992+
https://github.com/postgrespro/pg_probackup/issues/327
993+
994+
For PG >= 11 it is expected to pass this test
995+
"""
996+
997+
if self.pg_config_version < self.version_to_num('11.0'):
998+
return unittest.skip('You need PostgreSQL >= 11 for this test')
999+
1000+
fname = self.id().split('.')[3]
1001+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
1002+
master = self.make_simple_node(
1003+
base_dir=os.path.join(module_name, fname, 'master'),
1004+
set_replication=True,
1005+
initdb_params=['--data-checksums'],
1006+
pg_options={'autovacuum': 'off'})
1007+
1008+
self.init_pb(backup_dir)
1009+
self.add_instance(backup_dir, 'node', master)
1010+
self.set_archiving(backup_dir, 'node', master, replica=True)
1011+
master.slow_start()
1012+
1013+
master.pgbench_init(scale=10)
1014+
1015+
# TAKE FULL ARCHIVE BACKUP FROM MASTER
1016+
self.backup_node(backup_dir, 'node', master)
1017+
1018+
# Settings for Replica
1019+
replica = self.make_simple_node(
1020+
base_dir=os.path.join(module_name, fname, 'replica'))
1021+
replica.cleanup()
1022+
self.restore_node(backup_dir, 'node', replica)
1023+
1024+
self.set_replica(master, replica, synchronous=True)
1025+
self.set_archiving(backup_dir, 'node', replica, replica=True)
1026+
self.set_auto_conf(replica, {'port': replica.port})
1027+
replica.slow_start(replica=True)
1028+
1029+
# create cascade replicas
1030+
replica1 = self.make_simple_node(
1031+
base_dir=os.path.join(module_name, fname, 'replica1'))
1032+
replica1.cleanup()
1033+
1034+
# Settings for casaced replica
1035+
self.restore_node(backup_dir, 'node', replica1)
1036+
self.set_replica(replica, replica1, synchronous=False)
1037+
self.set_auto_conf(replica1, {'port': replica1.port})
1038+
replica1.slow_start(replica=True)
1039+
1040+
# Take full backup from master
1041+
self.backup_node(backup_dir, 'node', master)
1042+
1043+
pgbench = master.pgbench(
1044+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
1045+
options=['-T', '30', '-c', '1'])
1046+
1047+
# Take several incremental backups from master
1048+
self.backup_node(backup_dir, 'node', master, backup_type='page', options=['--no-validate'])
1049+
1050+
self.backup_node(backup_dir, 'node', master, backup_type='page', options=['--no-validate'])
1051+
1052+
pgbench.wait()
1053+
pgbench.stdout.close()
1054+
1055+
with open(os.path.join(master.logs_dir, 'postgresql.log'), 'r') as f:
1056+
log_content = f.read()
1057+
self.assertNotIn('different checksum', log_content)
1058+
1059+
with open(os.path.join(replica.logs_dir, 'postgresql.log'), 'r') as f:
1060+
log_content = f.read()
1061+
self.assertNotIn('different checksum', log_content)
1062+
1063+
with open(os.path.join(replica1.logs_dir, 'postgresql.log'), 'r') as f:
1064+
log_content = f.read()
1065+
self.assertNotIn('different checksum', log_content)
1066+
1067+
# Clean after yourself
1068+
self.del_test_dir(module_name, fname)
1069+
9861070
# @unittest.expectedFailure
9871071
# @unittest.skip("skip")
9881072
def test_archive_pg_receivexlog(self):

tests/compatibility.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,3 +1419,85 @@ def test_hidden_files(self):
14191419

14201420
# Clean after yourself
14211421
self.del_test_dir(module_name, fname)
1422+
1423+
# @unittest.skip("skip")
1424+
def test_compatibility_tablespace(self):
1425+
"""
1426+
https://github.com/postgrespro/pg_probackup/issues/348
1427+
"""
1428+
fname = self.id().split('.')[3]
1429+
node = self.make_simple_node(
1430+
base_dir=os.path.join(module_name, fname, 'node'),
1431+
set_replication=True,
1432+
initdb_params=['--data-checksums'])
1433+
1434+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
1435+
1436+
self.init_pb(backup_dir)
1437+
self.add_instance(backup_dir, 'node', node, old_binary=True)
1438+
node.slow_start()
1439+
1440+
backup_id = self.backup_node(
1441+
backup_dir, 'node', node, backup_type="full",
1442+
options=["-j", "4", "--stream"], old_binary=True)
1443+
1444+
tblspace_old_path = self.get_tblspace_path(node, 'tblspace_old')
1445+
1446+
self.create_tblspace_in_node(
1447+
node, 'tblspace',
1448+
tblspc_path=tblspace_old_path)
1449+
1450+
node.safe_psql(
1451+
"postgres",
1452+
"create table t_heap_lame tablespace tblspace "
1453+
"as select 1 as id, md5(i::text) as text, "
1454+
"md5(repeat(i::text,10))::tsvector as tsvector "
1455+
"from generate_series(0,1000) i")
1456+
1457+
tblspace_new_path = self.get_tblspace_path(node, 'tblspace_new')
1458+
1459+
node_restored = self.make_simple_node(
1460+
base_dir=os.path.join(module_name, fname, 'node_restored'))
1461+
node_restored.cleanup()
1462+
1463+
try:
1464+
self.restore_node(
1465+
backup_dir, 'node', node_restored,
1466+
options=[
1467+
"-j", "4",
1468+
"-T", "{0}={1}".format(
1469+
tblspace_old_path, tblspace_new_path)])
1470+
# we should die here because exception is what we expect to happen
1471+
self.assertEqual(
1472+
1, 0,
1473+
"Expecting Error because tablespace mapping is incorrect"
1474+
"\n Output: {0} \n CMD: {1}".format(
1475+
repr(self.output), self.cmd))
1476+
except ProbackupException as e:
1477+
self.assertIn(
1478+
'ERROR: Backup {0} has no tablespaceses, '
1479+
'nothing to remap'.format(backup_id),
1480+
e.message,
1481+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
1482+
repr(e.message), self.cmd))
1483+
1484+
self.backup_node(
1485+
backup_dir, 'node', node, backup_type="delta",
1486+
options=["-j", "4", "--stream"], old_binary=True)
1487+
1488+
self.restore_node(
1489+
backup_dir, 'node', node_restored,
1490+
options=[
1491+
"-j", "4",
1492+
"-T", "{0}={1}".format(
1493+
tblspace_old_path, tblspace_new_path)])
1494+
1495+
if self.paranoia:
1496+
pgdata = self.pgdata_content(node.data_dir)
1497+
1498+
if self.paranoia:
1499+
pgdata_restored = self.pgdata_content(node_restored.data_dir)
1500+
self.compare_pgdata(pgdata, pgdata_restored)
1501+
1502+
# Clean after yourself
1503+
self.del_test_dir(module_name, fname)

tests/expected/option_version.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pg_probackup 2.4.10
1+
pg_probackup 2.4.11

0 commit comments

Comments
 (0)