Re: File truncation within PostgresNode::issues_sql_like() wrong on Windows

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: File truncation within PostgresNode::issues_sql_like() wrong on Windows
Date: 2021-04-15 00:10:02
Message-ID: YHeEWs1Q35x4Y3YU@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Apr 14, 2021 at 05:10:41PM -0400, Andrew Dunstan wrote:
> That seems rather heavy-handed. The buildfarm's approach is a bit
> different. Essentially it seeks to the previous position of the log file
> before reading contents. Here is its equivalent of slurp_file:
>
> use Fcntl qw(:seek);
> sub file_lines
> {
>     my $filename = shift;
>     my $filepos  = shift;
>     my $handle;
>     open($handle, '<', $filename) || croak "opening $filename: $!";
>     seek($handle, $filepos, SEEK_SET) if $filepos;
>     my @lines = <$handle>;
>     close $handle;
>     return @lines;
> }

That's a bit surprising to see that you can safely open a file handle
with perl like that without using Win32API::File, and I would have
assumed that this would have conflicted with the backend redirecting
its output to stderr the same way as a truncation on Windows.

> A client wanting what's done in PostgresNode would do something like:
>
> my $logpos  = -s $logfile;
> do_some_stuff();
> my @lines = file_lines($logfile, $logpos);
>
> This has the benefit of working the same on all platforms, and no
> truncation, rotation, or restart is required.

Jacob has suggested something like that a couple of days ago, but all
this code was not centralized yet in a single place.

For this code, the cleanest approach would be to extend slurp_file()
with an extra argument to seek the file before fetching its contents
based on a location given by the caller? Looking at the docs of
Win32API::File, we'd need to use SetFilePointer() instead of seek().
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2021-04-15 00:16:29 Re: "could not find pathkey item to sort" for TPC-DS queries 94-96
Previous Message Robert Haas 2021-04-15 00:08:10 Re: New IndexAM API controlling index vacuum strategies