SlideShare a Scribd company logo
HBase– Yet Another NoSQL bluedavy http://blog.bluedavy.com
Basic Concept Example 表 表名 + Column Family + Column Qualifier users ( infos(name,email,age) auths(password,security) ) 表名+Column Family相当于Schema Column Qualifier可动态增加 读 table.get(rowKey,Column Family)  table.get(rowKey,ColumnFamily,Column Qualifier) table.get(rowKey,ColumnFamily,ColumnQualifier,maxVersions)  写 table.put(rowKey,ColumnFamily,ColumnQualifier,value)
Overview Client Zookeeper Region Server Master HDFS
Overview Client 读写数据的客户端 Zookeeper 保存rootregion的位置 Master选举 Region Server以及Region上下线的感应 Region Server 表的具体操作的场所 Master Region的分配以及balance HDFS 存放数据的地方
from Facebook
Features 水平扩展 可 靠 性 面向列 高性能随机读/写 范围查询 和Hadoop无缝集成
水平扩展 数据量太大了,读写性能下降? 传统方案:分库分表(迁移数据,中间层) HBase:啥都不用做,加机器即可。 且性能平稳。
水平扩展 HBase存储结构 HDFS
水平扩展 如何做到的? 当storeFile多了后,HBase会自动compact; 当rows多了后,HBase会自动将region split; HBase会定时对Region Server的Region数进行balance; Region Server下线,Master会重新分配其负责的Region到其他的Region Server; Region Server上线后,当Master进行balance时会迁移一些Region到新的Region Server。
面向列 动态增删schema? 传统方案:停机维护; HBase: No,Column Qualifier可动态增删。
面向列 如何做到的? 以Column Family为存储单元; K/V方式存储。
高性能随机读/写 如何做到的? 随机读 K/V存储; Cache; Split; Balance。 随机写(相对而言) Cache+WAL; Compact; Split; Balance;
范围查询 如何做到的? 存储时按字典序对key做排序; 1,10,11,15,19,2,24,3
可靠性 借助HDFS保证数据的可靠; WAL; 恢复机制。
不足 目前版本不支持二级索引; 易用性不够; 系统结构复杂,运维上有挑战; rowKey的设计对运行状况有很大影响; 对Online业务还是有很大挑战,主要是延时以及失败率。
HBase关键操作 读 写 Cache刷磁盘 Compact Split Balance 数据恢复
读 Example 代码 Configuration config=HBaseConfiguration.create(); HTable table=new HTable(config,"users"); Get queryRow=new Get(Bytes.toBytes("0")); queryRow.addColumn(Bytes.toBytes("infos"), Bytes.toBytes("nick")); Result rowResult=table.get(queryRow); System.out.println("nick is :"+Bytes.toString(rowResult.raw()[0].getValue()));
读 Client 本地cache Region Server 1、找rowKey对应的region 或接近rowKey的region 2、未找到则从缓存的.meta信息中获取meta的region server 2.1、从meta所在的Region Server获取rowKey对应的Region 3、RPC发送请求,从Region Server读数据,超时默认为60s 4、reader线程接到RPC请求后,丢到Queue里; 5、10个handler线程处理Queue,默认Queue最大为1000; 6、检查Region Server是否为运行状态; 7、检查Region是否为Online,如不Online则抛出异常; 8、再次检查Region是否正在关闭或已关闭; 9、创建Scanner(Region—Store—Memstore--StoreFile),在读取StoreFile时会先读取LruBlockCache(全局一个,默认20%的xmx空间); 10、扫描找到相应的数据,算法较复杂,不在此描述。 抛出异常或返回结果数据 如抛出异常,则检查重试次数是否超过10次(默认值),未超过则按照指数退避的方法sleep后再继续重试,重试时重新获取meta信息。
影响读的关键因素 速度 是否能从cache中获取到region server的地址; RPC发送请求的速度; RPC超时时间; Reader线程的活跃数; Handler Queue的Size; Handler线程的活跃数; Memstore的命中率; LruCache的命中率; HDFS读取速度; 读重试的次数以及重试的间隔时间。 失败率 Region Server以及Region的状态; HDFS能否读取。
写 Example 代码 Configuration config=HBaseConfiguration.create(); HTable table=new HTable(config,"users"); Put row=new Put(Bytes.toBytes(String.valueOf(“0”))); row.add(Bytes.toBytes("infos"), Bytes.toBytes("nick"), Bytes.toBytes("bixuan")); row.add(Bytes.toBytes("infos"), Bytes.toBytes("age"), Bytes.toBytes(“30”)); row.add(Bytes.toBytes("infos"), Bytes.toBytes("sex"), Bytes.toBytes("male")); table.put(row);
写 Client 本地cache Region Server 1、检验put的key/value size是否超过了最大值,默认无限制; 2、往writeBuffer中放入put,计算currentWriteBufferSize; 3、如为autoFlush或currentWriteBufferSize大于了2M,则提交; 4、从cache中获取需要操作的        Region Server地址; reader线程接到RPC请求后,丢到Queue里; 10个handler线程处理Queue,默认Queue最大为1000; 检查Region Server是否在运行状态,不运行则抛出异常; 检查Region是否online,不online则抛出异常; 检查RS的memstore的总值是否已超过最大限制,超过则唤醒flush线程,并等待5s或唤醒后再次检查,如还是超过,则继续; 如memstore的总值只是超过了最低限制,则只是唤醒flush线程; 从put中获取是否要写WAL; 如region为只读,则抛出异常; 如region的memstore大小超过128M,则通知进行flush,等待10s 后重新尝试; 再次检查region的状态; 行上加锁; 检查families,更新KV的timestamp; 如要写WAL,则写Hlog; 往memstore里写相应的信息; 检查memstore的size是否要flush,如要flush,则通知flusher flush。 5、未找到则从.meta.的region中获取需要操作的region server; 6、丢入htable instance创建的线程池提交put请求,Future方式等待结果; 7、线程池中RPC发送put请求到对应的region server; 抛出异常或返回结果数据 按提交put请求的server遍历返回的结果; 如返回的结果为null或不为DoNotRetryIOException的异常,则放入重试的list中; 进行重试,最大次数10次,每次做指数避让的sleep; 遍历返回的所有result,如其中有null或异常,则抛出RetriesExhaustedWithDetailsException; 从writeBuffer中删除已成功的put请求。
影响写的关键因素 速度 是否autoflush; 不为autoflush时的flushWriteBufferSize; 是否能从cache中获取需要操作的region server地址; Htable instance线程池的队列的size; RPC发送请求的速度以及超时时间; Reader线程的活跃数; Handler Queue的Size; Handler线程的活跃数; RS全局的memstore Size以及Region的memstore  size; Memstore刷磁盘的执行频率和时间; 是否WAL; 写Hlog的速度; 写重试的次数。 失败率 Region Server以及Region的状态; HDFS能否写成功。 可靠性 不为autoflush时不可靠; 目前的代码一直要到put成功为止。
Cache刷磁盘 MemstoreFlusher HRegion 1、从flush队列中获取刷磁盘的请求,超时时间为10s; 2、如队列中没有请求,或请求的类型为WakeFlushThread,则进入下面的流程;  2.1  判断当前所有的memstore size总和是否超过了最低的阈值(默认为0.35 * -Xmx),如超过则选择一个合适的Region,将其memstore刷入到磁盘; 3、如队列中的请求类型为FlushRegionEntry,则进入下面的流程;  3.1 将该region的memstore刷入到磁盘; 4、将Region的memstore刷入到磁盘。 5、检查Region的状态; 6、锁住对memstore以及storeFile的更新操作; 7、锁住hlog的cacheFlush,避免roll; 8、创建memstore的snapshot;        8.1  清空之前的memstore的内容; 9、释放memstore以及storeFile的更新锁; 10、刷memstore到磁盘并将新文件加入到store list中; 11、如store中的store files已>=3个,则表示需要进行compact; 12、hlog中记录下flush已完成。 13、返回是否需要compact; 14、如需要compact,则放一个请求到CompactSplitThread的队列中。
影响Cache刷磁盘的关键因素 Memstore中数据的大小; 写HDFS的速度。
Cache刷磁盘对读写造成的影响 对读的影响 memstore被清空,命中率会有些许下降; 对写的影响 有一小段锁住memstore及storeFile更新操作的时间,基本可忽略,因为只是创建snapshot;
Compact CompactSplitThread HRegion 1、根据队列中的请求获取需要Compact的Region,单线程工作; 2、检查Region Server的状态; 3、压缩region; 4、检查region的状态; 5、交给region中的store来完成compact,store会根据一定的算法选择需要compact的storeFiles(如store中有reference,则全部compact),最少要有3个,并根据需要保存的max version生成新的store file; 6、给store加锁,将没有compact的storeFile以及生成的新的store File合并为新的store list,排序并赋值给store files,删除旧的store files,释放锁; 7、如compact后的storeFile文件大于了256m,则获取其中间key,并返回,如小于则返回null; 8、返回中间key或null; 9、如hbase.regionserver.regionSplitLimit>当前server中online的region数,且中间key不为null,则进入split过程。
影响Compact的关键因素 需要compact的文件个数; 写HDFS的速度。
Compact对读写造成的影响 对读的影响; 有一小段锁store的时间,读需要等; 对写的影响; 有一小段锁store的时间,写需要等; Compact文件如果大的话,对写也会产生影响,抢IO资源;
Split CompactSplitThread HRegion 1、检查server的状态; 2、创建split文件夹; 3、close region; 4、设置状态为closing; 5、对region加写锁; 6、刷memstore; 7、关闭所有的store file reader; 8、设置状态为closed; 9、释放锁。 10、从online region中拿掉此region; 11、每个store file一个线程进行split,生成的为两个reference的文件; 12、创建两个daughter region,并将parent region从meta表中下线; 12、如split失败,则按状态进行回滚; 13、如split成功,则打开新创建的两个region,更新meta表信息,通知master发生了split事件。
影响Split的关键因素 写HDFS的速度;
Split对读写造成的影响 split时读写均无法操作,会直接抛错,要直到meta表信息更新完毕才能恢复。
Balance对读写造成的影响 部分读写操作可能会出现短暂的失败 原因在于balance需要关闭一些region。 部分读会出现慢的现象 原因在于balance后的region没cache。
数据恢复 store file中的元信息存储了seqid; region在open时会根据seqid以及hlog来进行恢复; master在重新分配region的时候会将hlog分好类,以便进行恢复; rs在做split动作时会先创建一个splits目录,以便恢复。

