42#define SYNC_QUEUE_MAX_LEN (1024)
79 pre_sync_fname(fname,
false);
109 char *old_pgdata,
char *new_pgdata)
146 new_pgdata, old_pgdata);
172 char *old_pgdata,
char *new_pgdata,
char *old_tablespace)
178 for (old_dbnum = new_dbnum = 0;
179 old_dbnum < old_db_arr->
ndbs;
180 old_dbnum++, new_dbnum++)
182 DbInfo *old_db = &old_db_arr->
dbs[old_dbnum],
192 for (; new_dbnum < new_db_arr->
ndbs; new_dbnum++)
194 new_db = &new_db_arr->
dbs[new_dbnum];
195 if (strcmp(old_db->
db_name, new_db->db_name) == 0)
199 if (new_dbnum >= new_db_arr->
ndbs)
200 pg_fatal(
"old database \"%s\" not found in the new cluster",
238 char *old_catalog_dir,
char *new_db_dir,
char *moved_db_dir)
240 const char *new_tablespace;
241 const char *old_tblspc_suffix;
242 const char *new_tblspc_suffix;
252 new_tblspc_suffix =
"/base";
253 old_tblspc_suffix =
"/base";
263 new_tablespace = old_tablespace;
270 snprintf(old_tblspc,
sizeof(old_tblspc),
"%s%s", old_tablespace, old_tblspc_suffix);
271 snprintf(new_tblspc,
sizeof(new_tblspc),
"%s%s", new_tablespace, new_tblspc_suffix);
272 snprintf(old_db_dir,
sizeof(old_db_dir),
"%s/%u", old_tblspc, db_oid);
279 snprintf(moved_tblspc,
sizeof(moved_tblspc),
"%s/moved_for_upgrade", old_tblspc);
280 snprintf(old_catalog_dir,
MAXPGPATH,
"%s/%u_old_catalogs", moved_tblspc, db_oid);
284 if (
stat(old_db_dir, &st) != 0)
287 pg_fatal(
"could not stat file \"%s\": %m", old_db_dir);
293 pg_fatal(
"could not create directory \"%s\"", moved_tblspc);
297 pg_fatal(
"could not create directory \"%s\"", old_catalog_dir);
300 if (rename(new_db_dir, moved_db_dir) != 0)
301 pg_fatal(
"could not rename \"%s\" to \"%s\"", new_db_dir, moved_db_dir);
304 if (rename(old_db_dir, new_db_dir) != 0)
305 pg_fatal(
"could not rename \"%s\" to \"%s\"", old_db_dir, new_db_dir);
364 const char *new_db_dir,
const char *moved_db_dir)
375 pg_fatal(
"could not open directory \"%s\": %m", new_db_dir);
376 while (errno = 0, (de =
readdir(dir)) != NULL)
392 if (rename(path,
dest) != 0)
393 pg_fatal(
"could not rename \"%s\" to \"%s\": %m", path,
dest);
396 pg_fatal(
"could not read directory \"%s\": %m", new_db_dir);
402 pg_fatal(
"could not open directory \"%s\": %m", moved_db_dir);
403 while (errno = 0, (de =
readdir(dir)) != NULL)
419 if (rename(path,
dest) != 0)
420 pg_fatal(
"could not rename \"%s\" to \"%s\": %m", path,
dest);
434 pg_fatal(
"could not read directory \"%s\": %m", moved_db_dir);
439 pg_fatal(
"could not synchronize directory \"%s\": %m", new_db_dir);
441 pg_fatal(
"could not synchronize parent directory of \"%s\": %m", new_db_dir);
474 old_catalog_dir, new_db_dir, moved_db_dir))
476 old_catalog_dir, new_db_dir, moved_db_dir);
481 old_catalog_dir, new_db_dir, moved_db_dir))
483 old_catalog_dir, new_db_dir, moved_db_dir);
488 old_catalog_dir, new_db_dir, moved_db_dir))
490 old_catalog_dir, new_db_dir, moved_db_dir);
504 bool vm_must_add_frozenbit =
false;
511 vm_must_add_frozenbit =
true;
521 Assert(!vm_must_add_frozenbit);
527 for (mapnum = 0; mapnum < size; mapnum++)
529 if (old_tablespace == NULL ||
530 strcmp(
maps[mapnum].old_tablespace, old_tablespace) == 0)
558 char extent_suffix[65];
566 for (segno = 0;; segno++)
569 extent_suffix[0] =
'\0';
571 snprintf(extent_suffix,
sizeof(extent_suffix),
".%d", segno);
573 snprintf(old_file,
sizeof(old_file),
"%s%s/%u/%u%s%s",
580 snprintf(new_file,
sizeof(new_file),
"%s%s/%u/%u%s%s",
589 if (type_suffix[0] !=
'\0' || segno != 0)
592 if (
stat(old_file, &statbuf) != 0)
598 pg_fatal(
"error while checking for file existence \"%s.%s\" (\"%s\" to \"%s\"): %m",
612 if (vm_must_add_frozenbit && strcmp(type_suffix,
"_vm") == 0)
void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata, char *old_tablespace)
bool reap_child(bool wait_for_child)
struct dirent * readdir(DIR *)
DIR * opendir(const char *)
void fsync_fname(const char *fname, bool isdir)
static int fsync_parent_path(const char *fname, int elevel)
void linkFile(const char *src, const char *dst, const char *schemaName, const char *relName)
void rewriteVisibilityMap(const char *fromfile, const char *tofile, const char *schemaName, const char *relName)
void cloneFile(const char *src, const char *dst, const char *schemaName, const char *relName)
void copyFileByRange(const char *src, const char *dst, const char *schemaName, const char *relName)
void copyFile(const char *src, const char *dst, const char *schemaName, const char *relName)
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
Assert(PointerIsAligned(start, uint64))
FileNameMap * gen_db_file_maps(DbInfo *old_db, DbInfo *new_db, int *nmaps, const char *old_pgdata, const char *new_pgdata)
static void check_ok(void)
static int pg_cmp_u32(uint32 a, uint32 b)
void pfree(void *pointer)
#define VISIBILITY_MAP_FROZEN_BIT_CAT_VER
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
@ TRANSFER_MODE_COPY_FILE_RANGE
void void prep_status_progress(const char *fmt,...) pg_attribute_printf(1
void void pg_noreturn void void end_progress_output(void)
int pg_mkdir_p(char *path, int omode)
#define qsort(a, b, c, d)
void transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata)
static void do_swap(FileNameMap *maps, int size, char *old_tablespace)
static char * sync_queue[SYNC_QUEUE_MAX_LEN]
static RelFileNumber parse_relfilenumber(const char *filename)
static void sync_queue_init(void)
void transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata, char *old_tablespace)
static void sync_queue_destroy(void)
static void transfer_relfile(FileNameMap *map, const char *type_suffix, bool vm_must_add_frozenbit)
static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
static int sync_queue_len
static bool sync_queue_inited
static void sync_queue_push(const char *fname)
static bool prepare_for_swap(const char *old_tablespace, Oid db_oid, char *old_catalog_dir, char *new_db_dir, char *moved_db_dir)
static void swap_catalog_files(FileNameMap *maps, int size, const char *old_catalog_dir, const char *new_db_dir, const char *moved_db_dir)
#define SYNC_QUEUE_MAX_LEN
static int FileNameMapCmp(const void *a, const void *b)
static void sync_queue_sync_all(void)
#define InvalidRelFileNumber
#define RelFileNumberIsValid(relnumber)
const char * tablespace_suffix
const char * new_tablespace
const char * old_tablespace_suffix
const char * old_tablespace
RelFileNumber relfilenumber
const char * new_tablespace_suffix
transferMode transfer_mode
static const pg_conv_map maps[]