aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2018-11-07 09:51:50 +1300
committerThomas Munro <tmunro@postgresql.org>2018-11-07 09:51:50 +1300
commitc24dcd0cfd949bdf245814c4c2b3df828ee7db36 (patch)
tree7b361229b1a9bb895894dff9eaa8a593be9e20ce /src/backend/access/transam/xlog.c
parent3fd2a7932ef0708dda57369bb20c0499d905cc82 (diff)
downloadpostgresql-c24dcd0cfd949bdf245814c4c2b3df828ee7db36.tar.gz
postgresql-c24dcd0cfd949bdf245814c4c2b3df828ee7db36.zip
Use pg_pread() and pg_pwrite() for data files and WAL.
Cut down on system calls by doing random I/O using offset-based OS routines where available. Remove the code for tracking the 'virtual' seek position. The only reason left to call FileSeek() was to get the file's size, so provide a new function FileSize() instead. Author: Oskari Saarenmaa, Thomas Munro Reviewed-by: Thomas Munro, Jesper Pedersen, Tom Lane, Alvaro Herrera Discussion: https://postgr.es/m/CAEepm=02rapCpPR3ZGF2vW=SBHSdFYO_bz_f-wwWJonmA3APgw@mail.gmail.com Discussion: https://postgr.es/m/b8748d39-0b19-0514-a1b9-4e5a28e6a208%40gmail.com Discussion: https://postgr.es/m/a86bd200-ebbe-d829-e3ca-0c4474b2fcb7%40ohmu.fi
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c30
1 files changed, 3 insertions, 27 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 246869bba29..7eed5866d2e 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -2478,18 +2478,6 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
Size nleft;
int written;
- /* Need to seek in the file? */
- if (openLogOff != startoffset)
- {
- if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
- ereport(PANIC,
- (errcode_for_file_access(),
- errmsg("could not seek in log file %s to offset %u: %m",
- XLogFileNameP(ThisTimeLineID, openLogSegNo),
- startoffset)));
- openLogOff = startoffset;
- }
-
/* OK to write the page(s) */
from = XLogCtl->pages + startidx * (Size) XLOG_BLCKSZ;
nbytes = npages * (Size) XLOG_BLCKSZ;
@@ -2498,7 +2486,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
{
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_WAL_WRITE);
- written = write(openLogFile, from, nleft);
+ written = pg_pwrite(openLogFile, from, nleft, startoffset);
pgstat_report_wait_end();
if (written <= 0)
{
@@ -2513,6 +2501,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
}
nleft -= written;
from += written;
+ startoffset += written;
} while (nleft > 0);
/* Update state for write */
@@ -11821,22 +11810,9 @@ retry:
/* Read the requested page */
readOff = targetPageOff;
- if (lseek(readFile, (off_t) readOff, SEEK_SET) < 0)
- {
- char fname[MAXFNAMELEN];
- int save_errno = errno;
-
- XLogFileName(fname, curFileTLI, readSegNo, wal_segment_size);
- errno = save_errno;
- ereport(emode_for_corrupt_record(emode, targetPagePtr + reqLen),
- (errcode_for_file_access(),
- errmsg("could not seek in log segment %s to offset %u: %m",
- fname, readOff)));
- goto next_record_is_invalid;
- }
pgstat_report_wait_start(WAIT_EVENT_WAL_READ);
- r = read(readFile, readBuf, XLOG_BLCKSZ);
+ r = pg_pread(readFile, readBuf, XLOG_BLCKSZ, (off_t) readOff);
if (r != XLOG_BLCKSZ)
{
char fname[MAXFNAMELEN];