Re: Use pg_pwritev_with_retry() instead of write() in dir_open_for_write() to avoid partial writes?
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
To: Nathan Bossart <nathandbossart@gmail.com>
Cc: Thomas Munro <thomas.munro@gmail.com>,
Michael Paquier <michael@paquier.xyz>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-09-23T06:16:56Z
Lists: pgsql-hackers
Attachments
- v4-0001-Move-pg_pwritev_with_retry-to-file_utils.c.patch (application/x-patch) patch v4-0001
- v4-0002-Use-pg_pwritev_with_retry-instead-of-write-in-wal.patch (application/x-patch) patch v4-0002
On Wed, Sep 21, 2022 at 4:30 AM Nathan Bossart <nathandbossart@gmail.com> wrote: > > 0001 looks reasonable to me. Thanks for reviewing. > + errno = 0; > + rc = pg_pwritev_zeros(fd, pad_to_size); > > Do we need to reset errno? pg_pwritev_zeros() claims to set errno > appropriately. Right, pg_pwritev_zeros(), (rather pg_pwritev_with_retry() ensures that pwritev() or pwrite()) sets the correct errno, please see Thomas's comments [1] as well. Removed it. > +/* > + * PWRITEV_BLCKSZ is same as XLOG_BLCKSZ for now, however it may change if > + * writing more bytes per pg_pwritev_with_retry() call is proven to be more > + * performant. > + */ > +#define PWRITEV_BLCKSZ XLOG_BLCKSZ > > This seems like something we should sort out now instead of leaving as > future work. Given your recent note, I think we should just use > XLOG_BLCKSZ and PGAlignedXLogBlock and add a comment about the performance > findings with different buffer sizes. Agreed. Removed the new structure and added a comment. Another change that I had to do was to allow lseek() even after pwrite() (via pg_pwritev_zeros()) on Windows in walmethods.c. Without this, the regression tests start to fail on Windows. And I figured out that it's not an issue with this patch, it looks like an issue with pwrite() implementation in win32pwrite.c, see the failure here [2], I plan to start a separate thread to discuss this. Please review the attached v4 patch set further. [1] https://www.postgresql.org/message-id/CA%2BhUKGJKwUrpP0igOFAv5khj3dbHvfWqLzFeo7vtNzDYXv_YZw%40mail.gmail.com [2] https://github.com/BRupireddy/postgres/tree/use_pwrite_without_lseek_on_windiws -- Bharath Rupireddy PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
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