mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Restore pg_pread and friends.
Commitscf112c12anda0dc8271were a little too hasty in getting rid of the pg_ prefixes where we use pread(), pwrite() and vectored variants. We dropped support for ancient Unixes where we needed to use lseek() to implement replacements for those, but it turns out that Windows also changes the current position even when you pass in an offset to ReadFile() and WriteFile() if the file handle is synchronous, despite its documentation saying otherwise. Switching to asynchronous file handles would fix that, but have other complications. For now let's just put back the pg_ prefix and add some comments to highlight the non-standard side-effect, which we can now describe as Windows-only. Reported-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Discussion: https://postgr.es/m/20220923202439.GA1156054%40nathanxps13
This commit is contained in:
@@ -1150,7 +1150,7 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
|
||||
/* write out tail end of mapping file (again) */
|
||||
errno = 0;
|
||||
pgstat_report_wait_start(WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE);
|
||||
if (pwrite(fd, data, len, xlrec->offset) != len)
|
||||
if (pg_pwrite(fd, data, len, xlrec->offset) != len)
|
||||
{
|
||||
/* if write didn't set errno, assume problem is no disk space */
|
||||
if (errno == 0)
|
||||
|
||||
@@ -718,7 +718,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
|
||||
|
||||
errno = 0;
|
||||
pgstat_report_wait_start(WAIT_EVENT_SLRU_READ);
|
||||
if (pread(fd, shared->page_buffer[slotno], BLCKSZ, offset) != BLCKSZ)
|
||||
if (pg_pread(fd, shared->page_buffer[slotno], BLCKSZ, offset) != BLCKSZ)
|
||||
{
|
||||
pgstat_report_wait_end();
|
||||
slru_errcause = SLRU_READ_FAILED;
|
||||
@@ -873,7 +873,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruWriteAll fdata)
|
||||
|
||||
errno = 0;
|
||||
pgstat_report_wait_start(WAIT_EVENT_SLRU_WRITE);
|
||||
if (pwrite(fd, shared->page_buffer[slotno], BLCKSZ, offset) != BLCKSZ)
|
||||
if (pg_pwrite(fd, shared->page_buffer[slotno], BLCKSZ, offset) != BLCKSZ)
|
||||
{
|
||||
pgstat_report_wait_end();
|
||||
/* if write didn't set errno, assume problem is no disk space */
|
||||
|
||||
@@ -2196,7 +2196,7 @@ XLogWrite(XLogwrtRqst WriteRqst, TimeLineID tli, bool flexible)
|
||||
INSTR_TIME_SET_CURRENT(start);
|
||||
|
||||
pgstat_report_wait_start(WAIT_EVENT_WAL_WRITE);
|
||||
written = pwrite(openLogFile, from, nleft, startoffset);
|
||||
written = pg_pwrite(openLogFile, from, nleft, startoffset);
|
||||
pgstat_report_wait_end();
|
||||
|
||||
/*
|
||||
@@ -3018,7 +3018,7 @@ XLogFileInitInternal(XLogSegNo logsegno, TimeLineID logtli,
|
||||
* enough.
|
||||
*/
|
||||
errno = 0;
|
||||
if (pwrite(fd, zbuffer.data, 1, wal_segment_size - 1) != 1)
|
||||
if (pg_pwrite(fd, zbuffer.data, 1, wal_segment_size - 1) != 1)
|
||||
{
|
||||
/* if write didn't set errno, assume no disk space */
|
||||
save_errno = errno ? errno : ENOSPC;
|
||||
|
||||
@@ -1544,7 +1544,7 @@ WALRead(XLogReaderState *state,
|
||||
|
||||
/* Reset errno first; eases reporting non-errno-affecting errors */
|
||||
errno = 0;
|
||||
readbytes = pread(state->seg.ws_file, p, segbytes, (off_t) startoff);
|
||||
readbytes = pg_pread(state->seg.ws_file, p, segbytes, (off_t) startoff);
|
||||
|
||||
#ifndef FRONTEND
|
||||
pgstat_report_wait_end();
|
||||
|
||||
@@ -3271,7 +3271,7 @@ retry:
|
||||
readOff = targetPageOff;
|
||||
|
||||
pgstat_report_wait_start(WAIT_EVENT_WAL_READ);
|
||||
r = pread(readFile, readBuf, XLOG_BLCKSZ, (off_t) readOff);
|
||||
r = pg_pread(readFile, readBuf, XLOG_BLCKSZ, (off_t) readOff);
|
||||
if (r != XLOG_BLCKSZ)
|
||||
{
|
||||
char fname[MAXFNAMELEN];
|
||||
|
||||
@@ -1828,7 +1828,7 @@ basebackup_read_file(int fd, char *buf, size_t nbytes, off_t offset,
|
||||
int rc;
|
||||
|
||||
pgstat_report_wait_start(WAIT_EVENT_BASEBACKUP_READ);
|
||||
rc = pread(fd, buf, nbytes, offset);
|
||||
rc = pg_pread(fd, buf, nbytes, offset);
|
||||
pgstat_report_wait_end();
|
||||
|
||||
if (rc < 0)
|
||||
|
||||
@@ -915,7 +915,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr, TimeLineID tli)
|
||||
/* OK to write the logs */
|
||||
errno = 0;
|
||||
|
||||
byteswritten = pwrite(recvFile, buf, segbytes, (off_t) startoff);
|
||||
byteswritten = pg_pwrite(recvFile, buf, segbytes, (off_t) startoff);
|
||||
if (byteswritten <= 0)
|
||||
{
|
||||
char xlogfname[MAXFNAMELEN];
|
||||
|
||||
@@ -2053,7 +2053,7 @@ FileRead(File file, char *buffer, int amount, off_t offset,
|
||||
|
||||
retry:
|
||||
pgstat_report_wait_start(wait_event_info);
|
||||
returnCode = pread(vfdP->fd, buffer, amount, offset);
|
||||
returnCode = pg_pread(vfdP->fd, buffer, amount, offset);
|
||||
pgstat_report_wait_end();
|
||||
|
||||
if (returnCode < 0)
|
||||
@@ -2135,7 +2135,7 @@ FileWrite(File file, char *buffer, int amount, off_t offset,
|
||||
retry:
|
||||
errno = 0;
|
||||
pgstat_report_wait_start(wait_event_info);
|
||||
returnCode = pwrite(VfdCache[file].fd, buffer, amount, offset);
|
||||
returnCode = pg_pwrite(VfdCache[file].fd, buffer, amount, offset);
|
||||
pgstat_report_wait_end();
|
||||
|
||||
/* if write didn't set errno, assume problem is no disk space */
|
||||
@@ -3740,7 +3740,7 @@ data_sync_elevel(int elevel)
|
||||
}
|
||||
|
||||
/*
|
||||
* A convenience wrapper for pwritev() that retries on partial write. If an
|
||||
* A convenience wrapper for pg_pwritev() that retries on partial write. If an
|
||||
* error is returned, it is unspecified how much has been written.
|
||||
*/
|
||||
ssize_t
|
||||
@@ -3760,7 +3760,7 @@ pg_pwritev_with_retry(int fd, const struct iovec *iov, int iovcnt, off_t offset)
|
||||
for (;;)
|
||||
{
|
||||
/* Write as much as we can. */
|
||||
part = pwritev(fd, iov, iovcnt, offset);
|
||||
part = pg_pwritev(fd, iov, iovcnt, offset);
|
||||
if (part < 0)
|
||||
return -1;
|
||||
|
||||
|
||||
@@ -1527,7 +1527,7 @@ AddToDataDirLockFile(int target_line, const char *str)
|
||||
len = strlen(destbuffer);
|
||||
errno = 0;
|
||||
pgstat_report_wait_start(WAIT_EVENT_LOCK_FILE_ADDTODATADIR_WRITE);
|
||||
if (pwrite(fd, destbuffer, len, 0) != len)
|
||||
if (pg_pwrite(fd, destbuffer, len, 0) != len)
|
||||
{
|
||||
pgstat_report_wait_end();
|
||||
/* if write didn't set errno, assume problem is no disk space */
|
||||
|
||||
Reference in New Issue
Block a user