Skip to content

Commit 11ef028

Browse files
committed
[Issue #313] add test incr_restore.IncrRestoreTest.test_incr_restore_issue_313
1 parent 3f06d21 commit 11ef028

9 files changed

+101
-17
lines changed

src/archive.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
148148
elog(ERROR, "getcwd() error");
149149

150150
/* verify that archive-push --instance parameter is valid */
151-
system_id = get_system_identifier(current_dir);
151+
system_id = get_system_identifier(current_dir, XLOG_CONTROL_FILE, FIO_DB_HOST);
152152

153153
if (instance->pgdata == NULL)
154154
elog(ERROR, "Cannot read pg_probackup.conf for this instance");

src/backup.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ check_system_identifiers(PGconn *conn, char *pgdata)
983983
uint64 system_id_conn;
984984
uint64 system_id_pgdata;
985985

986-
system_id_pgdata = get_system_identifier(pgdata);
986+
system_id_pgdata = get_system_identifier(pgdata, XLOG_CONTROL_FILE, FIO_DB_HOST);
987987
system_id_conn = get_remote_system_identifier(conn);
988988

989989
/* for checkdb check only system_id_pgdata and system_id_conn */

src/init.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ do_add_instance(InstanceState *instanceState, InstanceConfig *instance)
5757
"(-D, --pgdata)");
5858

5959
/* Read system_identifier from PGDATA */
60-
instance->system_identifier = get_system_identifier(instance->pgdata);
60+
instance->system_identifier = get_system_identifier(instance->pgdata, XLOG_CONTROL_FILE, FIO_DB_HOST);
6161
/* Starting from PostgreSQL 11 read WAL segment size from PGDATA */
6262
instance->xlog_seg_size = get_xlog_seg_size(instance->pgdata);
6363

