hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1097275 [2/8] - in /hbase/trunk: ./ src/docbkx/ src/main/java/org/apache/hadoop/hbase/ src/main/java/org/apache/hadoop/hbase/avro/ src/main/java/org/apache/hadoop/hbase/catalog/ src/main/java/org/apache/hadoop/hbase/client/ src/main/java/o...
Date Wed, 27 Apr 2011 23:12:44 GMT
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerInfo.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerInfo.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerInfo.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerInfo.java Wed Apr 27 23:12:42 2011
@@ -23,77 +23,48 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.net.InetSocketAddress;
-import java.util.Comparator;
-import java.util.Set;
 
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.io.VersionedWritable;
-import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableComparable;
 
 
 /**
- * HServerInfo is meta info about an {@link HRegionServer}.  It is the token
- * by which a master distingushes a particular regionserver from the rest.
- * It holds hostname, ports, regionserver startcode, and load.  Each server has
- * a <code>servername</code> where servername is made up of a concatenation of
- * hostname, port, and regionserver startcode.  This servername is used in
- * various places identifying this regionserver.  Its even used as part of
- * a pathname in the filesystem.  As part of the initialization,
- * master will pass the regionserver the address that it knows this regionserver
- * by.  In subsequent communications, the regionserver will pass a HServerInfo
- * with the master-supplied address.
+ * HServerInfo is meta info about an {@link HRegionServer}.  It hosts the
+ * {@link HServerAddress}, its webui port, and its server startcode.  It was
+ * used to pass meta info about a server across an RPC but we've since made
+ * it so regionserver info is up in ZooKeeper and so this class is on its
+ * way out. It used to carry {@link HServerLoad} but as off HBase 0.92.0, the
+ * HServerLoad is passed independent of this class. Also, we now no longer pass
+ * the webui from regionserver to master (TODO: Fix).
+ * @deprecated Use {@link InetSocketAddress} and or {@link ServerName} and or
+ * {@link HServerLoad}
  */
 public class HServerInfo extends VersionedWritable
