diff --git security/src/main/java/org/apache/hadoop/hbase/ipc/SecureRpcEngine.java security/src/main/java/org/apache/hadoop/hbase/ipc/SecureRpcEngine.java
index 39d20e6..8383d6c 100644
--- security/src/main/java/org/apache/hadoop/hbase/ipc/SecureRpcEngine.java
+++ security/src/main/java/org/apache/hadoop/hbase/ipc/SecureRpcEngine.java
@@ -212,11 +212,25 @@ public class SecureRpcEngine implements RpcEngine {
(VersionedProtocol) Proxy.newProxyInstance(
protocol.getClassLoader(), new Class[] { protocol },
new Invoker(protocol, addr, ticket, conf, factory, rpcTimeout));
- long serverVersion = proxy.getProtocolVersion(protocol.getName(),
- clientVersion);
- if (serverVersion != clientVersion) {
- throw new HBaseRPC.VersionMismatch(protocol.getName(), clientVersion,
- serverVersion);
+ try {
+ long serverVersion = proxy.getProtocolVersion(protocol.getName(),
+ clientVersion);
+ if (serverVersion != clientVersion) {
+ throw new HBaseRPC.VersionMismatch(protocol.getName(), clientVersion,
+ serverVersion);
+ }
+ } catch (Throwable t) {
+ if (t instanceof UndeclaredThrowableException) {
+ t = t.getCause();
+ }
+ if (t instanceof ServiceException) {
+ throw ProtobufUtil.getRemoteException((ServiceException)t);
+ }
+ if (!(t instanceof IOException)) {
+ LOG.error("Unexpected throwable object ", t);
+ throw new IOException(t);
+ }
+ throw (IOException)t;
}
return proxy;
}
diff --git src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java
index 408db79..bafec30 100644
--- src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java
+++ src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java
@@ -34,11 +34,13 @@ import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException;
import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.client.AdminProtocol;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
+import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.RetriesExhaustedException;
-import org.apache.hadoop.hbase.ipc.HRegionInterface;
import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
+import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.zookeeper.MetaNodeTracker;
import org.apache.hadoop.hbase.zookeeper.RootRegionTracker;
@@ -340,7 +342,7 @@ public class CatalogTracker {
* @throws IOException
* @deprecated Use #getRootServerConnection(long)
*/
- public HRegionInterface waitForRootServerConnection(long timeout)
+ public AdminProtocol waitForRootServerConnection(long timeout)
throws InterruptedException, NotAllMetaRegionsOnlineException, IOException {
return getRootServerConnection(timeout);
}
@@ -356,7 +358,7 @@ public class CatalogTracker {
* @throws NotAllMetaRegionsOnlineException if timed out waiting
* @throws IOException
*/
- HRegionInterface getRootServerConnection(long timeout)
+ AdminProtocol getRootServerConnection(long timeout)
throws InterruptedException, NotAllMetaRegionsOnlineException, IOException {
return getCachedConnection(waitForRoot(timeout));
}
@@ -370,7 +372,7 @@ public class CatalogTracker {
* @throws IOException
* @deprecated Use #getRootServerConnection(long)
*/
- public HRegionInterface waitForRootServerConnectionDefault()
+ public AdminProtocol waitForRootServerConnectionDefault()
throws NotAllMetaRegionsOnlineException, IOException {
try {
return getRootServerConnection(this.defaultTimeout);
@@ -395,11 +397,11 @@ public class CatalogTracker {
* @throws IOException
* @throws InterruptedException
*/
- private HRegionInterface getMetaServerConnection()
+ private AdminProtocol getMetaServerConnection()
throws IOException, InterruptedException {
synchronized (metaAvailable) {
if (metaAvailable.get()) {
- HRegionInterface current = getCachedConnection(this.metaLocation);
+ AdminProtocol current = getCachedConnection(this.metaLocation);
// If we are to refresh, verify we have a good connection by making
// an invocation on it.
if (verifyRegionLocation(current, this.metaLocation, META_REGION_NAME)) {
@@ -416,7 +418,7 @@ public class CatalogTracker {
ServerName newLocation = MetaReader.getMetaRegionLocation(this);
if (newLocation == null) return null;
- HRegionInterface newConnection = getCachedConnection(newLocation);
+ AdminProtocol newConnection = getCachedConnection(newLocation);
if (verifyRegionLocation(newConnection, newLocation, META_REGION_NAME)) {
setMetaLocation(newLocation);
return newConnection;
@@ -495,7 +497,7 @@ public class CatalogTracker {
* @throws IOException
* @deprecated Does not retry; use an HTable instance instead.
*/
- public HRegionInterface waitForMetaServerConnection(long timeout)
+ public AdminProtocol waitForMetaServerConnection(long timeout)
throws InterruptedException, NotAllMetaRegionsOnlineException, IOException {
return getCachedConnection(waitForMeta(timeout));
}
@@ -510,7 +512,7 @@ public class CatalogTracker {
* @throws IOException
* @deprecated Does not retry; use an HTable instance instead.
*/
- public HRegionInterface waitForMetaServerConnectionDefault()
+ public AdminProtocol waitForMetaServerConnectionDefault()
throws NotAllMetaRegionsOnlineException, IOException {
try {
return getCachedConnection(waitForMeta(defaultTimeout));
@@ -546,19 +548,19 @@ public class CatalogTracker {
/**
* @param sn ServerName to get a connection against.
- * @return The HRegionInterface we got when we connected to sn
+ * @return The AdminProtocol we got when we connected to sn
* May have come from cache, may not be good, may have been setup by this
* invocation, or may be null.
* @throws IOException
*/
- private HRegionInterface getCachedConnection(ServerName sn)
+ private AdminProtocol getCachedConnection(ServerName sn)
throws IOException {
if (sn == null) {
return null;
}
- HRegionInterface protocol = null;
+ AdminProtocol protocol = null;
try {
- protocol = connection.getHRegionConnection(sn.getHostname(), sn.getPort());
+ protocol = connection.getAdmin(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.
@@ -599,11 +601,11 @@ public class CatalogTracker {
* the Interface.
* @throws IOException
*/
- // TODO: We should be able to get the ServerName from the HRegionInterface
+ // TODO: We should be able to get the ServerName from the AdminProtocol
// rather than have to pass it in. Its made awkward by the fact that the
// HRI is likely a proxy against remote server so the getServerName needs
// to be fixed to go to a local method or to a cache before we can do this.
- private boolean verifyRegionLocation(HRegionInterface hostingServer,
+ private boolean verifyRegionLocation(AdminProtocol hostingServer,
final ServerName address, final byte [] regionName)
throws IOException {
if (hostingServer == null) {
@@ -613,7 +615,7 @@ public class CatalogTracker {
Throwable t = null;
try {
// Try and get regioninfo from the hosting server.
- return hostingServer.getRegionInfo(regionName) != null;
+ return ProtobufUtil.getRegionInfo(hostingServer, regionName) != null;
} catch (ConnectException e) {
t = e;
} catch (RetriesExhaustedException e) {
@@ -647,7 +649,7 @@ public class CatalogTracker {
*/
public boolean verifyRootRegionLocation(final long timeout)
throws InterruptedException, IOException {
- HRegionInterface connection = null;
+ AdminProtocol connection = null;
try {
connection = waitForRootServerConnection(timeout);
} catch (NotAllMetaRegionsOnlineException e) {
@@ -672,7 +674,7 @@ public class CatalogTracker {
*/
public boolean verifyMetaRegionLocation(final long timeout)
throws InterruptedException, IOException {
- HRegionInterface connection = null;
+ AdminProtocol connection = null;
try {
connection = waitForMetaServerConnection(timeout);
} catch (NotAllMetaRegionsOnlineException e) {
diff --git src/main/java/org/apache/hadoop/hbase/client/AdminProtocol.java src/main/java/org/apache/hadoop/hbase/client/AdminProtocol.java
new file mode 100644
index 0000000..bc37197
--- /dev/null
+++ src/main/java/org/apache/hadoop/hbase/client/AdminProtocol.java
@@ -0,0 +1,37 @@
+/**
+ * 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.client;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.ipc.VersionedProtocol;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService;
+import org.apache.hadoop.hbase.security.TokenInfo;
+import org.apache.hadoop.security.KerberosInfo;
+
+/**
+ * Protocol that a HBase client uses to communicate with a region server.
+ */
+@KerberosInfo(
+ serverPrincipal = "hbase.regionserver.kerberos.principal")
+@TokenInfo("HBASE_AUTH_TOKEN")
+@InterfaceAudience.Private
+public interface AdminProtocol extends
+ AdminService.BlockingInterface, VersionedProtocol {
+ public static final long VERSION = 1L;
+}
diff --git src/main/java/org/apache/hadoop/hbase/client/ClientProtocol.java src/main/java/org/apache/hadoop/hbase/client/ClientProtocol.java
new file mode 100644
index 0000000..1745aa3
--- /dev/null
+++ src/main/java/org/apache/hadoop/hbase/client/ClientProtocol.java
@@ -0,0 +1,39 @@
+/**
+ * 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.client;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.hbase.ipc.VersionedProtocol;
+import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ClientService;
+import org.apache.hadoop.hbase.security.TokenInfo;
+import org.apache.hadoop.security.KerberosInfo;
+
+/**
+ * Protocol that a HBase client uses to communicate with a region server.
+ */
+@KerberosInfo(
+ serverPrincipal = "hbase.regionserver.kerberos.principal")
+@TokenInfo("HBASE_AUTH_TOKEN")
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public interface ClientProtocol extends
+ ClientService.BlockingInterface, VersionedProtocol {
+ public static final long VERSION = 1L;
+}
diff --git src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
index ee16e72..9c62865 100644
--- src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
+++ src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
@@ -53,13 +53,21 @@ import org.apache.hadoop.hbase.UnknownRegionException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.catalog.CatalogTracker;
import org.apache.hadoop.hbase.catalog.MetaReader;
+import org.apache.hadoop.hbase.client.AdminProtocol;
+import org.apache.hadoop.hbase.client.ClientProtocol;
import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
-import org.apache.hadoop.hbase.ipc.HRegionInterface;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
-import org.apache.hadoop.hbase.protobuf.ClientProtocol;
import org.apache.hadoop.hbase.protobuf.RequestConverter;
import org.apache.hadoop.hbase.protobuf.ResponseConverter;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.CloseRegionRequest;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.CloseRegionResponse;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.CompactRegionRequest;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.FlushRegionRequest;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.RollWALWriterRequest;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.RollWALWriterResponse;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.SplitRegionRequest;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.StopServerRequest;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ScanRequest;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ScanResponse;
import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException;
@@ -71,6 +79,7 @@ import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.util.StringUtils;
import org.apache.zookeeper.KeeperException;
+import com.google.protobuf.ByteString;
import com.google.protobuf.ServiceException;
/**
@@ -1098,14 +1107,21 @@ public class HBaseAdmin implements Abortable, Closeable {
"The servername cannot be null or empty.");
}
ServerName sn = new ServerName(serverName);
- HRegionInterface rs = this.connection.getHRegionConnection(
+ AdminProtocol rs = this.connection.getAdmin(
sn.getHostname(), sn.getPort());
// Close the region without updating zk state.
- boolean isRegionClosed = rs.closeRegion(encodedRegionNameInBytes, false);
- if (false == isRegionClosed) {
- LOG.error("Not able to close the region " + encodedRegionName + ".");
+ CloseRegionRequest request =
+ RequestConverter.buildCloseRegionRequest(encodedRegionName, false);
+ try {
+ CloseRegionResponse response = rs.closeRegion(null, request);
+ boolean isRegionClosed = response.getClosed();
+ if (false == isRegionClosed) {
+ LOG.error("Not able to close the region " + encodedRegionName + ".");
+ }
+ return isRegionClosed;
+ } catch (ServiceException se) {
+ throw ProtobufUtil.getRemoteException(se);
}
- return isRegionClosed;
}
/**
@@ -1117,10 +1133,10 @@ public class HBaseAdmin implements Abortable, Closeable {
*/
public void closeRegion(final ServerName sn, final HRegionInfo hri)
throws IOException {
- HRegionInterface rs =
- this.connection.getHRegionConnection(sn.getHostname(), sn.getPort());
+ AdminProtocol rs =
+ this.connection.getAdmin(sn.getHostname(), sn.getPort());
// Close the region without updating zk state.
- rs.closeRegion(hri, false);
+ ProtobufUtil.closeRegion(rs, hri.getRegionName(), false);
}
/**
@@ -1183,9 +1199,15 @@ public class HBaseAdmin implements Abortable, Closeable {
private void flush(final ServerName sn, final HRegionInfo hri)
throws IOException {
- HRegionInterface rs =
- this.connection.getHRegionConnection(sn.getHostname(), sn.getPort());
- rs.flushRegion(hri);
+ AdminProtocol rs =
+ this.connection.getAdmin(sn.getHostname(), sn.getPort());
+ FlushRegionRequest request =
+ RequestConverter.buildFlushRegionRequest(hri.getRegionName());
+ try {
+ rs.flushRegion(null, request);
+ } catch (ServiceException se) {
+ throw ProtobufUtil.getRemoteException(se);
+ }
}
/**
@@ -1289,9 +1311,15 @@ public class HBaseAdmin implements Abortable, Closeable {
private void compact(final ServerName sn, final HRegionInfo hri,
final boolean major)
throws IOException {
- HRegionInterface rs =
- this.connection.getHRegionConnection(sn.getHostname(), sn.getPort());
- rs.compactRegion(hri, major);
+ AdminProtocol rs =
+ this.connection.getAdmin(sn.getHostname(), sn.getPort());
+ CompactRegionRequest request =
+ RequestConverter.buildCompactRegionRequest(hri.getRegionName(), major);
+ try {
+ rs.compactRegion(null, request);
+ } catch (ServiceException se) {
+ throw ProtobufUtil.getRemoteException(se);
+ }
}
/**
@@ -1471,9 +1499,15 @@ public class HBaseAdmin implements Abortable, Closeable {
private void split(final ServerName sn, final HRegionInfo hri,
byte[] splitPoint) throws IOException {
- HRegionInterface rs =
- this.connection.getHRegionConnection(sn.getHostname(), sn.getPort());
- rs.splitRegion(hri, splitPoint);
+ AdminProtocol rs =
+ this.connection.getAdmin(sn.getHostname(), sn.getPort());
+ SplitRegionRequest request =
+ RequestConverter.buildSplitRegionRequest(hri.getRegionName(), splitPoint);
+ try {
+ rs.splitRegion(null, request);
+ } catch (ServiceException se) {
+ throw ProtobufUtil.getRemoteException(se);
+ }
}
/**
@@ -1572,9 +1606,15 @@ public class HBaseAdmin implements Abortable, Closeable {
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());
+ AdminProtocol rs =
+ this.connection.getAdmin(hostname, port);
+ StopServerRequest request = RequestConverter.buildStopServerRequest(
+ "Called by admin client " + this.connection.toString());
+ try {
+ rs.stopServer(null, request);
+ } catch (ServiceException se) {
+ throw ProtobufUtil.getRemoteException(se);
+ }
}
/**
@@ -1715,9 +1755,21 @@ public class HBaseAdmin implements Abortable, Closeable {
public synchronized byte[][] rollHLogWriter(String serverName)
throws IOException, FailedLogCloseException {
ServerName sn = new ServerName(serverName);
- HRegionInterface rs = this.connection.getHRegionConnection(
+ AdminProtocol rs = this.connection.getAdmin(
sn.getHostname(), sn.getPort());
- return rs.rollHLogWriter();
+ RollWALWriterRequest request = RequestConverter.buildRollWALWriterRequest();;
+ try {
+ RollWALWriterResponse response = rs.rollWALWriter(null, request);
+ int regionCount = response.getRegionToFlushCount();
+ byte[][] regionsToFlush = new byte[regionCount][];
+ for (int i = 0; i < regionCount; i++) {
+ ByteString region = response.getRegionToFlush(i);
+ regionsToFlush[i] = region.toByteArray();
+ }
+ return regionsToFlush;
+ } catch (ServiceException se) {
+ throw ProtobufUtil.getRemoteException(se);
+ }
}
public String[] getMasterCoprocessors() {
diff --git src/main/java/org/apache/hadoop/hbase/client/HConnection.java src/main/java/org/apache/hadoop/hbase/client/HConnection.java
index 23f8e5a..0ae82c3 100644
--- src/main/java/org/apache/hadoop/hbase/client/HConnection.java
+++ src/main/java/org/apache/hadoop/hbase/client/HConnection.java
@@ -36,11 +36,11 @@ import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.catalog.CatalogTracker;
+import org.apache.hadoop.hbase.client.AdminProtocol;
+import org.apache.hadoop.hbase.client.ClientProtocol;
import org.apache.hadoop.hbase.client.coprocessor.Batch;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
-import org.apache.hadoop.hbase.ipc.HRegionInterface;
-import org.apache.hadoop.hbase.protobuf.ClientProtocol;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
/**
@@ -201,24 +201,13 @@ public interface HConnection extends Abortable, Closeable {
/**
* Establishes a connection to the region server at the specified address.
- * @param regionServer - the server to connect to
- * @return proxy for HRegionServer
- * @throws IOException if a remote or network exception occurs
- * @deprecated Use {@link #getHRegionConnection(String, int)}
- */
- @Deprecated
- 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)
+ public AdminProtocol getAdmin(final String hostname, final int port)
throws IOException;
/**
@@ -236,26 +225,13 @@ public interface HConnection extends Abortable, Closeable {
/**
* 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(String, int)}
- */
- @Deprecated
- 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(final String hostname,
+ public AdminProtocol getAdmin(final String hostname,
final int port, boolean getMaster)
throws IOException;
diff --git src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
index 820e2a9..349698d 100644
--- src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
+++ src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
@@ -66,20 +66,16 @@ import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.Stoppable;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
+import org.apache.hadoop.hbase.client.AdminProtocol;
+import org.apache.hadoop.hbase.client.ClientProtocol;
import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
import org.apache.hadoop.hbase.client.coprocessor.Batch;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.ExecRPCInvoker;
import org.apache.hadoop.hbase.ipc.HBaseRPC;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
-import org.apache.hadoop.hbase.ipc.HRegionInterface;
import org.apache.hadoop.hbase.ipc.VersionedProtocol;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
-import org.apache.hadoop.hbase.protobuf.ClientProtocol;
-import org.apache.hadoop.hbase.protobuf.RequestConverter;
-import org.apache.hadoop.hbase.protobuf.ResponseConverter;
-import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
-import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MultiRequest;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.util.Addressing;
import org.apache.hadoop.hbase.util.Bytes;
@@ -161,6 +157,12 @@ public class HConnectionManager {
/** Default client protocol class name. */
public static final String DEFAULT_CLIENT_PROTOCOL_CLASS = ClientProtocol.class.getName();
+ /** Parameter name for what admin protocol to use. */
+ public static final String REGION_PROTOCOL_CLASS = "hbase.adminprotocol.class";
+
+ /** Default admin protocol class name. */
+ public static final String DEFAULT_ADMIN_PROTOCOL_CLASS = AdminProtocol.class.getName();
+
private static final Log LOG = LogFactory.getLog(HConnectionManager.class);
static {
@@ -507,7 +509,7 @@ public class HConnectionManager {
/* Encapsulates connection to zookeeper and regionservers.*/
static class HConnectionImplementation implements HConnection, Closeable {
static final Log LOG = LogFactory.getLog(HConnectionImplementation.class);
- private final Class extends HRegionInterface> serverInterfaceClass;
+ private final Class extends AdminProtocol> adminClass;
private final Class extends ClientProtocol> clientClass;
private final long pause;
private final int numRetries;
@@ -535,8 +537,8 @@ public class HConnectionManager {
private final Configuration conf;
- // Known region HServerAddress.toString() -> HRegionInterface
+ // Known region ServerName.toString() -> RegionClient/Admin
private final ConcurrentHashMap> servers =
new ConcurrentHashMap>();
private final ConcurrentHashMap connectionLock =
@@ -576,15 +578,15 @@ public class HConnectionManager {
throws ZooKeeperConnectionException {
this.conf = conf;
this.managed = managed;
- String serverClassName = conf.get(HConstants.REGION_SERVER_CLASS,
- HConstants.DEFAULT_REGION_SERVER_CLASS);
+ String adminClassName = conf.get(REGION_PROTOCOL_CLASS,
+ DEFAULT_ADMIN_PROTOCOL_CLASS);
this.closed = false;
try {
- this.serverInterfaceClass =
- (Class extends HRegionInterface>) Class.forName(serverClassName);
+ this.adminClass =
+ (Class extends AdminProtocol>) Class.forName(adminClassName);
} catch (ClassNotFoundException e) {
throw new UnsupportedOperationException(
- "Unable to find region server interface " + serverClassName, e);
+ "Unable to find region server interface " + adminClassName, e);
}
String clientClassName = conf.get(CLIENT_PROTOCOL_CLASS,
DEFAULT_CLIENT_PROTOCOL_CLASS);
@@ -730,9 +732,6 @@ public class HConnectionManager {
return getKeepAliveMaster();
} catch (MasterNotRunningException e) {
throw e;
- } catch (IOException e) {
- throw new ZooKeeperConnectionException(
- "Can't create a connection to master", e);
}
}
}
@@ -1057,8 +1056,8 @@ public class HConnectionManager {
metaLocation = locateRegion(parentTable, metaKey);
// If null still, go around again.
if (metaLocation == null) continue;
- HRegionInterface server =
- getHRegionConnection(metaLocation.getHostname(), metaLocation.getPort());
+ ClientProtocol server =
+ getClient(metaLocation.getHostname(), metaLocation.getPort());
Result regionInfoRow = null;
// This block guards against two threads trying to load the meta
@@ -1086,9 +1085,9 @@ public class HConnectionManager {
}
// Query the root or meta region for the location of the meta region
- regionInfoRow = server.getClosestRowBefore(
- metaLocation.getRegionInfo().getRegionName(), metaKey,
- HConstants.CATALOG_FAMILY);
+ regionInfoRow = ProtobufUtil.getRowOrBefore(server,
+ metaLocation.getRegionInfo().getRegionName(), metaKey,
+ HConstants.CATALOG_FAMILY);
}
if (regionInfoRow == null) {
throw new TableNotFoundException(Bytes.toString(tableName));
@@ -1340,17 +1339,9 @@ public class HConnectionManager {
}
@Override
- @Deprecated
- public HRegionInterface getHRegionConnection(HServerAddress hsa)
- throws IOException {
- return getHRegionConnection(hsa, false);
- }
-
- @Override
- public HRegionInterface getHRegionConnection(final String hostname,
- final int port)
- throws IOException {
- return getHRegionConnection(hostname, port, false);
+ public AdminProtocol getAdmin(final String hostname,
+ final int port) throws IOException {
+ return getAdmin(hostname, port, false);
}
@Override
@@ -1361,21 +1352,10 @@ public class HConnectionManager {
}
@Override
- @Deprecated
- public HRegionInterface getHRegionConnection(HServerAddress hsa,
- boolean master)
- throws IOException {
- String hostname = hsa.getInetSocketAddress().getHostName();
- int port = hsa.getInetSocketAddress().getPort();
- return getHRegionConnection(hostname, port, master);
- }
-
- @Override
- public HRegionInterface getHRegionConnection(final String hostname,
- final int port, final boolean master)
- throws IOException {
- return (HRegionInterface)getProtocol(hostname, port,
- serverInterfaceClass, HRegionInterface.VERSION);
+ public AdminProtocol getAdmin(final String hostname,
+ final int port, final boolean master) throws IOException {
+ return (AdminProtocol)getProtocol(hostname, port,
+ adminClass, AdminProtocol.VERSION);
}
/**
@@ -1591,11 +1571,19 @@ public class HConnectionManager {
}catch (InvocationTargetException e){
// We will have this for all the exception, checked on not, sent
// by any layer, including the functional exception
- if (e.getCause () == null){
+ Throwable cause = e.getCause();
+ if (cause == null){
throw new RuntimeException(
"Proxy invocation failed and getCause is null", e);
}
- throw e.getCause();
+ if (cause instanceof UndeclaredThrowableException) {
+ cause = cause.getCause();
+ }
+ if (cause instanceof ServiceException) {
+ ServiceException se = (ServiceException)cause;
+ cause = ProtobufUtil.getRemoteException(se);
+ }
+ throw cause;
}
}
}
@@ -1715,39 +1703,8 @@ public class HConnectionManager {
ServerCallable callable =
new ServerCallable(connection, tableName, null) {
public MultiResponse call() throws IOException {
- try {
- MultiResponse response = new MultiResponse();
- for (Map.Entry>> e: multi.actions.entrySet()) {
- byte[] regionName = e.getKey();
- int rowMutations = 0;
- List> actions = e.getValue();
- for (Action action: actions) {
- Row row = action.getAction();
- if (row instanceof RowMutations) {
- MultiRequest request =
- RequestConverter.buildMultiRequest(regionName, (RowMutations)row);
- server.multi(null, request);
- response.add(regionName, action.getOriginalIndex(), new Result());
- rowMutations++;
- }
- }
- if (actions.size() > rowMutations) {
- MultiRequest request =
- RequestConverter.buildMultiRequest(regionName, actions);
- ClientProtos.MultiResponse
- proto = server.multi(null, request);
- List