src/pg_probackup.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ extern XLogRecPtr get_next_record_lsn(const char *archivedir, XLogSegNo segno, T
11391139
extern TimeLineID get_current_timeline(PGconn *conn);
11401140
extern TimeLineID get_current_timeline_from_control(bool safe);
11411141
extern XLogRecPtr get_checkpoint_location(PGconn *conn);
1142-
extern uint64 get_system_identifier(const char *pgdata_path);
1142+
extern uint64 get_system_identifier(const char *pgdata_path, const char *pg_control_filename, fio_location location);
11431143
extern uint64 get_remote_system_identifier(PGconn *conn);
11441144
extern uint32 get_data_checksum_version(bool safe);
11451145
extern pg_crc32c get_pgcontrol_checksum(const char *pgdata_path);

src/restore.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,7 @@ check_incremental_compatibility(const char *pgdata, uint64 system_identifier,
22332233
bool postmaster_is_up = false;
22342234
bool backup_label_exists = false;
22352235
pid_t pid;
2236-
char backup_label[MAXPGPATH];
2236+
char filename[MAXPGPATH];
22372237

22382238
/* check postmaster pid */
22392239
pid = fio_check_postmaster(pgdata, FIO_DB_HOST);
@@ -2268,7 +2268,12 @@ check_incremental_compatibility(const char *pgdata, uint64 system_identifier,
22682268
*/
22692269
elog(INFO, "Trying to read pg_control file in destination direstory");
22702270

2271-
system_id_pgdata = get_system_identifier(pgdata);
2271+
/* [Issue #313] check for previous failed incremental restore */
2272+
join_path_components(filename, instance_config.pgdata, XLOG_CONTROL_BAK_FILE);
2273+
if (fio_access(filename, F_OK, FIO_DB_HOST) == 0)
2274+
system_id_pgdata = get_system_identifier(pgdata, XLOG_CONTROL_BAK_FILE, FIO_DB_HOST);
2275+
else
2276+
system_id_pgdata = get_system_identifier(pgdata, XLOG_CONTROL_FILE, FIO_DB_HOST);
22722277

22732278
if (system_id_pgdata == instance_config.system_identifier)
22742279
system_id_match = true;
@@ -2283,8 +2288,8 @@ check_incremental_compatibility(const char *pgdata, uint64 system_identifier,
22832288
*/
22842289
if (incremental_mode == INCR_LSN)
22852290
{
2286-
join_path_components(backup_label, pgdata, "backup_label");
2287-
if (fio_access(backup_label, F_OK, FIO_DB_HOST) == 0)
2291+
join_path_components(filename, pgdata, PG_BACKUP_LABEL_FILE);
2292+
if (fio_access(filename, F_OK, FIO_DB_HOST) == 0)
22882293
{
22892294
elog(WARNING, "Destination directory contains \"backup_control\" file. "
22902295
"This does NOT mean that you should delete this file and retry, only that "

src/util.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,14 @@ get_checkpoint_location(PGconn *conn)
249249
}
250250

251251
uint64
252-
get_system_identifier(const char *pgdata_path)
252+
get_system_identifier(const char *pgdata_path, const char *pg_control_filename, fio_location location)
253253
{
254254
ControlFileData ControlFile;
255255
char *buffer;
256256
size_t size;
257257

258258
/* First fetch file... */
259-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size, false, FIO_DB_HOST);
259+
buffer = slurpFile(pgdata_path, pg_control_filename, &size, false, location);
260260
if (buffer == NULL)
261261
return 0;
262262
digestControlFile(&ControlFile, buffer, size);

tests/helpers/ptrack_helpers.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1602,11 +1602,11 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
16021602
files_to_ignore = [
16031603
'postmaster.pid', 'postmaster.opts',
16041604
'pg_internal.init', 'postgresql.auto.conf',
1605-
'backup_label', 'tablespace_map', 'recovery.conf',
1606-
'ptrack_control', 'ptrack_init', 'pg_control',
1607-
'probackup_recovery.conf', 'recovery.signal',
1608-
'standby.signal', 'ptrack.map', 'ptrack.map.mmap',
1609-
'ptrack.map.tmp'
1605+
'backup_label', 'backup_label.old', 'tablespace_map',
1606+
'recovery.conf', 'recovery.done', 'ptrack_control',
1607+
'ptrack_init', 'pg_control', 'probackup_recovery.conf',
1608+
'recovery.signal', 'standby.signal',
1609+
'ptrack.map', 'ptrack.map.mmap', 'ptrack.map.tmp'
16101610
]
16111611

16121612
if exclude_dirs:

tests/incr_restore.py

+80-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import hashlib
1010
import shutil
1111
import json
12-
from testgres import QueryException
12+
from testgres import QueryException, StartNodeException
1313

1414

1515
module_name = 'incr_restore'
@@ -2436,3 +2436,82 @@ def test_incremental_pg_filenode_map(self):
24362436
self.del_test_dir(module_name, fname)
24372437

24382438
# check that MinRecPoint and BackupStartLsn are correctly used in case of --incrementa-lsn
2439+
2440+
2441+
# @unittest.skip("skip")
2442+
def test_incr_restore_issue_313(self):
2443+
"""
2444+
Check that failed incremental restore can be restarted
2445+
"""
2446+
fname = self.id().split('.')[3]
2447+
2448+
node = self.make_simple_node(
2449+
base_dir = os.path.join(module_name, fname, 'node'),
2450+
set_replication = True,
2451+
initdb_params = ['--data-checksums'])
2452+
2453+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
2454+
self.init_pb(backup_dir)
2455+
self.add_instance(backup_dir, 'node', node)
2456+
self.set_archiving(backup_dir, 'node', node)
2457+
node.slow_start()
2458+
2459+
node.pgbench_init(scale = 50)
2460+
2461+
full_backup_id = self.backup_node(backup_dir, 'node', node, backup_type='full')
2462+
2463+
pgbench = node.pgbench(
2464+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
2465+
options=['-T', '10', '-c', '1', '--no-vacuum'])
2466+
pgbench.wait()
2467+
pgbench.stdout.close()
2468+
2469+
last_backup_id = self.backup_node(backup_dir, 'node', node, backup_type='delta')
2470+
2471+
pgdata = self.pgdata_content(node.data_dir)
2472+
node.cleanup()
2473+
2474+
self.restore_node(backup_dir, 'node', node, backup_id=full_backup_id)
2475+
2476+
count = 0
2477+
filelist = self.get_backup_filelist(backup_dir, 'node', last_backup_id)
2478+
for file in filelist:
2479+
# count only nondata files
2480+
if int(filelist[file]['is_datafile']) == 0 and int(filelist[file]['size']) > 0:
2481+
count += 1
2482+
2483+
gdb = self.restore_node(backup_dir, 'node', node, gdb=True,
2484+
backup_id=last_backup_id, options=['--progress', '--incremental-mode=checksum'])
2485+
gdb.verbose = False
2486+
gdb.set_breakpoint('restore_non_data_file')
2487+
gdb.run_until_break()
2488+
gdb.continue_execution_until_break(count - 2)
2489+
gdb.quit()
2490+
2491+
try:
2492+
node.slow_start()
2493+
# we should die here because exception is what we expect to happen
2494+
self.assertEqual(
2495+
1, 0,
2496+
"Expecting Error because backup is not fully restored")
2497+
except StartNodeException as e:
2498+
self.assertIn(
2499+
'Cannot start node',
2500+
e.message,
2501+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
2502+
repr(e.message), self.cmd))
2503+
2504+
with open(os.path.join(node.logs_dir, 'postgresql.log'), 'r') as f:
2505+
self.assertIn(
2506+
"postgres: could not find the database system",
2507+
f.read())
2508+
2509+
self.restore_node(backup_dir, 'node', node,
2510+
backup_id=last_backup_id, options=['--progress', '--incremental-mode=checksum'])
2511+
node.slow_start()
2512+
2513+
self.compare_pgdata(pgdata, self.pgdata_content(node.data_dir))
2514+
2515+
# Clean after yourself
2516+
node.stop()
2517+
self.del_test_dir(module_name, fname)

tests/restore.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3880,7 +3880,7 @@ def test_restore_issue_313(self):
38803880
node.cleanup()
38813881

38823882
count = 0
3883-
filelist = self.get_backup_filelist(backup_dir, 'node', backup_id)
3883+
filelist = self.get_backup_filelist(backup_dir, 'node', backup_id)
38843884
for file in filelist:
38853885
# count only nondata files
38863886
if int(filelist[file]['is_datafile']) == 0 and int(filelist[file]['size']) > 0:

0 commit comments

Comments
 (0)