Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit00c26b6

Browse files
committed
Fix a couple of bugs in pg_recvlogical output to stdout.
Don't close stdout on SIGHUP. Also, when a SIGHUP is received, close thefile immediately, rather than only after receiving some more data fromthe server. Rename a variable, to avoid mentally dealing with doublenegatives (not unsynced means synced).
1 parent8f9b959 commit00c26b6

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

‎src/bin/pg_basebackup/pg_recvlogical.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static intoutfd = -1;
5151
staticvolatilesig_atomic_ttime_to_abort= false;
5252
staticvolatilesig_atomic_toutput_reopen= false;
5353
staticint64output_last_fsync=-1;
54-
staticbooloutput_unsynced= false;
54+
staticbooloutput_needs_fsync= false;
5555
staticXLogRecPtroutput_written_lsn=InvalidXLogRecPtr;
5656
staticXLogRecPtroutput_fsync_lsn=InvalidXLogRecPtr;
5757

@@ -173,10 +173,10 @@ OutputFsync(int64 now)
173173
if (fsync_interval <=0)
174174
return true;
175175

176-
if (!output_unsynced)
176+
if (!output_needs_fsync)
177177
return true;
178178

179-
output_unsynced= false;
179+
output_needs_fsync= false;
180180

181181
/* Accept EINVAL, in case output is writing to a pipe or similar. */
182182
if (fsync(outfd)!=0&&errno!=EINVAL)
@@ -304,6 +304,17 @@ StreamLog(void)
304304
last_status=now;
305305
}
306306

307+
/* got SIGHUP, close output file */
308+
if (outfd!=-1&&output_reopen&&strcmp(outfile,"-")!=0)
309+
{
310+
now=feGetCurrentTimestamp();
311+
if (!OutputFsync(now))
312+
gotoerror;
313+
close(outfd);
314+
outfd=-1;
315+
}
316+
output_reopen= false;
317+
307318
r=PQgetCopyData(conn,&copybuf,1);
308319
if (r==0)
309320
{
@@ -327,7 +338,7 @@ StreamLog(void)
327338
((int64)1000);
328339

329340
/* Compute when we need to wakeup to fsync the output file. */
330-
if (fsync_interval>0&&output_unsynced)
341+
if (fsync_interval>0&&output_needs_fsync)
331342
fsync_target=output_last_fsync+ (fsync_interval-1)*
332343
((int64)1000);
333344

@@ -468,28 +479,14 @@ StreamLog(void)
468479
output_written_lsn=Max(temp,output_written_lsn);
469480
}
470481

471-
/* redirect output to stdout */
472-
if (outfd==-1&&strcmp(outfile,"-")==0)
473-
{
474-
outfd=fileno(stdout);
475-
}
476-
477-
/* got SIGHUP, close output file */
478-
if (outfd!=-1&&output_reopen)
479-
{
480-
now=feGetCurrentTimestamp();
481-
if (!OutputFsync(now))
482-
gotoerror;
483-
close(outfd);
484-
outfd=-1;
485-
output_reopen= false;
486-
}
487-
482+
/* open the output file, if not open yet */
488483
if (outfd==-1)
489484
{
490-
491-
outfd=open(outfile,O_CREAT |O_APPEND |O_WRONLY |PG_BINARY,
492-
S_IRUSR |S_IWUSR);
485+
if (strcmp(outfile,"-")==0)
486+
outfd=fileno(stdout);
487+
else
488+
outfd=open(outfile,O_CREAT |O_APPEND |O_WRONLY |PG_BINARY,
489+
S_IRUSR |S_IWUSR);
493490
if (outfd==-1)
494491
{
495492
fprintf(stderr,
@@ -503,7 +500,7 @@ StreamLog(void)
503500
bytes_written=0;
504501

505502
/* signal that a fsync is needed */
506-
output_unsynced= true;
503+
output_needs_fsync= true;
507504

508505
while (bytes_left)
509506
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp