NealSun96 commented on a change in pull request #973:
URL: https://github.com/apache/helix/pull/973#discussion_r416964720



##########
File path: 
helix-core/src/main/java/org/apache/helix/task/TaskStateModelFactory.java
##########
@@ -102,4 +107,40 @@ public boolean isShutdown() {
   public boolean isTerminated() {
     return _taskExecutor.isTerminated();
   }
+
+  /*
+   * Get target thread pool size from InstanceConfig first; if that fails, get 
it from
+   * ClusterConfig; if that fails, fall back to the default value.
+   */
+  private static int _getTaskThreadPoolSize(HelixManager manager) {
+    ConfigAccessor configAccessor = manager.getConfigAccessor();
+    // Check instance config first for thread pool size
+    try {
+      InstanceConfig instanceConfig =
+          configAccessor.getInstanceConfig(manager.getClusterName(), 
manager.getInstanceName());
+      int targetTaskThreadPoolSize = 
instanceConfig.getTargetTaskThreadPoolSize();
+      if (_verifyTargetThreadPoolSize(targetTaskThreadPoolSize)) {
+        return targetTaskThreadPoolSize;
+      }
+    } catch (HelixException e) {
+      // Pass if InstanceConfig doesn't exist.
+    }
+
+    // Fallback to cluster config since instance config doesn't provide the 
value
+    try {
+      ClusterConfig clusterConfig = 
configAccessor.getClusterConfig(manager.getClusterName());
+      int targetTaskThreadPoolSize = 
clusterConfig.getTargetTaskThreadPoolSize();
+      if (_verifyTargetThreadPoolSize(targetTaskThreadPoolSize)) {
+        return targetTaskThreadPoolSize;
+      }
+    } catch (HelixException e) {
+      // Pass if ClusterConfig doesn't exist.
+    }
+
+    return DEFAULT_TASK_THREAD_POOL_SIZE;
+  }
+
+  private static boolean _verifyTargetThreadPoolSize(int 
targetTaskThreadPoolSize) {

Review comment:
       This is to check against the default value: when the target thread pool 
size is not specified in the configs, a -1 is returned from 
`getTargetTaskThreadPoolSize()`. This check makes sure the default value is 
filtered out. 
   
   I don't see any other good way to do `getIntField()` while handling the "not 
defined" case differently, since `getIntField()` always asks for a default 
value; if `getIntField()` throws an exception when the value is not defined 
it's much cleaner. This is the best solution I came up with while using 
`getIntField()`.




----------------------------------------------------------------
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:
[email protected]



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

Reply via email to