Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit255a925

Browse files
committed
Fix race in SSI interaction with gin fast path.
The ginfast.c code previously checked for conflicts in before lockingthe relevant buffer, leaving a window where a RW conflict could bemissed. Re-order.There was also a place where buffer ID and block number were confusedwhile trying to predicate-lock a page, noted by visual inspection.Back-patch to all supported releases. Fixes one more problem discoveredwith the reproducer from bug #17949, in this case when Dmitry triedother 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 parent17b8887 commit255a925

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)

[8]ページ先頭

©2009-2025 Movatter.jp