You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by en...@apache.org on 2014/02/06 03:04:54 UTC

svn commit: r1565041 [3/3] - in /hbase/branches/hbase-10070: hbase-client/src/main/java/org/apache/hadoop/hbase/ hbase-client/src/main/java/org/apache/hadoop/hbase/catalog/ hbase-client/src/main/java/org/apache/hadoop/hbase/client/ hbase-client/src/tes...

Modified: hbase/branches/hbase-10070/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java?rev=1565041&r1=1565040&r2=1565041&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java (original)
+++ hbase/branches/hbase-10070/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java Thu Feb  6 02:04:53 2014
@@ -387,13 +387,19 @@ public final class HConstants {
   public static final byte [] REGIONINFO_QUALIFIER = Bytes.toBytes(REGIONINFO_QUALIFIER_STR);
 
   /** The server column qualifier */
-  public static final byte [] SERVER_QUALIFIER = Bytes.toBytes("server");
+  public static final String SERVER_QUALIFIER_STR = "server";
+  /** The server column qualifier */
+  public static final byte [] SERVER_QUALIFIER = Bytes.toBytes(SERVER_QUALIFIER_STR);
 
   /** The startcode column qualifier */
-  public static final byte [] STARTCODE_QUALIFIER = Bytes.toBytes("serverstartcode");
+  public static final String STARTCODE_QUALIFIER_STR = "serverstartcode";
+  /** The startcode column qualifier */
+  public static final byte [] STARTCODE_QUALIFIER = Bytes.toBytes(STARTCODE_QUALIFIER_STR);
 
   /** The open seqnum column qualifier */
-  public static final byte [] SEQNUM_QUALIFIER = Bytes.toBytes("seqnumDuringOpen");
+  public static final String SEQNUM_QUALIFIER_STR = "seqnumDuringOpen";
+  /** The open seqnum column qualifier */
+  public static final byte [] SEQNUM_QUALIFIER = Bytes.toBytes(SEQNUM_QUALIFIER_STR);
 
   /** The lower-half split region column qualifier */
   public static final byte [] SPLITA_QUALIFIER = Bytes.toBytes("splitA");

Modified: hbase/branches/hbase-10070/hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/HBaseProtos.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/HBaseProtos.java?rev=1565041&r1=1565040&r2=1565041&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/HBaseProtos.java (original)
+++ hbase/branches/hbase-10070/hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/HBaseProtos.java Thu Feb  6 02:04:53 2014
@@ -3687,6 +3687,16 @@ public final class HBaseProtos {
      * <code>optional bool split = 6;</code>
      */
     boolean getSplit();
+
+    // optional int32 replica_id = 7 [default = 0];
+    /**
+     * <code>optional int32 replica_id = 7 [default = 0];</code>
+     */
+    boolean hasReplicaId();
+    /**
+     * <code>optional int32 replica_id = 7 [default = 0];</code>
+     */
+    int getReplicaId();
   }
   /**
    * Protobuf type {@code RegionInfo}
@@ -3782,6 +3792,11 @@ public final class HBaseProtos {
               split_ = input.readBool();
               break;
             }
+            case 56: {
+              bitField0_ |= 0x00000040;
+              replicaId_ = input.readInt32();
+              break;
+            }
           }
         }
       } catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -3924,6 +3939,22 @@ public final class HBaseProtos {
       return split_;
     }
 
+    // optional int32 replica_id = 7 [default = 0];
+    public static final int REPLICA_ID_FIELD_NUMBER = 7;
+    private int replicaId_;
+    /**
+     * <code>optional int32 replica_id = 7 [default = 0];</code>
+     */
+    public boolean hasReplicaId() {
+      return ((bitField0_ & 0x00000040) == 0x00000040);
+    }
+    /**
+     * <code>optional int32 replica_id = 7 [default = 0];</code>
+     */
+    public int getReplicaId() {
+      return replicaId_;
+    }
+
     private void initFields() {
       regionId_ = 0L;
       tableName_ = org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.TableName.getDefaultInstance();
@@ -3931,6 +3962,7 @@ public final class HBaseProtos {
       endKey_ = com.google.protobuf.ByteString.EMPTY;
       offline_ = false;
       split_ = false;
+      replicaId_ = 0;
     }
     private byte memoizedIsInitialized = -1;
     public final boolean isInitialized() {
@@ -3974,6 +4006,9 @@ public final class HBaseProtos {
       if (((bitField0_ & 0x00000020) == 0x00000020)) {
         output.writeBool(6, split_);
       }
+      if (((bitField0_ & 0x00000040) == 0x00000040)) {
+        output.writeInt32(7, replicaId_);
+      }
       getUnknownFields().writeTo(output);
     }
 
@@ -4007,6 +4042,10 @@ public final class HBaseProtos {
         size += com.google.protobuf.CodedOutputStream
           .computeBoolSize(6, split_);
       }
+      if (((bitField0_ & 0x00000040) == 0x00000040)) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeInt32Size(7, replicaId_);
+      }
       size += getUnknownFields().getSerializedSize();
       memoizedSerializedSize = size;
       return size;
@@ -4060,6 +4099,11 @@ public final class HBaseProtos {
         result = result && (getSplit()
             == other.getSplit());
       }
+      result = result && (hasReplicaId() == other.hasReplicaId());
+      if (hasReplicaId()) {
+        result = result && (getReplicaId()
+            == other.getReplicaId());
+      }
       result = result &&
           getUnknownFields().equals(other.getUnknownFields());
       return result;
@@ -4097,6 +4141,10 @@ public final class HBaseProtos {
         hash = (37 * hash) + SPLIT_FIELD_NUMBER;
         hash = (53 * hash) + hashBoolean(getSplit());
       }
+      if (hasReplicaId()) {
+        hash = (37 * hash) + REPLICA_ID_FIELD_NUMBER;
+        hash = (53 * hash) + getReplicaId();
+      }
       hash = (29 * hash) + getUnknownFields().hashCode();
       memoizedHashCode = hash;
       return hash;
@@ -4228,6 +4276,8 @@ public final class HBaseProtos {
         bitField0_ = (bitField0_ & ~0x00000010);
         split_ = false;
         bitField0_ = (bitField0_ & ~0x00000020);
+        replicaId_ = 0;
+        bitField0_ = (bitField0_ & ~0x00000040);
         return this;
       }
 
@@ -4284,6 +4334,10 @@ public final class HBaseProtos {
           to_bitField0_ |= 0x00000020;
         }
         result.split_ = split_;
+        if (((from_bitField0_ & 0x00000040) == 0x00000040)) {
+          to_bitField0_ |= 0x00000040;
+        }
+        result.replicaId_ = replicaId_;
         result.bitField0_ = to_bitField0_;
         onBuilt();
         return result;
@@ -4318,6 +4372,9 @@ public final class HBaseProtos {
         if (other.hasSplit()) {
           setSplit(other.getSplit());
         }
+        if (other.hasReplicaId()) {
+          setReplicaId(other.getReplicaId());
+        }
         this.mergeUnknownFields(other.getUnknownFields());
         return this;
       }
@@ -4645,6 +4702,39 @@ public final class HBaseProtos {
         return this;
       }
 
+      // optional int32 replica_id = 7 [default = 0];
+      private int replicaId_ ;
+      /**
+       * <code>optional int32 replica_id = 7 [default = 0];</code>
+       */
+      public boolean hasReplicaId() {
+        return ((bitField0_ & 0x00000040) == 0x00000040);
+      }
+      /**
+       * <code>optional int32 replica_id = 7 [default = 0];</code>
+       */
+      public int getReplicaId() {
+        return replicaId_;
+      }
+      /**
+       * <code>optional int32 replica_id = 7 [default = 0];</code>
+       */
+      public Builder setReplicaId(int value) {
+        bitField0_ |= 0x00000040;
+        replicaId_ = value;
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>optional int32 replica_id = 7 [default = 0];</code>
+       */
+      public Builder clearReplicaId() {
+        bitField0_ = (bitField0_ & ~0x00000040);
+        replicaId_ = 0;
+        onChanged();
+        return this;
+      }
+
       // @@protoc_insertion_point(builder_scope:RegionInfo)
     }
 
@@ -15778,41 +15868,42 @@ public final class HBaseProtos {
       "ingPair\"o\n\022ColumnFamilySchema\022\014\n\004name\030\001 " +
       "\002(\014\022#\n\nattributes\030\002 \003(\0132\017.BytesBytesPair" +
       "\022&\n\rconfiguration\030\003 \003(\0132\017.NameStringPair" +
-      "\"\203\001\n\nRegionInfo\022\021\n\tregion_id\030\001 \002(\004\022\036\n\nta",
+      "\"\232\001\n\nRegionInfo\022\021\n\tregion_id\030\001 \002(\004\022\036\n\nta",
       "ble_name\030\002 \002(\0132\n.TableName\022\021\n\tstart_key\030" +
       "\003 \001(\014\022\017\n\007end_key\030\004 \001(\014\022\017\n\007offline\030\005 \001(\010\022" +
-      "\r\n\005split\030\006 \001(\010\"1\n\014FavoredNodes\022!\n\014favore" +
-      "d_node\030\001 \003(\0132\013.ServerName\"\225\001\n\017RegionSpec" +
-      "ifier\0222\n\004type\030\001 \002(\0162$.RegionSpecifier.Re" +
-      "gionSpecifierType\022\r\n\005value\030\002 \002(\014\"?\n\023Regi" +
-      "onSpecifierType\022\017\n\013REGION_NAME\020\001\022\027\n\023ENCO" +
-      "DED_REGION_NAME\020\002\"%\n\tTimeRange\022\014\n\004from\030\001" +
-      " \001(\004\022\n\n\002to\030\002 \001(\004\"A\n\nServerName\022\021\n\thost_n" +
-      "ame\030\001 \002(\t\022\014\n\004port\030\002 \001(\r\022\022\n\nstart_code\030\003 ",
-      "\001(\004\"\033\n\013Coprocessor\022\014\n\004name\030\001 \002(\t\"-\n\016Name" +
-      "StringPair\022\014\n\004name\030\001 \002(\t\022\r\n\005value\030\002 \002(\t\"" +
-      ",\n\rNameBytesPair\022\014\n\004name\030\001 \002(\t\022\r\n\005value\030" +
-      "\002 \001(\014\"/\n\016BytesBytesPair\022\r\n\005first\030\001 \002(\014\022\016" +
-      "\n\006second\030\002 \002(\014\",\n\rNameInt64Pair\022\014\n\004name\030" +
-      "\001 \001(\t\022\r\n\005value\030\002 \001(\003\"\256\001\n\023SnapshotDescrip" +
-      "tion\022\014\n\004name\030\001 \002(\t\022\r\n\005table\030\002 \001(\t\022\030\n\rcre" +
-      "ation_time\030\003 \001(\003:\0010\022.\n\004type\030\004 \001(\0162\031.Snap" +
-      "shotDescription.Type:\005FLUSH\022\017\n\007version\030\005" +
-      " \001(\005\"\037\n\004Type\022\014\n\010DISABLED\020\000\022\t\n\005FLUSH\020\001\"}\n",
-      "\024ProcedureDescription\022\021\n\tsignature\030\001 \002(\t" +
-      "\022\020\n\010instance\030\002 \001(\t\022\030\n\rcreation_time\030\003 \001(" +
-      "\003:\0010\022&\n\rconfiguration\030\004 \003(\0132\017.NameString" +
-      "Pair\"\n\n\010EmptyMsg\"\033\n\007LongMsg\022\020\n\010long_msg\030" +
-      "\001 \002(\003\"\'\n\rBigDecimalMsg\022\026\n\016bigdecimal_msg" +
-      "\030\001 \002(\014\"5\n\004UUID\022\026\n\016least_sig_bits\030\001 \002(\004\022\025" +
-      "\n\rmost_sig_bits\030\002 \002(\004\"K\n\023NamespaceDescri" +
-      "ptor\022\014\n\004name\030\001 \002(\014\022&\n\rconfiguration\030\002 \003(" +
-      "\0132\017.NameStringPair\"$\n\020RegionServerInfo\022\020" +
-      "\n\010infoPort\030\001 \001(\005*r\n\013CompareType\022\010\n\004LESS\020",
-      "\000\022\021\n\rLESS_OR_EQUAL\020\001\022\t\n\005EQUAL\020\002\022\r\n\tNOT_E" +
-      "QUAL\020\003\022\024\n\020GREATER_OR_EQUAL\020\004\022\013\n\007GREATER\020" +
-      "\005\022\t\n\005NO_OP\020\006B>\n*org.apache.hadoop.hbase." +
-      "protobuf.generatedB\013HBaseProtosH\001\240\001\001"
+      "\r\n\005split\030\006 \001(\010\022\025\n\nreplica_id\030\007 \001(\005:\0010\"1\n" +
+      "\014FavoredNodes\022!\n\014favored_node\030\001 \003(\0132\013.Se" +
+      "rverName\"\225\001\n\017RegionSpecifier\0222\n\004type\030\001 \002" +
+      "(\0162$.RegionSpecifier.RegionSpecifierType" +
+      "\022\r\n\005value\030\002 \002(\014\"?\n\023RegionSpecifierType\022\017" +
+      "\n\013REGION_NAME\020\001\022\027\n\023ENCODED_REGION_NAME\020\002" +
+      "\"%\n\tTimeRange\022\014\n\004from\030\001 \001(\004\022\n\n\002to\030\002 \001(\004\"" +
+      "A\n\nServerName\022\021\n\thost_name\030\001 \002(\t\022\014\n\004port",
+      "\030\002 \001(\r\022\022\n\nstart_code\030\003 \001(\004\"\033\n\013Coprocesso" +
+      "r\022\014\n\004name\030\001 \002(\t\"-\n\016NameStringPair\022\014\n\004nam" +
+      "e\030\001 \002(\t\022\r\n\005value\030\002 \002(\t\",\n\rNameBytesPair\022" +
+      "\014\n\004name\030\001 \002(\t\022\r\n\005value\030\002 \001(\014\"/\n\016BytesByt" +
+      "esPair\022\r\n\005first\030\001 \002(\014\022\016\n\006second\030\002 \002(\014\",\n" +
+      "\rNameInt64Pair\022\014\n\004name\030\001 \001(\t\022\r\n\005value\030\002 " +
+      "\001(\003\"\256\001\n\023SnapshotDescription\022\014\n\004name\030\001 \002(" +
+      "\t\022\r\n\005table\030\002 \001(\t\022\030\n\rcreation_time\030\003 \001(\003:" +
+      "\0010\022.\n\004type\030\004 \001(\0162\031.SnapshotDescription.T" +
+      "ype:\005FLUSH\022\017\n\007version\030\005 \001(\005\"\037\n\004Type\022\014\n\010D",
+      "ISABLED\020\000\022\t\n\005FLUSH\020\001\"}\n\024ProcedureDescrip" +
+      "tion\022\021\n\tsignature\030\001 \002(\t\022\020\n\010instance\030\002 \001(" +
+      "\t\022\030\n\rcreation_time\030\003 \001(\003:\0010\022&\n\rconfigura" +
+      "tion\030\004 \003(\0132\017.NameStringPair\"\n\n\010EmptyMsg\"" +
+      "\033\n\007LongMsg\022\020\n\010long_msg\030\001 \002(\003\"\'\n\rBigDecim" +
+      "alMsg\022\026\n\016bigdecimal_msg\030\001 \002(\014\"5\n\004UUID\022\026\n" +
+      "\016least_sig_bits\030\001 \002(\004\022\025\n\rmost_sig_bits\030\002" +
+      " \002(\004\"K\n\023NamespaceDescriptor\022\014\n\004name\030\001 \002(" +
+      "\014\022&\n\rconfiguration\030\002 \003(\0132\017.NameStringPai" +
+      "r\"$\n\020RegionServerInfo\022\020\n\010infoPort\030\001 \001(\005*",
+      "r\n\013CompareType\022\010\n\004LESS\020\000\022\021\n\rLESS_OR_EQUA" +
+      "L\020\001\022\t\n\005EQUAL\020\002\022\r\n\tNOT_EQUAL\020\003\022\024\n\020GREATER" +
+      "_OR_EQUAL\020\004\022\013\n\007GREATER\020\005\022\t\n\005NO_OP\020\006B>\n*o" +
+      "rg.apache.hadoop.hbase.protobuf.generate" +
+      "dB\013HBaseProtosH\001\240\001\001"
     };
     com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
       new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -15842,7 +15933,7 @@ public final class HBaseProtos {
           internal_static_RegionInfo_fieldAccessorTable = new
             com.google.protobuf.GeneratedMessage.FieldAccessorTable(
               internal_static_RegionInfo_descriptor,
-              new java.lang.String[] { "RegionId", "TableName", "StartKey", "EndKey", "Offline", "Split", });
+              new java.lang.String[] { "RegionId", "TableName", "StartKey", "EndKey", "Offline", "Split", "ReplicaId", });
           internal_static_FavoredNodes_descriptor =
             getDescriptor().getMessageTypes().get(4);
           internal_static_FavoredNodes_fieldAccessorTable = new

Modified: hbase/branches/hbase-10070/hbase-protocol/src/main/protobuf/HBase.proto
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-protocol/src/main/protobuf/HBase.proto?rev=1565041&r1=1565040&r2=1565041&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-protocol/src/main/protobuf/HBase.proto (original)
+++ hbase/branches/hbase-10070/hbase-protocol/src/main/protobuf/HBase.proto Thu Feb  6 02:04:53 2014
@@ -64,6 +64,7 @@ message RegionInfo {
   optional bytes end_key = 4;
   optional bool offline = 5;
   optional bool split = 6;
+  optional int32 replica_id = 7 [default = 0];
 }
 
 /**

Modified: hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java?rev=1565041&r1=1565040&r2=1565041&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java (original)
+++ hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java Thu Feb  6 02:04:53 2014
@@ -19,7 +19,6 @@ package org.apache.hadoop.hbase.catalog;
 
 import java.io.IOException;
 import java.io.InterruptedIOException;
-import java.net.ConnectException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -47,11 +46,10 @@ import com.google.protobuf.ServiceExcept
 
 /**
  * Writes region and assignment information to <code>hbase:meta</code>.
- * TODO: Put MetaReader and MetaEditor together; doesn't make sense having
- * them distinct. see HBASE-3475.
  */
 @InterfaceAudience.Private
-public class MetaEditor {
+public class MetaEditor extends MetaReader {
+
   // TODO: Strip CatalogTracker from this class.  Its all over and in the end
   // its only used to get its Configuration so we can get associated
   // Connection.
@@ -290,7 +288,7 @@ public class MetaEditor {
     Put put = new Put(regionInfo.getRegionName());
     addRegionInfo(put, regionInfo);
     if (sn != null) {
-      addLocation(put, sn, openSeqNum);
+      addLocation(put, sn, openSeqNum, regionInfo.getReplicaId());
     }
     putToMetaTable(catalogTracker, put);
     LOG.info("Added daughter " + regionInfo.getEncodedName() +
@@ -327,7 +325,7 @@ public class MetaEditor {
       Delete deleteB = makeDeleteFromRegionInfo(regionB);
 
       // The merged is a new region, openSeqNum = 1 is fine.
-      addLocation(putOfMerged, sn, 1);
+      addLocation(putOfMerged, sn, 1, mergedRegion.getReplicaId());
 
       byte[] tableRow = Bytes.toBytes(mergedRegion.getRegionNameAsString()
           + HConstants.DELIMITER);
@@ -365,8 +363,8 @@ public class MetaEditor {
       Put putA = makePutFromRegionInfo(splitA);
       Put putB = makePutFromRegionInfo(splitB);
 
-      addLocation(putA, sn, 1); //these are new regions, openSeqNum = 1 is fine.
-      addLocation(putB, sn, 1);
+      addLocation(putA, sn, 1, splitA.getReplicaId()); //new regions, openSeqNum = 1 is fine.
+      addLocation(putB, sn, 1, splitB.getReplicaId());
 
       byte[] tableRow = Bytes.toBytes(parent.getRegionNameAsString() + HConstants.DELIMITER);
       multiMutate(meta, tableRow, putParent, putA, putB);
@@ -401,29 +399,6 @@ public class MetaEditor {
     }
   }
 
-
-  /**
-   * Updates the location of the specified hbase:meta region in ROOT to be the
-   * specified server hostname and startcode.
-   * <p>
-   * Uses passed catalog tracker to get a connection to the server hosting
-   * ROOT and makes edits to that region.
-   *
-   * @param catalogTracker catalog tracker
-   * @param regionInfo region to update location of
-   * @param sn Server name
-   * @param openSeqNum the latest sequence number obtained when the region was open
-   * @throws IOException
-   * @throws ConnectException Usually because the regionserver carrying hbase:meta
-   * is down.
-   * @throws NullPointerException Because no -ROOT- server connection
-   */
-  public static void updateMetaLocation(CatalogTracker catalogTracker,
-      HRegionInfo regionInfo, ServerName sn, long openSeqNum)
-  throws IOException, ConnectException {
-    updateLocation(catalogTracker, regionInfo, sn, openSeqNum);
-  }
-
   /**
    * Updates the location of the specified region in hbase:meta to be the specified
    * server hostname and startcode.
@@ -458,8 +433,9 @@ public class MetaEditor {
   private static void updateLocation(final CatalogTracker catalogTracker,
       HRegionInfo regionInfo, ServerName sn, long openSeqNum)
   throws IOException {
-    Put put = new Put(regionInfo.getRegionName());
-    addLocation(put, sn, openSeqNum);
+    // region replicas are kept in the primary region's row
+    Put put = new Put(getMetaKeyForRegion(regionInfo));
+    addLocation(put, sn, openSeqNum, regionInfo.getReplicaId());
     putToCatalogTable(catalogTracker, put);
     LOG.info("Updated row " + regionInfo.getRegionNameAsString() +
       " with server=" + sn);
@@ -568,12 +544,12 @@ public class MetaEditor {
     return p;
   }
 
-  private static Put addLocation(final Put p, final ServerName sn, long openSeqNum) {
-    p.addImmutable(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
+  private static Put addLocation(final Put p, final ServerName sn, long openSeqNum, int replicaId){
+    p.addImmutable(HConstants.CATALOG_FAMILY, MetaReader.getServerColumn(replicaId),
       Bytes.toBytes(sn.getHostAndPort()));
-    p.addImmutable(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
+    p.addImmutable(HConstants.CATALOG_FAMILY, MetaReader.getStartCodeColumn(replicaId),
       Bytes.toBytes(sn.getStartcode()));
-    p.addImmutable(HConstants.CATALOG_FAMILY, HConstants.SEQNUM_QUALIFIER,
+    p.addImmutable(HConstants.CATALOG_FAMILY, MetaReader.getSeqNumColumn(replicaId),
         Bytes.toBytes(openSeqNum));
     return p;
   }

Modified: hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/client/CoprocessorHConnection.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/client/CoprocessorHConnection.java?rev=1565041&r1=1565040&r2=1565041&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/client/CoprocessorHConnection.java (original)
+++ hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/client/CoprocessorHConnection.java Thu Feb  6 02:04:53 2014
@@ -31,10 +31,6 @@ import org.apache.hadoop.hbase.MasterNot
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
-import org.apache.hadoop.hbase.client.HConnection;
-import org.apache.hadoop.hbase.client.HConnectionManager;
-import org.apache.hadoop.hbase.client.HTableInterface;
-import org.apache.hadoop.hbase.client.Row;
 import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
 import org.apache.hadoop.hbase.ipc.RpcServerInterface;
@@ -97,6 +93,7 @@ public class CoprocessorHConnection impl
     this.delegate = delegate;
   }
 
+  @Override
   public org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ClientService.BlockingInterface
       getClient(ServerName serverName) throws IOException {
     // client is trying to reach off-server, so we can't do anything special
@@ -129,260 +126,320 @@ public class CoprocessorHConnection impl
     return ClientService.newBlockingStub(channel);
   }
 
+  @Override
   public void abort(String why, Throwable e) {
     delegate.abort(why, e);
   }
 
+  @Override
   public boolean isAborted() {
     return delegate.isAborted();
   }
 
+  @Override
   public Configuration getConfiguration() {
     return delegate.getConfiguration();
   }
 
+  @Override
   public HTableInterface getTable(String tableName) throws IOException {
     return delegate.getTable(tableName);
   }
 
+  @Override
   public HTableInterface getTable(byte[] tableName) throws IOException {
     return delegate.getTable(tableName);
   }
 
+  @Override
   public HTableInterface getTable(TableName tableName) throws IOException {
     return delegate.getTable(tableName);
   }
 
+  @Override
   public HTableInterface getTable(String tableName, ExecutorService pool) throws IOException {
     return delegate.getTable(tableName, pool);
   }
 
+  @Override
   public HTableInterface getTable(byte[] tableName, ExecutorService pool) throws IOException {
     return delegate.getTable(tableName, pool);
   }
 
+  @Override
   public HTableInterface getTable(TableName tableName, ExecutorService pool) throws IOException {
     return delegate.getTable(tableName, pool);
   }
 
+  @Override
   public boolean isMasterRunning() throws MasterNotRunningException, ZooKeeperConnectionException {
     return delegate.isMasterRunning();
   }
 
+  @Override
   public boolean isTableEnabled(TableName tableName) throws IOException {
     return delegate.isTableEnabled(tableName);
   }
 
+  @Override
   public boolean isTableEnabled(byte[] tableName) throws IOException {
     return delegate.isTableEnabled(tableName);
   }
 
+  @Override
   public boolean isTableDisabled(TableName tableName) throws IOException {
     return delegate.isTableDisabled(tableName);
   }
 
+  @Override
   public boolean isTableDisabled(byte[] tableName) throws IOException {
     return delegate.isTableDisabled(tableName);
   }
 
+  @Override
   public boolean isTableAvailable(TableName tableName) throws IOException {
     return delegate.isTableAvailable(tableName);
   }
 
+  @Override
   public boolean isTableAvailable(byte[] tableName) throws IOException {
     return delegate.isTableAvailable(tableName);
   }
 
+  @Override
   public boolean isTableAvailable(TableName tableName, byte[][] splitKeys) throws IOException {
     return delegate.isTableAvailable(tableName, splitKeys);
   }
 
+  @Override
   public boolean isTableAvailable(byte[] tableName, byte[][] splitKeys) throws IOException {
     return delegate.isTableAvailable(tableName, splitKeys);
   }
 
+  @Override
   public HTableDescriptor[] listTables() throws IOException {
     return delegate.listTables();
   }
 
+  @Override
   public String[] getTableNames() throws IOException {
     return delegate.getTableNames();
   }
 
+  @Override
   public TableName[] listTableNames() throws IOException {
     return delegate.listTableNames();
   }
 
+  @Override
   public HTableDescriptor getHTableDescriptor(TableName tableName) throws IOException {
     return delegate.getHTableDescriptor(tableName);
   }
 
+  @Override
   public HTableDescriptor getHTableDescriptor(byte[] tableName) throws IOException {
     return delegate.getHTableDescriptor(tableName);
   }
 
+  @Override
   public HRegionLocation locateRegion(TableName tableName, byte[] row) throws IOException {
     return delegate.locateRegion(tableName, row);
   }
 
+  @Override
   public HRegionLocation locateRegion(byte[] tableName, byte[] row) throws IOException {
     return delegate.locateRegion(tableName, row);
   }
 
+  @Override
   public void clearRegionCache() {
     delegate.clearRegionCache();
   }
 
+  @Override
   public void clearRegionCache(TableName tableName) {
     delegate.clearRegionCache(tableName);
   }
 
+  @Override
   public void clearRegionCache(byte[] tableName) {
     delegate.clearRegionCache(tableName);
   }
 
+  @Override
   public HRegionLocation relocateRegion(TableName tableName, byte[] row) throws IOException {
     return delegate.relocateRegion(tableName, row);
   }
 
+  @Override
   public HRegionLocation relocateRegion(byte[] tableName, byte[] row) throws IOException {
     return delegate.relocateRegion(tableName, row);
   }
 
-  public void updateCachedLocations(TableName tableName, byte[] rowkey, Object exception,
-      ServerName source) {
-    delegate.updateCachedLocations(tableName, rowkey, exception, source);
+  @Override
+  public void updateCachedLocations(TableName tableName, byte[] regionName, byte[] rowkey,
+      Object exception, ServerName source) {
+    delegate.updateCachedLocations(tableName, regionName, rowkey, exception, source);
   }
 
+  @Override
   public void updateCachedLocations(TableName tableName, byte[] rowkey, Object exception,
       HRegionLocation source) {
     delegate.updateCachedLocations(tableName, rowkey, exception, source);
   }
 
+  @Override
   public void updateCachedLocations(byte[] tableName, byte[] rowkey, Object exception,
       HRegionLocation source) {
     delegate.updateCachedLocations(tableName, rowkey, exception, source);
   }
 
+  @Override
   public HRegionLocation locateRegion(byte[] regionName) throws IOException {
     return delegate.locateRegion(regionName);
   }
 
+  @Override
   public List<HRegionLocation> locateRegions(TableName tableName) throws IOException {
     return delegate.locateRegions(tableName);
   }
 
+  @Override
   public List<HRegionLocation> locateRegions(byte[] tableName) throws IOException {
     return delegate.locateRegions(tableName);
   }
 
+  @Override
   public List<HRegionLocation>
       locateRegions(TableName tableName, boolean useCache, boolean offlined) throws IOException {
     return delegate.locateRegions(tableName, useCache, offlined);
   }
 
+  @Override
   public List<HRegionLocation> locateRegions(byte[] tableName, boolean useCache, boolean offlined)
       throws IOException {
     return delegate.locateRegions(tableName, useCache, offlined);
   }
 
+  @Override
   public org.apache.hadoop.hbase.protobuf.generated.MasterProtos.MasterService.BlockingInterface getMaster()
   throws IOException {
     return delegate.getMaster();
   }
 
+  @Override
   public org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService.BlockingInterface
       getAdmin(ServerName serverName) throws IOException {
     return delegate.getAdmin(serverName);
   }
 
+  @Override
   public org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService.BlockingInterface
       getAdmin(ServerName serverName, boolean getMaster) throws IOException {
     return delegate.getAdmin(serverName, getMaster);
   }
 
+  @Override
   public HRegionLocation getRegionLocation(TableName tableName, byte[] row, boolean reload)
       throws IOException {
     return delegate.getRegionLocation(tableName, row, reload);
   }
 
+  @Override
   public HRegionLocation getRegionLocation(byte[] tableName, byte[] row, boolean reload)
       throws IOException {
     return delegate.getRegionLocation(tableName, row, reload);
   }
 
+  @Override
   public void processBatch(List<? extends Row> actions, TableName tableName, ExecutorService pool,
       Object[] results) throws IOException, InterruptedException {
     delegate.processBatch(actions, tableName, pool, results);
   }
 
+  @Override
   public void processBatch(List<? extends Row> actions, byte[] tableName, ExecutorService pool,
       Object[] results) throws IOException, InterruptedException {
     delegate.processBatch(actions, tableName, pool, results);
   }
 
+  @Override
   public <R> void processBatchCallback(List<? extends Row> list, TableName tableName,
       ExecutorService pool, Object[] results, Callback<R> callback) throws IOException,
       InterruptedException {
     delegate.processBatchCallback(list, tableName, pool, results, callback);
   }
 
+  @Override
   public <R> void processBatchCallback(List<? extends Row> list, byte[] tableName,
       ExecutorService pool, Object[] results, Callback<R> callback) throws IOException,
       InterruptedException {
     delegate.processBatchCallback(list, tableName, pool, results, callback);
   }
 
+  @Override
   public void setRegionCachePrefetch(TableName tableName, boolean enable) {
     delegate.setRegionCachePrefetch(tableName, enable);
   }
 
+  @Override
   public void setRegionCachePrefetch(byte[] tableName, boolean enable) {
     delegate.setRegionCachePrefetch(tableName, enable);
   }
 
+  @Override
   public boolean getRegionCachePrefetch(TableName tableName) {
     return delegate.getRegionCachePrefetch(tableName);
   }
 
+  @Override
   public boolean getRegionCachePrefetch(byte[] tableName) {
     return delegate.getRegionCachePrefetch(tableName);
   }
 
+  @Override
   public int getCurrentNrHRS() throws IOException {
     return delegate.getCurrentNrHRS();
   }
 
+  @Override
   public HTableDescriptor[] getHTableDescriptorsByTableName(List<TableName> tableNames)
       throws IOException {
     return delegate.getHTableDescriptorsByTableName(tableNames);
   }
 
+  @Override
   public HTableDescriptor[] getHTableDescriptors(List<String> tableNames) throws IOException {
     return delegate.getHTableDescriptors(tableNames);
   }
 
+  @Override
   public boolean isClosed() {
     return delegate.isClosed();
   }
 
+  @Override
   public void clearCaches(ServerName sn) {
     delegate.clearCaches(sn);
   }
 
+  @Override
   public void close() throws IOException {
     delegate.close();
   }
 
+  @Override
   public void deleteCachedRegionLocation(HRegionLocation location) {
     delegate.deleteCachedRegionLocation(location);
   }
 
+  @Override
   public MasterKeepAliveConnection getKeepAliveMasterService()
       throws MasterNotRunningException {
     return delegate.getKeepAliveMasterService();
   }
 
+  @Override
   public boolean isDeadServer(ServerName serverName) {
     return delegate.isDeadServer(serverName);
   }

Modified: hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditor.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditor.java?rev=1565041&r1=1565040&r2=1565041&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditor.java (original)
+++ hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditor.java Thu Feb  6 02:04:53 2014
@@ -25,24 +25,28 @@ import static org.junit.Assert.assertTru
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Random;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.Abortable;
-import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.MediumTests;
 import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -64,7 +68,7 @@ public class TestMetaReaderEditor {
       LOG.info(why, e);
       abort.set(true);
     }
-    
+
     @Override
     public boolean isAborted() {
       return abort.get();
@@ -294,5 +298,100 @@ public class TestMetaReaderEditor {
       pair.getFirst().getEncodedName());
   }
 
+  @Test
+  public void testParseReplicaIdFromServerColumn() {
+    String column1 = HConstants.SERVER_QUALIFIER_STR;
+    assertEquals(0, MetaReader.parseReplicaIdFromServerColumn(Bytes.toBytes(column1)));
+    String column2 = column1 + MetaReader.META_REPLICA_ID_DELIMITER;
+    assertEquals(-1, MetaReader.parseReplicaIdFromServerColumn(Bytes.toBytes(column2)));
+    String column3 = column2 + "00";
+    assertEquals(-1, MetaReader.parseReplicaIdFromServerColumn(Bytes.toBytes(column3)));
+    String column4 = column3 + "2A";
+    assertEquals(42, MetaReader.parseReplicaIdFromServerColumn(Bytes.toBytes(column4)));
+    String column5 = column4 + "2A";
+    assertEquals(-1, MetaReader.parseReplicaIdFromServerColumn(Bytes.toBytes(column5)));
+    String column6 = HConstants.STARTCODE_QUALIFIER_STR;
+    assertEquals(-1, MetaReader.parseReplicaIdFromServerColumn(Bytes.toBytes(column6)));
+  }
+
+  @Test
+  public void testMetaReaderGetColumnMethods() {
+    Assert.assertArrayEquals(HConstants.SERVER_QUALIFIER, MetaReader.getServerColumn(0));
+    Assert.assertArrayEquals(Bytes.toBytes(HConstants.SERVER_QUALIFIER_STR
+      + MetaReader.META_REPLICA_ID_DELIMITER + "002A"), MetaReader.getServerColumn(42));
+
+    Assert.assertArrayEquals(HConstants.STARTCODE_QUALIFIER, MetaReader.getStartCodeColumn(0));
+    Assert.assertArrayEquals(Bytes.toBytes(HConstants.STARTCODE_QUALIFIER_STR
+      + MetaReader.META_REPLICA_ID_DELIMITER + "002A"), MetaReader.getStartCodeColumn(42));
+
+    Assert.assertArrayEquals(HConstants.SEQNUM_QUALIFIER, MetaReader.getSeqNumColumn(0));
+    Assert.assertArrayEquals(Bytes.toBytes(HConstants.SEQNUM_QUALIFIER_STR
+      + MetaReader.META_REPLICA_ID_DELIMITER + "002A"), MetaReader.getSeqNumColumn(42));
+  }
+
+  @Test
+  public void testMetaLocationsForRegionReplicas() throws IOException {
+    Random random = new Random();
+    ServerName serverName0 = ServerName.valueOf("foo", 60010, random.nextLong());
+    ServerName serverName1 = ServerName.valueOf("bar", 60010, random.nextLong());
+    ServerName serverName100 = ServerName.valueOf("baz", 60010, random.nextLong());
+
+    long regionId = System.currentTimeMillis();
+    HRegionInfo primary = new HRegionInfo(TableName.valueOf("table_foo"),
+      HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false, regionId, 0);
+    HRegionInfo replica1 = new HRegionInfo(TableName.valueOf("table_foo"),
+      HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false, regionId, 1);
+    HRegionInfo replica100 = new HRegionInfo(TableName.valueOf("table_foo"),
+      HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false, regionId, 100);
+
+    long seqNum0 = random.nextLong();
+    long seqNum1 = random.nextLong();
+    long seqNum100 = random.nextLong();
+
+
+    HTable meta = MetaReader.getMetaHTable(CT);
+    try {
+      MetaEditor.updateRegionLocation(CT, primary, serverName0, seqNum0);
+
+      // assert that the server, startcode and seqNum columns are there for the primary region
+      assertMetaLocation(meta, primary.getRegionName(), serverName0, seqNum0, 0, true);
+
+      // add replica = 1
+      MetaEditor.updateRegionLocation(CT, replica1, serverName1, seqNum1);
+      // check whether the primary is still there
+      assertMetaLocation(meta, primary.getRegionName(), serverName0, seqNum0, 0, true);
+      // now check for replica 1
+      assertMetaLocation(meta, primary.getRegionName(), serverName1, seqNum1, 1, true);
+
+      // add replica = 1
+      MetaEditor.updateRegionLocation(CT, replica100, serverName100, seqNum100);
+      // check whether the primary is still there
+      assertMetaLocation(meta, primary.getRegionName(), serverName0, seqNum0, 0, true);
+      // check whether the replica 1 is still there
+      assertMetaLocation(meta, primary.getRegionName(), serverName1, seqNum1, 1, true);
+      // now check for replica 1
+      assertMetaLocation(meta, primary.getRegionName(), serverName100, seqNum100, 100, true);
+    } finally {
+      meta.close();
+    }
+  }
+
+  public static void assertMetaLocation(HTable meta, byte[] row, ServerName serverName,
+      long seqNum, int replicaId, boolean checkSeqNum) throws IOException {
+    Get get = new Get(row);
+    Result result = meta.get(get);
+    assertTrue(Bytes.equals(
+      result.getValue(HConstants.CATALOG_FAMILY, MetaReader.getServerColumn(replicaId)),
+      Bytes.toBytes(serverName.getHostAndPort())));
+    assertTrue(Bytes.equals(
+      result.getValue(HConstants.CATALOG_FAMILY, MetaReader.getStartCodeColumn(replicaId)),
+      Bytes.toBytes(serverName.getStartcode())));
+    if (checkSeqNum) {
+      assertTrue(Bytes.equals(
+        result.getValue(HConstants.CATALOG_FAMILY, MetaReader.getSeqNumColumn(replicaId)),
+        Bytes.toBytes(seqNum)));
+    }
+  }
+
 }
 

Modified: hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1565041&r1=1565040&r2=1565041&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (original)
+++ hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java Thu Feb  6 02:04:53 2014
@@ -26,6 +26,8 @@ import static org.junit.Assert.assertNul
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
 
 import java.io.IOException;
 import java.lang.reflect.Method;
@@ -60,6 +62,7 @@ import org.apache.hadoop.hbase.HTableDes
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.LargeTests;
 import org.apache.hadoop.hbase.MiniHBaseCluster;
+import org.apache.hadoop.hbase.RegionLocations;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
@@ -85,14 +88,15 @@ import org.apache.hadoop.hbase.ipc.RpcSe
 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto;
 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType;
-import org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MultiRowMutationService;
+import org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest;
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
 import org.apache.hadoop.hbase.regionserver.Store;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.hadoop.hbase.util.Pair;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.apache.log4j.Level;
 import org.junit.After;
@@ -5970,4 +5974,44 @@ public class TestFromClientSide {
     assertEquals(insertNum, count);
     table.close();
   }
+
+  @Test
+  public void testGetStartEndKeysWithRegionReplicas() throws IOException {
+    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("testGetStartEndKeys"));
+    HColumnDescriptor fam = new HColumnDescriptor(FAMILY);
+    htd.addFamily(fam);
+    byte[][] KEYS = HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE;
+    TEST_UTIL.getHBaseAdmin().createTable(htd, KEYS);
+    List<HRegionInfo> regions = TEST_UTIL.getHBaseAdmin().getTableRegions(htd.getTableName());
+
+    for (int regionReplication = 1; regionReplication < 4 ; regionReplication++) {
+      List<RegionLocations> regionLocations = new ArrayList<RegionLocations>();
+
+      // mock region locations coming from meta with multiple replicas
+      for (HRegionInfo region : regions) {
+        HRegionLocation[] arr = new HRegionLocation[regionReplication];
+        for (int i = 0; i < arr.length; i++) {
+          arr[i] = new HRegionLocation(RegionReplicaUtil.getRegionInfoForReplica(region, i), null);
+        }
+        regionLocations.add(new RegionLocations(arr));
+      }
+
+      HTable table = spy(new HTable(TEST_UTIL.getConfiguration(), htd.getTableName()));
+      when(table.listRegionLocations()).thenReturn(regionLocations);
+
+      Pair<byte[][], byte[][]> startEndKeys = table.getStartEndKeys();
+
+      assertEquals(KEYS.length + 1, startEndKeys.getFirst().length);
+
+      for (int i = 0; i < KEYS.length + 1; i++) {
+        byte[] startKey = i == 0 ? HConstants.EMPTY_START_ROW : KEYS[i - 1];
+        byte[] endKey = i == KEYS.length ? HConstants.EMPTY_END_ROW : KEYS[i];
+        assertArrayEquals(startKey, startEndKeys.getFirst()[i]);
+        assertArrayEquals(endKey, startEndKeys.getSecond()[i]);
+      }
+
+      table.close();
+    }
+  }
+
 }

Modified: hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java?rev=1565041&r1=1565040&r2=1565041&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java (original)
+++ hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java Thu Feb  6 02:04:53 2014
@@ -46,9 +46,9 @@ import org.apache.hadoop.conf.Configurat
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HRegionLocation;
 import org.apache.hadoop.hbase.MediumTests;
+import org.apache.hadoop.hbase.RegionLocations;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.Waiter;
@@ -359,15 +359,16 @@ public class TestHCM {
 
     assertNotNull(conn.getCachedLocation(TABLE_NAME, ROW));
 
-    final int nextPort = conn.getCachedLocation(TABLE_NAME, ROW).getPort() + 1;
-    HRegionLocation loc = conn.getCachedLocation(TABLE_NAME, ROW);
+    final int nextPort = conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation().getPort() + 1;
+    HRegionLocation loc = conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation();
     conn.updateCachedLocation(loc.getRegionInfo(), loc.getServerName(),
         ServerName.valueOf("127.0.0.1", nextPort,
         HConstants.LATEST_TIMESTAMP), HConstants.LATEST_TIMESTAMP);
-    Assert.assertEquals(conn.getCachedLocation(TABLE_NAME, ROW).getPort(), nextPort);
+    Assert.assertEquals(conn.getCachedLocation(TABLE_NAME, ROW)
+      .getRegionLocation().getPort(), nextPort);
 
-    conn.forceDeleteCachedLocation(TABLE_NAME, ROW.clone());
-    HRegionLocation rl = conn.getCachedLocation(TABLE_NAME, ROW);
+    conn.clearRegionCache(TABLE_NAME, ROW.clone());
+    RegionLocations rl = conn.getCachedLocation(TABLE_NAME, ROW);
     assertNull("What is this location?? " + rl, rl);
 
     // We're now going to move the region and check that it works for the client
@@ -389,7 +390,7 @@ public class TestHCM {
     }
 
     // Now moving the region to the second server
-    HRegionLocation toMove = conn.getCachedLocation(TABLE_NAME, ROW);
+    HRegionLocation toMove = conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation();
     byte[] regionName = toMove.getRegionInfo().getRegionName();
     byte[] encodedRegionNameBytes = toMove.getRegionInfo().getEncodedNameAsBytes();
 
@@ -438,7 +439,8 @@ public class TestHCM {
 
     // Cache was NOT updated and points to the wrong server
     Assert.assertFalse(
-        conn.getCachedLocation(TABLE_NAME, ROW).getPort() == destServerName.getPort());
+        conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation()
+          .getPort() == destServerName.getPort());
 
     // This part relies on a number of tries equals to 1.
     // We do a put and expect the cache to be updated, even if we don't retry
@@ -462,10 +464,13 @@ public class TestHCM {
     Assert.assertNotNull("Cached connection is null", conn.getCachedLocation(TABLE_NAME, ROW));
     Assert.assertEquals(
         "Previous server was " + curServer.getServerName().getHostAndPort(),
-        destServerName.getPort(), conn.getCachedLocation(TABLE_NAME, ROW).getPort());
+        destServerName.getPort(),
+        conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation().getPort());
 
-    Assert.assertFalse(destServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameBytes));
-    Assert.assertFalse(curServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameBytes));
+    Assert.assertFalse(destServer.getRegionsInTransitionInRS()
+      .containsKey(encodedRegionNameBytes));
+    Assert.assertFalse(curServer.getRegionsInTransitionInRS()
+      .containsKey(encodedRegionNameBytes));
 
     // We move it back to do another test with a scan
     LOG.info("Move starting region=" + toMove.getRegionInfo().getRegionNameAsString());
@@ -488,7 +493,7 @@ public class TestHCM {
     LOG.info("Move finished for region=" + toMove.getRegionInfo().getRegionNameAsString());
 
     // Cache was NOT updated and points to the wrong server
-    Assert.assertFalse(conn.getCachedLocation(TABLE_NAME, ROW).getPort() ==
+    Assert.assertFalse(conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation().getPort() ==
       curServer.getServerName().getPort());
 
     Scan sc = new Scan();
@@ -512,7 +517,8 @@ public class TestHCM {
     Assert.assertNotNull(conn.getCachedLocation(TABLE_NAME, ROW));
     Assert.assertEquals(
       "Previous server was "+destServer.getServerName().getHostAndPort(),
-      curServer.getServerName().getPort(), conn.getCachedLocation(TABLE_NAME, ROW).getPort());
+      curServer.getServerName().getPort(),
+      conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation().getPort());
 
     TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
         HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
@@ -551,7 +557,7 @@ public class TestHCM {
     HConnectionManager.HConnectionImplementation conn =
       (HConnectionManager.HConnectionImplementation)table.getConnection();
 
-    HRegionLocation location = conn.getCachedLocation(TABLE_NAME2, ROW);
+    HRegionLocation location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation();
     assertNotNull(location);
 
     ServerName anySource = ServerName.valueOf(location.getHostname(), location.getPort() - 1, 0L);
@@ -560,28 +566,28 @@ public class TestHCM {
     int nextPort = location.getPort() + 1;
     conn.updateCachedLocation(location.getRegionInfo(), location.getServerName(),
         ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1);
-    location = conn.getCachedLocation(TABLE_NAME2, ROW);
+    location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation();
     Assert.assertEquals(nextPort, location.getPort());
 
     // No source specified - same.
     nextPort = location.getPort() + 1;
     conn.updateCachedLocation(location.getRegionInfo(), location.getServerName(),
         ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1);
-    location = conn.getCachedLocation(TABLE_NAME2, ROW);
+    location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation();
     Assert.assertEquals(nextPort, location.getPort());
 
     // Higher seqNum - overwrites lower seqNum.
     nextPort = location.getPort() + 1;
     conn.updateCachedLocation(location.getRegionInfo(), anySource,
         ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() + 1);
-    location = conn.getCachedLocation(TABLE_NAME2, ROW);
+    location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation();
     Assert.assertEquals(nextPort, location.getPort());
 
     // Lower seqNum - does not overwrite higher seqNum.
     nextPort = location.getPort() + 1;
     conn.updateCachedLocation(location.getRegionInfo(), anySource,
         ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1);
-    location = conn.getCachedLocation(TABLE_NAME2, ROW);
+    location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation();
     Assert.assertEquals(nextPort - 1, location.getPort());
   }
 
@@ -778,7 +784,7 @@ public class TestHCM {
     table.put(put);
 
     // Now moving the region to the second server
-    HRegionLocation toMove = conn.getCachedLocation(TABLE_NAME3, ROW_X);
+    HRegionLocation toMove = conn.getCachedLocation(TABLE_NAME3, ROW_X).getRegionLocation();
     byte[] regionName = toMove.getRegionInfo().getRegionName();
     byte[] encodedRegionNameBytes = toMove.getRegionInfo().getEncodedNameAsBytes();
 
@@ -844,7 +850,8 @@ public class TestHCM {
 
     // Cache was NOT updated and points to the wrong server
     Assert.assertFalse(
-        conn.getCachedLocation(TABLE_NAME3, ROW_X).getPort() == destServerName.getPort());
+        conn.getCachedLocation(TABLE_NAME3, ROW_X).getRegionLocation()
+          .getPort() == destServerName.getPort());
 
     // Hijack the number of retry to fail after 2 tries
     final int prevNumRetriesVal = setNumTries(conn, 2);

Modified: hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java?rev=1565041&r1=1565040&r2=1565041&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java (original)
+++ hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java Thu Feb  6 02:04:53 2014
@@ -18,6 +18,7 @@
  */
 package org.apache.hadoop.hbase.regionserver;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -33,11 +34,15 @@ import org.apache.hadoop.hbase.HTableDes
 import org.apache.hadoop.hbase.SmallTests;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.exceptions.DeserializationException;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionInfo;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.MD5Hash;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import com.google.protobuf.ByteString;
+
 @Category(SmallTests.class)
 public class TestHRegionInfo {
   @Test
@@ -101,7 +106,7 @@ public class TestHRegionInfo {
                  + id + "." + md5HashInHex + ".",
                  nameStr);
   }
-  
+
   @Test
   public void testContainsRange() {
     HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf("testtable"));
@@ -121,7 +126,7 @@ public class TestHRegionInfo {
     assertFalse(hri.containsRange(Bytes.toBytes("g"), Bytes.toBytes("g")));
     // Single row range entirely outside
     assertFalse(hri.containsRange(Bytes.toBytes("z"), Bytes.toBytes("z")));
-    
+
     // Degenerate range
     try {
       hri.containsRange(Bytes.toBytes("z"), Bytes.toBytes("a"));
@@ -149,13 +154,106 @@ public class TestHRegionInfo {
   public void testComparator() {
     TableName tablename = TableName.valueOf("comparatorTablename");
     byte[] empty = new byte[0];
-    HRegionInfo older = new HRegionInfo(tablename, empty, empty, false, 0L); 
-    HRegionInfo newer = new HRegionInfo(tablename, empty, empty, false, 1L); 
+    HRegionInfo older = new HRegionInfo(tablename, empty, empty, false, 0L);
+    HRegionInfo newer = new HRegionInfo(tablename, empty, empty, false, 1L);
     assertTrue(older.compareTo(newer) < 0);
     assertTrue(newer.compareTo(older) > 0);
     assertTrue(older.compareTo(older) == 0);
     assertTrue(newer.compareTo(newer) == 0);
   }
-  
+
+  @Test
+  public void testRegionNameForRegionReplicas() throws Exception {
+    String tableName = "tablename";
+    final TableName tn = TableName.valueOf(tableName);
+    String startKey = "startkey";
+    final byte[] sk = Bytes.toBytes(startKey);
+    String id = "id";
+
+    // assert with only the region name without encoding
+
+    // primary, replicaId = 0
+    byte [] name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 0, false);
+    String nameStr = Bytes.toString(name);
+    assertEquals(tableName + "," + startKey + "," + id, nameStr);
+
+    // replicaId = 1
+    name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 1, false);
+    nameStr = Bytes.toString(name);
+    assertEquals(tableName + "," + startKey + "," + id + "_" +
+      String.format(HRegionInfo.REPLICA_ID_FORMAT, 1), nameStr);
+
+    // replicaId = max
+    name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 0xFFFF, false);
+    nameStr = Bytes.toString(name);
+    assertEquals(tableName + "," + startKey + "," + id + "_" +
+        String.format(HRegionInfo.REPLICA_ID_FORMAT, 0xFFFF), nameStr);
+  }
+
+  @Test
+  public void testParseName() throws IOException {
+    TableName tableName = TableName.valueOf("testParseName");
+    byte[] startKey = Bytes.toBytes("startKey");
+    long regionId = System.currentTimeMillis();
+    int replicaId = 42;
+
+    // test without replicaId
+    byte[] regionName = HRegionInfo.createRegionName(tableName, startKey, regionId, false);
+
+    byte[][] fields = HRegionInfo.parseRegionName(regionName);
+    assertArrayEquals(Bytes.toString(fields[0]),tableName.getName(), fields[0]);
+    assertArrayEquals(Bytes.toString(fields[1]),startKey, fields[1]);
+    assertArrayEquals(Bytes.toString(fields[2]), Bytes.toBytes(Long.toString(regionId)),fields[2]);
+    assertEquals(3, fields.length);
+
+    // test with replicaId
+    regionName = HRegionInfo.createRegionName(tableName, startKey, regionId,
+      replicaId, false);
+
+    fields = HRegionInfo.parseRegionName(regionName);
+    assertArrayEquals(Bytes.toString(fields[0]),tableName.getName(), fields[0]);
+    assertArrayEquals(Bytes.toString(fields[1]),startKey, fields[1]);
+    assertArrayEquals(Bytes.toString(fields[2]), Bytes.toBytes(Long.toString(regionId)),fields[2]);
+    assertArrayEquals(Bytes.toString(fields[3]), Bytes.toBytes(
+      String.format(HRegionInfo.REPLICA_ID_FORMAT, replicaId)), fields[3]);
+  }
+
+  @Test
+  public void testConvert() {
+    TableName tableName = TableName.valueOf("ns1:table1");
+    byte[] startKey = Bytes.toBytes("startKey");
+    byte[] endKey = Bytes.toBytes("endKey");
+    boolean split = false;
+    long regionId = System.currentTimeMillis();
+    int replicaId = 42;
+
+
+    HRegionInfo hri = new HRegionInfo(tableName, startKey, endKey, split,
+      regionId, replicaId);
+
+    // convert two times, compare
+    HRegionInfo convertedHri = HRegionInfo.convert(HRegionInfo.convert(hri));
+
+    assertEquals(hri, convertedHri);
+
+    // test convert RegionInfo without replicaId
+    RegionInfo info = RegionInfo.newBuilder()
+      .setTableName(HBaseProtos.TableName.newBuilder()
+        .setQualifier(ByteString.copyFrom(tableName.getQualifier()))
+        .setNamespace(ByteString.copyFrom(tableName.getNamespace()))
+        .build())
+      .setStartKey(ByteString.copyFrom(startKey))
+      .setEndKey(ByteString.copyFrom(endKey))
+      .setSplit(split)
+      .setRegionId(regionId)
+      .build();
+
+    convertedHri = HRegionInfo.convert(info);
+    HRegionInfo expectedHri = new HRegionInfo(tableName, startKey, endKey, split,
+      regionId, 0); // expecting default replicaId
+
+    assertEquals(expectedHri, convertedHri);
+  }
+
 }