Fix potential race condition in DocumentsWriter & DocumentsWriterDeleteQueue (#13169)

* Fix potential race condition in DocumentsWriter & DocumentsWriterDeleteQueue

* add changes
This commit is contained in:
Benjamin Trent 2024-03-12 07:50:04 -04:00 committed by GitHub
parent 44fa35b65f
commit b527e101e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 5 deletions

View File

@ -232,6 +232,8 @@ Bug Fixes
* GITHUB#13162: Fix NPE when LeafReader return null VectorValues (Pan Guixin)
* GITHUB#13169: Fix potential race condition in DocumentsWriter & DocumentsWriterDeleteQueue (Ben Trent)
Other
---------------------

View File

@ -540,13 +540,16 @@ final class DocumentsWriter implements Closeable, Accountable {
return deleteQueue.getNextSequenceNumber();
}
synchronized void resetDeleteQueue(DocumentsWriterDeleteQueue newQueue) {
synchronized long resetDeleteQueue(int maxNumPendingOps) {
final DocumentsWriterDeleteQueue newQueue = deleteQueue.advanceQueue(maxNumPendingOps);
assert deleteQueue.isAdvanced();
assert newQueue.isAdvanced() == false;
assert deleteQueue.getLastSequenceNumber() <= newQueue.getLastSequenceNumber();
assert deleteQueue.getMaxSeqNo() <= newQueue.getLastSequenceNumber()
: "maxSeqNo: " + deleteQueue.getMaxSeqNo() + " vs. " + newQueue.getLastSequenceNumber();
long oldMaxSeqNo = deleteQueue.getMaxSeqNo();
deleteQueue = newQueue;
return oldMaxSeqNo;
}
interface FlushNotifications { // TODO maybe we find a better name for this?

View File

@ -570,10 +570,7 @@ final class DocumentsWriterFlushControl implements Accountable, Closeable {
// Insert a gap in seqNo of current active thread count, in the worst case each of those
// threads now have one operation in flight. It's fine
// if we have some sequence numbers that were never assigned:
DocumentsWriterDeleteQueue newQueue =
documentsWriter.deleteQueue.advanceQueue(perThreadPool.size());
seqNo = documentsWriter.deleteQueue.getMaxSeqNo();
documentsWriter.resetDeleteQueue(newQueue);
seqNo = documentsWriter.resetDeleteQueue(perThreadPool.size());
} finally {
perThreadPool.unlockNewWriters();
}