s1monw commented on a change in pull request #688: LUCENE-8813: Ensure we never
apply deletes from a closed DWPTDeleteQueue
URL: https://github.com/apache/lucene-solr/pull/688#discussion_r288700001
##########
File path:
lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java
##########
@@ -200,44 +205,74 @@ void tryApplyGlobalSlice() {
}
}
- FrozenBufferedUpdates freezeGlobalBuffer(DeleteSlice callerSlice) throws
IOException {
+
+ FrozenBufferedUpdates freezeGlobalBuffer(DeleteSlice callerSlice) {
globalBufferLock.lock();
- /*
- * Here we freeze the global buffer so we need to lock it, apply all
- * deletes in the queue and reset the global slice to let the GC prune the
- * queue.
- */
- final Node<?> currentTail = tail; // take the current tail make this local
any
- // Changes after this call are applied later
- // and not relevant here
- if (callerSlice != null) {
- // Update the callers slices so we are on the same page
- callerSlice.sliceTail = currentTail;
- }
try {
- if (globalSlice.sliceTail != currentTail) {
- globalSlice.sliceTail = currentTail;
- globalSlice.apply(globalBufferedUpdates, BufferedUpdates.MAX_INT);
+ ensureOpen();
+ /*
+ * Here we freeze the global buffer so we need to lock it, apply all
+ * deletes in the queue and reset the global slice to let the GC prune
the
+ * queue.
+ */
+ final Node<?> currentTail = tail; // take the current tail make this
local any
+ // Changes after this call are applied later
+ // and not relevant here
+ if (callerSlice != null) {
+ // Update the callers slices so we are on the same page
+ callerSlice.sliceTail = currentTail;
}
+ return freezeGlobalBufferInternal(currentTail);
+ } finally {
+ globalBufferLock.unlock();
+ }
+ }
- if (globalBufferedUpdates.any()) {
- final FrozenBufferedUpdates packet = new
FrozenBufferedUpdates(infoStream, globalBufferedUpdates, null);
- globalBufferedUpdates.clear();
- return packet;
+ /**
+ * This may freeze the global buffer unless the delete queue has already
been closed.
+ * If the queue has been closed this method will return <code>null</code>
+ */
+ FrozenBufferedUpdates maybeFreezeGlobalBuffer() {
+ globalBufferLock.lock();
+ try {
+ if (closed == false) {
+ /*
+ * Here we freeze the global buffer so we need to lock it, apply all
+ * deletes in the queue and reset the global slice to let the GC prune
the
+ * queue.
+ */
+ return freezeGlobalBufferInternal(tail); // take the current tail make
this local any
} else {
+ assert anyChanges() == false : "we are closed but have changes";
return null;
}
} finally {
globalBufferLock.unlock();
}
}
+ private FrozenBufferedUpdates freezeGlobalBufferInternal(final Node<?>
currentTail ) {
+ if (globalSlice.sliceTail != currentTail) {
Review comment:
👍
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]