3

Hibernate HiLo algorithm is very well explained in this post - What's the Hi/Lo algorithm?

But I am not clear with how does it guarantee ID uniqueness for clustered application.

For example, if Hi number is 35 and if two clients try to increment the Hi number at the same time, what is the Hi number that each of the client would get?

Community
  • 1
  • 1
Daddy
  • 61
  • 2
  • I think the high number is incremeted atomically or with a lock (i.e. slow but safe). This is not a problem since it is seldomly done. The low numbers then are all lockfree for the new client with its unique high number. – eckes Oct 05 '14 at 05:03
  • The database sequence, used by all the cluster nodes, is where Hibernate gets the next *hi* value. It guarantees uniqueness and atomicity. Using hi/lo is simply a way to avoid going to the database sequence for each new ID you need, but only once every 50 (or so) new ID. – JB Nizet Oct 05 '14 at 06:55

0 Answers0