Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4befab3

Browse files
committed
cleanup, more comments, support old backup format
1 parent 45220ba commit 4befab3

File tree

5 files changed

+59
-27
lines changed

5 files changed

+59
-27
lines changed

contrib/pg_probackup/backup.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,9 @@ file_size(const char *file)
11321132
* Find corresponding file in previous backup.
11331133
* Compare generations and return true if we don't need full copy
11341134
* of the file, but just part of it.
1135+
*
1136+
* skip_size - size of the file in previous backup. We can skip it
1137+
* and copy just remaining part of the file.
11351138
*/
11361139
bool
11371140
backup_compressed_file_partially(pgFile *file, void *arg, size_t *skip_size)
@@ -1423,7 +1426,7 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
14231426
{
14241427
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE)
14251428
elog(ERROR, "You can't use PAGE mode backup with compressed tablespace.\n"
1426-
"Try PTRACK mode instead.");
1429+
"Try FULL or PTRACK mode instead.");
14271430
continue;
14281431
}
14291432

@@ -1776,18 +1779,19 @@ FileMap* cfs_mmap(int md)
17761779
{
17771780
FileMap* map;
17781781
#ifdef WIN32
1779-
HANDLE mh = CreateFileMapping(_get_osfhandle(md), NULL, PAGE_READWRITE,
1782+
HANDLE mh = CreateFileMapping(_get_osfhandle(md), NULL, PAGE_READWRITE,
17801783
0, (DWORD)sizeof(FileMap), NULL);
1781-
if (mh == NULL) {
1784+
if (mh == NULL)
17821785
return (FileMap*)MAP_FAILED;
1783-
}
1784-
map = (FileMap*)MapViewOfFile(mh, FILE_MAP_ALL_ACCESS, 0, 0, 0);
1786+
1787+
map = (FileMap*)MapViewOfFile(mh, FILE_MAP_ALL_ACCESS, 0, 0, 0);
17851788
CloseHandle(mh);
1786-
if (map == NULL) {
1789+
if (map == NULL)
17871790
return (FileMap*)MAP_FAILED;
1788-
}
1791+
17891792
#else
1790-
map = (FileMap*)mmap(NULL, sizeof(FileMap), PROT_WRITE | PROT_READ, MAP_SHARED, md, 0);
1793+
map = (FileMap*)mmap(NULL, sizeof(FileMap),
1794+
PROT_WRITE | PROT_READ, MAP_SHARED, md, 0);
17911795
#endif
17921796
return map;
17931797
}

contrib/pg_probackup/data.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,10 @@ backup_data_file(const char *from_root, const char *to_root,
412412
return true;
413413
}
414414

415-
415+
/*
416+
* Restore compressed file that was backed up partly.
417+
*
418+
*/
416419
static void
417420
restore_file_partly(const char *from_root,const char *to_root, pgFile *file)
418421
{
@@ -491,7 +494,8 @@ restore_file_partly(const char *from_root,const char *to_root, pgFile *file)
491494
write_size += read_len;
492495
}
493496

494-
elog(NOTICE, "restore_file_partly(). write_size %lu, file->write_size %lu", write_size, file->write_size);
497+
// elog(LOG, "restore_file_partly(). %s write_size %lu, file->write_size %lu",
498+
// file->path, write_size, file->write_size);
495499

496500
/* update file permission */
497501
if (chmod(to_path, file->mode) == -1)
@@ -518,7 +522,8 @@ restore_compressed_file(const char *from_root,
518522
else if (file->is_partial_copy == 1)
519523
restore_file_partly(from_root, to_root, file);
520524
else
521-
elog(ERROR, "restore_compressed_file()");
525+
elog(ERROR, "restore_compressed_file(). Unknown is_partial_copy value %d",
526+
file->is_partial_copy);
522527
}
523528

524529
/*
@@ -537,20 +542,18 @@ restore_data_file(const char *from_root,
537542
BackupPageHeader header;
538543
BlockNumber blknum;
539544

540-
/* If the file is not a datafile, just copy it. */
541545
if (!file->is_datafile)
542546
{
547+
/*
548+
* If the file is not a datafile and not compressed file,
549+
* just copy it.
550+
*/
543551
if (file->generation == -1)
544-
{
545552
copy_file(from_root, to_root, file);
546-
return;
547-
}
548553
else
549-
{
550-
/* It is compressed file */
551554
restore_compressed_file(from_root, to_root, file);
552-
return;
553-
}
555+
556+
return;
554557
}
555558

556559
/* open backup mode file for read */
@@ -808,6 +811,11 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
808811
return true;
809812
}
810813

