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

Commit345c26b

Browse files
committed
[Issue#228] nitpicking
1 parent75e5496 commit345c26b

File tree

5 files changed

+57
-73
lines changed

5 files changed

+57
-73
lines changed

‎src/backup.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
212212
"trying to look up on previous timelines",
213213
current.tli);
214214

215+
/* TODO: use read_timeline_history */
215216
tli_list=catalog_get_timelines(&instance_config);
216217

217218
if (parray_num(tli_list)==0)
@@ -526,7 +527,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
526527
arg->prev_start_lsn=prev_backup_start_lsn;
527528
arg->conn_arg.conn=NULL;
528529
arg->conn_arg.cancel_conn=NULL;
529-
arg->hdr_map=&(current).hdr_map;
530+
arg->hdr_map=&(current.hdr_map);
530531
arg->thread_num=i+1;
531532
/* By default there are some error */
532533
arg->ret=1;

‎src/data.c‎

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ typedef struct DataPage
3131
chardata[BLCKSZ];
3232
}DataPage;
3333

34-
staticboolget_compressed_page_meta(FILE*in,constchar*fullpath,BackupPageHeader*bph,
35-
pg_crc32*crc,booluse_crc32c);
34+
staticboolget_page_header(FILE*in,constchar*fullpath,BackupPageHeader*bph,
35+
pg_crc32*crc,booluse_crc32c);
3636

3737
#ifdefHAVE_LIBZ
3838
/* Implementation of zlib compression method */
@@ -861,6 +861,10 @@ restore_data_file(parray *parent_chain, pgFile *dest_file, FILE *out,
861861
* If "nblocks" is greater than zero, then skip restoring blocks,
862862
* whose position if greater than "nblocks".
863863
* If map is NULL, then page bitmap cannot be used for restore optimization
864+
* Page bitmap optimize restore of incremental chains, consisting of more than one
865+
* backup. We restoring from newest to oldest and page, once restored, marked in map.
866+
* When the same page, but in older backup, encountered, we check the map, if it is
867+
* marked as already restored, then page is skipped.
864868
*/
865869
size_t
866870
restore_data_file_internal(FILE*in,FILE*out,pgFile*file,uint32backup_version,
@@ -930,39 +934,37 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
930934
else
931935
{
932936
/* We get into this function either when restoring old backup
933-
* or when merging something.Aligh read_len only in restoring
934-
* or merging oldbackup.
937+
* or when merging something.Align read_len only in restoring
938+
* or merging oldbackups.
935939
*/
936-
if (get_compressed_page_meta(in,from_fullpath,&(page).bph,NULL, false))
940+
if (get_page_header(in,from_fullpath,&(page).bph,NULL, false))
937941
{
938942
cur_pos_in+=sizeof(BackupPageHeader);
939943

940944
/* backward compatibility kludge TODO: remove in 3.0 */
941945
blknum=page.bph.block;
942946
compressed_size=page.bph.compressed_size;
943947

944-
/* this will backfire when retrying merge of old backups,
945-
* just pray that this will never happen.
948+
/* this has a potential to backfire when retrying merge of old backups,
949+
* so we just forbid the retrying of failed merges between versions >= 2.4.0 and
950+
* version < 2.4.0
946951
*/
947952
if (backup_version >=20400)
948953
read_len=compressed_size;
949954
else
955+
/* For some unknown and possibly dump reason I/O operations
956+
* in versions < 2.4.0 were always aligned to 8 bytes.
957+
* Now we have to deal with backward compatibility.
958+
*/
950959
read_len=MAXALIGN(compressed_size);
951960

952-
//elog(INFO, "FILE: %s", from_fullpath);
953-
//elog(INFO, "blknum: %i", blknum);
954-
//
955-
//elog(INFO, "POS: %u", cur_pos_in);
956-
//elog(INFO, "SIZE: %i", compressed_size);
957-
//elog(INFO, "ASIZE: %i", read_len);
958-
959961
}
960962
else
961963
break;
962964
}
963965

964966
/*
965-
*Backupward compatibility kludge: in the good old days
967+
*Backward compatibility kludge: in the good old days
966968
* n_blocks attribute was available only in DELTA backups.
967969
* File truncate in PAGE and PTRACK happened on the fly when
968970
* special value PageIsTruncated is encountered.
@@ -1006,13 +1008,13 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
10061008
if (compressed_size>BLCKSZ)
10071009
elog(ERROR,"Size of a blknum %i exceed BLCKSZ: %i",blknum,compressed_size);
10081010

1009-
/*incremental restore in LSN mode */
1011+
/*Incremental restore in LSN mode */
10101012
if (map&&lsn_map&&datapagemap_is_set(lsn_map,blknum))
10111013
datapagemap_add(map,blknum);
10121014

10131015
if (map&&checksum_map&&checksum_map[blknum].checksum!=0)
10141016
{
1015-
//elog(INFO, "HDR CRC: %u, MAP CRC: %u", page_crc, checksum_map[blknum].checksum);
1017+
//elog(INFO, "HDR CRC: %u, MAP CRC: %u", page_crc, checksum_map[blknum].checksum);
10161018
/*
10171019
* The heart of incremental restore in CHECKSUM mode
10181020
* If page in backup has the same checksum and lsn as
@@ -1110,7 +1112,7 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
11101112
write_len+=BLCKSZ;
11111113
cur_pos_out+=BLCKSZ;/* update current write position */
11121114

1113-
/* Mark page as restored, to avoid reading this page when restoring parent backups */
1115+
/* Mark page as restored to avoid reading this page when restoring parent backups */
11141116
if (map)
11151117
datapagemap_add(map,blknum);
11161118
}
@@ -1238,7 +1240,7 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup,
12381240
/* incremental restore */
12391241
if (already_exists)
12401242
{
1241-
/* comparechecksumms ofremoteandlocal files */
1243+
/* comparechecksums ofalready existing fileandbackup file */
12421244
pg_crc32file_crc=fio_get_crc32(to_fullpath,FIO_DB_HOST, false);
12431245

12441246
if (file_crc==tmp_file->crc)
@@ -1625,7 +1627,7 @@ validate_file_pages(pgFile *file, const char *fullpath, XLogRecPtr stop_lsn,
16251627
if (interrupted||thread_interrupted)
16261628
elog(ERROR,"Interrupted during data file validation");
16271629

1628-
/* newer backups have headers in separate storage */
1630+
/* newer backups havepageheaders in separate storage */
16291631
if (headers)
16301632
{
16311633
n_hdr++;
@@ -1657,7 +1659,7 @@ validate_file_pages(pgFile *file, const char *fullpath, XLogRecPtr stop_lsn,
16571659
/* old backups rely on header located directly in data file */
16581660
else
16591661
{
1660-
if (get_compressed_page_meta(in,fullpath,&(compressed_page).bph,&crc,use_crc32c))
1662+
if (get_page_header(in,fullpath,&(compressed_page).bph,&crc,use_crc32c))
16611663
{
16621664
/* Backward compatibility kludge, TODO: remove in 3.0
16631665
* for some reason we padded compressed pages in old versions
@@ -1686,11 +1688,6 @@ validate_file_pages(pgFile *file, const char *fullpath, XLogRecPtr stop_lsn,
16861688
else
16871689
len=fread(compressed_page.data,1,read_len,in);
16881690

1689-
//elog(INFO, "POS: %u", cur_pos_in);
1690-
//
1691-
//elog(INFO, "LEN: %i", len);
1692-
//elog(INFO, "READ_LEN: %i", read_len);
1693-
16941691
if (len!=read_len)
16951692
{
16961693
elog(WARNING,"Cannot read block %u file \"%s\": %s",
@@ -1886,11 +1883,8 @@ get_lsn_map(const char *fullpath, uint32 checksum_version,
18861883
for (blknum=0;blknum<n_blocks;blknum++)
18871884
{
18881885
size_tread_len=fread(read_buffer,1,BLCKSZ,in);
1889-
//page_lsn = InvalidXLogRecPtr;
18901886
PageStatepage_st;
18911887

1892-
//page_st.lsn = InvalidXLogRecPtr
1893-
18941888
/* report error */
18951889
if (ferror(in))
18961890
elog(ERROR,"Cannot read block %u of \"%s\": %s",
@@ -1905,7 +1899,8 @@ get_lsn_map(const char *fullpath, uint32 checksum_version,
19051899
datapagemap_add(lsn_map,blknum);
19061900
}
19071901
else
1908-
elog(ERROR,"Failed to read blknum %u from file \"%s\"",blknum,fullpath);
1902+
elog(ERROR,"Cannot read block %u from file \"%s\": %s",
1903+
blknum,fullpath,strerror(errno));
19091904

19101905
if (feof(in))
19111906
break;
@@ -1926,10 +1921,10 @@ get_lsn_map(const char *fullpath, uint32 checksum_version,
19261921
returnlsn_map;
19271922
}
19281923

1929-
/* */
1924+
/*Every page in data file contains BackupPageHeader, extract it*/
19301925
bool
1931-
get_compressed_page_meta(FILE*in,constchar*fullpath,BackupPageHeader*bph,
1932-
pg_crc32*crc,booluse_crc32c)
1926+
get_page_header(FILE*in,constchar*fullpath,BackupPageHeader*bph,
1927+
pg_crc32*crc,booluse_crc32c)
19331928
{
19341929

19351930
/* read BackupPageHeader */
@@ -1952,26 +1947,18 @@ get_compressed_page_meta(FILE *in, const char *fullpath, BackupPageHeader* bph,
19521947
ftell(in),fullpath,strerror(errno));
19531948
}
19541949

1950+
/* In older versions < 2.4.0, when crc for file was calculated, header was
1951+
* not included in crc calculations. Now it is. And now we have
1952+
* the problem of backward compatibility for backups of old versions
1953+
*/
19551954
if (crc)
19561955
COMP_FILE_CRC32(use_crc32c,*crc,bph,read_len);
19571956

19581957
if (bph->block==0&&bph->compressed_size==0)
19591958
elog(ERROR,"Empty block in file \"%s\"",fullpath);
19601959

1961-
1962-
//*blknum = header.block;
1963-
//*compressed_size = header.compressed_size;
1964-
1965-
//elog(INFO, "blknum: %i", header.block);
1966-
//elog(INFO, "size: %i", header.compressed_size);
1967-
//elog(INFO, "size2: %i", *compressed_size);
1968-
//
1969-
//elog(INFO, "BLKNUM: %i", *blknum);
1970-
//elog(INFO, "File: %s", fullpath);
1971-
19721960
Assert(bph->compressed_size!=0);
19731961
return true;
1974-
19751962
}
19761963

19771964
/* Open local backup file for writing, set permissions and buffering */
@@ -2099,7 +2086,10 @@ send_pages(ConnectionArgs* conn_arg, const char *to_fullpath, const char *from_f
20992086
blknum++;
21002087
}
21012088

2102-
/* add one additional header */
2089+
/*
2090+
* Add dummy header, so we can later extract the length of last header
2091+
* as difference between their offsets.
2092+
*/
21032093
if (*headers)
21042094
{
21052095
file->n_headers=hdr_num+1;
@@ -2124,8 +2114,11 @@ send_pages(ConnectionArgs* conn_arg, const char *to_fullpath, const char *from_f
21242114
returnn_blocks_read;
21252115
}
21262116

2127-
/* attempt to open header file, read content and return as
2117+
/*
2118+
* Attempt to open header file, read content and return as
21282119
* array of headers.
2120+
* TODO: some access optimizations would be great here:
2121+
* less fseeks, buffering, descriptor sharing, etc.
21292122
*/
21302123
BackupPageHeader2*
21312124
get_data_file_headers(HeaderMap*hdr_map,pgFile*file,uint32backup_version,boolstrict)
@@ -2181,8 +2174,6 @@ get_data_file_headers(HeaderMap *hdr_map, pgFile *file, uint32 backup_version, b
21812174
gotocleanup;
21822175
}
21832176

2184-
//elog(INFO, "zsize: %i, size: %i", file->hdr_size, read_len);
2185-
21862177
/* allocate memory for uncompressed headers */
21872178
headers=pgut_malloc(read_len);
21882179
memset(headers,0,read_len);
@@ -2244,7 +2235,7 @@ write_page_headers(BackupPageHeader2 *headers, pgFile *file, HeaderMap *hdr_map,
22442235
if (file->n_headers <=0)
22452236
return;
22462237

2247-
/* when running merge we mustsave headers into the temp map */
2238+
/* when running merge we mustwrite headers into temp map */
22482239
map_path= (is_merge) ?hdr_map->path_tmp :hdr_map->path;
22492240
read_len= (file->n_headers+1)*sizeof(BackupPageHeader2);
22502241

‎src/restore.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
345345
if (params->incremental_mode!=INCR_NONE&&pgdata_is_empty&&tblspaces_are_empty)
346346
{
347347
elog(INFO,"Destination directory and tablespace directories are empty, "
348-
"disabled incremental restore");
348+
"disable incremental restore");
349349
params->incremental_mode=INCR_NONE;
350350
}
351351

@@ -699,7 +699,7 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
699699
parray_qsort(backup->files,pgFileCompareRelPathWithExternal);
700700
}
701701

702-
/* If dest backup version is older than 2.3.0, then bitmap optimization
702+
/* If dest backup version is older than 2.4.0, then bitmap optimization
703703
* is impossible to use, because bitmap restore rely on pgFile.n_blocks,
704704
* which is not always available in old backups.
705705
*/
@@ -2009,7 +2009,7 @@ check_incremental_compatibility(const char *pgdata, uint64 system_identifier,
20092009
{
20102010
elog(WARNING,"Destination directory contains \"backup_control\" file. "
20112011
"This does NOT mean that you should delete this file and retry, only that "
2012-
"incremental restore in 'lsn' modecan produce incorrect result, when applied "
2012+
"incremental restore in 'lsn' modemay produce incorrect result, when applied "
20132013
"to cluster with pg_control not synchronized with cluster state."
20142014
"Consider to use incremental restore in 'checksum' mode");
20152015
success= false;

‎src/utils/file.c‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ fio_disconnect(void)
455455
hdr.size=0;
456456
IO_CHECK(fio_write_all(fio_stdout,&hdr,sizeof(hdr)),sizeof(hdr));
457457
IO_CHECK(fio_read_all(fio_stdin,&hdr,sizeof(hdr)),sizeof(hdr));
458-
Assert(hdr.cop==FIO_SEND_FILE_EOF);
458+
Assert(hdr.cop==FIO_DISCONNECTED);
459459
SYS_CHECK(close(fio_stdin));
460460
SYS_CHECK(close(fio_stdout));
461461
fio_stdin=0;
@@ -1652,7 +1652,8 @@ static void fio_send_pages_impl(int out, char* buf)
16521652
/* read page, check header and validate checksumms */
16531653
for (;;)
16541654
{
1655-
/* Optimize stdio buffer usage, fseek only when current position
1655+
/*
1656+
* Optimize stdio buffer usage, fseek only when current position
16561657
* does not match the position of requested block.
16571658
*/
16581659
if (current_pos!=blknum*BLCKSZ)
@@ -1665,10 +1666,7 @@ static void fio_send_pages_impl(int out, char* buf)
16651666

16661667
read_len=fread(read_buffer,1,BLCKSZ,in);
16671668

1668-
page_st.lsn=InvalidXLogRecPtr;
1669-
page_st.checksum=0;
1670-
1671-
current_pos+=BLCKSZ;
1669+
current_pos+=read_len;
16721670

16731671
/* report error */
16741672
if (ferror(in))
@@ -1741,9 +1739,9 @@ static void fio_send_pages_impl(int out, char* buf)
17411739
* As far as unsigned number are always greater or equal than zero,
17421740
* there is no sense to add more checks.
17431741
*/
1744-
if ((req->horizonLsn==InvalidXLogRecPtr)||
1742+
if ((req->horizonLsn==InvalidXLogRecPtr)||/* full, page, ptrack */
17451743
(page_st.lsn==InvalidXLogRecPtr)||/* zeroed page */
1746-
(req->horizonLsn>0&&page_st.lsn >=req->horizonLsn))/* delta */
1744+
(req->horizonLsn>0&&page_st.lsn>req->horizonLsn))/* delta */
17471745
{
17481746
intcompressed_size=0;
17491747
charwrite_buffer[BLCKSZ*2];
@@ -1808,7 +1806,7 @@ static void fio_send_pages_impl(int out, char* buf)
18081806
{
18091807
hdr.size= (hdr_num+2)*sizeof(BackupPageHeader2);
18101808

1811-
/* addone additional header */
1809+
/* adddummy header */
18121810
headers= (BackupPageHeader2*)pgut_realloc(headers, (hdr_num+2)*sizeof(BackupPageHeader2));
18131811
headers[hdr_num+1].pos=cur_pos_out;
18141812
}
@@ -1817,13 +1815,6 @@ static void fio_send_pages_impl(int out, char* buf)
18171815
if (headers)
18181816
IO_CHECK(fio_write_all(out,headers,hdr.size),hdr.size);
18191817

1820-
/* send headers */
1821-
//hdr.cop = FIO_SEND_FILE_HEADERS;
1822-
//hdr.arg = hdr_num +1;
1823-
//hdr.size = hdr.arg * sizeof(BackupPageHeader2);
1824-
//IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));
1825-
//IO_CHECK(fio_write_all(out, headers, hdr.size), hdr.size);
1826-
18271818
cleanup:
18281819
pg_free(map);
18291820
pg_free(iter);
@@ -2388,7 +2379,7 @@ static void fio_get_checksum_map_impl(int out, char *buf)
23882379
req->n_blocks,req->stop_lsn,req->segmentno);
23892380
hdr.size=req->n_blocks;
23902381

2391-
/* sendarrays ofchecksums to main process */
2382+
/* sendarray ofPageState`s to main process */
23922383
IO_CHECK(fio_write_all(out,&hdr,sizeof(hdr)),sizeof(hdr));
23932384
if (hdr.size>0)
23942385
IO_CHECK(fio_write_all(out,checksum_map,hdr.size*sizeof(PageState)),hdr.size*sizeof(PageState));
@@ -2458,7 +2449,7 @@ static void fio_get_lsn_map_impl(int out, char *buf)
24582449
else
24592450
hdr.size=0;
24602451

2461-
/* sendarrays of checksums to main process */
2452+
/* sendbitmap to main process */
24622453
IO_CHECK(fio_write_all(out,&hdr,sizeof(hdr)),sizeof(hdr));
24632454
if (hdr.size>0)
24642455
IO_CHECK(fio_write_all(out,lsn_map->bitmap,hdr.size),hdr.size);
@@ -2691,7 +2682,7 @@ void fio_communicate(int in, int out)
26912682
fio_check_postmaster_impl(out,buf);
26922683
break;
26932684
caseFIO_DISCONNECT:
2694-
hdr.cop=FIO_SEND_FILE_EOF;
2685+
hdr.cop=FIO_DISCONNECTED;
26952686
IO_CHECK(fio_write_all(out,&hdr,sizeof(hdr)),sizeof(hdr));
26962687
break;
26972688
default:

‎src/utils/file.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef enum
4848
FIO_SEND_FILE_HEADERS,
4949
/* messages for closing connection */
5050
FIO_DISCONNECT,
51+
FIO_DISCONNECTED,
5152
/* message for compatibility check */
5253
FIO_AGENT_VERSION,
5354
FIO_LIST_DIR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp