Hbase auto increment any column/row-key

自闭症网瘾萝莉.ら 提交于 2019-12-18 09:28:19

问题


I am new to 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)

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


回答1:


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.

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

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.

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



来源:https://stackoverflow.com/questions/26890944/hbase-auto-increment-any-column-row-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!