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

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

问题描述

我是Hbase的新用户

I am new to Hbase

是否可以/如何在Hbase中自动递增row-key? (像每次插入row-key必须是自动增量本身)

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.

如果可以避免使用auto-增量ID,并且在分布式系统中只需要具有唯一的ID,可以使用类似hostname+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天全站免登陆