helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jiajunw...@apache.org
Subject [helix] branch master updated: Add host name to the Participant History znode. (#1417)
Date Tue, 29 Sep 2020 17:39:29 GMT
This is an automated email from the ASF dual-hosted git repository.

jiajunwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new 304a4e2  Add host name to the Participant History znode. (#1417)
304a4e2 is described below

commit 304a4e23e2afd085099757f182e7d5050ac96a45
Author: Jiajun Wang <jjwang@linkedin.com>
AuthorDate: Tue Sep 29 10:39:17 2020 -0700

    Add host name to the Participant History znode. (#1417)
    
    Add hostname to the Participant History znode.
    This is to ensure that we can track the participant instance allocation even the live
instance node has been removed.
---
 .../org/apache/helix/model/ParticipantHistory.java   | 19 ++++++++++++++++---
 .../integration/paticipant/TestInstanceHistory.java  | 20 +++++++++++++++++++-
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/helix-core/src/main/java/org/apache/helix/model/ParticipantHistory.java b/helix-core/src/main/java/org/apache/helix/model/ParticipantHistory.java
index 9ab59c2..8b432ce 100644
--- a/helix-core/src/main/java/org/apache/helix/model/ParticipantHistory.java
+++ b/helix-core/src/main/java/org/apache/helix/model/ParticipantHistory.java
@@ -19,6 +19,8 @@ package org.apache.helix.model;
  * under the License.
  */
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -38,6 +40,7 @@ import org.slf4j.LoggerFactory;
  */
 public class ParticipantHistory extends HelixProperty {
   private static Logger LOG = LoggerFactory.getLogger(ParticipantHistory.class);
+  private static final String UNKNOWN_HOST_NAME = "UnknownHostname";
 
   private final static int HISTORY_SIZE = 20;
   private enum ConfigProperty {
@@ -47,7 +50,8 @@ public class ParticipantHistory extends HelixProperty {
     HISTORY,
     OFFLINE,
     VERSION,
-    LAST_OFFLINE_TIME
+    LAST_OFFLINE_TIME,
+    HOST
   }
 
   public static long ONLINE = -1;
@@ -76,7 +80,15 @@ public class ParticipantHistory extends HelixProperty {
    * @return
    */
   public void reportOnline(String sessionId, String version) {
-    updateSessionHistory(sessionId, version);
+    String hostname;
+    try {
+      hostname = InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException e) {
+      LOG.error("Failed to get host name. Use {} for the participant history recording.",
+          UNKNOWN_HOST_NAME);
+      hostname = UNKNOWN_HOST_NAME;
+    }
+    updateSessionHistory(sessionId, version, hostname);
     _record.setSimpleField(ConfigProperty.LAST_OFFLINE_TIME.name(), String.valueOf(ONLINE));
   }
 
@@ -103,7 +115,7 @@ public class ParticipantHistory extends HelixProperty {
   /**
    * Add record to session online history list
    */
-  private void updateSessionHistory(String sessionId, String version) {
+  private void updateSessionHistory(String sessionId, String version, String hostname) {
     List<String> list = _record.getListField(ConfigProperty.HISTORY.name());
     if (list == null) {
       list = new ArrayList<>();
@@ -126,6 +138,7 @@ public class ParticipantHistory extends HelixProperty {
     String dateTime = df.format(new Date(timeMillis));
     sessionEntry.put(ConfigProperty.DATE.name(), dateTime);
     sessionEntry.put(ConfigProperty.VERSION.name(), version);
+    sessionEntry.put(ConfigProperty.HOST.name(), hostname);
 
     list.add(sessionEntry.toString());
   }
diff --git a/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestInstanceHistory.java
b/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestInstanceHistory.java
index 12b154c..2f6004d 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestInstanceHistory.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestInstanceHistory.java
@@ -19,6 +19,8 @@ package org.apache.helix.integration.paticipant;
  * under the License.
  */
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.List;
 
 import org.apache.helix.HelixManager;
@@ -32,7 +34,8 @@ import org.testng.annotations.Test;
 
 public class TestInstanceHistory extends ZkStandAloneCMTestBase {
 
-  @Test() public void testInstanceHistory() throws Exception {
+  @Test()
+  public void testInstanceHistory() throws Exception {
     HelixManager manager = HelixManagerFactory
         .getZKHelixManager(CLUSTER_NAME, "admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
     manager.connect();
@@ -44,6 +47,21 @@ public class TestInstanceHistory extends ZkStandAloneCMTestBase {
     List<String> list = history.getRecord().getListField("HISTORY");
     Assert.assertEquals(list.size(), 1);
 
+    Assert.assertTrue(list.get(0).contains("SESSION=" + _participants[0].getSessionId()));
+    Assert.assertTrue(list.get(0).contains("VERSION=" + _participants[0].getVersion()));
+
+    String hostname;
+    try {
+      hostname = InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException ex) {
+      hostname = "UnknownHostname";
+    }
+    Assert
+        .assertTrue(list.get(0).contains("HOST=" + hostname));
+
+    Assert.assertTrue(list.get(0).contains("TIME="));
+    Assert.assertTrue(list.get(0).contains("DATE="));
+
     for (int i = 0; i <= 22; i++) {
       _participants[0].disconnect();
       _participants[0].connect();


Mime
View raw message