zhaih commented on code in PR #13581: URL: https://github.com/apache/lucene/pull/13581#discussion_r1699037448
########## lucene/core/src/java/org/apache/lucene/util/hnsw/HnswGraphBuilder.java: ########## @@ -327,12 +331,14 @@ private void addDiverseNeighbors(int level, int node, NeighborArray candidates) continue; } int nbr = candidates.nodes()[i]; - NeighborArray nbrsOfNbr = hnsw.getNeighbors(level, nbr); - nbrsOfNbr.rwlock.writeLock().lock(); - try { + if (hnswLock != null) { + try (HnswLock.LockedRow rowLock = hnswLock.write(level, nbr)) { + NeighborArray nbrsOfNbr = rowLock.row; Review Comment: Sorry it's better to name it `operateOnNeighbors`. The consumer would pass the actual operation into the method, since I feel it's better to not let the caller deal with the lock at all, so in `HnswGraphBuilder` we should always call ``` operateOnNeighbors(...) ``` and within `OnHeapHnswGraph` ``` operateOnNeighbors(int level, int node, Consumer<NeighborArray> operation, bool read) { if (this.lock != null) { // use RowLock and call operation.accept(nbrArray) } else { operation.accept(getNeighbor(leve, node)); } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org