Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11ef028

Browse files
committed
[Issue#313] add test incr_restore.IncrRestoreTest.test_incr_restore_issue_313
1 parent3f06d21 commit11ef028

File tree

9 files changed

+101
-17
lines changed

9 files changed

+101
-17
lines changed

‎src/archive.c‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ check_system_identifiers(PGconn *conn, char *pgdata)
983983
uint64system_id_conn;
984984
uint64system_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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ extern XLogRecPtr get_next_record_lsn(const char *archivedir, XLogSegNosegno, T
11391139
externTimeLineIDget_current_timeline(PGconn*conn);
11401140
externTimeLineIDget_current_timeline_from_control(boolsafe);
11411141
externXLogRecPtrget_checkpoint_location(PGconn*conn);
1142-
externuint64get_system_identifier(constchar*pgdata_path);
1142+
externuint64get_system_identifier(constchar*pgdata_path,constchar*pg_control_filename,fio_locationlocation);
11431143
externuint64get_remote_system_identifier(PGconn*conn);
11441144
externuint32get_data_checksum_version(boolsafe);
11451145
externpg_crc32cget_pgcontrol_checksum(constchar*pgdata_path);

‎src/restore.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,7 @@ check_incremental_compatibility(const char *pgdata, uint64 system_identifier,
22332233
boolpostmaster_is_up= false;
22342234
boolbackup_label_exists= false;
22352235
pid_tpid;
2236-
charbackup_label[MAXPGPATH];
2236+
charfilename[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‎

Lines changed: 2 additions & 2 deletions
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(constchar*pgdata_path)
252+
get_system_identifier(constchar*pgdata_path,constchar*pg_control_filename,fio_locationlocation)
253253
{
254254
ControlFileDataControlFile;
255255
char*buffer;
256256
size_tsize;
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
return0;
262262
digestControlFile(&ControlFile,buffer,size);

‎tests/helpers/ptrack_helpers.py‎

Lines changed: 5 additions & 5 deletions
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
ifexclude_dirs:

‎tests/incr_restore.py‎

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
importhashlib
1010
importshutil
1111
importjson
12-
fromtestgresimportQueryException
12+
fromtestgresimportQueryException,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+
deftest_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+
forfileinfilelist:
2479+
# count only nondata files
2480+
ifint(filelist[file]['is_datafile'])==0andint(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+
exceptStartNodeExceptionase:
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+
withopen(os.path.join(node.logs_dir,'postgresql.log'),'r')asf:
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‎

Lines changed: 1 addition & 1 deletion
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
forfileinfilelist:
38853885
# count only nondata files
38863886
ifint(filelist[file]['is_datafile'])==0andint(filelist[file]['size'])>0:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp