@@ -30,6 +30,7 @@ typedef struct
3030 bool program_version_match ;
3131 bool use_bitmap ;
3232 bool is_retry ;
33+ bool no_sync ;
3334
3435 /*
3536 * Return value from the thread.
@@ -50,13 +51,13 @@ static void
5051merge_data_file (parray * parent_chain , pgBackup * full_backup ,
5152 pgBackup * dest_backup , pgFile * dest_file ,
5253 pgFile * tmp_file , const char * to_root , bool use_bitmap ,
53- bool is_retry );
54+ bool is_retry , bool no_sync );
5455
5556static void
5657merge_non_data_file (parray * parent_chain , pgBackup * full_backup ,
5758 pgBackup * dest_backup , pgFile * dest_file ,
5859 pgFile * tmp_file , const char * full_database_dir ,
59- const char * full_external_prefix );
60+ const char * full_external_prefix , bool no_sync );
6061
6162static bool is_forward_compatible (parray * parent_chain );
6263
@@ -68,7 +69,7 @@ static bool is_forward_compatible(parray *parent_chain);
6869 * - Remove unnecessary files, which doesn't exist in the target backup anymore
6970 */
7071void
71- do_merge (time_t backup_id )
72+ do_merge (time_t backup_id , bool no_validate , bool no_sync )
7273{
7374 parray * backups ;
7475 parray * merge_list = parray_new ();
@@ -405,9 +406,10 @@ do_merge(time_t backup_id)
405406 catalog_lock_backup_list (merge_list , parray_num (merge_list ) - 1 , 0 , true, true);
406407
407408 /* do actual merge */
408- merge_chain (merge_list , full_backup , dest_backup );
409+ merge_chain (merge_list , full_backup , dest_backup , no_validate , no_sync );
409410
410- pgBackupValidate (full_backup , NULL );
411+ if (!no_validate )
412+ pgBackupValidate (full_backup , NULL );
411413 if (full_backup -> status == BACKUP_STATUS_CORRUPT )
412414 elog (ERROR , "Merging of backup %s failed" , base36enc (backup_id ));
413415
@@ -434,7 +436,8 @@ do_merge(time_t backup_id)
434436 * that chain is ok.
435437 */
436438void
437- merge_chain (parray * parent_chain , pgBackup * full_backup , pgBackup * dest_backup )
439+ merge_chain (parray * parent_chain , pgBackup * full_backup , pgBackup * dest_backup ,
440+ bool no_validate , bool no_sync )
438441{
439442 int i ;
440443 char * dest_backup_id ;
@@ -554,25 +557,28 @@ merge_chain(parray *parent_chain, pgBackup *full_backup, pgBackup *dest_backup)
554557 * with sole exception of FULL backup. If it has MERGING status
555558 * then it isn't valid backup until merging is finished.
556559 */
557- elog (INFO , "Validate parent chain for backup %s" ,
558- base36enc (dest_backup -> start_time ));
559-
560- for (i = parray_num (parent_chain ) - 1 ; i >= 0 ; i -- )
560+ if (!no_validate )
561561 {
562- pgBackup * backup = (pgBackup * ) parray_get (parent_chain , i );
562+ elog (INFO , "Validate parent chain for backup %s" ,
563+ base36enc (dest_backup -> start_time ));
563564
564- /* FULL backup is not to be validated if its status is MERGING */
565- if (backup -> backup_mode == BACKUP_MODE_FULL &&
566- backup -> status == BACKUP_STATUS_MERGING )
565+ for (i = parray_num (parent_chain ) - 1 ; i >= 0 ; i -- )
567566 {
568- continue ;
569- }
567+ pgBackup * backup = (pgBackup * ) parray_get (parent_chain , i );
570568
571- pgBackupValidate (backup , NULL );
569+ /* FULL backup is not to be validated if its status is MERGING */
570+ if (backup -> backup_mode == BACKUP_MODE_FULL &&
571+ backup -> status == BACKUP_STATUS_MERGING )
572+ {
573+ continue ;
574+ }
572575
573- if (backup -> status != BACKUP_STATUS_OK )
574- elog (ERROR , "Backup %s has status %s, merge is aborted" ,
575- base36enc (backup -> start_time ), status2str (backup -> status ));
576+ pgBackupValidate (backup , NULL );
577+
578+ if (backup -> status != BACKUP_STATUS_OK )
579+ elog (ERROR , "Backup %s has status %s, merge is aborted" ,
580+ base36enc (backup -> start_time ), status2str (backup -> status ));
581+ }
576582 }
577583
578584 /*
@@ -665,6 +671,7 @@ merge_chain(parray *parent_chain, pgBackup *full_backup, pgBackup *dest_backup)
665671 arg -> program_version_match = program_version_match ;
666672 arg -> use_bitmap = use_bitmap ;
667673 arg -> is_retry = is_retry ;
674+ arg -> no_sync = no_sync ;
668675 /* By default there are some error */
669676 arg -> ret = 1 ;
670677
@@ -1102,14 +1109,16 @@ merge_files(void *arg)
11021109 dest_file , tmp_file ,
11031110 arguments -> full_database_dir ,
11041111 arguments -> use_bitmap ,
1105- arguments -> is_retry );
1112+ arguments -> is_retry ,
1113+ arguments -> no_sync );
11061114 else
11071115 merge_non_data_file (arguments -> parent_chain ,
11081116 arguments -> full_backup ,
11091117 arguments -> dest_backup ,
11101118 dest_file , tmp_file ,
11111119 arguments -> full_database_dir ,
1112- arguments -> full_external_prefix );
1120+ arguments -> full_external_prefix ,
1121+ arguments -> no_sync );
11131122
11141123done :
11151124 parray_append (arguments -> merge_filelist , tmp_file );
@@ -1202,7 +1211,8 @@ reorder_external_dirs(pgBackup *to_backup, parray *to_external,
12021211void
12031212merge_data_file (parray * parent_chain , pgBackup * full_backup ,
12041213 pgBackup * dest_backup , pgFile * dest_file , pgFile * tmp_file ,
1205- const char * full_database_dir , bool use_bitmap , bool is_retry )
1214+ const char * full_database_dir , bool use_bitmap , bool is_retry ,
1215+ bool no_sync )
12061216{
12071217 FILE * out = NULL ;
12081218 char * buffer = pgut_malloc (STDIO_BUFSIZE );
@@ -1273,7 +1283,7 @@ merge_data_file(parray *parent_chain, pgBackup *full_backup,
12731283 return ;
12741284
12751285 /* sync second temp file to disk */
1276- if (fio_sync (to_fullpath_tmp2 , FIO_BACKUP_HOST ) != 0 )
1286+ if (! no_sync && fio_sync (to_fullpath_tmp2 , FIO_BACKUP_HOST ) != 0 )
12771287 elog (ERROR , "Cannot sync merge temp file \"%s\": %s" ,
12781288 to_fullpath_tmp2 , strerror (errno ));
12791289
@@ -1294,7 +1304,8 @@ merge_data_file(parray *parent_chain, pgBackup *full_backup,
12941304void
12951305merge_non_data_file (parray * parent_chain , pgBackup * full_backup ,
12961306 pgBackup * dest_backup , pgFile * dest_file , pgFile * tmp_file ,
1297- const char * full_database_dir , const char * to_external_prefix )
1307+ const char * full_database_dir , const char * to_external_prefix ,
1308+ bool no_sync )
12981309{
12991310 int i ;
13001311 char to_fullpath [MAXPGPATH ];
@@ -1378,7 +1389,7 @@ merge_non_data_file(parray *parent_chain, pgBackup *full_backup,
13781389 to_fullpath_tmp , BACKUP_MODE_FULL , 0 , false);
13791390
13801391 /* sync temp file to disk */
1381- if (fio_sync (to_fullpath_tmp , FIO_BACKUP_HOST ) != 0 )
1392+ if (! no_sync && fio_sync (to_fullpath_tmp , FIO_BACKUP_HOST ) != 0 )
13821393 elog (ERROR , "Cannot sync merge temp file \"%s\": %s" ,
13831394 to_fullpath_tmp , strerror (errno ));
13841395
0 commit comments