HBase 遇到的问题以及处理

这篇具有很好参考价值的文章主要介绍了HBase 遇到的问题以及处理。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

背景

目前在hbase集群中发现了一些问题,主要是Region 一致性的问题,和RIT问题,根据目前遇到的问题整理了以下问题fix手册。 如果后面遇到新的问题可以再增加

Hbase hbck 处理Region一致性问题

Issue: Regions have the same start/end keys

Cause

Varies.

Resolution

手动合并重叠的区域。 在 HBase HMaster Web UI 表详情页面,选择有问题的表链接。 可以看到属于该表的每个区域的开始键/结束键。 然后合并重叠的区域。 在 HBase shell 中,执行 merge_region ‘xxxxxxxx’,‘yyyyyyy’, true。 例如:

RegionA, startkey:001, endkey:010,

RegionB, startkey:001, endkey:080,

RegionC, startkey:010, endkey:080.

在这种场景下,需要合并RegionA和RegionC,得到与RegionB相同key范围的RegionD,再合并RegionB和RegionD。 xxxxxxx 和 yyyyyy 是每个区域名称末尾的哈希字符串。 这里要小心不要合并两个不连续的区域。 每次合并后,如合并 A 和 C,HBase 将开始对 RegionD 进行压缩。 等待压缩完成,然后再与 RegionD 进行另一次合并。 您可以在 HBase HMaster UI 的区域服务器页面上找到压缩状态。

Issue: Region overlap

Cause

很有可能是在分裂过程中Region Server 重启,或split不彻底,导致重复上线,就会导致两个region有重叠的部分。

Resolution

这种场景下,和以上的处理方式相同,需要注意的是这Region进行Compact的时候不能合并成功,在hbase shell 进行合并后,可以观察HMaster的日志,如果最终可以合并成功,则不会出现error日志信息,如果遇到始终不能合并的Region,可以先尝试将此Region下线掉(unassign region),再次上线(assign region),再执行merge操作。例如:

merge_region 'regionA','regionB',true

在这个过程中有可能需要检查一些hfile文件其中的数据是否已经表中可以使用


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.KeyOnlyFilter;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.hadoop.hbase.io.hfile.HFile;
import org.apache.hadoop.hbase.io.hfile.HFileScanner;
import org.apache.hadoop.hbase.io.hfile.HFileWriterImpl;
import org.apache.hadoop.hbase.regionserver.HStoreFile;
import org.apache.hadoop.hbase.regionserver.TimeRangeTracker;
import org.apache.hadoop.hbase.util.BloomFilter;
import org.apache.hadoop.hbase.util.BloomFilterFactory;
import org.apache.hadoop.hbase.util.BloomFilterUtil;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.DataInput;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Map;
import java.util.Optional;

/**
 * @author wxl
 */
@Component
public class ReadHFile {
    private static final Logger log = LoggerFactory.getLogger(ReadHFile.class);

    private final PrintStream out = System.out;
    private static final String FOUR_SPACES = "    ";

    @Value("${hbase.hfile.path:''}")
    private String hfile;

    public void run() throws Exception {
        Configuration conf = HBaseConfiguration.create();
        Connection connection = ConnectionFactory.createConnection(conf);
        Table table = connection.getTable(TableName.valueOf("LG_DEVICE_DATA:ALL_DEVICE_DATA"));
        FileSystem fs = FileSystem.get(conf);

        Path path = new Path(hfile);
        FileStatus[] dirs = fs.listStatus(path);
        for (FileStatus hfile : dirs) {
            boolean hFileFormat = HFile.isHFileFormat(fs, hfile.getPath());
            if (!hFileFormat) {
                continue;
            }

            HFile.Reader reader = HFile.createReader(fs, hfile.getPath(), CacheConfig.DISABLED, true, conf);

            //打印meta 信息
            //Map<byte[], byte[]> fileInfo = reader.loadFileInfo();
            //printMeta(reader, fileInfo);
            Optional<byte[]> firstRowKey = reader.getFirstRowKey();
            Optional<byte[]> lastRowKey = reader.getLastRowKey();
            StringBuilder sb = new StringBuilder();
            if (firstRowKey.isPresent()) {
                isExists(table, firstRowKey.get(), false, hfile.getPath().toString());
            }
            if (lastRowKey.isPresent()) {
                isExists(table, lastRowKey.get(), false, hfile.getPath().toString());
            }
            reader.close();

        }

        fs.close();
        table.close();
        connection.close();
    }

