Skip to content

Navigation Menu

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

Appearance settings

Commit 28cc297

Browse filesBrowse files
committed
Use pg_pwrite_zeros() in walmethods.c
This change impacts pg_receivewal and pg_basebackup, for the pre-padding with zeros of all the new non-compressed WAL segments, so as the code is more robust on partial writes. This makes the code consistent with the backend (XLogFileInitInternal) when wal_init_zeros is enabled for the WAL segment initialization. Author: Bharath Rupireddy Reviewed-by: Nathan Bossart, Andres Freund, Thomas Munro, Michael Paquier Discussion: https://postgr.es/m/CALj2ACUq7nAb7=bJNbK3yYmp-SZhJcXFR_pLk8un6XgDzDF3OA@mail.gmail.com
1 parent 3bdbdf5 commit 28cc297
Copy full SHA for 28cc297

File tree

1 file changed

+11
-12
lines changed
Filter options

1 file changed

+11
-12
lines changed

‎src/bin/pg_basebackup/walmethods.c

Copy file name to clipboardExpand all lines: src/bin/pg_basebackup/walmethods.c
+11-12Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,21 @@ dir_open_for_write(WalWriteMethod *wwmethod, const char *pathname,
220220
/* Do pre-padding on non-compressed files */
221221
if (pad_to_size && wwmethod->compression_algorithm == PG_COMPRESSION_NONE)
222222
{
223-
PGAlignedXLogBlock zerobuf;
224-
int bytes;
223+
ssize_t rc;
225224

226-
memset(zerobuf.data, 0, XLOG_BLCKSZ);
227-
for (bytes = 0; bytes < pad_to_size; bytes += XLOG_BLCKSZ)
225+
rc = pg_pwrite_zeros(fd, pad_to_size);
226+
227+
if (rc < 0)
228228
{
229-
errno = 0;
230-
if (write(fd, zerobuf.data, XLOG_BLCKSZ) != XLOG_BLCKSZ)
231-
{
232-
/* If write didn't set errno, assume problem is no disk space */
233-
wwmethod->lasterrno = errno ? errno : ENOSPC;
234-
close(fd);
235-
return NULL;
236-
}
229+
wwmethod->lasterrno = errno;
230+
close(fd);
231+
return NULL;
237232
}
238233

234+
/*
235+
* pg_pwrite() (called via pg_pwrite_zeros()) may have moved the file
236+
* position, so reset it (see win32pwrite.c).
237+
*/
239238
if (lseek(fd, 0, SEEK_SET) != 0)
240239
{
241240
wwmethod->lasterrno = errno;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.