Skip to content

Commit cb46fd1

Browse files
committed
Fix review notes. Correct compute size of transfered files with dry-run option
1 parent 985cba3 commit cb46fd1

File tree

3 files changed

+33
-42
lines changed

3 files changed

+33
-42
lines changed

src/catchup.c

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,18 @@ catchup_multithreaded_copy(int num_threads,
511511
threads = (pthread_t *) palloc(sizeof(pthread_t) * num_threads);
512512
for (i = 0; i < num_threads; i++)
513513
{
514-
elog(VERBOSE, "Start thread num: %i", i);
515-
pthread_create(&threads[i], NULL, &catchup_thread_runner, &(threads_args[i]));
514+
if (!dry_run)
515+
{
516+
elog(VERBOSE, "Start thread num: %i", i);
517+
pthread_create(&threads[i], NULL, &catchup_thread_runner, &(threads_args[i]));
518+
}
516519
}
517520

518521
/* Wait threads */
519522
for (i = 0; i < num_threads; i++)
520523
{
521-
pthread_join(threads[i], NULL);
524+
if (!dry_run)
525+
pthread_join(threads[i], NULL);
522526
all_threads_successful &= threads_args[i].completed;
523527
transfered_bytes_result += threads_args[i].transfered_bytes;
524528
}
@@ -714,6 +718,8 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
714718
start_WAL_streaming(source_conn, dest_xlog_path, &instance_config.conn_opt,
715719
current.start_lsn, current.tli, false);
716720
}
721+
else
722+
elog(INFO, "WAL streaming cannot be started with --dry-run option");
717723

718724
source_filelist = parray_new();
719725

@@ -784,9 +790,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
784790

785791
/* Build the page map from ptrack information */
786792
make_pagemap_from_ptrack_2(source_filelist, source_conn,
787-
source_node_info.ptrack_schema,
788-
source_node_info.ptrack_version_num,
789-
dest_redo.lsn);
793+
source_node_info.ptrack_schema,
794+
source_node_info.ptrack_version_num,
795+
dest_redo.lsn);
790796
time(&end_time);
791797
elog(INFO, "Pagemap successfully extracted, time elapsed: %.0f sec",
792798
difftime(end_time, start_time));
@@ -909,7 +915,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
909915
*/
910916
if (current.backup_mode != BACKUP_MODE_FULL)
911917
{
912-
elog(INFO, "Redundant files %s in destination directory", dry_run ? "can" : "will");
918+
elog(INFO, "Redundant files in destination directory %s be removed", dry_run ? "can" : "will");
913919
parray_qsort(dest_filelist, pgFileCompareRelPathWithExternalDesc);
914920
for (i = 0; i < parray_num(dest_filelist); i++)
915921
{
@@ -945,8 +951,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
945951
}
946952

947953
/* shrink dest pgdata list */
948-
if (!dry_run)
949-
pgFileFree(file);
954+
pgFileFree(file);
950955
parray_remove(dest_filelist, i);
951956
i--;
952957
}
@@ -963,17 +968,14 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
963968
if (dest_filelist)
964969
parray_qsort(dest_filelist, pgFileCompareRelPathWithExternal);
965970

966-
if (!dry_run)
967-
{
968-
/* run copy threads */
969-
elog(INFO, "Start transferring data files");
970-
time(&start_time);
971-
transfered_datafiles_bytes = catchup_multithreaded_copy(num_threads, &source_node_info,
972-
source_pgdata, dest_pgdata,
973-
source_filelist, dest_filelist,
974-
dest_redo.lsn, current.backup_mode);
975-
catchup_isok = transfered_datafiles_bytes != -1;
976-
}
971+
/* run copy threads */
972+
elog(INFO, "Transferring data files %s started", dry_run ? "can be" : "");
973+
time(&start_time);
974+
transfered_datafiles_bytes = catchup_multithreaded_copy(num_threads, &source_node_info,
975+
source_pgdata, dest_pgdata,
976+
source_filelist, dest_filelist,
977+
dest_redo.lsn, current.backup_mode);
978+
catchup_isok = transfered_datafiles_bytes != -1;
977979

