【发布时间】:2016-09-02 12:56:43
【问题描述】:
我想删除 HBase 表中的 3 亿行。我可以使用 HBase API 并发送一批 Delete 对象。不过恐怕要花很多时间。
以前的代码就是这种情况,我想插入数百万行。我没有使用 HBase API 并发送一批 Put,而是使用 Map Reduce 作业,它发出 RowKey / Put 作为值并使用HFileOutputFormat2.configureIncrementalLoad(job, table, regionLocator) 设置我的 Reducer,以便它直接写入输出,准备好由@987654322 快速加载@(完成批量加载)。它要快得多(5 分钟而不是 3 小时)。
所以我想对批量删除做同样的事情。
但是,我似乎无法将这种技术与 Delete 一起使用,因为 HFileOutputFormat2 尝试为 KeyValue 或 Put (PutSortReducer) 配置 Reducer,但 Delete 不存在任何内容。
我的第一个问题是为什么没有“DeleteSortReducer”来为 Delete 启用完整的批量加载技术?它只是缺少一些东西,还没有完成吗?还是有更深层次的理由证明这一点?
第二个问题,有点相关:如果我复制/粘贴 PutSortReducer 的代码,将其修改为 Delete 并将其作为我工作的 Reducer 传递,它会起作用吗? HBase 完整的批量加载会产生充满墓碑的 HFile 吗?
例子:
public class DeleteSortReducer extends
Reducer<ImmutableBytesWritable, Delete, ImmutableBytesWritable, KeyValue> {
@Override
protected void reduce(
ImmutableBytesWritable row,
java.lang.Iterable<Delete> deletes,
Reducer<ImmutableBytesWritable, Delete,
ImmutableBytesWritable, KeyValue>.Context context)
throws java.io.IOException, InterruptedException
{
// although reduce() is called per-row, handle pathological case
long threshold = context.getConfiguration().getLong(
"putsortreducer.row.threshold", 1L * (1<<30));
Iterator<Delete> iter = deletes.iterator();
while (iter.hasNext()) {
TreeSet<KeyValue> map = new TreeSet<KeyValue>(KeyValue.COMPARATOR);
long curSize = 0;
// stop at the end or the RAM threshold
while (iter.hasNext() && curSize < threshold) {
Delete d = iter.next();
for (List<Cell> cells: d.getFamilyCellMap().values()) {
for (Cell cell: cells) {
KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
map.add(kv);
curSize += kv.heapSize();
}
}
}
context.setStatus("Read " + map.size() + " entries of " + map.getClass()
+ "(" + StringUtils.humanReadableInt(curSize) + ")");
int index = 0;
for (KeyValue kv : map) {
context.write(row, kv);
if (++index % 100 == 0)
context.setStatus("Wrote " + index);
}
// if we have more entries to process
if (iter.hasNext()) {
// force flush because we cannot guarantee intra-row sorted order
context.write(null, null);
}
}
}
}
【问题讨论】:
-
你从上面的程序有什么发现?您是否尝试过/找到其他方法?如果是的话,它们是什么
标签: hbase