Skip to content

Commit 8dea09c

Browse files
committed
Improve comments. Add pgBackupGetBackupMode()
1 parent 1cd6a97 commit 8dea09c

File tree

7 files changed

+52
-19
lines changed

7 files changed

+52
-19
lines changed

backup.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "streamutil.h"
2727
#include "receivelog.h"
2828

29-
static const char *backupModes[] = {"", "PAGE", "PTRACK", "FULL"};
3029
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
3130
static XLogRecPtr stop_backup_lsn = InvalidXLogRecPtr;
3231
const char *progname = "pg_probackup";
@@ -242,7 +241,14 @@ do_backup_database(parray *backup_list)
242241
make_pagemap_from_ptrack(backup_files_list);
243242
}
244243

245-
/* Sort pathname ascending TODO What for?*/
244+
/*
245+
* Sort pathname ascending. It is necessary to create intermediate
246+
* directories sequentially.
247+
*
248+
* For example:
249+
* 1 - create 'base'
250+
* 2 - create 'base/1'
251+
*/
246252
parray_qsort(backup_files_list, pgFileComparePath);
247253

248254
/*
@@ -416,7 +422,7 @@ do_backup(void)
416422
check_system_identifiers();
417423

418424
elog(LOG, "Backup start. backup-mode = %s+%s",
419-
backupModes[current.backup_mode], current.stream?"STREAM":"ARCHIVE");
425+
pgBackupGetBackupMode(&current), current.stream?"STREAM":"ARCHIVE");
420426

421427
/* Start backup. Update backup status. */
422428
current.status = BACKUP_STATUS_RUNNING;
@@ -1495,7 +1501,10 @@ make_pagemap_from_ptrack(parray *files)
14951501
}
14961502

14971503

1498-
/* TODO Add comment */
1504+
/*
1505+
* Stop WAL streaming if current 'xlogpos' exceeds 'stop_backup_lsn', which is
1506+
* set by pg_stop_backup().
1507+
*/
14991508
static bool
15001509
stop_streaming(XLogRecPtr xlogpos, uint32 timeline, bool segment_finished)
15011510
{

catalog.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*-------------------------------------------------------------------------
22
*
3-
* catalog.c: backup catalog opration
3+
* catalog.c: backup catalog operation
44
*
55
* Portions Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
66
* Portions Copyright (c) 2015-2017, Postgres Professional
@@ -222,6 +222,15 @@ read_backup(time_t timestamp)
222222
return readBackupControlFile(conf_path);
223223
}
224224

225+
/*
226+
* Get backup_mode in string representation.
227+
*/
228+
const char *
229+
pgBackupGetBackupMode(pgBackup *backup)
230+
{
231+
return backupModes[backup->backup_mode];
232+
}
233+
225234
static bool
226235
IsDir(const char *dirpath, const char *entry)
227236
{
@@ -370,15 +379,14 @@ pgBackupCreateDir(pgBackup *backup)
370379

371380
/*
372381
* Write information about backup.in to stream "out".
373-
* TODO improve comments
374382
*/
375383
void
376384
pgBackupWriteControl(FILE *out, pgBackup *backup)
377385
{
378386
char timestamp[20];
379387

380388
fprintf(out, "#Configuration\n");
381-
fprintf(out, "backup-mode = %s\n", backupModes[backup->backup_mode]);
389+
fprintf(out, "backup-mode = %s\n", pgBackupGetBackupMode(backup));
382390
fprintf(out, "stream = %s\n", backup->stream?"true":"false");
383391

384392
fprintf(out, "\n#Compatibility\n");
@@ -388,9 +396,11 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
388396

389397
fprintf(out, "\n#Result backup info\n");
390398
fprintf(out, "timelineid = %d\n", backup->tli);
399+
/* LSN returned by pg_start_backup */
391400
fprintf(out, "start-lsn = %x/%08x\n",
392401
(uint32) (backup->start_lsn >> 32),
393402
(uint32) backup->start_lsn);
403+
/* LSN returned by pg_stop_backup */
394404
fprintf(out, "stop-lsn = %x/%08x\n",
395405
(uint32) (backup->stop_lsn >> 32),
396406
(uint32) backup->stop_lsn);
@@ -409,11 +419,16 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
409419
fprintf(out, "recovery-time = '%s'\n", timestamp);
410420
}
411421

412-
/* TODO rename the field? */
422+
/*
423+
* Size of PGDATA directory. The size does not include size of related
424+
* WAL segments in archive 'wal' directory.
425+
*/
413426
if (backup->data_bytes != BYTES_INVALID)
414427
fprintf(out, "data-bytes = " INT64_FORMAT "\n", backup->data_bytes);
415428

416429
fprintf(out, "status = %s\n", status2str(backup->status));
430+
431+
/* 'parent_backup' is set if it is incremental backup */
417432
if (backup->parent_backup != 0)
418433
{
419434
char *parent_backup = base36enc(backup->parent_backup);

data.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ parse_page(const DataPage *page, XLogRecPtr *lsn)
5454
*/
5555
static void
5656
backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
57-
BlockNumber blknum, BlockNumber nblocks,
58-
FILE *in, FILE *out,
59-
pg_crc32 *crc)
57+
BlockNumber blknum, BlockNumber nblocks,
58+
FILE *in, FILE *out,
59+
pg_crc32 *crc)
6060
{
6161
BackupPageHeader header;
6262
off_t offset;
@@ -77,7 +77,7 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
7777
{
7878
/* TODO Should we check specific error code here? */
7979
if (verbose)
80-
elog(WARNING, "File: %s, could not seek to block %u."
80+
elog(WARNING, "File: %s, could not seek to block %u. "
8181
"Probably the file was truncated after backup start.",
8282
file->path, blknum);
8383
return;
@@ -98,7 +98,7 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
9898
* If after several attempts page header is still invalid, throw an error.
9999
* The same idea is applied to checksum verification.
100100
*/
101-
101+
102102
/*
103103
* TODO Should we show a hint about possible false positives suggesting to
104104
* decrease concurrent load? Or we can just copy this page and rely on

dir.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
339339

340340
/*
341341
* TODO Add comment, review
342-
* TODO if met file of unusual format throw a WARNING and don't add to list.
343342
*/
344343
static void
345344
dir_list_file_internal(parray *files, const char *root, bool exclude,
@@ -358,9 +357,13 @@ dir_list_file_internal(parray *files, const char *root, bool exclude,
358357
return;
359358
}
360359

360+
/*
361+
* Add to files list only files, links and directories. Skip sockets and
362+
* other unexpected file formats.
363+
*/
361364
if (!S_ISDIR(file->mode) && !S_ISLNK(file->mode) && !S_ISREG(file->mode))
362365
{
363-
elog(WARNING, "Skip file \"%s\": Unexpected file format", file->path);
366+
elog(WARNING, "Skip file \"%s\": unexpected file format", file->path);
364367
return;
365368
}
366369

pg_probackup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ extern void pgBackupValidate(pgBackup* backup);
301301

302302
/* in catalog.c */
303303
extern pgBackup *read_backup(time_t timestamp);
304+
extern const char *pgBackupGetBackupMode(pgBackup *backup);
304305

305306
extern parray *catalog_get_backup_list(time_t requested_backup_id);
306307
extern pgBackup *catalog_get_last_data_backup(parray *backup_list,

restore.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,14 @@ restore_backup(pgBackup *backup)
338338
parray_walk(files, pgFileFree);
339339
parray_free(files);
340340

341-
/* TODO print backup name */
342-
elog(LOG, "restore backup completed");
341+
if (verbose)
342+
{
343+
char *backup_id;
344+
345+
backup_id = base36enc(backup->start_time);
346+
elog(LOG, "restore %s backup completed", backup_id);
347+
free(backup_id);
348+
}
343349
}
344350

345351
/*

show.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "pg_probackup.h"
1212
#include <time.h>
1313

14-
static const char *backupModes[] = {"", "PAGE", "PTRACK", "FULL"};
1514
static void show_backup_list(FILE *out, parray *backup_list);
1615
static void show_backup_detail(FILE *out, pgBackup *backup);
1716

@@ -201,7 +200,7 @@ show_backup_list(FILE *out, parray *backup_list)
201200
fprintf(out, "%-8s %-19s %s%-9s %2d / %d %5s %6s %2X/%08X %2X/%08X %-8s\n",
202201
backup_id,
203202
timestamp,
204-
backupModes[backup->backup_mode],
203+
pgBackupGetBackupMode(backup),
205204
backup->stream ? "+STREAM": "+ARCHIVE",
206205
backup->tli,
207206
parent_tli,

0 commit comments

Comments
 (0)