814+
/*
815+
* Save part of the file into backup.
816+
* skip_size - size of the file in previous backup. We can skip it
817+
* and copy just remaining part of the file
818+
*/
811819
bool
812820
copy_file_partly(const char *from_root, const char *to_root,
813821
pgFile *file, size_t skip_size)
@@ -841,6 +849,7 @@ copy_file_partly(const char *from_root, const char *to_root,
841849
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
842850
else
843851
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
852+
844853
out = fopen(to_path, "w");
845854
if (out == NULL)
846855
{
@@ -863,7 +872,10 @@ copy_file_partly(const char *from_root, const char *to_root,
863872
elog(ERROR, "cannot seek %lu of \"%s\": %s",
864873
skip_size, file->path, strerror(errno));
865874

866-
/* copy content and calc CRC */
875+
/*
876+
* copy content
877+
* NOTE: Now CRC is not computed for compressed files now.
878+
*/
867879
for (;;)
868880
{
869881
if ((read_len = fread(buf, 1, sizeof(buf), in)) != sizeof(buf))
@@ -919,8 +931,10 @@ copy_file_partly(const char *from_root, const char *to_root,
919931
strerror(errno_tmp));
920932
}
921933

934+
/* add meta information needed for recovery */
922935
file->is_partial_copy = 1;
923-
elog(NOTICE, "copy_file_partly(). %s file->write_size %lu", to_path, file->write_size);
936+
937+
// elog(LOG, "copy_file_partly(). %s file->write_size %lu", to_path, file->write_size);
924938

925939
fclose(in);
926940
fclose(out);

contrib/pg_probackup/dir.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ dir_read_file_list(const char *root, const char *file_txt)
550550
{
551551
char path[MAXPGPATH];
552552
char type;
553-
int generation;
554-
int is_partial_copy;
553+
int generation = -1;
554+
int is_partial_copy = 0;
555555
unsigned long write_size;
556556
pg_crc32 crc;
557557
unsigned int mode; /* bit length of mode_t depends on platforms */
@@ -565,9 +565,17 @@ dir_read_file_list(const char *root, const char *file_txt)
565565
&tm.tm_hour, &tm.tm_min, &tm.tm_sec,
566566
&generation, &is_partial_copy) != 13)
567567
{
568-
elog(ERROR, "invalid format found in \"%s\"",
569-
file_txt);
568+
/* Maybe the file_list we're trying to recovery is in old format */
569+
if (sscanf(buf, "%s %c %lu %u %o %d-%d-%d %d:%d:%d",
570+
path, &type, &write_size, &crc, &mode,
571+
&tm.tm_year, &tm.tm_mon, &tm.tm_mday,
572+
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 11)
573+
{
574+
elog(ERROR, "invalid format found in \"%s\"",
575+
file_txt);
576+
}
570577
}
578+
571579
if (type != 'f' && type != 'F' && type != 'd' && type != 'l')
572580
{
573581
elog(ERROR, "invalid type '%c' found in \"%s\"",

contrib/pg_probackup/pg_probackup.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "storage/block.h"
2626
#include "storage/checksum.h"
2727

28-
#include "portability/mem.h"
2928
#ifndef WIN32
3029
#include <sys/mman.h>
3130
#endif
@@ -183,7 +182,12 @@ typedef union DataPage
183182
} DataPage;
184183

185184

186-
typedef struct
185+
/*
186+
* This struct definition mirrors one from cfs.h,
187+
* but doesn't use atomic variables, since they are not allowed in
188+
* frontend code.
189+
*/
190+
typedef struct
187191
{
188192
uint32 physSize;
189193
uint32 virtSize;

contrib/pg_probackup/validate.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ pgBackupValidateFiles(void *arg)
199199
elog(ERROR, "interrupted during validate");
200200

201201
/* skipped backup while differential backup */
202+
/* NOTE We don't compute checksums for compressed data,
203+
* so skip it too */
202204
if (file->write_size == BYTES_INVALID
203205
|| !S_ISREG(file->mode)
204206
|| file->generation != -1)

0 commit comments

Comments
 (0)