    public void isExists(Table table, byte[] rowKey, boolean p, String path) throws IOException {
        Get get = new Get(rowKey);
        get.setFilter(new KeyOnlyFilter());
        Result result = table.get(new Get(rowKey));
        if (p) {
            log.info("result: [{}]", result);
        }
        if (result == null || result.isEmpty()) {
            log.info("rowKey not exists: [{}] filePath: [{}]", new String(rowKey), path);
        }
//        else {
//            byte[] row = result.getRow();
//            log.info("ok: " + new String(row));
//        }
    }

    private void check(Table table, HFileScanner scanner) throws IOException {
        scanner.seekTo();
        byte[] pRowKey = null;
        int count = 0;
        while (scanner.next()) {
            Cell cell = scanner.getKey();
            byte[] rowKey = CellUtil.cloneRow(cell);
            if (!Bytes.equals(pRowKey, rowKey)) {
                boolean p = false;
                ++count;
                if (count % 1000 == 0) {
                    log.info("current count: [{}]", count);
                    //  p = true;
                }
                isExists(table, rowKey, p, "");
            }
            pRowKey = rowKey;
        }
        log.info("count rowKey: [{}]", count);
    }

    private void printMeta(HFile.Reader reader, Map<byte[], byte[]> fileInfo)
            throws IOException {
        out.println("Block index size as per heapsize: "
                + reader.indexSize());
        out.println(asSeparateLines(reader.toString()));
        out.println("Trailer:\n    "
                + asSeparateLines(reader.getTrailer().toString()));
        out.println("Fileinfo:");
        for (Map.Entry<byte[], byte[]> e : fileInfo.entrySet()) {
            out.print(FOUR_SPACES + Bytes.toString(e.getKey()) + " = ");
            if (Bytes.equals(e.getKey(), HStoreFile.MAX_SEQ_ID_KEY)
                    || Bytes.equals(e.getKey(), HStoreFile.DELETE_FAMILY_COUNT)
                    || Bytes.equals(e.getKey(), HStoreFile.EARLIEST_PUT_TS)
                    || Bytes.equals(e.getKey(), HFileWriterImpl.MAX_MEMSTORE_TS_KEY)
                    || Bytes.equals(e.getKey(), Bytes.toBytes("hfile.CREATE_TIME_TS"))
                    || Bytes.equals(e.getKey(), HStoreFile.BULKLOAD_TIME_KEY)) {
                out.println(Bytes.toLong(e.getValue()));
            } else if (Bytes.equals(e.getKey(), HStoreFile.TIMERANGE_KEY)) {
                TimeRangeTracker timeRangeTracker = TimeRangeTracker.parseFrom(e.getValue());
                out.println(timeRangeTracker.getMin() + "...." + timeRangeTracker.getMax());
            } else if (Bytes.equals(e.getKey(), Bytes.toBytes("hfile.AVG_KEY_LEN"))
                    || Bytes.equals(e.getKey(), Bytes.toBytes("hfile.AVG_VALUE_LEN"))
                    || Bytes.equals(e.getKey(), HFileWriterImpl.KEY_VALUE_VERSION)
                    || Bytes.equals(e.getKey(), HFile.FileInfo.MAX_TAGS_LEN)) {
                out.println(Bytes.toInt(e.getValue()));
            } else if (Bytes.equals(e.getKey(), HStoreFile.MAJOR_COMPACTION_KEY)
                    || Bytes.equals(e.getKey(), Bytes.toBytes("hfile.TAGS_COMPRESSED"))
                    || Bytes.equals(e.getKey(), HStoreFile.EXCLUDE_FROM_MINOR_COMPACTION_KEY)) {
                out.println(Bytes.toBoolean(e.getValue()));
            } else if (Bytes.equals(e.getKey(), Bytes.toBytes("hfile.LASTKEY"))) {
                out.println(new KeyValue.KeyOnlyKeyValue(e.getValue()).toString());
            } else {
                out.println(Bytes.toStringBinary(e.getValue()));
            }
        }

        try {
            out.println("Mid-key: " + reader.midKey().map(CellUtil::getCellKeyAsString));
        } catch (Exception e) {
            out.println("Unable to retrieve the midkey");
        }

        // Printing general bloom information
        DataInput bloomMeta = reader.getGeneralBloomFilterMetadata();
        BloomFilter bloomFilter = null;
        if (bloomMeta != null) {
            bloomFilter = BloomFilterFactory.createFromMeta(bloomMeta, reader);
        }

        out.println("Bloom filter:");
        if (bloomFilter != null) {
            out.println(FOUR_SPACES + bloomFilter.toString().replaceAll(
                    BloomFilterUtil.STATS_RECORD_SEP, "\n" + FOUR_SPACES));
        } else {
            out.println(FOUR_SPACES + "Not present");
        }

        // Printing delete bloom information
        bloomMeta = reader.getDeleteBloomFilterMetadata();
        bloomFilter = null;
        if (bloomMeta != null) {
            bloomFilter = BloomFilterFactory.createFromMeta(bloomMeta, reader);
        }

        out.println("Delete Family Bloom filter:");
        if (bloomFilter != null) {
            out.println(FOUR_SPACES
                    + bloomFilter.toString().replaceAll(BloomFilterUtil.STATS_RECORD_SEP,
                    "\n" + FOUR_SPACES));
        } else {
            out.println(FOUR_SPACES + "Not present");
        }
    }

