Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 28cc297

Browse 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

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/bin/pg_basebackup/walmethods.c

Lines 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)