`
brianf
  • 浏览: 37091 次
  • 来自: 杭州
社区版块
存档分类
最新评论

HLog代码分析及与HBase replication延时

阅读更多
在分享replication时,有同事提出replication延时怎么样,(基于0.94.3)
本文主要代码分析一下Hlog生成及对relication的影响。具体replication请参考
http://brianf.iteye.com/blog/1776936

首先分析hlog什么时候产生:

在生成HLog对象时,会调用HLog的rollWriter(),此时由于this.writer为null,所以通过rollWriter方法会创建第一个hlog文件,之后会调用replicaton相关的参见http://brianf.iteye.com/blog/1776936

    // rollWriter sets this.hdfs_out if it can.
    rollWriter();

    // handle the reflection necessary to call getNumCurrentReplicas()
    this.getNumCurrentReplicas = getGetNumCurrentReplicas(this.hdfs_out);

    logSyncerThread = new LogSyncer(this.optionalFlushInterval);

-----------------

 public byte [][] rollWriter(boolean force)
      throws FailedLogCloseException, IOException {
    // Return if nothing to flush.
    if (!force && this.writer != null && this.numEntries.get() <= 0) {
      return null;
    }


-------------
LogRoller.run中      

  public void run() {
    while (!server.isStopped()) {
      long now = System.currentTimeMillis();
      boolean periodic = false;
      if (!rollLog.get()) {
        periodic = (now - this.lastrolltime) > this.rollperiod;
        if (!periodic) {
          synchronized (rollLog) {
            try {
              rollLog.wait(this.threadWakeFrequency);
            } catch (InterruptedException e) {
              // Fall through
            }
          }
          continue;
        }
        // Time for periodic roll
        if (LOG.isDebugEnabled()) {
          LOG.debug("Hlog roll period " + this.rollperiod + "ms elapsed");
        }
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("HLog roll requested");
      }
      rollLock.lock(); // FindBugs UL_UNRELEASED_LOCK_EXCEPTION_PATH
      try {
        this.lastrolltime = now;
        // This is array of actual region names.
        byte [][] regionsToFlush = this.services.getWAL().rollWriter(rollLog.get());


LogRoller线程默认会等待1小时,也就是默认是1个小时一个log(后面会说还有hlog size也会是一个因素)
    this.rollperiod = this.server.getConfiguration().
      getLong("hbase.regionserver.logroll.period", 3600000);



而rollLog是AtomicBoolean, 当为true时,调用rollWriter会创建新log, 什么时候rollLog为true呢?


  public void logRollRequested() {
    synchronized (rollLog) {
      rollLog.set(true);
      rollLog.notifyAll();
    }
  }


是在Hlog.syncer方法中调用的。


数据写入hbase时,如put,调用Hlog的append ,此方法中将数据写到Hlog的缓存中(List),再同步sync数据到HDSF,还有LogSyncer线程会1000ms执行一次 Hlog.syncer方法 。



  private long append(HRegionInfo info, byte [] tableName, WALEdit edits, UUID clusterId,
      final long now, HTableDescriptor htd, boolean doSync)
    throws IOException {
      if (edits.isEmpty()) return this.unflushedEntries.get();;
      if (this.closed) {
        throw new IOException("Cannot append; log is closed");
      }
      long txid = 0;
      synchronized (this.updateLock) {
        long seqNum = obtainSeqNum();
        // The 'lastSeqWritten' map holds the sequence number of the oldest
        // write for each region (i.e. the first edit added to the particular
        // memstore). . When the cache is flushed, the entry for the
        // region being flushed is removed if the sequence number of the flush
        // is greater than or equal to the value in lastSeqWritten.
        // Use encoded name.  Its shorter, guaranteed unique and a subset of
        // actual  name.
        byte [] encodedRegionName = info.getEncodedNameAsBytes();
        this.lastSeqWritten.putIfAbsent(encodedRegionName, seqNum);
        HLogKey logKey = makeKey(encodedRegionName, tableName, seqNum, now, clusterId);
        doWrite(info, logKey, edits, htd);
        this.numEntries.incrementAndGet();
        txid = this.unflushedEntries.incrementAndGet();
        if (htd.isDeferredLogFlush()) {
          lastDeferredTxid = txid;
        }
      }
      // Sync if catalog region, and if not then check if that table supports
      // deferred log flushing
      if (doSync && 
          (info.isMetaRegion() ||
          !htd.isDeferredLogFlush())) {
        // sync txn to file system
        this.sync(txid);
      }
      return txid;
    }




其中在Hlog.syncer方法中调用checkLowReplication方法用来判断是否hlog在hdfs上的副本数低于配置项,若低于则requestLogRoll,最终调用logRollRequested方法,但是调用次数不超过默认5次(  
 this.lowReplicationRollLimit = conf.getInt(
        "hbase.regionserver.hlog.lowreplication.rolllimit", 5);


然后判断正在写的hlog是否大于一个size(64MB*0.95),若大于,说明也要生成新的Hlog
    this.blocksize = conf.getLong("hbase.regionserver.hlog.blocksize",
        getDefaultBlockSize());
    // Roll at 95% of block size.
    float multi = conf.getFloat("hbase.regionserver.logroll.multiplier", 0.95f);
    this.logrollsize = (long)(this.blocksize * multi);
--------------------
          if (tempWriter.getLength() > this.logrollsize) {
            requestLogRoll();
          }


对于replication来说,延迟时间主要是与ZK的通讯及RPC调用slave RS时间。



hbase.regionserver.optionallogflushinterval
将Hlog同步到HDFS的间隔。如果Hlog没有积累到一定的数量,到了时间,也会触发同步。默认是1秒,单位毫秒。
默认: 1000
hbase.regionserver.logroll.period
提交commit log的间隔,不管有没有写足够的值。
默认: 3600000
hbase.master.logcleaner.ttl
Hlog存在于.oldlogdir 文件夹的最长时间, 超过了就会被 Master 的线程清理掉.
默认: 600000
hbase.master.logcleaner.plugins
值用逗号间隔的文本表示。这些WAL/HLog  cleaners会按顺序调用。可以把先调用的放在前面。可以实现自己的LogCleanerDelegat,加到Classpath下,然后在这里写上类的全路径就可以。一般都是加在默认值的前面。
具体的初始是在CleanerChore 的initCleanerChain方法,此方法同时也实现HFile的cleaner的初台化。
默认: org.apache.hadoop.hbase.master.TimeToLiveLogCleaner

hbase.regionserver.hlog.blocksize
hbase.regionserver.maxlogs

WAL的最大值由hbase.regionserver.maxlogs * hbase.regionserver.hlog.blocksize (2GB by default)决定。一旦达到这个值,Memstore flush就会被触发。通过WAL限制来触发Memstore的flush并非最佳方式,这样做可能会会一次flush很多Region,引发flush雪崩。

最好将hbase.regionserver.hlog.blocksize * hbase.regionserver.maxlogs 设置为稍微大于hbase.regionserver.global.memstore.lowerLimit * HBASE_HEAPSIZE.
0
0
分享到:
评论

相关推荐

    HBase 应用平台 Replication 功能

    对于源码级别的理解,可以查看HBase的源代码,了解Replication的具体实现细节。同时,HBase提供了命令行工具以及Admin API来管理和监控复制状态。 总的来说,HBase的Replication功能是保证数据可靠性和一致性的...

    深入学习hbase原理资料整理

    《深入学习HBase原理》...6. HBase与其他技术如Hadoop、Hive、NoSQL和MongoDB的集成,提供了丰富的数据管理和分析能力。 深入理解这些原理,对于优化HBase的性能、保证数据安全以及构建高效的大数据解决方案至关重要。

    hbase的rowkey设计与hbase的协处理器运用.docx

    HBase RowKey 设计与协处理器运用 HBase 是一个基于 HDFS 的分布式、面向列的 NoSQL 数据库,具有高性能、可靠性和扩展性等特点。本文将详细介绍 HBase 的 RowKey 设计和协处理器运用。 HBase 的介绍 HBase 是一...

    Hbase权威指南 随书源代码 源码包 绝对完整版

    《HBase权威指南》是Hadoop生态中关于分布式数据库HBase的重要参考书籍,随书附带的源代码是学习和理解HBase实现机制的关键资源。这个源码包名为"hbase-book-master",意味着它是该书的主代码仓库,包含完整的示例和...

    hbase源码分析

    #### 一、HBase性能测试要点与分析 ##### 1.1 测试环境 - **硬件配置**: - 客户端:1台 - RegionServer:5台 - Master:1台 - ZooKeeper:3台 - **软件配置**: - CPU:每台服务器配备8核,通过超线程技术...

    hbase备份和数据恢复

    在大数据领域,HBase是一个基于Hadoop的分布式数据库,它为...而HBase与Hive的互导以及与HDFS的互导则为大数据分析提供了灵活的数据流转路径。理解和掌握这些知识点对于管理和优化大数据环境中的HBase操作至关重要。

    hbase-1.2.6-bin.tar.gz

    1. **列式存储**:与传统的关系型数据库不同,HBase以列族(Column Family)的形式存储数据,这种模式对于大数据分析非常高效,因为可以只扫描需要的列。 2. **分布式架构**:HBase通过Region Server将数据分布在...

    hbase-0.98.1源码包

    源码包“hbase-0.98.1-src.tar.gz”提供了HBase 0.98.1版本的完整源代码,对于理解其内部工作原理、进行二次开发或调试是非常有价值的。 HBase的核心概念包括: 1. 表:HBase中的表由行和列族组成,表名全局唯一。...

    HbaseReferenceBook-Hbase参考指南英文版

    HBase将数据存储在HDFS中,并通过HLog进行数据的日志记录,以保证数据的一致性和可靠性。HBase的设计也涉及到数据的物理存储和内存管理,以及如何通过RegionServer和MasterServer来维护数据的水平扩展性和高可用性。...

    hbase2.5.6最新版本下载

    总结,HBase 2.5.6作为最新的版本,持续致力于提升性能、稳定性、安全性及易用性,以满足大数据处理的挑战。无论是对于实时分析、大规模数据存储还是复杂的查询需求,HBase都是一个值得信赖的解决方案。在使用HBase ...

    hbase指南 英文

    - **HLog**:HBase 使用 HLog 来记录事务日志,确保数据的一致性和持久性。 - **MemStore**:用于存储最新的未持久化的数据修改,当 MemStore 达到一定大小后,会触发刷盘操作,将数据写入磁盘。 - **HFile**:HFile...

    Hbase权威指南随书源代码源码包

    3. 进阶功能:如Region分裂、负载均衡、数据压缩、备份与恢复等高级操作的示例代码,帮助读者掌握HBase的全面功能。 4. 客户端API:展示如何使用Java API或者命令行工具与其他程序交互,进行数据操作。 5. 性能调优...

    搭建HBase完全分布式数据库

    HBase是一个分布式、面向列的开源数据库,它运行在Hadoop的文件系统(HDFS)之上,利用Hadoop的MapReduce来处理HBase中的大数据,同时也使用Apache ZooKeeper作为分布式协同服务。HBase特别适合于需要快速读写访问...

    大数据HBASE考题材料

    HRegionServer与HMaster及客户端之间的通信采用RPC协议,即远程过程调用协议,这是一种用于不同计算机系统间的进程间通信的方式。 8. **HFile中的KeyValue结构** 在HFile数据格式中,KeyValue数据结构的Value...

    HBase详细讲解

    5. HLog:HLog是HBase中用于记录所有对表的更新操作的日志文件,这些日志文件可以在系统出现故障时用于数据的恢复。 在使用HBase时,Rowkey的设计非常重要,因为它直接关系到数据的读写性能和存储效率。设计Rowkey...

    05.02深入HBase1

    HBase还支持与其他Hadoop生态组件的集成,如MapReduce,这使得它能够方便地进行批量数据处理和分析。此外,HBase提供了数据迁移工具,例如importTsv,用于将TSV格式的数据导入到HBase表中。 总结起来,HBase的核心...

    hlog,日志,调试

    通过分析这些测试用例,开发者可以学习如何在代码中正确地集成和使用“hlog”日志系统,例如,如何设置日志级别,如何输出自定义信息,以及如何配置日志输出的位置和格式。 在调试过程中,有效的日志策略还包括以下...

    Hbase 高可用分布式搭建

    4. 数据复制:开启HBase的多版本特性,可以设置WAL(Write-Ahead Log)和HLog的复制,增强数据安全性。 五、HBase分布式搭建步骤 1. 安装Java环境:HBase依赖Java运行,确保所有节点安装JDK。 2. 安装Hadoop:按照...

    HBase技术介绍.docx

    #### 二、HBase的核心特性及原理 ##### 1. **基于Hadoop生态系统** - **HDFS(Hadoop Distributed File System)**: 作为HBase的基础存储层,提供高可用性和持久化的数据存储能力。 - **MapReduce**: 支持对HBase...

    HBASE编程指南word版

    #### 一、HBase简介及背景 - **定义**: HBase是一种分布式、可扩展的大规模列式存储系统,它基于Google的Bigtable论文设计实现,是Apache Hadoop生态系统中的重要组成部分。 - **应用场景**: 主要应用于海量数据...

Global site tag (gtag.js) - Google Analytics