Hbase auto increment any column/row-key

2019-03-02 06:15发布

问题:

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