More Related Content

What's hot

HBaseCon 2015: Just the Basics
HBaseCon 2015: Just the BasicsHBaseCon 2015: Just the Basics
HBaseCon 2015: Just the Basics
HBaseCon
 
Intro to HBase Internals & Schema Design (for HBase users)
Intro to HBase Internals & Schema Design (for HBase users)Intro to HBase Internals & Schema Design (for HBase users)
Intro to HBase Internals & Schema Design (for HBase users)
alexbaranau
 
Intro to HBase
Intro to HBaseIntro to HBase
Intro to HBase
alexbaranau
 
Apache hadoop hbase
Apache hadoop hbaseApache hadoop hbase
Apache hadoop hbase
sheetal sharma
 
Meet hbase 2.0
Meet hbase 2.0Meet hbase 2.0
Meet hbase 2.0
enissoz
 
HBaseCon 2015: Analyzing HBase Data with Apache Hive
HBaseCon 2015: Analyzing HBase Data with Apache  HiveHBaseCon 2015: Analyzing HBase Data with Apache  Hive
HBaseCon 2015: Analyzing HBase Data with Apache Hive
HBaseCon
 
HBase Advanced Schema Design - Berlin Buzzwords - June 2012
HBase Advanced Schema Design - Berlin Buzzwords - June 2012HBase Advanced Schema Design - Berlin Buzzwords - June 2012
HBase Advanced Schema Design - Berlin Buzzwords - June 2012
larsgeorge
 
HBase Read High Availability Using Timeline-Consistent Region Replicas
HBase Read High Availability Using Timeline-Consistent Region ReplicasHBase Read High Availability Using Timeline-Consistent Region Replicas
HBase Read High Availability Using Timeline-Consistent Region Replicas
HBaseCon
 
מיכאל
מיכאלמיכאל
מיכאל
sqlserver.co.il
 
HBaseCon 2013: Apache HBase Replication
HBaseCon 2013: Apache HBase ReplicationHBaseCon 2013: Apache HBase Replication
HBaseCon 2013: Apache HBase Replication
Cloudera, Inc.
 
HBase Read High Availability Using Timeline Consistent Region Replicas
HBase  Read High Availability Using Timeline Consistent Region ReplicasHBase  Read High Availability Using Timeline Consistent Region Replicas
HBase Read High Availability Using Timeline Consistent Region Replicas
enissoz
 
Chicago Data Summit: Apache HBase: An Introduction
Chicago Data Summit: Apache HBase: An IntroductionChicago Data Summit: Apache HBase: An Introduction
Chicago Data Summit: Apache HBase: An Introduction
Cloudera, Inc.
 
Hadoop World 2011: Advanced HBase Schema Design
Hadoop World 2011: Advanced HBase Schema DesignHadoop World 2011: Advanced HBase Schema Design
Hadoop World 2011: Advanced HBase Schema Design
Cloudera, Inc.
 
HBase in Practice
HBase in Practice HBase in Practice
HBase in Practice
DataWorks Summit/Hadoop Summit
 
Apache Hadoop and HBase
Apache Hadoop and HBaseApache Hadoop and HBase
Apache Hadoop and HBase
Cloudera, Inc.
 
Tajo Seoul Meetup July 2015 - What's New Tajo 0.11
Tajo Seoul Meetup July 2015 - What's New Tajo 0.11Tajo Seoul Meetup July 2015 - What's New Tajo 0.11
Tajo Seoul Meetup July 2015 - What's New Tajo 0.11
Hyunsik Choi
 
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
Simplilearn
 
Hbase: an introduction
Hbase: an introductionHbase: an introduction
Hbase: an introduction
Jean-Baptiste Poullet
 
Apache HBase for Architects
Apache HBase for ArchitectsApache HBase for Architects
Apache HBase for Architects
Nick Dimiduk
 
Facebook keynote-nicolas-qcon
Facebook keynote-nicolas-qconFacebook keynote-nicolas-qcon
Facebook keynote-nicolas-qconYiwei Ma
 

What's hot (20)

HBaseCon 2015: Just the Basics
HBaseCon 2015: Just the BasicsHBaseCon 2015: Just the Basics
HBaseCon 2015: Just the Basics
 
