mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-13 16:16:56 +08:00
Improved locking for HNSW vacuum
This commit is contained in:
@@ -548,7 +548,7 @@ 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 */
|
/* Release lock */
|
||||||
UnlockPage(index, HNSW_UPDATE_LOCK, lockmode);
|
UnlockPage(index, HNSW_UPDATE_LOCK, lockmode);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -263,12 +263,19 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
/* Repair graph for highest non-entry point */
|
/* Repair graph for highest non-entry point */
|
||||||
if (highestPoint != NULL)
|
if (highestPoint != NULL)
|
||||||
{
|
{
|
||||||
|
LockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
||||||
|
|
||||||
HnswLoadElement(highestPoint, NULL, NULL, index, vacuumstate->procinfo, vacuumstate->collation, true);
|
HnswLoadElement(highestPoint, NULL, NULL, index, vacuumstate->procinfo, vacuumstate->collation, true);
|
||||||
|
|
||||||
if (NeedsUpdated(vacuumstate, highestPoint))
|
if (NeedsUpdated(vacuumstate, highestPoint))
|
||||||
RepairGraphElement(vacuumstate, highestPoint, HnswGetEntryPoint(index));
|
RepairGraphElement(vacuumstate, highestPoint, HnswGetEntryPoint(index));
|
||||||
|
|
||||||
|
UnlockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Wait for inserts to complete */
|
||||||
|
LockPage(index, HNSW_UPDATE_LOCK, ExclusiveLock);
|
||||||
|
|
||||||
/* See if entry point needs updated */
|
/* See if entry point needs updated */
|
||||||
entryPoint = HnswGetEntryPoint(index);
|
entryPoint = HnswGetEntryPoint(index);
|
||||||
if (entryPoint != NULL)
|
if (entryPoint != NULL)
|
||||||
@@ -298,6 +305,9 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Release lock */
|
||||||
|
UnlockPage(index, HNSW_UPDATE_LOCK, ExclusiveLock);
|
||||||
|
|
||||||
/* Reset memory context */
|
/* Reset memory context */
|
||||||
MemoryContextSwitchTo(oldCtx);
|
MemoryContextSwitchTo(oldCtx);
|
||||||
MemoryContextReset(vacuumstate->tmpCtx);
|
MemoryContextReset(vacuumstate->tmpCtx);
|
||||||
@@ -315,10 +325,6 @@ RepairGraph(HnswVacuumState * vacuumstate)
|
|||||||
|
|
||||||
RepairGraphEntryPoint(vacuumstate);
|
RepairGraphEntryPoint(vacuumstate);
|
||||||
|
|
||||||
/* Wait for inserts to complete */
|
|
||||||
LockPage(index, HNSW_UPDATE_LOCK, ExclusiveLock);
|
|
||||||
UnlockPage(index, HNSW_UPDATE_LOCK, ExclusiveLock);
|
|
||||||
|
|
||||||
while (BlockNumberIsValid(blkno))
|
while (BlockNumberIsValid(blkno))
|
||||||
{
|
{
|
||||||
Buffer buf;
|
Buffer buf;
|
||||||
|
|||||||
Reference in New Issue
Block a user