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
132 {
"postgresql.auto.conf.tmp",
false},
135 {
"current_logfiles.tmp",
false},
139 {
"pg_internal.init",
true},
146 {
"backup_label",
false},
147 {
"tablespace_map",
false},
155 {
"backup_manifest",
false},
157 {
"postmaster.pid",
false},
158 {
"postmaster.opts",
false},
180 entry = filehash_insert(
filehash, path, &found);
207 return filehash_lookup(
filehash, path);
219 const char *link_target)
236 pg_fatal(
"data file \"%s\" in source is not a regular file", path);
241 pg_fatal(
"duplicate source file \"%s\"", path);
255 const char *link_target)
274 pg_fatal(
"duplicate source file \"%s\"", path);
299 segno = blkno / RELSEG_SIZE;
300 blkno_inseg = blkno % RELSEG_SIZE;
329 pg_fatal(
"unexpected page modification for non-regular file \"%s\"",
336 end_offset = (blkno_inseg + 1) * BLCKSZ;
337 if (end_offset <= entry->source_size && end_offset <= entry->target_size)
379 pg_log_debug(
"entry \"%s\" excluded from source file list",
382 pg_log_debug(
"entry \"%s\" excluded from target file list",
394 snprintf(localpath,
sizeof(localpath),
"%s/",
396 if (strstr(path, localpath) == path)
399 pg_log_debug(
"entry \"%s\" excluded from source file list",
402 pg_log_debug(
"entry \"%s\" excluded from target file list",
541 nmatch = sscanf(path,
"global/%u.%u", &rlocator.
relNumber, &segNo);
542 if (nmatch == 1 || nmatch == 2)
544 rlocator.
spcOid = GLOBALTABLESPACE_OID;
550 nmatch = sscanf(path,
"base/%u/%u.%u",
552 if (nmatch == 2 || nmatch == 3)
554 rlocator.
spcOid = DEFAULTTABLESPACE_OID;
562 if (nmatch == 3 || nmatch == 4)
577 if (strcmp(check_path, path) != 0)
600 segpath =
psprintf(
"%s.%u", path, segno);
624 if (
fa->action >
fb->action)
626 if (
fa->action <
fb->action)
630 return strcmp(
fb->path,
fa->path);
632 return strcmp(
fa->path,
fb->path);
641 const char *path = entry->
path;
647 if (strcmp(path,
"global/pg_control") == 0)
706 pg_fatal(
"file \"%s\" is of different type in source and target", entry->
path);
773 pg_fatal(
"unknown file type for \"%s\"", path);
778 pg_fatal(
"could not decide what to do with file \"%s\"", path);
791 filehash_iterator it;
795 filehash_start_iterate(
filehash, &it);
796 while ((entry = filehash_iterate(
filehash, &it)) != NULL)
808 filehash_start_iterate(
filehash, &it);
810 while ((entry = filehash_iterate(
filehash, &it)) != NULL)
828 unsigned char *ss = (
unsigned char *) s;
bool datapagemap_next(datapagemap_iterator_t *iter, BlockNumber *blkno)
void datapagemap_print(datapagemap_t *map)
void datapagemap_add(datapagemap_t *map, BlockNumber blkno)
datapagemap_iterator_t * datapagemap_iterate(datapagemap_t *map)
char * pg_strdup(const char *in)
void * pg_malloc(size_t size)
#define PG_TEMP_FILES_DIR
#define PG_TEMP_FILE_PREFIX
static const struct exclude_list_item excludeFiles[]
static bool isRelDataFile(const char *path)
void process_source_file(const char *path, file_type_t type, size_t size, const char *link_target)
static uint32 hash_string_pointer(const char *s)
static const char *const excludeDirContents[]
static const char * action_to_str(file_action_t action)
void print_filemap(filemap_t *filemap)
static char * datasegpath(RelFileLocator rlocator, ForkNumber forknum, BlockNumber segno)
static filehash_hash * filehash
void process_target_file(const char *path, file_type_t type, size_t size, const char *link_target)
void process_target_wal_block_change(ForkNumber forknum, RelFileLocator rlocator, BlockNumber blkno)
filemap_t * decide_file_actions(void)
static file_action_t decide_file_action(file_entry_t *entry)
static file_entry_t * lookup_filehash_entry(const char *path)
static file_entry_t * insert_filehash_entry(const char *path)
static bool check_file_excluded(const char *path, bool is_source)
#define FILEHASH_INITIAL_SIZE
static int final_filemap_cmp(const void *a, const void *b)
void calculate_totals(filemap_t *filemap)
uint32 hash_bytes(const unsigned char *k, int keylen)
static void const char fflush(stdout)
Assert(fmt[strlen(fmt) - 1] !='\n')
#define pg_log_debug(...)
void pfree(void *pointer)
char * last_dir_separator(const char *filename)
#define qsort(a, b, c, d)
char * psprintf(const char *fmt,...)
#define InvalidRelFileNumber
#define relpathperm(rlocator, forknum)
#define TABLESPACE_VERSION_DIRECTORY
bool pg_str_endswith(const char *str, const char *end)
datapagemap_t target_pages_to_overwrite
char * source_link_target
char * target_link_target
file_entry_t * entries[FLEXIBLE_ARRAY_MEMBER]