From 4c5c8c4ead74c92b6ab0ec55bca709d36ad152d9 Mon Sep 17 00:00:00 2001 From: Mike Drob Date: Tue, 8 Sep 2020 10:13:18 -0500 Subject: [PATCH] LUCENE-9504 Remove extra lock in DocumentsWriterDeleteQueue (#1826) --- .../index/DocumentsWriterDeleteQueue.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java index cb3db7a0ff7..ab5d657a1b0 100644 --- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java +++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java @@ -509,27 +509,18 @@ final class DocumentsWriterDeleteQueue implements Accountable, Closeable { } } - private boolean forceApplyGlobalSlice() { - globalBufferLock.lock(); - final Node currentTail = tail; + public int getBufferedUpdatesTermsSize() { + final ReentrantLock lock = globalBufferLock; // Trusted final + lock.lock(); try { + final Node currentTail = tail; if (globalSlice.sliceTail != currentTail) { globalSlice.sliceTail = currentTail; globalSlice.apply(globalBufferedUpdates, BufferedUpdates.MAX_INT); } - return globalBufferedUpdates.any(); - } finally { - globalBufferLock.unlock(); - } - } - - public int getBufferedUpdatesTermsSize() { - globalBufferLock.lock(); - try { - forceApplyGlobalSlice(); return globalBufferedUpdates.deleteTerms.size(); } finally { - globalBufferLock.unlock(); + lock.unlock(); } }