Re: Use pg_pwritev_with_retry() instead of write() in dir_open_for_write() to avoid partial writes?
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>, Alvaro Herrera <alvherre@alvh.no-ip.org>, Nathan Bossart <nathandbossart@gmail.com>, Thomas Munro <thomas.munro@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-02-15T00:55:25Z
Lists: pgsql-hackers
Attachments
- v3-0001-Revise-pg_pwrite_zeros.patch (text/x-diff)
Hi, On 2023-02-14 18:00:00 +0530, Bharath Rupireddy wrote: > On Mon, Feb 13, 2023 at 11:09 PM Andres Freund <andres@anarazel.de> wrote: > > > > > Later code assigns iov[0].iov_len thus we need to provide a separate > > > iov non-const variable, or can we use pwrite instead there? (I didn't > > > find pg_pwrite_with_retry(), though) > > > > Given that we need to do that, and given that we already need to loop to > > handle writes that are longer than PG_IOV_MAX * BLCKSZ, it's probably not > > worth avoiding iov initialization. > > > > But I think it's worth limiting the initialization to blocks. > > We can still optimize away the for loop by using a single iovec for > remaining size, like the attached v2 patch. > > > I'd also try to combine the first pg_writev_* with the second one. > > Done, PSA v2 patch. This feels way too complicated to me. How about something more like the attached? > 2) A small test module passing in a file with the size to write isn't > multiple of block size, meaning, the code we have in the function to > write last remaining bytes (less than BLCKSZ) gets covered which isn't > covered right now - FWIW, I tested this locally by just specifying a smaller size than BLCKSZ for the write size. Greetings, Andres Freund
Commits
-
Revise pg_pwrite_zeros()
- ce340e530d1f 16.0 landed
-
Use pg_pwrite_zeros() in walmethods.c
- 28cc2976a9cf 16.0 landed
-
Introduce pg_pwrite_zeros() in fileutils.c
- 3bdbdf5d06f2 16.0 landed
-
Move pg_pwritev_with_retry() to src/common/file_utils.c
- 4ab8c81bd90a 16.0 landed
-
Restore pg_pread and friends.
- b6d8a60aba32 16.0 landed
-
Remove dead pread and pwrite replacement code.
- cf112c122060 16.0 cited