@@ -468,9 +468,6 @@ merge_files(void *arg)
468468 char from_file_path [MAXPGPATH ];
469469 char * prev_file_path ;
470470
471- if (!pg_atomic_test_set_flag (& file -> lock ))
472- continue ;
473-
474471 /* check for interrupt */
475472 if (interrupted || thread_interrupted )
476473 elog (ERROR , "Interrupted during merging backups" );
@@ -479,6 +476,9 @@ merge_files(void *arg)
479476 if (S_ISDIR (file -> mode ))
480477 continue ;
481478
479+ if (!pg_atomic_test_set_flag (& file -> lock ))
480+ continue ;
481+
482482 if (progress )
483483 elog (INFO , "Progress: (%d/%d). Process file \"%s\"" ,
484484 i + 1 , num_files , file -> path );
@@ -491,20 +491,28 @@ merge_files(void *arg)
491491
492492 /*
493493 * Skip files which haven't changed since previous backup. But in case
494- * of DELTA backup we should consider n_blocks to truncate the target
495- * backup .
494+ * of DELTA backup we must truncate the target file to n_blocks.
495+ * Unless it is a non data file, in this case truncation is not needed .
496496 */
497- if (file -> write_size == BYTES_INVALID && file -> n_blocks == BLOCKNUM_INVALID )
497+ if (file -> write_size == BYTES_INVALID )
498498 {
499- elog (VERBOSE , "Skip merging file \"%s\", the file didn't change" ,
500- file -> path );
501-
502- /*
503- * If the file wasn't changed in PAGE backup, retreive its
504- * write_size from previous FULL backup.
505- */
506- if (to_file )
499+ /* sanity */
500+ if (!to_file )
501+ elog (ERROR , "The file \"%s\" is missing in FULL backup %s" ,
502+ file -> rel_path , base36enc (to_backup -> start_time ));
503+
504+ /* for not changed files of all types in PAGE and PTRACK */
505+ if (from_backup -> backup_mode != BACKUP_MODE_DIFF_DELTA ||
506+ /* and not changed non-data files in DELTA */
507+ (!file -> is_datafile || file -> is_cfs ))
507508 {
509+ elog (VERBOSE , "Skip merging file \"%s\", the file didn't change" ,
510+ file -> path );
511+
512+ /*
513+ * If the file wasn't changed, retreive its
514+ * write_size and compression algorihtm from previous FULL backup.
515+ */
508516 file -> compress_alg = to_file -> compress_alg ;
509517 file -> write_size = to_file -> write_size ;
510518
@@ -516,9 +524,9 @@ merge_files(void *arg)
516524 /* Otherwise just get it from the previous file */
517525 else
518526 file -> crc = to_file -> crc ;
519- }
520527
521- continue ;
528+ continue ;
529+ }
522530 }
523531
524532 /* We need to make full path, file object has relative path */
@@ -667,6 +675,8 @@ merge_files(void *arg)
667675 if (file -> write_size != BYTES_INVALID )
668676 elog (VERBOSE , "Merged file \"%s\": " INT64_FORMAT " bytes" ,
669677 file -> path , file -> write_size );
678+ else
679+ elog (ERROR , "Merge of file \"%s\" failed. Invalid size: %i" , BYTES_INVALID );
670680
671681 /* Restore relative path */
672682 file -> path = prev_file_path ;
0 commit comments