Skip to content

Commit bf8b122

Browse files
committed
fio_check_postmaster() refactoring
1 parent b2283f8 commit bf8b122

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

src/catchup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ catchup_preflight_checks(PGNodeInfo *source_node_info, PGconn *source_conn,
133133
if (current.backup_mode != BACKUP_MODE_FULL)
134134
{
135135
pid_t pid;
136-
pid = fio_check_postmaster(dest_pgdata, FIO_LOCAL_HOST);
136+
pid = fio_check_postmaster(FIO_LOCAL_HOST, dest_pgdata);
137137
if (pid == 1) /* postmaster.pid is mangled */
138138
{
139139
char pid_filename[MAXPGPATH];

src/pg_probackup.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,6 @@ extern PageState *fio_get_checksum_map(const char *fullpath, uint32 checksum_ver
12361236
extern datapagemap_t *fio_get_lsn_map(const char *fullpath, uint32 checksum_version,
12371237
int n_blocks, XLogRecPtr horizonLsn, BlockNumber segmentno,
12381238
fio_location location);
1239-
extern pid_t fio_check_postmaster(const char *pgdata, fio_location location);
12401239

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

src/restore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,7 @@ check_incremental_compatibility(const char *pgdata, uint64 system_identifier,
21602160
char backup_label[MAXPGPATH];
21612161

21622162
/* check postmaster pid */
2163-
pid = fio_check_postmaster(pgdata, FIO_DB_HOST);
2163+
pid = fio_check_postmaster(FIO_DB_HOST, pgdata);
21642164

21652165
if (pid == 1) /* postmaster.pid is mangled */
21662166
{

src/utils/file.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,37 +3206,43 @@ local_check_postmaster(const char *pgdata)
32063206
* and check that process is running, if process is running, return its pid number.
32073207
*/
32083208
pid_t
3209-
fio_check_postmaster(const char *pgdata, fio_location location)
3209+
fio_check_postmaster(fio_location location, const char *pgdata)
32103210
{
32113211
if (fio_is_remote(location))
32123212
{
3213-
fio_header hdr;
3214-
3215-
hdr.cop = FIO_CHECK_POSTMASTER;
3216-
hdr.size = strlen(pgdata) + 1;
3213+
fio_header hdr = {
3214+
.cop = FIO_CHECK_POSTMASTER,
3215+
.handle = -1,
3216+
.size = strlen(pgdata) + 1,
3217+
.arg = 0,
3218+
};
32173219

32183220
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
32193221
IO_CHECK(fio_write_all(fio_stdout, pgdata, hdr.size), hdr.size);
32203222

32213223
/* receive result */
32223224
IO_CHECK(fio_read_all(fio_stdin, &hdr, sizeof(hdr)), sizeof(hdr));
3225+
Assert(hdr.cop == FIO_CHECK_POSTMASTER);
3226+
32233227
return hdr.arg;
32243228
}
32253229
else
32263230
return local_check_postmaster(pgdata);
32273231
}
32283232

32293233
static void
3230-
fio_check_postmaster_impl(int out, char *buf)
3234+
fio_check_postmaster_impl(const char *pgdata, int out)
32313235
{
3232-
fio_header hdr;
3233-
pid_t postmaster_pid;
3234-
char *pgdata = (char*) buf;
3236+
fio_header hdr = {
3237+
.cop = FIO_CHECK_POSTMASTER,
3238+
.handle = -1,
3239+
.size = 0,
3240+
.arg = 0,
3241+
};
32353242

3236-
postmaster_pid = local_check_postmaster(pgdata);
3243+
hdr.arg = local_check_postmaster(pgdata);
32373244

32383245
/* send arrays of checksums to main process */
3239-
hdr.arg = postmaster_pid;
32403246
IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));
32413247
}
32423248

@@ -3427,8 +3433,7 @@ fio_communicate(int in, int out)
34273433
fio_get_lsn_map_impl(out, buf);
34283434
break;
34293435
case FIO_CHECK_POSTMASTER:
3430-
/* calculate crc32 for a file */
3431-
fio_check_postmaster_impl(out, buf);
3436+
fio_check_postmaster_impl(buf, out);
34323437
break;
34333438
case FIO_DISCONNECT:
34343439
hdr.cop = FIO_DISCONNECTED;

src/utils/file.h

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

151152
/* gzFile-style functions */
152153
#ifdef HAVE_LIBZ

0 commit comments

Comments
 (0)