Re: Use streaming read API in pgstattuple. - Mailing list pgsql-hackers

From Matheus Alcantara
Subject Re: Use streaming read API in pgstattuple.
Date
Msg-id f05d896e-148e-46e2-a475-e0fb4c094614@gmail.com
Whole thread Raw
In response to Re: Use streaming read API in pgstattuple.  (Nazir Bilal Yavuz <byavuz81@gmail.com>)
Responses Re: Use streaming read API in pgstattuple.
List pgsql-hackers
Hi,


On 29/11/24 04:28, Nazir Bilal Yavuz wrote:
> -        for (; blkno < nblocks; blkno++)
> +        p.last_exclusive = nblocks;
> +
> +        while (BufferIsValid(buf = read_stream_next_buffer(stream, NULL)))
>           {
>               CHECK_FOR_INTERRUPTS();
> 
> -            pagefn(&stat, rel, blkno, bstrategy);
> +            pagefn(&stat, rel, buf);
>           }
> +
> +        Assert(read_stream_next_buffer(stream, NULL) == InvalidBuffer);
> 
> With this change we assume that if stream returns an invalid buffer
> that means stream must be finished. We don't check if the stream
> didn't finish but somehow read an invalid buffer. In the upstream
> version, if we read an invalid buffer then postgres server will fail.
> But in the patched version, the server will continue to run because it
> will think that stream has reached to end. This could be happening for
> other streaming read users; for example at least the
> read_stream_next_buffer() calls in the collect_corrupt_items()
> function face the same issue.

Just for reference; On pg_prewarm() for example this loop is 
implemented as:

for (block = first_block; block <= last_block; ++block)
{
     Buffer        buf;
     ...
     buf = read_stream_next_buffer(stream, NULL);
     ...
}
Assert(read_stream_next_buffer(stream, NULL) == InvalidBuffer);


Would this approach make sense on these cases? (this patch and on 
collect_corrupt_items)


-- 
Matheus Alcantara



pgsql-hackers by date:

Previous
From: Dmitry Dolgov
Date:
Subject: Re: Changing shared_buffers without restart
Next
From: Dmitry Nikitin
Date:
Subject: Unclear code - please elaborate