Re: Extension Enhancement: Buffer Invalidation in pg_buffercache
Japin Li <japinli@hotmail.com>
From: Japin Li <japinli@hotmail.com>
To: jian he <jian.universality@gmail.com>
Cc: Palak Chaturvedi <chaturvedipalak1911@gmail.com>, Thomas Munro
<thomas.munro@gmail.com>, pgsql-hackers@postgresql.org,
pgsql-hackers@lists.postgresql.org
Date: 2023-07-04T09:45:47Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add pg_buffercache_evict() function for testing.
- 13453eedd3f6 17.0 landed
On Tue, 04 Jul 2023 at 17:00, jian he <jian.universality@gmail.com> wrote:
> the following will also crash. no idea why.
> begin;
> select count(*) from onek;
> select relpages from pg_class where relname = 'onek'; --queryA
>
> SELECT count(*) FROM pg_buffercache WHERE relfilenode =
> pg_relation_filenode('onek'::regclass); --queryB
>
> insert into onek values(default);
>
> select count(pg_buffercache_invalidate(bufferid)) from
> pg_buffercache where relfilenode =
> pg_relation_filenode('onek'::regclass);
>
> ---------------------------------
> queryA returns 35, queryB returns 37.
> ----------------------------------
> crash info:
> test_dev=*# insert into onek values(default);
> INSERT 0 1
> test_dev=*# select count(pg_buffercache_invalidate(bufferid)) from
> pg_buffercache where relfilenode =
> pg_relation_filenode('onek'::regclass);
> TRAP: failed Assert("resarr->nitems < resarr->maxitems"), File:
> "../../Desktop/pg_sources/main/postgres/src/backend/utils/resowner/resowner.c",
> Line: 275, PID: 1533312
According to the comments of ResourceArrayAdd(), the caller must have previously
done ResourceArrayEnlarge(). I tried to call ResourceOwnerEnlargeBuffers() before
PinBuffer_Locked(), so it can avoid this crash.
if ((buf_state & BM_DIRTY) == BM_DIRTY)
{
+ /* make sure we can handle the pin */
+ ResourceOwnerEnlargeBuffers(CurrentResourceOwner);
+
/*
* Try once to flush the dirty buffer.
*/
PinBuffer_Locked(bufHdr);
--
Regrads,
Japin Li.