Skip to content

Commit 419008d

Browse files
committed
code cleanup
1 parent 01a2146 commit 419008d

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

backup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ add_pgdata_files(parray *files, const char *root)
13121312
parray_remove(files, i);
13131313
i--;
13141314
}
1315-
/* compress map file it is not data file */
1315+
/* compress map file is not data file */
13161316
else if (path_len > 4 &&
13171317
strncmp(file->path + (path_len - 4), ".cfm", 4) == 0)
13181318
{

restore.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,24 @@ do_restore_or_validate(time_t target_backup_id,
209209

210210
/*
211211
* Validate backups from base_full_backup to dest_backup.
212-
* And restore if subcommand is RESTORE.
213-
* TODO what if we found out that backup is not valid?
214212
*/
215213
for (i = base_full_backup_index; i >= dest_backup_index; i--)
216214
{
217215
pgBackup *backup = (pgBackup *) parray_get(backups, i);
216+
pgBackupValidate(backup);
217+
}
218218

219-
if (backup->status == BACKUP_STATUS_OK)
219+
/* We ensured that all backups are valid, now restore if required */
220+
if (is_restore)
221+
{
222+
for (i = base_full_backup_index; i >= dest_backup_index; i--)
220223
{
221-
pgBackupValidate(backup);
222-
223-
if (is_restore)
224+
pgBackup *backup = (pgBackup *) parray_get(backups, i);
225+
if (backup->status == BACKUP_STATUS_OK)
224226
restore_backup(backup);
227+
else
228+
elog(ERROR, "backup %s is not valid",
229+
base36enc(backup->start_time));
225230
}
226231
}
227232

@@ -548,9 +553,8 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
548553
* Check that all tablespace mapping entries have correct linked directory
549554
* paths. Linked directories must be empty or do not exist.
550555
*
551-
* If tablespace-mapping option is supplied all OLDDIR entries should have
556+
* If tablespace-mapping option is supplied, all OLDDIR entries must have
552557
* entries in tablespace_map file.
553-
* TODO review
554558
*/
555559
static void
556560
check_tablespace_mapping(pgBackup *backup)
@@ -568,7 +572,7 @@ check_tablespace_mapping(pgBackup *backup)
568572

569573
elog(LOG, "check tablespace directories of backup %s", base36enc(backup->start_time));
570574

571-
/* 1 - OLDDIR should has an entry in links */
575+
/* 1 - each OLDDIR must have an entry in tablespace_map file (links) */
572576
for (cell = tablespace_dirs.head; cell; cell = cell->next)
573577
{
574578
tmp_file->linked = cell->old_dir;
@@ -579,7 +583,7 @@ check_tablespace_mapping(pgBackup *backup)
579583
cell->old_dir);
580584
}
581585

582-
/* 2 - all linked directories should be empty */
586+
/* 2 - all linked directories must be empty */
583587
for (i = 0; i < parray_num(links); i++)
584588
{
585589
pgFile *link = (pgFile *) parray_get(links, i);

validate.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ static void pgBackupValidateFiles(void *arg);
1818
typedef struct
1919
{
2020
parray *files;
21-
bool validate_crc;
2221
bool corrupted;
2322
} validate_files_args;
2423

2524
/*
2625
* Validate backup files.
27-
* TODO review
2826
*/
2927
void
3028
pgBackupValidate(pgBackup *backup)
@@ -63,12 +61,6 @@ pgBackupValidate(pgBackup *backup)
6361
{
6462
validate_files_args *arg = pg_malloc(sizeof(validate_files_args));
6563
arg->files = files;
66-
arg->validate_crc = true;
67-
68-
/* TODO Why didn't we validate checksums on restore before? */
69-
// if (backup_subcmd == RESTORE)
70-
// arg->validate_crc = false;
71-
7264
arg->corrupted = false;
7365
validate_threads_args[i] = arg;
7466
pthread_create(&validate_threads[i], NULL, (void *(*)(void *)) pgBackupValidateFiles, arg);
@@ -99,7 +91,7 @@ pgBackupValidate(pgBackup *backup)
9991
}
10092

10193
/*
102-
* Validate files in the backup with size or CRC.
94+
* Validate files in the backup.
10395
* NOTE: If file is not valid, do not use ERROR log message,
10496
* rather throw a WARNING and set arguments->corrupted = true.
10597
* This is necessary to update backup status.
@@ -109,6 +101,7 @@ pgBackupValidateFiles(void *arg)
109101
{
110102
int i;
111103
validate_files_args *arguments = (validate_files_args *)arg;
104+
pg_crc32 crc;
112105

113106
for (i = 0; i < parray_num(arguments->files); i++)
114107
{
@@ -158,18 +151,13 @@ pgBackupValidateFiles(void *arg)
158151
return;
159152
}
160153

161-
if (arguments->validate_crc)
154+
crc = pgFileGetCRC(file);
155+
if (crc != file->crc)
162156
{
163-
pg_crc32 crc;
164-
165-
crc = pgFileGetCRC(file);
166-
if (crc != file->crc)
167-
{
168-
elog(WARNING, "Invalid CRC of backup file \"%s\" : %X. Expected %X",
169-
file->path, file->crc, crc);
170-
arguments->corrupted = true;
171-
return;
172-
}
157+
elog(WARNING, "Invalid CRC of backup file \"%s\" : %X. Expected %X",
158+
file->path, file->crc, crc);
159+
arguments->corrupted = true;
160+
return;
173161
}
174162
}
175163
}

0 commit comments

Comments
 (0)