You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2020/10/28 21:55:22 UTC

[GitHub] [helix] dasahcc commented on a change in pull request #1489: Refine the HelixTaskExecutor to reduce duplicate code and clarify the code structure.

dasahcc commented on a change in pull request #1489:
URL: https://github.com/apache/helix/pull/1489#discussion_r513783040



##########
File path: helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java
##########
@@ -192,43 +191,38 @@ public void registerMessageHandlerFactory(String type, MessageHandlerFactory fac
   @Override
   public void registerMessageHandlerFactory(String type, MessageHandlerFactory factory,
       int threadpoolSize) {
-    if (factory instanceof  MultiTypeMessageHandlerFactory) {
+    if (factory instanceof MultiTypeMessageHandlerFactory) {
       if (!((MultiTypeMessageHandlerFactory) factory).getMessageTypes().contains(type)) {
         throw new HelixException("Message factory type mismatch. Type: " + type + ", factory: "
             + ((MultiTypeMessageHandlerFactory) factory).getMessageTypes());
       }
     } else {
       if (!factory.getMessageType().equals(type)) {
         throw new HelixException(
-            "Message factory type mismatch. Type: " + type + ", factory: " + factory.getMessageType());
+            "Message factory type mismatch. Type: " + type + ", factory: " + factory
+                .getMessageType());
       }
     }
 
     _isShuttingDown = false;
 
-    MsgHandlerFactoryRegistryItem newItem = new MsgHandlerFactoryRegistryItem(factory, threadpoolSize);
+    MsgHandlerFactoryRegistryItem newItem =
+        new MsgHandlerFactoryRegistryItem(factory, threadpoolSize);
     MsgHandlerFactoryRegistryItem prevItem = _hdlrFtyRegistry.putIfAbsent(type, newItem);
     if (prevItem == null) {
-      ExecutorService newPool = Executors.newFixedThreadPool(threadpoolSize, new ThreadFactory() {
-        @Override public Thread newThread(Runnable r) {
-          return new Thread(r, "HelixTaskExecutor-message_handle_thread_" + thread_uid.getAndIncrement());
-        }
-      });
-      ExecutorService prevExecutor = _executorMap.putIfAbsent(type, newPool);
-      if (prevExecutor != null) {
-        LOG.warn("Skip creating a new thread pool for type: " + type + ", already existing pool: "
-            + prevExecutor + ", isShutdown: " + prevExecutor.isShutdown());
-        newPool.shutdown();
-        newPool = null;
-      } else {
+      _executorMap.computeIfAbsent(type, msgType -> {

Review comment:
       We can use putIfAbsent since we are not using the return value anymore here.

##########
File path: helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java
##########
@@ -997,30 +873,186 @@ public void onMessage(String instanceName, List<Message> messages,
       }
     }
 
-    // update message state to READ in batch and schedule all read messages
+    // update message state to READ in batch and schedule tasks for all read messages
     if (readMsgs.size() > 0) {
       updateMessageState(readMsgs, accessor, instanceName);
 
-      // Remove message if schedule tasks are failed.
       for (Map.Entry<String, MessageHandler> handlerEntry : stateTransitionHandlers.entrySet()) {
         MessageHandler handler = handlerEntry.getValue();
         NotificationContext context = stateTransitionContexts.get(handlerEntry.getKey());
-        Message msg = handler._message;
-        if (!scheduleTask(new HelixTask(msg, context, handler, this))) {
-          removeMessageFromTaskAndFutureMap(msg);
-          removeMessageFromZK(accessor, msg, instanceName);
-        }
+        scheduleTaskForMessage(instanceName, accessor, handler, context);
       }
 
       for (int i = 0; i < nonStateTransitionHandlers.size(); i++) {
         MessageHandler handler = nonStateTransitionHandlers.get(i);
         NotificationContext context = nonStateTransitionContexts.get(i);
-        Message msg = handler._message;
-        if (!scheduleTask(new HelixTask(msg, context, handler, this))) {
-          removeMessageFromTaskAndFutureMap(msg);
-          removeMessageFromZK(accessor, msg, instanceName);
+        scheduleTaskForMessage(instanceName, accessor, handler, context);
+      }
+    }
+  }
+
+  /**
+   * Inspect the message. Report and remove it if no operation needs to be done.
+   * @param message
+   * @param instanceName
+   * @param changeContext
+   * @param manager
+   * @param sessionId
+   * @param stateTransitionHandlers
+   * @return True if the message is no-op message and no other process step is required.
+   */
+  private boolean checkForNoOpMessage(Message message, String instanceName,

Review comment:
       nit: better to name it as isNoOpMessage? The word check could be confusing here.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org