dweiss commented on code in PR #12199:
URL: https://github.com/apache/lucene/pull/12199#discussion_r1133753108


##########
lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.java:
##########
@@ -113,15 +113,17 @@ private synchronized DocumentsWriterPerThread newWriter() 
{
    * operation (add/updateDocument).
    */
   DocumentsWriterPerThread getAndLock() {
-    synchronized (this) {
-      ensureOpen();
-      DocumentsWriterPerThread dwpt = 
freeList.poll(DocumentsWriterPerThread::tryLock);
-      if (dwpt == null) {
-        dwpt = newWriter();
-      }
-      // DWPT is already locked before return by this method:
-      return dwpt;
+    ensureOpen();
+    DocumentsWriterPerThread dwpt = 
freeList.poll(DocumentsWriterPerThread::tryLock);
+    if (dwpt == null) {
+      // newWriter() adds the DWPT to the `dwpts` set as a side-effect. 
However it is not added to
+      // `freeList` at this point, it will be added later on once 
DocumentsWriter has indexed a
+      // document into this DWPT and then gives it back to the pool by calling
+      // #marksAsFreeAndUnlock.
+      dwpt = newWriter();

Review Comment:
   Nice, Uwe. Although nobody can ever convince me those optional expressions 
are easier to read and understand than a plain if... :)



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to