Change ConsistentMap key hasher to use sha256
Change-Id: Ia83322cc314b178dd438a4c7a05e7ab3bac4ad3d
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/FederatedDistributedPrimitiveCreator.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/FederatedDistributedPrimitiveCreator.java
index 22a59d7..212c150 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/FederatedDistributedPrimitiveCreator.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/FederatedDistributedPrimitiveCreator.java
@@ -20,7 +20,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import org.onlab.util.HexString;
import org.onosproject.cluster.PartitionId;
@@ -66,9 +65,8 @@
Map<PartitionId, AsyncConsistentMap<String, byte[]>> maps =
Maps.transformValues(members,
partition -> partition.newAsyncConsistentMap(name, null));
- HashFunction hashFunction = Hashing.goodFastHash(32);
Hasher<String> hasher = key -> {
- int hashCode = hashFunction.hashUnencodedChars(key).asInt();
+ int hashCode = Hashing.sha256().hashString(key, Charsets.UTF_8).asInt();
return sortedMemberPartitionIds.get(Math.abs(hashCode) % members.size());
};
AsyncConsistentMap<String, byte[]> partitionedMap = new PartitionedAsyncConsistentMap<>(name, maps, hasher);
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/TransactionManager.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/TransactionManager.java
index 223cfec..803c1c7 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/TransactionManager.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/TransactionManager.java
@@ -23,12 +23,14 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
+import com.google.common.base.Charsets;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.hash.Hashing;
import com.google.common.util.concurrent.Futures;
+import org.onlab.util.HexString;
import org.onosproject.cluster.PartitionId;
import org.onosproject.store.primitives.MapUpdate;
import org.onosproject.store.primitives.PartitionService;
@@ -101,7 +103,8 @@
}
Hasher<K> hasher = key -> {
- int hashCode = Hashing.sha256().hashBytes(serializer.encode(key)).asInt();
+ int hashCode = Hashing.sha256()
+ .hashString(HexString.toHexString(serializer.encode(key)), Charsets.UTF_8).asInt();
return sortedPartitions.get(Math.abs(hashCode) % sortedPartitions.size());
};
return new PartitionedTransactionalMap<>(partitions, hasher);