HBase

HBase

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Region类似于表,当表的数据达到阈值时会分表(裂变,可能会裂变到其他的RegionServer中去)

在这里插入图片描述

Memstore与storefile

一个region由多个store组成,一个store对应一个CF(列族,多个列)

store包括位于内存中的memstore和位于磁盘的storefile写操作先写入memstore,当memstore中的数据达到某个阈值,hregionserver会启动flashcache进程写入storefile,每次写入形成单独的一个storefile。

当storefile文件的数量增长到一定阈值后,系统会进行合并(minor、major compaction),在合并过程中会进行版本合并和删除工作(majar),形成更大的storefile

当一个region所有storefile的大小和数量超过一定阈值后,会把当前的region分割为两个,并由hmaster分配到相应的regionserver服务器,实现负载均衡客户端检索数据,先在memstore找,找不到再找storefile

Region存储的是我们的表,Store是列族,最后落地到menStor,StoreFile

在这里插入图片描述
在这里插入图片描述

JAVA API操作HBase

创建表

public class Hbase {
    HBaseAdmin admin;
    String TN = "phone";
    @Before
    public void init() throws  Exception{
        Configuration  conf = new Configuration();
        conf.set("hbase.zookeeper.quorum","hadoop101,hadoop102,hadoop103");
        admin = new HBaseAdmin(conf);
    }
    @Test
    public  void  creatTable()throws  Exception{
        if(admin.tableExists(TN)){
            admin.disableTable(TN);
            admin.deleteTable(TN);
        }
        HTableDescriptor desc  = new HTableDescriptor(TableName.valueOf(TN));
        HColumnDescriptor cf = new HColumnDescriptor("cf".getBytes());
        desc.addFamily(cf);
        admin.createTable(desc);
    }
    @After
    public void  destory()throws  Exception{
        if (admin!=null){
            admin.close();
        }
    }
}

在这里插入图片描述

增加数据

public class Hbase {
    HBaseAdmin admin;
    HTable hTable;
    String TN = "phone";
    @Before
    public void init() throws  Exception{
        Configuration  conf = new Configuration();
        conf.set("hbase.zookeeper.quorum","hadoop101,hadoop102,hadoop103");
        admin = new HBaseAdmin(conf);
        hTable = new HTable(conf,TN.getBytes());
    }
    @Test
    public  void  creatTable()throws  Exception{
        if(admin.tableExists(TN)){
            admin.disableTable(TN);
            admin.deleteTable(TN);
        }
        HTableDescriptor desc  = new HTableDescriptor(TableName.valueOf(TN));
        HColumnDescriptor cf = new HColumnDescriptor("cf".getBytes());
        desc.addFamily(cf);
        admin.createTable(desc);
    }
    @Test
    public void insertDB()throws  Exception{
        String rowKey = "1";
        Put put = new Put(rowKey.getBytes());
        put.add("cf".getBytes(),"name".getBytes(),"xiaoming".getBytes());
        put.add("cf".getBytes(),"age".getBytes(),"12".getBytes());
        put.add("cf".getBytes(),"sex".getBytes(),"man".getBytes());
        hTable.put(put);
    }
    @After
    public void  destory()throws  Exception{
        if (admin!=null){
            admin.close();
        }
    }
}

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值