mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-10 14:46:56 +08:00
Wait for inserts to complete when vacuuming HNSW
This commit is contained in:
@@ -561,6 +561,12 @@ HnswInsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_ti
|
|||||||
element = HnswInitElement(heap_tid, m, ml, HnswGetMaxLevel(m));
|
element = HnswInitElement(heap_tid, m, ml, HnswGetMaxLevel(m));
|
||||||
element->vec = DatumGetVector(value);
|
element->vec = DatumGetVector(value);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a shared lock for the duration of the insert. Use a page lock so it
|
||||||
|
* does not interfere with buffer lock (or reads when vacuuming).
|
||||||
|
*/
|
||||||
|
LockPage(index, HNSW_METAPAGE_BLKNO, ShareLock);
|
||||||
|
|
||||||
/* Get entry point */
|
/* Get entry point */
|
||||||
entryPoint = HnswGetEntryPoint(index);
|
entryPoint = HnswGetEntryPoint(index);
|
||||||
|
|
||||||
@@ -568,7 +574,10 @@ HnswInsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_ti
|
|||||||
if (entryPoint == NULL)
|
if (entryPoint == NULL)
|
||||||
{
|
{
|
||||||
if (HnswAddEntryPoint(index, element, m, &entryPoint))
|
if (HnswAddEntryPoint(index, element, m, &entryPoint))
|
||||||
|
{
|
||||||
|
UnlockPage(index, HNSW_METAPAGE_BLKNO, ShareLock);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert element in graph */
|
/* Insert element in graph */
|
||||||
@@ -580,6 +589,9 @@ HnswInsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_ti
|
|||||||
/* Write to disk */
|
/* Write to disk */
|
||||||
WriteElement(index, procinfo, collation, element, m, efConstruction, dup, entryPoint);
|
WriteElement(index, procinfo, collation, element, m, efConstruction, dup, entryPoint);
|
||||||
|
|
||||||
|
/* Release shared lock */
|
||||||
|
UnlockPage(index, HNSW_METAPAGE_BLKNO, ShareLock);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "commands/vacuum.h"
|
#include "commands/vacuum.h"
|
||||||
#include "hnsw.h"
|
#include "hnsw.h"
|
||||||
#include "storage/bufmgr.h"
|
#include "storage/bufmgr.h"
|
||||||
|
#include "storage/lmgr.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -256,6 +257,10 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
* ideal.
|
* ideal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Wait for inserts to complete */
|
||||||
|
LockPage(index, HNSW_METAPAGE_BLKNO, ExclusiveLock);
|
||||||
|
UnlockPage(index, HNSW_METAPAGE_BLKNO, ExclusiveLock);
|
||||||
|
|
||||||
if (!BlockNumberIsValid(highestPoint->blkno))
|
if (!BlockNumberIsValid(highestPoint->blkno))
|
||||||
highestPoint = NULL;
|
highestPoint = NULL;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user