@@ -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 ))
@@ -1961,16 +1964,18 @@ parse_backup_filelist_filenames(parray *files, const char *root)
19611964 {
19621965 pgFile * file = (pgFile * ) parray_get (files , i );
19631966 char * relative ;
1964- char * filename = palloc ( MAXPGPATH ) ;
1967+ char filename [ MAXPGPATH ] ;
19651968 int sscanf_result ;
19661969
19671970 relative = GetRelativePath (file -> path , root );
1971+ filename [0 ] = '\0' ;
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 ));
@@ -2004,9 +2010,11 @@ parse_backup_filelist_filenames(parray *files, const char *root)
20042010 }
20052011 else if (path_is_prefix_of_path (PG_TBLSPC_DIR , relative ))
20062012 {
2007- char * temp_relative_path = palloc ( MAXPGPATH ) ;
2013+ char temp_relative_path [ 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 )
2036+ {
2037+ elog (VERBOSE , "The TABLESPACE_VERSION_DIRECTORY itself, filepath %s" , relative );
2038+ }
2039+ else if (sscanf_result == 0 )
20272040 {
2028- elog (VERBOSE , "the TABLESPACE_VERSION_DIRECTORY itself, filepath %s" , relative );
2041+ /* Found file in pg_tblspc/tblsOid/TABLESPACE_VERSION_DIRECTORY
2042+ Legal only in case of 'pg_compression'
2043+ */
2044+ if (strcmp (file -> name , "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
@@ -2054,7 +2084,7 @@ parse_backup_filelist_filenames(parray *files, const char *root)
20542084 }
20552085
20562086 /* Check files located inside database directories */
2057- if (filename && file -> dbOid != 0 )
2087+ if (filename [ 0 ] != '\0' && file -> dbOid != 0 )
20582088 {
20592089 if (strcmp (filename , "pg_internal.init" ) == 0 )
20602090 {
@@ -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 [ 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,62 @@ 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+ pgFile * prev_file ;
2189+ char * cfs_tblspc_path ;
2190+ char * relative_prev_file ;
2191+
2192+ cfs_tblspc_path = strdup (relative );
2193+ len = strlen ("/pg_compression" );
2194+ cfs_tblspc_path [strlen (cfs_tblspc_path ) - len ] = 0 ;
2195+ elog (VERBOSE , "CFS DIRECTORY %s, pg_compression path: %s" , cfs_tblspc_path , relative );
2196+
2197+ for (p = i ; p >= 0 ; p -- )
2198+ {
2199+ prev_file = (pgFile * ) parray_get (files , p );
2200+ relative_prev_file = GetRelativePath (prev_file -> path , root );
2201+
2202+ //elog(VERBOSE, "P: %lu, Checking file in cfs tablespace %s", p, relative_prev_file);
2203+ elog (VERBOSE , "Checking file in cfs tablespace %s" , relative_prev_file );
2204+
2205+ if (strstr (relative_prev_file , cfs_tblspc_path ) != NULL )
2206+ {
2207+ if (S_ISREG (prev_file -> mode ) && prev_file -> is_datafile )
2208+ {
2209+ elog (VERBOSE , "Setting 'is_cfs' on file %s, name %s" ,
2210+ relative_prev_file , prev_file -> name );
2211+ prev_file -> is_cfs = true;
2212+ }
2213+ }
2214+ else
2215+ {
2216+ elog (VERBOSE , "Breaking on %s" , relative_prev_file );
2217+ break ;
2218+ }
2219+ }
2220+ free (cfs_tblspc_path );
21302221}
21312222
2223+
21322224/*
21332225 * Output the list of files to backup catalog DATABASE_FILE_LIST
21342226 */
0 commit comments