benwtrent commented on code in PR #13124:
URL: https://github.com/apache/lucene/pull/13124#discussion_r1502165014


##########
lucene/core/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java:
##########
@@ -910,4 +936,58 @@ public void setSuppressExceptions(ConcurrentMergeScheduler 
cms) {
           }
         });
   }
+
+  private class ScaledExecutor extends ThreadPoolExecutor {
+
+    AtomicInteger activeCount = new AtomicInteger(0);
+
+    public ScaledExecutor() {
+      super(
+          Math.max(0, maxThreadCount - 1),
+          Math.max(1, maxThreadCount - 1),
+          Long.MAX_VALUE,
+          TimeUnit.NANOSECONDS,
+          new SynchronousQueue<>());
+    }
+
+    private void updatePoolSize() {
+      int newMax = Math.max(0, maxThreadCount - 1);
+      if (newMax > getCorePoolSize()) {
+        setMaximumPoolSize(Math.max(newMax, 1));
+        setCorePoolSize(newMax);
+      } else {
+        setCorePoolSize(newMax);
+        setMaximumPoolSize(Math.max(newMax, 1));
+      }
+    }
+
+    boolean incrementUpTo(int max) {
+      while (true) {
+        int value = activeCount.get();
+        if (value >= max) {
+          return false;
+        }
+        if (activeCount.compareAndSet(value, value + 1)) {
+          return true;
+        }

Review Comment:
   @jpountz you are correct, my logic here isn't what it needs to be. I will 
fix it up.



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to