Update Hbase Java API.md

This commit is contained in:
heibaiying 2019-04-10 17:45:57 +08:00 committed by GitHub
parent 051e9991f3
commit 712aea8c00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,7 @@
## 一、简述
截至到目前2019年4月Hbase 主要有1.x 和 2.x 两个主要的版本两个版本的Java API的接口和方法都是有所不同的1.x 中某些方法在2.x中被标识为`@deprecated `过时所以下面关于API的样例我会分别给出1.x和2.x两个版本。完整的代码见本仓库
截至到目前2019年4月HBase 主要有1.x 和 2.x 两个主要的版本两个版本的Java API的接口和方法有所不同的1.x 中某些方法在2.x中被标识为`@deprecated `过时所以下面关于API的样例我会分别给出1.x和2.x两个版本。完整的代码见本仓库
>+ [Java API 1.x Examples](https://github.com/heibaiying/BigData-Notes/tree/master/code/Hbase/hbase-java-api-1.x)
>
@ -23,7 +23,7 @@
#### 2.1 新建Maven工程导入项目依赖
要使用Java API 操作HBase,仅需要引入`hbase-client`。这里我服务端的Hbase版本为`hbase-1.2.0-cdh5.15.2`,对应的`Hbase client` 选取 1.2.0 版本
要使用Java API 操作HBase,仅需要引入`hbase-client`。这里我服务端的HBase版本为`hbase-1.2.0-cdh5.15.2`,对应的`Hbase client` 选取 1.2.0 版本
```xml
<dependency>
@ -412,7 +412,7 @@ public class HBaseUtilsTest {
2.x 版本相比于1.x 废弃了一部分方法关于废弃的方法在源码中都会指明新的替代方法比如在2.x中创建表时`HTableDescriptor``HColumnDescriptor`等类都标识为废弃且会在3.0.0版本移除,取而代之的是使用`TableDescriptorBuilder``ColumnFamilyDescriptorBuilder`来定义表和列族。在升级版本时,可以用源码中指明的新的替代方法来代替过期的方法。
<div align="center"> <img src="https://github.com/heibaiying/BigData-Notes/blob/master/pictures/deprecated.png"/> </div>
<div align="center"> <img width="700px" src="https://github.com/heibaiying/BigData-Notes/blob/master/pictures/deprecated.png"/> </div>
@ -683,10 +683,13 @@ public class HBaseUtils {
首先官方对于`Connection Pooling`做了如下表述:
```properties
Connection Pooling
For applications which require high-end multithreaded access (e.g., web-servers or application servers that may serve many application threads in a single JVM), you can pre-create a Connection, as shown in the following example:
Connection Pooling For applications which require high-end multithreaded
access (e.g., web-servers or application servers that may serve many
application threads in a single JVM), you can pre-create a Connection,
as shown in the following example:
#对于高并发多线程访问的应用程序例如在单个JVM中存在的为多个线程服务的Web服务器或应用程序服务器您只需要预先创建一个Connection。例子如下
#对于高并发多线程访问的应用程序例如在单个JVM中存在的为多个线程服务的Web服务器或应用程序服务器
您只需要预先创建一个Connection。例子如下
```
```java
@ -701,9 +704,13 @@ try (Connection connection = ConnectionFactory.createConnection(conf);
之所以能这样使用这是因为Connection并不是一个简单的socket连接[接口文档](https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Connection.html)中对Connection的表述是
```properties
A cluster connection encapsulating lower level individual connections to actual servers and a connection to zookeeper. Connections are instantiated through the ConnectionFactory class. The lifecycle of the connection is managed by the caller, who has to close() the connection to release the resources.
A cluster connection encapsulating lower level individual connections to actual servers and a
connection to zookeeper. Connections are instantiated through the ConnectionFactory class.
The lifecycle of the connection is managed by the caller, who has to close() the connection
to release the resources.
# Connection是一个集群连接封装了与多台服务器Matser/Region Server的底层连接以及与zookeeper的连接。连接通过ConnectionFactory类实例化。连接的生命周期由调用者管理调用者必须使用close()关闭连接以释放资源。
# Connection是一个集群连接封装了与多台服务器Matser/Region Server的底层连接以及与zookeeper的连接。
连接通过ConnectionFactory 类实例化。连接的生命周期由调用者管理调用者必须使用close()关闭连接以释放资源。
```
之所以封装这些连接是因为HBase客户端需要连接三个不同的服务角色
@ -712,11 +719,11 @@ A cluster connection encapsulating lower level individual connections to actual
+ HBase Master主要用于执行HBaseAdmin接口的一些操作例如建表等。
+ HBase RegionServer用于读、写数据。
<div align="center"> <img src="https://github.com/heibaiying/BigData-Notes/blob/master/pictures/hbase-arc.png"/> </div>
<div align="center"> <img width="700px" src="https://github.com/heibaiying/BigData-Notes/blob/master/pictures/hbase-arc.png"/> </div>
Connection对象和实际的socket连接之间的对应关系如下图
<div align="center"> <img src="https://github.com/heibaiying/BigData-Notes/blob/master/pictures/hbase-connection.png"/> </div>
<div align="center"> <img width="700px" src="https://github.com/heibaiying/BigData-Notes/blob/master/pictures/hbase-connection.png"/> </div>
> 上面两张图片引用自博客:[连接HBase的正确姿势](https://yq.aliyun.com/articles/581702?spm=a2c4e.11157919.spm-cont-list.1.146c27aeFxoMsN%20%E8%BF%9E%E6%8E%A5HBase%E7%9A%84%E6%AD%A3%E7%A1%AE%E5%A7%BF%E5%8A%BF)