@@ -1377,8 +1377,6 @@ fio_get_crc32_ex(const char *file_path, fio_location location,
1377
1377
{
1378
1378
if (decompress && truncated )
1379
1379
elog (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" );
1382
1380
1383
1381
if (fio_is_remote (location ))
1384
1382
{
@@ -1408,7 +1406,7 @@ fio_get_crc32_ex(const char *file_path, fio_location location,
1408
1406
if (decompress )
1409
1407
return pgFileGetCRCgz (file_path , true, missing_ok );
1410
1408
else if (truncated )
1411
- return pgFileGetCRCTruncated (file_path , true);
1409
+ return pgFileGetCRCTruncated (file_path , true, missing_ok );
1412
1410
else
1413
1411
return pgFileGetCRC (file_path , true, missing_ok );
1414
1412
}
@@ -1422,9 +1420,10 @@ fio_get_crc32(const char *file_path, fio_location location,
1422
1420
}
1423
1421
1424
1422
pg_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 )
1426
1425
{
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);
1428
1427
}
1429
1428
1430
1429
/* Remove file */
@@ -3003,6 +3002,7 @@ fio_send_file_impl(int out, char const* path)
3003
3002
fio_header hdr ;
3004
3003
char * buf = pgut_malloc (CHUNK_SIZE );
3005
3004
size_t read_len = 0 ;
3005
+ int64_t read_size = 0 ;
3006
3006
char * errormsg = NULL ;
3007
3007
3008
3008
/* open source file for read */
@@ -3066,7 +3066,19 @@ fio_send_file_impl(int out, char const* path)
3066
3066
if (read_len > 0 )
3067
3067
{
3068
3068
/* 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
+
3070
3082
if (non_zero_len > 0 )
3071
3083
{
3072
3084
hdr .cop = FIO_PAGE ;
@@ -3082,6 +3094,8 @@ fio_send_file_impl(int out, char const* path)
3082
3094
hdr .arg = read_len - non_zero_len ;
3083
3095
IO_CHECK (fio_write_all (out , & hdr , sizeof (hdr )), sizeof (hdr ));
3084
3096
}
3097
+
3098
+ read_size += read_len ;
3085
3099
}
3086
3100
3087
3101
if (feof (fp ))
@@ -3166,7 +3180,7 @@ pgFileGetCRC(const char *file_path, bool use_crc32c, bool missing_ok)
3166
3180
* Read the local file to compute CRC for it extened to real_size.
3167
3181
*/
3168
3182
pg_crc32
3169
- pgFileGetCRCTruncated (const char * file_path , bool use_crc32c )
3183
+ pgFileGetCRCTruncated (const char * file_path , bool use_crc32c , bool missing_ok )
3170
3184
{
3171
3185
FILE * fp ;
3172
3186
char * buf ;
@@ -3180,6 +3194,15 @@ pgFileGetCRCTruncated(const char *file_path, bool use_crc32c)
3180
3194
fp = fopen (file_path , PG_BINARY_R );
3181
3195
if (fp == NULL )
3182
3196
{
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
+
3183
3206
elog (ERROR , "Cannot open file \"%s\": %s" ,
3184
3207
file_path , strerror (errno ));
3185
3208
}
@@ -3200,6 +3223,14 @@ pgFileGetCRCTruncated(const char *file_path, bool use_crc32c)
3200
3223
elog (ERROR , "Cannot read \"%s\": %s" , file_path , strerror (errno ));
3201
3224
3202
3225
non_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
+ }
3203
3234
if (non_zero_len )
3204
3235
{
3205
3236
fio_send_file_crc (& st , buf , non_zero_len );
@@ -3894,12 +3925,12 @@ fio_communicate(int in, int out)
3894
3925
break ;
3895
3926
case FIO_GET_CRC32 :
3896
3927
Assert ((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 );
3898
3929
/* calculate crc32 for a file */
3899
3930
if ((hdr .arg & GET_CRC32_DECOMPRESS ))
3900
3931
crc = pgFileGetCRCgz (buf , true, (hdr .arg & GET_CRC32_MISSING_OK ) != 0 );
3901
3932
else if ((hdr .arg & GET_CRC32_TRUNCATED ))
3902
- crc = pgFileGetCRCTruncated (buf , true);
3933
+ crc = pgFileGetCRCTruncated (buf , true, ( hdr . arg & GET_CRC32_MISSING_OK ) != 0 );
3903
3934
else
3904
3935
crc = pgFileGetCRC (buf , true, (hdr .arg & GET_CRC32_MISSING_OK ) != 0 );
3905
3936
IO_CHECK (fio_write_all (out , & crc , sizeof (crc )), sizeof (crc ));
0 commit comments