You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by mb...@apache.org on 2015/05/21 18:43:28 UTC
[45/50] [abbrv] hbase git commit: HBASE-13698 Add RegionLocator
methods to Thrift2
HBASE-13698 Add RegionLocator methods to Thrift2
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1bfe3879
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1bfe3879
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1bfe3879
Branch: refs/heads/hbase-12439
Commit: 1bfe3879566266a4e2fcd708934c94607163d295
Parents: 315f596
Author: Elliott Clark <ec...@apache.org>
Authored: Mon May 18 15:57:28 2015 -0700
Committer: Elliott Clark <ec...@apache.org>
Committed: Wed May 20 13:33:59 2015 -0700
----------------------------------------------------------------------
hbase-thrift/pom.xml | 2 +-
.../thrift2/ThriftHBaseServiceHandler.java | 57 +
.../hadoop/hbase/thrift2/ThriftUtilities.java | 40 +
.../hbase/thrift2/generated/THBaseService.java | 4248 +++++++++++++-----
.../hbase/thrift2/generated/THRegionInfo.java | 1038 +++++
.../thrift2/generated/THRegionLocation.java | 498 ++
.../hbase/thrift2/generated/TMutation.java | 4 +-
.../hbase/thrift2/generated/TServerName.java | 595 +++
.../apache/hadoop/hbase/thrift2/hbase.thrift | 44 +
9 files changed, 5470 insertions(+), 1056 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/1bfe3879/hbase-thrift/pom.xml
----------------------------------------------------------------------
diff --git a/hbase-thrift/pom.xml b/hbase-thrift/pom.xml
index e845482..43c93d1 100644
--- a/hbase-thrift/pom.xml
+++ b/hbase-thrift/pom.xml
@@ -342,7 +342,7 @@
Profile for regenerating the thrift java classes.
The generated files are to be committed to version control.
Activate using:
- mvn compile -Dcompile-thrift
+ mvn compile -Pcompile-thrift
-->
<profile>
<id>compile-thrift</id>
http://git-wip-us.apache.org/repos/asf/hbase/blob/1bfe3879/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java
----------------------------------------------------------------------
diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java
index 5031fb1..1343149 100644
--- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java
+++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java
@@ -47,7 +47,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.client.RegionLocator;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.security.UserProvider;
@@ -56,6 +58,7 @@ import org.apache.hadoop.hbase.thrift2.generated.TAppend;
import org.apache.hadoop.hbase.thrift2.generated.TDelete;
import org.apache.hadoop.hbase.thrift2.generated.TGet;
import org.apache.hadoop.hbase.thrift2.generated.THBaseService;
+import org.apache.hadoop.hbase.thrift2.generated.THRegionLocation;
import org.apache.hadoop.hbase.thrift2.generated.TIOError;
import org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument;
import org.apache.hadoop.hbase.thrift2.generated.TIncrement;
@@ -141,6 +144,14 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
}
}
+ private RegionLocator getLocator(ByteBuffer tableName) {
+ try {
+ return connectionCache.getRegionLocator(byteBufferToByteArray(tableName));
+ } catch (IOException ie) {
+ throw new RuntimeException(ie);
+ }
+ }
+
private void closeTable(Table table) throws TIOError {
try {
table.close();
@@ -385,6 +396,8 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
return results;
}
+
+
@Override
public void closeScanner(int scannerId) throws TIOError, TIllegalArgument, TException {
LOG.debug("scannerClose: id=" + scannerId);
@@ -412,4 +425,48 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
}
}
+ @Override
+ public List<THRegionLocation> getAllRegionLocations(ByteBuffer table)
+ throws TIOError, TException {
+ RegionLocator locator = null;
+ try {
+ locator = getLocator(table);
+ return ThriftUtilities.regionLocationsFromHBase(locator.getAllRegionLocations());
+
+ } catch (IOException e) {
+ throw getTIOError(e);
+ } finally {
+ if (locator != null) {
+ try {
+ locator.close();
+ } catch (IOException e) {
+ LOG.warn("Couldn't close the locator.", e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public THRegionLocation getRegionLocation(ByteBuffer table, ByteBuffer row, boolean reload)
+ throws TIOError, TException {
+
+ RegionLocator locator = null;
+ try {
+ locator = getLocator(table);
+ byte[] rowBytes = byteBufferToByteArray(row);
+ HRegionLocation hrl = locator.getRegionLocation(rowBytes, reload);
+ return ThriftUtilities.regionLocationFromHBase(hrl);
+
+ } catch (IOException e) {
+ throw getTIOError(e);
+ } finally {
+ if (locator != null) {
+ try {
+ locator.close();
+ } catch (IOException e) {
+ LOG.warn("Couldn't close the locator.", e);
+ }
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/1bfe3879/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java
----------------------------------------------------------------------
diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java
index d2da993..3251d13 100644
--- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java
+++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java
@@ -26,6 +26,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
@@ -34,6 +37,7 @@ import org.apache.hadoop.hbase.client.Append;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.HRegionLocator;
import org.apache.hadoop.hbase.client.Increment;
import org.apache.hadoop.hbase.client.OperationWithAttributes;
import org.apache.hadoop.hbase.client.Put;
@@ -51,12 +55,15 @@ import org.apache.hadoop.hbase.thrift2.generated.TDelete;
import org.apache.hadoop.hbase.thrift2.generated.TDeleteType;
import org.apache.hadoop.hbase.thrift2.generated.TDurability;
import org.apache.hadoop.hbase.thrift2.generated.TGet;
+import org.apache.hadoop.hbase.thrift2.generated.THRegionInfo;
+import org.apache.hadoop.hbase.thrift2.generated.THRegionLocation;
import org.apache.hadoop.hbase.thrift2.generated.TIncrement;
import org.apache.hadoop.hbase.thrift2.generated.TMutation;
import org.apache.hadoop.hbase.thrift2.generated.TPut;
import org.apache.hadoop.hbase.thrift2.generated.TResult;
import org.apache.hadoop.hbase.thrift2.generated.TRowMutations;
import org.apache.hadoop.hbase.thrift2.generated.TScan;
+import org.apache.hadoop.hbase.thrift2.generated.TServerName;
import org.apache.hadoop.hbase.thrift2.generated.TTimeRange;
import org.apache.hadoop.hbase.util.Bytes;
@@ -467,6 +474,39 @@ public class ThriftUtilities {
return out;
}
+ public static THRegionLocation regionLocationFromHBase(HRegionLocation hrl) {
+ HRegionInfo hri = hrl.getRegionInfo();
+ ServerName serverName = hrl.getServerName();
+
+ THRegionInfo thRegionInfo = new THRegionInfo();
+ THRegionLocation thRegionLocation = new THRegionLocation();
+ TServerName tServerName = new TServerName();
+
+ tServerName.setHostName(serverName.getHostname());
+ tServerName.setPort(serverName.getPort());
+ tServerName.setStartCode(serverName.getStartcode());
+
+ thRegionInfo.setTableName(hri.getTable().getName());
+ thRegionInfo.setEndKey(hri.getEndKey());
+ thRegionInfo.setStartKey(hri.getStartKey());
+ thRegionInfo.setOffline(hri.isOffline());
+ thRegionInfo.setSplit(hri.isSplit());
+ thRegionInfo.setReplicaId(hri.getReplicaId());
+
+ thRegionLocation.setRegionInfo(thRegionInfo);
+ thRegionLocation.setServerName(tServerName);
+
+ return thRegionLocation;
+ }
+
+ public static List<THRegionLocation> regionLocationsFromHBase(List<HRegionLocation> locations) {
+ List<THRegionLocation> tlocations = new ArrayList<THRegionLocation>(locations.size());
+ for (HRegionLocation hrl:locations) {
+ tlocations.add(regionLocationFromHBase(hrl));
+ }
+ return tlocations;
+ }
+
/**
* Adds all the attributes into the Operation object
*/