Hbase - pre-partitioning techniques

You can use two lines of code to get the pre-partition design Hbase, we have not found a table in the new time, actually do the pre-partition to be calculated, if not the write tools that can be miserable, needs its own count with the fingers , and in this to provide you with a decimal hexadecimal version, based on the number Region to the average range, you can use as a tool class.

9028759-a347afda2d847ab8.png
Big Data Hbase doing tricks pre-partition

Instructions

scala version

/**
    * Hbase 预分区转换
    * @param region Hbase regionServer 的节点数
    * @param radix 进制 10 | 16
    * @param start 开始 => 比如:00
    * @param end 结束 => 比如:ff
    * @return Array
    */
  def getSplitForRadix(region: Int, radix: Int, start: String, end: String): Array[String] = {
    val range = start.toInt to java.lang.Long.valueOf(end, radix).toInt
    range
      .filter(_ % (range.size / region) == 0)
      .map(if (radix == 16) Integer.toHexString else _.toString)
      .tail //Hbase 左闭右开
      .toArray
  }

java version

public static List<String> getSplitForRadix(int region, int radix, String start, String end) {
        Integer s = Integer.parseInt(start);
        Integer e = Long.valueOf(end, radix).intValue() + 1;
        return IntStream
                .range(s, e)
                .filter(value -> (value % ((e - s) / region)) == 0)
                .mapToObj(value -> {
                    if (radix == 16) {
                        return Integer.toHexString(value);
                    } else {
                        return String.valueOf(value);
                    }
                })
                .skip(1)
                .collect(Collectors.toList());
    }

Use Case

I have eight RegionServer, want to pre-decimal partitioning

val region = 8
val radix = 10
val start = "00"
val end = "99"

println(getSplitForRadix(region, radix, start, end).mkString(","))

Generating the following results

12,24,36,48,60,72,84,96

If the pre-partition hexadecimal

val region = 8
val radix = 16
val start = "00"
val end = "ff"

println(getSplits(region, radix, start, end).mkString(","))

Generating the following results

20,40,60,80,a0,c0,e0

PS: I believe you will not pick my fault codes on it, ha ha


9028759-07315bb8dadcd082.png

Guess you like

Origin blog.csdn.net/weixin_34293141/article/details/90840036