Skip to content

Commit

Permalink
HBASE-23304: RPCs needed for client meta information lookup (#904)
Browse files Browse the repository at this point in the history
* HBASE-23304: RPCs needed for client meta information lookup

This patch implements the RPCs needed for the meta information
lookup during connection init. New tests added to cover the RPC
code paths. HBASE-23305 builds on this to implement the client
side logic.

Fixed a bunch of checkstyle nits around the places the patch
touches.

Signed-off-by: Andrew Purtell <apurtell@apache.org>
(cherry picked from commit 4f8fbba)
(cherry picked from commit 488460e)
  • Loading branch information
bharathv committed Sep 19, 2020
1 parent 9a1d5a0 commit 18200b0
Show file tree
Hide file tree
Showing 11 changed files with 4,943 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.apache.hadoop.hbase.HBaseIOException;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.NamespaceDescriptor;
Expand Down Expand Up @@ -3703,15 +3704,17 @@ public static RegionState parseMetaRegionStateFrom(final byte[] data, int replic
/**
* Get a ServerName from the passed in data bytes.
* @param data Data with a serialize server name in it; can handle the old style
* servername where servername was host and port. Works too with data that
* begins w/ the pb 'PBUF' magic and that is then followed by a protobuf that
* has a serialized {@link ServerName} in it.
* servername where servername was host and port. Works too with data that
* begins w/ the pb 'PBUF' magic and that is then followed by a protobuf that
* has a serialized {@link ServerName} in it.
* @return Returns null if <code>data</code> is null else converts passed data
* to a ServerName instance.
* @throws DeserializationException
* to a ServerName instance.
* @throws DeserializationException when data cannot be de-serialized as expected.
*/
public static ServerName parseServerNameFrom(final byte [] data) throws DeserializationException {
if (data == null || data.length <= 0) return null;
if (data == null || data.length <= 0) {
return null;
}
if (isPBMagicPrefix(data)) {
int prefixLen = lengthOfPBMagic();
try {
Expand Down Expand Up @@ -3743,4 +3746,20 @@ public static ServerName parseServerNameFrom(final byte [] data) throws Deserial
int port = Addressing.parsePort(str);
return ServerName.valueOf(hostname, port, -1L);
}

public static HBaseProtos.RegionLocation toRegionLocation(HRegionLocation loc) {
HBaseProtos.RegionLocation.Builder builder = HBaseProtos.RegionLocation.newBuilder();
builder.setRegionInfo(HRegionInfo.convert(loc.getRegionInfo()));
if (loc.getServerName() != null) {
builder.setServerName(toServerName(loc.getServerName()));
}
builder.setSeqNum(loc.getSeqNum());
return builder.build();
}

public static HRegionLocation toRegionLocation(HBaseProtos.RegionLocation proto) {
org.apache.hadoop.hbase.HRegionInfo regionInfo = HRegionInfo.convert(proto.getRegionInfo());
ServerName serverName = proto.hasServerName() ? toServerName(proto.getServerName()) : null;
return new HRegionLocation(regionInfo, serverName, proto.getSeqNum());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,9 @@ public String getZNodeForReplica(int replicaId) {
*/
public int getMetaReplicaIdFromZnode(String znode) {
String pattern = conf.get("zookeeper.znode.metaserver","meta-region-server");
if (znode.equals(pattern)) return DEFAULT_REPLICA_ID;
if (znode.equals(pattern)) {
return DEFAULT_REPLICA_ID;
}
// the non-default replicas are of the pattern meta-region-server-<replicaId>
String nonDefaultPattern = pattern + "-";
return Integer.parseInt(znode.substring(nonDefaultPattern.length()));
Expand Down
Loading

0 comments on commit 18200b0

Please sign in to comment.