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 2021/05/16 03:14:41 UTC
[GitHub] [helix] huizhilu opened a new pull request #1740: Add java api for enable/disable cluster pause mode
huizhilu opened a new pull request #1740:
URL: https://github.com/apache/helix/pull/1740
### Issues
- [ ] My PR addresses the following Helix issues and references them in the PR description:
Resolves #1739
### Description
- [ ] Here are some details about my PR, including screenshots of any UI changes:
The existing controller pause mode does not apply to participants. We need a new feature (cluster pause mode) to pause both controller and participant. APIs are needed to enable/disable cluster pause mode.
This PR adds 2 java APIs to HelixAdmin
```
enableClusterPauseMode()
disableClusterPauseMode()
```
### Tests
- [ ] The following tests are written for this issue:
`testEnableDisableClusterPauseMode`
- The following is the result of the "mvn test" command on the appropriate module:
Running...
### Changes that Break Backward Compatibility (Optional)
- My PR contains changes that break backward compatibility or previous assumptions for certain methods or API. They include:
(Consider including all behavior changes for public methods or API. Also include these changes in merge description so that other developers are aware of these changes. This allows them to make relevant code changes in feature branches accounting for the new method/API behavior.)
### Documentation (Optional)
- In case of new functionality, my PR adds documentation in the following wiki page:
(Link the GitHub wiki you added)
### Commits
- My commits all reference appropriate Apache Helix GitHub issues in their subject lines. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
1. Subject is separated from body by a blank line
1. Subject is limited to 50 characters (not including Jira issue reference)
1. Subject does not end with a period
1. Subject uses the imperative mood ("add", not "adding")
1. Body wraps at 72 characters
1. Body explains "what" and "why", not "how"
### Code Quality
- My diff has been formatted using helix-style.xml
(helix-style-intellij.xml if IntelliJ IDE is used)
--
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
[GitHub] [helix] huizhilu commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r634814610
##########
File path: helix-core/src/main/java/org/apache/helix/model/management/ClusterManagementMode.java
##########
@@ -0,0 +1,70 @@
+package org.apache.helix.model.management;
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents the management mode of the cluster:
+ * 1. what type of mode it targets to be;
+ * 2. what progress status it is now.
+ */
+public class ClusterManagementMode {
Review comment:
As discussed, this is not doable with enum. Let's keep the current design.
--
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
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r635625189
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -130,6 +140,22 @@ public void setHelixVersion(String helixVersion) {
_record.setSimpleField(LiveInstanceProperty.HELIX_VERSION.toString(), helixVersion);
}
+ /**
+ * Gets the live instance's status.
Review comment:
nit, please comment about the return value, it would be null if there is no status specified.
--
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
[GitHub] [helix] junkaixue commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
junkaixue commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633037624
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,20 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents {@link LiveInstanceStatus} */
+ STATUS
+ }
+
+ /**
+ * Represents status of a live instance, eg. PAUSED.
+ */
+ public enum LiveInstanceStatus {
+ NORMAL,
+ PAUSED,
+ ENTERING_PAUSE,
+ EXITING_PAUSE
Review comment:
I dont think we need this. This can be derived as the pausing message is pending there and not removed with status not in PAUSED.
This kind of status is more like in Cluster Pause Status. Instance level is not necessary.
##########
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);
+
+ /**
+ * Gets a cluster out of pause mode. When this method returns, it means
+ * the resume signal has been successfully sent, but it does not mean the cluster has
+ * fully exited pause mode.
+ * <p>
+ * To check whether the cluster has fully exited pause mode, call
+ * {@link #getClusterPauseStatus(String)}.
+ *
+ * @param clusterName Cluster name.
+ */
+ void disableClusterPauseMode(String clusterName);
Review comment:
Why we need two APIs? enableClusterPauseMode can add an argument with enabled to be true or false. It follows our convention.
You can have private function to support enable/disable separately. But they can share the same API.
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,20 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents {@link LiveInstanceStatus} */
+ STATUS
+ }
+
+ /**
+ * Represents status of a live instance, eg. PAUSED.
+ */
+ public enum LiveInstanceStatus {
+ NORMAL,
Review comment:
We do not need a explicit NORMAL for status. We can just remove the entry as the normal status for backward compatible.
##########
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");
Review comment:
NIT: we should not hard code it.
##########
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());
Review comment:
Question: why not use System.currenttimemillis
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -28,7 +28,11 @@
public class PauseSignal extends HelixProperty {
public enum PauseSignalProperty {
- REASON
+ REASON,
+ PAUSE_CLUSTER,
Review comment:
Question: I am not quite sure what do you mean the PAUSE_CLUSTER? Can you elaborate more on each of the entry. FROM_HOST is something I am not clear as well.
Also do we need to explicitly put CANCEL_PENDING_ST or not. We can just make cluster status as PAUSING/EXITING something.
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -28,7 +28,11 @@
public class PauseSignal extends HelixProperty {
public enum PauseSignalProperty {
Review comment:
I would suggest not mess up with Cluster Status and Action you would like to perform. Better to have two enums to hold them separately. One for user command one for cluster status.
--
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
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r635610464
##########
File path: helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,72 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(), reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the api accordingly.
+ // If we put all mode config in one znode, one generic method is good enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + " not supported");
Review comment:
???
--
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
[GitHub] [helix] huizhilu commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
huizhilu commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633039726
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -28,7 +28,11 @@
public class PauseSignal extends HelixProperty {
public enum PauseSignalProperty {
Review comment:
We don't want to put cluster status into the PAUSE znode. The PAUSE znode is only created/updated by users. Controller does not write any cluster status to it.
The PAUSE znode will be deleted by controller after cluster fully exits.
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,20 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents {@link LiveInstanceStatus} */
+ STATUS
+ }
+
+ /**
+ * Represents status of a live instance, eg. PAUSED.
+ */
+ public enum LiveInstanceStatus {
+ NORMAL,
Review comment:
Yeah that's correct. I've thought about it. It is put there to help in the return of java/rest api. If the cluster has fully exited pause, what will the query result look like? "NORMAL" is helping with it. I just wanted to make it as a constant instead of hardcoding in the API.
##########
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");
Review comment:
It's the same as the other API: `disableCluster()`...
Will put "pause" as a default pause id in `PauseSignal`
##########
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);
+
+ /**
+ * Gets a cluster out of pause mode. When this method returns, it means
+ * the resume signal has been successfully sent, but it does not mean the cluster has
+ * fully exited pause mode.
+ * <p>
+ * To check whether the cluster has fully exited pause mode, call
+ * {@link #getClusterPauseStatus(String)}.
+ *
+ * @param clusterName Cluster name.
+ */
+ void disableClusterPauseMode(String clusterName);
Review comment:
I understand there are many similar APIs in Helix. However, to me, passing boolean parameters to differentiate the behaviors is really a code smell. Ref: https://softwareengineering.stackexchange.com/questions/208224/is-it-better-to-have-one-method-that-takes-a-bool-as-a-parameter-or-two-methods
I would try to avoid that. So I prefer two methods.
##########
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());
Review comment:
`Instant.now()` gives a human readable format at UTC zone. The epoch timestamp really does not help being written to znode, because we usually will directly read the znode. So a readable format will really help.
The trade-off is also added to the design doc.
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -28,7 +28,11 @@
public class PauseSignal extends HelixProperty {
public enum PauseSignalProperty {
- REASON
+ REASON,
+ PAUSE_CLUSTER,
Review comment:
These fields are representing the user's action. It'd be a record to help tracking and debugging.
PAUSE_CLUSTER: whether enable/disable pause mode
FROM_HOST: where the pause signal is sent from, eg. Helix REST or a user's laptop that directly calls java api.
CANCEL_PENDING_ST: whether to cancel pending st. Controller will read this field to determine to send cancel messages.
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,20 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents {@link LiveInstanceStatus} */
+ STATUS
+ }
+
+ /**
+ * Represents status of a live instance, eg. PAUSED.
+ */
+ public enum LiveInstanceStatus {
+ NORMAL,
+ PAUSED,
+ ENTERING_PAUSE,
+ EXITING_PAUSE
Review comment:
Yes it could be derived. But do we want to hard code those status in the API? I thought about it. I think it's cleaner to define the status here in live instance, which could be used for controller and participant.
When exiting pause, once controller receives the exit notification, the controller status will marked as "EXITING_PAUSE" in LEADER.
So I think this enum will help.
--
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
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r634791356
##########
File path: helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,77 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(), reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the api accordingly.
+ // If we put all mode config in one znode, one generic method is good enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + " not supported");
+ }
+ }
+
+ private void enableClusterPauseMode(String clusterName, boolean cancelPendingST, String reason) {
+ String hostname = NetworkUtil.getLocalhostName();
+ logger.info(
+ "Enable cluster pause mode for cluster: {}. CancelPendingST: {}. Reason: {}. From Host: {}",
+ clusterName, cancelPendingST, reason, hostname);
+
+ BaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<>(_zkClient);
+ HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseDataAccessor);
+
+ if (baseDataAccessor.exists(accessor.keyBuilder().pause().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " pause signal already exits");
+ }
+ if (baseDataAccessor.exists(accessor.keyBuilder().maintenance().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " maintenance signal already exits");
+ }
+
+ PauseSignal pauseSignal = new PauseSignal();
+ pauseSignal.setPauseCluster(Boolean.toString(true));
Review comment:
nit, Can we make it in the constructor parameter to avoid possible misusage?
Ultimately, it would be great if we have a super class for all signals. And the 3 modes are child classes.
Then on set, directly create child class objects.
On read, the super class can have a static method to convert into the child class according to the internal mode field.
This would help to avoid possible misusage and duplicate code.
##########
File path: helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,77 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(), reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the api accordingly.
+ // If we put all mode config in one znode, one generic method is good enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + " not supported");
+ }
+ }
+
+ private void enableClusterPauseMode(String clusterName, boolean cancelPendingST, String reason) {
+ String hostname = NetworkUtil.getLocalhostName();
+ logger.info(
+ "Enable cluster pause mode for cluster: {}. CancelPendingST: {}. Reason: {}. From Host: {}",
+ clusterName, cancelPendingST, reason, hostname);
+
+ BaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<>(_zkClient);
+ HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseDataAccessor);
+
+ if (baseDataAccessor.exists(accessor.keyBuilder().pause().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " pause signal already exits");
+ }
+ if (baseDataAccessor.exists(accessor.keyBuilder().maintenance().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " maintenance signal already exits");
+ }
+
+ PauseSignal pauseSignal = new PauseSignal();
+ pauseSignal.setPauseCluster(Boolean.toString(true));
+ pauseSignal.setCancelPendingST(cancelPendingST);
+ pauseSignal.setFromHost(hostname);
+ pauseSignal.setTriggerTime(Instant.now().toString());
+ if (reason != null && !reason.isEmpty()) {
+ pauseSignal.setReason(reason);
+ }
+ if (!accessor.createPause(pauseSignal)) {
Review comment:
There could be a race condition between maintenance node creating and pause node creating. But it cannot be resolved easily since they are different paths. Let's add a TODO here that, once we merge the status signal nodes into one path, then there won't be any more race conditions.
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -130,6 +135,22 @@ public void setHelixVersion(String helixVersion) {
_record.setSimpleField(LiveInstanceProperty.HELIX_VERSION.toString(), helixVersion);
}
+ /**
+ * Gets the live instance's status.
+ */
+ public String getStatus() {
+ return _record.getSimpleField(LiveInstanceProperty.STATUS.name());
+ }
+
+ /**
+ * Sets the status in simple field.
+ *
+ * @param status status value
+ */
+ public void setStatus(String status) {
Review comment:
Accepts enum?
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -63,4 +72,36 @@ public String getReason() {
public boolean isValid() {
return true;
}
+
+ public void setPauseCluster(String pause) {
+ _record.setSimpleField(PauseSignalProperty.CLUSTER_PAUSE.name(), pause);
+ }
+
+ public String getPauseCluster() {
Review comment:
Same here, return boolean, please.
##########
File path: helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,77 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(), reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the api accordingly.
+ // If we put all mode config in one znode, one generic method is good enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + " not supported");
+ }
+ }
+
+ private void enableClusterPauseMode(String clusterName, boolean cancelPendingST, String reason) {
+ String hostname = NetworkUtil.getLocalhostName();
+ logger.info(
+ "Enable cluster pause mode for cluster: {}. CancelPendingST: {}. Reason: {}. From Host: {}",
+ clusterName, cancelPendingST, reason, hostname);
+
+ BaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<>(_zkClient);
+ HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseDataAccessor);
+
+ if (baseDataAccessor.exists(accessor.keyBuilder().pause().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " pause signal already exits");
+ }
+ if (baseDataAccessor.exists(accessor.keyBuilder().maintenance().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " maintenance signal already exits");
+ }
+
+ PauseSignal pauseSignal = new PauseSignal();
+ pauseSignal.setPauseCluster(Boolean.toString(true));
+ pauseSignal.setCancelPendingST(cancelPendingST);
+ pauseSignal.setFromHost(hostname);
+ pauseSignal.setTriggerTime(Instant.now().toString());
+ if (reason != null && !reason.isEmpty()) {
+ pauseSignal.setReason(reason);
+ }
+ if (!accessor.createPause(pauseSignal)) {
+ throw new HelixException("Failed to create pause signal");
+ }
+ }
+
+ private void disableClusterPauseMode(String clusterName) {
+ logger.info("Disable cluster pause mode for cluster: {}", clusterName);
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_zkClient));
+ PropertyKey pausePropertyKey = accessor.keyBuilder().pause();
+ PauseSignal pauseSignal = accessor.getProperty(pausePropertyKey);
+ if (pauseSignal == null || pauseSignal.getPauseCluster() == null) {
Review comment:
getPauseCluster == false? or !isPauseCluster() ?
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -63,4 +72,36 @@ public String getReason() {
public boolean isValid() {
return true;
}
+
+ public void setPauseCluster(String pause) {
+ _record.setSimpleField(PauseSignalProperty.CLUSTER_PAUSE.name(), pause);
+ }
+
+ public String getPauseCluster() {
+ return _record.getSimpleField(PauseSignalProperty.CLUSTER_PAUSE.name());
+ }
+
+ public void setFromHost(String host) {
+ _record.setSimpleField(PauseSignalProperty.FROM_HOST.name(), host);
+ }
+
+ public String getFromHost() {
+ return _record.getSimpleField(PauseSignalProperty.FROM_HOST.name());
+ }
+
+ public void setCancelPendingST(boolean cancel) {
+ _record.setBooleanField(PauseSignalProperty.CANCEL_PENDING_ST.name(), cancel);
+ }
+
+ public boolean getCancelPendingST() {
+ return _record.getBooleanField(PauseSignalProperty.CANCEL_PENDING_ST.name(), false);
+ }
+
+ public void setTriggerTime(String time) {
Review comment:
I suggest taking a long type as the input. This will help to avoid misusage.
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -63,4 +72,36 @@ public String getReason() {
public boolean isValid() {
return true;
}
+
+ public void setPauseCluster(String pause) {
Review comment:
What is this (╯°Д°)╯ ┻━┻
Why not directly passing boolean in? Do you support other pause String? Like setPauseCluster("Foobar") ???
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -52,6 +55,8 @@
private static final Logger _logger = LoggerFactory.getLogger(LiveInstance.class.getName());
+ public static final String PAUSED_STATUS = "PAUSED";
Review comment:
enum?
##########
File path: helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,77 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(), reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the api accordingly.
+ // If we put all mode config in one znode, one generic method is good enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + " not supported");
+ }
+ }
+
+ private void enableClusterPauseMode(String clusterName, boolean cancelPendingST, String reason) {
+ String hostname = NetworkUtil.getLocalhostName();
+ logger.info(
+ "Enable cluster pause mode for cluster: {}. CancelPendingST: {}. Reason: {}. From Host: {}",
+ clusterName, cancelPendingST, reason, hostname);
+
+ BaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<>(_zkClient);
+ HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseDataAccessor);
+
+ if (baseDataAccessor.exists(accessor.keyBuilder().pause().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " pause signal already exits");
+ }
+ if (baseDataAccessor.exists(accessor.keyBuilder().maintenance().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " maintenance signal already exits");
+ }
+
+ PauseSignal pauseSignal = new PauseSignal();
+ pauseSignal.setPauseCluster(Boolean.toString(true));
+ pauseSignal.setCancelPendingST(cancelPendingST);
+ pauseSignal.setFromHost(hostname);
+ pauseSignal.setTriggerTime(Instant.now().toString());
+ if (reason != null && !reason.isEmpty()) {
+ pauseSignal.setReason(reason);
+ }
+ if (!accessor.createPause(pauseSignal)) {
+ throw new HelixException("Failed to create pause signal");
+ }
+ }
+
+ private void disableClusterPauseMode(String clusterName) {
+ logger.info("Disable cluster pause mode for cluster: {}", clusterName);
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_zkClient));
+ PropertyKey pausePropertyKey = accessor.keyBuilder().pause();
+ PauseSignal pauseSignal = accessor.getProperty(pausePropertyKey);
+ if (pauseSignal == null || pauseSignal.getPauseCluster() == null) {
+ throw new HelixException("Cluster pause mode is not enabled for cluster " + clusterName);
+ }
+
+ if (!accessor.removeProperty(pausePropertyKey)) {
+ throw new HelixException("Failed to disable cluster pause mode for cluster: " + clusterName);
+ }
+ }
+
+ @Override
+ public ClusterManagementMode getClusterManagementMode(String clusterName) {
+ // TODO: implement logic
+ return null;
Review comment:
If you are not adding this implementation, please delay the API into the next PR too.
##########
File path: helix-core/src/main/java/org/apache/helix/model/management/ClusterManagementMode.java
##########
@@ -0,0 +1,70 @@
+package org.apache.helix.model.management;
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents the management mode of the cluster:
+ * 1. what type of mode it targets to be;
+ * 2. what progress status it is now.
+ */
+public class ClusterManagementMode {
Review comment:
You can just make this class enum and list all the possible mode,
NORMAL()
CLUSTER_PAUSE(Status status) // inprogress or completed
CONTROLLER_PAUSE()
MAINTENANCE()
Then you don't need to face a Maintenance mode object with inprogress status. Which does not make sense.
--
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
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r635515263
##########
File path: helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,72 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(), reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the api accordingly.
+ // If we put all mode config in one znode, one generic method is good enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + " not supported");
Review comment:
nit "is not supported"?
##########
File path: helix-core/src/main/java/org/apache/helix/HelixAdmin.java
##########
@@ -37,6 +37,8 @@
import org.apache.helix.model.MaintenanceSignal;
import org.apache.helix.model.ResourceConfig;
import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.api.status.ClusterManagementMode;
+import org.apache.helix.model.management.ClusterManagementModeRequest;
Review comment:
ClusterManagementModeRequest should go to org.apache.helix.api.status too.
Or maybe we should make both of them in org.apache.helix.**model**.status? @junkaixue any opinion about the allocation of these 2 classes?
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -130,6 +140,22 @@ public void setHelixVersion(String helixVersion) {
_record.setSimpleField(LiveInstanceProperty.HELIX_VERSION.toString(), helixVersion);
}
+ /**
+ * Gets the live instance's status.
+ */
+ public String getStatus() {
Review comment:
Return LiveInstanceStatus object?
##########
File path: helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,72 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(), reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the api accordingly.
+ // If we put all mode config in one znode, one generic method is good enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + " not supported");
+ }
+ }
+
+ private void enableClusterPauseMode(String clusterName, boolean cancelPendingST, String reason) {
+ String hostname = NetworkUtil.getLocalhostName();
+ logger.info(
+ "Enable cluster pause mode for cluster: {}. CancelPendingST: {}. Reason: {}. From Host: {}",
+ clusterName, cancelPendingST, reason, hostname);
+
+ BaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<>(_zkClient);
+ HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseDataAccessor);
+
+ if (baseDataAccessor.exists(accessor.keyBuilder().pause().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " pause signal already exits");
Review comment:
nit, but please double-check all the spelling. exits -> exists.
##########
File path: helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,72 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(), reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the api accordingly.
+ // If we put all mode config in one znode, one generic method is good enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + " not supported");
+ }
+ }
+
+ private void enableClusterPauseMode(String clusterName, boolean cancelPendingST, String reason) {
+ String hostname = NetworkUtil.getLocalhostName();
+ logger.info(
+ "Enable cluster pause mode for cluster: {}. CancelPendingST: {}. Reason: {}. From Host: {}",
+ clusterName, cancelPendingST, reason, hostname);
+
+ BaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<>(_zkClient);
+ HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseDataAccessor);
+
+ if (baseDataAccessor.exists(accessor.keyBuilder().pause().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " pause signal already exits");
+ }
+ if (baseDataAccessor.exists(accessor.keyBuilder().maintenance().getPath(), AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " maintenance signal already exits");
Review comment:
exits -> exists
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -63,4 +74,33 @@ public String getReason() {
public boolean isValid() {
return true;
}
+
+ public void setClusterPause(boolean pause) {
+ _record.setBooleanField(PauseSignalProperty.CLUSTER_PAUSE.name(), pause);
+ }
+
+ public boolean isClusterPause() {
+ return _record.getBooleanField(PauseSignalProperty.CLUSTER_PAUSE.name(), false);
+ }
+
+ public void setFromHost(String host) {
+ _record.setSimpleField(PauseSignalProperty.FROM_HOST.name(), host);
+ }
+
+ public String getFromHost() {
+ return _record.getSimpleField(PauseSignalProperty.FROM_HOST.name());
+ }
+
+ public void setCancelPendingST(boolean cancel) {
+ _record.setBooleanField(PauseSignalProperty.CANCEL_PENDING_ST.name(), cancel);
+ }
+
+ public boolean getCancelPendingST() {
+ return _record.getBooleanField(PauseSignalProperty.CANCEL_PENDING_ST.name(), false);
Review comment:
Question, I am thinking that shall we default cancel the pending ST?
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,17 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents the status of live instance, eg. PAUSED */
+ STATUS
+ }
+
+ /**
+ * Saved values for the {@link LiveInstanceProperty#STATUS} field
+ */
+ public enum LiveInstanceStatus {
+ PAUSED
Review comment:
Question, do we need NORMAL here too?
--
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
[GitHub] [helix] huizhilu commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
huizhilu commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r635534075
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,17 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents the status of live instance, eg. PAUSED */
+ STATUS
+ }
+
+ /**
+ * Saved values for the {@link LiveInstanceProperty#STATUS} field
+ */
+ public enum LiveInstanceStatus {
+ PAUSED
Review comment:
No. For backward compatibility, the status field in live instance will be removed once it goes back to NORMAL.
--
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
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r635604654
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -130,6 +140,22 @@ public void setHelixVersion(String helixVersion) {
_record.setSimpleField(LiveInstanceProperty.HELIX_VERSION.toString(), helixVersion);
}
+ /**
+ * Gets the live instance's status.
+ */
+ public LiveInstanceStatus getStatus() {
+ return LiveInstanceStatus.valueOf(_record.getSimpleField(LiveInstanceProperty.STATUS.name()));
Review comment:
As you said, "For backward compatibility, the status field in live instance will be removed once it goes back to NORMAL.", this method will throw NPE under normal status. I guess your current test does not cover this case.
--
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
[GitHub] [helix] huizhilu merged pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
huizhilu merged pull request #1740:
URL: https://github.com/apache/helix/pull/1740
--
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
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633763117
##########
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 suggest to make some meaningful refactoring instead of introducing more patches.
1. ClusterPauseStatus -> ClusterManagementStatus {NORMAL, CONTROLLER_PAUSED, CLUSTER_PAUSING, CLUSTER_PAUSED, CLUSTER_UNPAUSING, CONTROLLER_MAINTENANCE}
2. No more enable or disable, just call it set status.
3. Deprecate all the other existing method to pause or maintain the cluster.
##########
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:
Question, why we need an additional exception type here? Could you please share more thoughts?
##########
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:
1. The description does not necessarily match the Exception class name. Do you mean "exits" or "exists"?
2. If pause mode has existed, shall we consider the operation is done? But I agree that we should not just return nothing, since it might be paused due to a different reason.
This makes me think about whether or not we shall enter pause mode if the cluster is in controller pause or maintenance mode. My preference is don't mix things up. Reject the call under any confusing situations. So you have to check for the other signals here.
##########
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:
Why? If you return "UNKNOWN" when getLocalhostName() gets an error, the application will continue executing and cause bigger trouble.
--
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
[GitHub] [helix] junkaixue commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
junkaixue commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r635572443
##########
File path: helix-core/src/main/java/org/apache/helix/HelixAdmin.java
##########
@@ -37,6 +37,8 @@
import org.apache.helix.model.MaintenanceSignal;
import org.apache.helix.model.ResourceConfig;
import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.api.status.ClusterManagementMode;
+import org.apache.helix.model.management.ClusterManagementModeRequest;
Review comment:
+1 Better to keep both of them there. They are all user faced objects.
--
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
[GitHub] [helix] junkaixue commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
junkaixue commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633037624
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,20 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents {@link LiveInstanceStatus} */
+ STATUS
+ }
+
+ /**
+ * Represents status of a live instance, eg. PAUSED.
+ */
+ public enum LiveInstanceStatus {
+ NORMAL,
+ PAUSED,
+ ENTERING_PAUSE,
+ EXITING_PAUSE
Review comment:
I dont think we need this. This can be derived as the pausing message is pending there and not removed with status not in PAUSED.
This kind of status is more like in Cluster Pause Status. Instance level is not necessary.
##########
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);
+
+ /**
+ * Gets a cluster out of pause mode. When this method returns, it means
+ * the resume signal has been successfully sent, but it does not mean the cluster has
+ * fully exited pause mode.
+ * <p>
+ * To check whether the cluster has fully exited pause mode, call
+ * {@link #getClusterPauseStatus(String)}.
+ *
+ * @param clusterName Cluster name.
+ */
+ void disableClusterPauseMode(String clusterName);
Review comment:
Why we need two APIs? enableClusterPauseMode can add an argument with enabled to be true or false. It follows our convention.
You can have private function to support enable/disable separately. But they can share the same API.
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,20 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents {@link LiveInstanceStatus} */
+ STATUS
+ }
+
+ /**
+ * Represents status of a live instance, eg. PAUSED.
+ */
+ public enum LiveInstanceStatus {
+ NORMAL,
Review comment:
We do not need a explicit NORMAL for status. We can just remove the entry as the normal status for backward compatible.
##########
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");
Review comment:
NIT: we should not hard code it.
##########
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());
Review comment:
Question: why not use System.currenttimemillis
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -28,7 +28,11 @@
public class PauseSignal extends HelixProperty {
public enum PauseSignalProperty {
- REASON
+ REASON,
+ PAUSE_CLUSTER,
Review comment:
Question: I am not quite sure what do you mean the PAUSE_CLUSTER? Can you elaborate more on each of the entry. FROM_HOST is something I am not clear as well.
Also do we need to explicitly put CANCEL_PENDING_ST or not. We can just make cluster status as PAUSING/EXITING something.
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -28,7 +28,11 @@
public class PauseSignal extends HelixProperty {
public enum PauseSignalProperty {
Review comment:
I would suggest not mess up with Cluster Status and Action you would like to perform. Better to have two enums to hold them separately. One for user command one for cluster status.
--
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
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633827503
##########
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:
Then I think we should not change it.
1. Throw exception is the right way when the tool hits any problem.
2. If you are convinced that no one is using this method, just remove or deprecate it.
This change does not make sense to me.
--
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
[GitHub] [helix] huizhilu commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
huizhilu commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633039726
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -28,7 +28,11 @@
public class PauseSignal extends HelixProperty {
public enum PauseSignalProperty {
Review comment:
We don't want to put cluster status into the PAUSE znode. The PAUSE znode is only created/updated by users. Controller does not write any cluster status to it.
The PAUSE znode will be deleted by controller after cluster fully exits.
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,20 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents {@link LiveInstanceStatus} */
+ STATUS
+ }
+
+ /**
+ * Represents status of a live instance, eg. PAUSED.
+ */
+ public enum LiveInstanceStatus {
+ NORMAL,
Review comment:
Yeah that's correct. I've thought about it. It is put there to help in the return of java/rest api. If the cluster has fully exited pause, what will the query result look like? "NORMAL" is helping with it. I just wanted to make it as a constant instead of hardcoding in the API.
##########
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");
Review comment:
It's the same as the other API: `disableCluster()`...
Will put "pause" as a default pause id in `PauseSignal`
##########
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);
+
+ /**
+ * Gets a cluster out of pause mode. When this method returns, it means
+ * the resume signal has been successfully sent, but it does not mean the cluster has
+ * fully exited pause mode.
+ * <p>
+ * To check whether the cluster has fully exited pause mode, call
+ * {@link #getClusterPauseStatus(String)}.
+ *
+ * @param clusterName Cluster name.
+ */
+ void disableClusterPauseMode(String clusterName);
Review comment:
I understand there are many similar APIs in Helix. However, to me, passing boolean parameters to differentiate the behaviors is really a code smell. Ref: https://softwareengineering.stackexchange.com/questions/208224/is-it-better-to-have-one-method-that-takes-a-bool-as-a-parameter-or-two-methods
I would try to avoid that. So I prefer two methods.
##########
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());
Review comment:
`Instant.now()` gives a human readable format at UTC zone. The epoch timestamp really does not help being written to znode, because we usually will directly read the znode. So a readable format will really help.
The trade-off is also added to the design doc.
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -28,7 +28,11 @@
public class PauseSignal extends HelixProperty {
public enum PauseSignalProperty {
- REASON
+ REASON,
+ PAUSE_CLUSTER,
Review comment:
These fields are representing the user's action. It'd be a record to help tracking and debugging.
PAUSE_CLUSTER: whether enable/disable pause mode
FROM_HOST: where the pause signal is sent from, eg. Helix REST or a user's laptop that directly calls java api.
CANCEL_PENDING_ST: whether to cancel pending st. Controller will read this field to determine to send cancel messages.
--
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
[GitHub] [helix] huizhilu commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
huizhilu commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633040606
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,20 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents {@link LiveInstanceStatus} */
+ STATUS
+ }
+
+ /**
+ * Represents status of a live instance, eg. PAUSED.
+ */
+ public enum LiveInstanceStatus {
+ NORMAL,
+ PAUSED,
+ ENTERING_PAUSE,
+ EXITING_PAUSE
Review comment:
Yes it could be derived. But do we want to hard code those status in the API? I thought about it. I think it's cleaner to define the status here in live instance, which could be used for controller and participant.
When exiting pause, once controller receives the exit notification, the controller status will marked as "EXITING_PAUSE" in LEADER.
So I think this enum will help.
--
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
[GitHub] [helix] huizhilu commented on pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
huizhilu commented on pull request #1740:
URL: https://github.com/apache/helix/pull/1740#issuecomment-844546214
This PR is ready to be merged, approved @jiajunwang
Cluster pause mode feature is going to be added. This commit adds java api to set cluster pause mode.
--
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
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633833425
##########
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:
I suggest calling it HelixStatusConflictException, or other more general names. Since my suggestion is that we check Maintenance mode too. And I think having 2 or more classes for a similar reason makes sense.
You can always carry the current status in the Exception object for the rest to process.
--
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
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633828575
##########
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:
So do you agree that we should fail the operation even if the cluster is only in the Maintenance mode?
--
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
[GitHub] [helix] jiajunwang commented on a change in pull request #1740: Add java api for enable/disable cluster pause mode
Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r633831169
##########
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:
Not true. If you make this change, then we are diverged from what we want to implement. It would be impossible to remove this public API once we have it in a short period.
This is a new API, we don't add APIs that known to be refactored soon.
--
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