Hbase 自动增加任何列/行键 [英] Hbase auto increment any column/row-key

查看:44
本文介绍了Hbase 自动增加任何列/行键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Hbase 的新手

I am new to Hbase

是否可以/如何在 Hbase 中自动增加行键?(就像每个插入行键必须是自动递增本身)

is it possible to/how can I auto increment row-key in Hbase? (like for each insert row-key has to be auto increment itself)

或者是否可以自动增加任何其他列?(例如对于每个插入,此列必须自动递增 1)

or is it possible to auto-increment any other column ? (like for each insert this column has to be auto-increment by 1)

推荐答案

HBase 不推荐单增行键,参考:http://hbase.apache.org/book/rowkey.design.html,第 6.3.2 页.实际上,使用全局排序的行键会导致您的分布式应用程序的所有实例都写入同一个区域,这将成为瓶颈.

Monolitically increasing row keys are not recommended in HBase, see this for reference: http://hbase.apache.org/book/rowkey.design.html, p.6.3.2. In fact, using globally ordered row keys would cause all instances of your distributed application write to the same region, which will become a bottleneck.

如果您可以避免使用自动递增 ID 并且在分布式系统中只需要唯一的 ID,您可以使用诸如主机名"+PID"+TIMESTAMP"之类的东西作为键.这样每一行都是唯一的

If you can avoid using auto-increment IDs and need to have just unique IDs in a distributed system, you can use something like "hostname" + "PID" + "TIMESTAMP" as a key. This way it would be unique for each row

如果您确定在表中需要全局自动增量(它可以是列中的键或某些值),您可以使用 incrementColumnValue 调用 - 有表中的一个单独行(或为此创建一个专用表)将存储实际值,并且该过程将在插入新行之前调用 incrementColumnValue 以获取下一个值.但是这样你不能保证不会有间隙:如果客户端在调用 incrementColumnValue 后失败,你可能会增加计数器但不会插入行.

If you are sure you need a global autoincrement in a table (it can be a key or some value from the column), you can use incrementColumnValue call - have a separate row in your table (or create a dedicated table for this) that would store the actual value, and the process will call incrementColumnValue before inserting new row to get the next value. But this way you cannot guarantee that there would be no gaps: if the client will fail after calling the incrementColumnValue, you might get the counter incremented but the row won't be inserted.

简而言之,所有提出的解决方案都是客户端的,HBase 中没有针对此功能的服务器端实现

In short, all of the proposed solutions are client-side, there is no server-side implementation for this feature in HBase

这篇关于Hbase 自动增加任何列/行键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