pgvector.git / summary / log / commit / refs

commit    2a3c0a769ae147d8b1b67dacc85cf923d55901ca
Author:   Andrew Kane <andrew@ankane.org>
Date:     Wed Nov 02 19:23:49 2022 +0000

    Ensure only one backend tries to extend relation at the same time - fixes #41


src/ivfinsert.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ivfinsert.c b/src/ivfinsert.c index c896437c..e6158e1a 100644 --- a/src/ivfinsert.c +++ b/src/ivfinsert.c @@ -97,9 +97,21 @@ InsertTuple(Relation rel, IndexTuple itup, Relation heapRel, Datum *values) } 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 */ - Buffer newbuf = IvfflatNewBuffer(rel, MAIN_FORKNUM); - Page newpage = GenericXLogRegisterBuffer(state, newbuf, GENERIC_XLOG_FULL_IMAGE); + newbuf = IvfflatNewBuffer(rel, MAIN_FORKNUM); + newpage = GenericXLogRegisterBuffer(state, newbuf, GENERIC_XLOG_FULL_IMAGE); insertPage = BufferGetBlockNumber(newbuf); @@ -117,6 +129,7 @@ InsertTuple(Relation rel, IndexTuple itup, Relation heapRel, Datum *values) /* Unlock */ UnlockReleaseBuffer(buf); UnlockReleaseBuffer(newbuf); + UnlockReleaseBuffer(metabuf); } } [parent: 349d844fa159]