huizhilu commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633799505



##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/NetworkUtil.java
##########
@@ -120,7 +120,7 @@ public static String getLocalhostName() {
         try {
             return InetAddress.getLocalHost().getHostName();
         } catch (final UnknownHostException e) {
-            throw new RuntimeException("unable to retrieve localhost name");
+            return "UNKNOWN";

Review comment:
       This static API is not used anywhere else. I don't think it would cause 
rebalance errors. 

##########
File path: 
helix-core/src/main/java/org/apache/helix/api/exceptions/HelixPauseExitsException.java
##########
@@ -0,0 +1,28 @@
+package org.apache.helix.api.exceptions;
+
+/*
+ * 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 org.apache.helix.HelixException;
+
+public class HelixPauseExitsException extends HelixException {
+  public HelixPauseExitsException(String message) {

Review comment:
       To specifically represents the pause signal has already existed. Could 
be used for REST api when determining the response code. We can reject the 
request upon existence or still continue updating the pause znode.

##########
File path: 
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +499,67 @@ public boolean isInMaintenanceMode(String clusterName) {
         .exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
   }
 
+  @Override
+  public void enableClusterPauseMode(String clusterName, boolean 
cancelPendingST, String reason) {
+    logger.info("Enable cluster pause mode for cluster: {}. Cancel pending ST: 
{}. Reason: {}.",
+        clusterName, cancelPendingST, reason);
+
+    PauseSignal pauseSignal = new PauseSignal("pause");
+    pauseSignal.setPauseCluster(Boolean.toString(true));
+    pauseSignal.setCancelPendingST(cancelPendingST);
+    pauseSignal.setFromHost(NetworkUtil.getLocalhostName());
+    pauseSignal.setTriggerTime(Instant.now().toString());
+    if (reason != null && !reason.isEmpty()) {
+      pauseSignal.setReason(reason);
+    }
+
+    BaseDataAccessor<ZNRecord> baseDataAccessor = new 
ZkBaseDataAccessor<>(_zkClient);
+    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, 
baseDataAccessor);
+
+    if (baseDataAccessor.exists(accessor.keyBuilder().pause().getPath(), 
AccessOption.PERSISTENT)) {
+      throw new HelixPauseExitsException(clusterName + " pause signal already 
exits");

Review comment:
       Ah typo... Should be Exists.
   Right, if it already exists, because we have different modes for the PAUSE 
znode, we don't want to overwrite it. So the PauseExistsException tells the 
znode already exists and rejects the request as a clear way.

##########
File path: helix-core/src/main/java/org/apache/helix/HelixAdmin.java
##########
@@ -367,6 +368,41 @@ void manuallyEnableMaintenanceMode(String clusterName, 
boolean enabled, String r
    */
   boolean isInMaintenanceMode(String clusterName);
 
+  /**
+   * Puts a cluster into pause mode, which will pause controller and 
participants.
+   * This can be used to retain the cluster state. When this method returns, 
it means
+   * the pause signal has been successfully sent, but it does not mean the 
cluster has
+   * fully entered pause mode. Because the cluster can take some time to 
finish the pause and
+   * process possible pending state transitions if necessary.
+   * <p>
+   * To check the cluster pause status, call {@link 
#getClusterPauseStatus(String)}.
+   *
+   * @param clusterName Participant cluster name.
+   * @param cancelPendingST whether or not cancel the pending state 
transitions for participants.
+   * @param reason The reason to put the cluster into pause mode.
+   */
+  void enableClusterPauseMode(String clusterName, boolean cancelPendingST, 
String reason);
+
+  /**
+   * Gets cluster pause status {@link ClusterPauseStatus}.
+   *
+   * @param clusterName cluster name.
+   * @return {@link ClusterPauseStatus}
+   */
+  ClusterPauseStatus getClusterPauseStatus(String clusterName);

Review comment:
       I total agree with this direction, which I have thought about, as I 
designed the REST endpoint `PUT /cluster/status`.
   However, I think this is out of scope of this PR as it'd need quite many 
changes including the code in REST. It'd be cleaner to refactor the APIs in 
another PR.




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