【发布时间】:2017-11-16 12:40:39
【问题描述】:
我正在尝试使用BulkLoad 在HBase 中加载数据。我也在使用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)
需要这方面的帮助。
【问题讨论】:
-
你的行键是连续的吗?当您将具有顺序键的记录写入 Hbase 时,HBase 仅命中一个 Region。此行为特定于 HBase,与使用 Spark 无关。查看这篇文章:sematext.com/blog/2012/04/09/…
-
我正在保存密钥,例如 001_16062017105407、002_16062017105455、003_16062017105505 和升序。
标签: scala apache-spark hbase hadoop2