Intro to HBase Internals & Schema Design (for HBase users)
Intro to HBase Internals & Schema Design (for HBase users)Intro to HBase Internals & Schema Design (for HBase users)
Intro to HBase Internals & Schema Design (for HBase users)
 
Intro to HBase
Intro to HBaseIntro to HBase
Intro to HBase
 
Apache hadoop hbase
Apache hadoop hbaseApache hadoop hbase
Apache hadoop hbase
 
Meet hbase 2.0
Meet hbase 2.0Meet hbase 2.0
Meet hbase 2.0
 
HBaseCon 2015: Analyzing HBase Data with Apache Hive
HBaseCon 2015: Analyzing HBase Data with Apache  HiveHBaseCon 2015: Analyzing HBase Data with Apache  Hive
HBaseCon 2015: Analyzing HBase Data with Apache Hive
 
HBase Advanced Schema Design - Berlin Buzzwords - June 2012
HBase Advanced Schema Design - Berlin Buzzwords - June 2012HBase Advanced Schema Design - Berlin Buzzwords - June 2012
HBase Advanced Schema Design - Berlin Buzzwords - June 2012
 
HBase Read High Availability Using Timeline-Consistent Region Replicas
HBase Read High Availability Using Timeline-Consistent Region ReplicasHBase Read High Availability Using Timeline-Consistent Region Replicas
HBase Read High Availability Using Timeline-Consistent Region Replicas
 
מיכאל
מיכאלמיכאל
מיכאל
 
HBaseCon 2013: Apache HBase Replication
HBaseCon 2013: Apache HBase ReplicationHBaseCon 2013: Apache HBase Replication
HBaseCon 2013: Apache HBase Replication
 
HBase Read High Availability Using Timeline Consistent Region Replicas
HBase  Read High Availability Using Timeline Consistent Region ReplicasHBase  Read High Availability Using Timeline Consistent Region Replicas
HBase Read High Availability Using Timeline Consistent Region Replicas
 
Chicago Data Summit: Apache HBase: An Introduction
Chicago Data Summit: Apache HBase: An IntroductionChicago Data Summit: Apache HBase: An Introduction
Chicago Data Summit: Apache HBase: An Introduction
 
Hadoop World 2011: Advanced HBase Schema Design
Hadoop World 2011: Advanced HBase Schema DesignHadoop World 2011: Advanced HBase Schema Design
Hadoop World 2011: Advanced HBase Schema Design
 
HBase in Practice
HBase in Practice HBase in Practice
HBase in Practice
 
Apache Hadoop and HBase
Apache Hadoop and HBaseApache Hadoop and HBase
Apache Hadoop and HBase
 
Tajo Seoul Meetup July 2015 - What's New Tajo 0.11
Tajo Seoul Meetup July 2015 - What's New Tajo 0.11Tajo Seoul Meetup July 2015 - What's New Tajo 0.11
Tajo Seoul Meetup July 2015 - What's New Tajo 0.11
 
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
 
Hbase: an introduction
Hbase: an introductionHbase: an introduction
Hbase: an introduction
 
Apache HBase for Architects
Apache HBase for ArchitectsApache HBase for Architects
Apache HBase for Architects
 
Facebook keynote-nicolas-qcon
Facebook keynote-nicolas-qconFacebook keynote-nicolas-qcon
Facebook keynote-nicolas-qcon
 

Viewers also liked

Sun JDK 1.6内存管理 -调优篇
Sun JDK 1.6内存管理 -调优篇Sun JDK 1.6内存管理 -调优篇
Sun JDK 1.6内存管理 -调优篇bluedavy lin
 
JavaOne summary
JavaOne summaryJavaOne summary
JavaOne summary
bluedavy lin
 
HBase@taobao for 技术沙龙
HBase@taobao for 技术沙龙HBase@taobao for 技术沙龙
HBase@taobao for 技术沙龙
bluedavy lin
 
OSGi理论与实战
OSGi理论与实战OSGi理论与实战
OSGi理论与实战
bluedavy lin
 
并发编程交流
并发编程交流并发编程交流
并发编程交流
bluedavy lin
 
Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇bluedavy lin
 
Sun jdk 1.6 gc
Sun jdk 1.6 gcSun jdk 1.6 gc
Sun jdk 1.6 gc
bluedavy lin
 
Hbase简介与实践分享
Hbase简介与实践分享Hbase简介与实践分享
Hbase简介与实践分享
bluedavy lin
 
Sun jdk 1.6 gc english version
Sun jdk 1.6 gc english versionSun jdk 1.6 gc english version
Sun jdk 1.6 gc english version
bluedavy lin
 
Java内存管理问题案例分享
Java内存管理问题案例分享Java内存管理问题案例分享
Java内存管理问题案例分享
bluedavy lin
 
Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)ykdsg
 
Java memory problem cases solutions
Java memory problem cases solutionsJava memory problem cases solutions
Java memory problem cases solutions
bluedavy lin
 
Java常见问题排查
Java常见问题排查Java常见问题排查
Java常见问题排查
bluedavy lin
 
