Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-9534: Ensure DWPT#ramBytesUsed is only called unter lock (#1889)

Simon Willnauer208a1c07b06a
diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java
index c35cae4166d..d368e88c323 100644
--- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java
+++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java
@@ -673,7 +673,7 @@ final class DocumentsWriterFlushControl implements Accountable, Closeable {
int count = 0;
for (DocumentsWriterPerThread next : perThreadPool) {
if (next.isFlushPending() == false && next.getNumDocsInRAM() > 0) {
- final long nextRam = next.ramBytesUsed();
+ final long nextRam = next.getLastCommittedBytesUsed();
if (infoStream.isEnabled("FP")) {
infoStream.message("FP", "thread state has " + nextRam + " bytes; docInRAM=" + next.getNumDocsInRAM());
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
index d772a9dac0e..d8ae3754ec0 100644
--- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
+++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
@@ -289,8 +289,8 @@ final class DocumentsWriterPerThread implements Accountable {
assert deleteSlice.isEmpty() : "all deletes must be applied in prepareFlush";
segmentInfo.setMaxDoc(numDocsInRAM);
final SegmentWriteState flushState = new SegmentWriteState(infoStream, directory, segmentInfo, fieldInfos.finish(),
- pendingUpdates, new IOContext(new FlushInfo(numDocsInRAM, ramBytesUsed())));
- final double startMBUsed = ramBytesUsed() / 1024. / 1024.;
+ pendingUpdates, new IOContext(new FlushInfo(numDocsInRAM, lastCommittedBytesUsed)));
+ final double startMBUsed = lastCommittedBytesUsed / 1024. / 1024.;
// Apply delete-by-docID now (delete-byDocID only
// happens when an exception is hit processing that
@@ -496,11 +496,13 @@ final class DocumentsWriterPerThread implements Accountable {
@Override
public long ramBytesUsed() {
+ assert lock.isHeldByCurrentThread();
return (deleteDocIDs.length * Integer.BYTES)+ pendingUpdates.ramBytesUsed() + indexingChain.ramBytesUsed();
}
@Override
public Collection<Accountable> getChildResources() {
+ assert lock.isHeldByCurrentThread();
return List.of(pendingUpdates, indexingChain);
}