-
Notifications
You must be signed in to change notification settings - Fork 87
[pbckp-128] dry-run option for catchup #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
d601bee
00f781d
985cba3
cb46fd1
ac77a14
a01b518
4d6a3e9
b4d565f
c32f854
448efc2
63760d4
417992f
76736ef
f38feeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* | ||
* catchup.c: sync DB cluster | ||
* | ||
* Copyright (c) 2021, Postgres Professional | ||
* Copyright (c) 2022, Postgres Professional | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
|
@@ -509,14 +509,18 @@ catchup_multithreaded_copy(int num_threads, | |
threads = (pthread_t *) palloc(sizeof(pthread_t) * num_threads); | ||
for (i = 0; i < num_threads; i++) | ||
{ | ||
elog(VERBOSE, "Start thread num: %i", i); | ||
pthread_create(&threads[i], NULL, &catchup_thread_runner, &(threads_args[i])); | ||
if (!dry_run) | ||
{ | ||
elog(VERBOSE, "Start thread num: %i", i); | ||
pthread_create(&threads[i], NULL, &catchup_thread_runner, &(threads_args[i])); | ||
} | ||
} | ||
|
||
/* Wait threads */ | ||
for (i = 0; i < num_threads; i++) | ||
{ | ||
pthread_join(threads[i], NULL); | ||
if (!dry_run) | ||
pthread_join(threads[i], NULL); | ||
all_threads_successful &= threads_args[i].completed; | ||
transfered_bytes_result += threads_args[i].transfered_bytes; | ||
} | ||
|
@@ -706,9 +710,14 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, | |
|
||
/* Start stream replication */ | ||
join_path_components(dest_xlog_path, dest_pgdata, PG_XLOG_DIR); | ||
fio_mkdir(dest_xlog_path, DIR_PERMISSION, FIO_LOCAL_HOST); | ||
start_WAL_streaming(source_conn, dest_xlog_path, &instance_config.conn_opt, | ||
current.start_lsn, current.tli, false); | ||
if (!dry_run) | ||
{ | ||
fio_mkdir(dest_xlog_path, DIR_PERMISSION, FIO_LOCAL_HOST); | ||
start_WAL_streaming(source_conn, dest_xlog_path, &instance_config.conn_opt, | ||
current.start_lsn, current.tli, false); | ||
} | ||
else | ||
elog(INFO, "WAL streaming cannot be started with --dry-run option"); | ||
|
||
source_filelist = parray_new(); | ||
|
||
|
@@ -779,9 +788,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, | |
|
||
/* Build the page map from ptrack information */ | ||
make_pagemap_from_ptrack_2(source_filelist, source_conn, | ||
source_node_info.ptrack_schema, | ||
source_node_info.ptrack_version_num, | ||
dest_redo.lsn); | ||
source_node_info.ptrack_schema, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. оформление: зачем-то появились три лишних табуляции. |
||
source_node_info.ptrack_version_num, | ||
dest_redo.lsn); | ||
time(&end_time); | ||
elog(INFO, "Pagemap successfully extracted, time elapsed: %.0f sec", | ||
difftime(end_time, start_time)); | ||
|
@@ -820,9 +829,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, | |
char dirpath[MAXPGPATH]; | ||
|
||
join_path_components(dirpath, dest_pgdata, file->rel_path); | ||
|
||
elog(VERBOSE, "Create directory '%s'", dirpath); | ||
fio_mkdir(dirpath, DIR_PERMISSION, FIO_LOCAL_HOST); | ||
if (!dry_run) | ||
fio_mkdir(dirpath, DIR_PERMISSION, FIO_LOCAL_HOST); | ||
} | ||
else | ||
{ | ||
|
@@ -853,15 +862,18 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, | |
elog(VERBOSE, "Create directory \"%s\" and symbolic link \"%s\"", | ||
linked_path, to_path); | ||
|
||
/* create tablespace directory */ | ||
if (fio_mkdir(linked_path, file->mode, FIO_LOCAL_HOST) != 0) | ||
elog(ERROR, "Could not create tablespace directory \"%s\": %s", | ||
linked_path, strerror(errno)); | ||
|
||
/* create link to linked_path */ | ||
if (fio_symlink(linked_path, to_path, true, FIO_LOCAL_HOST) < 0) | ||
elog(ERROR, "Could not create symbolic link \"%s\" -> \"%s\": %s", | ||
linked_path, to_path, strerror(errno)); | ||
if (!dry_run) | ||
{ | ||
/* create tablespace directory */ | ||
if (fio_mkdir(linked_path, file->mode, FIO_LOCAL_HOST) != 0) | ||
elog(ERROR, "Could not create tablespace directory \"%s\": %s", | ||
linked_path, strerror(errno)); | ||
|
||
/* create link to linked_path */ | ||
if (fio_symlink(linked_path, to_path, true, FIO_LOCAL_HOST) < 0) | ||
elog(ERROR, "Could not create symbolic link \"%s\" -> \"%s\": %s", | ||
linked_path, to_path, strerror(errno)); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -930,8 +942,11 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, | |
char fullpath[MAXPGPATH]; | ||
|
||
join_path_components(fullpath, dest_pgdata, file->rel_path); | ||
fio_delete(file->mode, fullpath, FIO_LOCAL_HOST); | ||
elog(VERBOSE, "Deleted file \"%s\"", fullpath); | ||
if (!dry_run) | ||
{ | ||
fio_delete(file->mode, fullpath, FIO_LOCAL_HOST); | ||
elog(VERBOSE, "Deleted file \"%s\"", fullpath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Сообщение надо оставить |
||
} | ||
|
||
/* shrink dest pgdata list */ | ||
pgFileFree(file); | ||
|
@@ -961,7 +976,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, | |
catchup_isok = transfered_datafiles_bytes != -1; | ||
|
||
/* at last copy control file */ | ||
if (catchup_isok) | ||
if (catchup_isok && !dry_run) | ||
{ | ||
char from_fullpath[MAXPGPATH]; | ||
char to_fullpath[MAXPGPATH]; | ||
|
@@ -972,7 +987,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, | |
transfered_datafiles_bytes += source_pg_control_file->size; | ||
} | ||
|
||
if (!catchup_isok) | ||
if (!catchup_isok && !dry_run) | ||
{ | ||
char pretty_time[20]; | ||
char pretty_transfered_data_bytes[20]; | ||
|
@@ -1010,15 +1025,19 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, | |
pg_free(stop_backup_query_text); | ||
} | ||
|
||
wait_wal_and_calculate_stop_lsn(dest_xlog_path, stop_backup_result.lsn, ¤t); | ||
if (!dry_run) | ||
wait_wal_and_calculate_stop_lsn(dest_xlog_path, stop_backup_result.lsn, ¤t); | ||
|
||
#if PG_VERSION_NUM >= 90600 | ||
/* Write backup_label */ | ||
Assert(stop_backup_result.backup_label_content != NULL); | ||
pg_stop_backup_write_file_helper(dest_pgdata, PG_BACKUP_LABEL_FILE, "backup label", | ||
stop_backup_result.backup_label_content, stop_backup_result.backup_label_content_len, | ||
NULL); | ||
free(stop_backup_result.backup_label_content); | ||
if (!dry_run) | ||
{ | ||
pg_stop_backup_write_file_helper(dest_pgdata, PG_BACKUP_LABEL_FILE, "backup label", | ||
stop_backup_result.backup_label_content, stop_backup_result.backup_label_content_len, | ||
NULL); | ||
free(stop_backup_result.backup_label_content); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Получается что тут память утекает? |
||
} | ||
stop_backup_result.backup_label_content = NULL; | ||
stop_backup_result.backup_label_content_len = 0; | ||
|
||
|
@@ -1040,6 +1059,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, | |
#endif | ||
|
||
/* wait for end of wal streaming and calculate wal size transfered */ | ||
if (!dry_run) | ||
{ | ||
parray *wal_files_list = NULL; | ||
wal_files_list = parray_new(); | ||
|
@@ -1091,13 +1111,13 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, | |
} | ||
|
||
/* Sync all copied files unless '--no-sync' flag is used */ | ||
if (sync_dest_files) | ||
if (sync_dest_files && !dry_run) | ||
catchup_sync_destination_files(dest_pgdata, FIO_LOCAL_HOST, source_filelist, source_pg_control_file); | ||
else | ||
elog(WARNING, "Files are not synced to disk"); | ||
|
||
/* Cleanup */ | ||
if (dest_filelist) | ||
if (dest_filelist && !dry_run) | ||
kulaginm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
parray_walk(dest_filelist, pgFileFree); | ||
parray_free(dest_filelist); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
придирка: необязательно проверять условие в цикле, когда можно весь цикл вынести под условие