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

Commit37c3be1

Browse files
author
Michael Paquier
committed
Refactor write/read calculation size of backups
This commit simplifies the way backup sizes are saved internally byreusing the same variable for incremental and full backup, which wereusing separated and exclusively used variables, resulted in a coupleof bytes wasted all the time. This was also reflected by a uselesscolumn in the output table of subcommand "show".
1 parent9cd8e33 commit37c3be1

File tree

10 files changed

+141
-125
lines changed

10 files changed

+141
-125
lines changed

‎backup.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
9292
elog(INFO,_("database backup start"));
9393

9494
/* Initialize size summary */
95-
current.total_data_bytes=0;
96-
current.read_data_bytes=0;
95+
current.data_bytes=0;
9796

9897
/*
9998
* Obtain current timeline by scanning control file, theh LSN
@@ -395,16 +394,25 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
395394
pgFile*file= (pgFile*)parray_get(files,i);
396395
if (!S_ISREG(file->mode))
397396
continue;
398-
current.total_data_bytes+=file->size;
399-
current.read_data_bytes+=file->read_size;
397+
/*
398+
* Count only the amount of data. For a full backup, the total
399+
* amount of data written counts while for an incremental
400+
* backup only the data read counts.
401+
*/
402+
if (current.backup_mode==BACKUP_MODE_INCREMENTAL)
403+
current.data_bytes+=file->read_size;
404+
elseif (current.backup_mode==BACKUP_MODE_FULL)
405+
current.data_bytes+=file->size;
406+
407+
/* Count total amount of data for backup */
400408
if (file->write_size!=BYTES_INVALID)
401-
current.write_bytes+=file->write_size;
409+
current.backup_bytes+=file->write_size;
402410
}
403411

404412
if (verbose)
405413
{
406-
printf(_("database backup completed(read: "INT64_FORMAT"write: "INT64_FORMAT")\n"),
407-
current.read_data_bytes,current.write_bytes);
414+
printf(_("database backup completed(written: "INT64_FORMAT"Backup: "INT64_FORMAT")\n"),
415+
current.data_bytes,current.backup_bytes);
408416
printf(_("========================================\n"));
409417
}
410418

@@ -444,7 +452,7 @@ do_backup_arclog(parray *backup_list)
444452
}
445453

446454
/* initialize size summary */
447-
current.read_arclog_bytes=0;
455+
current.arclog_bytes=0;
448456

449457
/*
450458
* Switch xlog if database is not backed up, current timeline of
@@ -523,10 +531,10 @@ do_backup_arclog(parray *backup_list)
523531
pgFile*file= (pgFile*)parray_get(files,i);
524532
if (!S_ISREG(file->mode))
525533
continue;
526-
current.read_arclog_bytes+=file->read_size;
534+
current.arclog_bytes+=file->read_size;
527535
if (file->write_size!=BYTES_INVALID)
528536
{
529-
current.write_bytes+=file->write_size;
537+
current.backup_bytes+=file->write_size;
530538
arclog_write_bytes+=file->write_size;
531539
}
532540
}
@@ -553,7 +561,7 @@ do_backup_arclog(parray *backup_list)
553561
if (verbose)
554562
{
555563
printf(_("archived WAL backup completed(read: "INT64_FORMAT" write: "INT64_FORMAT")\n"),
556-
current.read_arclog_bytes,arclog_write_bytes);
564+
current.arclog_bytes,arclog_write_bytes);
557565
printf(_("========================================\n"));
558566
}
559567

@@ -589,7 +597,7 @@ do_backup_srvlog(parray *backup_list)
589597
}
590598

591599
/* initialize size summary */
592-
current.read_srvlog_bytes=0;
600+
current.srvlog_bytes=0;
593601

