Hi, I have implemented an auto increment feature/tool and would like your comments (or criticism) on how it could be improved. Before going into the details I would like to give pointers to the implementation -
Maven project - http://github.com/imyousuf/smart-dao/tree/hbase/smart-hbase/hbase-auto-long-rowid-incrementor/ [branch: hbase] To build will need - http://github.com/imyousuf/smart-core [parent POM] The main implementation - http://github.com/imyousuf/smart-dao/blob/hbase/smart-hbase/hbase-auto-long-rowid-incrementor/src/main/java/com/smartitengineering/dao/hbase/autoincrement/AutoIncrementLongRowIdGenerator.java Test - http://github.com/imyousuf/smart-dao/blob/hbase/smart-hbase/hbase-auto-long-rowid-incrementor/src/test/java/com/smartitengineering/dao/hbase/autoincrement/AutoIncrementRowIdForLongTest.java Now a little more details. Its a web service implementation over HTTP (not a proper REST API) and the hypothesis of the implementation is that all new primary keys for the intended tables will be generated through this web service. Now the web service fetches guesses next row id in sequence, fetches lock to ensures no-one is using it and returns it to client. The idea is the client uses the row id and lock id to make the next insertion. The rows are inserted in inverse order that is greatest (Long.MAX_VALUE - 1) first and smallest last as suggested by Ryan. We use the smallest which is a top of a scan and store it for future use and decrement it as we progress. To ensure uniqueness we are using MutableLong and it is synchronized within the duration of the change. To test for concurrency from test are running 100 X 30 requests just to do a simulation of whether the servlet holds up or not. From the tests it seems to hold up, but I will feel more confident with some suggestions/comments/criticism from you. Waiting eagerly for some feedback. Thank you, -- Imran M Yousuf Twitter: @imyousuf - http://twitter.com/imyousuf Blog: http://imyousuf-tech.blogs.smartitengineering.com/ Mobile: +880-1711402557
