8000 [PBCKP-146] - fio_get_crc32 - add "missing_ok" parameter · postgrespro/pg_probackup@4730857 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4730857

Browse files
committed
[PBCKP-146] - fio_get_crc32 - add "missing_ok" parameter
1 parent 80efb85 commit 4730857

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

src/archive.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
512512
pg_crc32 crc32_src;
513513
pg_crc32 crc32_dst;
514514

515-
crc32_src = fio_get_crc32(from_fullpath, FIO_DB_HOST, false);
516-
crc32_dst = fio_get_crc32(to_fullpath, FIO_BACKUP_HOST, false);
515+
crc32_src = fio_get_crc32(from_fullpath, FIO_DB_HOST, false, false);
516+
crc32_dst = fio_get_crc32(to_fullpath, FIO_BACKUP_HOST, false, false);
517517

518518
if (crc32_src == crc32_dst)
519519
{
@@ -760,9 +760,8 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
760760
pg_crc32 crc32_src;
761761
pg_crc32 crc32_dst;
762762

763-
/* TODO: what if one of them goes missing? */
764-
crc32_src = fio_get_crc32(from_fullpath, FIO_DB_HOST, false);
765-
crc32_dst = fio_get_crc32(to_fullpath_gz, FIO_BACKUP_HOST, true);
763+
crc32_src = fio_get_crc32(from_fullpath, FIO_DB_HOST, false, false);
764+
crc32_dst = fio_get_crc32(to_fullpath_gz, FIO_BACKUP_HOST, true, false);
766765

767766
if (crc32_src == crc32_dst)
768767
{

src/data.c

Lines changed: 6 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(from_fullpath, FIO_DB_HOST, 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(from_fullpath, FIO_DB_HOST, false, true);
806809

807810
/* ...and checksum is the same... */
808811
if (EQ_TRADITIONAL_CRC32(file->crc, prev_file->crc))
@@ -1327,7 +1330,7 @@ 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(to_fullpath, FIO_DB_HOST, false);
1333+
pg_crc32 file_crc = fio_get_crc32(to_fullpath, FIO_DB_HOST, false, false);
13311334

13321335
if (file_crc == tmp_file->crc)
13331336
{

src/utils/file.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,9 +1355,15 @@ fio_sync(char const* path, fio_location location)
13551355
}
13561356
}
13571357

1358+
enum {
1359+
GET_CRC32_DECOMPRESS = 1,
1360+
GET_CRC32_MISSING_OK = 2
1361+
};
1362+
13581363
/* Get crc32 of file */
13591364
pg_crc32
1360-
fio_get_crc32(const char *file_path, fio_location location, bool decompress)
1365+
fio_get_crc32(const char *file_path, fio_location location,
1366+
bool decompress, bool missing_ok)
13611367
{
13621368
if (fio_is_remote(location))
13631369
{
@@ -1370,7 +1376,9 @@ fio_get_crc32(const char *file_path, fio_location location, bool decompress)
13701376
hdr.arg = 0;
13711377

13721378
if (decompress)
1373-
hdr.arg = 1;
1379+
hdr.arg = GET_CRC32_DECOMPRESS;
1380+
if (missing_ok)
1381+
hdr.arg |= GET_CRC32_MISSING_OK;
13741382

13751383
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
13761384
IO_CHECK(fio_write_all(fio_stdout, file_path, path_len), path_len);
@@ -1381,9 +1389,9 @@ fio_get_crc32(const char *file_path, fio_location location, bool decompress)
13811389
else
13821390
{
13831391
if (decompress)
1384-
return pgFileGetCRCgz(file_path, true, true);
1392+
return pgFileGetCRCgz(file_path, true, missing_ok);
13851393
else
1386-
return pgFileGetCRC(file_path, true, true);
1394+
return pgFileGetCRC(file_path, true, missing_ok);
13871395
}
13881396
}
13891397

@@ -3380,10 +3388,10 @@ fio_communicate(int in, int out)
33803388
break;
33813389
case FIO_GET_CRC32:
33823390
/* calculate crc32 for a file */
3383-
if (hdr.arg == 1)
3384-
crc = pgFileGetCRCgz(buf, true, true);
3391+
if ((hdr.arg & GET_CRC32_DECOMPRESS))
3392+
crc = pgFileGetCRCgz(buf, true, (hdr.arg & GET_CRC32_MISSING_OK) != 0);
33853393
else
3386-
crc = pgFileGetCRC(buf, true, true);
3394+
crc = pgFileGetCRC(buf, true, (hdr.arg & GET_CRC32_MISSING_OK) != 0);
33873395
IO_CHECK(fio_write_all(out, &crc, sizeof(crc)), sizeof(crc));
33883396
break;
33893397
case FIO_GET_CHECKSUM_MAP:

src/utils/file.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ extern int fio_truncate(int fd, off_t size);
120120
extern int fio_close(int fd);
121121
extern void fio_disconnect(void);
122122
extern int fio_sync(char const* path, fio_location location);
123-
extern pg_crc32 fio_get_crc32(const char *file_path, fio_location location, bool decompress);
123+
extern pg_crc32 fio_get_crc32(const char *file_path, fio_location location,
124+
bool decompress, bool missing_ok);
124125

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

0 commit comments

Comments
 (0)
0