diff --git src/main/java/org/apache/hadoop/hbase/ClusterStatus.java src/main/java/org/apache/hadoop/hbase/ClusterStatus.java index 01bc1dd..681ce94 100644 --- src/main/java/org/apache/hadoop/hbase/ClusterStatus.java +++ src/main/java/org/apache/hadoop/hbase/ClusterStatus.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.TreeMap; import org.apache.hadoop.hbase.master.AssignmentManager.RegionState; +import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.io.VersionedWritable; /** @@ -214,12 +215,12 @@ public class ClusterStatus extends VersionedWritable { out.writeUTF(hbaseVersion); out.writeInt(getServersSize()); for (Map.Entry e: this.liveServers.entrySet()) { - out.writeUTF(e.getKey().toString()); + Bytes.writeByteArray(out, e.getKey().getVersionedBytes()); e.getValue().write(out); } out.writeInt(deadServers.size()); for (ServerName server: deadServers) { - out.writeUTF(server.toString()); + Bytes.writeByteArray(out, server.getVersionedBytes()); } out.writeInt(this.intransition.size()); for (Map.Entry e: this.intransition.entrySet()) { @@ -235,15 +236,15 @@ public class ClusterStatus extends VersionedWritable { int count = in.readInt(); this.liveServers = new HashMap(count); for (int i = 0; i < count; i++) { - String str = in.readUTF(); + byte [] versionedBytes = Bytes.readByteArray(in); HServerLoad hsl = new HServerLoad(); hsl.readFields(in); - this.liveServers.put(new ServerName(str), hsl); + this.liveServers.put(ServerName.parseVersionedServerName(versionedBytes), hsl); } count = in.readInt(); deadServers = new ArrayList(count); for (int i = 0; i < count; i++) { - deadServers.add(new ServerName(in.readUTF())); + deadServers.add(ServerName.parseVersionedServerName(Bytes.readByteArray(in))); } count = in.readInt(); this.intransition = new TreeMap(); diff --git src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java index ed8c421..a22c855 100644 --- src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java +++ src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java @@ -58,8 +58,7 @@ public class MasterAddressTracker extends ZooKeeperNodeTracker { * @return Server name or null if timed out. */ public ServerName getMasterAddress() { - byte [] data = super.getData(); - return data == null ? null : new ServerName(Bytes.toString(data)); + return bytesToServerName(super.getData()); } /** @@ -81,7 +80,14 @@ public class MasterAddressTracker extends ZooKeeperNodeTracker { */ public synchronized ServerName waitForMaster(long timeout) throws InterruptedException { - byte [] data = super.blockUntilAvailable(); - return data == null ? null : new ServerName(Bytes.toString(data)); + return bytesToServerName(super.blockUntilAvailable()); + } + + /** + * @param bytes Byte array of {@link ServerName#toString()} + * @return A {@link ServerName} instance. + */ + private ServerName bytesToServerName(final byte [] bytes) { + return bytes == null ? null: ServerName.parseVersionedServerName(bytes); } } \ No newline at end of file diff --git src/main/java/org/apache/hadoop/hbase/ServerName.java src/main/java/org/apache/hadoop/hbase/ServerName.java index 973ec1c..90d6acd 100644 --- src/main/java/org/apache/hadoop/hbase/ServerName.java +++ src/main/java/org/apache/hadoop/hbase/ServerName.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase; import java.util.Collection; +import java.util.regex.Pattern; import org.apache.hadoop.hbase.util.Addressing; import org.apache.hadoop.hbase.util.Bytes; @@ -37,19 +38,45 @@ import org.apache.hadoop.hbase.util.Bytes; * and the startcode for the regionserver is 1212121212, then * the {@link #toString()} would be example.org,1234,1212121212. * + *

You can obtain a versioned serialized form of this class by calling + * {@link #getVersionedBytes()}. To deserialize, call {@link #parseVersionedServerName(byte[])} + * *

Immutable. */ public class ServerName implements Comparable { /** + * Version for this class. + * Its a short rather than a byte so I can for sure distinguish between this + * version of this class and the version previous to this which did not have + * a version. + */ + private static final short VERSION = 0; + static final byte [] VERSION_BYTE = Bytes.toBytes(VERSION); + + /** + * What to use if no startcode supplied. + */ + public static final int NON_STARTCODE = -1; + + /** * This character is used as separator between server hostname, port and * startcode. */ public static final String SERVERNAME_SEPARATOR = ","; + public static Pattern SERVERNAME_PATTERN = + Pattern.compile(Addressing.VALID_HOSTNAME_REGEX_PREFIX + + SERVERNAME_SEPARATOR + Addressing.VALID_PORT_REGEX + + SERVERNAME_SEPARATOR + Addressing.VALID_PORT_REGEX + "$"); + private final String servername; private final String hostname; private final int port; private final long startcode; + + /** + * Cached bytes of this ServerName instance. + */ private byte [] bytes; public ServerName(final String hostname, final int port, final long startcode) { @@ -64,10 +91,6 @@ public class ServerName implements Comparable { parseStartcode(serverName)); } - public ServerName(final byte [] bytes) { - this(Bytes.toString(bytes)); - } - public ServerName(final String hostAndPort, final long startCode) { this(Addressing.parseHostname(hostAndPort), Addressing.parsePort(hostAndPort), startCode); @@ -97,10 +120,13 @@ public class ServerName implements Comparable { } /** - * @return {@link #getServerName()} as bytes + * @return {@link #getServerName()} as bytes with a short-sized prefix with + * the {@link ServerName#VERSION} of this class. */ - public synchronized byte [] getBytes() { - if (this.bytes == null) this.bytes = Bytes.toBytes(getServerName()); + public synchronized byte [] getVersionedBytes() { + if (this.bytes == null) { + this.bytes = Bytes.add(VERSION_BYTE, Bytes.toBytes(getServerName())); + } return this.bytes; } @@ -230,4 +256,34 @@ public class ServerName implements Comparable { return left.getHostname().equals(right.getHostname()) && left.getPort() == right.getPort(); } -} + + /** + * Use this method instantiating a {@link ServerName} from bytes + * gotten from a call to {@link #getVersionedBytes()}. Will take care of the + * case where bytes were written by an earlier version of hbase. + * @param versionedBytes Pass bytes gotten from a call to {@link #getVersionedBytes()} + * @return A ServerName instance. + * @see #getVersionedBytes() + */ + public static ServerName parseVersionedServerName(final byte [] versionedBytes) { + // Version is a short. + short version = Bytes.toShort(versionedBytes); + if (version == VERSION) { + int length = versionedBytes.length - Bytes.SIZEOF_SHORT; + return new ServerName(Bytes.toString(versionedBytes, Bytes.SIZEOF_SHORT, length)); + } + // Presume the bytes were written with an old version of hbase and that the + // bytes are actually a String of the form "'' ':' ''". + return new ServerName(Bytes.toString(versionedBytes), NON_STARTCODE); + } + + /** + * @param str Either an instance of {@link ServerName#toString()} or a + * "'' ':' ''". + * @return A ServerName instance. + */ + public static ServerName parseServerName(final String str) { + return SERVERNAME_PATTERN.matcher(str).matches()? new ServerName(str): + new ServerName(str, NON_STARTCODE); + } +} \ No newline at end of file diff --git src/main/java/org/apache/hadoop/hbase/executor/RegionTransitionData.java src/main/java/org/apache/hadoop/hbase/executor/RegionTransitionData.java index b537c37..7ae5d55 100644 --- src/main/java/org/apache/hadoop/hbase/executor/RegionTransitionData.java +++ src/main/java/org/apache/hadoop/hbase/executor/RegionTransitionData.java @@ -187,7 +187,8 @@ public class RegionTransitionData implements Writable { // remaining fields are optional so prefixed with boolean // the name of the regionserver sending the data if (in.readBoolean()) { - this.origin = new ServerName(in.readUTF()); + byte [] versionedBytes = Bytes.readByteArray(in); + this.origin = ServerName.parseVersionedServerName(versionedBytes); } if (in.readBoolean()) { this.payload = Bytes.readByteArray(in); @@ -201,8 +202,8 @@ public class RegionTransitionData implements Writable { Bytes.writeByteArray(out, regionName); // remaining fields are optional so prefixed with boolean out.writeBoolean(this.origin != null); - if(this.origin != null) { - out.writeUTF(this.origin.toString()); + if (this.origin != null) { + Bytes.writeByteArray(out, this.origin.getVersionedBytes()); } out.writeBoolean(this.payload != null); if (this.payload != null) { diff --git src/main/java/org/apache/hadoop/hbase/ipc/HMasterRegionInterface.java src/main/java/org/apache/hadoop/hbase/ipc/HMasterRegionInterface.java index 965102c..0dc5bea 100644 --- src/main/java/org/apache/hadoop/hbase/ipc/HMasterRegionInterface.java +++ src/main/java/org/apache/hadoop/hbase/ipc/HMasterRegionInterface.java @@ -55,7 +55,7 @@ public interface HMasterRegionInterface extends VersionedProtocol { throws IOException; /** - * @param sn {@link ServerName#getBytes()} + * @param sn {@link ServerName#getVersionedBytes()} * @param hsl Server load. * @throws IOException */ @@ -65,7 +65,7 @@ public interface HMasterRegionInterface extends VersionedProtocol { /** * Called by a region server to report a fatal error that is causing * it to abort. - * @param sn {@link ServerName#getBytes()} + * @param sn {@link ServerName#getVersionedBytes()} * @param errorMessage informative text to expose in the master logs and UI */ public void reportRSFatalError(byte [] sn, String errorMessage); diff --git src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java index 695fdf2..6fe7a78 100644 --- src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java +++ src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java @@ -145,7 +145,7 @@ class ActiveMasterManager extends ZooKeeperListener { this.clusterHasActiveMaster.set(true); byte [] bytes = ZKUtil.getDataAndWatch(this.watcher, this.watcher.masterAddressZNode); - ServerName currentMaster = new ServerName(Bytes.toString(bytes)); + ServerName currentMaster = ServerName.parseVersionedServerName(bytes); if (ServerName.isSameHostnameAndPort(currentMaster, this.sn)) { String msg = ("Current master has this master's address, " + currentMaster + "; master was restarted? Waiting on znode to expire..."); diff --git src/main/java/org/apache/hadoop/hbase/master/HMaster.java src/main/java/org/apache/hadoop/hbase/master/HMaster.java index cde36e1..01b2d85 100644 --- src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -25,7 +25,6 @@ import java.lang.reflect.InvocationTargetException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -41,11 +40,9 @@ import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HServerLoad; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.MasterNotRunningException; -import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableDescriptors; -import org.apache.hadoop.hbase.TableExistsException; import org.apache.hadoop.hbase.TableNotDisabledException; import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.UnknownRegionException; @@ -54,8 +51,8 @@ import org.apache.hadoop.hbase.catalog.MetaEditor; import org.apache.hadoop.hbase.catalog.MetaReader; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.MetaScanner; -import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor; +import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.executor.ExecutorService; import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorType; import org.apache.hadoop.hbase.ipc.HBaseRPC; @@ -63,7 +60,7 @@ import org.apache.hadoop.hbase.ipc.HBaseServer; import org.apache.hadoop.hbase.ipc.HMasterInterface; import org.apache.hadoop.hbase.ipc.HMasterRegionInterface; import org.apache.hadoop.hbase.ipc.RpcServer; -import org.apache.hadoop.hbase.master.RegionPlan; +import org.apache.hadoop.hbase.master.handler.CreateTableHandler; import org.apache.hadoop.hbase.master.handler.DeleteTableHandler; import org.apache.hadoop.hbase.master.handler.DisableTableHandler; import org.apache.hadoop.hbase.master.handler.EnableTableHandler; @@ -71,18 +68,14 @@ import org.apache.hadoop.hbase.master.handler.ModifyTableHandler; import org.apache.hadoop.hbase.master.handler.TableAddFamilyHandler; import org.apache.hadoop.hbase.master.handler.TableDeleteFamilyHandler; import org.apache.hadoop.hbase.master.handler.TableModifyFamilyHandler; -import org.apache.hadoop.hbase.master.handler.CreateTableHandler; import org.apache.hadoop.hbase.master.metrics.MasterMetrics; import org.apache.hadoop.hbase.monitoring.MemoryBoundedLogMessageBuffer; import org.apache.hadoop.hbase.monitoring.MonitoredTask; import org.apache.hadoop.hbase.monitoring.TaskMonitor; -import org.apache.hadoop.hbase.regionserver.HRegion; -import org.apache.hadoop.hbase.regionserver.wal.HLog; import org.apache.hadoop.hbase.replication.regionserver.Replication; import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.FSTableDescriptors; -import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.InfoServer; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.Sleeper; @@ -762,7 +755,7 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { @Override public void regionServerReport(final byte [] sn, final HServerLoad hsl) throws IOException { - this.serverManager.regionServerReport(new ServerName(sn), hsl); + this.serverManager.regionServerReport(ServerName.parseVersionedServerName(sn), hsl); if (hsl != null && this.metrics != null) { // Up our metrics. this.metrics.incrementRequests(hsl.getTotalNumberOfRequests()); @@ -771,9 +764,8 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { @Override public void reportRSFatalError(byte [] sn, String errorText) { - ServerName serverName = new ServerName(sn); - String msg = "Region server " + serverName + " reported a fatal error:\n" - + errorText; + String msg = "Region server " + Bytes.toString(sn) + + " reported a fatal error:\n" + errorText; LOG.error(msg); rsFatals.add(msg); } diff --git src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java index b9c850d..f06e89b 100644 --- src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java +++ src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java @@ -205,7 +205,11 @@ public class MasterFileSystem { } List serverNames = new ArrayList(); for (FileStatus status : logFolders) { - ServerName serverName = new ServerName(status.getPath().getName()); + String sn = status.getPath().getName(); + // Is this old or new style servername? If old style, it will be + // hostname, colon, and port. If new style, it will be formatted as + // ServerName.toString. + ServerName serverName = ServerName.parseServerName(sn); if (!onlineServers.contains(serverName)) { LOG.info("Log folder " + status.getPath() + " doesn't belong " + "to a known region server, splitting"); diff --git src/main/java/org/apache/hadoop/hbase/master/ServerManager.java src/main/java/org/apache/hadoop/hbase/master/ServerManager.java index f994f99..49aca7c 100644 --- src/main/java/org/apache/hadoop/hbase/master/ServerManager.java +++ src/main/java/org/apache/hadoop/hbase/master/ServerManager.java @@ -249,7 +249,7 @@ public class ServerManager { * @deprecated Use {@link #getLoad(HServerAddress)} */ public HServerLoad getLoad(final HServerAddress address) { - ServerName sn = new ServerName(address.toString(), -1); + ServerName sn = new ServerName(address.toString(), ServerName.NON_STARTCODE); ServerName actual = ServerName.findServerWithSameHostnamePort(this.getOnlineServersList(), sn); return actual == null? null: getLoad(actual); diff --git src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index cd809ba..d9ab73f 100644 --- src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -742,7 +742,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, // Why we do this? this.requestCount.set(0); try { - this.hbaseMaster.regionServerReport(this.serverNameFromMasterPOV.getBytes(), hsl); + this.hbaseMaster.regionServerReport(this.serverNameFromMasterPOV.getVersionedBytes(), hsl); } catch (IOException ioe) { if (ioe instanceof RemoteException) { ioe = ((RemoteException)ioe).unwrapRemoteException(); @@ -1501,7 +1501,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, } if (hbaseMaster != null) { hbaseMaster.reportRSFatalError( - this.serverNameFromMasterPOV.getBytes(), msg); + this.serverNameFromMasterPOV.getVersionedBytes(), msg); } } catch (Throwable t) { LOG.warn("Unable to report fatal error to master", t); diff --git src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java index 6ba24c0..6df265d 100644 --- src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java +++ src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java @@ -246,7 +246,7 @@ public class ReplicationZookeeper { } List addresses = new ArrayList(children.size()); for (String child : children) { - addresses.add(new ServerName(child)); + addresses.add(ServerName.parseServerName(child)); } return addresses; } diff --git src/main/java/org/apache/hadoop/hbase/util/Addressing.java src/main/java/org/apache/hadoop/hbase/util/Addressing.java index 714e2d9..4fb7769 100644 --- src/main/java/org/apache/hadoop/hbase/util/Addressing.java +++ src/main/java/org/apache/hadoop/hbase/util/Addressing.java @@ -25,6 +25,21 @@ import java.net.InetSocketAddress; * Utility for network addresses, resolving and naming. */ public class Addressing { + /** + * Regex for RFC952 hostname matching. Does not have a '$" on the end. Can + * be used as prefix on a larger regex. + * @see http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address + */ + public static final String VALID_HOSTNAME_REGEX_PREFIX = + "^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\\-]*[A-Za-z0-9])"; + /** + * Regex for RFC952 hostname matching. + * @see http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address + */ + public static final String VALID_HOSTNAME_REGEX = + VALID_HOSTNAME_REGEX_PREFIX + "$"; + + public static final String VALID_PORT_REGEX = "[\\d]+"; public static final String HOSTNAME_PORT_SEPARATOR = ":"; /** diff --git src/main/java/org/apache/hadoop/hbase/zookeeper/RegionServerTracker.java src/main/java/org/apache/hadoop/hbase/zookeeper/RegionServerTracker.java index 83a51bd..cb94ddb 100644 --- src/main/java/org/apache/hadoop/hbase/zookeeper/RegionServerTracker.java +++ src/main/java/org/apache/hadoop/hbase/zookeeper/RegionServerTracker.java @@ -30,7 +30,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.Abortable; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.master.ServerManager; -import org.apache.hadoop.hbase.zookeeper.ZKUtil.NodeAndData; import org.apache.zookeeper.KeeperException; /** @@ -75,7 +74,7 @@ public class RegionServerTracker extends ZooKeeperListener { synchronized(this.regionServers) { this.regionServers.clear(); for (String n: servers) { - ServerName sn = new ServerName(ZKUtil.getNodeName(n)); + ServerName sn = ServerName.parseServerName(ZKUtil.getNodeName(n)); this.regionServers.add(sn); } } @@ -93,7 +92,7 @@ public class RegionServerTracker extends ZooKeeperListener { String serverName = ZKUtil.getNodeName(path); LOG.info("RegionServer ephemeral node deleted, processing expiration [" + serverName + "]"); - ServerName sn = new ServerName(serverName); + ServerName sn = ServerName.parseServerName(serverName); if (!serverManager.isServerOnline(sn)) { LOG.info(serverName.toString() + " is not online"); return; diff --git src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java index 51f7725..663d177 100644 --- src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java +++ src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java @@ -94,7 +94,7 @@ public class RootRegionTracker extends ZooKeeperNodeTracker { int index = str.indexOf(ServerName.SERVERNAME_SEPARATOR); if (index != -1) { // Presume its ServerName.toString() format. - return new ServerName(str); + return ServerName.parseServerName(str); } // Presume it a hostname:port format. String hostname = Addressing.parseHostname(str); diff --git src/test/java/org/apache/hadoop/hbase/TestServerName.java src/test/java/org/apache/hadoop/hbase/TestServerName.java index 298fbe6..e3bc432 100644 --- src/test/java/org/apache/hadoop/hbase/TestServerName.java +++ src/test/java/org/apache/hadoop/hbase/TestServerName.java @@ -1,6 +1,4 @@ /** - * Copyright 2011 The Apache Software Foundation - * * 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 @@ -19,15 +17,42 @@ */ package org.apache.hadoop.hbase; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; -import java.util.HashSet; -import java.util.Set; +import java.util.regex.Pattern; +import org.apache.hadoop.hbase.util.Addressing; +import org.apache.hadoop.hbase.util.Bytes; import org.junit.Test; public class TestServerName { @Test + public void testRegexPatterns() { + assertTrue(Pattern.matches(Addressing.VALID_PORT_REGEX, "123")); + assertFalse(Pattern.matches(Addressing.VALID_PORT_REGEX, "")); + assertTrue(Pattern.matches(Addressing.VALID_HOSTNAME_REGEX, "example.org")); + assertTrue(Pattern.matches(Addressing.VALID_HOSTNAME_REGEX, + "www1.example.org")); + assertTrue(ServerName.SERVERNAME_PATTERN.matcher("www1.example.org,1234,567").matches()); + } + + @Test public void testParseOfBytes() { + 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"; + byte [] bytes = Bytes.toBytes(hostnamePortStr); + String expecting = + hostnamePortStr.replace(":", ServerName.SERVERNAME_SEPARATOR) + + ServerName.SERVERNAME_SEPARATOR + ServerName.NON_STARTCODE; + assertEquals(expecting, ServerName.parseVersionedServerName(bytes).toString()); + } + + @Test public void testServerName() { ServerName sn = new ServerName("www.example.org", 1234, 5678); ServerName sn2 = new ServerName("www.example.org", 1234, 5678); diff --git src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressManager.java src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressManager.java index 47f52d6..ff4c8dd 100644 --- src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressManager.java +++ src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterAddressManager.java @@ -77,7 +77,7 @@ public class TestMasterAddressManager { int port = 1234; ServerName sn = new ServerName(host, port, System.currentTimeMillis()); LOG.info("Creating master node"); - ZKUtil.createEphemeralNodeAndWatch(zk, zk.masterAddressZNode, sn.getBytes()); + ZKUtil.createEphemeralNodeAndWatch(zk, zk.masterAddressZNode, sn.getVersionedBytes()); // Wait for the node to be created LOG.info("Waiting for master address manager to be notified"); diff --git src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java index b8ab708..2ee4227 100644 --- src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java +++ src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java @@ -405,7 +405,7 @@ public class TestSplitTransactionOnCluster { HRegionServer hrs = getOtherRegionServer(cluster, metaRegionServer); LOG.info("Moving " + hri.getRegionNameAsString() + " to " + hrs.getServerName() + "; metaServerIndex=" + metaServerIndex); - admin.move(hri.getEncodedNameAsBytes(), hrs.getServerName().getBytes()); + admin.move(hri.getEncodedNameAsBytes(), hrs.getServerName().getVersionedBytes()); } // Wait till table region is up on the server that is NOT carrying .META.. while (true) {