高性能的Java代码编写及常见问题排查
高性能的Java代码编写及常见问题排查高性能的Java代码编写及常见问题排查
高性能的Java代码编写及常见问题排查
bluedavy lin
 
C1000K高性能服务器构建技术
C1000K高性能服务器构建技术C1000K高性能服务器构建技术
C1000K高性能服务器构建技术
Feng Yu
 

Viewers also liked (15)

Sun JDK 1.6内存管理 -调优篇
Sun JDK 1.6内存管理 -调优篇Sun JDK 1.6内存管理 -调优篇
Sun JDK 1.6内存管理 -调优篇
 
JavaOne summary
JavaOne summaryJavaOne summary
JavaOne summary
 
HBase@taobao for 技术沙龙
HBase@taobao for 技术沙龙HBase@taobao for 技术沙龙
HBase@taobao for 技术沙龙
 
OSGi理论与实战
OSGi理论与实战OSGi理论与实战
OSGi理论与实战
 
并发编程交流
并发编程交流并发编程交流
并发编程交流
 
Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇
 
Sun jdk 1.6 gc
Sun jdk 1.6 gcSun jdk 1.6 gc
Sun jdk 1.6 gc
 
Hbase简介与实践分享
Hbase简介与实践分享Hbase简介与实践分享
Hbase简介与实践分享
 
Sun jdk 1.6 gc english version
Sun jdk 1.6 gc english versionSun jdk 1.6 gc english version
Sun jdk 1.6 gc english version
 
Java内存管理问题案例分享
Java内存管理问题案例分享Java内存管理问题案例分享
Java内存管理问题案例分享
 
Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)
 
Java memory problem cases solutions
Java memory problem cases solutionsJava memory problem cases solutions
Java memory problem cases solutions
 
Java常见问题排查
Java常见问题排查Java常见问题排查
Java常见问题排查
 
高性能的Java代码编写及常见问题排查
高性能的Java代码编写及常见问题排查高性能的Java代码编写及常见问题排查
高性能的Java代码编写及常见问题排查
 
C1000K高性能服务器构建技术
C1000K高性能服务器构建技术C1000K高性能服务器构建技术
C1000K高性能服务器构建技术
 

Similar to 菜鸟看Hbase

Admin High Availability
Admin High AvailabilityAdmin High Availability
Admin High Availabilityrsnarayanan
 
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
IndicThreads
 
Hypertable Distilled by edydkim.github.com
Hypertable Distilled by edydkim.github.comHypertable Distilled by edydkim.github.com
Hypertable Distilled by edydkim.github.com
Edward D. Kim
 
Azure Hd insigth news
Azure Hd insigth newsAzure Hd insigth news
Azure Hd insigth news
nnakasone
 
Building Big Data Applications using Spark, Hive, HBase and Kafka
Building Big Data Applications using Spark, Hive, HBase and KafkaBuilding Big Data Applications using Spark, Hive, HBase and Kafka
Building Big Data Applications using Spark, Hive, HBase and Kafka
Ashish Thapliyal
 
SQL et in-memory sur Hadoop avec Pivotal et HAWQ
SQL et in-memory sur Hadoop avec Pivotal et HAWQSQL et in-memory sur Hadoop avec Pivotal et HAWQ
SQL et in-memory sur Hadoop avec Pivotal et HAWQ
Modern Data Stack France
 
Big Data: Big SQL and HBase
Big Data:  Big SQL and HBase Big Data:  Big SQL and HBase
Big Data: Big SQL and HBase
Cynthia Saracco
 
Design for a Distributed Name Node
Design for a Distributed Name NodeDesign for a Distributed Name Node
Design for a Distributed Name Node
Aaron Cordova
 
Ai tour 2019 Mejores Practicas en Entornos de Produccion Big Data Open Source...
Ai tour 2019 Mejores Practicas en Entornos de Produccion Big Data Open Source...Ai tour 2019 Mejores Practicas en Entornos de Produccion Big Data Open Source...
Ai tour 2019 Mejores Practicas en Entornos de Produccion Big Data Open Source...
nnakasone
 
New Security Features in Apache HBase 0.98: An Operator's Guide
New Security Features in Apache HBase 0.98: An Operator's GuideNew Security Features in Apache HBase 0.98: An Operator's Guide
New Security Features in Apache HBase 0.98: An Operator's Guide
HBaseCon
 
Hadoop Summit Dublin 2016: Hadoop Platform at Yahoo - A Year in Review
Hadoop Summit Dublin 2016: Hadoop Platform at Yahoo - A Year in Review Hadoop Summit Dublin 2016: Hadoop Platform at Yahoo - A Year in Review
Hadoop Summit Dublin 2016: Hadoop Platform at Yahoo - A Year in Review
Sumeet Singh
 
Hbase
HbaseHbase
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling
Thorsten Kamann
 
