mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-13 08:06:54 +08:00
Improved locking for HNSW vacuum [skip ci]
This commit is contained in:
@@ -263,6 +263,7 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
/* Repair graph for highest non-entry point */
|
/* Repair graph for highest non-entry point */
|
||||||
if (highestPoint != NULL)
|
if (highestPoint != NULL)
|
||||||
{
|
{
|
||||||
|
/* Get a shared lock */
|
||||||
LockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
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);
|
||||||
@@ -270,13 +271,13 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
if (NeedsUpdated(vacuumstate, highestPoint))
|
if (NeedsUpdated(vacuumstate, highestPoint))
|
||||||
RepairGraphElement(vacuumstate, highestPoint, HnswGetEntryPoint(index));
|
RepairGraphElement(vacuumstate, highestPoint, HnswGetEntryPoint(index));
|
||||||
|
|
||||||
|
/* Release lock */
|
||||||
UnlockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
UnlockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for inserts to complete */
|
/* Prevent concurrent inserts when possibly updating entry point */
|
||||||
LockPage(index, HNSW_UPDATE_LOCK, ExclusiveLock);
|
LockPage(index, HNSW_UPDATE_LOCK, ExclusiveLock);
|
||||||
|
|
||||||
/* See if entry point needs updated */
|
|
||||||
entryPoint = HnswGetEntryPoint(index);
|
entryPoint = HnswGetEntryPoint(index);
|
||||||
if (entryPoint != NULL)
|
if (entryPoint != NULL)
|
||||||
{
|
{
|
||||||
@@ -323,6 +324,10 @@ RepairGraph(HnswVacuumState * vacuumstate)
|
|||||||
BufferAccessStrategy bas = vacuumstate->bas;
|
BufferAccessStrategy bas = vacuumstate->bas;
|
||||||
BlockNumber blkno = HNSW_HEAD_BLKNO;
|
BlockNumber blkno = HNSW_HEAD_BLKNO;
|
||||||
|
|
||||||
|
/* Wait for inserts to complete */
|
||||||
|
LockPage(index, HNSW_UPDATE_LOCK, ExclusiveLock);
|
||||||
|
UnlockPage(index, HNSW_UPDATE_LOCK, ExclusiveLock);
|
||||||
|
|
||||||
RepairGraphEntryPoint(vacuumstate);
|
RepairGraphEntryPoint(vacuumstate);
|
||||||
|
|
||||||
while (BlockNumberIsValid(blkno))
|
while (BlockNumberIsValid(blkno))
|
||||||
|
|||||||
Reference in New Issue
Block a user