Skip to content
Merged
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ Bug Fixes
* GITHUB#15668: Fix UnsupportedOperationException in WeightedSpanTermExtractor by
implementing getFieldInfos in DelegatingLeafReader. (Simranjeet Singh)

* GITHUB#15590: Fix race and improve performance of HNSW graph building (Viliam Durina)

* GITHUB#15702: Fix Potential NullPointException in BytesRefHash initialization#15702 (tyronecai)

* GITHUB#15731: Fix tessellator failure when a hole is touching another hole in the middle of a segment. In this case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.LongAdder;
import org.apache.lucene.internal.hppc.IntArrayList;
import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.ArrayUtil;
Expand Down Expand Up @@ -63,7 +64,7 @@ public final class OnHeapHnswGraph extends HnswGraph implements Accountable {
private int upto;
private NeighborArray cur;

private volatile long graphRamBytesUsed;
private final LongAdder graphRamBytesUsed = new LongAdder();

/**
* ctor
Expand All @@ -83,7 +84,7 @@ public final class OnHeapHnswGraph extends HnswGraph implements Accountable {
numNodes = INIT_SIZE;
}
this.graph = new NeighborArray[numNodes][];
this.graphRamBytesUsed = RAM_BYTES_USED + RamUsageEstimator.shallowSizeOf(graph);
this.graphRamBytesUsed.add(RAM_BYTES_USED + RamUsageEstimator.shallowSizeOf(graph));
}

/**
Expand Down Expand Up @@ -160,27 +161,14 @@ public void addNode(int level, int node) {
graph[node] = ArrayUtil.growExact(graph[node], level + 1);
}

if (level == 0) {
graph[node][level] =
new NeighborArray(
nsize0,
true,
l -> {
assert l > 0;
long bytesUsed = graphRamBytesUsed;
graphRamBytesUsed = bytesUsed + l;
});
} else {
graph[node][level] =
new NeighborArray(
nsize,
true,
l -> {
assert l > 0;
long bytesUsed = graphRamBytesUsed;
graphRamBytesUsed = bytesUsed + l;
});
}
graph[node][level] =
new NeighborArray(
level == 0 ? nsize0 : nsize,
true,
l -> {
assert l > 0;
graphRamBytesUsed.add(l);
});
maxNodeId.accumulateAndGet(node, Math::max);
}

Expand Down Expand Up @@ -289,7 +277,6 @@ public NodesIterator getNodesOnLevel(int level) {
}
}

@SuppressWarnings({"unchecked", "rawtypes"})
private void generateLevelToNodes() {
if (lastFreezeSize == size()) {
return;
Expand Down Expand Up @@ -323,7 +310,7 @@ private void generateLevelToNodes() {
*/
@Override
public long ramBytesUsed() {
return graphRamBytesUsed;
return graphRamBytesUsed.sum();
}

@Override
Expand Down
Loading