hbase hbck流程

 

HBaseFsck类的hbase hbck流程;hbck是一个很重的管理工具,他会访问所有rs,扫描整个meta表,以及读取所有table region里的regioninfo,所以不要频繁使用hbck,会给hbase带来压力

 

 /**
   * This repair method requires the cluster to be online since it contacts
   * region servers and the masters.  It makes each region's state in HDFS, in
   * hbase:meta, and deployments consistent.
   *
   * @return If > 0 , number of errors detected, if < 0 there was an unrecoverable
   * error.  If 0, we have a clean hbase.
   */
  public int onlineConsistencyRepair() throws IOException, KeeperException,
    InterruptedException {
    clearState();

    // get regions according to what is online on each RegionServer
    //加载每个regionserver上的region,将regioninfo放入map中,regioninfo中没有metainfo
    loadDeployedRegions();
    // check whether hbase:meta is deployed and online
    //加载meta表的regioninfo,并检查meta表的regioninfo
    recordMetaRegion();
    // Check if hbase:meta is found only once and in the right place
    //检查meta表,有且只有一个region
    if (!checkMetaRegion()) {
      String errorMsg = "hbase:meta table is not consistent. ";
      if (shouldFixAssignments()) {
        errorMsg += "HBCK will try fixing it. Rerun once hbase:meta is back to consistent state.";
      } else {
        errorMsg += "Run HBCK with proper fix options to fix hbase:meta inconsistency.";
      }
      errors.reportError(errorMsg + " Exiting...");
      return -2;
    }
    // Not going with further consistency check for tables when hbase:meta itself is not consistent.
    LOG.info("Loading regionsinfo from the hbase:meta table");
    //扫描meta表,将regioninfo放入map中,添加metainfo信息
    boolean success = loadMetaEntries();
    if (!success) return -1;

    // Empty cells in hbase:meta?
    reportEmptyMetaCells();

    // Check if we have to cleanup empty REGIONINFO_QUALIFIER rows from hbase:meta
    if (shouldFixEmptyMetaCells()) {
      fixEmptyMetaCells();
    }

    // get a list of all tables that have not changed recently.
    if (!checkMetaOnly) {
      reportTablesInFlux();
    }

    // load regiondirs and regioninfos from HDFS
    if (shouldCheckHdfs()) {//唯一一个默认是true的
      loadHdfsRegionDirs();//获得所有hbase table region dir,将regioninfo hbckinfo上添加hdfsentry对象,表示region在hdfs上的信息
      loadHdfsRegionInfos();//获得所有hbase table region hfile,检查region是否存在(meta region存在,hdfs region不存在)
    }

    // Get disabled tables from ZooKeeper
    loadDisabledTables();

    // fix the orphan tables
    fixOrphanTables();

    // Check and fix consistency
    checkAndFixConsistency();//默认流程,检查meta和hdfs上的region丢失

    // Check integrity (does not fix)
    checkIntegrity();//默认流程,检查region漏洞
    return errors.getErrorList().size();
  }

 

### HBase 的使用指南与教程 #### 1. 学习资源推荐 对于希望深入学习 HBase 的用户来说,有几本经典书籍可以作为参考资料。例如,《HBase: The Definitive Guide》是一本覆盖范围广泛的参考书,适合初学者和中级学习者[^1]。如果更倾向于实践案例,则可以选择《HBase in Action》,该书专注于实际应用场景,更适合有一定开发经验的技术人员[^1]。 #### 2. 命令行工具 HBCK2 使用说明 HBCK2 是 HBase 提供的一个修复工具,主要用于解决元数据一致性问题和其他潜在的数据损坏情况。要运行 HBCK2,可以通过 `$HBASE_HOME/bin/hbase` 脚本来启动,并指定 `-j` 参数来加载对应的 JAR 文件。具体命令如下: ```bash ${HBASE_HOME}/bin/hbase --config /etc/hbase-conf hbck -j ~/hbase-operator-tools/hbase-hbck2/target/hbase-hbck2-xxx.jar ``` 默认情况下,如果不加特殊参数,执行 `hbck` 将会调用旧版本的修复工具(即 HBCK1)。因此,在需要高级功能时务必显式指明路径[^2]。 #### 3. 集成 Spark 和 HBase (HBase-RDD) 为了简化大数据处理流程中的复杂操作,社区还提供了专门针对 Apache Spark 设计的支持库——HBase-RDD。此项目允许开发者创建自定义逻辑轻松读取、写入甚至删除存储在 HBase 中的内容。更多详情可访问官方仓库链接获取最新文档和支持信息[^3]: [https://gitcode.com/gh_mirrors/hb/hbase-rdd](https://gitcode.com/gh_mirrors/hb/hbase-rdd) #### 4. Zookeeper 在 HBase 架构中的角色 值得注意的是,Zookeeper 对于整个 HBase 生态系统至关重要。它不仅负责协调多个节点之间的通信,而且承担着诸如选举 Master 实例、维护 RegionServer 注册表等功能。通过采用 Zap 协议保障集群内部状态同步一致,从而减少应用程序层面额外的工作量[^4]。 以下是基于 Java 编程语言连接到远程 HBase 表格实例的一个简单例子: ```java Configuration config = HBaseConfiguration.create(); config.set("hbase.zookeeper.quorum", "localhost"); try(Connection connection = ConnectionFactory.createConnection(config)){ Table table = connection.getTable(TableName.valueOf("myTable")); Get get = new Get(Bytes.toBytes("rowKeyExample")); Result result = table.get(get); byte[] value = result.getValue(Bytes.toBytes("columnFamily"), Bytes.toBytes("qualifier")); } catch(IOException e){ System.err.println(e.getMessage()); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值