Re: Getting rid of some more lseek() calls

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>, Andres Freund <andres@anarazel.de>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2020-02-13T07:14:00Z
Lists: pgsql-hackers
On Thu, Feb 13, 2020 at 02:51:44PM +1300, Thomas Munro wrote:
> Ok, how about this?

Alvaro's point sounds sensible to me.  I like the approach you are
taking in 0001.  At least it avoids more issues with WIN32 and stat()
(I hope to work on that at some point, we'll see..).

+/*
+ * pg_file_size --- return the size of a file
+ */
+int64
+pg_file_size(int fd)
+{
This routine has nothing really dependent on the backend.  Would it
make sense to put it in a different place where it can be used by the
frontend?  The function should include at least a comment about why we
have a special path for Windows, aka not falling into the trap of the
4GB limit for stat().

The commit message of 0001 mentions pg_read(), and that should be
pg_pread().

There are two combinations of lseek/read that could be replaced: one
in pg_receivewal.c:FindStreamingStart(), and one in
SimpleXLogPageRead() for parsexlog.c as of pg_rewind.

Patch 0002 looks good to me.  This actually removes a confusion when
failing to seek the end of the file as the offset referenced to would
be 0.  Patch 0003 is also a very good thing.
--
Michael

Commits

  1. Use pg_pread() and pg_pwrite() in slru.c.

  2. Use pg_pwrite() in more places.