if (fd < 0)
goto error;
- if (lseek(fd, off, SEEK_SET) != off)
+ if (pg_pwrite(fd, query, query_len, off) != query_len)
goto error;
-
- if (write(fd, query, query_len) != query_len)
- goto error;
- if (write(fd, "\0", 1) != 1)
+ if (pg_pwrite(fd, "\0", 1, off + query_len) != 1)
goto error;
CloseTransientFile(fd);
path, (uint32) xlrec->offset)));
pgstat_report_wait_end();
- /* now seek to the position we want to write our data to */
- if (lseek(fd, xlrec->offset, SEEK_SET) != xlrec->offset)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not seek to end of file \"%s\": %m",
- path)));
-
data = XLogRecGetData(r) + sizeof(*xlrec);
len = xlrec->num_mappings * sizeof(LogicalRewriteMappingData);
/* write out tail end of mapping file (again) */
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE);
- if (write(fd, data, len) != 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)
#define NAPTIME_PER_CYCLE 100 /* max sleep time between cycles (100ms) */
/*
- * These variables are used similarly to openLogFile/SegNo/Off,
+ * These variables are used similarly to openLogFile/SegNo,
* but for walreceiver to write the XLOG. recvFileTLI is the TimeLineID
* corresponding the filename of recvFile.
*/
static int recvFile = -1;
static TimeLineID recvFileTLI = 0;
static XLogSegNo recvSegNo = 0;
-static uint32 recvOff = 0;
/*
* Flags set by interrupt handlers of walreceiver for later service in the
use_existent = true;
recvFile = XLogFileInit(recvSegNo, &use_existent, true);
recvFileTLI = ThisTimeLineID;
- recvOff = 0;
}
/* Calculate the start offset of the received logs */
else
segbytes = nbytes;
- /* Need to seek in the file? */
- if (recvOff != startoff)
- {
- if (lseek(recvFile, (off_t) startoff, SEEK_SET) < 0)
- {
- char xlogfname[MAXFNAMELEN];
- int save_errno = errno;
-
- XLogFileName(xlogfname, recvFileTLI, recvSegNo, wal_segment_size);
- errno = save_errno;
- ereport(PANIC,
- (errcode_for_file_access(),
- errmsg("could not seek in log segment %s to offset %u: %m",
- xlogfname, startoff)));
- }
-
- recvOff = startoff;
- }
-
/* OK to write the logs */
errno = 0;
- byteswritten = write(recvFile, buf, segbytes);
+ byteswritten = pg_pwrite(recvFile, buf, segbytes, (off_t) startoff);
if (byteswritten <= 0)
{
char xlogfname[MAXFNAMELEN];
(errcode_for_file_access(),
errmsg("could not write to log segment %s "
"at offset %u, length %lu: %m",
- xlogfname, recvOff, (unsigned long) segbytes)));
+ xlogfname, startoff, (unsigned long) segbytes)));
}
/* Update state for write */
recptr += byteswritten;
- recvOff += byteswritten;
nbytes -= byteswritten;
buf += byteswritten;
len = strlen(destbuffer);
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_LOCK_FILE_ADDTODATADIR_WRITE);
- if (lseek(fd, (off_t) 0, SEEK_SET) != 0 ||
- (int) write(fd, destbuffer, len) != 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 */