22 *
33 * catchup.c: sync DB cluster
44 *
5- * Copyright (c) 2021 , Postgres Professional
5+ * Copyright (c) 2022 , Postgres Professional
66 *
77 *-------------------------------------------------------------------------
88 */
@@ -507,16 +507,20 @@ catchup_multithreaded_copy(int num_threads,
507507 /* Run threads */
508508 thread_interrupted = false;
509509 threads = (pthread_t * ) palloc (sizeof (pthread_t ) * num_threads );
510- for ( i = 0 ; i < num_threads ; i ++ )
510+ if (! dry_run )
511511 {
512- elog (VERBOSE , "Start thread num: %i" , i );
513- pthread_create (& threads [i ], NULL , & catchup_thread_runner , & (threads_args [i ]));
512+ for (i = 0 ; i < num_threads ; i ++ )
513+ {
514+ elog (VERBOSE , "Start thread num: %i" , i );
515+ pthread_create (& threads [i ], NULL , & catchup_thread_runner , & (threads_args [i ]));
516+ }
514517 }
515518
516519 /* Wait threads */
517520 for (i = 0 ; i < num_threads ; i ++ )
518521 {
519- pthread_join (threads [i ], NULL );
522+ if (!dry_run )
523+ pthread_join (threads [i ], NULL );
520524 all_threads_successful &= threads_args [i ].completed ;
521525 transfered_bytes_result += threads_args [i ].transfered_bytes ;
522526 }
@@ -706,9 +710,14 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
706710
707711 /* Start stream replication */
708712 join_path_components (dest_xlog_path , dest_pgdata , PG_XLOG_DIR );
709- fio_mkdir (dest_xlog_path , DIR_PERMISSION , FIO_LOCAL_HOST );
710- start_WAL_streaming (source_conn , dest_xlog_path , & instance_config .conn_opt ,
711- current .start_lsn , current .tli , false);
713+ if (!dry_run )
714+ {
715+ fio_mkdir (dest_xlog_path , DIR_PERMISSION , FIO_LOCAL_HOST );
716+ start_WAL_streaming (source_conn , dest_xlog_path , & instance_config .conn_opt ,
717+ current .start_lsn , current .tli , false);
718+ }
719+ else
720+ elog (INFO , "WAL streaming skipping with --dry-run option" );
712721
713722 source_filelist = parray_new ();
714723
@@ -779,9 +788,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
779788
780789 /* Build the page map from ptrack information */
781790 make_pagemap_from_ptrack_2 (source_filelist , source_conn ,
782- source_node_info .ptrack_schema ,
783- source_node_info .ptrack_version_num ,
784- dest_redo .lsn );
791+ source_node_info .ptrack_schema ,
792+ source_node_info .ptrack_version_num ,
793+ dest_redo .lsn );
785794 time (& end_time );
786795 elog (INFO , "Pagemap successfully extracted, time elapsed: %.0f sec" ,
787796 difftime (end_time , start_time ));
@@ -820,9 +829,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
820829 char dirpath [MAXPGPATH ];
821830
822831 join_path_components (dirpath , dest_pgdata , file -> rel_path );
823-
824832 elog (VERBOSE , "Create directory '%s'" , dirpath );
825- fio_mkdir (dirpath , DIR_PERMISSION , FIO_LOCAL_HOST );
833+ if (!dry_run )
834+ fio_mkdir (dirpath , DIR_PERMISSION , FIO_LOCAL_HOST );
826835 }
827836 else
828837 {
@@ -853,15 +862,18 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
853862 elog (VERBOSE , "Create directory \"%s\" and symbolic link \"%s\"" ,
854863 linked_path , to_path );
855864
856- /* create tablespace directory */
857- if (fio_mkdir (linked_path , file -> mode , FIO_LOCAL_HOST ) != 0 )
858- elog (ERROR , "Could not create tablespace directory \"%s\": %s" ,
859- linked_path , strerror (errno ));
860-
861- /* create link to linked_path */
862- if (fio_symlink (linked_path , to_path , true, FIO_LOCAL_HOST ) < 0 )
863- elog (ERROR , "Could not create symbolic link \"%s\" -> \"%s\": %s" ,
864- linked_path , to_path , strerror (errno ));
865+ if (!dry_run )
866+ {
867+ /* create tablespace directory */
868+ if (fio_mkdir (linked_path , file -> mode , FIO_LOCAL_HOST ) != 0 )
869+ elog (ERROR , "Could not create tablespace directory \"%s\": %s" ,
870+ linked_path , strerror (errno ));
871+
872+ /* create link to linked_path */
873+ if (fio_symlink (linked_path , to_path , true, FIO_LOCAL_HOST ) < 0 )
874+ elog (ERROR , "Could not create symbolic link \"%s\" -> \"%s\": %s" ,
875+ linked_path , to_path , strerror (errno ));
876+ }
865877 }
866878 }
867879
@@ -930,7 +942,10 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
930942 char fullpath [MAXPGPATH ];
931943
932944 join_path_components (fullpath , dest_pgdata , file -> rel_path );
933- fio_delete (file -> mode , fullpath , FIO_LOCAL_HOST );
945+ if (!dry_run )
946+ {
947+ fio_delete (file -> mode , fullpath , FIO_LOCAL_HOST );
948+ }
934949 elog (VERBOSE , "Deleted file \"%s\"" , fullpath );
935950
936951 /* shrink dest pgdata list */
@@ -961,7 +976,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
961976 catchup_isok = transfered_datafiles_bytes != -1 ;
962977
963978 /* at last copy control file */
964- if (catchup_isok )
979+ if (catchup_isok && ! dry_run )
965980 {
966981 char from_fullpath [MAXPGPATH ];
967982 char to_fullpath [MAXPGPATH ];
@@ -972,7 +987,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
972987 transfered_datafiles_bytes += source_pg_control_file -> size ;
973988 }
974989
975- if (!catchup_isok )
990+ if (!catchup_isok && ! dry_run )
976991 {
977992 char pretty_time [20 ];
978993 char pretty_transfered_data_bytes [20 ];
@@ -1010,14 +1025,18 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
10101025 pg_free (stop_backup_query_text );
10111026 }
10121027
1013- wait_wal_and_calculate_stop_lsn (dest_xlog_path , stop_backup_result .lsn , & current );
1028+ if (!dry_run )
1029+ wait_wal_and_calculate_stop_lsn (dest_xlog_path , stop_backup_result .lsn , & current );
10141030
10151031#if PG_VERSION_NUM >= 90600
10161032 /* Write backup_label */
10171033 Assert (stop_backup_result .backup_label_content != NULL );
1018- pg_stop_backup_write_file_helper (dest_pgdata , PG_BACKUP_LABEL_FILE , "backup label" ,
1019- stop_backup_result .backup_label_content , stop_backup_result .backup_label_content_len ,
1020- NULL );
1034+ if (!dry_run )
1035+ {
1036+ pg_stop_backup_write_file_helper (dest_pgdata , PG_BACKUP_LABEL_FILE , "backup label" ,
1037+ stop_backup_result .backup_label_content , stop_backup_result .backup_label_content_len ,
1038+ NULL );
1039+ }
10211040 free (stop_backup_result .backup_label_content );
10221041 stop_backup_result .backup_label_content = NULL ;
10231042 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,
10401059#endif
10411060
10421061 /* wait for end of wal streaming and calculate wal size transfered */
1062+ if (!dry_run )
10431063 {
10441064 parray * wal_files_list = NULL ;
10451065 wal_files_list = parray_new ();
@@ -1091,17 +1111,17 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
10911111 }
10921112
10931113 /* Sync all copied files unless '--no-sync' flag is used */
1094- if (sync_dest_files )
1114+ if (sync_dest_files && ! dry_run )
10951115 catchup_sync_destination_files (dest_pgdata , FIO_LOCAL_HOST , source_filelist , source_pg_control_file );
10961116 else
10971117 elog (WARNING , "Files are not synced to disk" );
10981118
10991119 /* Cleanup */
1100- if (dest_filelist )
1120+ if (dest_filelist && ! dry_run )
11011121 {
11021122 parray_walk (dest_filelist , pgFileFree );
1103- parray_free (dest_filelist );
11041123 }
1124+ parray_free (dest_filelist );
11051125 parray_walk (source_filelist , pgFileFree );
11061126 parray_free (source_filelist );
11071127 pgFileFree (source_pg_control_file );
0 commit comments