HMaster 功能之定期清理archive

作者: 虾米在海飘 | 来源:发表于2016-12-08 11:25 被阅读1949次

    在HBase中,HMaster不承担读写数据的任务,那HMaster的主要功能呢?
    HMaster功能:

    1. 管理HRegionServer,实现其负载均衡
    2. 管理和分配HRegion,比如在HRegion split时分配新的HRegion;在HRegionServer退出时迁移其内的HRegion到其他HRegionServer上
    3. 监控集群中所有HRegionServer的状态(通过Heartbeat和监听ZooKeeper中的状态)
    4. 处理schema更新请求 (创建、删除、修改Table的定义), 如下图:
    HMaster功能

    除此之外还有:HMaster.HFileCleaner 定期清理archive下的文件 。

    首先回顾下HBase 在HDFS上的物理目录结构:

    /hbase/data
    /hbase/archive
    /hbase/.tmp
    /hbase/corrupt
    /hbase/hbase.id
    /hbase/hbase.version
    /hbase/WALs
    /hbase/oldWALs
    /hbase/.hbase-snapshot

    1. /hbase/data
      hbase 的核心目录,0.98版本里支持 namespace 的概念模型,系统会预置两个 namespace 即:hbase和default


      预置namespace

      /hbase/data/hbase 存储了存储了 HBase 的 namespace、meta 两个系统级表。namespace 中存储了 HBase 中的所有 namespace 信息,包括预置的hbase 和 default。


      namespace、meta
      hbase/data/default/ 存储所有用户数据表/hbase/data/default/表名
      用户表
    2. /hbase/archive
      存储表的归档和快照,HBase 在做 Split或者 compact 操作完成之后,会将 HFile 移到archive 目录中,然后将之前的 hfile 删除掉,该目录由 HMaster 上的一个定时任务定期去清理。存储表的归档和快照具体目录:/hbase/archive/data/default/表名/region名/列族名/fd2221d8d1ae4e579c21882f0ec4c5a5
    3. /hbase/.tmp
      这个目录用来存储临时文件,当对表进行操作的时候,首先会将表移动到该目录下,然后再进行操作。
    4. /hbase/hbase.id
      存储集群唯一的 cluster id 号,是一个 uuid。
    5. /hbase/hbase.version
      同样也是一个文件,存储集群的版本号,貌似是加密的,看不到,只能通过web-ui 才能正确显示出来。
    6. /hbase/WALs
      被HLog实例管理的WAL文件
    7. /hbase/oldWALs
      当/hbase/WALs 中的HLog文件被持久化到存储文件中,不再需要日志文件时,它们会被移动到/hbase/oldWALs目录。
    8. /hbase/.hbase-snapshot
      HBase 从0.95开始引入了Snapshot,可以对table进行Snapshot,也可以Restore到Snapshot。Snapshot可以在线做,也可以离线做。Snapshot的实现不涉及到table实际数据的拷贝,仅仅拷贝一些元数据,比如组成table的region info,表的descriptor,还有表对应的HFile的文件的引用。
      /hbase/.hbase-snapshot存储的是snapshot的相关信息。

    snapshot 'memberTb','memberTbSnapshotOne'

    对memberTb做snapshot后,会生成相应的.snapshotinfo和data.manifest


    hbase-snapshot.png

    定时清理任务的插件设置:
    HFileCleaner 定期清理.archive目录下的HFile。
    它会从hbase.master.hfilecleaner.plugins配置里加载所有BaseHFileCleanerDelegate。 只有所有delegate都同意才能被删除。

    HFileCleaner
    HFileCleaner执行的cleanerInterval默认为1分钟,archiveDir为hbase的archive路径:
    Paste_Image.png

    而HBase的配置可以看出来,source为programatically,即程序自动添加:

    hbase.master.hfilecleaner.plugins

    则,就是HFileLinkCleaner,SnapshotHFileCleaner,TimeToLiveHFileCleaner 这三种规则的约束来清理archive中的数据!

    1. HFileLinkCleaner
    HFileLinkCleaner

    /**

    • HFileLink cleaner that determines if a hfile should be deleted.
    • HFiles can be deleted only if there're no links to them.
    • When a HFileLink is created a back reference file is created in:
    •  /hbase/archive/table/region/cf/.links-hfile/ref-region.ref-table
      
    • To check if the hfile can be deleted the back references folder must be empty.
      */

    如果对archive中的文件的引用不存在了,则可以删除
    问题:/hbase/archive/table/region/cf/.links-hfile/ref-region.ref-table 从何而来?
    回答:HBase 做split的时候

    2.SnapshotHFileCleaner


    SnapshotHFileCleaner

    /**

    • Implementation of a file cleaner that checks if a hfile is still used by snapshots of HBase
    • tables.
      */

    未被snapshots 引用的文件,可以删除

    问题: snapshot为嘛会引用到archive中的文件?
    回答: Hbase做major compact的时候。详情见HBase major compact 对snapshot 的影响

    3.TimeToLiveHFileCleaner


    TimeToLiveHFileCleaner

    /**

    • HFile cleaner that uses the timestamp of the hfile to determine if it should be deleted. By
    • default they are allowed to live for {@value #DEFAULT_TTL}
      */

    默认清理时间超过5分钟的HFile

    参考内容;
    http://blog.bcmeng.com/post/hbase-hdfs.html
    http://www.cnblogs.com/nexiyi/p/hbase_on_hdfs_directory.html
    http://ppg.iteye.com/blog/1888453
    http://brianf.iteye.com/blog/1884885
    http://46aae4d1e2371e4aa769798941cef698.devproxy.yunshipei.com/gzh1992n/article/details/47173753
    http://www.cnblogs.com/tgzhu/p/5857035.html
    http://www.cnblogs.com/foxmailed/p/3914117.html

    相关文章

      网友评论

        本文标题:HMaster 功能之定期清理archive

        本文链接:https://www.haomeiwen.com/subject/jbajmttx.html