Home php教程 php手册 基于HBase Thrift接口的一些使用问题及相关注意事项的详解

基于HBase Thrift接口的一些使用问题及相关注意事项的详解

Jun 13, 2016 am 11:51 AM
hbase java thrift use based on interface Precautions of Related Detailed explanation question No

HBase对于非Java语言提供了Thrift接口支持,这里结合对HBase Thrift接口(HBase版本为0.92.1)的使用经验,总结其中遇到的一些问题及其相关注意事项。
1. 字节的存放顺序
HBase中,由于row(row key和column family、column qualifier、time stamp)是按照字典序进行排序的,因此,对于short、int、long等类型的数据,通过Bytes.toBytes(…)转换成byte数组后,必须按照大端模式(高字节在低地址,低字节在高地址)存放。对于value,也是同样的道理。因此,在使用Thrift API(C++、Php、Python等)方式时,最好对于row和value都统一按照大端进行pack和unpack处理。
举个例子,C++中,对于int型变量,经过以下方式转换为字典序:

复制代码 代码如下:


string key;
  int32_t timestamp = 1352563200;
  const char* pTs =(const char*) ×tamp;
  size_t n = sizeof(int32_t);
  key.append(pTs, n);


通过以下方式将字典序转换为int:

复制代码 代码如下:


const char * ts = key.c_str();
int32_t timestamp = *((int32_t*)(ts));


Php中则提供了pack和unpack方法进行转换:

复制代码 代码如下:


  $key = pack("N", $num);
  $num = unpack("N", $key);


2. TScan的使用陷阱
HBase的PHP Thrift接口中,TScan可以直接通过设置startRow、stopRow、columns、filter等属性,默认这些属性均为null,设置后变为非null(通过TScan的构造函数或直接对TScan的成员变量进行赋值)。通过write()方法和Thrift Server进行RPC操作时,直接判断的依据是这些属性不为null,则通过Thrift协议传输到Thrift Server端。
但是在C++的Thrift接口中,TScan中有一个_TScan__isset __isset类型的变量,其内部结构如下:

复制代码 代码如下:


typedef struct _TScan__isset {
  _TScan__isset() : startRow(false), stopRow(false), timestamp(false), columns(false), caching(false), filterString(false) {}
  bool startRow;
  bool stopRow;
  bool timestamp;
  bool columns;
  bool caching;
  bool filterString;
} _TScan__isset;


TScan的write()方法则是通过判断_TScan__isset下的各个bool变量标记是否设置了startRow、stopRow、columns、filter等属性,决定是否将这些属性通过Thrift协议传输到Thrift Server端,而这些属性必须通过__set_xxx()方法进行设置才能生效!在TScan的默认构造函数中,并不会对这些属性对应的__isset标记设置为true!
因此,如果直接通过TScan的构造函数初始化startRow、stopRow、columns、filter等属性会导致从头遍历该表,只有调用了__set_xxx()方法才会将对应的bool标识设置为true,这样服务端才会从Thrift Server获取startRow、stopRow、columns、filter等属性进行扫描。
3. 并发访问线程数
首先,为了尽可能减少由于网络传输带来的时间开销,HBase的Thrift Server最好和应用客户端部署在同一台机器上。Thrift Server启动时可以通过参数配置并发线程数,否则很容易导致Thrift Server线程满了不响应客户端的读写请求,具体命令:bin/hbase-daemon.sh start thrift --threadpool -m 200 -w 500(更多参数参考这里:bin/hbase-daemon.sh start thrift -h)。
4. 最大堆内存配置
如果客户端与Thrift Server进行scan操作顺序读取数据,而且设置了一定的cache记录条数(通过TScan的int32_t caching变量设置),那么这些被caching的记录数可能会占用Thrift Server相当部分的堆内存,尤其在多客户端并发访问时更明显。
因此,在Thrift Server启动前,可以调大最大堆内存,否则可能由于java.lang.OutOfMemoryError异常而导致进程被杀掉,尤其是当Scan时设置了较大的caching记录条数的情况(默认为export HBASE_HEAPSIZE=1000MB,可以在conf/hbase-env.sh中设置)。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

TimeStamp to Date in Java TimeStamp to Date in Java Aug 30, 2024 pm 04:28 PM

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Java Program to Find the Volume of Capsule Java Program to Find the Volume of Capsule Feb 07, 2025 am 11:37 AM

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

Create the Future: Java Programming for Absolute Beginners Create the Future: Java Programming for Absolute Beginners Oct 13, 2024 pm 01:32 PM

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

See all articles