uschindler 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_r404813760
########## 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 think this should release again. The way of use of finally here is my favourite use of finally. You can make very elegant methods body's with returns and still have finally executed. ---------------------------------------------------------------- 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