mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-13 16:16:56 +08:00
Use LockRelationForExtension
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "ivfflat.h"
|
#include "ivfflat.h"
|
||||||
#include "storage/bufmgr.h"
|
#include "storage/bufmgr.h"
|
||||||
|
#include "storage/lmgr.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -121,7 +122,6 @@ InsertTuple(Relation rel, Datum *values, bool *isnull, ItemPointer heap_tid, Rel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Buffer metabuf;
|
|
||||||
Buffer newbuf;
|
Buffer newbuf;
|
||||||
Page newpage;
|
Page newpage;
|
||||||
|
|
||||||
@@ -130,14 +130,16 @@ InsertTuple(Relation rel, Datum *values, bool *isnull, ItemPointer heap_tid, Rel
|
|||||||
* that only one backend tries to extend a relation at the same
|
* that only one backend tries to extend a relation at the same
|
||||||
* time!
|
* time!
|
||||||
*/
|
*/
|
||||||
metabuf = ReadBuffer(rel, IVFFLAT_METAPAGE_BLKNO);
|
LockRelationForExtension(rel, ExclusiveLock);
|
||||||
LockBuffer(metabuf, BUFFER_LOCK_EXCLUSIVE);
|
|
||||||
|
|
||||||
/* Add a new page */
|
/* Add a new page */
|
||||||
newbuf = IvfflatNewBuffer(rel, MAIN_FORKNUM);
|
newbuf = IvfflatNewBuffer(rel, MAIN_FORKNUM);
|
||||||
newpage = GenericXLogRegisterBuffer(state, newbuf, GENERIC_XLOG_FULL_IMAGE);
|
|
||||||
|
/* Unlock extend relation lock as early as possible */
|
||||||
|
UnlockRelationForExtension(rel, ExclusiveLock);
|
||||||
|
|
||||||
/* Init new page */
|
/* Init new page */
|
||||||
|
newpage = GenericXLogRegisterBuffer(state, newbuf, GENERIC_XLOG_FULL_IMAGE);
|
||||||
IvfflatInitPage(newbuf, newpage);
|
IvfflatInitPage(newbuf, newpage);
|
||||||
|
|
||||||
/* Update insert page */
|
/* Update insert page */
|
||||||
@@ -151,9 +153,6 @@ InsertTuple(Relation rel, Datum *values, bool *isnull, ItemPointer heap_tid, Rel
|
|||||||
MarkBufferDirty(buf);
|
MarkBufferDirty(buf);
|
||||||
GenericXLogFinish(state);
|
GenericXLogFinish(state);
|
||||||
|
|
||||||
/* Unlock extend relation lock as early as possible */
|
|
||||||
UnlockReleaseBuffer(metabuf);
|
|
||||||
|
|
||||||
/* Unlock previous buffer */
|
/* Unlock previous buffer */
|
||||||
UnlockReleaseBuffer(buf);
|
UnlockReleaseBuffer(buf);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user