一:读写思想

1.系统表

  hbase:namespace

    存储hbase中所有的namespace的信息

  hbase:meta   

    rowkey:hbase中所有表的region的名称
    column:regioninfo:region的名称,region的范围
    server:该region在哪台regionserver上

2.读写流程

  tbname,rowkey  ->   region  ->  regionserver  ->  store ->  storefile

  但是这些都是加载过meta表之后,然后meta表如何寻找?

3.读的流程  

  -》根据表名和rowkey找到对应的region
  -》zookeeper中存储了meta表的region信息
  -》从meta表中获取相应的region的信息
  -》找到对应的regionserver
  -》查找对应的region
  -》读memstore
  -》storefile

4.写的流程  

  -》根据表名和rowkey找到对应的region
  -》zookeeper中存储了meta表的region信息
  -》从meta表中获取相应的region的信息
  -》找到对应的regionserver
  -》正常情况
  -》WAL(write ahead log预写日志),一个regionserver维护一个hlog
  -》memstore (达到一定大小,flush到磁盘)
  -》当多个storefile达到一定大小以后,会进行compact,合并成一个storefile
  -》当单个storefile达到一定大小以后,会进行split操作,等分割region

5.注意点

  关于版本的合并和删除是在compact阶段完成的。hbase只负责数据的增加存储
  hmaster短暂的不参与实际的读写

二:HBase Client API 的书写

1.添加依赖

  

2.添加配置文件

  core-site.xml

  hdfs-site.xml

  hbase-site.xml

  log4j.properties

  regionservers

3.get的书写

  

4.put的书写

  

5.delete的书写

  

  注意全部删除:

  

6.scan的书写

  

7.过滤条件的scan的书写

  

三:复制源代码

  

 package com.beifeng.bigdat;

 import java.io.IOException;

 import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.PrefixFilter;
import org.apache.hadoop.hbase.util.Bytes; public class HbaseClientTest {
public static HTable getTable(String name) throws Exception{
Configuration conf=HBaseConfiguration.create();
HTable table=new HTable(conf,name);
return table; }
public static void getData(HTable table) throws Exception{
Get get=new Get(Bytes.toBytes("103"));
get.addFamily(Bytes.toBytes("info"));
Result rs=table.get(get);
for(Cell cell:rs.rawCells()){
System.out.println(
Bytes.toString(CellUtil.cloneFamily(cell))+"--"+
Bytes.toString(CellUtil.cloneQualifier(cell))+"---"+
Bytes.toString(CellUtil.cloneValue(cell))+"----"+
cell.getTimestamp()
);
System.out.println("----------------------------------------------");
}
} public static void putData(HTable table) throws Exception{
Put put=new Put(Bytes.toBytes("103"));
put.add(Bytes.toBytes("info"),
Bytes.toBytes("name"),
Bytes.toBytes("zhaoliu"));
table.put(put);
getData(table);
} public static void deleteData(HTable table) throws Exception{
Delete delete =new Delete(Bytes.toBytes("103"));
delete.deleteColumns(Bytes.toBytes("info"), Bytes.toBytes("name"));
table.delete(delete);
getData(table);
} public static void scanData(HTable table) throws Exception{
Scan scan =new Scan();
ResultScanner rs=table.getScanner(scan);
for(Result r:rs){
System.out.println(Bytes.toString(r.getRow()));
for(Cell cell:r.rawCells()){
System.out.println(
Bytes.toString(CellUtil.cloneFamily(cell))+"---"+
Bytes.toString(CellUtil.cloneQualifier(cell))+"---"+
Bytes.toString(CellUtil.cloneValue(cell))+"--"+
cell.getTimestamp()
);
System.out.println();
}
}
} public static void filterScan(HTable table) throws Exception{
Scan scan =new Scan();
Filter filter=new PrefixFilter(Bytes.toBytes("10"));
scan.setFilter(filter);
scan.setCacheBlocks(true);
scan.setCaching(1000);
scan.setBatch(100);
ResultScanner rs=table.getScanner(scan);
for(Result r:rs){
System.out.println(Bytes.toString(r.getRow()));
for(Cell cell:r.rawCells()){
System.out.println(
Bytes.toString(CellUtil.cloneFamily(cell))+"---"+
Bytes.toString(CellUtil.cloneQualifier(cell))+"---"+
Bytes.toString(CellUtil.cloneValue(cell))+"--"+
cell.getTimestamp()
);
System.out.println();
}
} } public static void main(String[] args) throws Exception {
HTable table=getTable("nstest1:tb1");
//getData(table);
//putData(table);
//deleteData(table);
//scanData(table);
filterScan(table);
} }

