hbase在单个表的多个区域中批量加载

7lrncoxx  于 2021-06-08  发布在  Hbase
关注(0)|答案(1)|浏览(322)

我正在尝试加载数据 HBase 使用 BulkLoad . 我也在使用 Scala 以及 Spark 编写代码。但每次数据只加载到一个区域。我需要把它加载到多个区域。我使用了以下代码-
hbase配置:

def getConf: Configuration = {
    val hbaseSitePath = "/etc/hbase/conf/hbase-site.xml"
    val conf = HBaseConfiguration.create()
    conf.addResource(new Path(hbaseSitePath))
    conf.setInt("hbase.mapreduce.bulkload.max.hfiles.perRegion.perFamily", 100)
    conf   
}

使用上述配置,我只能在一个区域中加载80gb的数据。
但是当我尝试在多个区域中加载相同数量的数据时,出现了下面提到的配置异常
java.io.ioexception:尝试将32个以上的hfiles加载到一个区域的一个族中
已更新配置-

def getConf: Configuration = {

  val conf = HBaseConfiguration.create()
  conf.addResource(new Path(hbaseSitePath))
  conf.setInt("hbase.mapreduce.bulkload.max.hfiles.perRegion.perFamily", 32)

  conf.setLong("hbase.hregion.max.filesize", 107374182)
  conf.set("hbase.regionserver.region.split.policy","org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy")
  conf
}

为了保存记录,我使用以下代码-

val kv = new KeyValue(Bytes.toBytes(key), columnFamily.getBytes(),
        columnName.getBytes(), columnValue.getBytes())

      (new ImmutableBytesWritable(Bytes.toBytes(key)), kv)

rdd.saveAsNewAPIHadoopFile(pathToHFile, classOf[ImmutableBytesWritable], classOf[KeyValue],
      classOf[HFileOutputFormat2], conf) //Here rdd is the input

    val loadFiles = new LoadIncrementalHFiles(conf)
    loadFiles.doBulkLoad(new Path(pathToHFile), hTable)

我需要帮助。

gywdnpxw

gywdnpxw1#

因为32是每个区域的默认值,所以出现了问题。你应该定义 KeyPrefixRegionSplitPolicy 分割你的文件,你可以增加 hbase.mapreduce.bulkload.max.hfiles.perRegion.perFamily 如下所示

conf.setInt("hbase.mapreduce.bulkload.max.hfiles.perRegion.perFamily", 1024)

还可以根据需要增加文件大小

conf.setLong("hbase.hregion.max.filesize", 107374182)

相关问题