2
2
*
3
3
* catchup.c: sync DB cluster
4
4
*
5
- * Copyright (c) 2021 , Postgres Professional
5
+ * Copyright (c) 2022 , Postgres Professional
6
6
*
7
7
*-------------------------------------------------------------------------
8
8
*/
@@ -507,16 +507,20 @@ catchup_multithreaded_copy(int num_threads,
507
507
/* Run threads */
508
508
thread_interrupted = false;
509
509
threads = (pthread_t * ) palloc (sizeof (pthread_t ) * num_threads );
510
- for ( i = 0 ; i < num_threads ; i ++ )
510
+ if (! dry_run )
511
511
{
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
+ }
514
517
}
515
518
516
519
/* Wait threads */
517
520
for (i = 0 ; i < num_threads ; i ++ )
518
521
{
519
- pthread_join (threads [i ], NULL );
522
+ if (!dry_run )
523
+ pthread_join (threads [i ], NULL );
520
524
all_threads_successful &= threads_args [i ].completed ;
521
525
transfered_bytes_result += threads_args [i ].transfered_bytes ;
522
526
}
@@ -706,9 +710,14 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
706
710
707
711
/* Start stream replication */
708
712
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" );
712
721
713
722
source_filelist = parray_new ();
714
723
@@ -779,9 +788,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
779
788
780
789
/* Build the page map from ptrack information */
781
790
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 );
785
794
time (& end_time );
786
795
elog (INFO , "Pagemap successfully extracted, time elapsed: %.0f sec" ,
787
796
difftime (end_time , start_time ));
@@ -820,9 +829,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
820
829
char dirpath [MAXPGPATH ];
821
830
822
831
join_path_components (dirpath , dest_pgdata , file -> rel_path );
823
-
824
832
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 );
826
835
}
827
836
else
828
837
{
@@ -853,15 +862,18 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
853
862
elog (VERBOSE , "Create directory \"%s\" and symbolic link \"%s\"" ,
854
863
linked_path , to_path );
855
864
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
+ }
865
877
}
866
878
}
867
879
@@ -930,7 +942,10 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
930
942
char fullpath [MAXPGPATH ];
931
943
932
944
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
+ }
934
949
elog (VERBOSE , "Deleted file \"%s\"" , fullpath );
935
950
936
951
/* shrink dest pgdata list */
@@ -961,7 +976,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
961
976
catchup_isok = transfered_datafiles_bytes != -1 ;
962
977
963
978
/* at last copy control file */
964
- if (catchup_isok)
979
+ if (catchup_isok && ! dry_run )
965
980
{
966
981
char from_fullpath [MAXPGPATH ];
967
982
char to_fullpath [MAXPGPATH ];
@@ -972,7 +987,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
972
987
transfered_datafiles_bytes += source_pg_control_file -> size ;
973
988
}
974
989
975
- if (!catchup_isok )
990
+ if (!catchup_isok && ! dry_run )
976
991
{
977
992
char pretty_time [20 ];
978
993
char pretty_transfered_data_bytes [20 ];
@@ -1010,14 +1025,18 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
1010
1025
pg_free (stop_backup_query_text );
1011
1026
}
1012
1027
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 );
1014
1030
1015
1031
#if PG_VERSION_NUM >= 90600
1016
1032
/* Write backup_label */
1017
1033
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
+ }
1021
1040
free (stop_backup_result .backup_label_content );
1022
1041
stop_backup_result .backup_label_content = NULL ;
1023
1042
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,
1040
1059
#endif
1041
1060
1042
1061
/* wait for end of wal streaming and calculate wal size transfered */
1062
+ if (!dry_run )
1043
1063
{
1044
1064
parray * wal_files_list = NULL ;
1045
1065
wal_files_list = parray_new ();
@@ -1091,17 +1111,17 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
1091
1111
}
1092
1112
1093
1113
/* Sync all copied files unless '--no-sync' flag is used */
1094
- if (sync_dest_files )
1114
+ if (sync_dest_files && ! dry_run )
1095
1115
catchup_sync_destination_files (dest_pgdata , FIO_LOCAL_HOST , source_filelist , source_pg_control_file );
1096
1116
else
1097
1117
elog (WARNING , "Files are not synced to disk" );
1098
1118
1099
1119
/* Cleanup */
1100
- if (dest_filelist )
1120
+ if (dest_filelist && ! dry_run )
1101
1121
{
1102
1122
parray_walk (dest_filelist , pgFileFree );
1103
- parray_free (dest_filelist );
1104
1123
}
1124
+ parray_free (dest_filelist );
1105
1125
parray_walk (source_filelist , pgFileFree );
1106
1126
parray_free (source_filelist );
1107
1127
pgFileFree (source_pg_control_file );
0 commit comments