@@ -104,7 +104,6 @@ static int checkpoint_timeout(void);
104
104
105
105
//static void backup_list_file(parray *files, const char *root, )
106
106
static void parse_backup_filelist_filenames (parray * files , const char * root );
107
- static void write_backup_file_list (parray * files , const char * root );
108
107
static void wait_wal_lsn (XLogRecPtr lsn , bool wait_prev_segment );
109
108
static void wait_replica_wal_lsn (XLogRecPtr lsn , bool is_start_backup );
110
109
static void make_pagemap_from_ptrack (parray * files );
@@ -515,8 +514,6 @@ do_backup_instance(void)
515
514
516
515
/* get list of backups already taken */
517
516
backup_list = catalog_get_backup_list (INVALID_BACKUP_ID );
518
- if (backup_list == NULL )
519
- elog (ERROR , "Failed to get backup list." );
520
517
521
518
prev_backup = catalog_get_last_data_backup (backup_list , current .tli );
522
519
if (prev_backup == NULL )
@@ -697,8 +694,11 @@ do_backup_instance(void)
697
694
pg_atomic_clear_flag (& file -> lock );
698
695
}
699
696
700
- /* sort by size for load balancing */
697
+ /* Sort by size for load balancing */
701
698
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 );
702
702
703
703
/* init thread args with own file lists */
704
704
threads = (pthread_t * ) palloc (sizeof (pthread_t ) * num_threads );
@@ -788,7 +788,7 @@ do_backup_instance(void)
788
788
}
789
789
790
790
/* Print the list of files to backup catalog */
791
- write_backup_file_list ( backup_files_list , pgdata );
791
+ pgBackupWriteFileList ( & current , backup_files_list , pgdata );
792
792
793
793
/* Compute summary of size of regular files in the backup */
794
794
for (i = 0 ; i < parray_num (backup_files_list ); i ++ )
@@ -989,23 +989,23 @@ check_server_version(void)
989
989
if (PQresultStatus (res ) == PGRES_FATAL_ERROR )
990
990
/* It seems we connected to PostgreSQL (not Postgres Pro) */
991
991
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" ,
993
993
PROGRAM_NAME , PG_MAJORVERSION , PGPRO_EDITION , server_version_str );
994
994
else if (strcmp (server_version_str , PG_MAJORVERSION ) != 0 &&
995
995
strcmp (PQgetvalue (res , 0 , 0 ), PGPRO_EDITION ) != 0 )
996
996
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" ,
998
998
PROGRAM_NAME , PG_MAJORVERSION , PGPRO_EDITION ,
999
999
server_version_str , PQgetvalue (res , 0 , 0 ));
1000
1000
#else
1001
1001
if (PQresultStatus (res ) != PGRES_FATAL_ERROR )
1002
1002
/* It seems we connected to Postgres Pro (not PostgreSQL) */
1003
1003
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" ,
1005
1005
PROGRAM_NAME , PG_MAJORVERSION ,
1006
1006
server_version_str , PQgetvalue (res , 0 , 0 ));
1007
1007
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" ,
1009
1009
PROGRAM_NAME , PG_MAJORVERSION , server_version_str );
1010
1010
#endif
1011
1011
@@ -2076,35 +2076,32 @@ backup_files(void *arg)
2076
2076
/* Check that file exist in previous backup */
2077
2077
if (current .backup_mode != BACKUP_MODE_FULL )
2078
2078
{
2079
- int p ;
2080
2079
char * relative ;
2081
- int n_prev_files = parray_num (arguments -> prev_filelist );
2080
+ pgFile key ;
2081
+ pgFile * * prev_file ;
2082
2082
2083
2083
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 ;
2089
2085
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;
2098
2091
}
2099
2092
/* copy the file into backup */
2100
2093
if (file -> is_datafile && !file -> is_cfs )
2101
2094
{
2095
+ char to_path [MAXPGPATH ];
2096
+
2097
+ join_path_components (to_path , arguments -> to_root ,
2098
+ file -> path + strlen (arguments -> from_root ) + 1 );
2099
+
2102
2100
/* 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 ,
2106
2102
arguments -> prev_start_lsn ,
2107
- current .backup_mode ))
2103
+ current .backup_mode ,
2104
+ compress_alg , compress_level ))
2108
2105
{
2109
2106
file -> write_size = BYTES_INVALID ;
2110
2107
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)
2279
2276
free (cfs_tblspc_path );
2280
2277
}
2281
2278
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
-
2307
2279
/*
2308
2280
* Find pgfile by given rnode in the backup_files_list
2309
2281
* and add given blkno to its pagemap.
0 commit comments