Skip to content

Commit

Permalink
KYLIN-3597, fix the critical bug reported by sonar: Make sure this ex…
Browse files Browse the repository at this point in the history
…pression can't be zero before doing this division.
  • Loading branch information
Aaaaaaron authored and shaofengshi committed Nov 12, 2018
1 parent 91a1b31 commit f0b26c4
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public RefinedKetamaNodeLocator(List<MemcachedNode> nodes, HashAlgorithm alg, Ke
* continuum
* @param alg The hash algorithm to use when choosing a node in the Ketama
* consistent hash continuum
* @param weights node weights for ketama, a map from InetSocketAddress to
* @param nodeWeights node weights for ketama, a map from InetSocketAddress to
* weight as Integer
* @param configuration node locator configuration
*/
Expand Down Expand Up @@ -233,7 +233,7 @@ protected void setKetamaNodes(List<MemcachedNode> nodes) {
if (isWeightedKetama) {

int thisWeight = weights.get(node.getSocketAddress());
float percent = (float) thisWeight / (float) totalWeight;
float percent = (totalWeight == 0 ? 0f : (float) thisWeight / (float) totalWeight);
int pointerPerServer = (int) ((Math.floor(
(float) (percent * (float) config.getNodeRepetitions() / 4 * (float) nodeCount + 0.0000000001)))
* 4);
Expand Down

0 comments on commit f0b26c4

Please sign in to comment.