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/29 02:50:43 UTC

[GitHub] [helix] huizhilu opened a new pull request #1771: Add model to record history and status of management mode

huizhilu opened a new pull request #1771:
URL: https://github.com/apache/helix/pull/1771


   ### Issues
   
   - [ ] My PR addresses the following Helix issues and references them in the PR description:
   
   Resolves #1770 
   
   ### Description
   
   - [ ] Here are some details about my PR, including screenshots of any UI changes:
   
   Management mode operation history needs to be persisted to the controller history znode.
   ```
   {
       "id": "STATUS",
       "listFields": {
           "MANAGEMENT_MODE_HISTORY": [
               "{STATUS=COMPLETED, CONTROLLER=controller-0, MODE=CLUSTER_PAUSE, FROM_HOST=host-name, TIME=2021-05-29T02:33:37.078Z, REASON=FREEZE CLUSTER}"
            ]
       },
       "mapFields": {},
       "simpleFields": {}
   }
   ```
   
   The status of IN_PROGRESS or COMPLETED is recorded in the temporary status znode: /CLUSTER/STATUS.
   After the cluster exits CLUSTER_FREEZE mode, this znode can be deleted.
   ```
   {
       "id": "STATUS",
       "listFields": {},
       "mapFields": {},
       "simpleFields": {
           "MANAGEMENT_MODE": "CLUSTER_FREEZE",
           "MANAGEMENT_MODE_STATUS": "COMPLETED"      // or IN_PROGRESS
       }
   }
   ```
   
   ### Tests
   
   - [ ] The following tests are written for this issue:
   
   testManagementModeHistory
   
   - The following is the result of the "mvn test" command on the appropriate module:
   
   (If CI test fails due to known issue, please specify the issue and test PR locally. Then copy & paste the result of "mvn test" to here.)
   
   ### 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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
huizhilu commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r648600920



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +146,52 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    List<String> historyList = getManagementModeHistory();
+    if (historyList.isEmpty()) {
+      historyList = new ArrayList<>();
+      _record.setListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name(), historyList);
+    }
+
+    if (historyList.size() >= HISTORY_SIZE) {
+      historyList = historyList.subList(historyList.size() - HISTORY_SIZE + 1, historyList.size());
+    }
+
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());
+    historyEntry.put(PauseSignal.PauseSignalProperty.FROM_HOST.name(), fromHost);
+    historyEntry.put(PauseSignal.PauseSignalProperty.REASON.name(), reason);
+    historyList.add(historyEntry.toString());

Review comment:
       Clarified offline. We don't read the string back into znrecord, so it's not necessary to serialize it into json. Easier for users to directly read the content. And consistent with the HISTORY content.




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
huizhilu merged pull request #1771:
URL: https://github.com/apache/helix/pull/1771


   


-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
huizhilu commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r648654806



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +134,40 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());

Review comment:
       We (you and me) discussed it offline before and agreed on recording COMPLETED is good enough. For sure we could record STARTED as well if we think it is very useful.
   The status field makes it clear to users the timestamp is for completed. Otherwise, if users have no context, they would be confused: what does it mean. So I prefer to make it clear. And it's extensible for use to add other status, eg. STARTED.




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r647949956



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +146,52 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    List<String> historyList = getManagementModeHistory();
+    if (historyList.isEmpty()) {
+      historyList = new ArrayList<>();
+      _record.setListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name(), historyList);
+    }
+
+    if (historyList.size() >= HISTORY_SIZE) {
+      historyList = historyList.subList(historyList.size() - HISTORY_SIZE + 1, historyList.size());
+    }
+
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());
+    historyEntry.put(PauseSignal.PauseSignalProperty.FROM_HOST.name(), fromHost);
+    historyEntry.put(PauseSignal.PauseSignalProperty.REASON.name(), reason);
+    historyList.add(historyEntry.toString());

Review comment:
       I don't like it too. But remember our ZNode is not really designed for human to read (this is just nice to have thing). If it is auto compressed, it won't be readable anyway.
   Being able to read it programmatically is MORE important. Encoding in JSON is a safer way. And it is what we are doing elsewhere like throttling config, etc. We should keep the convention.




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
huizhilu commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r648651852



##########
File path: helix-core/src/main/java/org/apache/helix/PropertyPathBuilder.java
##########
@@ -53,6 +54,7 @@
 import static org.apache.helix.PropertyType.MESSAGES;
 import static org.apache.helix.PropertyType.PAUSE;
 import static org.apache.helix.PropertyType.STATEMODELDEFS;
+import static org.apache.helix.PropertyType.STATUS;

Review comment:
       Discussed offline. This question is about making the code style consistent in this file, without mixing usages of static/non-static.
   Conclusion is: static import for the fields are fine, but preferred not too many. No static imports for classes. For this file, we'll stick to non-static imports: using `PropertyType.STATUS`. The other static imports will be addressed by #1790




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r648563323



##########
File path: helix-core/src/main/java/org/apache/helix/PropertyPathBuilder.java
##########
@@ -53,6 +54,7 @@
 import static org.apache.helix.PropertyType.MESSAGES;
 import static org.apache.helix.PropertyType.PAUSE;
 import static org.apache.helix.PropertyType.STATEMODELDEFS;
+import static org.apache.helix.PropertyType.STATUS;

Review comment:
       Question, it seems the import method is not aligned here. Shall we use static import or just import?
   
   Please suggest and ensure your new import aligns with the decision. I can help to quickly fix the others if you don't want to pollute this 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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r646988032



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -189,7 +209,49 @@ public ZNRecord updateMaintenanceHistory(boolean enabled, String reason, long cu
         }
       }
     }
-    maintenanceHistoryList.add(new ObjectMapper().writeValueAsString(maintenanceEntry));
+
+    return populateHistoryEntries(HistoryType.MAINTENANCE,
+        new ObjectMapper().writeValueAsString(maintenanceEntry));
+  }
+
+  private ZNRecord populateHistoryEntries(HistoryType type, String entry) {
+    String configKey;
+    int historySize;
+    switch (type) {
+      case CONTROLLER_LEADERSHIP:
+        configKey = ConfigProperty.HISTORY.name();
+        historySize = HISTORY_SIZE;
+        break;
+      case MAINTENANCE:
+        configKey = MaintenanceConfigKey.MAINTENANCE_HISTORY.name();
+        historySize = MAINTENANCE_HISTORY_SIZE;
+        break;
+      case MANAGEMENT_MODE:
+        configKey = ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name();
+        historySize = HISTORY_SIZE;
+        break;
+      default:
+        throw new HelixException("Unknown history type " + type.name());
+    }
+
+    List<String> historyList = _record.getListField(configKey);
+    if (historyList == null) {
+      historyList = new ArrayList<>();
+      _record.setListField(configKey, historyList);
+    }
+
+    if (historyList.isEmpty()) {

Review comment:
       If it is empty, why we need to create a new Array?

##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -57,6 +60,12 @@
 
   }
 
+  private enum ManagementModeConfigKey {
+    MANAGEMENT_MODE_HISTORY,

Review comment:
       nit, It can be simplified to "HISTORY".

##########
File path: helix-core/src/test/java/org/apache/helix/model/TestControllerHistoryModel.java
##########
@@ -0,0 +1,69 @@
+package org.apache.helix.model;
+
+/*
+ * 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.time.Instant;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.helix.TestHelper;
+import org.apache.helix.api.status.ClusterManagementMode;
+import org.apache.helix.util.HelixUtil;
+import org.apache.helix.zookeeper.zkclient.NetworkUtil;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestControllerHistoryModel {
+  @Test
+  public void testManagementModeHistory() {
+    ControllerHistory controllerHistory = new ControllerHistory("HISTORY");
+    String controller = "controller-0";
+    ClusterManagementMode mode = new ClusterManagementMode(ClusterManagementMode.Type.CLUSTER_PAUSE,
+        ClusterManagementMode.Status.COMPLETED);
+    long time = System.currentTimeMillis();
+    String fromHost = NetworkUtil.getLocalhostName();
+    String reason = TestHelper.getTestMethodName();
+    controllerHistory.updateManagementModeHistory(controller, mode, fromHost, time, reason);
+
+    List<String> historyList = controllerHistory.getManagementModeHistory();
+    String lastHistory = historyList.get(historyList.size() - 1);
+    Map<String, String> historyMap = HelixUtil.stringToMap(lastHistory);
+
+    Map<String, String> expectedMap = new HashMap<>();
+    expectedMap.put("CONTROLLER", controller);
+    expectedMap.put("TIME", Instant.ofEpochMilli(time).toString());
+    expectedMap.put("MODE", mode.getMode().name());
+    expectedMap.put("STATUS", mode.getStatus().name());
+    expectedMap.put(PauseSignal.PauseSignalProperty.FROM_HOST.name(), fromHost);
+    expectedMap.put(PauseSignal.PauseSignalProperty.REASON.name(), reason);
+
+    Assert.assertEquals(historyMap, expectedMap);
+
+    // Add more than 10 entries, it should only keep the latest 10.
+    for (int i = 0; i < 15; i++) {
+      controllerHistory.updateManagementModeHistory(controller, mode, fromHost, time, reason);
+    }
+
+    historyList = controllerHistory.getManagementModeHistory();
+
+    Assert.assertEquals(historyList.size(), 10);

Review comment:
       Check if the remaining 10 is the latest 10.

##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -189,7 +209,49 @@ public ZNRecord updateMaintenanceHistory(boolean enabled, String reason, long cu
         }
       }
     }
-    maintenanceHistoryList.add(new ObjectMapper().writeValueAsString(maintenanceEntry));
+
+    return populateHistoryEntries(HistoryType.MAINTENANCE,
+        new ObjectMapper().writeValueAsString(maintenanceEntry));
+  }
+
+  private ZNRecord populateHistoryEntries(HistoryType type, String entry) {
+    String configKey;
+    int historySize;
+    switch (type) {
+      case CONTROLLER_LEADERSHIP:
+        configKey = ConfigProperty.HISTORY.name();
+        historySize = HISTORY_SIZE;
+        break;
+      case MAINTENANCE:
+        configKey = MaintenanceConfigKey.MAINTENANCE_HISTORY.name();
+        historySize = MAINTENANCE_HISTORY_SIZE;
+        break;
+      case MANAGEMENT_MODE:
+        configKey = ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name();
+        historySize = HISTORY_SIZE;
+        break;
+      default:
+        throw new HelixException("Unknown history type " + type.name());
+    }
+
+    List<String> historyList = _record.getListField(configKey);
+    if (historyList == null) {
+      historyList = new ArrayList<>();
+      _record.setListField(configKey, historyList);
+    }
+
+    if (historyList.isEmpty()) {
+      historyList = new ArrayList<>();
+      _record.setListField(configKey, historyList);
+    }
+
+    if (historyList.size() >= historySize) {
+      historyList = historyList.subList(historyList.size() - HISTORY_SIZE + 1, historyList.size());

Review comment:
       HISTORY_SIZE ==> historySize, or it is a bug for MAINTENANCE_HISTORY
   
   And I would prefer removing the items from the list instead of using subList. Note that subList returns a view of the original list. And "The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list." - https://docs.oracle.com/javase/8/docs/api/java/util/List.html#subList-int-int-

##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +134,40 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());

Review comment:
       Question, I assume we only record when the management mode change is completed? Or also when it is started? If we need to record when it has not finished, what is the status? If it would be PENDING instead of "STARTED", then will it be confusing?

##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -189,7 +209,49 @@ public ZNRecord updateMaintenanceHistory(boolean enabled, String reason, long cu
         }
       }
     }
-    maintenanceHistoryList.add(new ObjectMapper().writeValueAsString(maintenanceEntry));
+
+    return populateHistoryEntries(HistoryType.MAINTENANCE,
+        new ObjectMapper().writeValueAsString(maintenanceEntry));
+  }
+
+  private ZNRecord populateHistoryEntries(HistoryType type, String entry) {
+    String configKey;
+    int historySize;
+    switch (type) {
+      case CONTROLLER_LEADERSHIP:
+        configKey = ConfigProperty.HISTORY.name();
+        historySize = HISTORY_SIZE;
+        break;
+      case MAINTENANCE:
+        configKey = MaintenanceConfigKey.MAINTENANCE_HISTORY.name();
+        historySize = MAINTENANCE_HISTORY_SIZE;
+        break;
+      case MANAGEMENT_MODE:
+        configKey = ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name();
+        historySize = HISTORY_SIZE;
+        break;
+      default:
+        throw new HelixException("Unknown history type " + type.name());
+    }
+
+    List<String> historyList = _record.getListField(configKey);
+    if (historyList == null) {
+      historyList = new ArrayList<>();
+      _record.setListField(configKey, historyList);

Review comment:
       This set is not necessary. Please remove.




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
huizhilu commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r643635966



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +146,52 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    List<String> historyList = getManagementModeHistory();
+    if (historyList.isEmpty()) {
+      historyList = new ArrayList<>();
+      _record.setListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name(), historyList);
+    }
+
+    if (historyList.size() >= HISTORY_SIZE) {
+      historyList = historyList.subList(historyList.size() - HISTORY_SIZE + 1, historyList.size());
+    }
+
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());
+    historyEntry.put(PauseSignal.PauseSignalProperty.FROM_HOST.name(), fromHost);
+    historyEntry.put(PauseSignal.PauseSignalProperty.REASON.name(), reason);
+    historyList.add(historyEntry.toString());

Review comment:
       No. I actually intend not to serialize it using object mapper, because it would have the backslash`\"`, look like below.
   ```
               "{\"DATE\":\"2021-01-20-09:20:29\",\"TIMESTAMP\":\"1611134429950\",\"OPERATION_TYPE\":\"EXIT\",\"REASON\":\"\",\"TRIGGERED_BY\":\"USER\"}"
   ```
   Because of the double serialization, it is not easy to read and increases the znode size. ToString() makes it clearer and easier to read. It is same as the HISTORY fields.




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r643436444



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +146,52 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {

Review comment:
       Not related to this PR, I guess you will need to refactor ClusterAccessor.getControllerHistory() later on since it is written in a very different way.
   Maybe we shall make HistoryType enum private (just like the other enums) so the other callers won't be able to get the information in such a raw way.
   

##########
File path: helix-core/src/test/java/org/apache/helix/model/TestControllerHistory.java
##########
@@ -0,0 +1,69 @@
+package org.apache.helix.model;
+
+/*
+ * 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.time.Instant;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.helix.TestHelper;
+import org.apache.helix.api.status.ClusterManagementMode;
+import org.apache.helix.util.HelixUtil;
+import org.apache.helix.zookeeper.zkclient.NetworkUtil;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestControllerHistory {

Review comment:
       Please merge the test case to the existing TestControllerHistory test class.

##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +146,52 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    List<String> historyList = getManagementModeHistory();
+    if (historyList.isEmpty()) {
+      historyList = new ArrayList<>();
+      _record.setListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name(), historyList);
+    }
+
+    if (historyList.size() >= HISTORY_SIZE) {
+      historyList = historyList.subList(historyList.size() - HISTORY_SIZE + 1, historyList.size());
+    }
+
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());
+    historyEntry.put(PauseSignal.PauseSignalProperty.FROM_HOST.name(), fromHost);
+    historyEntry.put(PauseSignal.PauseSignalProperty.REASON.name(), reason);
+    historyList.add(historyEntry.toString());

Review comment:
       Humm, don't you need to do "new ObjectMapper().writeValueAsString(...)"?

##########
File path: helix-core/src/main/java/org/apache/helix/util/HelixUtil.java
##########
@@ -152,6 +152,18 @@ public static String serializeByComma(List<String> objects) {
     return keyValueMap;
   }
 
+  /**
+   * Performs conversion from a map string into a map. The string was converted by map's toString().
+   *
+   * @param mapAsString A string that is converted by map's toString() method.
+   *                    Example: "{k1=v1, k2=v2}"
+   * @return Map<String, String>
+   */
+  public static Map<String, String> stringToMap(String mapAsString) {

Review comment:
       If you encode the original entry map using Json, then you don't need this method here which looks very hacky.




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
huizhilu commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r647030771



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +134,40 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());

Review comment:
       As we discussed before, we only record when the status is completed. In progress doesn't seem that helpful.

##########
File path: helix-core/src/main/java/org/apache/helix/util/HelixUtil.java
##########
@@ -152,6 +152,18 @@ public static String serializeByComma(List<String> objects) {
     return keyValueMap;
   }
 
+  /**
+   * Performs conversion from a map string into a map. The string was converted by map's toString().
+   *
+   * @param mapAsString A string that is converted by map's toString() method.
+   *                    Example: "{k1=v1, k2=v2}"
+   * @return Map<String, String>
+   */
+  public static Map<String, String> stringToMap(String mapAsString) {

Review comment:
       Basically I'd like to avoid the double json serialized strings when using json serialization, which is difficult to read and unnecessary. String to map isn't that hacky. It's a util to convert the string back to map.
   ```
   "MAINTENANCE_HISTORY": [
               "{\"DATE\":\"2021-03-11-06:36:09\",\"TIMESTAMP\":\"1615444569731\",\"OPERATION_TYPE\":\"EXIT\",\"REASON\":null,\"TRIGGERED_BY\":\"USER\"}"
   ```
   

##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -57,6 +60,12 @@
 
   }
 
+  private enum ManagementModeConfigKey {
+    MANAGEMENT_MODE_HISTORY,

Review comment:
       No, controller already has the "HISTORY" field. "MANAGEMENT_MODE_HISTORY" be needed to differentiate from it. Otherwise, we'll mix controller leader switch history with management mode history.




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r647949956



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +146,52 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    List<String> historyList = getManagementModeHistory();
+    if (historyList.isEmpty()) {
+      historyList = new ArrayList<>();
+      _record.setListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name(), historyList);
+    }
+
+    if (historyList.size() >= HISTORY_SIZE) {
+      historyList = historyList.subList(historyList.size() - HISTORY_SIZE + 1, historyList.size());
+    }
+
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());
+    historyEntry.put(PauseSignal.PauseSignalProperty.FROM_HOST.name(), fromHost);
+    historyEntry.put(PauseSignal.PauseSignalProperty.REASON.name(), reason);
+    historyList.add(historyEntry.toString());

Review comment:
       I don't like it too. But remember our ZNode is not really designed for human to read. If it is auto compressed, it won't be readable anyway.
   Being able to read it programmatically is MORE important. Encoding in JSON is a safer way. And it is what we are doing elsewhere like throttling config, etc. We should keep the convention.




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
huizhilu commented on pull request #1771:
URL: https://github.com/apache/helix/pull/1771#issuecomment-858125226


   This PR is ready to be merged, approved by @jiajunwang 
   
   Management mode operation history needs to be persisted to the controller history znode. The status of IN_PROGRESS or COMPLETED is recorded in the temporary status znode: /{clusterName}/STATUS/CLUSTER/{clusterName}.
   This commit adds data model and methods to record the status and history for management 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] junkaixue commented on a change in pull request #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
junkaixue commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r643692630



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +146,52 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,

Review comment:
       We have a history update function for instance and controller. Can we resue the code or let's put it into some comment place to avoid redundant code?

##########
File path: helix-core/src/main/java/org/apache/helix/PropertyKey.java
##########
@@ -241,6 +243,13 @@ public PropertyKey clusterConfig() {
           _clusterName, ConfigScopeProperty.CLUSTER.toString(), _clusterName);
     }
 
+    /**
+     * Get a property key associated with this cluster status
+     * @return {@link PropertyKey}
+     */
+    public PropertyKey clusterStatus() {
+      return new PropertyKey(STATUS, ClusterStatus.class, _clusterName);
+    }

Review comment:
       Question: from this property key, it looks like on the top of root path? 

##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +146,52 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    List<String> historyList = getManagementModeHistory();
+    if (historyList.isEmpty()) {
+      historyList = new ArrayList<>();
+      _record.setListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name(), historyList);
+    }
+
+    if (historyList.size() >= HISTORY_SIZE) {
+      historyList = historyList.subList(historyList.size() - HISTORY_SIZE + 1, historyList.size());
+    }
+
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());
+    historyEntry.put(PauseSignal.PauseSignalProperty.FROM_HOST.name(), fromHost);

Review comment:
       Is this from host necessary? We can make it optional.




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r648706443



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +134,40 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());

Review comment:
       Thanks for the details. I don't see any real problem here. Although I still don't think the additional status string is useful, please feel free to keep it if you believe it can provide value.




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r647092576



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -57,6 +60,12 @@
 
   }
 
+  private enum ManagementModeConfigKey {
+    MANAGEMENT_MODE_HISTORY,

Review comment:
       Any 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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
huizhilu commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r647884166



##########
File path: helix-core/src/main/java/org/apache/helix/PropertyKey.java
##########
@@ -241,6 +243,13 @@ public PropertyKey clusterConfig() {
           _clusterName, ConfigScopeProperty.CLUSTER.toString(), _clusterName);
     }
 
+    /**
+     * Get a property key associated with this cluster status
+     * @return {@link PropertyKey}
+     */
+    public PropertyKey clusterStatus() {
+      return new PropertyKey(STATUS, ClusterStatus.class, _clusterName);
+    }

Review comment:
       It's `/{clusterName}/STATUS/CLUSTER/{clusterName}`




-- 
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 #1771: Add model to record history and status of management mode

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1771:
URL: https://github.com/apache/helix/pull/1771#discussion_r647950517



##########
File path: helix-core/src/main/java/org/apache/helix/model/ControllerHistory.java
##########
@@ -136,6 +134,40 @@ public ZNRecord updateHistory(String clusterName, String instanceName, String ve
     return historyList;
   }
 
+  /**
+   * Gets the management mode history.
+   *
+   * @return List of history json strings.
+   */
+  public List<String> getManagementModeHistory() {
+    List<String> history =
+        _record.getListField(ManagementModeConfigKey.MANAGEMENT_MODE_HISTORY.name());
+    return history == null ? Collections.emptyList() : history;
+  }
+
+  /**
+   * Updates management mode and status history to controller history in FIFO order.
+   *
+   * @param controller controller name
+   * @param mode cluster management mode {@link ClusterManagementMode}
+   * @param fromHost the hostname that creates the management mode signal
+   * @param time time in millis
+   * @param reason reason to put the cluster in management mode
+   * @return updated history znrecord
+   */
+  public ZNRecord updateManagementModeHistory(String controller, ClusterManagementMode mode,
+      String fromHost, long time, String reason) {
+    Map<String, String> historyEntry = new HashMap<>();
+    historyEntry.put(ConfigProperty.CONTROLLER.name(), controller);
+    historyEntry.put(ConfigProperty.TIME.name(), Instant.ofEpochMilli(time).toString());
+    historyEntry.put(ManagementModeConfigKey.MODE.name(), mode.getMode().name());
+    historyEntry.put(ManagementModeConfigKey.STATUS.name(), mode.getStatus().name());

Review comment:
       So the status would always be completed, and it is not delivering any useful information, right?




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