You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ec...@apache.org on 2014/08/01 00:07:43 UTC
[07/50] [abbrv] git commit: [HBASE-9704] Fix regression from
https://phabricator.fb.com/D1363451
[HBASE-9704] Fix regression from https://phabricator.fb.com/D1363451
Summary: The root region location was used both by the region servers and the client to identify the communication protocol.
Test Plan: Run failed unit tests.
Reviewers: daviddeng, elliott
Reviewed By: elliott
Subscribers: hbase-eng@
Differential Revision: https://phabricator.fb.com/D1385394
Tasks: 4449946
git-svn-id: svn+ssh://tubbs/svnhive/hadoop/branches/titan/VENDOR.hbase/hbase-trunk@42901 e7acf4d4-3532-417f-9e73-7a9ae25a1f51
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/bd018332
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/bd018332
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/bd018332
Branch: refs/heads/0.89-fb
Commit: bd0183320170bb59c7a80acaf1c33922aeeaac74
Parents: 31b1af1
Author: manukranthk <ma...@e7acf4d4-3532-417f-9e73-7a9ae25a1f51>
Authored: Mon Jun 16 22:08:36 2014 +0000
Committer: Elliott Clark <el...@fb.com>
Committed: Thu Jul 31 14:44:22 2014 -0700
----------------------------------------------------------------------
.../org/apache/hadoop/hbase/HConstants.java | 6 ++
.../hadoop/hbase/client/TableServers.java | 70 ++++++++++++++------
.../org/apache/hadoop/hbase/master/HMaster.java | 3 +
.../hadoop/hbase/master/RegionManager.java | 4 +-
.../hbase/regionserver/HRegionServer.java | 10 ++-
.../hbase/zookeeper/ZooKeeperWrapper.java | 24 +++++--
6 files changed, 88 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/bd018332/src/main/java/org/apache/hadoop/hbase/HConstants.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/HConstants.java b/src/main/java/org/apache/hadoop/hbase/HConstants.java
index 65f7ff8..ddaabce 100644
--- a/src/main/java/org/apache/hadoop/hbase/HConstants.java
+++ b/src/main/java/org/apache/hadoop/hbase/HConstants.java
@@ -1124,6 +1124,12 @@ public final class HConstants {
public static final ProtocolVersion PROTOCOL_VERSION
= PROTOCOL_VERSION_THRIFT;
+ public static final String CLIENT_TO_RS_PROTOCOL_VERSION =
+ "hbase.client.to.rs.protocol.version";
+
+ public static final String CLIENT_TO_RS_PROTOCOL_VERSION_DEFAULT =
+ PROTOCOL_VERSION_THRIFT.name();
+
private HConstants() {
// Can't be instantiated with this constructor.
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/bd018332/src/main/java/org/apache/hadoop/hbase/client/TableServers.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/client/TableServers.java b/src/main/java/org/apache/hadoop/hbase/client/TableServers.java
index 9c04348..a95e2ba 100644
--- a/src/main/java/org/apache/hadoop/hbase/client/TableServers.java
+++ b/src/main/java/org/apache/hadoop/hbase/client/TableServers.java
@@ -244,9 +244,7 @@ public class TableServers implements ServerConnection {
batchedUploadUpdatesMap = new ConcurrentHashMap<>();
private int batchedUploadSoftFlushRetries;
private long batchedUploadSoftFlushTimeoutMillis;
- private final boolean useThrift;
- // Zookeeper wrapper to query zookeeper for client bootstrap.
- private static ZooKeeperWrapper staticZK = null;
+ private AtomicBoolean useThrift = null;
private Map<StringBytes, StringBytes> initializedTableSet =
new ConcurrentHashMap<>();
@@ -258,21 +256,6 @@ public class TableServers implements ServerConnection {
public TableServers(Configuration conf) {
this.conf = conf;
params = HConnectionParams.getInstance(conf);
- boolean useThrift = conf.getBoolean(HConstants.CLIENT_TO_RS_USE_THRIFT,
- HConstants.CLIENT_TO_RS_USE_THRIFT_DEFAULT);
- try {
- if (staticZK == null) {
- staticZK = getZooKeeperWrapper();
- }
- RootRegionLocation loc = staticZK.readWrappedRootRegionLocation();
- if (loc != null) {
- useThrift = loc.getProtocolVersion() ==
- ProtocolVersion.THRIFT ? true : false;
- }
- } catch (Exception e) {
- LOG.error("Falling back to config based protocol version detection", e);
- }
- this.useThrift = useThrift;
String serverClassName =
conf.get(HConstants.REGION_SERVER_CLASS,
@@ -1199,6 +1182,48 @@ private HRegionLocation locateMetaInRoot(final byte[] row,
metaCache.clear();
}
+ public static ProtocolVersion getProtocolVersionFromConf(Configuration conf) {
+ String protocolVersion = conf.get(HConstants.CLIENT_TO_RS_PROTOCOL_VERSION);
+ if (protocolVersion == null) {
+ return null;
+ }
+ try {
+ return ProtocolVersion.valueOf(protocolVersion);
+ } catch(Exception e) {
+ return null;
+ }
+ }
+
+ public void lazilySetProtocolVersionFromConfigAndRoot() {
+ if (this.useThrift != null) return;
+ synchronized (this) {
+ if (this.useThrift != null) return;
+ useThrift = new AtomicBoolean();
+ ProtocolVersion protocolVersion = getProtocolVersionFromConf(this.conf);
+ if (protocolVersion != null) {
+ if (protocolVersion == ProtocolVersion.THRIFT) {
+ useThrift.set(true);
+ } else {
+ useThrift.set(false);
+ }
+ } else {
+ try {
+ ZooKeeperWrapper staticZK = getZooKeeperWrapper();
+ RootRegionLocation loc =
+ staticZK.readWrappedRootRegionLocation(protocolVersion);
+ if (loc != null) {
+ useThrift.set(loc.getProtocolVersion() ==
+ ProtocolVersion.THRIFT ? true : false);
+ }
+ } catch (Exception e) {
+ LOG.error("Falling back to config based protocol version detection", e);
+ this.useThrift.set(conf.getBoolean(HConstants.CLIENT_TO_RS_USE_THRIFT,
+ HConstants.CLIENT_TO_RS_USE_THRIFT_DEFAULT));
+ }
+ }
+ }
+ }
+
@SuppressWarnings("resource")
@Override
public HRegionInterface getHRegionConnection(
@@ -1209,7 +1234,9 @@ private HRegionLocation locateMetaInRoot(final byte[] row,
getMaster();
}
HRegionInterface server = HRegionServer.getMainRS(regionServer);
- if (server != null && !this.useThrift) {
+ lazilySetProtocolVersionFromConfigAndRoot();
+
+ if (server != null && !this.useThrift.get()) {
return server;
}
@@ -1222,7 +1249,7 @@ private HRegionLocation locateMetaInRoot(final byte[] row,
// establish an RPC for this RS
// set hbase.ipc.client.connect.max.retries to retry connection
// attempts
- if (this.useThrift) {
+ if (this.useThrift.get()) {
Class<? extends ThriftClientInterface> serverInterface =
ThriftHRegionInterface.Async.class;
if (thriftPortWrittenToMeta) {
@@ -1310,7 +1337,8 @@ private HRegionLocation locateMetaInRoot(final byte[] row,
&& localTimeouts < params.getNumRetries()) {
// Don't read root region until we're out of safe mode so we know
// that the meta regions have been assigned.
- rootRegionAddress = zk.readRootRegionLocation();
+ rootRegionAddress = zk.readRootRegionLocation(
+ getProtocolVersionFromConf(conf));
if (rootRegionAddress == null) {
try {
if (LOG.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/hbase/blob/bd018332/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
index 0d008ff..c95f821 100755
--- a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
+++ b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
@@ -76,6 +76,7 @@ import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.LocalHBaseCluster;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.MiniZooKeeperCluster;
+import org.apache.hadoop.hbase.ProtocolVersion;
import org.apache.hadoop.hbase.RemoteExceptionHandler;
import org.apache.hadoop.hbase.StopStatus;
import org.apache.hadoop.hbase.TableExistsException;
@@ -271,6 +272,8 @@ public class HMaster extends HasThread implements HMasterInterface,
*/
public HMaster(Configuration conf) throws IOException {
this.conf = conf;
+ this.conf.set(HConstants.CLIENT_TO_RS_PROTOCOL_VERSION,
+ ProtocolVersion.THRIFT.name());
// Get my address. So what's the difference between the temp a and address?
// address.toString() will always produce an IP address as the hostname.
http://git-wip-us.apache.org/repos/asf/hbase/blob/bd018332/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java b/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java
index b44d1a7..6a61715 100755
--- a/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java
+++ b/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java
@@ -53,6 +53,7 @@ import org.apache.hadoop.hbase.HServerInfo;
import org.apache.hadoop.hbase.HServerLoad;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.TableServers;
import org.apache.hadoop.hbase.executor.HBaseEventHandler.HBaseEventType;
import org.apache.hadoop.hbase.executor.RegionTransitionEventData;
import org.apache.hadoop.hbase.ipc.HRegionInterface;
@@ -2756,7 +2757,8 @@ public class RegionManager {
/** Recovers root region location from ZK. Should only be called on master startup. */
void recoverRootRegionLocationFromZK() {
- HServerInfo rootLocationInZK = zkWrapper.readRootRegionServerInfo();
+ HServerInfo rootLocationInZK = zkWrapper.readRootRegionServerInfo(
+ TableServers.getProtocolVersionFromConf(this.master.getConfiguration()));
if (rootLocationInZK != null) {
synchronized (rootRegionLocation) {
rootRegionLocation.set(rootLocationInZK);
http://git-wip-us.apache.org/repos/asf/hbase/blob/bd018332/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
index 5abb0ec..7cbf606 100755
--- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
+++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
@@ -93,6 +93,7 @@ import org.apache.hadoop.hbase.Leases;
import org.apache.hadoop.hbase.Leases.LeaseStillHeldException;
import org.apache.hadoop.hbase.LocalHBaseCluster;
import org.apache.hadoop.hbase.NotServingRegionException;
+import org.apache.hadoop.hbase.ProtocolVersion;
import org.apache.hadoop.hbase.RemoteExceptionHandler;
import org.apache.hadoop.hbase.UnknownRowLockException;
import org.apache.hadoop.hbase.UnknownScannerException;
@@ -620,6 +621,9 @@ public class HRegionServer implements HRegionServerIf, HBaseRPCErrorHandler,
this.rpcServerInfo = new HServerInfo(new HServerAddress(
new InetSocketAddress(address.getBindAddress(), port)),
System.currentTimeMillis(), machineName);
+
+ this.conf.set(HConstants.CLIENT_TO_RS_PROTOCOL_VERSION,
+ ProtocolVersion.HADOOP_RPC.name());
}
if (useThrift) {
int niftyServerPort =
@@ -643,6 +647,8 @@ public class HRegionServer implements HRegionServerIf, HBaseRPCErrorHandler,
port = niftyThriftServer.getPort();
}
isRpcServerRunning = true;
+ this.conf.set(HConstants.CLIENT_TO_RS_PROTOCOL_VERSION,
+ ProtocolVersion.THRIFT.name());
}
this.serverInfo = new HServerInfo(new HServerAddress(
@@ -890,7 +896,9 @@ public class HRegionServer implements HRegionServerIf, HBaseRPCErrorHandler,
for (int tries = 0; !stopRequestedAtStageOne.get() && isHealthy();) {
// Try to get the root region location from the master.
if (!haveRootRegion.get()) {
- HServerAddress rootServer = zooKeeperWrapper.readRootRegionLocation();
+ HServerAddress rootServer =
+ zooKeeperWrapper.readRootRegionLocation(
+ TableServers.getProtocolVersionFromConf(conf));
if (rootServer != null) {
// By setting the root region location, we bypass the wait imposed
// on HTable for all regions being assigned.
http://git-wip-us.apache.org/repos/asf/hbase/blob/bd018332/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
index de7589e..6b42554 100644
--- a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
+++ b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
@@ -53,7 +53,9 @@ import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.HServerInfo;
+import org.apache.hadoop.hbase.ProtocolVersion;
import org.apache.hadoop.hbase.RootRegionLocation;
+import org.apache.hadoop.hbase.client.TableServers;
import org.apache.hadoop.hbase.executor.HBaseEventHandler.HBaseEventType;
import org.apache.hadoop.hbase.executor.RegionTransitionEventData;
import org.apache.hadoop.hbase.util.Bytes;
@@ -183,6 +185,11 @@ public class ZooKeeperWrapper implements Watcher {
private static SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
+ /**
+ * Configuration object to get the protocol version from.
+ */
+ private final Configuration conf;
+
private static String format(long date) {
return format.format(new Date(date));
}
@@ -259,6 +266,7 @@ public class ZooKeeperWrapper implements Watcher {
Abortable abortable) throws IOException {
this.instanceName = instanceName;
Properties properties = HQuorumPeer.makeZKProps(conf);
+ this.conf = conf;
quorumServers = HQuorumPeer.getZKQuorumServersString(properties);
if (quorumServers == null) {
throw new IOException("Could not read quorum servers from " +
@@ -394,7 +402,8 @@ public class ZooKeeperWrapper implements Watcher {
sb.append("\nHBase tree in ZooKeeper is rooted at ").append(parentZNode);
sb.append("\n Cluster up? ").append(exists(clusterStateZNode, true));
sb.append("\n Master address: ").append(readMasterAddress(null));
- sb.append("\n Region server holding ROOT: ").append(readRootRegionLocation());
+ sb.append("\n Region server holding ROOT: ").append(readRootRegionLocation(
+ TableServers.getProtocolVersionFromConf(conf)));
sb.append("\n Region servers:");
for (HServerAddress address : scanRSDirectory()) {
sb.append("\n - ").append(address);
@@ -588,12 +597,13 @@ public class ZooKeeperWrapper implements Watcher {
* @return HServerAddress pointing to server serving root region or null if
* there was a problem reading the ZNode.
*/
- public HServerAddress readRootRegionLocation() {
- RootRegionLocation loc = readWrappedRootRegionLocation();
+ public HServerAddress readRootRegionLocation(ProtocolVersion defaultProtocolVersion) {
+ RootRegionLocation loc = readWrappedRootRegionLocation(defaultProtocolVersion);
return loc == null ? null : loc.getServerAddress();
}
- public RootRegionLocation readWrappedRootRegionLocation() {
+ public RootRegionLocation readWrappedRootRegionLocation(
+ ProtocolVersion defaultProtocolVersion) {
RootRegionLocation loc = readRootRegionLocation(rootRegionZNodeFinal, null);
if (loc != null) {
return loc;
@@ -611,8 +621,10 @@ public class ZooKeeperWrapper implements Watcher {
/**
* @return the location of the server serving the root region, including the start code
*/
- public HServerInfo readRootRegionServerInfo() {
- RootRegionLocation loc = readWrappedRootRegionLocation();
+ public HServerInfo readRootRegionServerInfo(ProtocolVersion
+ defaultProtocolVersion) {
+ RootRegionLocation loc = readWrappedRootRegionLocation(
+ defaultProtocolVersion);
if (loc == null) return null;
return new HServerInfo(loc.getServerAddress(),
loc.getStartCode(), loc.getHostName());