From c207a2d50e094c2a0e54438447ff7fd429af2262 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Mon, 11 Mar 2024 19:50:48 -0700 Subject: [PATCH] Reduced lock contention with parallel HNSW index builds --- CHANGELOG.md | 4 ++++ src/hnswbuild.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34af92e..bf81eb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.2 (unreleased) + +- Reduced lock contention with parallel HNSW index builds + ## 0.6.1 (2024-03-04) - Fixed error with `ANALYZE` and vectors with different dimensions diff --git a/src/hnswbuild.c b/src/hnswbuild.c index 990fb7f..b5a72ab 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -437,8 +437,8 @@ InsertTupleInMemory(HnswBuildState * buildstate, HnswElement element) char *base = buildstate->hnswarea; /* Wait if another process needs exclusive lock */ - LWLockAcquire(entryWaitLock, LW_EXCLUSIVE); - LWLockRelease(entryWaitLock); + if (LWLockAcquireOrWait(entryWaitLock, LW_EXCLUSIVE)) + LWLockRelease(entryWaitLock); /* Get entry point */ LWLockAcquire(entryLock, LW_SHARED);