HBASE的读写以及client API的更多相关文章

  1. 073 HBASE的读写以及client API

    一:读写思想 1.系统表 hbase:namespace 存储hbase中所有的namespace的信息 hbase:meta rowkey:hbase中所有表的region的名称 column:re ...

  2. HBase 二次开发 java api和demo

    1. 试用thrift python/java以及hbase client api.结论例如以下:     1.1 thrift的安装和公布繁琐.可能会遇到未知的错误,且hbase.thrift的版本 ...

  3. hbase的读写过程

    hbase的读写过程: hbase的架构: Hbase真实数据hbase真实数据存储在hdfs上,通过配置文件的hbase.rootdir属性可知,文件在/user/hbase/下hdfs dfs - ...

  4. Hbase的读写流程

    HBase读写流程 1.HBase读数据流程 HRegionServer保存着meta表以及表数据,要访问表数据,首先Client先去访问zookeeper,从zookeeper里面获取meta表所在 ...

  5. HBase 数据读写流程

    HBase 数据读写流程 2016-10-18 杜亦舒 读数据 HBase的表是按行拆分为一个个 region 块儿,这些块儿被放置在各个 regionserver 中 假设现在想在用户表中获取 ro ...

  6. ecshop /api/client/api.php、/api/client/includes/lib_api.php SQL Injection Vul

    catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 ECShop存在一个盲注漏洞,问题存在于/api/client/api. ...

  7. Memcached Java Client API详解

    针对Memcached官方网站提供的java_memcached-release_2.0.1版本进行阅读分析,Memcached Java客户端lib库主要提供的调用类是SockIOPool和MemC ...

  8. Jersey(1.19.1) - Client API, Uniform Interface Constraint

    The Jersey client API is a high-level Java based API for interoperating with RESTful Web services. I ...

  9. Jersey(1.19.1) - Client API, Ease of use and reusing JAX-RS artifacts

    Since a resource is represented as a Java type it makes it easy to configure, pass around and inject ...

随机推荐

  1. javascript优化--13模式1(DOM和浏览器模式)

    注意分离: 通过将CSS关闭来测试页面是否仍然可用,内容是否依然可读: 将JavaScript关闭来测试页面仍然可以执行正常功能:所有连接是否正常工作:所有的表单是否可以正常工作: 不使用内联处理器( ...

  2. js:语言精髓笔记1--标识符与基本类型

    标识符: 命名: 语法以及类型----语法关键字                                           //逻辑 值(的存储位置)----变量和常量           ...

  3. HDU3657 Game(最小割)

    题目大概说,给一个n×m的格子,每个格子都有数字,选择一个格子就能加上格子数字的分数,有k个格子必须选择,如果两个相邻的格子都被选择了那分数要减去两个格子数字的与再乘2.问能取得的最大分数. 已经知道 ...

  4. 【python游戏编程之旅】第三篇---pygame事件与设备轮询

    本系列博客介绍以python+pygame库进行小游戏的开发.有写的不对之处还望各位海涵. 在上一篇博客中,我们学习了pygame中的IO.数据http://www.cnblogs.com/msxh/ ...

  5. c# windows service

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. [Unity2D]精灵

    精灵是Unity2D里面对通过图片纹理实现的游戏对象,通常会是游戏里面的玩家,敌人之类的,在Unity里面创建一个精灵的操作非常简单,直接把图片资源拖放到Hierarachy视图就可以完成了精灵的创建 ...

  7. Java中替换HTML标签的方法代码

    这篇文章主要介绍了Java中替换HTML标签的方法代码,需要的朋友可以参考下 replaceAll("\\&[a-zA-Z]{0,9};", "").r ...

  8. div居中(内容+元素:水平+垂直)

    内容水平居中 text-align: center; 内容垂直居中 /*第一种 行内垂直居中*/ height: 43px; line-height:43px; /*我们将行距增加到和整个div一样高 ...

  9. 【原】Windows下Nexus搭建Maven私服

    一.Maven安装 详见Java开发环境搭建 二.Nexus安装 2.1.下载 地址:http://www.sonatype.org/nexus/go/ 选择OSS(ZIP)版本 2.2.安装 将安装 ...

  10. 小红伞和virtualbox5.0.10冲突

    win7 sp1 64bit 旗舰版:virtual box 5.0.10 提示 error in supr3hardNtChildWaitFor……Timed out after 60001 ms ...