mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-11 15:16:54 +08:00
Ensure only one backend tries to extend relation at the same time - fixes #41
This commit is contained in:
@@ -97,9 +97,21 @@ InsertTuple(Relation rel, IndexTuple itup, Relation heapRel, Datum *values)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Buffer metabuf;
|
||||||
|
Buffer newbuf;
|
||||||
|
Page newpage;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* From ReadBufferExtended: Caller is responsible for ensuring
|
||||||
|
* that only one backend tries to extend a relation at the same
|
||||||
|
* time!
|
||||||
|
*/
|
||||||
|
metabuf = ReadBuffer(rel, IVFFLAT_METAPAGE_BLKNO);
|
||||||
|
LockBuffer(metabuf, BUFFER_LOCK_EXCLUSIVE);
|
||||||
|
|
||||||
/* Add a new page */
|
/* Add a new page */
|
||||||
Buffer newbuf = IvfflatNewBuffer(rel, MAIN_FORKNUM);
|
newbuf = IvfflatNewBuffer(rel, MAIN_FORKNUM);
|
||||||
Page newpage = GenericXLogRegisterBuffer(state, newbuf, GENERIC_XLOG_FULL_IMAGE);
|
newpage = GenericXLogRegisterBuffer(state, newbuf, GENERIC_XLOG_FULL_IMAGE);
|
||||||
|
|
||||||
insertPage = BufferGetBlockNumber(newbuf);
|
insertPage = BufferGetBlockNumber(newbuf);
|
||||||
|
|
||||||
@@ -117,6 +129,7 @@ InsertTuple(Relation rel, IndexTuple itup, Relation heapRel, Datum *values)
|
|||||||
/* Unlock */
|
/* Unlock */
|
||||||
UnlockReleaseBuffer(buf);
|
UnlockReleaseBuffer(buf);
|
||||||
UnlockReleaseBuffer(newbuf);
|
UnlockReleaseBuffer(newbuf);
|
||||||
|
UnlockReleaseBuffer(metabuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user