(BDT302) Big Data Beyond Hadoop: Running Mahout, Giraph, and R on Amazon EMR ...
(BDT302) Big Data Beyond Hadoop: Running Mahout, Giraph, and R on Amazon EMR ...(BDT302) Big Data Beyond Hadoop: Running Mahout, Giraph, and R on Amazon EMR ...
(BDT302) Big Data Beyond Hadoop: Running Mahout, Giraph, and R on Amazon EMR ...
Amazon Web Services
 
Chicago Data Summit: Geo-based Content Processing Using HBase
Chicago Data Summit: Geo-based Content Processing Using HBaseChicago Data Summit: Geo-based Content Processing Using HBase
Chicago Data Summit: Geo-based Content Processing Using HBase
Cloudera, Inc.
 
System Update (2011 CrossRef Workshops)
System Update (2011 CrossRef Workshops)System Update (2011 CrossRef Workshops)
System Update (2011 CrossRef Workshops)Crossref
 
NoSql Database
NoSql DatabaseNoSql Database
NoSql Database
Suresh Parmar
 
April 2013 HUG: HBase as a Service at Yahoo!
April 2013 HUG: HBase as a Service at Yahoo!April 2013 HUG: HBase as a Service at Yahoo!
April 2013 HUG: HBase as a Service at Yahoo!
Yahoo Developer Network
 
Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"
Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"
Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"
Lviv Startup Club
 

Similar to 菜鸟看Hbase (20)

Admin High Availability
Admin High AvailabilityAdmin High Availability
Admin High Availability
 
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
 
Hypertable Distilled by edydkim.github.com
Hypertable Distilled by edydkim.github.comHypertable Distilled by edydkim.github.com
Hypertable Distilled by edydkim.github.com
 
Azure Hd insigth news
Azure Hd insigth newsAzure Hd insigth news
Azure Hd insigth news
 
Building Big Data Applications using Spark, Hive, HBase and Kafka
Building Big Data Applications using Spark, Hive, HBase and KafkaBuilding Big Data Applications using Spark, Hive, HBase and Kafka
Building Big Data Applications using Spark, Hive, HBase and Kafka
 
SQL et in-memory sur Hadoop avec Pivotal et HAWQ
SQL et in-memory sur Hadoop avec Pivotal et HAWQSQL et in-memory sur Hadoop avec Pivotal et HAWQ
SQL et in-memory sur Hadoop avec Pivotal et HAWQ
 
Big Data: Big SQL and HBase
Big Data:  Big SQL and HBase Big Data:  Big SQL and HBase
Big Data: Big SQL and HBase
 
Design for a Distributed Name Node
Design for a Distributed Name NodeDesign for a Distributed Name Node
Design for a Distributed Name Node
 
Ai tour 2019 Mejores Practicas en Entornos de Produccion Big Data Open Source...
Ai tour 2019 Mejores Practicas en Entornos de Produccion Big Data Open Source...Ai tour 2019 Mejores Practicas en Entornos de Produccion Big Data Open Source...
Ai tour 2019 Mejores Practicas en Entornos de Produccion Big Data Open Source...
 
New Security Features in Apache HBase 0.98: An Operator's Guide
New Security Features in Apache HBase 0.98: An Operator's GuideNew Security Features in Apache HBase 0.98: An Operator's Guide
New Security Features in Apache HBase 0.98: An Operator's Guide
 
Hadoop Summit Dublin 2016: Hadoop Platform at Yahoo - A Year in Review
Hadoop Summit Dublin 2016: Hadoop Platform at Yahoo - A Year in Review Hadoop Summit Dublin 2016: Hadoop Platform at Yahoo - A Year in Review
Hadoop Summit Dublin 2016: Hadoop Platform at Yahoo - A Year in Review
 
Hbase
HbaseHbase
Hbase
 
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling
 
No sql
No sqlNo sql
No sql
 
(BDT302) Big Data Beyond Hadoop: Running Mahout, Giraph, and R on Amazon EMR ...
(BDT302) Big Data Beyond Hadoop: Running Mahout, Giraph, and R on Amazon EMR ...(BDT302) Big Data Beyond Hadoop: Running Mahout, Giraph, and R on Amazon EMR ...
(BDT302) Big Data Beyond Hadoop: Running Mahout, Giraph, and R on Amazon EMR ...
 
Chicago Data Summit: Geo-based Content Processing Using HBase
Chicago Data Summit: Geo-based Content Processing Using HBaseChicago Data Summit: Geo-based Content Processing Using HBase
Chicago Data Summit: Geo-based Content Processing Using HBase
 
System Update (2011 CrossRef Workshops)
System Update (2011 CrossRef Workshops)System Update (2011 CrossRef Workshops)
System Update (2011 CrossRef Workshops)
 
NoSql Database
NoSql DatabaseNoSql Database
NoSql Database
 
April 2013 HUG: HBase as a Service at Yahoo!
April 2013 HUG: HBase as a Service at Yahoo!April 2013 HUG: HBase as a Service at Yahoo!
April 2013 HUG: HBase as a Service at Yahoo!
 
Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"
Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"
Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"
 

Recently uploaded

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

