Skip to content

Commit e9c3175

Browse files
committed
[Issue #169] pgFileGetCRC refactoring, now it operates only locally
1 parent 8110715 commit e9c3175

File tree

6 files changed

+23
-81
lines changed

6 files changed

+23
-81
lines changed

src/archive.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,11 @@ fileEqualCRC(const char *path1, const char *path2, bool path2_is_compressed)
594594
else
595595
#endif
596596
{
597-
crc2 = pgFileGetCRC(path2, true, true, NULL, FIO_BACKUP_HOST);
597+
crc2 = fio_get_crc32(path2, FIO_BACKUP_HOST);
598598
}
599599

600600
/* Get checksum of original file */
601-
crc1 = pgFileGetCRC(path1, true, true, NULL, FIO_DB_HOST);
601+
crc1 = fio_get_crc32(path1, FIO_DB_HOST);
602602

603603
return EQ_CRC32C(crc1, crc2);
604604
}

src/backup.c

+13-10
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
575575
{
576576
parray *xlog_files_list;
577577
char pg_xlog_path[MAXPGPATH];
578+
char wal_full_path[MAXPGPATH];
578579

579580
/* Scan backup PG_XLOG_DIR */
580581
xlog_files_list = parray_new();
@@ -586,11 +587,13 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
586587
for (i = 0; i < parray_num(xlog_files_list); i++)
587588
{
588589
pgFile *file = (pgFile *) parray_get(xlog_files_list, i);
590+
591+
join_path_components(wal_full_path, pg_xlog_path, file->rel_path);
592+
589593
if (S_ISREG(file->mode))
590594
{
591-
file->crc = pgFileGetCRC(file->path, true, false,
592-
&file->read_size, FIO_BACKUP_HOST);
593-
file->write_size = file->read_size;
595+
file->crc = pgFileGetCRC(wal_full_path, true, false);
596+
file->write_size = file->size;
594597
}
595598
/* Remove file path root prefix*/
596599
if (strstr(file->path, database_path) == file->path)
@@ -1805,10 +1808,11 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18051808
{
18061809
file = pgFileNew(backup_label, PG_BACKUP_LABEL_FILE, true, 0,
18071810
FIO_BACKUP_HOST);
1808-
file->crc = pgFileGetCRC(file->path, true, false,
1809-
&file->read_size, FIO_BACKUP_HOST);
1810-
file->write_size = file->read_size;
1811-
file->uncompressed_size = file->read_size;
1811+
1812+
file->crc = pgFileGetCRC(backup_label, true, false);
1813+
1814+
file->write_size = file->size;
1815+
file->uncompressed_size = file->size;
18121816
free(file->path);
18131817
file->path = strdup(PG_BACKUP_LABEL_FILE);
18141818
parray_append(backup_files_list, file);
@@ -1854,9 +1858,8 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18541858
FIO_BACKUP_HOST);
18551859
if (S_ISREG(file->mode))
18561860
{
1857-
file->crc = pgFileGetCRC(file->path, true, false,
1858-
&file->read_size, FIO_BACKUP_HOST);
1859-
file->write_size = file->read_size;
1861+
file->crc = pgFileGetCRC(tablespace_map, true, false);
1862+
file->write_size = file->size;
18601863
}
18611864
free(file->path);
18621865
file->path = strdup(PG_TABLESPACE_MAP_FILE);

src/dir.c

+2-62
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,9 @@ pgFileDelete(pgFile *file, const char *full_path)
259259
* We cannot make decision about file decompression because
260260
* user may ask to backup already compressed files and we should be
261261
* obvious about it.
262-
* TODO: add decompression option.
263262
*/
264263
pg_crc32
265-
pgFileGetCRCnew(const char *file_path, bool use_crc32c, bool missing_ok)
264+
pgFileGetCRC(const char *file_path, bool use_crc32c, bool missing_ok)
266265
{
267266
FILE *fp;
268267
pg_crc32 crc = 0;
@@ -316,65 +315,6 @@ pgFileGetCRCnew(const char *file_path, bool use_crc32c, bool missing_ok)
316315
return crc;
317316
}
318317

319-
/*
320-
* Read the file to compute its CRC.
321-
* As a handy side effect, we return filesize via bytes_read parameter.
322-
*/
323-
pg_crc32
324-
pgFileGetCRC(const char *file_path, bool use_crc32c, bool raise_on_deleted,
325-
size_t *bytes_read, fio_location location)
326-
{
327-
FILE *fp;
328-
pg_crc32 crc = 0;
329-
char buf[STDIO_BUFSIZE];
330-
size_t len = 0;
331-
size_t total = 0;
332-
int errno_tmp;
333-
334-
INIT_FILE_CRC32(use_crc32c, crc);
335-
336-
/* open file in binary read mode */
337-
fp = fio_fopen(file_path, PG_BINARY_R, location);
338-
if (fp == NULL)
339-
{
340-
if (!raise_on_deleted && errno == ENOENT)
341-
{
342-
FIN_FILE_CRC32(use_crc32c, crc);
343-
return crc;
344-
}
345-
else
346-
elog(ERROR, "cannot open file \"%s\": %s",
347-
file_path, strerror(errno));
348-
}
349-
350-
/* calc CRC of file */
351-
for (;;)
352-
{
353-
if (interrupted)
354-
elog(ERROR, "interrupted during CRC calculation");
355-
356-
len = fio_fread(fp, buf, sizeof(buf));
357-
if (len == 0)
358-
break;
359-
/* update CRC */
360-
COMP_FILE_CRC32(use_crc32c, crc, buf, len);
361-
total += len;
362-
}
363-
364-
if (bytes_read)
365-
*bytes_read = total;
366-
367-
errno_tmp = errno;
368-
if (len < 0)
369-
elog(WARNING, "cannot read \"%s\": %s", file_path,
370-
strerror(errno_tmp));
371-
372-
FIN_FILE_CRC32(use_crc32c, crc);
373-
fio_fclose(fp);
374-
375-
return crc;
376-
}
377-
378318
void
379319
pgFileFree(void *file)
380320
{
@@ -1775,7 +1715,7 @@ write_database_map(pgBackup *backup, parray *database_map, parray *backup_files_
17751715
FIO_BACKUP_HOST);
17761716
pfree(file->path);
17771717
file->path = pgut_strdup(DATABASE_MAP);
1778-
file->crc = pgFileGetCRCnew(database_map_path, true, false);
1718+
file->crc = pgFileGetCRC(database_map_path, true, false);
17791719

17801720
file->write_size = file->read_size;
17811721
file->uncompressed_size = file->read_size;

src/pg_probackup.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,9 @@ extern pgFile *pgFileInit(const char *path, const char *rel_path);
826826
extern void pgFileDelete(pgFile *file, const char *full_path);
827827

828828
extern void pgFileFree(void *file);
829-
extern pg_crc32 pgFileGetCRC(const char *file_path, bool use_crc32c,
830-
bool raise_on_deleted, size_t *bytes_read, fio_location location);
831-
extern pg_crc32 pgFileGetCRCnew(const char *file_path, bool missing_ok, bool use_crc32c);
832-
//extern pg_crc32 pgFileGetCRC_compressed(const char *file_path, bool use_crc32c, bool missing_ok);
829+
830+
extern pg_crc32 pgFileGetCRC(const char *file_path, bool missing_ok, bool use_crc32c);
831+
833832
extern int pgFileCompareName(const void *f1, const void *f2);
834833
extern int pgFileComparePath(const void *f1, const void *f2);
835834
extern int pgFileMapComparePath(const void *f1, const void *f2);

src/utils/file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ pg_crc32 fio_get_crc32(const char *file_path, fio_location location)
926926
return crc;
927927
}
928928
else
929-
return pgFileGetCRCnew(file_path, true, true);
929+
return pgFileGetCRC(file_path, true, true);
930930
}
931931

932932
/* Remove file */
@@ -1629,7 +1629,7 @@ void fio_communicate(int in, int out)
16291629
break;
16301630
case FIO_GET_CRC32:
16311631
/* calculate crc32 for a file */
1632-
crc = pgFileGetCRCnew(buf, true, true);
1632+
crc = pgFileGetCRC(buf, true, true);
16331633
IO_CHECK(fio_write_all(out, &crc, sizeof(crc)), sizeof(crc));
16341634
break;
16351635
default:

src/validate.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pgBackupValidateFiles(void *arg)
328328
crc = pgFileGetCRC(file->path,
329329
arguments->backup_version <= 20021 ||
330330
arguments->backup_version >= 20025,
331-
true, NULL, FIO_LOCAL_HOST);
331+
false);
332332
if (crc != file->crc)
333333
{
334334
elog(WARNING, "Invalid CRC of backup file \"%s\" : %X. Expected %X",

0 commit comments

Comments
 (0)