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

Commit75534a0

Browse files
committed
Code cleanup. Unify restore and validate. Remove unused functions.
1 parent9d14e06 commit75534a0

File tree

8 files changed

+263
-510
lines changed

8 files changed

+263
-510
lines changed

‎backup.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
208208
(uint32) (*lsn >>32), (uint32)*lsn);
209209

210210
current.parent_backup=prev_backup->start_time;
211-
pgBackupWriteIni(&current);
211+
pgBackupWriteConf(&current);
212212
}
213213

214214
/* initialize backup list */
@@ -466,18 +466,18 @@ do_backup(bool smooth_checkpoint)
466466
current.checksum_version=get_data_checksum_version(true);
467467
current.stream=stream_wal;
468468

469-
/* Create backup directory andbackup.ini */
469+
/* Create backup directory andBACKUP_CONF_FILE */
470470

471471
if (pgBackupCreateDir(&current))
472472
elog(ERROR,"cannot create backup directory");
473-
pgBackupWriteIni(&current);
473+
pgBackupWriteConf(&current);
474474

475475
elog(LOG,"backup destination is initialized");
476476

477477
/* get list of backups already taken */
478-
backup_list=catalog_get_backup_list(0);
479-
if (!backup_list)
480-
elog(ERROR,"cannot process any more");
478+
backup_list=catalog_get_backup_list(INVALID_BACKUP_ID);
479+
if (backup_list==NULL)
480+
elog(ERROR,"Failed to get backup list.");
481481

482482
/* set the error processing function for the backup process */
483483
pgut_atexit_push(backup_cleanup,NULL);
@@ -489,7 +489,7 @@ do_backup(bool smooth_checkpoint)
489489
/* update backup status to DONE */
490490
current.end_time=time(NULL);
491491
current.status=BACKUP_STATUS_DONE;
492-
pgBackupWriteIni(&current);
492+
pgBackupWriteConf(&current);
493493

494494
/* Calculate the total data read */
495495
if (verbose)
@@ -995,15 +995,15 @@ backup_cleanup(bool fatal, void *userdata)
995995
}
996996

997997
/*
998-
* Update status of backup.ini to ERROR.
998+
* Update status of backup in BACKUP_CONF_FILE to ERROR.
999999
* end_time != 0 means backup finished
10001000
*/
10011001
if (current.status==BACKUP_STATUS_RUNNING&&current.end_time==0)
10021002
{
1003-
elog(LOG,"backup is running, update its status to ERROR");
1003+
elog(LOG,"Backup is running, update its status to ERROR");
10041004
current.end_time=time(NULL);
10051005
current.status=BACKUP_STATUS_ERROR;
1006-
pgBackupWriteIni(&current);
1006+
pgBackupWriteConf(&current);
10071007
}
10081008
}
10091009

‎catalog.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,17 @@ IsDir(const char *dirpath, const char *entry)
248248
}
249249

250250
/*
251-
* Create listfo backups started between begin and end from backup catalog.
252-
* Ifrange was NULL, allofbackup are listed.
251+
* Create listof backups.
252+
* If'requested_backup_id' is INVALID_BACKUP_ID, return listofall backups.
253253
* The list is sorted in order of descending start time.
254+
* If valid backup id is passed only matching backup will be added to the list.
254255
*/
255256
parray*
256-
catalog_get_backup_list(time_tbackup_id)
257+
catalog_get_backup_list(time_trequested_backup_id)
257258
{
258259
DIR*date_dir=NULL;
259260
structdirent*date_ent=NULL;
260-
DIR*time_dir=NULL;
261261
charbackups_path[MAXPGPATH];
262-
chardate_path[MAXPGPATH];
263262
parray*backups=NULL;
264263
pgBackup*backup=NULL;
265264

@@ -273,38 +272,42 @@ catalog_get_backup_list(time_t backup_id)
273272
gotoerr_proc;
274273
}
275274

276-
/* scandate/time directories and list backups in the range */
275+
/* scanthe directory and list backups */
277276
backups=parray_new();
278277
for (; (date_ent=readdir(date_dir))!=NULL;errno=0)
279278
{
280-
charini_path[MAXPGPATH];
279+
charbackup_conf_path[MAXPGPATH];
280+
chardate_path[MAXPGPATH];
281281

282282
/* skip not-directory entries and hidden entries */
283-
if (!IsDir(backups_path,date_ent->d_name)||date_ent->d_name[0]=='.')
283+
if (!IsDir(backups_path,date_ent->d_name)
284+
||date_ent->d_name[0]=='.')
284285
continue;
285286

286-
/* open subdirectory(date directory) and search time directory */
287+
/* open subdirectoryof specific backup */
287288
join_path_components(date_path,backups_path,date_ent->d_name);
288289

289-
/* read backup information frombackup.ini */
290-
snprintf(ini_path,MAXPGPATH,"%s/%s",date_path,BACKUP_CONF_FILE);
291-
backup=read_backup_from_file(ini_path);
290+
/* read backup information fromBACKUP_CONF_FILE */
291+
snprintf(backup_conf_path,MAXPGPATH,"%s/%s",date_path,BACKUP_CONF_FILE);
292+
backup=read_backup_from_file(backup_conf_path);
292293

293-
/* ignore corruptedbackup */
294+
/* ignore corruptedbackups */
294295
if (backup)
295296
{
296-
if (backup_id!=0&&backup_id!=backup->start_time)
297+
if (requested_backup_id!=INVALID_BACKUP_ID
298+
&&requested_backup_id!=backup->start_time)
297299
{
298300
pgBackupFree(backup);
299301
continue;
300302
}
301303
parray_append(backups,backup);
302304
backup=NULL;
303305
}
306+
304307
if (errno&&errno!=ENOENT)
305308
{
306309
elog(WARNING,"cannot read date directory \"%s\": %s",
307-
date_ent->d_name,strerror(errno));
310+
date_ent->d_name,strerror(errno));
308311
gotoerr_proc;
309312
}
310313
}
@@ -323,8 +326,6 @@ catalog_get_backup_list(time_t backup_id)
323326
returnbackups;
324327

325328
err_proc:
326-
if (time_dir)
327-
closedir(time_dir);
328329
if (date_dir)
329330
closedir(date_dir);
330331
if (backup)
@@ -449,9 +450,9 @@ pgBackupWriteResultSection(FILE *out, pgBackup *backup)
449450
}
450451
}
451452

452-
/* createbackup.conf */
453+
/* createBACKUP_CONF_FILE */
453454
void
454-
pgBackupWriteIni(pgBackup*backup)
455+
pgBackupWriteConf(pgBackup*backup)
455456
{
456457
FILE*fp=NULL;
457458
charini_path[MAXPGPATH];
@@ -472,7 +473,7 @@ pgBackupWriteIni(pgBackup *backup)
472473
}
473474

