adoroszlai commented on code in PR #9387:
URL: https://github.com/apache/ozone/pull/9387#discussion_r2569482646


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/HddsServerUtil.java:
##########
@@ -730,4 +732,26 @@ private static String createStartupMessage(VersionInfo 
versionInfo,
         "       conf = " + conf);
   }
 
+  public static void setPoolSize(ThreadPoolExecutor executor, int size, Logger 
logger) {
+    Preconditions.assertTrue(size > 0, () -> "Pool size must be positive: " + 
size);
+
+    int currentCorePoolSize = executor.getCorePoolSize();
+
+    // In ThreadPoolExecutor, maximumPoolSize must always be greater than or
+    // equal to the corePoolSize. We must make sure this invariant holds when
+    // changing the pool size. Therefore, we take into account whether the
+    // new size is greater or smaller than the current core pool size.
+    String change = "unchanged";
+    if (size > currentCorePoolSize) {
+      change = "increased";
+      executor.setMaximumPoolSize(size);
+      executor.setCorePoolSize(size);
+    } else if (size < currentCorePoolSize) {
+      change = "decreased";
+      executor.setCorePoolSize(size);
+      executor.setMaximumPoolSize(size);
+    }
+    LOG.info("{} pool size {} from {} to {}", logger.getName(), change, 
currentCorePoolSize, size);

Review Comment:
   @ivandika3 thanks for the review.  I just noticed that here message is 
accidentally logged with `HddsServerUtil.LOG`.  Should I change it to `logger`? 
 With that, output would become:
   
   ```
   INFO  replication.ReplicationServer (HddsServerUtil.java:setPoolSize(755)) - 
org.apache.hadoop.ozone.container.replication.ReplicationServer pool size 
decreased from 10 to 9
   INFO  replication.ReplicationServer (HddsServerUtil.java:setPoolSize(755)) - 
org.apache.hadoop.ozone.container.replication.ReplicationServer pool size 
increased from 9 to 10
   INFO  commandhandler.DeleteBlocksCommandHandler 
(HddsServerUtil.java:setPoolSize(755)) - 
org.apache.hadoop.ozone.container.common.statemachine.commandhandler.DeleteBlocksCommandHandler
 pool size decreased from 5 to 4
   INFO  commandhandler.DeleteBlocksCommandHandler 
(HddsServerUtil.java:setPoolSize(755)) - 
org.apache.hadoop.ozone.container.common.statemachine.commandhandler.DeleteBlocksCommandHandler
 pool size increased from 4 to 5
   ```
   
   and we can even remove `logger.getName()`, since it includes it by default:
   
   ```
   INFO  replication.ReplicationServer (HddsServerUtil.java:setPoolSize(755)) - 
pool size decreased from 10 to 9
   INFO  replication.ReplicationServer (HddsServerUtil.java:setPoolSize(755)) - 
pool size increased from 9 to 10
   INFO  commandhandler.DeleteBlocksCommandHandler 
(HddsServerUtil.java:setPoolSize(755)) - pool size decreased from 5 to 4
   INFO  commandhandler.DeleteBlocksCommandHandler 
(HddsServerUtil.java:setPoolSize(755)) - pool size increased from 4 to 5
   ```
   
   Let me know which one you prefer.



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