-  implements WritableComparable<HServerInfo> {
-  private static final byte VERSION = 0;
-  
-  /*
-   * This character is used as separator between server hostname and port and
-   * its startcode. Servername is formatted as
-   * <code>&lt;hostname> '{@ink #SERVERNAME_SEPARATOR"}' &lt;port> '{@ink #SERVERNAME_SEPARATOR"}' &lt;startcode></code>.
-   */
-  private static final String SERVERNAME_SEPARATOR = ",";
-
-  private HServerAddress serverAddress;
+implements WritableComparable<HServerInfo> {
+  private static final byte VERSION = 1;
+  private HServerAddress serverAddress = new HServerAddress();
   private long startCode;
-  private HServerLoad load;
-  private int infoPort;
-  // Servername is made of hostname, port and startcode.
-  private String serverName = null;
-  // Hostname of the regionserver.
-  private String hostname;
-  private String cachedHostnamePort = null;
-
-  /** @return the object version number */
-  public byte getVersion() {
-    return VERSION;
-  }
+  private int webuiport;
 
   public HServerInfo() {
-    this(new HServerAddress(), 0, HConstants.DEFAULT_REGIONSERVER_INFOPORT,
-      "default name");
+    super();
   }
 
   /**
-   * Constructor that creates a HServerInfo with a generated startcode and an
-   * empty load.
-   * @param serverAddress An {@link InetSocketAddress} encased in a {@link Writable}
-   * @param infoPort Port the webui runs on.
-   * @param hostname Server hostname.
+   * Constructor that creates a HServerInfo with a generated startcode
+   * @param serverAddress
+   * @param webuiport Port the webui runs on.
    */
-  public HServerInfo(HServerAddress serverAddress, final int infoPort,
-      final String hostname) {
-    this(serverAddress, System.currentTimeMillis(), infoPort, hostname);
+  public HServerInfo(final HServerAddress serverAddress, final int webuiport) {
+    this(serverAddress, System.currentTimeMillis(), webuiport);
   }
 
   public HServerInfo(HServerAddress serverAddress, long startCode,
-      final int infoPort, String hostname) {
+      final int webuiport) {
     this.serverAddress = serverAddress;
     this.startCode = startCode;
-    this.load = new HServerLoad();
-    this.infoPort = infoPort;
-    this.hostname = hostname;
+    this.webuiport = webuiport;
   }
 
   /**
@@ -103,106 +74,32 @@ public class HServerInfo extends Version
   public HServerInfo(HServerInfo other) {
     this.serverAddress = new HServerAddress(other.getServerAddress());
     this.startCode = other.getStartCode();
-    this.load = other.getLoad();
-    this.infoPort = other.getInfoPort();
-    this.hostname = other.hostname;
+    this.webuiport = other.getInfoPort();
   }
 
-  public HServerLoad getLoad() {
-    return load;
-  }
-
-  public void setLoad(HServerLoad load) {
-    this.load = load;
+  /** @return the object version number */
+  public byte getVersion() {
+    return VERSION;
   }
 
   public synchronized HServerAddress getServerAddress() {
     return new HServerAddress(serverAddress);
   }
 
-  public synchronized void setServerAddress(HServerAddress serverAddress) {
-    this.serverAddress = serverAddress;
-    this.hostname = serverAddress.getHostname();
-    this.serverName = null;
-  }
-
   public synchronized long getStartCode() {
     return startCode;
   }
 
   public int getInfoPort() {
-    return this.infoPort;
-  }
-
-  public String getHostname() {
-    return this.hostname;
-  }
-
-  /**
-   * @return The hostname and port concatenated with a ':' as separator.
-   */
-  public synchronized String getHostnamePort() {
-    if (this.cachedHostnamePort == null) {
-      this.cachedHostnamePort = getHostnamePort(this.hostname, this.serverAddress.getPort());
-    }
-    return this.cachedHostnamePort;
+    return getWebuiPort();
   }
 
-  /**
-   * @param hostname
-   * @param port
-   * @return The hostname and port concatenated with a ':' as separator.
-   */
-  public static String getHostnamePort(final String hostname, final int port) {
-    return hostname + ":" + port;
+  public int getWebuiPort() {
+    return this.webuiport;
   }
 
-  /**
-   * Gets the unique server instance name.  Includes the hostname, port, and
-   * start code.
-   * @return Server name made of the concatenation of hostname, port and
-   * startcode formatted as <code>&lt;hostname> ',' &lt;port> ',' &lt;startcode></code>
-   */
-  public synchronized String getServerName() {
-    if (this.serverName == null) {
-      this.serverName = getServerName(this.hostname,
-        this.serverAddress.getPort(), this.startCode);
-    }
-    return this.serverName;
-  }
-
-  public static synchronized String getServerName(final String hostAndPort,
-      final long startcode) {
-    int index = hostAndPort.indexOf(":");
-    if (index <= 0) throw new IllegalArgumentException("Expected <hostname> ':' <port>");
-    return getServerName(hostAndPort.substring(0, index),
-      Integer.parseInt(hostAndPort.substring(index + 1)), startcode);
-  }
-
-  /**
-   * @param address Server address
-   * @param startCode Server 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(HServerAddress address, long startCode) {
-    return getServerName(address.getHostname(), address.getPort(), startCode);
-  }
-
-  /*
-   * @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) {
-    StringBuilder name = new StringBuilder(hostName);
-    name.append(SERVERNAME_SEPARATOR);
-    name.append(port);
-    name.append(SERVERNAME_SEPARATOR);
-    name.append(startCode);
-    return name.toString();
+  public String getHostname() {
+    return this.serverAddress.getHostname();
   }
 
   /**
@@ -211,97 +108,46 @@ public class HServerInfo extends Version
    * @see #getLoad()
    */
   @Override
-  public String toString() {
-    return "serverName=" + getServerName() +
-      ", load=(" + this.load.toString() + ")";
+  public synchronized String toString() {
+    return ServerName.getServerName(this.serverAddress.getHostnameAndPort(),
+      this.startCode);
   }
 
   @Override
   public boolean equals(Object obj) {
-    if (this == obj) {
-      return true;
-    }
-    if (obj == null) {
-      return false;
-    }
-    if (getClass() != obj.getClass()) {
-      return false;
-    }
+    if (this == obj) return true;
+    if (obj == null) return false;
+    if (getClass() != obj.getClass()) return false;
     return compareTo((HServerInfo)obj) == 0;
   }
 
   @Override
   public int hashCode() {
-    return this.getServerName().hashCode();
+    int code = this.serverAddress.hashCode();
+    code ^= this.webuiport;
+    code ^= this.startCode;
+    return code;
   }
 
   public void readFields(DataInput in) throws IOException {
+    super.readFields(in);
     this.serverAddress.readFields(in);
     this.startCode = in.readLong();
-    this.load.readFields(in);
-    this.infoPort = in.readInt();
-    this.hostname = in.readUTF();
+    this.webuiport = in.readInt();
   }
 
   public void write(DataOutput out) throws IOException {
+    super.write(out);
     this.serverAddress.write(out);
     out.writeLong(this.startCode);
-    this.load.write(out);
-    out.writeInt(this.infoPort);
-    out.writeUTF(hostname);
+    out.writeInt(this.webuiport);
   }
 
   public int compareTo(HServerInfo o) {
-    return this.getServerName().compareTo(o.getServerName());
-  }
-
-  /**
-   * Orders HServerInfos by load then name.  Natural/ascending order.
-   */
-  public static class LoadComparator implements Comparator<HServerInfo> {
-    @Override
-    public int compare(HServerInfo left, HServerInfo right) {
-      int loadCompare = left.getLoad().compareTo(right.getLoad());
-      return loadCompare != 0 ? loadCompare : left.compareTo(right);
-    }
-  }
-
-  /**
-   * Utility method that does a find of a servername or a hostandport combination
-   * in the passed Set.
-   * @param servers Set of server names
-   * @param serverName Name to look for
-   * @param hostAndPortOnly If <code>serverName</code> is a
-   * <code>hostname ':' port</code>
-   * or <code>hostname , port , startcode</code>.
-   * @return True if <code>serverName</code> found in <code>servers</code>
-   */
-  public static boolean isServer(final Set<String> servers,
-      final String serverName, final boolean hostAndPortOnly) {
-    if (!hostAndPortOnly) return servers.contains(serverName);
-    String serverNameColonReplaced =
-      serverName.replaceFirst(":", SERVERNAME_SEPARATOR);
-    for (String hostPortStartCode: servers) {
-      int index = hostPortStartCode.lastIndexOf(SERVERNAME_SEPARATOR);
-      String hostPortStrippedOfStartCode = hostPortStartCode.substring(0, index);
-      if (hostPortStrippedOfStartCode.equals(serverNameColonReplaced)) return true;
-    }
-    return false;
-  }
-
-  /**
-   * Utility method to excise the start code from a server name
-   * @param inServerName full server name
-   * @return server name less its start code
-   */
-  public static String getServerNameLessStartCode(String inServerName) {
-    if (inServerName != null && inServerName.length() > 0) {
-      int index = inServerName.lastIndexOf(SERVERNAME_SEPARATOR);
-      if (index > 0) {
-        return inServerName.substring(0, index);
-      }
-    }
-    return inServerName;
+    int compare = this.serverAddress.compareTo(o.getServerAddress());
+    if (compare != 0) return compare;
+    if (this.webuiport != o.getInfoPort()) return this.webuiport - o.getInfoPort();
+    if (this.startCode != o.getStartCode()) return (int)(this.startCode - o.getStartCode());
+    return 0;
   }
-
-}
+}
\ No newline at end of file

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerLoad.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerLoad.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerLoad.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerLoad.java Wed Apr 27 23:12:42 2011
@@ -29,29 +29,31 @@ import java.util.TreeMap;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Strings;
 import org.apache.hadoop.io.VersionedWritable;
-import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableComparable;
 
 /**
- * This class encapsulates metrics for determining the load on a HRegionServer
+ * This class is used exporting current state of load on a RegionServer.
  */
 public class HServerLoad extends VersionedWritable
-  implements WritableComparable<HServerLoad> {
-  private static final byte VERSION = 0;
+implements WritableComparable<HServerLoad> {
+  private static final byte VERSION = 1;
+  // Empty load instance.
+  public static final HServerLoad EMPTY_HSERVERLOAD = new HServerLoad();
+
+  /** Number of requests since last report
+   */
+  // TODO: Instead build this up out of region counters.
+  private int numberOfRequests = 0;
 
-  /** number of regions */
-    // could just use regionLoad.size() but master.RegionManager likes to play
-    // around with this value while passing HServerLoad objects around during
-    // balancer calculations
-  private int numberOfRegions;
-  /** number of requests since last report */
-  private int numberOfRequests;
   /** the amount of used heap, in MB */
-  private int usedHeapMB;
+  private int usedHeapMB = 0;
+
   /** the maximum allowable size of the heap, in MB */
-  private int maxHeapMB;
+  private int maxHeapMB = 0;
+
   /** per-region load metrics */
-  private Map<byte[], RegionLoad> regionLoad = new TreeMap<byte[], RegionLoad>(Bytes.BYTES_COMPARATOR);
+  private Map<byte[], RegionLoad> regionLoad =
+    new TreeMap<byte[], RegionLoad>(Bytes.BYTES_COMPARATOR);
 
   /** @return the object version number */
   public byte getVersion() {
@@ -61,7 +63,14 @@ public class HServerLoad extends Version
   /**
    * Encapsulates per-region loading metrics.
    */
-  public static class RegionLoad implements Writable {
+  public static class RegionLoad extends VersionedWritable {
+    private static final byte VERSION = 0;
+
+    /** @return the object version number */
+    public byte getVersion() {
+      return VERSION;
+    }
+
     /** the region name */
     private byte[] name;
     /** the number of stores for the region */
@@ -236,6 +245,9 @@ public class HServerLoad extends Version
 
     // Writable
     public void readFields(DataInput in) throws IOException {
+      super.readFields(in);
+      int version = getVersion();
+      if (version != VERSION) throw new IOException("Version mismatch; " + version);
       int namelen = in.readInt();
       this.name = new byte[namelen];
       in.readFully(this.name);
@@ -249,6 +261,7 @@ public class HServerLoad extends Version
     }
 
     public void write(DataOutput out) throws IOException {
+      super.write(out);
       out.writeInt(name.length);
       out.write(name);
       out.writeInt(stores);
@@ -308,10 +321,11 @@ public class HServerLoad extends Version
    * @param maxHeapMB
    */
   public HServerLoad(final int numberOfRequests, final int usedHeapMB,
-      final int maxHeapMB) {
+      final int maxHeapMB, final Map<byte[], RegionLoad> regionLoad) {
     this.numberOfRequests = numberOfRequests;
     this.usedHeapMB = usedHeapMB;
     this.maxHeapMB = maxHeapMB;
+    this.regionLoad = regionLoad;
   }
 
   /**
@@ -319,7 +333,7 @@ public class HServerLoad extends Version
    * @param hsl the template HServerLoad
    */
   public HServerLoad(final HServerLoad hsl) {
-    this(hsl.numberOfRequests, hsl.usedHeapMB, hsl.maxHeapMB);
+    this(hsl.numberOfRequests, hsl.usedHeapMB, hsl.maxHeapMB, hsl.getRegionsLoad());
     for (Map.Entry<byte[], RegionLoad> e : hsl.regionLoad.entrySet()) {
       this.regionLoad.put(e.getKey(), e.getValue());
     }
@@ -338,7 +352,7 @@ public class HServerLoad extends Version
     // int load = numberOfRequests == 0 ? 1 : numberOfRequests;
     // load *= numberOfRegions == 0 ? 1 : numberOfRegions;
     // return load;
-    return numberOfRegions;
+    return this.regionLoad.size();
   }
 
   /**
@@ -356,6 +370,7 @@ public class HServerLoad extends Version
    * @return The load as a String
    */
   public String toString(int msgInterval) {
+    int numberOfRegions = this.regionLoad.size();
     StringBuilder sb = new StringBuilder();
     sb = Strings.appendKeyValue(sb, "requests",
       Integer.valueOf(numberOfRequests/msgInterval));
@@ -384,23 +399,13 @@ public class HServerLoad extends Version
     return compareTo((HServerLoad)o) == 0;
   }
 
-  /**
-   * @see java.lang.Object#hashCode()
-   */
-  @Override
-  public int hashCode() {
-    int result = Integer.valueOf(numberOfRequests).hashCode();
-    result ^= Integer.valueOf(numberOfRegions).hashCode();
-    return result;
-  }
-
   // Getters
 
   /**
    * @return the numberOfRegions
    */
   public int getNumberOfRegions() {
-    return numberOfRegions;
+    return this.regionLoad.size();
   }
 
   /**
@@ -471,69 +476,16 @@ public class HServerLoad extends Version
     return count;
   }
 
-  // Setters
-
-  /**
-   * @param numberOfRegions the number of regions
-   */
-  public void setNumberOfRegions(int numberOfRegions) {
-    this.numberOfRegions = numberOfRegions;
-  }
-
-  /**
-   * @param numberOfRequests the number of requests to set
-   */
-  public void setNumberOfRequests(int numberOfRequests) {
-    this.numberOfRequests = numberOfRequests;
-  }
-
-  /**
-   * @param usedHeapMB the amount of heap in use, in MB
-   */
-  public void setUsedHeapMB(int usedHeapMB) {
-    this.usedHeapMB = usedHeapMB;
-  }
-
-  /**
-   * @param maxHeapMB the maximum allowable heap size, in MB
-   */
-  public void setMaxHeapMB(int maxHeapMB) {
-    this.maxHeapMB = maxHeapMB;
-  }
-
-  /**
-   * @param load Instance of HServerLoad
-   */
-  public void addRegionInfo(final HServerLoad.RegionLoad load) {
-    this.numberOfRegions++;
-    this.regionLoad.put(load.getName(), load);
-  }
-
-  /**
-   * @param name
-   * @param stores
-   * @param storefiles
-   * @param memstoreSizeMB
-   * @param storefileIndexSizeMB
-   * @param requestsCount
-   * @deprecated Use {@link #addRegionInfo(RegionLoad)}
-   */
-  @Deprecated
-  public void addRegionInfo(final byte[] name, final int stores,
-      final int storefiles, final int storefileSizeMB,
-      final int memstoreSizeMB, final int storefileIndexSizeMB,
-      final int readRequestsCount, final int writeRequestsCount) {
-    this.regionLoad.put(name, new HServerLoad.RegionLoad(name, stores, storefiles,
-      storefileSizeMB, memstoreSizeMB, storefileIndexSizeMB, readRequestsCount, writeRequestsCount));
-  }
-
   // Writable
 
   public void readFields(DataInput in) throws IOException {
+    super.readFields(in);
+    int version = getVersion();
+    if (version != VERSION) throw new IOException("Version mismatch; " + version);
     numberOfRequests = in.readInt();
     usedHeapMB = in.readInt();
     maxHeapMB = in.readInt();
-    numberOfRegions = in.readInt();
+    int numberOfRegions = in.readInt();
     for (int i = 0; i < numberOfRegions; i++) {
       RegionLoad rl = new RegionLoad();
       rl.readFields(in);
@@ -542,10 +494,11 @@ public class HServerLoad extends Version
   }
 
   public void write(DataOutput out) throws IOException {
+    super.write(out);
     out.writeInt(numberOfRequests);
     out.writeInt(usedHeapMB);
     out.writeInt(maxHeapMB);
-    out.writeInt(numberOfRegions);
+    out.writeInt(this.regionLoad.size());
     for (RegionLoad rl: regionLoad.values())
       rl.write(out);
   }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java Wed Apr 27 23:12:42 2011
@@ -254,12 +254,10 @@ public class LocalHBaseCluster {
     while (regionServerThread.isAlive()) {
       try {
         LOG.info("Waiting on " +
-          regionServerThread.getRegionServer().getHServerInfo().toString());
+          regionServerThread.getRegionServer().toString());
         regionServerThread.join();
       } catch (InterruptedException e) {
         e.printStackTrace();
-      } catch (IOException e) {
-        e.printStackTrace();
       }
     }
     return regionServerThread.getName();
@@ -275,12 +273,10 @@ public class LocalHBaseCluster {
     while (rst.isAlive()) {
       try {
         LOG.info("Waiting on " +
-          rst.getRegionServer().getHServerInfo().toString());
+          rst.getRegionServer().toString());
         rst.join();
       } catch (InterruptedException e) {
         e.printStackTrace();
-      } catch (IOException e) {
-        e.printStackTrace();
       }
     }
     for (int i=0;i<regionThreads.size();i++) {
@@ -451,4 +447,4 @@ public class LocalHBaseCluster {
     admin.createTable(htd);
     cluster.shutdown();
   }
-}
+}
\ No newline at end of file

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java Wed Apr 27 23:12:42 2011
@@ -55,12 +55,11 @@ public class MasterAddressTracker extend
   /**
    * Get the address of the current master if one is available.  Returns null
    * if no current master.
-   *
-   * @return server address of current active master, or null if none available
+   * @return Server name or null if timed out.
    */
-  public HServerAddress getMasterAddress() {
+  public ServerName getMasterAddress() {
     byte [] data = super.getData();
-    return data == null ? null : new HServerAddress(Bytes.toString(data));
+    return data == null ? null : new ServerName(Bytes.toString(data));
   }
 
   /**
@@ -77,12 +76,12 @@ public class MasterAddressTracker extend
    * has passed.
    *
    * @param timeout maximum time to wait for master in millis, 0 for forever
-   * @return server address of current active master, null if timed out
+   * @return String of master host and port or null if timed out.
    * @throws InterruptedException if the thread is interrupted while waiting
    */
-  public synchronized HServerAddress waitForMaster(long timeout)
+  public synchronized ServerName waitForMaster(long timeout)
   throws InterruptedException {
     byte [] data = super.blockUntilAvailable();
-    return data == null ? null : new HServerAddress(Bytes.toString(data));
+    return data == null ? null : new ServerName(Bytes.toString(data));
   }
-}
+}
\ No newline at end of file

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/Server.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/Server.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/Server.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/Server.java Wed Apr 27 23:12:42 2011
@@ -44,11 +44,7 @@ public interface Server extends Abortabl
   public CatalogTracker getCatalogTracker();
 
   /**
-   * Gets the unique server name for this server.
-   * If a RegionServer, it returns a concatenation of hostname, port and
-   * startcode formatted as <code>&lt;hostname> ',' &lt;port> ',' &lt;startcode></code>.
-   * If the master, it returns <code>&lt;hostname> ':' &lt;port>'.
-   * @return unique server name
+   * @return The unique server name for this server.
    */
-  public String getServerName();
+  public ServerName getServerName();
 }
\ No newline at end of file

Added: hbase/trunk/src/main/java/org/apache/hadoop/hbase/ServerName.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/ServerName.java?rev=1097275&view=auto
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/ServerName.java (added)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/ServerName.java Wed Apr 27 23:12:42 2011
@@ -0,0 +1,221 @@
+/**
+ * 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
+ * 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.
+ */
+package org.apache.hadoop.hbase;
+
+import java.util.Collection;
+
+import org.apache.hadoop.hbase.util.Addressing;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * 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:
+ * <code>&lt;hostname> '{@link #SERVERNAME_SEPARATOR"}' &lt;port> '{@ink #SERVERNAME_SEPARATOR"}' &lt;startcode></code>.
+ * For example, if hostname is <code>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>.
+ * 
+ * <p>Immutable.
+ */
+public class ServerName implements Comparable<ServerName> {
+  /**
+   * This character is used as separator between server hostname, port and
+   * startcode.
+   */
+  public static final String SERVERNAME_SEPARATOR = ",";
+
+  private final String servername;
+  private final String hostname;
+  private final int port;
+  private final long startcode;
+  private byte [] bytes;
+
+  public ServerName(final String hostname, final int port, final long startcode) {
+    this.hostname = hostname;
+    this.port = port;
+    this.startcode = startcode;
+    this.servername = getServerName(hostname, port, startcode);
+  }
+
+  public ServerName(final String serverName) {
+    this(parseHostname(serverName), parsePort(serverName),
+      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);
+  }
+
+  public static String parseHostname(final String serverName) {
+    if (serverName == null || serverName.length() <= 0) {
+      throw new IllegalArgumentException("Passed hostname is null or empty");
+    }
+    int index = serverName.indexOf(SERVERNAME_SEPARATOR);
+    return serverName.substring(0, index);
+  }
+
+  public static int parsePort(final String serverName) {
+    String [] split = serverName.split(SERVERNAME_SEPARATOR);
+    return Integer.parseInt(split[1]);
+  }
+
+  public static long parseStartcode(final String serverName) {
+    int index = serverName.lastIndexOf(SERVERNAME_SEPARATOR);
+    return Long.parseLong(serverName.substring(index + 1));
+  }
+
+  @Override
+  public String toString() {
+    return getServerName();
+  }
+
+  /**
+   * @return {@link #getServerName()} as bytes
+   */
+  public synchronized byte [] getBytes() {
+    if (this.bytes == null) this.bytes = Bytes.toBytes(getServerName());
+    return this.bytes;
+  }
+
+  public String getServerName() {
+    return servername;
+  }
+
+  public String getHostname() {
+    return hostname;
+  }
+
+  public int getPort() {
+    return port;
+  }
+
+  public long getStartcode() {
+    return startcode;
+  }
+
+  /**
+   * @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) {
+    StringBuilder name = new StringBuilder(hostName);
+    name.append(SERVERNAME_SEPARATOR);
+    name.append(port);
+    name.append(SERVERNAME_SEPARATOR);
+    name.append(startcode);
+    return name.toString();
+  }
+
+  /**
+   * @param hostAndPort String in form of &lt;hostname> ':' &lt;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 synchronized String getServerName(final String hostAndPort,
+      final long startcode) {
+    int index = hostAndPort.indexOf(":");
+    if (index <= 0) throw new IllegalArgumentException("Expected <hostname> ':' <port>");
+    return getServerName(hostAndPort.substring(0, index),
+      Integer.parseInt(hostAndPort.substring(index + 1)), startcode);
+  }
+
+  /**
+   * @return Hostname and port formatted as described at
+   * {@link Addressing#createHostAndPortStr(String, int)}
+   */
+  public String getHostAndPort() {
+    return Addressing.createHostAndPortStr(this.hostname, this.port);
+  }
+
+  /**
+   * @param serverName ServerName in form specified by {@link #getServerName()}
+   * @return The server start code parsed from <code>servername</code>
+   */
+  public static long getServerStartcodeFromServerName(final String serverName) {
+    int index = serverName.lastIndexOf(SERVERNAME_SEPARATOR);
+    return Long.parseLong(serverName.substring(index + 1));
+  }
+
+  /**
+   * Utility method to excise the start code from a server name
+   * @param inServerName full server name
+   * @return server name less its start code
+   */
+  public static String getServerNameLessStartCode(String inServerName) {
+    if (inServerName != null && inServerName.length() > 0) {
+      int index = inServerName.lastIndexOf(SERVERNAME_SEPARATOR);
+      if (index > 0) {
+        return inServerName.substring(0, index);
+      }
+    }
+    return inServerName;
+  }
+
+  @Override
+  public int compareTo(ServerName other) {
+    int compare = this.getHostname().compareTo(other.getHostname());
+    if (compare != 0) return compare;
+    compare = this.getPort() - other.getPort();
+    if (compare != 0) return compare;
+    return (int)(this.getStartcode() - other.getStartcode());
+  }
+
+  @Override
+  public int hashCode() {
+    return getServerName().hashCode();
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null) return false;
+    if (!(o instanceof ServerName)) return false;
+    return this.compareTo((ServerName)o) == 0;
+  }
+
+
+  /**
+   * @return ServerName with matching hostname and port.
+   */
+  public static ServerName findServerWithSameHostnamePort(final Collection<ServerName> names,
+      final ServerName serverName) {
+    for (ServerName sn: names) {
+      if (sn.getHostname().equals(serverName.getHostname()) &&
+          sn.getPort() == serverName.getPort()) {
+        return sn;
+      }
+    }
+    return null;
+  }
+}
\ No newline at end of file

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/avro/AvroUtil.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/avro/AvroUtil.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/avro/AvroUtil.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/avro/AvroUtil.java Wed Apr 27 23:12:42 2011
@@ -23,20 +23,17 @@ import java.nio.ByteBuffer;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericArray;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.util.Utf8;
 import org.apache.hadoop.hbase.ClusterStatus;
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HServerAddress;
-import org.apache.hadoop.hbase.HServerInfo;
 import org.apache.hadoop.hbase.HServerLoad;
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.client.Delete;
-import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Result;
-import org.apache.hadoop.hbase.client.Scan;
-import org.apache.hadoop.hbase.io.hfile.Compression;
-import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.avro.generated.AClusterStatus;
 import org.apache.hadoop.hbase.avro.generated.AColumn;
 import org.apache.hadoop.hbase.avro.generated.AColumnValue;
@@ -54,11 +51,13 @@ import org.apache.hadoop.hbase.avro.gene
 import org.apache.hadoop.hbase.avro.generated.AServerInfo;
 import org.apache.hadoop.hbase.avro.generated.AServerLoad;
 import org.apache.hadoop.hbase.avro.generated.ATableDescriptor;
-
-import org.apache.avro.Schema;
-import org.apache.avro.generic.GenericArray;
-import org.apache.avro.generic.GenericData;
-import org.apache.avro.util.Utf8;
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.io.hfile.Compression;
+import org.apache.hadoop.hbase.util.Bytes;
 
 public class AvroUtil {
 
@@ -113,26 +112,26 @@ public class AvroUtil {
     return asl;
   }
 
-  static public AServerInfo hsiToASI(HServerInfo hsi) throws IOException {
+  static public AServerInfo hsiToASI(ServerName sn, HServerLoad hsl) throws IOException {
     AServerInfo asi = new AServerInfo();
-    asi.infoPort = hsi.getInfoPort();
-    asi.load = hslToASL(hsi.getLoad());
-    asi.serverAddress = hsaToASA(hsi.getServerAddress());
-    asi.serverName = new Utf8(hsi.getServerName());
-    asi.startCode = hsi.getStartCode();
+    asi.infoPort = -1;
+    asi.load = hslToASL(hsl);
+    asi.serverAddress = hsaToASA(new HServerAddress(sn.getHostname(), sn.getPort()));
+    asi.serverName = new Utf8(sn.toString());
+    asi.startCode = sn.getStartcode();
     return asi;
   }
 
   static public AClusterStatus csToACS(ClusterStatus cs) throws IOException {
     AClusterStatus acs = new AClusterStatus();
     acs.averageLoad = cs.getAverageLoad();
-    Collection<String> deadServerNames = cs.getDeadServerNames();
+    Collection<ServerName> deadServerNames = cs.getDeadServerNames();
     Schema stringArraySchema = Schema.createArray(Schema.create(Schema.Type.STRING));
     GenericData.Array<CharSequence> adeadServerNames = null;
     if (deadServerNames != null) {
       adeadServerNames = new GenericData.Array<CharSequence>(deadServerNames.size(), stringArraySchema);
-      for (String deadServerName : deadServerNames) {
-	adeadServerNames.add(new Utf8(deadServerName));
+      for (ServerName deadServerName : deadServerNames) {
+	adeadServerNames.add(new Utf8(deadServerName.toString()));
       }
     } else {
       adeadServerNames = new GenericData.Array<CharSequence>(0, stringArraySchema);
@@ -142,19 +141,19 @@ public class AvroUtil {
     acs.hbaseVersion = new Utf8(cs.getHBaseVersion());
     acs.regionsCount = cs.getRegionsCount();
     acs.requestsCount = cs.getRequestsCount();
-    Collection<HServerInfo> hserverInfos = cs.getServerInfo();
+    Collection<ServerName> hserverInfos = cs.getServers();
     Schema s = Schema.createArray(AServerInfo.SCHEMA$);
     GenericData.Array<AServerInfo> aserverInfos = null;
     if (hserverInfos != null) {
       aserverInfos = new GenericData.Array<AServerInfo>(hserverInfos.size(), s);
-      for (HServerInfo hsi : hserverInfos) {
-	aserverInfos.add(hsiToASI(hsi));
+      for (ServerName hsi : hserverInfos) {
+	aserverInfos.add(hsiToASI(hsi, cs.getLoad(hsi)));
       }
     } else {
       aserverInfos = new GenericData.Array<AServerInfo>(0, s);
     }
     acs.serverInfos = aserverInfos;
-    acs.servers = cs.getServers();
+    acs.servers = cs.getServers().size();
     return acs;
   }
 

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java Wed Apr 27 23:12:42 2011
@@ -30,9 +30,9 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.Abortable;
 import org.apache.hadoop.hbase.HRegionInfo;
-import org.apache.hadoop.hbase.HServerAddress;
 import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException;
 import org.apache.hadoop.hbase.NotServingRegionException;
+import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.client.HConnection;
 import org.apache.hadoop.hbase.client.RetriesExhaustedException;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
@@ -63,12 +63,11 @@ public class CatalogTracker {
   private final MetaNodeTracker metaNodeTracker;
   private final AtomicBoolean metaAvailable = new AtomicBoolean(false);
   /**
-   * Do not clear this address once set.  Let it be cleared by
-   * {@link #setMetaLocation(HServerAddress)} only.  Its needed when we do
+   * Do not clear this address once set.  Its needed when we do
    * server shutdown processing -- we need to know who had .META. last.  If you
    * want to know if the address is good, rely on {@link #metaAvailable} value.
    */
-  private HServerAddress metaLocation;
+  private ServerName metaLocation;
   private final int defaultTimeout;
   private boolean stopped = false;
 
@@ -155,17 +154,18 @@ public class CatalogTracker {
   /**
    * Gets the current location for <code>-ROOT-</code> or null if location is
    * not currently available.
-   * @return location of root, null if not available
+   * @return server name
    * @throws InterruptedException 
    */
-  public HServerAddress getRootLocation() throws InterruptedException {
+  public ServerName getRootLocation() throws InterruptedException {
     return this.rootRegionTracker.getRootRegionLocation();
   }
 
   /**
-   * @return Location of meta or null if not yet available.
+   * @return Location of server hosting meta region formatted as per
+   * {@link ServerName}, or null if none available
    */
-  public HServerAddress getMetaLocation() {
+  public ServerName getMetaLocation() {
     return this.metaLocation;
   }
 
@@ -184,18 +184,19 @@ public class CatalogTracker {
    * for up to the specified timeout if not immediately available.  Returns null
    * if the timeout elapses before root is available.
    * @param timeout maximum time to wait for root availability, in milliseconds
-   * @return location of root
+   * @return Location of server hosting root region,
+   * or null if none available
    * @throws InterruptedException if interrupted while waiting
    * @throws NotAllMetaRegionsOnlineException if root not available before
    *                                          timeout
    */
-  HServerAddress waitForRoot(final long timeout)
+  ServerName waitForRoot(final long timeout)
   throws InterruptedException, NotAllMetaRegionsOnlineException {
-    HServerAddress address = rootRegionTracker.waitRootRegionLocation(timeout);
-    if (address == null) {
+    ServerName sn = rootRegionTracker.waitRootRegionLocation(timeout);
+    if (sn == null) {
       throw new NotAllMetaRegionsOnlineException("Timed out; " + timeout + "ms");
     }
-    return address;
+    return sn;
   }
 
   /**
@@ -238,11 +239,11 @@ public class CatalogTracker {
    */
   private HRegionInterface getRootServerConnection()
   throws IOException, InterruptedException {
-    HServerAddress address = this.rootRegionTracker.getRootRegionLocation();
-    if (address == null) {
+    ServerName sn = this.rootRegionTracker.getRootRegionLocation();
+    if (sn == null) {
       return null;
     }
-    return getCachedConnection(address);
+    return getCachedConnection(sn);
   }
 
   /**
@@ -278,7 +279,7 @@ public class CatalogTracker {
       if (rootConnection == null) {
         return null;
       }
-      HServerAddress newLocation = MetaReader.readMetaLocation(rootConnection);
+      ServerName newLocation = MetaReader.readMetaLocation(rootConnection);
       if (newLocation == null) {
         return null;
       }
@@ -317,7 +318,7 @@ public class CatalogTracker {
    * @throws NotAllMetaRegionsOnlineException if meta not available before
    *                                          timeout
    */
-  public HServerAddress waitForMeta(long timeout)
+  public ServerName waitForMeta(long timeout)
   throws InterruptedException, IOException, NotAllMetaRegionsOnlineException {
     long stop = System.currentTimeMillis() + timeout;
     synchronized (metaAvailable) {
@@ -372,18 +373,18 @@ public class CatalogTracker {
     this.metaAvailable.set(false);
   }
 
-  private void setMetaLocation(HServerAddress metaLocation) {
+  private void setMetaLocation(final ServerName metaLocation) {
     metaAvailable.set(true);
     this.metaLocation = metaLocation;
     // no synchronization because these are private and already under lock
-    metaAvailable.notifyAll();
+    this.metaAvailable.notifyAll();
   }
 
-  private HRegionInterface getCachedConnection(HServerAddress address)
+  private HRegionInterface getCachedConnection(ServerName sn)
   throws IOException {
     HRegionInterface protocol = null;
     try {
-      protocol = connection.getHRegionConnection(address, false);
+      protocol = connection.getHRegionConnection(sn.getHostname(), sn.getPort());
     } catch (RetriesExhaustedException e) {
       if (e.getCause() != null && e.getCause() instanceof ConnectException) {
         // Catch this; presume it means the cached connection has gone bad.
@@ -392,10 +393,10 @@ public class CatalogTracker {
       }
     } catch (SocketTimeoutException e) {
       // Return 'protocol' == null.
-      LOG.debug("Timed out connecting to " + address);
+      LOG.debug("Timed out connecting to " + sn);
     } catch (SocketException e) {
       // Return 'protocol' == null.
-      LOG.debug("Exception connecting to " + address);
+      LOG.debug("Exception connecting to " + sn);
     } catch (IOException ioe) {
       Throwable cause = ioe.getCause();
       if (cause != null && cause instanceof EOFException) {
@@ -412,7 +413,7 @@ public class CatalogTracker {
   }
 
   private boolean verifyRegionLocation(HRegionInterface metaServer,
-      final HServerAddress address,
+      final ServerName address,
       byte [] regionName)
   throws IOException {
     if (metaServer == null) {
@@ -469,7 +470,8 @@ public class CatalogTracker {
       throw e;
     }
     return (connection == null)? false:
-      verifyRegionLocation(connection,this.rootRegionTracker.getRootRegionLocation(),
+      verifyRegionLocation(connection,
+        this.rootRegionTracker.getRootRegionLocation(),
         HRegionInfo.ROOT_REGIONINFO.getRegionName());
   }
 

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java Wed Apr 27 23:12:42 2011
@@ -26,8 +26,8 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HRegionInfo;
-import org.apache.hadoop.hbase.HServerInfo;
 import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException;
+import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
@@ -87,18 +87,17 @@ public class MetaEditor {
   }
 
   public static void addDaughter(final CatalogTracker catalogTracker,
-      final HRegionInfo regionInfo, final HServerInfo serverInfo)
+      final HRegionInfo regionInfo, final ServerName sn)
   throws NotAllMetaRegionsOnlineException, IOException {
     HRegionInterface server = catalogTracker.waitForMetaServerConnectionDefault();
     byte [] catalogRegionName = CatalogTracker.META_REGION;
     Put put = new Put(regionInfo.getRegionName());
     addRegionInfo(put, regionInfo);
-    if (serverInfo != null) addLocation(put, serverInfo);
+    if (sn != null) addLocation(put, sn);
     server.put(catalogRegionName, put);
     LOG.info("Added daughter " + regionInfo.getRegionNameAsString() +
       " in region " + Bytes.toString(catalogRegionName) +
-      (serverInfo == null?
-        ", serverInfo=null": ", serverInfo=" + serverInfo.getServerName()));
+      (sn == null? ", serverName=null": ", serverName=" + sn.toString()));
   }
 
   /**
@@ -110,18 +109,18 @@ public class MetaEditor {
    *
    * @param catalogTracker catalog tracker
    * @param regionInfo region to update location of
-   * @param serverInfo server the region is located on
+   * @param sn Server name
    * @throws IOException
    * @throws ConnectException Usually because the regionserver carrying .META.
    * is down.
    * @throws NullPointerException Because no -ROOT- server connection
    */
   public static void updateMetaLocation(CatalogTracker catalogTracker,
-      HRegionInfo regionInfo, HServerInfo serverInfo)
+      HRegionInfo regionInfo, ServerName sn)
   throws IOException, ConnectException {
     HRegionInterface server = catalogTracker.waitForRootServerConnectionDefault();
     if (server == null) throw new IOException("No server for -ROOT-");
-    updateLocation(server, CatalogTracker.ROOT_REGION, regionInfo, serverInfo);
+    updateLocation(server, CatalogTracker.ROOT_REGION, regionInfo, sn);
   }
 
   /**
@@ -133,14 +132,14 @@ public class MetaEditor {
    *
    * @param catalogTracker catalog tracker
    * @param regionInfo region to update location of
-   * @param serverInfo server the region is located on
+   * @param sn Server name
    * @throws IOException
    */
   public static void updateRegionLocation(CatalogTracker catalogTracker,
-      HRegionInfo regionInfo, HServerInfo serverInfo)
+      HRegionInfo regionInfo, ServerName sn)
   throws IOException {
     updateLocation(catalogTracker.waitForMetaServerConnectionDefault(),
-        CatalogTracker.META_REGION, regionInfo, serverInfo);
+        CatalogTracker.META_REGION, regionInfo, sn);
   }
 
   /**
@@ -152,20 +151,19 @@ public class MetaEditor {
    * @param server connection to server hosting catalog region
    * @param catalogRegionName name of catalog region being updated
    * @param regionInfo region to update location of
-   * @param serverInfo server the region is located on
+   * @param sn Server name
    * @throws IOException In particular could throw {@link java.net.ConnectException}
    * if the server is down on other end.
    */
   private static void updateLocation(HRegionInterface server,
-      byte [] catalogRegionName, HRegionInfo regionInfo, HServerInfo serverInfo)
+      byte [] catalogRegionName, HRegionInfo regionInfo, ServerName sn)
   throws IOException {
     Put put = new Put(regionInfo.getRegionName());
-    addLocation(put, serverInfo);
+    addLocation(put, sn);
     server.put(catalogRegionName, put);
     LOG.info("Updated row " + regionInfo.getRegionNameAsString() +
       " in region " + Bytes.toString(catalogRegionName) + " with " +
-      "server=" + serverInfo.getHostnamePort() + ", " +
-      "startcode=" + serverInfo.getStartCode());
+      "serverName=" + sn.toString());
   }
 
   /**
@@ -228,11 +226,11 @@ public class MetaEditor {
     return p;
   }
 
-  private static Put addLocation(final Put p, final HServerInfo hsi) {
+  private static Put addLocation(final Put p, final ServerName sn) {
     p.add(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
-      Bytes.toBytes(hsi.getHostnamePort()));
+      Bytes.toBytes(sn.getHostAndPort()));
     p.add(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
-      Bytes.toBytes(hsi.getStartCode()));
+      Bytes.toBytes(sn.getStartcode()));
     return p;
   }
 }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java Wed Apr 27 23:12:42 2011
@@ -30,11 +30,10 @@ import java.util.TreeSet;
 
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HRegionInfo;
-import org.apache.hadoop.hbase.HServerAddress;
-import org.apache.hadoop.hbase.HServerInfo;
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException;
 import org.apache.hadoop.hbase.NotServingRegionException;
+import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.Scan;
@@ -125,10 +124,11 @@ public class MetaReader {
    * to META.  If the region does not have an assignment it will have a null
    * value in the map.
    *
-   * @return map of regions to their currently assigned server
+   * @return map of regions to their currently assigned server where server is
+   * a String of &lt;host> ':' &lt;port>
    * @throws IOException
    */
-  public static Map<HRegionInfo,HServerAddress> fullScan(
+  public static Map<HRegionInfo, ServerName> fullScan(
       CatalogTracker catalogTracker)
   throws IOException {
     return fullScan(catalogTracker, new TreeSet<String>());
@@ -147,7 +147,7 @@ public class MetaReader {
    * @return map of regions to their currently assigned server
    * @throws IOException
    */
-  public static Map<HRegionInfo,HServerAddress> fullScan(
+  public static Map<HRegionInfo, ServerName> fullScan(
       CatalogTracker catalogTracker, final Set<String> disabledTables)
   throws IOException {
     return fullScan(catalogTracker, disabledTables, false);
@@ -168,17 +168,17 @@ public class MetaReader {
    * @return map of regions to their currently assigned server
    * @throws IOException
    */
-  public static Map<HRegionInfo,HServerAddress> fullScan(
+  public static Map<HRegionInfo, ServerName> fullScan(
       CatalogTracker catalogTracker, final Set<String> disabledTables,
       final boolean excludeOfflinedSplitParents)
   throws IOException {
-    final Map<HRegionInfo,HServerAddress> regions =
-      new TreeMap<HRegionInfo,HServerAddress>();
+    final Map<HRegionInfo, ServerName> regions =
+      new TreeMap<HRegionInfo, ServerName>();
     Visitor v = new Visitor() {
       @Override
       public boolean visit(Result r) throws IOException {
         if (r ==  null || r.isEmpty()) return true;
-        Pair<HRegionInfo,HServerAddress> region = metaRowToRegionPair(r);
+        Pair<HRegionInfo, ServerName> region = metaRowToRegionPair(r);
         if (region == null) return true;
         HRegionInfo hri = region.getFirst();
         if (disabledTables.contains(
@@ -199,8 +199,6 @@ public class MetaReader {
    * Returns a map of every region to it's currently assigned server, according
    * to META.  If the region does not have an assignment it will have a null
    * value in the map.
-   * <p>
-   * Returns HServerInfo which includes server startcode.
    *
    * @return map of regions to their currently assigned server
    * @throws IOException
@@ -273,10 +271,10 @@ public class MetaReader {
   /**
    * Reads the location of META from ROOT.
    * @param metaServer connection to server hosting ROOT
-   * @return location of META in ROOT, null if not available
+   * @return location of META in ROOT where location, or null if not available
    * @throws IOException
    */
-  public static HServerAddress readMetaLocation(HRegionInterface metaServer)
+  public static ServerName readMetaLocation(HRegionInterface metaServer)
   throws IOException {
     return readLocation(metaServer, CatalogTracker.ROOT_REGION,
         CatalogTracker.META_REGION);
@@ -286,10 +284,10 @@ public class MetaReader {
    * Reads the location of the specified region from META.
    * @param catalogTracker
    * @param regionName region to read location of
-   * @return location of region in META, null if not available
+   * @return location of META in ROOT where location is, or null if not available
    * @throws IOException
    */
-  public static HServerAddress readRegionLocation(CatalogTracker catalogTracker,
+  public static ServerName readRegionLocation(CatalogTracker catalogTracker,
       byte [] regionName)
   throws IOException {
     if (isMetaRegion(regionName)) throw new IllegalArgumentException("See readMetaLocation");
@@ -297,14 +295,17 @@ public class MetaReader {
         CatalogTracker.META_REGION, regionName);
   }
 
-  private static HServerAddress readLocation(HRegionInterface metaServer,
+  private static ServerName readLocation(HRegionInterface metaServer,
       byte [] catalogRegionName, byte [] regionName)
   throws IOException {
     Result r = null;
     try {
       r = metaServer.get(catalogRegionName,
-        new Get(regionName).addColumn(HConstants.CATALOG_FAMILY,
-        HConstants.SERVER_QUALIFIER));
+        new Get(regionName).
+        addColumn(HConstants.CATALOG_FAMILY,
+          HConstants.SERVER_QUALIFIER).
+        addColumn(HConstants.CATALOG_FAMILY,
+          HConstants.STARTCODE_QUALIFIER));
     } catch (java.net.SocketTimeoutException e) {
       // Treat this exception + message as unavailable catalog table. Catch it
       // and fall through to return a null
@@ -334,78 +335,57 @@ public class MetaReader {
     if (r == null || r.isEmpty()) {
       return null;
     }
-    byte [] value = r.getValue(HConstants.CATALOG_FAMILY,
-      HConstants.SERVER_QUALIFIER);
-    return new HServerAddress(Bytes.toString(value));
+    return getServerNameFromResult(r);
   }
 
   /**
    * Gets the region info and assignment for the specified region from META.
    * @param catalogTracker
    * @param regionName
-   * @return region info and assignment from META, null if not available
+   * @return location of META in ROOT where location is
+   * a String of &lt;host> ':' &lt;port>, or null if not available
    * @throws IOException
    */
-  public static Pair<HRegionInfo, HServerAddress> getRegion(
+  public static Pair<HRegionInfo, ServerName> getRegion(
       CatalogTracker catalogTracker, byte [] regionName)
   throws IOException {
     Get get = new Get(regionName);
     get.addFamily(HConstants.CATALOG_FAMILY);
     byte [] meta = getCatalogRegionNameForRegion(regionName);
     Result r = catalogTracker.waitForMetaServerConnectionDefault().get(meta, get);
-    if(r == null || r.isEmpty()) {
-      return null;
-    }
-    return metaRowToRegionPair(r);
+    return (r == null || r.isEmpty())? null: metaRowToRegionPair(r);
   }
 
   /**
    * @param data A .META. table row.
-   * @return A pair of the regioninfo and the server address from <code>data</code>
-   * or null for server address if no address set in .META. or null for a result
-   * if no HRegionInfo found.
+   * @return A pair of the regioninfo and the ServerName
+   * (or null for server address if no address set in .META.).
    * @throws IOException
    */
-  public static Pair<HRegionInfo, HServerAddress> metaRowToRegionPair(
-      Result data) throws IOException {
-    byte [] bytes =
-      data.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
+  public static Pair<HRegionInfo, ServerName> metaRowToRegionPair(Result data)
+  throws IOException {
+    byte [] bytes = data.getValue(HConstants.CATALOG_FAMILY,
+      HConstants.REGIONINFO_QUALIFIER);
     if (bytes == null) return null;
     HRegionInfo info = Writables.getHRegionInfo(bytes);
-    final byte[] value = data.getValue(HConstants.CATALOG_FAMILY,
-      HConstants.SERVER_QUALIFIER);
-    if (value != null && value.length > 0) {
-      HServerAddress server = new HServerAddress(Bytes.toString(value));
-      return new Pair<HRegionInfo,HServerAddress>(info, server);
-    } else {
-      return new Pair<HRegionInfo, HServerAddress>(info, null);
-    }
+    ServerName sn = getServerNameFromResult(data);
+    // sn can be null in case where no server inof.
+    return new Pair<HRegionInfo, ServerName>(info, sn);
   }
 
   /**
-   * @param data A .META. table row.
-   * @return A pair of the regioninfo and the server info from <code>data</code>
-   * (or null for server address if no address set in .META.).
-   * @throws IOException
+   * @param data Result to interrogate.
+   * @return A ServerName instance or null if necessary fields not found or empty.
    */
-  public static Pair<HRegionInfo, HServerInfo> metaRowToRegionPairWithInfo(
-      Result data) throws IOException {
-    byte [] bytes = data.getValue(HConstants.CATALOG_FAMILY,
-      HConstants.REGIONINFO_QUALIFIER);
-    if (bytes == null) return null;
-    HRegionInfo info = Writables.getHRegionInfo(bytes);
-    final byte[] value = data.getValue(HConstants.CATALOG_FAMILY,
+  private static ServerName getServerNameFromResult(final Result data) {
+    byte[] value = data.getValue(HConstants.CATALOG_FAMILY,
       HConstants.SERVER_QUALIFIER);
-    if (value != null && value.length > 0) {
-      final long startCode = Bytes.toLong(data.getValue(HConstants.CATALOG_FAMILY,
-          HConstants.STARTCODE_QUALIFIER));
-      HServerAddress server = new HServerAddress(Bytes.toString(value));
-      HServerInfo hsi = new HServerInfo(server, startCode, 0,
-          server.getHostname());
-      return new Pair<HRegionInfo,HServerInfo>(info, hsi);
-    } else {
-      return new Pair<HRegionInfo, HServerInfo>(info, null);
-    }
+    if (value == null || value.length == 0) return null;
+    String hostAndPort = Bytes.toString(value);
+    value = data.getValue(HConstants.CATALOG_FAMILY,
+      HConstants.STARTCODE_QUALIFIER);
+    if (value == null || value.length == 0) return null;
+    return new ServerName(hostAndPort, Bytes.toLong(value));
   }
 
   /**
@@ -528,26 +508,27 @@ public class MetaReader {
   /**
    * @param catalogTracker
    * @param tableName
-   * @return Return list of regioninfos and server addresses.
+   * @return Return list of regioninfos and server.
    * @throws IOException
    * @throws InterruptedException
    */
-  public static List<Pair<HRegionInfo, HServerAddress>>
+  public static List<Pair<HRegionInfo, ServerName>>
   getTableRegionsAndLocations(CatalogTracker catalogTracker, String tableName)
   throws IOException, InterruptedException {
     byte [] tableNameBytes = Bytes.toBytes(tableName);
     if (Bytes.equals(tableNameBytes, HConstants.ROOT_TABLE_NAME)) {
       // If root, do a bit of special handling.
-      HServerAddress hsa = catalogTracker.getRootLocation();
-      List<Pair<HRegionInfo, HServerAddress>> list =
-        new ArrayList<Pair<HRegionInfo, HServerAddress>>();
-      list.add(new Pair<HRegionInfo, HServerAddress>(HRegionInfo.ROOT_REGIONINFO, hsa));
+      ServerName serverName = catalogTracker.getRootLocation();
+      List<Pair<HRegionInfo, ServerName>> list =
+        new ArrayList<Pair<HRegionInfo, ServerName>>();
+      list.add(new Pair<HRegionInfo, ServerName>(HRegionInfo.ROOT_REGIONINFO,
+        serverName));
       return list;
     }
     HRegionInterface metaServer =
       getCatalogRegionInterface(catalogTracker, tableNameBytes);
-    List<Pair<HRegionInfo, HServerAddress>> regions =
-      new ArrayList<Pair<HRegionInfo, HServerAddress>>();
+    List<Pair<HRegionInfo, ServerName>> regions =
+      new ArrayList<Pair<HRegionInfo, ServerName>>();
     Scan scan = getScanForTableName(tableNameBytes);
     scan.addFamily(HConstants.CATALOG_FAMILY);
     long scannerid =
@@ -556,7 +537,7 @@ public class MetaReader {
       Result data;
       while((data = metaServer.next(scannerid)) != null) {
         if (data != null && data.size() > 0) {
-          Pair<HRegionInfo, HServerAddress> region = metaRowToRegionPair(data);
+          Pair<HRegionInfo, ServerName> region = metaRowToRegionPair(data);
           if (region == null) continue;
           regions.add(region);
         }
@@ -575,7 +556,7 @@ public class MetaReader {
    * @throws IOException
    */
   public static NavigableMap<HRegionInfo, Result>
-  getServerUserRegions(CatalogTracker catalogTracker, final HServerInfo hsi)
+  getServerUserRegions(CatalogTracker catalogTracker, final ServerName serverName)
   throws IOException {
     HRegionInterface metaServer =
       catalogTracker.waitForMetaServerConnectionDefault();
@@ -588,10 +569,9 @@ public class MetaReader {
       Result result;
       while((result = metaServer.next(scannerid)) != null) {
         if (result != null && result.size() > 0) {
-          Pair<HRegionInfo, HServerInfo> pair =
-            metaRowToRegionPairWithInfo(result);
+          Pair<HRegionInfo, ServerName> pair = metaRowToRegionPair(result);
           if (pair == null) continue;
-          if (pair.getSecond() == null || !pair.getSecond().equals(hsi)) {
+          if (pair.getSecond() == null || !serverName.equals(pair.getSecond())) {
             continue;
           }
           hris.put(pair.getFirst(), result);

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/RootLocationEditor.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/RootLocationEditor.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/RootLocationEditor.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/RootLocationEditor.java Wed Apr 27 23:12:42 2011
@@ -21,7 +21,7 @@ package org.apache.hadoop.hbase.catalog;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.HServerAddress;
+import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
@@ -53,11 +53,11 @@ public class RootLocationEditor {
    * Sets the location of <code>-ROOT-</code> in ZooKeeper to the
    * specified server address.
    * @param zookeeper zookeeper reference
-   * @param location server address hosting root
+   * @param location The server hosting <code>-ROOT-</code>
    * @throws KeeperException unexpected zookeeper exception
    */
   public static void setRootLocation(ZooKeeperWatcher zookeeper,
-      HServerAddress location)
+      final ServerName location)
   throws KeeperException {
     LOG.info("Setting ROOT region location in ZooKeeper as " + location);
     try {
@@ -69,4 +69,4 @@ public class RootLocationEditor {
           Bytes.toBytes(location.toString()));
     }
   }
-}
+}
\ No newline at end of file

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Wed Apr 27 23:12:42 2011
@@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.MasterNot
 import org.apache.hadoop.hbase.NotServingRegionException;
 import org.apache.hadoop.hbase.RegionException;
 import org.apache.hadoop.hbase.RemoteExceptionHandler;
+import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableExistsException;
 import org.apache.hadoop.hbase.UnknownRegionException;
 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
@@ -46,6 +47,7 @@ import org.apache.hadoop.hbase.catalog.C
 import org.apache.hadoop.hbase.catalog.MetaReader;
 import org.apache.hadoop.hbase.ipc.HMasterInterface;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
+import org.apache.hadoop.hbase.util.Addressing;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.hadoop.ipc.RemoteException;
@@ -371,7 +373,7 @@ public class HBaseAdmin implements Abort
     }
     // Wait until all regions deleted
     HRegionInterface server =
-      connection.getHRegionConnection(firstMetaServer.getServerAddress());
+      connection.getHRegionConnection(firstMetaServer.getHostname(), firstMetaServer.getPort());
     for (int tries = 0; tries < (this.numRetries * this.retryLongerMultiplier); tries++) {
       long scannerId = -1L;
       try {
@@ -762,18 +764,15 @@ public class HBaseAdmin implements Abort
     CatalogTracker ct = getCatalogTracker();
     try {
       if (hostAndPort != null) {
-        HServerAddress hsa = new HServerAddress(hostAndPort);
-        Pair<HRegionInfo, HServerAddress> pair =
-          MetaReader.getRegion(ct, regionname);
+        Pair<HRegionInfo, ServerName> pair = MetaReader.getRegion(ct, regionname);
         if (pair == null || pair.getSecond() == null) {
           LOG.info("No server in .META. for " +
             Bytes.toString(regionname) + "; pair=" + pair);
         } else {
-          closeRegion(hsa, pair.getFirst());
+          closeRegion(pair.getSecond(), pair.getFirst());
         }
       } else {
-        Pair<HRegionInfo, HServerAddress> pair =
-          MetaReader.getRegion(ct, regionname);
+        Pair<HRegionInfo, ServerName> pair = MetaReader.getRegion(ct, regionname);
         if (pair == null || pair.getSecond() == null) {
           LOG.info("No server in .META. for " +
             Bytes.toString(regionname) + "; pair=" + pair);
@@ -786,9 +785,10 @@ public class HBaseAdmin implements Abort
     }
   }
 
-  private void closeRegion(final HServerAddress hsa, final HRegionInfo hri)
+  private void closeRegion(final ServerName sn, final HRegionInfo hri)
   throws IOException {
-    HRegionInterface rs = this.connection.getHRegionConnection(hsa);
+    HRegionInterface rs =
+      this.connection.getHRegionConnection(sn.getHostname(), sn.getPort());
     // Close the region without updating zk state.
     rs.closeRegion(hri, false);
   }
@@ -820,7 +820,7 @@ public class HBaseAdmin implements Abort
     CatalogTracker ct = getCatalogTracker();
     try {
       if (isRegionName) {
-        Pair<HRegionInfo, HServerAddress> pair =
+        Pair<HRegionInfo, ServerName> pair =
           MetaReader.getRegion(ct, tableNameOrRegionName);
         if (pair == null || pair.getSecond() == null) {
           LOG.info("No server in .META. for " +
@@ -829,10 +829,10 @@ public class HBaseAdmin implements Abort
           flush(pair.getSecond(), pair.getFirst());
         }
       } else {
-        List<Pair<HRegionInfo, HServerAddress>> pairs =
+        List<Pair<HRegionInfo, ServerName>> pairs =
           MetaReader.getTableRegionsAndLocations(ct,
               Bytes.toString(tableNameOrRegionName));
-        for (Pair<HRegionInfo, HServerAddress> pair: pairs) {
+        for (Pair<HRegionInfo, ServerName> pair: pairs) {
           if (pair.getFirst().isOffline()) continue;
           if (pair.getSecond() == null) continue;
           try {
@@ -850,9 +850,10 @@ public class HBaseAdmin implements Abort
     }
   }
 
-  private void flush(final HServerAddress hsa, final HRegionInfo hri)
+  private void flush(final ServerName sn, final HRegionInfo hri)
   throws IOException {
-    HRegionInterface rs = this.connection.getHRegionConnection(hsa);
+    HRegionInterface rs =
+      this.connection.getHRegionConnection(sn.getHostname(), sn.getPort());
     rs.flushRegion(hri);
   }
 
@@ -922,7 +923,7 @@ public class HBaseAdmin implements Abort
     CatalogTracker ct = getCatalogTracker();
     try {
       if (isRegionName(tableNameOrRegionName)) {
-        Pair<HRegionInfo, HServerAddress> pair =
+        Pair<HRegionInfo, ServerName> pair =
           MetaReader.getRegion(ct, tableNameOrRegionName);
         if (pair == null || pair.getSecond() == null) {
           LOG.info("No server in .META. for " +
@@ -931,10 +932,10 @@ public class HBaseAdmin implements Abort
           compact(pair.getSecond(), pair.getFirst(), major);
         }
       } else {
-        List<Pair<HRegionInfo, HServerAddress>> pairs =
+        List<Pair<HRegionInfo, ServerName>> pairs =
           MetaReader.getTableRegionsAndLocations(ct,
               Bytes.toString(tableNameOrRegionName));
-        for (Pair<HRegionInfo, HServerAddress> pair: pairs) {
+        for (Pair<HRegionInfo, ServerName> pair: pairs) {
           if (pair.getFirst().isOffline()) continue;
           if (pair.getSecond() == null) continue;
           try {
@@ -953,10 +954,11 @@ public class HBaseAdmin implements Abort
     }
   }
 
-  private void compact(final HServerAddress hsa, final HRegionInfo hri,
+  private void compact(final ServerName sn, final HRegionInfo hri,
       final boolean major)
   throws IOException {
-    HRegionInterface rs = this.connection.getHRegionConnection(hsa);
+    HRegionInterface rs =
+      this.connection.getHRegionConnection(sn.getHostname(), sn.getPort());
     rs.compactRegion(hri, major);
   }
 
@@ -969,7 +971,7 @@ public class HBaseAdmin implements Abort
    * @param destServerName The servername of the destination regionserver.  If
    * passed the empty byte array we'll assign to a random server.  A server name
    * is made of host, port and startcode.  Here is an example:
-   * <code> host187.example.com,60020,1289493121758</code>.
+   * <code> host187.example.com,60020,1289493121758</code>
    * @throws UnknownRegionException Thrown if we can't find a region named
    * <code>encodedRegionName</code>
    * @throws ZooKeeperConnectionException
@@ -1077,7 +1079,7 @@ public class HBaseAdmin implements Abort
     try {
       if (isRegionName(tableNameOrRegionName)) {
         // Its a possible region name.
-        Pair<HRegionInfo, HServerAddress> pair =
+        Pair<HRegionInfo, ServerName> pair =
           MetaReader.getRegion(ct, tableNameOrRegionName);
         if (pair == null || pair.getSecond() == null) {
           LOG.info("No server in .META. for " +
@@ -1086,10 +1088,10 @@ public class HBaseAdmin implements Abort
           split(pair.getSecond(), pair.getFirst(), splitPoint);
         }
       } else {
-        List<Pair<HRegionInfo, HServerAddress>> pairs =
+        List<Pair<HRegionInfo, ServerName>> pairs =
           MetaReader.getTableRegionsAndLocations(ct,
               Bytes.toString(tableNameOrRegionName));
-        for (Pair<HRegionInfo, HServerAddress> pair: pairs) {
+        for (Pair<HRegionInfo, ServerName> pair: pairs) {
           // May not be a server for a particular row
           if (pair.getSecond() == null) continue;
           HRegionInfo r = pair.getFirst();
@@ -1106,9 +1108,10 @@ public class HBaseAdmin implements Abort
     }
   }
 
-  private void split(final HServerAddress hsa, final HRegionInfo hri,
+  private void split(final ServerName sn, final HRegionInfo hri,
       byte[] splitPoint) throws IOException {
-    HRegionInterface rs = this.connection.getHRegionConnection(hsa);
+    HRegionInterface rs =
+      this.connection.getHRegionConnection(sn.getHostname(), sn.getPort());
     rs.splitRegion(hri, splitPoint);
   }
 
@@ -1179,10 +1182,27 @@ public class HBaseAdmin implements Abort
   /**
    * Stop the designated regionserver.
    * @throws IOException if a remote or network exception occurs
+   * @deprecated Use {@link #stopRegionServer(String)}
    */
   public synchronized void stopRegionServer(final HServerAddress hsa)
   throws IOException {
-    HRegionInterface rs = this.connection.getHRegionConnection(hsa);
+    HRegionInterface rs =
+      this.connection.getHRegionConnection(hsa);
+    rs.stop("Called by admin client " + this.connection.toString());
+  }
+
+  /**
+   * Stop the designated regionserver
+   * @param hostnamePort Hostname and port delimited by a <code>:</code> as in
+   * <code>example.org:1234</code>
+   * @throws IOException if a remote or network exception occurs
+   */
+  public synchronized void stopRegionServer(final String hostnamePort)
+  throws IOException {
+    String hostname = Addressing.parseHostname(hostnamePort);
+    int port = Addressing.parsePort(hostnamePort);
+    HRegionInterface rs =
+      this.connection.getHRegionConnection(hostname, port);
     rs.stop("Called by admin client " + this.connection.toString());
   }
 

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnection.java?rev=1097275&r1=1097274&r2=1097275&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnection.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnection.java Wed Apr 27 23:12:42 2011
@@ -20,6 +20,7 @@
 package org.apache.hadoop.hbase.client;
 
 import java.io.IOException;
+import java.net.InetSocketAddress;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
@@ -188,19 +189,44 @@ public interface HConnection extends Abo
    * @param regionServer - the server to connect to
    * @return proxy for HRegionServer
    * @throws IOException if a remote or network exception occurs
+   * @deprecated Use {@link #getHRegionConnection(InetSocketAddress)}
    */
   public HRegionInterface getHRegionConnection(HServerAddress regionServer)
   throws IOException;
 
   /**
    * Establishes a connection to the region server at the specified address.
+   * @param hostname RegionServer hostname
+   * @param port RegionServer port
+   * @return proxy for HRegionServer
+   * @throws IOException if a remote or network exception occurs
+   *
+   */
+  public HRegionInterface getHRegionConnection(final String hostname, final int port)
+  throws IOException;
+
+  /**
+   * Establishes a connection to the region server at the specified address.
    * @param regionServer - the server to connect to
    * @param getMaster - do we check if master is alive
    * @return proxy for HRegionServer
    * @throws IOException if a remote or network exception occurs
+   * @deprecated Use {@link #getHRegionConnection(HServerAddress, boolean)}
+   */
+  public HRegionInterface getHRegionConnection(HServerAddress regionServer,
+     boolean getMaster)
+  throws IOException;
+
+  /**
+   * Establishes a connection to the region server at the specified address.
+   * @param hostname RegionServer hostname
+   * @param port RegionServer port
+   * @param getMaster - do we check if master is alive
+   * @return proxy for HRegionServer
+   * @throws IOException if a remote or network exception occurs
    */
-  public HRegionInterface getHRegionConnection(
-      HServerAddress regionServer, boolean getMaster)
+  public HRegionInterface getHRegionConnection(final String hostname,
+     final int port, boolean getMaster)
   throws IOException;
 
   /**
@@ -343,6 +369,7 @@ public interface HConnection extends Abo
    * Scan zookeeper to get the number of region servers
    * @return the number of region servers that are currently running
    * @throws IOException if a remote or network exception occurs
+   * @deprecated This method will be changed from public to package protected.
    */
   public int getCurrentNrHRS() throws IOException;
-}
+}
\ No newline at end of file



Mime
View raw message