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

Commit41457fc

Browse files
committed
Minor cleanup of pg_rewind.
Update comments and function names to use the terms "source" and "target"consistently. Some places were calling them remote and local instead, whichwas confusing.Fix incorrect comment in extractPageInfo on database creation record - itwas wrong on what happens for databases created in the target that don'texist in source.
1 parent0d8a22a commit41457fc

File tree

8 files changed

+58
-52
lines changed

8 files changed

+58
-52
lines changed

‎src/bin/pg_rewind/fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
#include"filemap.h"
2727

2828
void
29-
fetchRemoteFileList(void)
29+
fetchSourceFileList(void)
3030
{
3131
if (datadir_source)
32-
traverse_datadir(datadir_source,&process_remote_file);
32+
traverse_datadir(datadir_source,&process_source_file);
3333
else
3434
libpqProcessFileList();
3535
}

‎src/bin/pg_rewind/fetch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* Common interface. Calls the copy or libpq method depending on global
2626
* config options.
2727
*/
28-
externvoidfetchRemoteFileList(void);
28+
externvoidfetchSourceFileList(void);
2929
externchar*fetchFile(char*filename,size_t*filesize);
3030
externvoidexecuteFileMap(void);
3131

‎src/bin/pg_rewind/filemap.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ filemap_create(void)
5151
}
5252

5353
/*
54-
* Callback for processingremote file list.
54+
* Callback for processingsource file list.
5555
*
5656
* This is called once for every file in the source server. We decide what
5757
* action needs to be taken for the file, depending on whether the file
5858
* exists in the target and whether the size matches.
5959
*/
6060
void
61-
process_remote_file(constchar*path,file_type_ttype,size_tnewsize,
61+
process_source_file(constchar*path,file_type_ttype,size_tnewsize,
6262
constchar*link_target)
6363
{
6464
boolexists;
@@ -97,7 +97,7 @@ process_remote_file(const char *path, file_type_t type, size_t newsize,
9797

9898
snprintf(localpath,sizeof(localpath),"%s/%s",datadir_target,path);
9999

100-
/* Does the correspondinglocalfile exist? */
100+
/* Does the corresponding file exist in the target data dir? */
101101
if (lstat(localpath,&statbuf)<0)
102102
{
103103
if (errno!=ENOENT)
@@ -185,18 +185,19 @@ process_remote_file(const char *path, file_type_t type, size_t newsize,
185185
*
186186
* If it's smaller in the target, it means that it has been
187187
* truncated in the target, or enlarged in the source, or
188-
* both. If it was truncatedlocally, we need to copy the
189-
* missing tail from theremote system. If it was enlarged in
190-
* theremote system, there will be WAL records in theremote
188+
* both. If it was truncatedin the target, we need to copy the
189+
* missing tail from thesource system. If it was enlarged in
190+
* thesource system, there will be WAL records in thesource
191191
* system for the new blocks, so we wouldn't need to copy them
192192
* here. But we don't know which scenario we're dealing with,
193193
* and there's no harm in copying the missing blocks now, so
194194
* do it now.
195195
*
196-
* If it's the same size, do nothing here. Any locally
197-
* modified blocks will be copied based on parsing the local
198-
* WAL, and any remotely modified blocks will be updated after
199-
* rewinding, when the remote WAL is replayed.
196+
* If it's the same size, do nothing here. Any blocks modified
197+
* in the target will be copied based on parsing the target
198+
* system's WAL, and any blocks modified in the source will be
199+
* updated after rewinding, when the source system's WAL is
200+
* replayed.
200201
*/
201202
oldsize=statbuf.st_size;
202203
if (oldsize<newsize)
@@ -233,14 +234,15 @@ process_remote_file(const char *path, file_type_t type, size_t newsize,
233234
}
234235

235236
/*
236-
* Callback for processinglocal file list.
237+
* Callback for processingtarget file list.
237238
*
238-
* All remote files must be already processed before calling this. This only
239-
* marks local files that didn't exist in the remote system for deletion.
239+
* All source files must be already processed before calling this. This only
240+
* marks target data directory's files that didn't exist in the source for
241+
* deletion.
240242
*/
241243
void
242-
process_local_file(constchar*path,file_type_ttype,size_toldsize,
243-
constchar*link_target)
244+
process_target_file(constchar*path,file_type_ttype,size_toldsize,
245+
constchar*link_target)
244246
{
245247
boolexists;
246248
charlocalpath[MAXPGPATH];
@@ -266,7 +268,7 @@ process_local_file(const char *path, file_type_t type, size_t oldsize,
266268
if (map->nlist==0)
267269
{
268270
/* should not happen */
269-
pg_fatal("remote file list is empty\n");
271+
pg_fatal("source file list is empty\n");
270272
}
271273

272274
filemap_list_to_array(map);
@@ -288,7 +290,7 @@ process_local_file(const char *path, file_type_t type, size_t oldsize,
288290
exists= (bsearch(&key_ptr,map->array,map->narray,sizeof(file_entry_t*),
289291
path_cmp)!=NULL);
290292

291-
/* Remove any file or folder that doesn't exist in theremote system. */
293+
/* Remove any file or folder that doesn't exist in thesource system. */
292294
if (!exists)
293295
{
294296
entry=pg_malloc(sizeof(file_entry_t));
@@ -313,16 +315,16 @@ process_local_file(const char *path, file_type_t type, size_t oldsize,
313315
else
314316
{
315317
/*
316-
* We already handled all files that exist in theremote system in
317-
*process_remote_file().
318+
* We already handled all files that exist in thesource system in
319+
*process_source_file().
318320
*/
319321
}
320322
}
321323

322324
/*
323-
* This callback gets called while we read theoldWAL, for every block that
324-
* have changed in thelocal system. It makes note of all the changed blocks
325-
* in the pagemap of the file.
325+
* This callback gets called while we read the WAL in the target, for every
326+
*block thathave changed in thetarget system. It makes note of all the
327+
*changed blocksin the pagemap of the file.
326328
*/
327329
void
328330
process_block_change(ForkNumberforknum,RelFileNodernode,BlockNumberblkno)
@@ -388,8 +390,8 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
388390
{
389391
/*
390392
* If we don't have any record of this file in the file map, it means
391-
* that it's a relation that doesn't exist in theremote system, and
392-
* it was subsequently removed in thelocal system, too. We can safely
393+
* that it's a relation that doesn't exist in thesource system, and
394+
* it was subsequently removed in thetarget system, too. We can safely
393395
* ignore it.
394396
*/
395397
}

‎src/bin/pg_rewind/filemap.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ typedef struct file_entry_t
6262
typedefstructfilemap_t
6363
{
6464
/*
65-
* New entries are accumulated to a linked list, inprocess_remote_file
66-
* andprocess_local_file.
65+
* New entries are accumulated to a linked list, inprocess_source_file
66+
* andprocess_target_file.
6767
*/
6868
file_entry_t*first;
6969
file_entry_t*last;
@@ -94,9 +94,12 @@ extern void calculate_totals(void);
9494
externvoidprint_filemap(void);
9595

9696
/* Functions for populating the filemap */
97-
externvoidprocess_remote_file(constchar*path,file_type_ttype,size_tnewsize,constchar*link_target);
98-
externvoidprocess_local_file(constchar*path,file_type_ttype,size_tnewsize,constchar*link_target);
99-
externvoidprocess_block_change(ForkNumberforknum,RelFileNodernode,BlockNumberblkno);
97+
externvoidprocess_source_file(constchar*path,file_type_ttype,
98+
size_tnewsize,constchar*link_target);
99+
externvoidprocess_target_file(constchar*path,file_type_ttype,
100+
size_tnewsize,constchar*link_target);
101+
externvoidprocess_block_change(ForkNumberforknum,RelFileNodernode,
102+
BlockNumberblkno);
100103
externvoidfilemap_finalize(void);
101104

102105
#endif/* FILEMAP_H */

‎src/bin/pg_rewind/libpq_fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ libpqProcessFileList(void)
190190
else
191191
type=FILE_TYPE_REGULAR;
192192

193-
process_remote_file(path,type,filesize,link_target);
193+
process_source_file(path,type,filesize,link_target);
194194
}
195195
}
196196

‎src/bin/pg_rewind/logging.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ pg_log(eLogType type, const char *fmt,...)
7676
}
7777

7878

79+
/*
80+
* Print an error message, and exit.
81+
*/
7982
void
8083
pg_fatal(constchar*fmt,...)
8184
{

‎src/bin/pg_rewind/parsexlog.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,39 +314,37 @@ extractPageInfo(XLogReaderState *record)
314314
{
315315
/*
316316
* New databases can be safely ignored. It won't be present in the
317-
*remote system, so it will becopied in toto. There's one
318-
*corner-case,though: if a new, different, database is also created
319-
*in the remotesystem, we'll see that the files already exist and
320-
*not copythem. That's OK, though; WAL replay of creating the new
321-
*database,from theremote WAL, will re-copy the new database,
322-
* overwriting the database created in thelocal system.
317+
*source system, so it will bedeleted. There's one corner-case,
318+
* though: if a new, different, database is also created in the
319+
*sourcesystem, we'll see that the files already exist and not copy
320+
* them. That's OK, though; WAL replay of creating the new database,
321+
* from thesource systems's WAL, will re-copy the new database,
322+
* overwriting the database created in thetarget system.
323323
*/
324324
}
325325
elseif (rmid==RM_DBASE_ID&&rminfo==XLOG_DBASE_DROP)
326326
{
327327
/*
328328
* An existing database was dropped. We'll see that the files don't
329-
* exist inlocal system, and copy them in toto from theremote
329+
* exist inthe target data dir, and copy them in toto from thesource
330330
* system. No need to do anything special here.
331331
*/
332332
}
333333
elseif (rmid==RM_SMGR_ID&&rminfo==XLOG_SMGR_CREATE)
334334
{
335335
/*
336-
* We can safely ignore these. Thelocalfile will be removed, if it
337-
* doesn't exist inremote system. If a file with same name is created
338-
* inremote system, too, there will be WAL records for all the blocks
339-
* in it.
336+
* We can safely ignore these. The file will be removed from the
337+
*target, if itdoesn't exist insource system. If a file with same
338+
*name is createdinsource system, too, there will be WAL records
339+
*for all the blocksin it.
340340
*/
341341
}
342342
elseif (rmid==RM_SMGR_ID&&rminfo==XLOG_SMGR_TRUNCATE)
343343
{
344344
/*
345-
* We can safely ignore these. If a file is truncated locally, we'll
346-
* notice that when we compare the sizes, and will copy the missing
347-
* tail from remote system.
348-
*
349-
* TODO: But it would be nice to do some sanity cross-checking here..
345+
* We can safely ignore these. When we compare the sizes later on,
346+
* we'll notice that they differ, and copy the missing tail from
347+
* source system.
350348
*/
351349
}
352350
elseif (info&XLR_SPECIAL_REL_UPDATE)

‎src/bin/pg_rewind/pg_rewind.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ main(int argc, char **argv)
263263
chkpttli);
264264

265265
/*
266-
* Build the filemap, by comparing theremote andlocal data directories.
266+
* Build the filemap, by comparing thesource andtarget data directories.
267267
*/
268268
filemap_create();
269269
pg_log(PG_PROGRESS,"reading source file list\n");
270-
fetchRemoteFileList();
270+
fetchSourceFileList();
271271
pg_log(PG_PROGRESS,"reading target file list\n");
272-
traverse_datadir(datadir_target,&process_local_file);
272+
traverse_datadir(datadir_target,&process_target_file);
273273

274274
/*
275275
* Read the target WAL from last checkpoint before the point of fork, to

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp