diff --git a/src/hnsw.c b/src/hnsw.c index fa08cf5..29a4740 100644 --- a/src/hnsw.c +++ b/src/hnsw.c @@ -17,7 +17,10 @@ #endif int hnsw_ef_search; -int hnsw_lock_tranche_id; +int hnsw_entry_lock_tranche_id; +int hnsw_allocator_lock_tranche_id; +int hnsw_flush_lock_tranche_id; +int hnsw_element_lock_tranche_id; static relopt_kind hnsw_relopt_kind; /* @@ -36,16 +39,27 @@ HnswInitLockTranche(void) bool found; LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); - tranche_ids = ShmemInitStruct("hnsw LWLock ids", - sizeof(int) * 1, + tranche_ids = ShmemInitStruct("hnsw LWLock ids v2", + sizeof(int) * 4, &found); if (!found) + { tranche_ids[0] = LWLockNewTrancheId(); - hnsw_lock_tranche_id = tranche_ids[0]; + tranche_ids[1] = LWLockNewTrancheId(); + tranche_ids[2] = LWLockNewTrancheId(); + tranche_ids[3] = LWLockNewTrancheId(); + } + hnsw_entry_lock_tranche_id = tranche_ids[0]; + hnsw_allocator_lock_tranche_id = tranche_ids[1]; + hnsw_flush_lock_tranche_id = tranche_ids[2]; + hnsw_element_lock_tranche_id = tranche_ids[3]; LWLockRelease(AddinShmemInitLock); /* Per-backend registration of the tranche ID */ - LWLockRegisterTranche(hnsw_lock_tranche_id, "HnswBuild"); + LWLockRegisterTranche(hnsw_entry_lock_tranche_id, "HnswEntry"); + LWLockRegisterTranche(hnsw_allocator_lock_tranche_id, "HnswAllocator"); + LWLockRegisterTranche(hnsw_flush_lock_tranche_id, "HnswFlush"); + LWLockRegisterTranche(hnsw_element_lock_tranche_id, "HnswElement"); } /* diff --git a/src/hnsw.h b/src/hnsw.h index 7d2ae19..39cbeb5 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -113,7 +113,10 @@ /* Variables */ extern int hnsw_ef_search; -extern int hnsw_lock_tranche_id; +extern int hnsw_entry_lock_tranche_id; +extern int hnsw_allocator_lock_tranche_id; +extern int hnsw_flush_lock_tranche_id; +extern int hnsw_element_lock_tranche_id; typedef struct HnswElementData HnswElementData; typedef struct HnswNeighborArray HnswNeighborArray; diff --git a/src/hnswbuild.c b/src/hnswbuild.c index 1a2a96c..a500905 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -548,7 +548,7 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heaptid, Hn HnswPtrStore(base, element->value, valuePtr); /* Create a lock for the element */ - LWLockInitialize(&element->lock, hnsw_lock_tranche_id); + LWLockInitialize(&element->lock, hnsw_element_lock_tranche_id); /* Insert tuple */ InsertTupleInMemory(buildstate, element); @@ -611,9 +611,9 @@ InitGraph(HnswGraph * graph, char *base, long memoryTotal) graph->flushed = false; graph->indtuples = 0; SpinLockInit(&graph->lock); - LWLockInitialize(&graph->entryLock, hnsw_lock_tranche_id); - LWLockInitialize(&graph->allocatorLock, hnsw_lock_tranche_id); - LWLockInitialize(&graph->flushLock, hnsw_lock_tranche_id); + LWLockInitialize(&graph->entryLock, hnsw_entry_lock_tranche_id); + LWLockInitialize(&graph->allocatorLock, hnsw_allocator_lock_tranche_id); + LWLockInitialize(&graph->flushLock, hnsw_flush_lock_tranche_id); } /*