@@ -104,7 +104,6 @@ static int checkpoint_timeout(void);
104104
105105//static void backup_list_file(parray *files, const char *root, )
106106static void parse_backup_filelist_filenames (parray * files , const char * root );
107- static void write_backup_file_list (parray * files , const char * root );
108107static void wait_wal_lsn (XLogRecPtr lsn , bool wait_prev_segment );
109108static void wait_replica_wal_lsn (XLogRecPtr lsn , bool is_start_backup );
110109static void make_pagemap_from_ptrack (parray * files );
@@ -515,8 +514,6 @@ do_backup_instance(void)
515514
516515 /* get list of backups already taken */
517516 backup_list = catalog_get_backup_list (INVALID_BACKUP_ID );
518- if (backup_list == NULL )
519- elog (ERROR , "Failed to get backup list." );
520517
521518 prev_backup = catalog_get_last_data_backup (backup_list , current .tli );
522519 if (prev_backup == NULL )
@@ -697,8 +694,11 @@ do_backup_instance(void)
697694 pg_atomic_clear_flag (& file -> lock );
698695 }
699696
700- /* sort by size for load balancing */
697+ /* Sort by size for load balancing */
701698 parray_qsort (backup_files_list , pgFileCompareSize );
699+ /* Sort the array for binary search */
700+ if (prev_backup_filelist )
701+ parray_qsort (prev_backup_filelist , pgFileComparePath );
702702
703703 /* init thread args with own file lists */
704704 threads = (pthread_t * ) palloc (sizeof (pthread_t ) * num_threads );
@@ -788,7 +788,7 @@ do_backup_instance(void)
788788 }
789789
790790 /* Print the list of files to backup catalog */
791- write_backup_file_list ( backup_files_list , pgdata );
791+ pgBackupWriteFileList ( & current , backup_files_list , pgdata );
792792
793793 /* Compute summary of size of regular files in the backup */
794794 for (i = 0 ; i < parray_num (backup_files_list ); i ++ )
@@ -989,23 +989,23 @@ check_server_version(void)
989989 if (PQresultStatus (res ) == PGRES_FATAL_ERROR )
990990 /* It seems we connected to PostgreSQL (not Postgres Pro) */
991991 elog (ERROR , "%s was built with Postgres Pro %s %s, "
992- "but connection made with PostgreSQL %s" ,
992+ "but connection is made with PostgreSQL %s" ,
993993 PROGRAM_NAME , PG_MAJORVERSION , PGPRO_EDITION , server_version_str );
994994 else if (strcmp (server_version_str , PG_MAJORVERSION ) != 0 &&
995995 strcmp (PQgetvalue (res , 0 , 0 ), PGPRO_EDITION ) != 0 )
996996 elog (ERROR , "%s was built with Postgres Pro %s %s, "
997- "but connection made with Postgres Pro %s %s" ,
997+ "but connection is made with Postgres Pro %s %s" ,
998998 PROGRAM_NAME , PG_MAJORVERSION , PGPRO_EDITION ,
999999 server_version_str , PQgetvalue (res , 0 , 0 ));
10001000#else
10011001 if (PQresultStatus (res ) != PGRES_FATAL_ERROR )
10021002 /* It seems we connected to Postgres Pro (not PostgreSQL) */
10031003 elog (ERROR , "%s was built with PostgreSQL %s, "
1004- "but connection made with Postgres Pro %s %s" ,
1004+ "but connection is made with Postgres Pro %s %s" ,
10051005 PROGRAM_NAME , PG_MAJORVERSION ,
10061006 server_version_str , PQgetvalue (res , 0 , 0 ));
10071007 else if (strcmp (server_version_str , PG_MAJORVERSION ) != 0 )
1008- elog (ERROR , "%s was built with PostgreSQL %s, but connection made with %s" ,
1008+ elog (ERROR , "%s was built with PostgreSQL %s, but connection is made with %s" ,
10091009 PROGRAM_NAME , PG_MAJORVERSION , server_version_str );
10101010#endif
10111011
@@ -2076,35 +2076,32 @@ backup_files(void *arg)
20762076 /* Check that file exist in previous backup */
20772077 if (current .backup_mode != BACKUP_MODE_FULL )
20782078 {
2079- int p ;
20802079 char * relative ;
2081- int n_prev_files = parray_num (arguments -> prev_filelist );
2080+ pgFile key ;
2081+ pgFile * * prev_file ;
20822082
20832083 relative = GetRelativePath (file -> path , arguments -> from_root );
2084- for (p = 0 ; p < n_prev_files ; p ++ )
2085- {
2086- pgFile * prev_file ;
2087-
2088- prev_file = (pgFile * ) parray_get (arguments -> prev_filelist , p );
2084+ key .path = relative ;
20892085
2090- if (strcmp (relative , prev_file -> path ) == 0 )
2091- {
2092- /* File exists in previous backup */
2093- file -> exists_in_prev = true;
2094- // elog(VERBOSE, "File exists at the time of previous backup %s", relative);
2095- break ;
2096- }
2097- }
2086+ prev_file = (pgFile * * ) parray_bsearch (arguments -> prev_filelist ,
2087+ & key , pgFileComparePath );
2088+ if (prev_file )
2089+ /* File exists in previous backup */
2090+ file -> exists_in_prev = true;
20982091 }
20992092 /* copy the file into backup */
21002093 if (file -> is_datafile && !file -> is_cfs )
21012094 {
2095+ char to_path [MAXPGPATH ];
2096+
2097+ join_path_components (to_path , arguments -> to_root ,
2098+ file -> path + strlen (arguments -> from_root ) + 1 );
2099+
21022100 /* backup block by block if datafile AND not compressed by cfs*/
2103- if (!backup_data_file (arguments ,
2104- arguments -> from_root ,
2105- arguments -> to_root , file ,
2101+ if (!backup_data_file (arguments , to_path , file ,
21062102 arguments -> prev_start_lsn ,
2107- current .backup_mode ))
2103+ current .backup_mode ,
2104+ compress_alg , compress_level ))
21082105 {
21092106 file -> write_size = BYTES_INVALID ;
21102107 elog (VERBOSE , "File \"%s\" was not copied to backup" , file -> path );
@@ -2279,31 +2276,6 @@ set_cfs_datafiles(parray *files, const char *root, char *relative, size_t i)
22792276 free (cfs_tblspc_path );
22802277}
22812278
2282-
2283- /*
2284- * Output the list of files to backup catalog DATABASE_FILE_LIST
2285- */
2286- static void
2287- write_backup_file_list (parray * files , const char * root )
2288- {
2289- FILE * fp ;
2290- char path [MAXPGPATH ];
2291-
2292- pgBackupGetPath (& current , path , lengthof (path ), DATABASE_FILE_LIST );
2293-
2294- fp = fopen (path , "wt" );
2295- if (fp == NULL )
2296- elog (ERROR , "cannot open file list \"%s\": %s" , path ,
2297- strerror (errno ));
2298-
2299- print_file_list (fp , files , root );
2300-
2301- if (fflush (fp ) != 0 ||
2302- fsync (fileno (fp )) != 0 ||
2303- fclose (fp ))
2304- elog (ERROR , "cannot write file list \"%s\": %s" , path , strerror (errno ));
2305- }
2306-
23072279/*
23082280 * Find pgfile by given rnode in the backup_files_list
23092281 * and add given blkno to its pagemap.
0 commit comments