8000 Fix race in SSI interaction with gin fast path. · postgres/postgres@13f1278 · GitHub
[go: up one dir, main page]

Skip to content

Commit 13f1278

Browse files
committed
Fix race in SSI interaction with gin fast path.
The ginfast.c code previously checked for conflicts in before locking the relevant buffer, leaving a window where a RW conflict could be missed. Re-order. There was also a place where buffer ID and block number were confused while trying to predicate-lock a page, noted by visual inspection. Back-patch to all supported releases. Fixes one more problem discovered with the reproducer from bug #17949, in this case when Dmitry tried other index types. Reported-by: Artem Anisimov <artem.anisimov.255@gmail.com> Reported-by: Dmitry Dolgov <9erthalion6@gmail.com> Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Discussion: https://postgr.es/m/17949-a0f17035294a55e2%40postgresql.org
1 parent 814f3c8 commit 13f1278

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/backend/access/gin/ginfast.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,10 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
244244
/*
245245
* An insertion to the pending list could logically belong anywhere in the
246246
* tree, so it conflicts with all serializable scans. All scans acquire a
247-
* predicate lock on the metabuffer to represent that.
247+
* predicate lock on the metabuffer to represent that. Therefore we'll
248+
* check for conflicts in, but not until we have the page locked and are
249+
* ready to modify the page.
248250
*/
249-
CheckForSerializableConflictIn(index, NULL, metabuffer);
250251

251252
if (collector->sumsize + collector->ntuples * sizeof(ItemIdData) > GinListPageSize)
252253
{
@@ -290,6 +291,8 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
290291
LockBuffer(metabuffer, GIN_EXCLUSIVE);
291292
metadata = GinPageGetMeta(metapage);
292293

294+
CheckForSerializableConflictIn(index, NULL, metabuffer);
295+
293296
if (metadata->head == InvalidBlockNumber)
294297
{
295298
/*
@@ -352,6 +355,8 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
352355
char *ptr;
353356
char *collectordata;
354357

358+
CheckForSerializableConflictIn(index, NULL, metabuffer);
359+
355360
buffer = ReadBuffer(index, metadata->tail);
356361
LockBuffer(buffer, GIN_EXCLUSIVE);
357362
page = BufferGetPage(buffer);

src/backend/access/gin/ginget.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ collectMatchBitmap(GinBtreeData *btree, GinBtreeStack *stack,
139139
* Predicate lock entry leaf page, following pages will be locked by
140140
* moveRightIfItNeeded()
141141
*/
142-
PredicateLockPage(btree->index, stack->buffer, snapshot);
142+
PredicateLockPage(btree->index,
143+
BufferGetBlockNumber(stack->buffer),
144+
snapshot);
143145

144146
for (;;)
145147
{

0 commit comments

Comments
 (0)
0