@@ -118,6 +118,7 @@ static XLogRecPtr get_last_ptrack_lsn(void);
118118static void check_server_version (void );
119119static void check_system_identifiers (void );
120120static void confirm_block_size (const char * name , int blcksz );
121+ static void set_cfs_datafiles (parray * files , const char * root , char * relative , size_t i );
121122
122123
123124#define disconnect_and_exit (code ) \
@@ -1878,6 +1879,7 @@ backup_files(void *arg)
18781879 struct stat buf ;
18791880
18801881 pgFile * file = (pgFile * ) parray_get (arguments -> backup_files_list , i );
1882+ elog (VERBOSE , "Copying file: \"%s\" " , file -> path );
18811883 if (__sync_lock_test_and_set (& file -> lock , 1 ) != 0 )
18821884 continue ;
18831885
@@ -1918,8 +1920,9 @@ backup_files(void *arg)
19181920 if (S_ISREG (buf .st_mode ))
19191921 {
19201922 /* copy the file into backup */
1921- if (file -> is_datafile )
1923+ if (file -> is_datafile && ! file -> is_cfs )
19221924 {
1925+ /* backup block by block if datafile AND not compressed by cfs*/
19231926 if (!backup_data_file (arguments -> from_root ,
19241927 arguments -> to_root , file ,
19251928 arguments -> prev_backup_start_lsn ))
@@ -1965,12 +1968,14 @@ parse_backup_filelist_filenames(parray *files, const char *root)
19651968 int sscanf_result ;
19661969
19671970 relative = GetRelativePath (file -> path , root );
1971+ file -> is_cfs = false;
19681972
19691973 elog (VERBOSE , "-----------------------------------------------------: %s" , relative );
19701974 if (path_is_prefix_of_path ("global" , relative ))
19711975 {
19721976 file -> tblspcOid = GLOBALTABLESPACE_OID ;
19731977 sscanf_result = sscanf (relative , "global/%s" , filename );
1978+ elog (VERBOSE , "global sscanf result: %i" , sscanf_result );
19741979 if (strcmp (relative , "global" ) == 0 )
19751980 {
19761981 Assert (S_ISDIR (file -> mode ));
@@ -1986,6 +1991,7 @@ parse_backup_filelist_filenames(parray *files, const char *root)
19861991 {
19871992 file -> tblspcOid = DEFAULTTABLESPACE_OID ;
19881993 sscanf_result = sscanf (relative , "base/%u/%s" , & (file -> dbOid ), filename );
1994+ elog (VERBOSE , "base sscanf result: %i" , sscanf_result );
19891995 if (strcmp (relative , "base" ) == 0 )
19901996 {
19911997 Assert (S_ISDIR (file -> mode ));
@@ -2007,6 +2013,8 @@ parse_backup_filelist_filenames(parray *files, const char *root)
20072013 char * temp_relative_path = palloc (MAXPGPATH );
20082014
20092015 sscanf_result = sscanf (relative , "pg_tblspc/%u/%s" , & (file -> tblspcOid ), temp_relative_path );
2016+ elog (VERBOSE , "pg_tblspc sscanf result: %i" , sscanf_result );
2017+
20102018 if (strcmp (relative , "pg_tblspc" ) == 0 )
20112019 {
20122020 Assert (S_ISDIR (file -> mode ));
@@ -2022,21 +2030,43 @@ parse_backup_filelist_filenames(parray *files, const char *root)
20222030 /*continue parsing */
20232031 sscanf_result = sscanf (temp_relative_path + strlen (TABLESPACE_VERSION_DIRECTORY )+ 1 , "%u/%s" ,
20242032 & (file -> dbOid ), filename );
2033+ elog (VERBOSE , "TABLESPACE_VERSION_DIRECTORY sscanf result: %i" , sscanf_result );
20252034
2026- if (sscanf_result == 0 )
2035+ if (sscanf_result == -1 )
20272036 {
2028- elog (VERBOSE , "the TABLESPACE_VERSION_DIRECTORY itself, filepath %s" , relative );
2037+ elog (VERBOSE , "The TABLESPACE_VERSION_DIRECTORY itself, filepath %s" , relative );
2038+ }
2039+ else if (sscanf_result == 0 )
2040+ {
2041+ /* Found file in pg_tblspc/tblsOid/TABLESPACE_VERSION_DIRECTORY
2042+ Legal only in case of 'pg_compression'
2043+ */
2044+ if (strcmp (relative + strlen (relative ) - strlen ("pg_compression" ), "pg_compression" ) == 0 )
2045+ {
2046+ elog (VERBOSE , "Found pg_compression file in TABLESPACE_VERSION_DIRECTORY, filepath %s" , relative );
2047+ /*Set every datafile in tablespace as is_cfs */
2048+ set_cfs_datafiles (files , root , relative , i );
2049+ }
2050+ else
2051+ {
2052+ elog (VERBOSE , "Found illegal file in TABLESPACE_VERSION_DIRECTORY, filepath %s" , relative );
2053+ }
2054+
20292055 }
20302056 else if (sscanf_result == 1 )
20312057 {
20322058 Assert (S_ISDIR (file -> mode ));
20332059 elog (VERBOSE , "dboid %u, filepath %s" , file -> dbOid , relative );
20342060 file -> is_database = true;
20352061 }
2036- else
2062+ else if ( sscanf_result == 2 )
20372063 {
20382064 elog (VERBOSE , "dboid %u, filename %s, filepath %s" , file -> dbOid , filename , relative );
20392065 }
2066+ else
2067+ {
2068+ elog (VERBOSE , "Illegal file filepath %s" , relative );
2069+ }
20402070 }
20412071 }
20422072 else
@@ -2081,7 +2111,7 @@ parse_backup_filelist_filenames(parray *files, const char *root)
20812111 * Check that and do not mark them with 'is_datafile' flag.
20822112 */
20832113 char * forkNameptr ;
2084- char * suffix = palloc (MAXPGPATH );;
2114+ char * suffix = palloc (MAXPGPATH );
20852115
20862116 forkNameptr = strstr (filename , "_" );
20872117 if (forkNameptr != NULL )
@@ -2108,7 +2138,16 @@ parse_backup_filelist_filenames(parray *files, const char *root)
21082138 {
21092139 /* first segment of the relfile */
21102140 elog (VERBOSE , "relOid %u, segno %d, filepath %s" , file -> relOid , 0 , relative );
2111- file -> is_datafile = true;
2141+ if (strcmp (relative + strlen (relative ) - strlen ("cfm" ), "cfm" ) == 0 )
2142+ {
2143+ /* reloid.cfm */
2144+ elog (VERBOSE , "Found cfm file %s" , relative );
2145+ }
2146+ else
2147+ {
2148+ elog (VERBOSE , "Found first segment of the relfile %s" , relative );
2149+ file -> is_datafile = true;
2150+ }
21122151 }
21132152 else if (sscanf_result == 2 )
21142153 {
@@ -2126,9 +2165,52 @@ parse_backup_filelist_filenames(parray *files, const char *root)
21262165 }
21272166 }
21282167 }
2129- }
2168+ }
2169+ }
2170+
2171+ /* If file is equal to pg_compression, then we consider this tablespace as
2172+ * cfs-compressed and should mark every file in this tablespace as cfs-file
2173+ * Setting is_cfs is done via going back through 'files' set every file
2174+ * that contain cfs_tablespace in his path as 'is_cfs'
2175+ * Goings back through array 'files' is valid option possible because of current
2176+ * sort rules:
2177+ * tblspcOid/TABLESPACE_VERSION_DIRECTORY
2178+ * tblspcOid/TABLESPACE_VERSION_DIRECTORY/dboid
2179+ * tblspcOid/TABLESPACE_VERSION_DIRECTORY/dboid/1
2180+ * tblspcOid/TABLESPACE_VERSION_DIRECTORY/dboid/1.cfm
2181+ * tblspcOid/TABLESPACE_VERSION_DIRECTORY/pg_compression
2182+ */
2183+ static void
2184+ set_cfs_datafiles (parray * files , const char * root , char * relative , size_t i )
2185+ {
2186+ int len ;
2187+ size_t p ;
2188+ char * cfs_tblspc_path ;
2189+
2190+ cfs_tblspc_path = strdup (relative );
2191+ len = strlen ("/pg_compression" );
2192+ cfs_tblspc_path [strlen (cfs_tblspc_path ) - len ] = 0 ;
2193+ elog (VERBOSE , "CFS DIRECTORY %s, pg_compression path: %s" , cfs_tblspc_path , relative );
2194+
2195+ for (p = i ; p != 0 ; p -- )
2196+ {
2197+ char * relative_prev_file ;
2198+ pgFile * prev_file = (pgFile * ) parray_get (files , p );
2199+ relative_prev_file = GetRelativePath (prev_file -> path , root );
2200+ //elog(VERBOSE, "P: %d, CHECKING file %s", p, relative_prev_file);
2201+ if (strstr (relative_prev_file , cfs_tblspc_path ) != NULL )
2202+ {
2203+ if (S_ISREG (prev_file -> mode ) && prev_file -> is_datafile )
2204+ {
2205+ elog (VERBOSE , "Setting as 'is_cfs' file %s, fork %s" ,
2206+ relative_prev_file , prev_file -> forkName );
2207+ prev_file -> is_cfs = true;
2208+ }
2209+ }
2210+ }
21302211}
21312212
2213+
21322214/*
21332215 * Output the list of files to backup catalog DATABASE_FILE_LIST
21342216 */
0 commit comments