@@ -118,6 +118,7 @@ static XLogRecPtr get_last_ptrack_lsn(void);
118
118
static void check_server_version (void );
119
119
static void check_system_identifiers (void );
120
120
static 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 );
121
122
122
123
123
124
#define disconnect_and_exit (code ) \
@@ -1878,6 +1879,7 @@ backup_files(void *arg)
1878
1879
struct stat buf ;
1879
1880
1880
1881
pgFile * file = (pgFile * ) parray_get (arguments -> backup_files_list , i );
1882
+ elog (VERBOSE , "Copying file: \"%s\" " , file -> path );
1881
1883
if (__sync_lock_test_and_set (& file -> lock , 1 ) != 0 )
1882
1884
continue ;
1883
1885
@@ -1918,8 +1920,9 @@ backup_files(void *arg)
1918
1920
if (S_ISREG (buf .st_mode ))
1919
1921
{
1920
1922
/* copy the file into backup */
1921
- if (file -> is_datafile )
1923
+ if (file -> is_datafile && ! file -> is_cfs )
1922
1924
{
1925
+ /* backup block by block if datafile AND not compressed by cfs*/
1923
1926
if (!backup_data_file (arguments -> from_root ,
1924
1927
arguments -> to_root , file ,
1925
1928
arguments -> prev_backup_start_lsn ))
@@ -1965,12 +1968,14 @@ parse_backup_filelist_filenames(parray *files, const char *root)
1965
1968
int sscanf_result ;
1966
1969
1967
1970
relative = GetRelativePath (file -> path , root );
1971
+ file -> is_cfs = false;
1968
1972
1969
1973
elog (VERBOSE , "-----------------------------------------------------: %s" , relative );
1970
1974
if (path_is_prefix_of_path ("global" , relative ))
1971
1975
{
1972
1976
file -> tblspcOid = GLOBALTABLESPACE_OID ;
1973
1977
sscanf_result = sscanf (relative , "global/%s" , filename );
1978
+ elog (VERBOSE , "global sscanf result: %i" , sscanf_result );
1974
1979
if (strcmp (relative , "global" ) == 0 )
1975
1980
{
1976
1981
Assert (S_ISDIR (file -> mode ));
@@ -1986,6 +1991,7 @@ parse_backup_filelist_filenames(parray *files, const char *root)
1986
1991
{
1987
1992
file -> tblspcOid = DEFAULTTABLESPACE_OID ;
1988
1993
sscanf_result = sscanf (relative , "base/%u/%s" , & (file -> dbOid ), filename );
1994
+ elog (VERBOSE , "base sscanf result: %i" , sscanf_result );
1989
1995
if (strcmp (relative , "base" ) == 0 )
1990
1996
{
1991
1997
Assert (S_ISDIR (file -> mode ));
@@ -2007,6 +2013,8 @@ parse_backup_filelist_filenames(parray *files, const char *root)
2007
2013
char * temp_relative_path = palloc (MAXPGPATH );
2008
2014
2009
2015
sscanf_result = sscanf (relative , "pg_tblspc/%u/%s" , & (file -> tblspcOid ), temp_relative_path );
2016
+ elog (VERBOSE , "pg_tblspc sscanf result: %i" , sscanf_result );
2017
+
2010
2018
if (strcmp (relative , "pg_tblspc" ) == 0 )
2011
2019
{
2012
2020
Assert (S_ISDIR (file -> mode ));
@@ -2022,21 +2030,43 @@ parse_backup_filelist_filenames(parray *files, const char *root)
2022
2030
/*continue parsing */
2023
2031
sscanf_result = sscanf (temp_relative_path + strlen (TABLESPACE_VERSION_DIRECTORY )+ 1 , "%u/%s" ,
2024
2032
& (file -> dbOid ), filename );
2033
+ elog (VERBOSE , "TABLESPACE_VERSION_DIRECTORY sscanf result: %i" , sscanf_result );
2025
2034
2026
- if (sscanf_result == 0 )
2035
+ if (sscanf_result == -1 )
2027
2036
{
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
+
2029
2055
}
2030
2056
else if (sscanf_result == 1 )
2031
2057
{
2032
2058
Assert (S_ISDIR (file -> mode ));
2033
2059
elog (VERBOSE , "dboid %u, filepath %s" , file -> dbOid , relative );
2034
2060
file -> is_database = true;
2035
2061
}
2036
- else
2062
+ else if ( sscanf_result == 2 )
2037
2063
{
2038
2064
elog (VERBOSE , "dboid %u, filename %s, filepath %s" , file -> dbOid , filename , relative );
2039
2065
}
2066
+ else
2067
+ {
2068
+ elog (VERBOSE , "Illegal file filepath %s" , relative );
2069
+ }
2040
2070
}
2041
2071
}
2042
2072
else
@@ -2081,7 +2111,7 @@ parse_backup_filelist_filenames(parray *files, const char *root)
2081
2111
* Check that and do not mark them with 'is_datafile' flag.
2082
2112
*/
2083
2113
char * forkNameptr ;
2084
- char * suffix = palloc (MAXPGPATH );;
2114
+ char * suffix = palloc (MAXPGPATH );
2085
2115
2086
2116
forkNameptr = strstr (filename , "_" );
2087
2117
if (forkNameptr != NULL )
@@ -2108,7 +2138,16 @@ parse_backup_filelist_filenames(parray *files, const char *root)
2108
2138
{
2109
2139
/* first segment of the relfile */
2110
2140
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
+ }
2112
2151
}
2113
2152
else if (sscanf_result == 2 )
2114
2153
{
@@ -2126,9 +2165,52 @@ parse_backup_filelist_filenames(parray *files, const char *root)
2126
2165
}
2127
2166
}
2128
2167
}
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
+ }
2130
2211
}
2131
2212
2213
+
2132
2214
/*
2133
2215
* Output the list of files to backup catalog DATABASE_FILE_LIST
2134
2216
*/
0 commit comments