Skip to content

Commit

Permalink
Handle partial writes to stdout in WAL redo process.
Browse files Browse the repository at this point in the history
  • Loading branch information
hlinnaka authored and lubennikovaav committed Feb 9, 2022
1 parent d6cb3fa commit bcbf12c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/backend/tcop/zenith_wal_redo.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ GetPage(StringInfo input_message)
BlockNumber blknum;
Buffer buf;
Page page;
int tot_written;

/*
* message format:
Expand All @@ -683,7 +684,21 @@ GetPage(StringInfo input_message)
/* single thread, so don't bother locking the page */

/* Response: Page content */
write(STDOUT_FILENO, page, BLCKSZ); /* FIXME: check errors */
tot_written = 0;
do {
ssize_t rc;

rc = write(STDOUT_FILENO, &page[tot_written], BLCKSZ - tot_written);
if (rc < 0) {
/* If interrupted by signal, just retry */
if (errno == EINTR)
continue;
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not write to stdout: %m")));
}
tot_written += rc;
} while (tot_written < BLCKSZ);

ReleaseBuffer(buf);
DropDatabaseBuffers(rnode.dbNode);
Expand Down

0 comments on commit bcbf12c

Please sign in to comment.