594602
/*
595603
* To take incremental backup, the file list of the last completed database
@@ -632,18 +640,18 @@ do_backup_srvlog(parray *backup_list)
632640
pgFile*file= (pgFile*)parray_get(files,i);
633641
if (!S_ISREG(file->mode))
634642
continue;
635-
current.read_srvlog_bytes+=file->read_size;
643+
current.srvlog_bytes+=file->read_size;
636644
if (file->write_size!=BYTES_INVALID)
637645
{
638-
current.write_bytes+=file->write_size;
646+
current.backup_bytes+=file->write_size;
639647
srvlog_write_bytes+=file->write_size;
640648
}
641649
}
642650

643651
if (verbose)
644652
{
645653
printf(_("serverlog backup completed(read: "INT64_FORMAT" write: "INT64_FORMAT")\n"),
646-
current.read_srvlog_bytes,srvlog_write_bytes);
654+
current.srvlog_bytes,srvlog_write_bytes);
647655
printf(_("========================================\n"));
648656
}
649657

@@ -728,11 +736,10 @@ do_backup(pgBackupOption bkupopt)
728736
current.stop_lsn=0;
729737
current.start_time=time(NULL);
730738
current.end_time= (time_t)0;
731-
current.total_data_bytes=BYTES_INVALID;
732-
current.read_data_bytes=BYTES_INVALID;
733-
current.read_arclog_bytes=BYTES_INVALID;
734-
current.read_srvlog_bytes=BYTES_INVALID;
735-
current.write_bytes=0;/* write_bytes is valid always */
739+
current.data_bytes=BYTES_INVALID;
740+
current.arclog_bytes=BYTES_INVALID;
741+
current.srvlog_bytes=BYTES_INVALID;
742+
current.backup_bytes=0;
736743
current.block_size=BLCKSZ;
737744
current.wal_block_size=XLOG_BLCKSZ;
738745
current.recovery_xid=0;
@@ -779,23 +786,23 @@ do_backup(pgBackupOption bkupopt)
779786
int64total_read=0;
780787

781788
/* WAL archives */
782-
total_read+=current.read_arclog_bytes;
789+
total_read+=current.arclog_bytes;
783790

784791
/* Database data */
785792
if (current.backup_mode==BACKUP_MODE_FULL||
786793
current.backup_mode==BACKUP_MODE_INCREMENTAL)
787-
total_read+=current.read_arclog_bytes;
794+
total_read+=current.arclog_bytes;
788795

789796
/* Server logs */
790797
if (current.with_serverlog)
791-
total_read+=current.read_srvlog_bytes;
798+
total_read+=current.srvlog_bytes;
792799

793800
if (total_read==0)
794801
printf(_("nothing to backup\n"));
795802
else
796803
printf(_("all backup completed(read: "INT64_FORMAT" write: "
797804
INT64_FORMAT")\n"),
798-
total_read,current.write_bytes);
805+
total_read,current.backup_bytes);
799806
printf(_("========================================\n"));
800807
}
801808

‎catalog.c

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -384,21 +384,18 @@ pgBackupWriteResultSection(FILE *out, pgBackup *backup)
384384
fprintf(out,"RECOVERY_TIME='%s'\n",timestamp);
385385
}
386386

387-
if (backup->total_data_bytes!=BYTES_INVALID)
388-
fprintf(out,"TOTAL_DATA_BYTES="INT64_FORMAT"\n",
389-
backup->total_data_bytes);
390-
if (backup->read_data_bytes!=BYTES_INVALID)
391-
fprintf(out,"READ_DATA_BYTES="INT64_FORMAT"\n",
392-
backup->read_data_bytes);
393-
if (backup->read_arclog_bytes!=BYTES_INVALID)
394-
fprintf(out,"READ_ARCLOG_BYTES="INT64_FORMAT"\n",
395-
backup->read_arclog_bytes);
396-
if (backup->read_srvlog_bytes!=BYTES_INVALID)
397-
fprintf(out,"READ_SRVLOG_BYTES="INT64_FORMAT"\n",
398-
backup->read_srvlog_bytes);
399-
if (backup->write_bytes!=BYTES_INVALID)
400-
fprintf(out,"WRITE_BYTES="INT64_FORMAT"\n",
401-
backup->write_bytes);
387+
if (backup->data_bytes!=BYTES_INVALID)
388+
fprintf(out,"DATA_BYTES="INT64_FORMAT"\n",
389+
backup->data_bytes);
390+
if (backup->arclog_bytes!=BYTES_INVALID)
391+
fprintf(out,"ARCLOG_BYTES="INT64_FORMAT"\n",
392+
backup->arclog_bytes);
393+
if (backup->srvlog_bytes!=BYTES_INVALID)
394+
fprintf(out,"SRVLOG_BYTES="INT64_FORMAT"\n",
395+
backup->srvlog_bytes);
396+
if (backup->backup_bytes!=BYTES_INVALID)
397+
fprintf(out,"BACKUP_BYTES="INT64_FORMAT"\n",
398+
backup->backup_bytes);
402399

403400
fprintf(out,"BLOCK_SIZE=%u\n",backup->block_size);
404401
fprintf(out,"XLOG_BLOCK_SIZE=%u\n",backup->wal_block_size);
@@ -455,11 +452,10 @@ catalog_read_ini(const char *path)
455452
{'t',0,"end-time",NULL,SOURCE_ENV },
456453
{'u',0,"recovery-xid",NULL,SOURCE_ENV },
457454
{'t',0,"recovery-time",NULL,SOURCE_ENV },
458-
{'I',0,"total-data-bytes",NULL,SOURCE_ENV },
459-
{'I',0,"read-data-bytes",NULL,SOURCE_ENV },
460-
{'I',0,"read-arclog-bytes",NULL,SOURCE_ENV },
461-
{'I',0,"read-srvlog-bytes",NULL,SOURCE_ENV },
462-
{'I',0,"write-bytes",NULL,SOURCE_ENV },
455+
{'I',0,"data-bytes",NULL,SOURCE_ENV },
456+
{'I',0,"arclog-bytes",NULL,SOURCE_ENV },
457+
{'I',0,"srvlog-bytes",NULL,SOURCE_ENV },
458+
{'I',0,"backup-bytes",NULL,SOURCE_ENV },
463459
{'u',0,"block-size",NULL,SOURCE_ENV },
464460
{'u',0,"xlog-block-size",NULL,SOURCE_ENV },
465461
{'s',0,"status",NULL,SOURCE_ENV },
@@ -484,11 +480,10 @@ catalog_read_ini(const char *path)
484480
options[i++].var=&backup->end_time;
485481
options[i++].var=&backup->recovery_xid;
486482
options[i++].var=&backup->recovery_time;
487-
options[i++].var=&backup->total_data_bytes;
488-
options[i++].var=&backup->read_data_bytes;
489-
options[i++].var=&backup->read_arclog_bytes;
490-
options[i++].var=&backup->read_srvlog_bytes;
491-
options[i++].var=&backup->write_bytes;
483+
options[i++].var=&backup->data_bytes;
484+
options[i++].var=&backup->arclog_bytes;
485+
options[i++].var=&backup->srvlog_bytes;
486+
options[i++].var=&backup->backup_bytes;
492487
options[i++].var=&backup->block_size;
493488
options[i++].var=&backup->wal_block_size;
494489
options[i++].var=&status;
@@ -635,9 +630,8 @@ catalog_init_config(pgBackup *backup)
635630
backup->end_time= (time_t)0;
636631
backup->recovery_xid=0;
637632
backup->recovery_time= (time_t)0;
638-
backup->total_data_bytes=BYTES_INVALID;
639-
backup->read_data_bytes=BYTES_INVALID;
640-
backup->read_arclog_bytes=BYTES_INVALID;
641-
backup->read_srvlog_bytes=BYTES_INVALID;
642-
backup->write_bytes=BYTES_INVALID;
633+
backup->data_bytes=BYTES_INVALID;
634+
backup->arclog_bytes=BYTES_INVALID;
635+
backup->srvlog_bytes=BYTES_INVALID;
636+
backup->backup_bytes=BYTES_INVALID;
643637
}

‎data/sample_backup/20090531/170553/backup.ini

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ START_LSN=0/0b40c800
88
STOP_LSN=0/0b4c8020
99
START_TIME='2009-05-31 17:05:53'
1010
END_TIME='2009-05-31 17:09:13'
11-
TOTAL_DATA_BYTES=1242102558
12-
READ_DATA_BYTES=1024
13-
READ_ARCLOG_BYTES=9223372036854775807
14-
READ_SRVLOG_BYTES=-1
15-
WRITE_BYTES=242102558
11+
DATA_BYTES=1242102558
12+
ARCLOG_BYTES=9223372036854775807
13+
SRVLOG_BYTES=-1
14+
BACKUP_BYTES=242102558
1615
BLOCK_SIZE=8192
1716
XLOG_BLOCK_SIZE=8192
1817
STATUS=DONE

‎data/sample_backup/20090601/170553/backup.ini

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ START_LSN=0/0b40c800
88
STOP_LSN=0/0b4c8020
99
START_TIME='2009-06-01 17:05:53'
1010
END_TIME='2009-06-01 17:09:13'
11-
TOTAL_DATA_BYTES=1242102558
12-
READ_DATA_BYTES=9223372036854775807
13-
READ_ARCLOG_BYTES=16777216
14-
READ_SRVLOG_BYTES=-1
15-
WRITE_BYTES=162372983
11+
DATA_BYTES=9223372036854775807
12+
ARCLOG_BYTES=16777216
13+
SRVLOG_BYTES=-1
14+
BACKUP_BYTES=162372983
1615
BLOCK_SIZE=8192
1716
XLOG_BLOCK_SIZE=8192
1817
STATUS=DONE

‎data/sample_backup/20090602/170553/backup.ini

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ START_LSN=0/0b40c800
88
STOP_LSN=0/0b4c8020
99
START_TIME='2009-06-02 17:05:03'
1010
END_TIME='2009-06-02 17:05:03'
11-
TOTAL_DATA_BYTES=-1
12-
READ_DATA_BYTES=-1
13-
READ_ARCLOG_BYTES=-1
14-
READ_SRVLOG_BYTES=4335423
15-
WRITE_BYTES=162372983
11+
DATA_BYTES=-1
12+
ARCLOG_BYTES=-1
13+
SRVLOG_BYTES=4335423
14+
BACKUP_BYTES=162372983
1615
BLOCK_SIZE=8192
1716
XLOG_BLOCK_SIZE=8192
1817
STATUS=DELETED

‎data/sample_backup/20090603/170553/backup.ini

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ START_LSN=0/0b40c800
88
STOP_LSN=0/0b4c8020
99
START_TIME='2009-06-03 17:05:53'
1010
END_TIME='2009-06-03 17:05:53'
11-
TOTAL_DATA_BYTES=-1
12-
READ_DATA_BYTES=-1
13-
READ_ARCLOG_BYTES=-1
14-
READ_SRVLOG_BYTES=-1
15-
WRITE_BYTES=-1
11+
DATA_BYTES=-1
12+
ARCLOG_BYTES=-1
13+
SRVLOG_BYTES=-1
14+
BACKUP_BYTES=-1
1615
BLOCK_SIZE=8192
1716
XLOG_BLOCK_SIZE=8192
1817
STATUS=RUNNING

‎expected/backup_restore.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ CHECKPOINT
2929
# of recovery target option in recovery.conf
3030
3
3131
# of deleted backups (show all)
32-
4
32+
3
3333
# of deleted backups
3434
0
3535
delete backup
3636
# of deleted backups
37-
4
37+
3
3838
# of deleted backups
39-
9
39+
8

‎expected/show_validate.out

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
\! rm -rf ${PWD}/results/sample_backup
33
\! cp -rp data/sample_backup ${PWD}/results/sample_backup
44
\! pg_rman show -B ${PWD}/results/sample_backup
5-
===========================================================================================================
6-
Start Mode Current TLI Parent TLI TimeTotalData WAL Log Backup Status
7-
===========================================================================================================
8-
2009-06-03 17:05:53 FULL 1 0 0m ---- ---- ---- ---- ----RUNNING
9-
2009-06-01 17:05:53 INCR 1 0 3m ----9223PB 16MB ---- 162MB DONE
10-
2009-05-31 17:05:53 FULL 1 0 3m 1242MB ----9223PB ---- 242MB DONE
5+
==================================================================================================
6+
Start Mode Current TLI Parent TLI Time Data WAL Log Backup Status
7+
==================================================================================================
8+
2009-06-03 17:05:53 FULL 1 0 0m ---- ---- ---- ---- RUNNING
9+
2009-06-01 17:05:53 INCR 1 0 3m 9223PB 16MB ---- 162MB DONE
10+
2009-05-31 17:05:53 FULL 1 0 3m 1242MB 9223PB ---- 242MB DONE
1111
\! pg_rman validate -B ${PWD}/results/sample_backup 2009-05-31 17:05:53 --debug
1212
INFO: validate: 2009-05-31 17:05:53 backup and archive log files by CRC
1313
LOG: database files...
@@ -22,13 +22,13 @@ WARNING: CRC of backup file "PG_VERSION" must be 0 but FEF71BC1
2222
LOG: archive WAL files...
2323
WARNING: backup 2009-06-01 17:05:53 is corrupted
2424
\! pg_rman show -a -B ${PWD}/results/sample_backup
25-
===========================================================================================================
26-
Start Mode Current TLI Parent TLI TimeTotalData WAL Log Backup Status
27-
===========================================================================================================
28-
2009-06-03 17:05:53 FULL 1 0 0m ---- ---- ---- ---- ----RUNNING
29-
2009-06-02 17:05:03 ARCH 1 0 0m ---- ---- ----4335kB 162MB DELETED
30-
2009-06-01 17:05:53 INCR 1 0 3m ----9223PB 16MB ---- 162MB CORRUPT
31-
2009-05-31 17:05:53 FULL 1 0 3m 1242MB ----9223PB ---- 242MB OK
25+
==================================================================================================
26+
Start Mode Current TLI Parent TLI Time Data WAL Log Backup Status
27+
==================================================================================================
28+
2009-06-03 17:05:53 FULL 1 0 0m ---- ---- ---- ---- RUNNING
29+
2009-06-02 17:05:03 ARCH 1 0 0m ---- ---- 4335kB 162MB DELETED
30+
2009-06-01 17:05:53 INCR 1 0 3m 9223PB 16MB ---- 162MB CORRUPT
31+
2009-05-31 17:05:53 FULL 1 0 3m 1242MB 9223PB ---- 242MB OK
3232
\! pg_rman show 2009-06-01 17:05:53 -B ${PWD}/results/sample_backup
3333
# configuration
3434
BACKUP_MODE=INCREMENTAL
@@ -41,10 +41,9 @@ STOP_LSN=0/0b4c8020
4141
START_TIME='2009-06-01 17:05:53'
4242
END_TIME='2009-06-01 17:09:13'
4343
RECOVERY_XID=0
44-
TOTAL_DATA_BYTES=1242102558
45-
READ_DATA_BYTES=9223372036854775807
46-
READ_ARCLOG_BYTES=16777216
47-
WRITE_BYTES=162372983
44+
DATA_BYTES=9223372036854775807
45+
ARCLOG_BYTES=16777216
46+
BACKUP_BYTES=162372983
4847
BLOCK_SIZE=8192
4948
XLOG_BLOCK_SIZE=8192
5049
STATUS=CORRUPT

‎pg_rman.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,19 @@ typedef struct pgBackup
144144
time_trecovery_time;
145145
uint32recovery_xid;
146146

147-
/* Size (-1 means nothing was backed up) */
148-
int64total_data_bytes;
149-
int64read_data_bytes;
150-
int64read_arclog_bytes;
151-
int64read_srvlog_bytes;
152-
int64write_bytes;
147+
/* Different sizes (-1 means nothing was backed up) */
148+
/*
149+
* Amount of raw data. For a full backup, this is the total amount of
150+
* data while for an incremental backup this is just the differential
151+
* of data taken.
152+
*/
153+
int64data_bytes;
154+
/* Amount of data for WAL archives */
155+
int64arclog_bytes;
156+
/* Amount of data for server logs */
157+
int64srvlog_bytes;
158+
/* Total size of backup */
159+
int64backup_bytes;
153160

154161
/* data/wal block size for compatibility check */
155162
uint32block_size;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp