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/06/02 04:03:45 UTC

[GitHub] [helix] huizhilu commented on a change in pull request #1771: Add model to record history and status of management mode

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