Re: Use pg_pwritev_with_retry() instead of write() in dir_open_for_write() to avoid partial writes?

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Use pg_pwritev_with_retry() instead of write() in dir_open_for_write() to avoid partial writes?
Date: 2022-09-29 06:02:32
Message-ID: CALj2ACWvZA4jYSWE=6a27rDFzTsuNN9SiL9cJQ-JUwEos3tR4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Sep 24, 2022 at 1:54 AM Nathan Bossart <nathandbossart(at)gmail(dot)com> wrote:
>
> + PGAlignedXLogBlock zbuffer;
> +
> + memset(zbuffer.data, 0, XLOG_BLCKSZ);
>
> This seems excessive for only writing a single byte.

Yes, I removed it now, instead doing pg_pwrite(fd, "\0", 1,
wal_segment_size - 1).

> +#ifdef WIN32
> + /*
> + * XXX: It looks like on Windows, we need an explicit lseek() call here
> + * despite using pwrite() implementation from win32pwrite.c. Otherwise
> + * an error occurs.
> + */
>
> I think this comment is too vague. Can we describe the error in more
> detail? Or better yet, can we fix it as a prerequisite to this patch set?

The commit b6d8a60aba322678585ebe11dab072a37ac32905 brings back
pg_pwrite() and its friends. This puts the responsibility of doing
lseek(SEEK_SET) on the callers if they wish to.

Please see the v5 patch set and review it further.

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v5-0001-Move-pg_pwritev_with_retry-to-file_utils.c.patch application/octet-stream 6.1 KB
v5-0002-Use-pg_pwritev_with_retry-instead-of-write-in-wal.patch application/octet-stream 7.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhang Mingli 2022-09-29 06:11:30 Re: Summary function for pg_buffercache
Previous Message Michael Paquier 2022-09-29 05:33:06 Re: [small patch] Change datatype of ParallelMessagePending from "volatile bool" to "volatile sig_atomic_t"