菜鸟看Hbase

  • 1. HBase– Yet Another NoSQL bluedavy http://blog.bluedavy.com
  • 2. Basic Concept Example 表 表名 + Column Family + Column Qualifier users ( infos(name,email,age) auths(password,security) ) 表名+Column Family相当于Schema Column Qualifier可动态增加 读 table.get(rowKey,Column Family) table.get(rowKey,ColumnFamily,Column Qualifier) table.get(rowKey,ColumnFamily,ColumnQualifier,maxVersions) 写 table.put(rowKey,ColumnFamily,ColumnQualifier,value)
  • 3. Overview Client Zookeeper Region Server Master HDFS
  • 4. Overview Client 读写数据的客户端 Zookeeper 保存rootregion的位置 Master选举 Region Server以及Region上下线的感应 Region Server 表的具体操作的场所 Master Region的分配以及balance HDFS 存放数据的地方
  • 6. Features 水平扩展 可 靠 性 面向列 高性能随机读/写 范围查询 和Hadoop无缝集成
  • 9. 水平扩展 如何做到的? 当storeFile多了后,HBase会自动compact; 当rows多了后,HBase会自动将region split; HBase会定时对Region Server的Region数进行balance; Region Server下线,Master会重新分配其负责的Region到其他的Region Server; Region Server上线后,当Master进行balance时会迁移一些Region到新的Region Server。
  • 10. 面向列 动态增删schema? 传统方案:停机维护; HBase: No,Column Qualifier可动态增删。
  • 11. 面向列 如何做到的? 以Column Family为存储单元; K/V方式存储。
  • 12. 高性能随机读/写 如何做到的? 随机读 K/V存储; Cache; Split; Balance。 随机写(相对而言) Cache+WAL; Compact; Split; Balance;
  • 15. 不足 目前版本不支持二级索引; 易用性不够; 系统结构复杂,运维上有挑战; rowKey的设计对运行状况有很大影响; 对Online业务还是有很大挑战,主要是延时以及失败率。
  • 16. HBase关键操作 读 写 Cache刷磁盘 Compact Split Balance 数据恢复
  • 17. 读 Example 代码 Configuration config=HBaseConfiguration.create(); HTable table=new HTable(config,"users"); Get queryRow=new Get(Bytes.toBytes("0")); queryRow.addColumn(Bytes.toBytes("infos"), Bytes.toBytes("nick")); Result rowResult=table.get(queryRow); System.out.println("nick is :"+Bytes.toString(rowResult.raw()[0].getValue()));
  • 18. 读 Client 本地cache Region Server 1、找rowKey对应的region 或接近rowKey的region 2、未找到则从缓存的.meta信息中获取meta的region server 2.1、从meta所在的Region Server获取rowKey对应的Region 3、RPC发送请求,从Region Server读数据,超时默认为60s 4、reader线程接到RPC请求后,丢到Queue里; 5、10个handler线程处理Queue,默认Queue最大为1000; 6、检查Region Server是否为运行状态; 7、检查Region是否为Online,如不Online则抛出异常; 8、再次检查Region是否正在关闭或已关闭; 9、创建Scanner(Region—Store—Memstore--StoreFile),在读取StoreFile时会先读取LruBlockCache(全局一个,默认20%的xmx空间); 10、扫描找到相应的数据,算法较复杂,不在此描述。 抛出异常或返回结果数据 如抛出异常,则检查重试次数是否超过10次(默认值),未超过则按照指数退避的方法sleep后再继续重试,重试时重新获取meta信息。
  • 19. 影响读的关键因素 速度 是否能从cache中获取到region server的地址; RPC发送请求的速度; RPC超时时间; Reader线程的活跃数; Handler Queue的Size; Handler线程的活跃数; Memstore的命中率; LruCache的命中率; HDFS读取速度; 读重试的次数以及重试的间隔时间。 失败率 Region Server以及Region的状态; HDFS能否读取。
  • 20. 写 Example 代码 Configuration config=HBaseConfiguration.create(); HTable table=new HTable(config,"users"); Put row=new Put(Bytes.toBytes(String.valueOf(“0”))); row.add(Bytes.toBytes("infos"), Bytes.toBytes("nick"), Bytes.toBytes("bixuan")); row.add(Bytes.toBytes("infos"), Bytes.toBytes("age"), Bytes.toBytes(“30”)); row.add(Bytes.toBytes("infos"), Bytes.toBytes("sex"), Bytes.toBytes("male")); table.put(row);
  • 21. 写 Client 本地cache Region Server 1、检验put的key/value size是否超过了最大值,默认无限制; 2、往writeBuffer中放入put,计算currentWriteBufferSize; 3、如为autoFlush或currentWriteBufferSize大于了2M,则提交; 4、从cache中获取需要操作的 Region Server地址; reader线程接到RPC请求后,丢到Queue里; 10个handler线程处理Queue,默认Queue最大为1000; 检查Region Server是否在运行状态,不运行则抛出异常; 检查Region是否online,不online则抛出异常; 检查RS的memstore的总值是否已超过最大限制,超过则唤醒flush线程,并等待5s或唤醒后再次检查,如还是超过,则继续; 如memstore的总值只是超过了最低限制,则只是唤醒flush线程; 从put中获取是否要写WAL; 如region为只读,则抛出异常; 如region的memstore大小超过128M,则通知进行flush,等待10s 后重新尝试; 再次检查region的状态; 行上加锁; 检查families,更新KV的timestamp; 如要写WAL,则写Hlog; 往memstore里写相应的信息; 检查memstore的size是否要flush,如要flush,则通知flusher flush。 5、未找到则从.meta.的region中获取需要操作的region server; 6、丢入htable instance创建的线程池提交put请求,Future方式等待结果; 7、线程池中RPC发送put请求到对应的region server; 抛出异常或返回结果数据 按提交put请求的server遍历返回的结果; 如返回的结果为null或不为DoNotRetryIOException的异常,则放入重试的list中; 进行重试,最大次数10次,每次做指数避让的sleep; 遍历返回的所有result,如其中有null或异常,则抛出RetriesExhaustedWithDetailsException; 从writeBuffer中删除已成功的put请求。
  • 22. 影响写的关键因素 速度 是否autoflush; 不为autoflush时的flushWriteBufferSize; 是否能从cache中获取需要操作的region server地址; Htable instance线程池的队列的size; RPC发送请求的速度以及超时时间; Reader线程的活跃数; Handler Queue的Size; Handler线程的活跃数; RS全局的memstore Size以及Region的memstore size; Memstore刷磁盘的执行频率和时间; 是否WAL; 写Hlog的速度; 写重试的次数。 失败率 Region Server以及Region的状态; HDFS能否写成功。 可靠性 不为autoflush时不可靠; 目前的代码一直要到put成功为止。
  • 23. Cache刷磁盘 MemstoreFlusher HRegion 1、从flush队列中获取刷磁盘的请求,超时时间为10s; 2、如队列中没有请求,或请求的类型为WakeFlushThread,则进入下面的流程; 2.1 判断当前所有的memstore size总和是否超过了最低的阈值(默认为0.35 * -Xmx),如超过则选择一个合适的Region,将其memstore刷入到磁盘; 3、如队列中的请求类型为FlushRegionEntry,则进入下面的流程; 3.1 将该region的memstore刷入到磁盘; 4、将Region的memstore刷入到磁盘。 5、检查Region的状态; 6、锁住对memstore以及storeFile的更新操作; 7、锁住hlog的cacheFlush,避免roll; 8、创建memstore的snapshot; 8.1 清空之前的memstore的内容; 9、释放memstore以及storeFile的更新锁; 10、刷memstore到磁盘并将新文件加入到store list中; 11、如store中的store files已>=3个,则表示需要进行compact; 12、hlog中记录下flush已完成。 13、返回是否需要compact; 14、如需要compact,则放一个请求到CompactSplitThread的队列中。
  • 25. Cache刷磁盘对读写造成的影响 对读的影响 memstore被清空,命中率会有些许下降; 对写的影响 有一小段锁住memstore及storeFile更新操作的时间,基本可忽略,因为只是创建snapshot;
  • 26. Compact CompactSplitThread HRegion 1、根据队列中的请求获取需要Compact的Region,单线程工作; 2、检查Region Server的状态; 3、压缩region; 4、检查region的状态; 5、交给region中的store来完成compact,store会根据一定的算法选择需要compact的storeFiles(如store中有reference,则全部compact),最少要有3个,并根据需要保存的max version生成新的store file; 6、给store加锁,将没有compact的storeFile以及生成的新的store File合并为新的store list,排序并赋值给store files,删除旧的store files,释放锁; 7、如compact后的storeFile文件大于了256m,则获取其中间key,并返回,如小于则返回null; 8、返回中间key或null; 9、如hbase.regionserver.regionSplitLimit>当前server中online的region数,且中间key不为null,则进入split过程。
  • 28. Compact对读写造成的影响 对读的影响; 有一小段锁store的时间,读需要等; 对写的影响; 有一小段锁store的时间,写需要等; Compact文件如果大的话,对写也会产生影响,抢IO资源;
  • 29. Split CompactSplitThread HRegion 1、检查server的状态; 2、创建split文件夹; 3、close region; 4、设置状态为closing; 5、对region加写锁; 6、刷memstore; 7、关闭所有的store file reader; 8、设置状态为closed; 9、释放锁。 10、从online region中拿掉此region; 11、每个store file一个线程进行split,生成的为两个reference的文件; 12、创建两个daughter region,并将parent region从meta表中下线; 12、如split失败,则按状态进行回滚; 13、如split成功,则打开新创建的两个region,更新meta表信息,通知master发生了split事件。
  • 33. 数据恢复 store file中的元信息存储了seqid; region在open时会根据seqid以及hlog来进行恢复; master在重新分配region的时候会将hlog分好类,以便进行恢复; rs在做split动作时会先创建一个splits目录,以便恢复。