mikemccand commented on a change in pull request #1397: LUCENE-9304: Refactor 
DWPTPool to pool DWPT directly
URL: https://github.com/apache/lucene-solr/pull/1397#discussion_r404796958
 
 

 ##########
 File path: 
lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java
 ##########
 @@ -380,52 +368,35 @@ DocumentsWriterPerThread nextPendingFlush() {
       fullFlush = this.fullFlush;
       numPending = this.numPending;
     }
-    if (numPending > 0 && !fullFlush) { // don't check if we are doing a full 
flush
-      final int limit = perThreadPool.getActiveThreadStateCount();
-      for (int i = 0; i < limit && numPending > 0; i++) {
-        final ThreadState next = perThreadPool.getThreadState(i);
-        if (next.flushPending) {
-          final DocumentsWriterPerThread dwpt = tryCheckoutForFlush(next);
-          if (dwpt != null) {
-            return dwpt;
+    if (numPending > 0 && fullFlush == false) { // don't check if we are doing 
a full flush
+      for (final DocumentsWriterPerThread next : perThreadPool) {
+        if (next.isFlushPending()) {
+          if (next.tryLock()) {
+            try {
+              if (perThreadPool.isRegistered(next)) {
+                return checkOutForFlush(next);
+              }
+            } finally {
+              next.unlock();
 
 Review comment:
   I was just worried that unlocking on return was not intended -- sometimes 
people think `finally` clauses are not executed on `return` ;)
   
   If it is intentional that's great.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to