mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-12 15:46:54 +08:00
Reduced lock contention with parallel HNSW index builds
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 0.6.2 (unreleased)
|
||||||
|
|
||||||
|
- Reduced lock contention with parallel HNSW index builds
|
||||||
|
|
||||||
## 0.6.1 (2024-03-04)
|
## 0.6.1 (2024-03-04)
|
||||||
|
|
||||||
- Fixed error with `ANALYZE` and vectors with different dimensions
|
- Fixed error with `ANALYZE` and vectors with different dimensions
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ typedef struct HnswGraph
|
|||||||
|
|
||||||
/* Entry state */
|
/* Entry state */
|
||||||
LWLock entryLock;
|
LWLock entryLock;
|
||||||
|
LWLock entryWaitLock;
|
||||||
HnswElementPtr entryPoint;
|
HnswElementPtr entryPoint;
|
||||||
|
|
||||||
/* Allocations state */
|
/* Allocations state */
|
||||||
|
|||||||
@@ -431,10 +431,15 @@ InsertTupleInMemory(HnswBuildState * buildstate, HnswElement element)
|
|||||||
HnswGraph *graph = buildstate->graph;
|
HnswGraph *graph = buildstate->graph;
|
||||||
HnswElement entryPoint;
|
HnswElement entryPoint;
|
||||||
LWLock *entryLock = &graph->entryLock;
|
LWLock *entryLock = &graph->entryLock;
|
||||||
|
LWLock *entryWaitLock = &graph->entryWaitLock;
|
||||||
int efConstruction = buildstate->efConstruction;
|
int efConstruction = buildstate->efConstruction;
|
||||||
int m = buildstate->m;
|
int m = buildstate->m;
|
||||||
char *base = buildstate->hnswarea;
|
char *base = buildstate->hnswarea;
|
||||||
|
|
||||||
|
/* Wait if another process needs exclusive lock */
|
||||||
|
LWLockAcquire(entryWaitLock, LW_EXCLUSIVE);
|
||||||
|
LWLockRelease(entryWaitLock);
|
||||||
|
|
||||||
/* Get entry point */
|
/* Get entry point */
|
||||||
LWLockAcquire(entryLock, LW_SHARED);
|
LWLockAcquire(entryLock, LW_SHARED);
|
||||||
entryPoint = HnswPtrAccess(base, graph->entryPoint);
|
entryPoint = HnswPtrAccess(base, graph->entryPoint);
|
||||||
@@ -446,7 +451,9 @@ InsertTupleInMemory(HnswBuildState * buildstate, HnswElement element)
|
|||||||
LWLockRelease(entryLock);
|
LWLockRelease(entryLock);
|
||||||
|
|
||||||
/* Get exclusive lock */
|
/* Get exclusive lock */
|
||||||
|
LWLockAcquire(entryWaitLock, LW_EXCLUSIVE);
|
||||||
LWLockAcquire(entryLock, LW_EXCLUSIVE);
|
LWLockAcquire(entryLock, LW_EXCLUSIVE);
|
||||||
|
LWLockRelease(entryWaitLock);
|
||||||
|
|
||||||
/* Get latest entry point after lock is acquired */
|
/* Get latest entry point after lock is acquired */
|
||||||
entryPoint = HnswPtrAccess(base, graph->entryPoint);
|
entryPoint = HnswPtrAccess(base, graph->entryPoint);
|
||||||
@@ -612,6 +619,7 @@ InitGraph(HnswGraph * graph, char *base, long memoryTotal)
|
|||||||
graph->indtuples = 0;
|
graph->indtuples = 0;
|
||||||
SpinLockInit(&graph->lock);
|
SpinLockInit(&graph->lock);
|
||||||
LWLockInitialize(&graph->entryLock, hnsw_lock_tranche_id);
|
LWLockInitialize(&graph->entryLock, hnsw_lock_tranche_id);
|
||||||
|
LWLockInitialize(&graph->entryWaitLock, hnsw_lock_tranche_id);
|
||||||
LWLockInitialize(&graph->allocatorLock, hnsw_lock_tranche_id);
|
LWLockInitialize(&graph->allocatorLock, hnsw_lock_tranche_id);
|
||||||
LWLockInitialize(&graph->flushLock, hnsw_lock_tranche_id);
|
LWLockInitialize(&graph->flushLock, hnsw_lock_tranche_id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user