Skip to content

Commit 0d87b0d

Browse files
kulaginmgsmolk
authored andcommitted
fio_check_postmaster() refactoring
1 parent 464f248 commit 0d87b0d

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/pg_probackup.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,6 @@ extern PageState *fio_get_checksum_map(fio_location location, const char *fullpa
12591259

12601260
extern datapagemap_t *fio_get_lsn_map(fio_location location, const char *fullpath, uint32 checksum_version,
12611261
int n_blocks, XLogRecPtr horizonLsn, BlockNumber segmentno);
1262-
extern pid_t fio_check_postmaster(fio_location location, const char *pgdata);
12631262

12641263
extern int32 fio_decompress(void* dst, void const* src, size_t size, int compress_alg, char **errormsg);
12651264

src/utils/file.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3658,33 +3658,39 @@ fio_check_postmaster(fio_location location, const char *pgdata)
36583658
{
36593659
if (fio_is_remote(location))
36603660
{
3661-
fio_header hdr;
3662-
3663-
hdr.cop = FIO_CHECK_POSTMASTER;
3664-
hdr.size = strlen(pgdata) + 1;
3661+
fio_header hdr = {
3662+
.cop = FIO_CHECK_POSTMASTER,
3663+
.handle = -1,
3664+
.size = strlen(pgdata) + 1,
3665+
.arg = 0,
3666+
};
36653667

36663668
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
36673669
IO_CHECK(fio_write_all(fio_stdout, pgdata, hdr.size), hdr.size);
36683670

36693671
/* receive result */
36703672
IO_CHECK(fio_read_all(fio_stdin, &hdr, sizeof(hdr)), sizeof(hdr));
3673+
Assert(hdr.cop == FIO_CHECK_POSTMASTER);
3674+
36713675
return hdr.arg;
36723676
}
36733677
else
36743678
return local_check_postmaster(pgdata);
36753679
}
36763680

36773681
static void
3678-
fio_check_postmaster_impl(int out, char *buf)
3682+
fio_check_postmaster_impl(const char *pgdata, int out)
36793683
{
3680-
fio_header hdr;
3681-
pid_t postmaster_pid;
3682-
char *pgdata = (char*) buf;
3684+
fio_header hdr = {
3685+
.cop = FIO_CHECK_POSTMASTER,
3686+
.handle = -1,
3687+
.size = 0,
3688+
.arg = 0,
3689+
};
36833690

3684-
postmaster_pid = local_check_postmaster(pgdata);
3691+
hdr.arg = local_check_postmaster(pgdata);
36853692

36863693
/* send arrays of checksums to main process */
3687-
hdr.arg = postmaster_pid;
36883694
IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));
36893695
}
36903696

@@ -3881,8 +3887,7 @@ fio_communicate(int in, int out)
38813887
fio_get_lsn_map_impl(out, buf);
38823888
break;
38833889
case FIO_CHECK_POSTMASTER:
3884-
/* calculate crc32 for a file */
3885-
fio_check_postmaster_impl(out, buf);
3890+
fio_check_postmaster_impl(buf, out);
38863891
break;
38873892
case FIO_DISCONNECT:
38883893
hdr.cop = FIO_DISCONNECTED;

src/utils/file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ extern int fio_access(fio_location location, const char* path, int mode);
151151
extern int fio_stat(fio_location location, const char* path, struct stat* st, bool follow_symlinks);
152152
extern bool fio_is_same_file(fio_location location, const char* filename1, const char* filename2, bool follow_symlink);
153153
extern ssize_t fio_readlink(fio_location location, const char *path, char *value, size_t valsiz);
154+
extern pid_t fio_check_postmaster(fio_location location, const char *pgdata);
154155

155156
/* gzFile-style functions */
156157
#ifdef HAVE_LIBZ

0 commit comments

Comments
 (0)