@@ -1377,8 +1377,6 @@ fio_get_crc32_ex(const char *file_path, fio_location location,
13771377{
13781378if (decompress && truncated )
13791379elog (ERROR ,"Could not calculate CRC for compressed truncated file" );
1380- if (missing_ok && truncated )
1381- elog (ERROR ,"CRC calculation for missing truncated file is forbidden" );
13821380
13831381if (fio_is_remote (location ))
13841382{
@@ -1408,7 +1406,7 @@ fio_get_crc32_ex(const char *file_path, fio_location location,
14081406if (decompress )
14091407return pgFileGetCRCgz (file_path , true,missing_ok );
14101408else if (truncated )
1411- return pgFileGetCRCTruncated (file_path , true);
1409+ return pgFileGetCRCTruncated (file_path , true, missing_ok );
14121410else
14131411return pgFileGetCRC (file_path , true,missing_ok );
14141412}
@@ -1422,9 +1420,10 @@ fio_get_crc32(const char *file_path, fio_location location,
14221420}
14231421
14241422pg_crc32
1425- fio_get_crc32_truncated (const char * file_path ,fio_location location )
1423+ fio_get_crc32_truncated (const char * file_path ,fio_location location ,
1424+ bool missing_ok )
14261425{
1427- return fio_get_crc32_ex (file_path ,location , false,false , true);
1426+ return fio_get_crc32_ex (file_path ,location , false,missing_ok , true);
14281427}
14291428
14301429/* Remove file */
@@ -3003,6 +3002,7 @@ fio_send_file_impl(int out, char const* path)
30033002fio_header hdr ;
30043003char * buf = pgut_malloc (CHUNK_SIZE );
30053004size_t read_len = 0 ;
3005+ int64_t read_size = 0 ;
30063006char * errormsg = NULL ;
30073007
30083008/* open source file for read */
@@ -3066,7 +3066,19 @@ fio_send_file_impl(int out, char const* path)
30663066if (read_len > 0 )
30673067{
30683068/* send chunk */
3069- size_t non_zero_len = find_zero_tail (buf ,read_len );
3069+ int64_t non_zero_len = find_zero_tail (buf ,read_len );
3070+ /*
3071+ * It is dirty trick to silence warnings in CFS GC process:
3072+ * backup at least cfs header size bytes.
3073+ */
3074+ if (read_size + non_zero_len < PAGE_ZEROSEARCH_FINE_GRANULARITY &&
3075+ read_size + read_len > 0 )
3076+ {
3077+ non_zero_len = Min (PAGE_ZEROSEARCH_FINE_GRANULARITY ,
3078+ read_size + read_len );
3079+ non_zero_len -= read_size ;
3080+ }
3081+
30703082if (non_zero_len > 0 )
30713083{
30723084hdr .cop = FIO_PAGE ;
@@ -3082,6 +3094,8 @@ fio_send_file_impl(int out, char const* path)
30823094hdr .arg = read_len - non_zero_len ;
30833095IO_CHECK (fio_write_all (out ,& hdr ,sizeof (hdr )),sizeof (hdr ));
30843096}
3097+
3098+ read_size += read_len ;
30853099}
30863100
30873101if (feof (fp ))
@@ -3166,7 +3180,7 @@ pgFileGetCRC(const char *file_path, bool use_crc32c, bool missing_ok)
31663180 * Read the local file to compute CRC for it extened to real_size.
31673181 */
31683182pg_crc32
3169- pgFileGetCRCTruncated (const char * file_path ,bool use_crc32c )
3183+ pgFileGetCRCTruncated (const char * file_path ,bool use_crc32c , bool missing_ok )
31703184{
31713185FILE * fp ;
31723186char * buf ;
@@ -3180,6 +3194,15 @@ pgFileGetCRCTruncated(const char *file_path, bool use_crc32c)
31803194fp = fopen (file_path ,PG_BINARY_R );
31813195if (fp == NULL )
31823196{
3197+ if (errno == ENOENT )
3198+ {
3199+ if (missing_ok )
3200+ {
3201+ FIN_FILE_CRC32 (use_crc32c ,st .crc );
3202+ return st .crc ;
3203+ }
3204+ }
3205+
31833206elog (ERROR ,"Cannot open file \"%s\": %s" ,
31843207file_path ,strerror (errno ));
31853208}
@@ -3200,6 +3223,14 @@ pgFileGetCRCTruncated(const char *file_path, bool use_crc32c)
32003223elog (ERROR ,"Cannot read \"%s\": %s" ,file_path ,strerror (errno ));
32013224
32023225non_zero_len = find_zero_tail (buf ,len );
3226+ /* same trick as in fio_send_file */
3227+ if (st .read_size + non_zero_len < PAGE_ZEROSEARCH_FINE_GRANULARITY &&
3228+ st .read_size + len > 0 )
3229+ {
3230+ non_zero_len = Min (PAGE_ZEROSEARCH_FINE_GRANULARITY ,
3231+ st .read_size + len );
3232+ non_zero_len -= st .read_size ;
3233+ }
32033234if (non_zero_len )
32043235{
32053236fio_send_file_crc (& st ,buf ,non_zero_len );
@@ -3894,12 +3925,12 @@ fio_communicate(int in, int out)
38943925break ;
38953926case FIO_GET_CRC32 :
38963927Assert ((hdr .arg & GET_CRC32_TRUNCATED )== 0 ||
3897- (hdr .arg & GET_CRC32_TRUNCATED )== GET_CRC32_TRUNCATED );
3928+ (hdr .arg & ( GET_CRC32_TRUNCATED | GET_CRC32_DECOMPRESS ) )== GET_CRC32_TRUNCATED );
38983929/* calculate crc32 for a file */
38993930if ((hdr .arg & GET_CRC32_DECOMPRESS ))
39003931crc = pgFileGetCRCgz (buf , true, (hdr .arg & GET_CRC32_MISSING_OK )!= 0 );
39013932else if ((hdr .arg & GET_CRC32_TRUNCATED ))
3902- crc = pgFileGetCRCTruncated (buf , true);
3933+ crc = pgFileGetCRCTruncated (buf , true, ( hdr . arg & GET_CRC32_MISSING_OK ) != 0 );
39033934else
39043935crc = pgFileGetCRC (buf , true, (hdr .arg & GET_CRC32_MISSING_OK )!= 0 );
39053936IO_CHECK (fio_write_all (out ,& crc ,sizeof (crc )),sizeof (crc ));