    /**
     * Format a string of the form "k1=v1, k2=v2, ..." into separate lines
     * with a four-space indentation.
     */
    private static String asSeparateLines(String keyValueStr) {
        return keyValueStr.replaceAll(", ([a-zA-Z]+=)",
                ",\n" + FOUR_SPACES + "$1");
    }
}

Issue: ERROR: Found lingering reference file xxxx

Cause

这很可能是由于 RegionServer 崩溃或 VM 重启时region 没有删除完全导致的。

Resolution

hbase hbck -fixReferenceFiles month_hotstatic

检测hbase 的Region是否健康

使用hbase hbck 命令检测,如果发现>=1个问题检测到,则表示Region出现了问题文章来源地址https://www.toymoban.com/news/detail-581646.html

0 inconsistencies detected.
Status: OK

特别注意

  • 以上问题处理完后需要重启Phoenix Query Server 因其内部有缓存,可能会导致查询问题

到了这里,关于HBase 遇到的问题以及处理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【大数据】分布式数据库HBase

    目录 1.概述 1.1.前言 1.2.数据模型 1.3.列式存储的优势 2.实现原理 2.1.region 2.2.LSM树 2.3.完整读写过程 2.4.master的作用 本文式作者大数据系列专栏中的一篇文章,按照专栏来阅读,循序渐进能更好的理解,专栏地址: https://blog.csdn.net/joker_zjn/category_12631789.html?spm=1001.2014.3001.5482 当

    2024年04月27日
    浏览(32)
  • 使用IDEA连接hbase数据库

     Hbase是安装在另一台LINUX服务器上的,需要本地通过JAVA连接HBase数据库进行操作。由于是第一次接触HBase,过程当中百度了很多资料,也遇到了很多的问题。耗费了不少时间才成功连接上。特记录下过程当中遇到的问题。 JAVA连接HBase代码如下: 首先通过POM将需要的JAR包导入。

    2024年02月03日
    浏览(80)
  • HBase的数据库与HadoopEcosyste

    HBase是一个分布式、可扩展、高性能、高可用性的列式存储系统,基于Google的Bigtable设计。HBase是Hadoop生态系统的一个重要组成部分,与Hadoop HDFS、MapReduce、ZooKeeper等产品密切相关。本文将从以下几个方面进行深入探讨: 背景介绍 核心概念与联系 核心算法原理和具体操作步骤

    2024年02月20日
    浏览(34)
  • 大数据NoSQL数据库HBase集群部署

    目录 1.  简介 2.  安装 1. HBase依赖Zookeeper、JDK、Hadoop(HDFS),请确保已经完成前面 2. 【node1执行】下载HBase安装包 3. 【node1执行】,修改配置文件,修改conf/hbase-env.sh文件 4. 【node1执行】,修改配置文件,修改conf/hbase-site.xml文件 5. 【node1执行】,修改配置文件,修改conf/regi

    2024年02月08日
    浏览(40)
  • HBase的数据库容量规划与优化

    HBase的数据库容量规划与优化 HBase是一个分布式、可扩展、高性能的列式存储系统,基于Google的Bigtable设计。它是Hadoop生态系统的一部分,可以与HDFS、MapReduce、ZooKeeper等组件集成。HBase适用于大规模数据存储和实时数据访问场景,如日志处理、实时统计、搜索引擎等。 在实际

    2024年02月20日
    浏览(33)
  • HBase的数据库安全与权限管理

    HBase是一个分布式、可扩展、高性能的列式存储系统,基于Google的Bigtable设计。它是Hadoop生态系统的一部分,可以与HDFS、MapReduce、ZooKeeper等组件集成。HBase具有高可靠性、高性能和高可扩展性等特点,适用于大规模数据存储和实时数据处理。 在现代企业中,数据安全和权限管

    2024年02月20日
    浏览(34)
  • HBase的数据库备份与恢复策略

    HBase是一个分布式、可扩展、高性能的列式存储系统,基于Google的Bigtable设计。它是Hadoop生态系统的一部分,可以与HDFS、MapReduce、ZooKeeper等组件集成。HBase具有高可用性、高可扩展性和高性能等优势,适用于大规模数据存储和实时数据处理。 在实际应用中,数据备份和恢复是

    2024年02月19日
    浏览(45)
  • 大数据NoSQL数据库HBase集群部署——详细讲解~

    HBase 是一种分布式、可扩展、支持海量数据存储的 NoSQL 数据库。 和Redis一样,HBase是一款KeyValue型存储的数据库。 不过和Redis设计方向不同 Redis设计为少量数据,超快检索 HBase设计为海量数据,快速检索 HBase在大数据领域应用十分广泛,现在我们来在node1、node2、node3上部署H

    2024年02月11日
    浏览(36)
  • HBase的数据库设计模式与实践

    HBase是一个分布式、可扩展、高性能的列式存储系统,基于Google的Bigtable设计。它是Hadoop生态系统的一部分,可以与HDFS、MapReduce、ZooKeeper等组件集成。HBase适用于大规模数据存储和实时数据访问的场景,如日志记录、实时数据分析、实时搜索等。 在现实应用中,HBase的数据库设

    2024年02月20日
    浏览(31)
  • 客户端读写HBase数据库的运行原理

    1.HBase的特点 HBase是一个数据库,与RDMS相比,有以下特点: ① 它不支持SQL ② 不支持事务 ③ 没有表关系,不支持JOIN ④ 有列族,列族下可以有上百个列 ⑤ 单元格,即列值,可以存储多个版本的值,每个版本都有对应时间戳 ⑥ 行键按照字典序升序排列 ⑦ 元数据 和 数据 分

    2024年02月10日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包