29 #include "catalog/pg_tablespace_d.h" 42 #define SH_PREFIX filehash 43 #define SH_ELEMENT_TYPE file_entry_t 44 #define SH_KEY_TYPE const char * 46 #define SH_HASH_KEY(tb, key) hash_string_pointer(key) 47 #define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0) 48 #define SH_SCOPE static inline 49 #define SH_RAW_ALLOCATOR pg_malloc0 54 #define FILEHASH_INITIAL_SIZE 1000 133 {
"postgresql.auto.conf.tmp",
false},
136 {
"current_logfiles.tmp",
false},
140 {
"pg_internal.init",
true},
147 {
"backup_label",
false},
148 {
"tablespace_map",
false},
156 {
"backup_manifest",
false},
158 {
"postmaster.pid",
false},
159 {
"postmaster.opts",
false},
181 entry = filehash_insert(
filehash, path, &found);
208 return filehash_lookup(
filehash, path);
220 const char *link_target)
237 pg_fatal(
"data file \"%s\" in source is not a regular file", path);
242 pg_fatal(
"duplicate source file \"%s\"", path);
256 const char *link_target)
275 pg_fatal(
"duplicate source file \"%s\"", path);
300 segno = blkno / RELSEG_SIZE;
301 blkno_inseg = blkno % RELSEG_SIZE;
330 pg_fatal(
"unexpected page modification for non-regular file \"%s\"",
337 end_offset = (blkno_inseg + 1) * BLCKSZ;
338 if (end_offset <= entry->source_size && end_offset <= entry->target_size)
365 for (excludeIdx = 0; excludeFiles[excludeIdx].
name != NULL; excludeIdx++)
367 int cmplen = strlen(excludeFiles[excludeIdx].
name);
370 if (filename == NULL)
377 if (strncmp(filename, excludeFiles[excludeIdx].name, cmplen) == 0)
380 pg_log_debug(
"entry \"%s\" excluded from source file list",
383 pg_log_debug(
"entry \"%s\" excluded from target file list",
395 snprintf(localpath,
sizeof(localpath),
"%s/",
397 if (strstr(path, localpath) == path)
400 pg_log_debug(
"entry \"%s\" excluded from source file list",
403 pg_log_debug(
"entry \"%s\" excluded from target file list",
447 for (i = 0; i < filemap->
nentries; i++)
485 for (i = 0; i < filemap->
nentries; i++)
542 nmatch = sscanf(path,
"global/%u.%u", &rnode.
relNode, &segNo);
543 if (nmatch == 1 || nmatch == 2)
545 rnode.
spcNode = GLOBALTABLESPACE_OID;
551 nmatch = sscanf(path,
"base/%u/%u.%u",
553 if (nmatch == 2 || nmatch == 3)
555 rnode.
spcNode = DEFAULTTABLESPACE_OID;
563 if (nmatch == 3 || nmatch == 4)
578 if (strcmp(check_path, path) != 0)
601 segpath =
psprintf(
"%s.%u", path, segno);
642 const char *path = entry->
path;
648 if (strcmp(path,
"global/pg_control") == 0)
707 pg_fatal(
"file \"%s\" is of different type in source and target", entry->
path);
774 pg_fatal(
"unknown file type for \"%s\"", path);
779 pg_fatal(
"could not decide what to do with file \"%s\"", path);
792 filehash_iterator it;
796 filehash_start_iterate(
filehash, &it);
797 while ((entry = filehash_iterate(
filehash, &it)) != NULL)
809 filehash_start_iterate(
filehash, &it);
811 while ((entry = filehash_iterate(
filehash, &it)) != NULL)
829 unsigned char *ss = (
unsigned char *) s;
static file_entry_t * insert_filehash_entry(const char *path)
void datapagemap_add(datapagemap_t *map, BlockNumber blkno)
static int final_filemap_cmp(const void *a, const void *b)
#define relpathperm(rnode, forknum)
bool pg_str_endswith(const char *str, const char *end)
void * pg_malloc(size_t size)
char * psprintf(const char *fmt,...)
static file_entry_t * lookup_filehash_entry(const char *path)
#define PG_TEMP_FILES_DIR
static bool check_file_excluded(const char *path, bool is_source)
void process_target_file(const char *path, file_type_t type, size_t size, const char *link_target)
static char * datasegpath(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
uint32 hash_bytes(const unsigned char *k, int keylen)
char * source_link_target
void pfree(void *pointer)
#define PG_TEMP_FILE_PREFIX
bool datapagemap_next(datapagemap_iterator_t *iter, BlockNumber *blkno)
#define pg_log_debug(...)
static file_action_t decide_file_action(file_entry_t *entry)
#define TABLESPACE_VERSION_DIRECTORY
static const char * action_to_str(file_action_t action)
void process_target_wal_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
char * pg_strdup(const char *in)
static const struct exclude_list_item excludeFiles[]
filemap_t * decide_file_actions(void)
void print_filemap(filemap_t *filemap)
static filehash_hash * filehash
datapagemap_t target_pages_to_overwrite
char * last_dir_separator(const char *filename)
void datapagemap_print(datapagemap_t *map)
void calculate_totals(filemap_t *filemap)
#define Assert(condition)
char * target_link_target
static bool isRelDataFile(const char *path)
datapagemap_iterator_t * datapagemap_iterate(datapagemap_t *map)
void process_source_file(const char *path, file_type_t type, size_t size, const char *link_target)
#define FILEHASH_INITIAL_SIZE
file_entry_t * entries[FLEXIBLE_ARRAY_MEMBER]
#define qsort(a, b, c, d)
static const char * excludeDirContents[]
#define offsetof(type, field)
static uint32 hash_string_pointer(const char *s)