Skip to content

Commit 83d2fb3

Browse files
committed
PGPRO-1457: minor changes proposed by Arthur Zakirov
1 parent e29a5db commit 83d2fb3

File tree

3 files changed

+41
-43
lines changed

3 files changed

+41
-43
lines changed

src/data.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,20 @@ backup_data_page(backup_files_args *arguments,
316316
if (is_checksum_enabled)
317317
((PageHeader) page)->pd_checksum = pg_checksum_page(page, absolute_blknum);
318318
}
319-
/* get lsn from page */
319+
/* get lsn from page, provided by pg_ptrack_get_block() */
320320
if (backup_mode == BACKUP_MODE_DIFF_DELTA &&
321-
file->exists_in_prev &&
322-
header.compressed_size != PageIsTruncated &&
323-
!parse_page(page, &page_lsn))
324-
elog(ERROR, "Cannot parse page after pg_ptrack_get_block. "
325-
"Possible risk of a memory corruption");
321+
file->exists_in_prev &&
322+
header.compressed_size != PageIsTruncated &&
323+
!parse_page(page, &page_lsn))
324+
elog(ERROR, "Cannot parse page after pg_ptrack_get_block. "
325+
"Possible risk of a memory corruption");
326326

327327
}
328328

329329
if (backup_mode == BACKUP_MODE_DIFF_DELTA &&
330-
file->exists_in_prev &&
331-
header.compressed_size != PageIsTruncated &&
332-
page_lsn < prev_backup_start_lsn)
330+
file->exists_in_prev &&
331+
header.compressed_size != PageIsTruncated &&
332+
page_lsn < prev_backup_start_lsn)
333333
{
334334
elog(VERBOSE, "Skipping blknum: %u in file: %s", blknum, file->path);
335335
(*n_skipped)++;

src/restore.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -379,26 +379,6 @@ restore_backup(pgBackup *backup)
379379
pgBackupGetPath(backup, list_path, lengthof(list_path), DATABASE_FILE_LIST);
380380
files = dir_read_file_list(database_path, list_path);
381381

382-
/*
383-
* For PAGE and PTRACK backups remove files which haven't changed
384-
* since previous backup and thus were not backed up.
385-
* We can`t do the same when restoring DELTA backup because we need information
386-
* about every file to correctly truncate them.
387-
*/
388-
if (backup->backup_mode == BACKUP_MODE_DIFF_PAGE ||
389-
backup->backup_mode == BACKUP_MODE_DIFF_PTRACK)
390-
{
391-
for (i = parray_num(files) - 1; i >= 0; i--)
392-
{
393-
pgFile *file = (pgFile *) parray_get(files, i);
394-
if (file->write_size == BYTES_INVALID)
395-
{
396-
elog(VERBOSE, "The file didn`t changed. Skip restore: %s", file->path);
397-
pgFileFree(parray_remove(files, i));
398-
}
399-
}
400-
}
401-
402382
/* setup threads */
403383
for (i = 0; i < parray_num(files); i++)
404384
{
@@ -725,6 +705,20 @@ restore_files(void *arg)
725705
i + 1, (unsigned long) parray_num(arguments->files), rel_path);
726706

727707

708+
/*
709+
* For PAGE and PTRACK backups skip files which haven't changed
710+
* since previous backup and thus were not backed up.
711+
* We cannot do the same when restoring DELTA backup because we need information
712+
* about every file to correctly truncate them.
713+
*/
714+
if (file->write_size == BYTES_INVALID &&
715+
(arguments->backup->backup_mode == BACKUP_MODE_DIFF_PAGE
716+
|| arguments->backup->backup_mode == BACKUP_MODE_DIFF_PTRACK))
717+
{
718+
elog(VERBOSE, "The file didn`t changed. Skip restore: %s", file->path);
719+
continue;
720+
}
721+
728722
/* Directories was created before */
729723
if (S_ISDIR(file->mode))
730724
{

tests/delta.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,10 @@ def test_delta_vacuum_truncate_2(self):
156156

157157
self.backup_node(
158158
backup_dir, 'node', node, backup_type='delta'
159-
# options=['--log-level-file=verbose']
160159
)
161160

162161
self.backup_node(
163162
backup_dir, 'node', node, backup_type='delta'
164-
# options=['--log-level-file=verbose']
165163
)
166164

167165
pgdata = self.pgdata_content(node.data_dir)
@@ -231,25 +229,21 @@ def test_delta_vacuum_truncate_3(self):
231229
"select pg_relation_filepath('t_heap')"
232230
).rstrip()
233231

234-
235232
self.backup_node(backup_dir, 'node', node)
236233

237234
print(os.path.join(node.data_dir, filepath + '.1'))
238235
os.unlink(os.path.join(node.data_dir, filepath + '.1'))
239236

240237
self.backup_node(
241238
backup_dir, 'node', node, backup_type='delta'
242-
# options=['--log-level-file=verbose']
243239
)
244240

245241
self.backup_node(
246242
backup_dir, 'node', node, backup_type='delta'
247-
# options=['--log-level-file=verbose']
248243
)
249244

250245
pgdata = self.pgdata_content(node.data_dir)
251246

252-
253247
self.restore_node(
254248
backup_dir,
255249
'node',
@@ -273,8 +267,10 @@ def test_delta_vacuum_truncate_3(self):
273267

274268
# @unittest.skip("skip")
275269
def test_delta_stream(self):
276-
"""make archive node, take full and delta stream backups, restore them and check data correctness"""
277-
self.maxDiff = None
270+
"""
271+
make archive node, take full and delta stream backups,
272+
restore them and check data correctness
273+
"""
278274
fname = self.id().split('.')[3]
279275
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
280276
node = self.make_simple_node(
@@ -350,7 +346,10 @@ def test_delta_stream(self):
350346

351347
# @unittest.skip("skip")
352348
def test_delta_archive(self):
353-
"""make archive node, take full and delta archive backups, restore them and check data correctness"""
349+
"""
350+
make archive node, take full and delta archive backups,
351+
restore them and check data correctness
352+
"""
354353
self.maxDiff = None
355354
fname = self.id().split('.')[3]
356355
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
@@ -422,9 +421,12 @@ def test_delta_archive(self):
422421
# Clean after yourself
423422
self.del_test_dir(module_name, fname)
424423

425-
# @unittest.skip("skip")
424+
@unittest.skip("skip")
426425
def test_delta_multiple_segments(self):
427-
"""Make node, create table with multiple segments, write some data to it, check delta and data correctness"""
426+
"""
427+
Make node, create table with multiple segments,
428+
write some data to it, check delta and data correctness
429+
"""
428430
fname = self.id().split('.')[3]
429431
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
430432
node = self.make_simple_node(
@@ -928,8 +930,8 @@ def test_alter_table_set_tablespace_delta(self):
928930
def test_alter_database_set_tablespace_delta(self):
929931
"""
930932
Make node, take full backup, create database,
931-
take delta backup, alter database tablespace location, take delta backup
932-
restore last delta backup.
933+
take delta backup, alter database tablespace location,
934+
take delta backup restore last delta backup.
933935
"""
934936
fname = self.id().split('.')[3]
935937
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
@@ -953,7 +955,9 @@ def test_alter_database_set_tablespace_delta(self):
953955
self.backup_node(backup_dir, 'node', node, options=["--stream"])
954956

955957
# CREATE DATABASE DB1
956-
node.safe_psql("postgres", "create database db1 tablespace = 'somedata'")
958+
node.safe_psql(
959+
"postgres",
960+
"create database db1 tablespace = 'somedata'")
957961
node.safe_psql(
958962
"db1",
959963
"create table t_heap as select i as id, md5(i::text) as text, "

0 commit comments

Comments
 (0)