javasnowflake icon indicating copy to clipboard operation
javasnowflake copied to clipboard

Negative ids

Open pparth opened this issue 10 years ago • 2 comments

Hello,

Using the latest version, i still get negative Ids from some hosts. I use Amazon-deployed hosts; is this a problem for the algorithm?

pparth avatar Jul 24 '13 07:07 pparth

For example, for 2 hosts, and for generating Ids within 10 secs, i get: 1225682100845207552 from the one and -7277113995538210816 from the other

pparth avatar Jul 24 '13 07:07 pparth

This issue occurs cause datacenterId resides in the most significant part of generated Id. Java long type stores sign in the most significant bit. So if dataCenterId will be > 512 we will have negative values in Java.
Fixed in https://github.com/Predictor/javasnowflake/pull/2

akhitev avatar Sep 13 '13 10:09 akhitev