hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1490072 - in /hbase/trunk: hbase-client/src/main/java/org/apache/hadoop/hbase/ hbase-server/src/main/java/org/apache/hadoop/hbase/master/ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ hbase-server/src/main/java/org/apach...
Date Wed, 05 Jun 2013 23:16:21 GMT
Author: stack
Date: Wed Jun  5 23:16:20 2013
New Revision: 1490072

URL: http://svn.apache.org/r1490072
Log:
HBASE-8645 Change ServerName so it uses hostname only, not FQDN hostnames

Modified:
    hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java

Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java?rev=1490072&r1=1490071&r2=1490072&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java (original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java Wed Jun
 5 23:16:20 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.hadoop.hbase;
 
+import com.google.common.net.InetAddresses;
 import com.google.protobuf.InvalidProtocolBufferException;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
@@ -33,16 +34,15 @@ import java.util.regex.Pattern;
 
 /**
  * Instance of an HBase ServerName.
- * A server name is used uniquely identifying a server instance and is made
- * of the combination of hostname, port, and startcode. The startcode
- * distingushes restarted servers on same hostname and port (startcode is
- * usually timestamp of server startup). The {@link #toString()} format of
- * ServerName is safe to use in the  filesystem and as znode name up in
- * ZooKeeper.  Its format is:
+ * A server name is used uniquely identifying a server instance in a cluster and is made
+ * of the combination of hostname, port, and startcode.  The startcode distingushes restarted
+ * servers on same hostname and port (startcode is usually timestamp of server startup).
The
+ * {@link #toString()} format of ServerName is safe to use in the  filesystem and as znode
name
+ * up in ZooKeeper.  Its format is:
  * <code>&lt;hostname> '{@link #SERVERNAME_SEPARATOR}' &lt;port> '{@link
#SERVERNAME_SEPARATOR}' &lt;startcode></code>.
- * For example, if hostname is <code>example.org</code>, port is <code>1234</code>,
+ * For example, if hostname is <code>www.example.org</code>, port is <code>1234</code>,
  * and the startcode for the regionserver is <code>1212121212</code>, then
- * the {@link #toString()} would be <code>example.org,1234,1212121212</code>.
+ * the {@link #toString()} would be <code>www.example.org,1234,1212121212</code>.
  * 
  * <p>You can obtain a versioned serialized form of this class by calling
  * {@link #getVersionedBytes()}.  To deserialize, call {@link #parseVersionedServerName(byte[])}
@@ -83,7 +83,7 @@ public class ServerName implements Compa
   public static final String UNKNOWN_SERVERNAME = "#unknown#";
 
   private final String servername;
-  private final String hostname;
+  private final String hostnameOnly;
   private final int port;
   private final long startcode;
 
@@ -95,10 +95,23 @@ public class ServerName implements Compa
   public static final List<ServerName> EMPTY_SERVER_LIST = new ArrayList<ServerName>(0);
 
   public ServerName(final String hostname, final int port, final long startcode) {
-    this.hostname = hostname;
+    // Drop the domain is there is one; no need of it in a local cluster.  With it, we get
long
+    // unwieldy names.
+    this.hostnameOnly = hostname;
     this.port = port;
     this.startcode = startcode;
-    this.servername = getServerName(hostname, port, startcode);
+    this.servername = getServerName(this.hostnameOnly, port, startcode);
+  }
+
+  /**
+   * @param hostname
+   * @return hostname minus the domain, if there is one (will do pass-through on ip addresses)
+   */
+  static String getHostNameMinusDomain(final String hostname) {
+    if (InetAddresses.isInetAddress(hostname)) return hostname;
+    String [] parts = hostname.split("\\.");
+    if (parts == null || parts.length == 0) return hostname;
+    return parts[0];
   }
 
   public ServerName(final String serverName) {
@@ -135,6 +148,16 @@ public class ServerName implements Compa
   }
 
   /**
+   * @return Return a SHORT version of {@link ServerName#toString()}, one that has the host
only,
+   * minus the domain, and the port only -- no start code; the String is for us internally
mostly
+   * tying threads to their server.  Not for external use.  It is lossy and will not work
in
+   * in compares, etc.
+   */
+  public String toShortString() {
+    return Addressing.createHostAndPortStr(getHostNameMinusDomain(this.hostnameOnly), this.port);
+  }
+
+  /**
    * @return {@link #getServerName()} as bytes with a short-sized prefix with
    * the ServerName#VERSION of this class.
    */
@@ -150,7 +173,7 @@ public class ServerName implements Compa
   }
 
   public String getHostname() {
-    return hostname;
+    return hostnameOnly;
   }
 
   public int getPort() {
@@ -162,13 +185,14 @@ public class ServerName implements Compa
   }
 
   /**
+   * For internal use only.
    * @param hostName
    * @param port
    * @param startcode
    * @return Server name made of the concatenation of hostname, port and
    * startcode formatted as <code>&lt;hostname> ',' &lt;port> ',' &lt;startcode></code>
    */
-  public static String getServerName(String hostName, int port, long startcode) {
+  static String getServerName(String hostName, int port, long startcode) {
     final StringBuilder name = new StringBuilder(hostName.length() + 1 + 5 + 1 + 13);
     name.append(hostName);
     name.append(SERVERNAME_SEPARATOR);
@@ -197,7 +221,7 @@ public class ServerName implements Compa
    * {@link Addressing#createHostAndPortStr(String, int)}
    */
   public String getHostAndPort() {
-    return Addressing.createHostAndPortStr(this.hostname, this.port);
+    return Addressing.createHostAndPortStr(this.hostnameOnly, this.port);
   }
 
   /**

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1490072&r1=1490071&r2=1490072&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Wed
Jun  5 23:16:20 2013
@@ -420,7 +420,7 @@ MasterServices, Server {
         ", hbase.cluster.distributed=" + this.conf.getBoolean("hbase.cluster.distributed",
false));
 
     // set the thread name now we have an address
-    setName(MASTER + "-" + this.serverName.toString());
+    setName(MASTER + ":" + this.serverName.toShortString());
 
     Replication.decorateMasterConfiguration(this.conf);
 

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1490072&r1=1490071&r2=1490072&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Wed Jun  5 23:16:20 2013
@@ -1508,7 +1508,7 @@ public class HRegionServer implements Cl
   private void startServiceThreads() throws IOException {
     String n = Thread.currentThread().getName();
     // Start executor services
-    this.service = new ExecutorService(getServerName().toString());
+    this.service = new ExecutorService(getServerName().toShortString());
     this.service.startExecutorService(ExecutorType.RS_OPEN_REGION,
       conf.getInt("hbase.regionserver.executor.openregion.threads", 3));
     this.service.startExecutorService(ExecutorType.RS_OPEN_META,

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java?rev=1490072&r1=1490071&r2=1490072&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java
Wed Jun  5 23:16:20 2013
@@ -358,7 +358,7 @@ class MemStoreFlusher implements FlushRe
 
   synchronized void start(UncaughtExceptionHandler eh) {
     ThreadFactory flusherThreadFactory = Threads.newDaemonThreadFactory(
-        server.getServerName().toString() + "-MemStoreFlusher", eh);
+        server.getServerName().toShortString() + "-MemStoreFlusher", eh);
     for (int i = 0; i < flushHandlers.length; i++) {
       flushHandlers[i] = new FlushHandler();
       flusherThreadFactory.newThread(flushHandlers[i]);

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java?rev=1490072&r1=1490071&r2=1490072&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
Wed Jun  5 23:16:20 2013
@@ -101,7 +101,7 @@ public class Replication implements WALA
     this.replication = isReplication(this.conf);
     this.scheduleThreadPool = Executors.newScheduledThreadPool(1,
       new ThreadFactoryBuilder()
-        .setNameFormat(server.getServerName() + "Replication Statistics #%d")
+        .setNameFormat(server.getServerName().toShortString() + "Replication Statistics #%d")
         .setDaemon(true)
         .build());
     if (replication) {

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java?rev=1490072&r1=1490071&r2=1490072&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java
Wed Jun  5 23:16:20 2013
@@ -48,7 +48,7 @@ public class JVMClusterUtil {
     private final HRegionServer regionServer;
 
     public RegionServerThread(final HRegionServer r, final int index) {
-      super(r, "RegionServer:" + index + ";" + r.getServerName());
+      super(r, "RS:" + index + ";" + r.getServerName().toShortString());
       this.regionServer = r;
     }
 
@@ -109,7 +109,7 @@ public class JVMClusterUtil {
     private final HMaster master;
 
     public MasterThread(final HMaster m, final int index) {
-      super(m, "Master:" + index + ";" + m.getServerName());
+      super(m, "M:" + index + ";" + m.getServerName().toShortString());
       this.master = m;
     }
 

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java?rev=1490072&r1=1490071&r2=1490072&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java Wed
Jun  5 23:16:20 2013
@@ -32,6 +32,30 @@ import org.junit.experimental.categories
 @Category(SmallTests.class)
 public class TestServerName {
   @Test
+  public void testGetHostNameMinusDomain() {
+    assertEquals("2607:f0d0:1002:51::4",
+      ServerName.getHostNameMinusDomain("2607:f0d0:1002:51::4"));
+    assertEquals("2607:f0d0:1002:0051:0000:0000:0000:0004",
+        ServerName.getHostNameMinusDomain("2607:f0d0:1002:0051:0000:0000:0000:0004"));
+    assertEquals("1.1.1.1", ServerName.getHostNameMinusDomain("1.1.1.1"));
+    assertEquals("x", ServerName.getHostNameMinusDomain("x"));
+    assertEquals("x", ServerName.getHostNameMinusDomain("x.y.z"));
+    assertEquals("asf000", ServerName.getHostNameMinusDomain("asf000.sp2.ygridcore.net"));
+    ServerName sn = new ServerName("asf000.sp2.ygridcore.net", 1, 1);
+    assertEquals("asf000.sp2.ygridcore.net,1,1", sn.toString());
+  }
+
+  @Test
+  public void testShortString() {
+    ServerName sn = new ServerName("asf000.sp2.ygridcore.net", 1, 1);
+    assertEquals("asf000:1", sn.toShortString());
+    sn = new ServerName("2607:f0d0:1002:0051:0000:0000:0000:0004", 1, 1);
+    assertEquals("2607:f0d0:1002:0051:0000:0000:0000:0004:1", sn.toShortString());
+    sn = new ServerName("1.1.1.1", 1, 1);
+    assertEquals("1.1.1.1:1", sn.toShortString());
+  }
+
+  @Test
   public void testRegexPatterns() {
     assertTrue(Pattern.matches(Addressing.VALID_PORT_REGEX, "123"));
     assertFalse(Pattern.matches(Addressing.VALID_PORT_REGEX, ""));
@@ -46,8 +70,8 @@ public class TestServerName {
     final String snStr = "www.example.org,1234,5678";
     ServerName sn = new ServerName(snStr);
     byte [] versionedBytes = sn.getVersionedBytes();
-    assertEquals(snStr, ServerName.parseVersionedServerName(versionedBytes).toString());
-    final String hostnamePortStr = "www.example.org:1234";
+    assertEquals(sn.toString(), ServerName.parseVersionedServerName(versionedBytes).toString());
+    final String hostnamePortStr = sn.getHostAndPort();
     byte [] bytes = Bytes.toBytes(hostnamePortStr);
     String expecting =
       hostnamePortStr.replace(":", ServerName.SERVERNAME_SEPARATOR) +
@@ -69,8 +93,8 @@ public class TestServerName {
     assertEquals(sn.toString(),
       ServerName.getServerName("www.example.org:1234", 5678));
     assertEquals(sn.toString(),
-      "www.example.org" + ServerName.SERVERNAME_SEPARATOR +
-      "1234" + ServerName.SERVERNAME_SEPARATOR + "5678");
+      "www.example.org" + ServerName.SERVERNAME_SEPARATOR + "1234" +
+      ServerName.SERVERNAME_SEPARATOR + "5678");
   }
 
   @Test



Mime
View raw message