Skip to content

Commit 4ec7b9c

Browse files
committed
[PBCKP-146] - fio_get_crc32 - add "missing_ok" parameter
1 parent 623ddbb commit 4ec7b9c

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

src/data.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,11 @@ backup_non_data_file(pgFile *file, pgFile *prev_file,
801801
(prev_file && file->exists_in_prev &&
802802
file->mtime <= parent_backup_time))
803803
{
804-
805-
file->crc = fio_get_crc32(FIO_DB_HOST, from_fullpath, false);
804+
/*
805+
* file could be deleted under our feets.
806+
* But then backup_non_data_file_internal will handle it safely
807+
*/
808+
file->crc = fio_get_crc32(FIO_DB_HOST, from_fullpath, false, true);
806809

807810
/* ...and checksum is the same... */
808811
if (EQ_TRADITIONAL_CRC32(file->crc, prev_file->crc))
@@ -1327,7 +1330,8 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup,
13271330
if (already_exists)
13281331
{
13291332
/* compare checksums of already existing file and backup file */
1330-
pg_crc32 file_crc = fio_get_crc32(FIO_DB_HOST, to_fullpath, false);
1333+
pg_crc32 file_crc = fio_get_crc32(FIO_DB_HOST, to_fullpath, false,
1334+
false);
13311335

13321336
if (file_crc == tmp_file->crc)
13331337
{

src/utils/file.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,9 +1402,15 @@ fio_sync(fio_location location, const char* path)
14021402
}
14031403
}
14041404

1405+
enum {
1406+
GET_CRC32_DECOMPRESS = 1,
1407+
GET_CRC32_MISSING_OK = 2
1408+
};
1409+
14051410
/* Get crc32 of file */
14061411
pg_crc32
1407-
fio_get_crc32(fio_location location, const char *file_path, bool decompress)
1412+
fio_get_crc32(fio_location location, const char *file_path,
1413+
bool decompress, bool missing_ok)
14081414
{
14091415
if (fio_is_remote(location))
14101416
{
@@ -1417,7 +1423,9 @@ fio_get_crc32(fio_location location, const char *file_path, bool decompress)
14171423
hdr.arg = 0;
14181424

14191425
if (decompress)
1420-
hdr.arg = 1;
1426+
hdr.arg = GET_CRC32_DECOMPRESS;
1427+
if (missing_ok)
1428+
hdr.arg |= GET_CRC32_MISSING_OK;
14211429

14221430
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
14231431
IO_CHECK(fio_write_all(fio_stdout, file_path, path_len), path_len);
@@ -1428,9 +1436,9 @@ fio_get_crc32(fio_location location, const char *file_path, bool decompress)
14281436
else
14291437
{
14301438
if (decompress)
1431-
return pgFileGetCRCgz(file_path, true, true);
1439+
return pgFileGetCRCgz(file_path, true, missing_ok);
14321440
else
1433-
return pgFileGetCRC(file_path, true, true);
1441+
return pgFileGetCRC(file_path, true, missing_ok);
14341442
}
14351443
}
14361444

@@ -3365,10 +3373,10 @@ fio_communicate(int in, int out)
33653373
break;
33663374
case FIO_GET_CRC32:
33673375
/* calculate crc32 for a file */
3368-
if (hdr.arg == 1)
3369-
crc = pgFileGetCRCgz(buf, true, true);
3376+
if ((hdr.arg & GET_CRC32_DECOMPRESS))
3377+
crc = pgFileGetCRCgz(buf, true, (hdr.arg & GET_CRC32_MISSING_OK) != 0);
33703378
else
3371-
crc = pgFileGetCRC(buf, true, true);
3379+
crc = pgFileGetCRC(buf, true, (hdr.arg & GET_CRC32_MISSING_OK) != 0);
33723380
IO_CHECK(fio_write_all(out, &crc, sizeof(crc)), sizeof(crc));
33733381
break;
33743382
case FIO_GET_CHECKSUM_MAP:
@@ -3606,9 +3614,9 @@ pioLocalDrive_pioGetCRC32(VSelf, path_t path, bool compressed, err_i *err)
36063614
elog(VERBOSE, "Local Drive calculate crc32 for '%s', compressed=%d",
36073615
path, compressed);
36083616
if (compressed)
3609-
return pgFileGetCRCgz(path, true, true);
3617+
return pgFileGetCRCgz(path, true, false);
36103618
else
3611-
return pgFileGetCRC(path, true, true);
3619+
return pgFileGetCRC(path, true, false);
36123620
}
36133621

36143622
static bool
@@ -3867,7 +3875,7 @@ pioRemoteDrive_pioGetCRC32(VSelf, path_t path, bool compressed, err_i *err)
38673875
hdr.arg = 0;
38683876

38693877
if (compressed)
3870-
hdr.arg = 1;
3878+
hdr.arg = GET_CRC32_DECOMPRESS;
38713879
elog(VERBOSE, "Remote Drive calculate crc32 for '%s', hdr.arg=%d",
38723880
path, compressed);
38733881

src/utils/file.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ extern int fio_closedir(DIR *dirp);
161161

162162
/* pathname-style functions */
163163
extern int fio_sync(fio_location location, const char* path);
164-
extern pg_crc32 fio_get_crc32(fio_location location, const char *file_path, bool decompress);
164+
extern pg_crc32
165+
fio_get_crc32(fio_location location, const char *file_path,
166+
bool decompress, bool missing_ok);
165167

166168
extern int fio_rename(fio_location location, const char* old_path, const char* new_path);
167169
extern int fio_symlink(fio_location location, const char* target, const char* link_path, bool overwrite);

0 commit comments

Comments
 (0)