mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
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, which was confusing. Fix incorrect comment in extractPageInfo on database creation record - it was wrong on what happens for databases created in the target that don't exist in source.
This commit is contained in:
@@ -51,14 +51,14 @@ filemap_create(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for processing remote file list.
|
||||
* Callback for processing source file list.
|
||||
*
|
||||
* This is called once for every file in the source server. We decide what
|
||||
* action needs to be taken for the file, depending on whether the file
|
||||
* exists in the target and whether the size matches.
|
||||
*/
|
||||
void
|
||||
process_remote_file(const char *path, file_type_t type, size_t newsize,
|
||||
process_source_file(const char *path, file_type_t type, size_t newsize,
|
||||
const char *link_target)
|
||||
{
|
||||
bool exists;
|
||||
@@ -97,7 +97,7 @@ process_remote_file(const char *path, file_type_t type, size_t newsize,
|
||||
|
||||
snprintf(localpath, sizeof(localpath), "%s/%s", datadir_target, path);
|
||||
|
||||
/* Does the corresponding local file exist? */
|
||||
/* Does the corresponding file exist in the target data dir? */
|
||||
if (lstat(localpath, &statbuf) < 0)
|
||||
{
|
||||
if (errno != ENOENT)
|
||||
@@ -185,18 +185,19 @@ process_remote_file(const char *path, file_type_t type, size_t newsize,
|
||||
*
|
||||
* If it's smaller in the target, it means that it has been
|
||||
* truncated in the target, or enlarged in the source, or
|
||||
* both. If it was truncated locally, we need to copy the
|
||||
* missing tail from the remote system. If it was enlarged in
|
||||
* the remote system, there will be WAL records in the remote
|
||||
* both. If it was truncated in the target, we need to copy the
|
||||
* missing tail from the source system. If it was enlarged in
|
||||
* the source system, there will be WAL records in the source
|
||||
* system for the new blocks, so we wouldn't need to copy them
|
||||
* here. But we don't know which scenario we're dealing with,
|
||||
* and there's no harm in copying the missing blocks now, so
|
||||
* do it now.
|
||||
*
|
||||
* If it's the same size, do nothing here. Any locally
|
||||
* modified blocks will be copied based on parsing the local
|
||||
* WAL, and any remotely modified blocks will be updated after
|
||||
* rewinding, when the remote WAL is replayed.
|
||||
* If it's the same size, do nothing here. Any blocks modified
|
||||
* in the target will be copied based on parsing the target
|
||||
* system's WAL, and any blocks modified in the source will be
|
||||
* updated after rewinding, when the source system's WAL is
|
||||
* replayed.
|
||||
*/
|
||||
oldsize = statbuf.st_size;
|
||||
if (oldsize < newsize)
|
||||
@@ -233,14 +234,15 @@ process_remote_file(const char *path, file_type_t type, size_t newsize,
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for processing local file list.
|
||||
* Callback for processing target file list.
|
||||
*
|
||||
* All remote files must be already processed before calling this. This only
|
||||
* marks local files that didn't exist in the remote system for deletion.
|
||||
* All source files must be already processed before calling this. This only
|
||||
* marks target data directory's files that didn't exist in the source for
|
||||
* deletion.
|
||||
*/
|
||||
void
|
||||
process_local_file(const char *path, file_type_t type, size_t oldsize,
|
||||
const char *link_target)
|
||||
process_target_file(const char *path, file_type_t type, size_t oldsize,
|
||||
const char *link_target)
|
||||
{
|
||||
bool exists;
|
||||
char localpath[MAXPGPATH];
|
||||
@@ -266,7 +268,7 @@ process_local_file(const char *path, file_type_t type, size_t oldsize,
|
||||
if (map->nlist == 0)
|
||||
{
|
||||
/* should not happen */
|
||||
pg_fatal("remote file list is empty\n");
|
||||
pg_fatal("source file list is empty\n");
|
||||
}
|
||||
|
||||
filemap_list_to_array(map);
|
||||
@@ -288,7 +290,7 @@ process_local_file(const char *path, file_type_t type, size_t oldsize,
|
||||
exists = (bsearch(&key_ptr, map->array, map->narray, sizeof(file_entry_t *),
|
||||
path_cmp) != NULL);
|
||||
|
||||
/* Remove any file or folder that doesn't exist in the remote system. */
|
||||
/* Remove any file or folder that doesn't exist in the source system. */
|
||||
if (!exists)
|
||||
{
|
||||
entry = pg_malloc(sizeof(file_entry_t));
|
||||
@@ -313,16 +315,16 @@ process_local_file(const char *path, file_type_t type, size_t oldsize,
|
||||
else
|
||||
{
|
||||
/*
|
||||
* We already handled all files that exist in the remote system in
|
||||
* process_remote_file().
|
||||
* We already handled all files that exist in the source system in
|
||||
* process_source_file().
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This callback gets called while we read the old WAL, for every block that
|
||||
* have changed in the local system. It makes note of all the changed blocks
|
||||
* in the pagemap of the file.
|
||||
* This callback gets called while we read the WAL in the target, for every
|
||||
* block that have changed in the target system. It makes note of all the
|
||||
* changed blocks in the pagemap of the file.
|
||||
*/
|
||||
void
|
||||
process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
|
||||
@@ -388,8 +390,8 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
|
||||
{
|
||||
/*
|
||||
* If we don't have any record of this file in the file map, it means
|
||||
* that it's a relation that doesn't exist in the remote system, and
|
||||
* it was subsequently removed in the local system, too. We can safely
|
||||
* that it's a relation that doesn't exist in the source system, and
|
||||
* it was subsequently removed in the target system, too. We can safely
|
||||
* ignore it.
|
||||
*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user