978980
/* at last copy control file */
979981
if (catchup_isok && !dry_run)
@@ -1101,7 +1103,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
11011103
pretty_size(transfered_datafiles_bytes, pretty_transfered_data_bytes, lengthof(pretty_transfered_data_bytes));
11021104
pretty_size(transfered_walfiles_bytes, pretty_transfered_wal_bytes, lengthof(pretty_transfered_wal_bytes));
11031105

1104-
elog(INFO, "Databases %s synchronized. Transfered datafiles size: %s, transfered wal size: %s, time elapsed: %s",
1106+
elog(INFO, "Databases %s synchronized. Transfered datafiles sizes: %s, transfered wal size: %s, time elapsed: %s",
11051107
dry_run ? "can be" : "was",
11061108
pretty_transfered_data_bytes, pretty_transfered_wal_bytes, pretty_time);
11071109

@@ -1112,14 +1114,10 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
11121114
}
11131115

11141116
/* Sync all copied files unless '--no-sync' flag is used */
1115-
if (!dry_run)
1116-
{
1117-
/* Sync all copied files unless '--no-sync' flag is used */
1118-
if (sync_dest_files)
1119-
catchup_sync_destination_files(dest_pgdata, FIO_LOCAL_HOST, source_filelist, source_pg_control_file);
1120-
else
1121-
elog(WARNING, "Files are not synced to disk");
1122-
}
1117+
if (sync_dest_files && !dry_run)
1118+
catchup_sync_destination_files(dest_pgdata, FIO_LOCAL_HOST, source_filelist, source_pg_control_file);
1119+
else
1120+
elog(WARNING, "Files are not synced to disk");
11231121

11241122
/* Cleanup */
11251123
if (dest_filelist && !dry_run)

src/ptrack.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,8 @@ make_pagemap_from_ptrack_2(parray *files,
260260
page_map_entry *dummy_map = NULL;
261261

262262
/* Receive all available ptrack bitmaps at once */
263-
if (!dry_run)
264-
filemaps = pg_ptrack_get_pagemapset(backup_conn, ptrack_schema,
265-
ptrack_version_num, lsn);
263+
filemaps = pg_ptrack_get_pagemapset(backup_conn, ptrack_schema,
264+
ptrack_version_num, lsn);
266265

267266
if (filemaps != NULL)
268267
parray_qsort(filemaps, pgFileMapComparePath);

tests/catchup.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ def test_dry_run_catchup_full(self):
14751475
dst_pg = self.make_empty_node(os.path.join(module_name, self.fname, 'dst'))
14761476

14771477
# save the condition before dry-run
1478-
dst_before = dst_pg.data_dir
1478+
content_before = self.pgdata_content(dst_pg.data_dir)
14791479

14801480
# do full catchup
14811481
self.catchup_node(
@@ -1487,16 +1487,10 @@ def test_dry_run_catchup_full(self):
14871487

14881488
# compare data dirs before and after cathup
14891489
self.compare_pgdata(
1490-
self.pgdata_content(dst_before),
1490+
content_before,
14911491
self.pgdata_content(dst_pg.data_dir)
14921492
)
14931493

1494-
# compare data dirs before and after cathup
1495-
# self.compare_pgdata(
1496-
# self.pgdata_content(dst_before),
1497-
# self.pgdata_content(dst_pg.data_dir)
1498-
# )
1499-
15001494
# Cleanup
15011495
src_pg.stop()
15021496

@@ -1534,7 +1528,7 @@ def test_dry_run_catchup_ptrack(self):
15341528
dst_pg.stop()
15351529

15361530
# save the condition before dry-run
1537-
dst_before = dst_pg.data_dir
1531+
content_before = self.pgdata_content(dst_pg.data_dir)
15381532

15391533
# do incremental catchup
15401534
self.catchup_node(
@@ -1546,7 +1540,7 @@ def test_dry_run_catchup_ptrack(self):
15461540

15471541
# compare data dirs before and after cathup
15481542
self.compare_pgdata(
1549-
self.pgdata_content(dst_before),
1543+
content_before,
15501544
self.pgdata_content(dst_pg.data_dir)
15511545
)
15521546

0 commit comments

Comments
 (0)