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

Commit05ce188

Browse files
author
Michael Paquier
committed
Simplify code related to HAVE_DATABASE, HAVE_ARCLOG, TOTAL_READ_SIZE
Those macros were mainly used in code paths where they didn't make thatmuch sense, complicating heavily the code. Correct at the same time somecode comments.
1 parent96cfb3e commit05ce188

File tree

6 files changed

+94
-67
lines changed

6 files changed

+94
-67
lines changed

‎backup.c

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -660,28 +660,35 @@ do_backup(pgBackupOption bkupopt)
660660

661661
/* PGDATA and BACKUP_MODE are always required */
662662
if (pgdata==NULL)
663-
elog(ERROR_ARGS,_("required parameter not specified: PGDATA (-D, --pgdata)"));
663+
elog(ERROR_ARGS,_("Required parameter not specified: PGDATA "
664+
"(-D, --pgdata)"));
664665

666+
/* A backup mode is needed */
665667
if (current.backup_mode==BACKUP_MODE_INVALID)
666-
elog(ERROR_ARGS,_("required parameter not specified: BACKUP_MODE (-b, --backup-mode)"));
668+
elog(ERROR_ARGS,_("Required parameter not specified: BACKUP_MODE "
669+
"(-b, --backup-mode)"));
667670

668-
/* ARCLOG_PATH is requried only when backup archive WAL */
669-
if (HAVE_ARCLOG(&current)&&arclog_path==NULL)
670-
elog(ERROR_ARGS,_("required parameter not specified: ARCLOG_PATH (-A, --arclog-path)"));
671+
/* ARCLOG_PATH is required for all the modes */
672+
if (arclog_path==NULL)
673+
elog(ERROR_ARGS,
674+
_("Required parameter not specified: ARCLOG_PATH "
675+
"(-A, --arclog-path)"));
671676

672677
/* SRVLOG_PATH is required only when backup serverlog */
673678
if (current.with_serverlog&&srvlog_path==NULL)
674-
elog(ERROR_ARGS,_("required parameter not specified: SRVLOG_PATH (-S, --srvlog-path)"));
679+
elog(ERROR_ARGS,_("required parameter not specified: SRVLOG_PATH "
680+
"(-S, --srvlog-path)"));
675681

676682
#ifndefHAVE_LIBZ
677683
if (current.compress_data)
678684
{
679-
elog(WARNING,_("requested compression not available in this: installation -- archive will be uncompressed"));
685+
elog(WARNING,_("requested compression not available in this "
686+
"installation. Archive will not be compressed"));
680687
current.compress_data= false;
681688
}
682689
#endif
683690

684-
/*confirm data block size and xlog block size are compatible */
691+
/*Confirm data block size and xlog block size are compatible */
685692
check_server_version();
686693

687694
/* setup cleanup callback function */
@@ -758,23 +765,37 @@ do_backup(pgBackupOption bkupopt)
758765
if (!check)
759766
pgBackupWriteIni(&current);
760767

768+
/* Calculate the total data read */
761769
if (verbose)
762770
{
763-
if (TOTAL_READ_SIZE(&current)==0)
771+
int64total_read=0;
772+
773+
/* WAL archives */
774+
total_read+=current.read_arclog_bytes;
775+
776+
/* Database data */
777+
if (current.backup_mode==BACKUP_MODE_FULL||
778+
current.backup_mode==BACKUP_MODE_INCREMENTAL)
779+
total_read+=current.read_arclog_bytes;
780+
781+
/* Server logs */
782+
if (current.with_serverlog)
783+
total_read+=current.read_srvlog_bytes;
784+
785+
if (total_read==0)
764786
printf(_("nothing to backup\n"));
765787
else
766788
printf(_("all backup completed(read: "INT64_FORMAT" write: "
767789
INT64_FORMAT")\n"),
768-
TOTAL_READ_SIZE(&current),current.write_bytes);
790+
total_read,current.write_bytes);
769791
printf(_("========================================\n"));
770792
}
771793

772794
/*
773795
* Delete old files (archived WAL and serverlog) after update of status.
774796
*/
775-
if (HAVE_ARCLOG(&current))
776-
delete_old_files(arclog_path,files_arclog,keep_arclog_files,
777-
keep_arclog_days, true);
797+
delete_old_files(arclog_path,files_arclog,keep_arclog_files,
798+
keep_arclog_days, true);
778799
if (current.with_serverlog)
779800
delete_old_files(srvlog_path,files_srvlog,keep_srvlog_files,
780801
keep_srvlog_days, false);

‎catalog.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,13 @@ catalog_get_last_data_backup(parray *backup_list)
254254
{
255255
backup= (pgBackup*)parray_get(backup_list,i);
256256

257-
/* we need completed database backup */
258-
if (backup->status==BACKUP_STATUS_OK&&HAVE_DATABASE(backup))
257+
/*
258+
* We need completed database backup in the case of a full or
259+
* incremental backup.
260+
*/
261+
if (backup->status==BACKUP_STATUS_OK&&
262+
(backup->backup_mode==BACKUP_MODE_INCREMENTAL||
263+
backup->backup_mode==BACKUP_MODE_FULL))
259264
returnbackup;
260265
}
261266

@@ -277,7 +282,7 @@ catalog_get_last_arclog_backup(parray *backup_list)
277282
backup= (pgBackup*)parray_get(backup_list,i);
278283

279284
/* we need completed archived WAL backup */
280-
if (backup->status==BACKUP_STATUS_OK&&HAVE_ARCLOG(backup))
285+
if (backup->status==BACKUP_STATUS_OK)
281286
returnbackup;
282287
}
283288

‎pg_rman.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,6 @@ typedef struct pgBackupOption
176176
#defineKEEP_INFINITE(INT_MAX)
177177
#defineBYTES_INVALID(-1)
178178

179-
#defineHAVE_DATABASE(backup)((backup)->backup_mode >= BACKUP_MODE_INCREMENTAL)
180-
#defineHAVE_ARCLOG(backup)((backup)->backup_mode >= BACKUP_MODE_ARCHIVE)
181-
#defineTOTAL_READ_SIZE(backup)\
182-
((HAVE_DATABASE((backup)) ? (backup)->read_data_bytes : 0) + \
183-
(HAVE_ARCLOG((backup)) ? (backup)->read_arclog_bytes : 0) + \
184-
((backup)->with_serverlog ? (backup)->read_srvlog_bytes : 0))
185-
186179
typedefstructpgTimeLine
187180
{
188181
TimeLineIDtli;
@@ -265,7 +258,9 @@ extern char *slurpFile(const char *datadir,
265258

266259
/* in validate.c */
267260
externintdo_validate(pgBackupRange*range);
268-
externvoidpgBackupValidate(pgBackup*backup,boolsize_only,boolfor_get_timeline,boolwith_database);
261+
externvoidpgBackupValidate(pgBackup*backup,
262+
boolsize_only,
263+
boolfor_get_timeline);
269264

270265
/* in catalog.c */
271266
externpgBackup*catalog_get_backup(time_ttimestamp);

‎restore.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ do_restore(const char *target_time,
164164

165165
#ifndefHAVE_LIBZ
166166
/* Make sure we won't need decompression we haven't got */
167-
if (base_backup->compress_data&&
168-
(HAVE_DATABASE(base_backup)||HAVE_ARCLOG(base_backup)))
169-
{
167+
if (base_backup->compress_data)
170168
elog(ERROR_SYSTEM,
171-
_("can't restore from compressed backup (compression not supported in this installation)"));
172-
}
169+
_("can't restore from compressed backup (compression "
170+
"not supported in this installation)"));
171+
173172
#endif
174-
if (satisfy_timeline(timelines,base_backup)&&satisfy_recovery_target(base_backup,rt))
173+
if (satisfy_timeline(timelines,base_backup)&&
174+
satisfy_recovery_target(base_backup,rt))
175175
gotobase_backup_found;
176176
}
177177
/* no full backup found, can't restore */
@@ -238,9 +238,6 @@ do_restore(const char *target_time,
238238
if (backup->status!=BACKUP_STATUS_OK)
239239
continue;
240240

241-
if (!HAVE_ARCLOG(backup))
242-
continue;
243-
244241
/* care timeline junction */
245242
if (!satisfy_timeline(timelines,backup))
246243
continue;
@@ -333,7 +330,7 @@ restore_database(pgBackup *backup)
333330
* Validate backup files with its size, because load of CRC calculation is
334331
* not right.
335332
*/
336-
pgBackupValidate(backup, true, false, true);
333+
pgBackupValidate(backup, true, false);
337334

338335
/* make direcotries and symbolic links */
339336
pgBackupGetPath(backup,path,lengthof(path),MKDIRS_SH_FILE);
@@ -497,7 +494,7 @@ restore_archive_logs(pgBackup *backup, bool is_hard_copy)
497494
* Validate backup files with its size, because load of CRC calculation is
498495
* not light.
499496
*/
500-
pgBackupValidate(backup, true, false, false);
497+
pgBackupValidate(backup, true, false);
501498

502499
pgBackupGetPath(backup,list_path,lengthof(list_path),ARCLOG_FILE_LIST);
503500
pgBackupGetPath(backup,base_path,lengthof(list_path),ARCLOG_DIR);
@@ -850,13 +847,13 @@ readTimeLineHistory(TimeLineID targetTLI)
850847
staticbool
851848
satisfy_recovery_target(constpgBackup*backup,constpgRecoveryTarget*rt)
852849
{
853-
if(rt->xid_specified)
854-
returnbackup->recovery_xid <=rt->recovery_target_xid);
850+
if(rt->xid_specified)
851+
returnbackup->recovery_xid <=rt->recovery_target_xid;
855852

856853
if (rt->time_specified)
857-
returnbackup->recovery_time <=rt->recovery_target_time);
858-
else
859-
return true;
854+
returnbackup->recovery_time <=rt->recovery_target_time;
855+
856+
return true;
860857
}
861858

862859
staticbool
@@ -948,7 +945,7 @@ get_fullbackup_timeline(parray *backups, const pgRecoveryTarget *rt)
948945
* calculation is not right.
949946
*/
950947
if (base_backup->status==BACKUP_STATUS_DONE)
951-
pgBackupValidate(base_backup, true, true, false);
948+
pgBackupValidate(base_backup, true, true);
952949

953950
if(!satisfy_recovery_target(base_backup,rt))
954951
continue;

‎show.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,14 @@ show_backup_list(FILE *out, parray *backup_list, bool show_all)
189189
snprintf(duration,lengthof(duration),"%lum",
190190
(backup->end_time-backup->start_time) /60);
191191
/* "Full" is only for full backup */
192-
if (backup->backup_mode>=BACKUP_MODE_FULL)
192+
if (backup->backup_mode==BACKUP_MODE_FULL)
193193
pretty_size(backup->total_data_bytes,total_data_bytes_str,
194194
lengthof(total_data_bytes_str));
195-
elseif (backup->backup_mode>=BACKUP_MODE_INCREMENTAL)
195+
if (backup->backup_mode==BACKUP_MODE_INCREMENTAL)
196196
pretty_size(backup->read_data_bytes,read_data_bytes_str,
197197
lengthof(read_data_bytes_str));
198-
if (HAVE_ARCLOG(backup))
199-
pretty_size(backup->read_arclog_bytes,read_arclog_bytes_str,
200-
lengthof(read_arclog_bytes_str));
198+
pretty_size(backup->read_arclog_bytes,read_arclog_bytes_str,
199+
lengthof(read_arclog_bytes_str));
201200
if (backup->with_serverlog)
202201
pretty_size(backup->read_srvlog_bytes,read_srvlog_bytes_str,
203202
lengthof(read_srvlog_bytes_str));

‎validate.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ do_validate(pgBackupRange *range)
5151
continue;
5252

5353
/* validate with CRC value and update status to OK */
54-
pgBackupValidate(backup, false, false, (HAVE_DATABASE(backup)));
54+
pgBackupValidate(backup, false, false);
5555
}
5656

5757
/* cleanup */
@@ -67,7 +67,9 @@ do_validate(pgBackupRange *range)
6767
* Validate each files in the backup with its size.
6868
*/
6969
void
70-
pgBackupValidate(pgBackup*backup,boolsize_only,boolfor_get_timeline,boolwith_database)
70+
pgBackupValidate(pgBackup*backup,
71+
boolsize_only,
72+
boolfor_get_timeline)
7173
{
7274
chartimestamp[100];
7375
charbase_path[MAXPGPATH];
@@ -76,19 +78,27 @@ pgBackupValidate(pgBackup *backup, bool size_only, bool for_get_timeline, bool w
7678
boolcorrupted= false;
7779

7880
time2iso(timestamp,lengthof(timestamp),backup->start_time);
79-
if(!for_get_timeline){
80-
if (with_database)
81-
elog(INFO,"validate: %s backup and archive log files by %s",timestamp, (size_only ?"SIZE" :"CRC"));
82-
else{
81+
if (!for_get_timeline)
82+
{
83+
if (backup->backup_mode==BACKUP_MODE_FULL||
84+
backup->backup_mode==BACKUP_MODE_INCREMENTAL)
85+
elog(INFO,"validate: %s backup and archive log files by %s",
86+
timestamp, (size_only ?"SIZE" :"CRC"));
87+
else
88+
{
8389
if (backup->backup_mode==BACKUP_MODE_ARCHIVE)
84-
elog(INFO,"validate: %s archive log files by %s",timestamp, (size_only ?"SIZE" :"CRC"));
90+
elog(INFO,"validate: %s archive log files by %s",
91+
timestamp, (size_only ?"SIZE" :"CRC"));
8592
elseif (backup->with_serverlog)
86-
elog(INFO,"validate: %s server log files by %s",timestamp, (size_only ?"SIZE" :"CRC"));
93+
elog(INFO,"validate: %s server log files by %s",
94+
timestamp, (size_only ?"SIZE" :"CRC"));
8795
}
8896
}
8997

90-
if(!check){
91-
if (HAVE_DATABASE(backup))
98+
if (!check)
99+
{
100+
if (backup->backup_mode==BACKUP_MODE_FULL||
101+
backup->backup_mode==BACKUP_MODE_INCREMENTAL)
92102
{
93103
elog(LOG,"database files...");
94104
pgBackupGetPath(backup,base_path,lengthof(base_path),DATABASE_DIR);
@@ -100,17 +110,17 @@ pgBackupValidate(pgBackup *backup, bool size_only, bool for_get_timeline, bool w
100110
parray_walk(files,pgFileFree);
101111
parray_free(files);
102112
}
103-
if (HAVE_ARCLOG(backup))
104-
{
105-
elog(LOG,"archive WAL files...");
106-
pgBackupGetPath(backup,base_path,lengthof(base_path),ARCLOG_DIR);
107-
pgBackupGetPath(backup,path,lengthof(path),ARCLOG_FILE_LIST);
108-
files=dir_read_file_list(base_path,path);
109-
if (!pgBackupValidateFiles(files,base_path,size_only))
110-
corrupted= true;
111-
parray_walk(files,pgFileFree);
112-
parray_free(files);
113-
}
113+
114+
/* WAL archives are present for all modes */
115+
elog(LOG,"archive WAL files...");
116+
pgBackupGetPath(backup,base_path,lengthof(base_path),ARCLOG_DIR);
117+
pgBackupGetPath(backup,path,lengthof(path),ARCLOG_FILE_LIST);
118+
files=dir_read_file_list(base_path,path);
119+
if (!pgBackupValidateFiles(files,base_path,size_only))
120+
corrupted= true;
121+
parray_walk(files,pgFileFree);
122+
parray_free(files);
123+
114124
if (backup->with_serverlog)
115125
{
116126
elog(LOG,"server log files...");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp