Skip to content

Commit 2d3f19e

Browse files
committed
[Issue #169] minor improvements
1 parent 9c662d5 commit 2d3f19e

File tree

2 files changed

+29
-41
lines changed

2 files changed

+29
-41
lines changed

src/data.c

+15-14
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ read_page_from_file(pgFile *file, BlockNumber blknum,
237237
{
238238
int i;
239239
/* Check if the page is zeroed. */
240-
for(i = 0; i < BLCKSZ && page[i] == 0; i++);
240+
for (i = 0; i < BLCKSZ && page[i] == 0; i++);
241241

242242
/* Page is zeroed. No need to check header and checksum. */
243243
if (i == BLCKSZ)
@@ -271,9 +271,10 @@ read_page_from_file(pgFile *file, BlockNumber blknum,
271271
* should be a pointer to allocated BLCKSZ of bytes.
272272
*
273273
* Prints appropriate warnings/errors/etc into log.
274-
* Returns 0 if page was successfully retrieved
275-
* SkipCurrentPage(-3) if we need to skip this page
274+
* Returns:
275+
* PageIsOk(0) if page was successfully retrieved
276276
* PageIsTruncated(-2) if the page was truncated
277+
* SkipCurrentPage(-3) if we need to skip this page
277278
* PageIsCorrupted(-4) if the page check mismatch
278279
*/
279280
static int32
@@ -312,9 +313,8 @@ prepare_page(ConnectionArgs *conn_arg,
312313
switch (result)
313314
{
314315
case 2:
315-
page_is_valid = true;
316316
elog(VERBOSE, "File: \"%s\" blknum %u, empty page", from_fullpath, blknum);
317-
break;
317+
return PageIsOk;
318318

319319
case 1:
320320
page_is_valid = true;
@@ -393,6 +393,12 @@ prepare_page(ConnectionArgs *conn_arg,
393393
}
394394
}
395395

396+
/* Get page via ptrack interface from PostgreSQL shared buffer.
397+
* We do this in following cases:
398+
* 1. PTRACK backup of 1.x versions
399+
* 2. During backup, regardless of backup mode, of PostgreSQL instance
400+
* with ptrack support we encountered invalid page.
401+
*/
396402
if ((backup_mode == BACKUP_MODE_DIFF_PTRACK
397403
&& (ptrack_version_num >= 15 && ptrack_version_num < 20))
398404
|| !page_is_valid)
@@ -434,7 +440,6 @@ prepare_page(ConnectionArgs *conn_arg,
434440
!parse_page(page, &page_lsn))
435441
elog(ERROR, "Cannot parse page after pg_ptrack_get_block. "
436442
"Possible risk of a memory corruption");
437-
438443
}
439444

440445
if (page_is_truncated)
@@ -1260,22 +1265,18 @@ create_empty_file(fio_location from_location, const char *to_root,
12601265
/* open file for write */
12611266
join_path_components(to_path, to_root, file->rel_path);
12621267
out = fio_fopen(to_path, PG_BINARY_W, to_location);
1268+
12631269
if (out == NULL)
1264-
{
1265-
elog(ERROR, "cannot open destination file \"%s\": %s",
1270+
elog(ERROR, "Cannot open destination file \"%s\": %s",
12661271
to_path, strerror(errno));
1267-
}
12681272

12691273
/* update file permission */
12701274
if (fio_chmod(to_path, file->mode, to_location) == -1)
1271-
{
1272-
fio_fclose(out);
1273-
elog(ERROR, "cannot change mode of \"%s\": %s", to_path,
1275+
elog(ERROR, "Cannot change mode of \"%s\": %s", to_path,
12741276
strerror(errno));
1275-
}
12761277

12771278
if (fio_fclose(out))
1278-
elog(ERROR, "cannot close \"%s\": %s", to_path, strerror(errno));
1279+
elog(ERROR, "Cannot close \"%s\": %s", to_path, strerror(errno));
12791280

12801281
return true;
12811282
}

src/restore.c

+14-27
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,11 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
697697
if (S_ISDIR(dest_file->mode))
698698
continue;
699699

700+
/* skip external files if ordered to do so */
701+
if (dest_file->external_dir_num > 0 &&
702+
params->skip_external_dirs)
703+
continue;
704+
700705
/* construct fullpath */
701706
if (dest_file->external_dir_num == 0)
702707
{
@@ -708,7 +713,7 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
708713
}
709714
else
710715
{
711-
char *external_path = parray_get(external_dirs, dest_file->external_dir_num - 1);
716+
char *external_path = parray_get(external_dirs, dest_file->external_dir_num - 1);
712717
join_path_components(to_fullpath, external_path, dest_file->rel_path);
713718
}
714719

@@ -831,8 +836,10 @@ restore_files(void *arg)
831836
to_fullpath, strerror(errno_tmp));
832837
}
833838

834-
if (!fio_is_remote_file(out))
835-
setbuf(out, buffer);
839+
/* update file permission */
840+
if (fio_chmod(to_fullpath, dest_file->mode, FIO_DB_HOST) == -1)
841+
elog(ERROR, "Cannot change mode of \"%s\": %s", to_fullpath,
842+
strerror(errno));
836843

837844
if (!dest_file->is_datafile || dest_file->is_cfs)
838845
elog(VERBOSE, "Restoring non-data file: \"%s\"", to_fullpath);
@@ -843,6 +850,9 @@ restore_files(void *arg)
843850
if (dest_file->write_size == 0)
844851
goto done;
845852

853+
if (!fio_is_remote_file(out))
854+
setbuf(out, buffer);
855+
846856
/* Restore destination file */
847857
if (dest_file->is_datafile && !dest_file->is_cfs)
848858
/* Destination file is data file */
@@ -853,30 +863,7 @@ restore_files(void *arg)
853863
arguments->restored_bytes += restore_non_data_file(arguments->parent_chain,
854864
arguments->dest_backup, dest_file, out, to_fullpath);
855865

856-
/*
857-
* Destination file is data file.
858-
* Iterate over incremental chain and lookup given destination file.
859-
* Apply changed blocks to destination file from every backup in parent chain.
860-
*/
861-
862-
done:
863-
864-
/* Truncate file up to n_blocks. NOTE: no need, we just should not write
865-
* blocks that are exceeding n_blocks.
866-
* But for this to work, n_blocks should be trusted.
867-
*/
868-
869-
/* update file permission
870-
* TODO: chmod must be done right after fopen()
871-
*/
872-
if (fio_chmod(to_fullpath, dest_file->mode, FIO_DB_HOST) == -1)
873-
{
874-
int errno_tmp = errno;
875-
fio_fclose(out);
876-
elog(ERROR, "Cannot change mode of \"%s\": %s", to_fullpath,
877-
strerror(errno_tmp));
878-
}
879-
866+
done:
880867
/* close file */
881868
if (fio_fclose(out) != 0)
882869
elog(ERROR, "Cannot close file \"%s\": %s", to_fullpath,

0 commit comments

Comments
 (0)