474475
/*
475-
* Readbackup.ini and create pgBackup.
476+
* ReadBACKUP_CONF_FILE and create pgBackup.
476477
* - Comment starts with ';'.
477478
* - Do not care section.
478479
*/
@@ -646,6 +647,7 @@ pgBackupGetPath(const pgBackup *backup, char *path, size_t len, const char *subd
646647
void
647648
init_backup(pgBackup*backup)
648649
{
650+
backup->backup_id=INVALID_BACKUP_ID;
649651
backup->backup_mode=BACKUP_MODE_INVALID;
650652
backup->status=BACKUP_STATUS_INVALID;
651653
backup->tli=0;

‎delete.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ do_delete(time_t backup_id)
3535
catalog_lock(false);
3636

3737
/* Get complete list of backups */
38-
backup_list=catalog_get_backup_list(0);
39-
if (!backup_list)
40-
elog(ERROR,"no backup list found, can't process any more");
38+
backup_list=catalog_get_backup_list(INVALID_BACKUP_ID);
39+
if (backup_list==NULL)
40+
elog(ERROR,"Failed to get backup list.");
4141

4242
delete_list=parray_new();
4343

@@ -120,7 +120,7 @@ do_deletewal(time_t backup_id, bool strict, bool need_catalog_lock)
120120
catalog_lock(false);
121121

122122
/* Find oldest LSN, used by backups */
123-
backup_list=catalog_get_backup_list(0);
123+
backup_list=catalog_get_backup_list(INVALID_BACKUP_ID);
124124
for (i=0;i<parray_num(backup_list);i++)
125125
{
126126
pgBackup*last_backup= (pgBackup*)parray_get(backup_list,i);
@@ -177,7 +177,7 @@ do_retention_purge(void)
177177
catalog_lock(false);
178178

179179
/* Get a complete list of backups. */
180-
backup_list=catalog_get_backup_list(0);
180+
backup_list=catalog_get_backup_list(INVALID_BACKUP_ID);
181181
if (parray_num(backup_list)==0)
182182
{
183183
elog(INFO,"backup list is empty, purging won't be executed");
@@ -271,7 +271,7 @@ pgBackupDeleteFiles(pgBackup *backup)
271271
* the error occurs before deleting all backup files.
272272
*/
273273
backup->status=BACKUP_STATUS_DELETING;
274-
pgBackupWriteIni(backup);
274+
pgBackupWriteConf(backup);
275275

276276
/* list files to be deleted */
277277
files=parray_new();

‎pg_probackup.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ int
107107
main(intargc,char*argv[])
108108
{
109109
ProbackupSubcmdbackup_subcmd;
110-
time_tbackup_id=0;
111110
inti;
112111

113112
/* initialize configuration */
@@ -170,8 +169,8 @@ main(int argc, char *argv[])
170169

171170
if (backup_id_string_param!=NULL)
172171
{
173-
backup_id=base36dec(backup_id_string_param);
174-
if (backup_id==0)
172+
current.backup_id=base36dec(backup_id_string_param);
173+
if (current.backup_id==0)
175174
elog(ERROR,"Invalid backup-id");
176175
}
177176

@@ -213,21 +212,19 @@ main(int argc, char *argv[])
213212
caseBACKUP:
214213
returndo_backup(smooth_checkpoint);
215214
caseRESTORE:
216-
returndo_restore(backup_id,
217-
target_time,
218-
target_xid,
219-
target_inclusive,
220-
target_tli);
215+
returndo_restore_or_validate(current.backup_id,
216+
target_time,target_xid,
217+
target_inclusive,target_tli,
218+
true);
221219
caseVALIDATE:
222-
returndo_validate(backup_id,
223-
target_time,
224-
target_xid,
225-
target_inclusive,
226-
target_tli);
220+
returndo_restore_or_validate(current.backup_id,
221+
target_time,target_xid,
222+
target_inclusive,target_tli,
223+
false);
227224
caseSHOW:
228-
returndo_show(backup_id);
225+
returndo_show(current.backup_id);
229226
caseDELETE:
230-
returndo_delete(backup_id);
227+
returndo_delete(current.backup_id);
231228
caseCONFIGURE:
232229
elog(ERROR,"not implemented yet");
233230
}

‎pg_probackup.h

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include"storage/bufpage.h"
2626
#include"storage/block.h"
2727
#include"storage/checksum.h"
28+
#include"access/timeline.h"
2829

2930
#ifndefWIN32
3031
#include<sys/mman.h>
@@ -116,13 +117,16 @@ typedef enum ProbackupSubcmd
116117
CONFIGURE
117118
}ProbackupSubcmd;
118119

120+
#defineINVALID_BACKUP_ID 0
121+
119122

120123
/* special values of pgBackup fields */
121124
#defineKEEP_INFINITE(INT_MAX)
122125
#defineBYTES_INVALID(-1)
123126

124127
typedefstructpgBackup
125128
{
129+
time_tbackup_id;
126130
/* Mode - one of BACKUP_MODE_xxx above*/
127131
BackupModebackup_mode;
128132

@@ -164,13 +168,6 @@ typedef struct pgBackup
164168
time_tparent_backup;
165169
}pgBackup;
166170

167-
168-
typedefstructpgTimeLine
169-
{
170-
TimeLineIDtli;
171-
XLogRecPtrend;
172-
}pgTimeLine;
173-
174171
typedefstructpgRecoveryTarget
175172
{
176173
booltime_specified;
@@ -252,18 +249,18 @@ extern void process_block_change(ForkNumber forknum, RelFileNode rnode,
252249
BlockNumberblkno);
253250

254251
/* in restore.c */
255-
externintdo_restore(time_tbackup_id,
252+
externintdo_restore_or_validate(time_ttarget_backup_id,
256253
constchar*target_time,
257254
constchar*target_xid,
258255
constchar*target_inclusive,
259-
TimeLineIDtarget_tli);
256+
TimeLineIDtarget_tli,
257+
boolis_restore);
260258
externboolsatisfy_timeline(constparray*timelines,constpgBackup*backup);
261259
externboolsatisfy_recovery_target(constpgBackup*backup,
262260
constpgRecoveryTarget*rt);
263-
externTimeLineIDget_fullbackup_timeline(parray*backups,
264-
constpgRecoveryTarget*rt);
265-
externTimeLineIDfindNewestTimeLine(TimeLineIDstartTLI);
266-
externparray*readTimeLineHistory(TimeLineIDtargetTLI);
261+
// extern TimeLineID get_fullbackup_timeline(parray *backups,
262+
// const pgRecoveryTarget *rt);
263+
externparray*readTimeLineHistory_probackup(TimeLineIDtargetTLI);
267264
externpgRecoveryTarget*checkIfCreateRecoveryConf(
268265
constchar*target_time,
269266
constchar*target_xid,
@@ -275,8 +272,7 @@ extern void opt_tablespace_map(pgut_option *opt, const char *arg);
275272
externintdo_init(void);
276273

277274
/* in show.c */
278-
externintdo_show(time_tbackup_id);
279-
externintdo_retention_show(void);
275+
externintdo_show(time_trequested_backup_id);
280276

281277
/* in delete.c */
282278
externintdo_delete(time_tbackup_id);
@@ -290,28 +286,22 @@ extern char *slurpFile(const char *datadir,
290286
boolsafe);
291287

292288
/* in validate.c */
293-
externintdo_validate(time_tbackup_id,
294-
constchar*target_time,
295-
constchar*target_xid,
296-
constchar*target_inclusive,
297-
TimeLineIDtarget_tli);
298-
externvoiddo_validate_last(void);
299289
externboolpgBackupValidate(pgBackup*backup,
300290
boolsize_only,
301291
boolfor_get_timeline);
302292

303293
externpgBackup*read_backup(time_ttimestamp);
304294
externvoidinit_backup(pgBackup*backup);
305295

306-
externparray*catalog_get_backup_list(time_tbackup_id);
296+
externparray*catalog_get_backup_list(time_trequested_backup_id);
307297
externpgBackup*catalog_get_last_data_backup(parray*backup_list,
308298
TimeLineIDtli);
309299

310300
externvoidcatalog_lock(boolcheck_catalog);
311301

312302
externvoidpgBackupWriteConfigSection(FILE*out,pgBackup*backup);
313303
externvoidpgBackupWriteResultSection(FILE*out,pgBackup*backup);
314-
externvoidpgBackupWriteIni(pgBackup*backup);
304+
externvoidpgBackupWriteConf(pgBackup*backup);
315305
externvoidpgBackupGetPath(constpgBackup*backup,char*path,size_tlen,constchar*subdir);
316306
externintpgBackupCreateDir(pgBackup*backup);
317307
externvoidpgBackupFree(void*backup);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp