HIVE-10620 : ZooKeeperHiveLock overrides equal() method but not hashcode() (Chaoyu Tang, reviewed by Ashutosh)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/61763335 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/61763335 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/61763335 Branch: refs/heads/beeline-cli Commit: 61763335b6a184e4a0ce6dde8a6e3a5d93af4857 Parents: 7149ab1 Author: Szehon Ho <sze...@cloudera.com> Authored: Thu May 7 11:18:13 2015 -0700 Committer: Szehon Ho <sze...@cloudera.com> Committed: Thu May 7 11:18:13 2015 -0700 ---------------------------------------------------------------------- .../ql/lockmgr/zookeeper/ZooKeeperHiveLock.java | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/61763335/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/ZooKeeperHiveLock.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/ZooKeeperHiveLock.java b/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/ZooKeeperHiveLock.java index 8e35007..463a339 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/ZooKeeperHiveLock.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/ZooKeeperHiveLock.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hive.ql.lockmgr.zookeeper; +import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.hadoop.hive.ql.lockmgr.HiveLock; import org.apache.hadoop.hive.ql.lockmgr.HiveLockMode; import org.apache.hadoop.hive.ql.lockmgr.HiveLockObject; @@ -71,4 +72,25 @@ public class ZooKeeperHiveLock extends HiveLock { obj.equals(zLock.getHiveLockObject()) && mode == zLock.getHiveLockMode(); } + + @Override + public int hashCode() { + HashCodeBuilder builder = new HashCodeBuilder(); + boolean pathPresent = path != null; + builder.append(pathPresent); + if (pathPresent) { + builder.append(path.toCharArray()); + } + boolean lockObjectPresent = obj != null; + builder.append(lockObjectPresent); + if (lockObjectPresent) { + builder.append(obj.hashCode()); + } + boolean modePresent = mode != null; + builder.append(modePresent); + if (modePresent) { + builder.append(mode); + } + return builder.toHashCode(); + } }