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 2022/03/14 16:58:24 UTC

[GitHub] [helix] desaikomal commented on a change in pull request #1978: Enable HelixManager as an event listener

desaikomal commented on a change in pull request #1978:
URL: https://github.com/apache/helix/pull/1978#discussion_r826164021



##########
File path: helix-core/src/main/java/org/apache/helix/HelixCloudProperty.java
##########
@@ -180,4 +185,20 @@ public void setCloudRequestTimeout(long cloudRequestTimeout) {
   public void setCustomizedCloudProperties(Properties customizedCloudProperties) {
     _customizedCloudProperties.putAll(customizedCloudProperties);
   }
+
+  public boolean isCloudEventCallbackEnabled() {
+    return _isCloudEventCallbackEnabled;
+  }
+
+  public void enableCloudEventCallback(boolean enabled) {
+    _isCloudEventCallbackEnabled = enabled;
+  }

Review comment:
       +1, set<> would be better naming convention. 

##########
File path: helix-core/src/main/java/org/apache/helix/cloud/event/helix/CloudEventCallbackProperty.java
##########
@@ -0,0 +1,233 @@
+package org.apache.helix.cloud.event.helix;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.BiConsumer;
+
+import org.apache.helix.HelixManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A property for users to customize the behavior of a Helix manager as a cloud event listener
+ * Use this
+ */
+public class CloudEventCallbackProperty {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(CloudEventCallbackProperty.class.getName());
+
+  // The key for user to pass in callback impl class name in the constructor
+  public static final String CALLBACK_IMPL_CLASS_NAME = "callbackImplClassName";
+  private ConcurrentHashMap<OnPauseOperations, BiConsumer<HelixManager, Object>>
+      _onPauseOperationMap;
+  private ConcurrentHashMap<OnResumeOperations, BiConsumer<HelixManager, Object>>
+      _onResumeOperationMap;
+  private String _callbackImplClassName;
+
+  /**
+   * Constructor
+   * @param userArgs A map contains information that users pass in
+   */
+  public CloudEventCallbackProperty(Map<String, String> userArgs) {
+    _callbackImplClassName = userArgs.get(CALLBACK_IMPL_CLASS_NAME);
+    _onPauseOperationMap = new ConcurrentHashMap<>();
+    _onResumeOperationMap = new ConcurrentHashMap<>();
+  }
+
+  /**
+   * A collection of types of optional Helix-supported operations
+   */
+  public enum OptionalHelixOperation {
+    MAINTENANCE_MODE
+  }
+
+  /**
+   * A collection of types and positions for user to plugin customized callback
+   */
+  public enum UserDefinedCallbackType {
+    PRE_ON_PAUSE, POST_ON_PAUSE, PRE_ON_RESUME, POST_ON_RESUME,
+  }
+
+  private enum OnPauseOperations {
+    PRE_ON_PAUSE, MAINTENANCE_MODE, DEFAULT_HELIX_OPERATION, POST_ON_PAUSE
+  }
+
+  private enum OnResumeOperations {
+    PRE_ON_RESUME, DEFAULT_HELIX_OPERATION, MAINTENANCE_MODE, POST_ON_RESUME,
+  }
+
+  /**
+   * Trigger the registered onPause callbacks one by one
+   * Order:
+   * 1. PRE onPause
+   * 2. Helix optional: Maintenance Mode
+   * 3. Helix default
+   * 4. POST onPause
+   * @param helixManager Helix manager to perform operations
+   * @param eventInfo Information of the event provided by upsteam
+   * @param callbackImplClass Implementation class for Helix default and optional operations
+   */
+  public void onPause(HelixManager helixManager, Object eventInfo,
+      AbstractCloudEventCallbackImpl callbackImplClass) {
+    Iterator<OnPauseOperations> iterator = Arrays.stream(OnPauseOperations.values()).iterator();
+    while (iterator.hasNext()) {
+      OnPauseOperations operation = iterator.next();
+      switch (operation) {
+        case DEFAULT_HELIX_OPERATION:
+          callbackImplClass.onPauseDefaultHelixOperation(helixManager, eventInfo);
+          break;
+        case MAINTENANCE_MODE:
+          callbackImplClass.onPauseMaintenanceMode(helixManager, eventInfo);
+          break;
+        default:
+          _onPauseOperationMap.getOrDefault(operation, (manager, info) -> {
+          }).accept(helixManager, eventInfo);

Review comment:
       Not code related but behavior related question: 
   - we will use the main thread for calling all the callbacks and hence if any of the callbacks block, our thread will block, is that what we want?
   - if callback fails, do we still proceed with MM (maintence mode)?
   - have we reasoned through all the failure scenarios ?




-- 
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: reviews-unsubscribe@helix.apache.org

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