You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by pt...@apache.org on 2016/01/20 23:15:43 UTC

[41/46] storm git commit: Merge branch 'STORM-1481' of https://github.com/vesense/storm into STORM-1481

Merge branch 'STORM-1481' of https://github.com/vesense/storm into STORM-1481

STORM-1481: avoid Math.abs(Integer) get a negative value


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/4fb83d92
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/4fb83d92
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/4fb83d92

Branch: refs/heads/master
Commit: 4fb83d926c9cfcdf0abad667cfd7390b1f56f654
Parents: e29b146
Author: Robert (Bobby) Evans <ev...@yahoo-inc.com>
Authored: Wed Jan 20 13:57:55 2016 -0600
Committer: Robert (Bobby) Evans <ev...@yahoo-inc.com>
Committed: Wed Jan 20 13:59:18 2016 -0600

----------------------------------------------------------------------
 .../storm/trident/partition/IndexHashGrouping.java     |  8 +++++---
 storm-core/src/jvm/org/apache/storm/utils/Utils.java   | 13 +++++++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/4fb83d92/storm-core/src/jvm/org/apache/storm/trident/partition/IndexHashGrouping.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/org/apache/storm/trident/partition/IndexHashGrouping.java b/storm-core/src/jvm/org/apache/storm/trident/partition/IndexHashGrouping.java
index 223006f..25c3a1a 100644
--- a/storm-core/src/jvm/org/apache/storm/trident/partition/IndexHashGrouping.java
+++ b/storm-core/src/jvm/org/apache/storm/trident/partition/IndexHashGrouping.java
@@ -20,15 +20,17 @@ package org.apache.storm.trident.partition;
 import org.apache.storm.generated.GlobalStreamId;
 import org.apache.storm.grouping.CustomStreamGrouping;
 import org.apache.storm.task.WorkerTopologyContext;
+import org.apache.storm.utils.Utils;
+
 import java.util.Arrays;
 import java.util.List;
 
 public class IndexHashGrouping implements CustomStreamGrouping {
     public static int objectToIndex(Object val, int numPartitions) {
-        if(val==null) return 0;
-        else {
-            return Math.abs(val.hashCode()) % numPartitions;
+        if(val == null) {
+            return 0;
         }
+        return Utils.toPositive(val.hashCode()) % numPartitions;
     }
     
     int _index;

http://git-wip-us.apache.org/repos/asf/storm/blob/4fb83d92/storm-core/src/jvm/org/apache/storm/utils/Utils.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/org/apache/storm/utils/Utils.java b/storm-core/src/jvm/org/apache/storm/utils/Utils.java
index 3605b7a..9d0c7c6 100644
--- a/storm-core/src/jvm/org/apache/storm/utils/Utils.java
+++ b/storm-core/src/jvm/org/apache/storm/utils/Utils.java
@@ -1369,5 +1369,18 @@ public class Utils {
         }
         return topologyInfo;
     }
+
+    /**
+     * A cheap way to deterministically convert a number to a positive value. When the input is
+     * positive, the original value is returned. When the input number is negative, the returned
+     * positive value is the original value bit AND against Integer.MAX_VALUE(0x7fffffff) which
+     * is not its absolutely value.
+     *
+     * @param number a given number
+     * @return a positive number.
+     */
+    public static int toPositive(int number) {
+        return number & Integer.MAX_VALUE;
+    }
 }