A pit of distributed shard selection

The front-end time is used to select shards, and the hash value of String is used to take the remainder. It is found that the hash value has a negative number, and it is immediately changed to Math.abs(value.hashCode())% unit. I looked at the source code of Math.abs today and found that when the comment says Integer.minValue, the absolute value will overflow. Tried it, and sure enough it returned the same negative number. I have to encapsulate another layer by myself. When the value is equal to Integer.minValue, it returns 0 directly. The unit test passes.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326877111&siteId=291194637