From 3bdc3f25ecc969c039946e1abebe593c7e65ff92 Mon Sep 17 00:00:00 2001 From: Harry Zhang Date: Mon, 23 Jan 2017 22:31:50 +0800 Subject: [PATCH] Use fnv.New32a() in hash instead adler32 --- pkg/controller/lookup_cache.go | 4 ++-- pkg/util/mount/mount_linux.go | 4 ++-- pkg/util/mount/mount_linux_test.go | 9 +++++---- plugin/pkg/scheduler/core/equivalence_cache.go | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/controller/lookup_cache.go b/pkg/controller/lookup_cache.go index 2f7ea89951..160aa6e086 100644 --- a/pkg/controller/lookup_cache.go +++ b/pkg/controller/lookup_cache.go @@ -17,7 +17,7 @@ limitations under the License. package controller import ( - "hash/adler32" + "hash/fnv" "sync" "github.com/golang/groupcache/lru" @@ -33,7 +33,7 @@ type objectWithMeta interface { // Since we match objects by namespace and Labels/Selector, so if two objects have the same namespace and labels, // they will have the same key. func keyFunc(obj objectWithMeta) uint64 { - hash := adler32.New() + hash := fnv.New32a() hashutil.DeepHashObject(hash, &equivalenceLabelObj{ namespace: obj.GetNamespace(), labels: obj.GetLabels(), diff --git a/pkg/util/mount/mount_linux.go b/pkg/util/mount/mount_linux.go index 69f756d1ca..b8b2a623ee 100644 --- a/pkg/util/mount/mount_linux.go +++ b/pkg/util/mount/mount_linux.go @@ -21,7 +21,7 @@ package mount import ( "bufio" "fmt" - "hash/adler32" + "hash/fnv" "io" "os" "os/exec" @@ -282,7 +282,7 @@ func readProcMounts(mountFilePath string, out *[]MountPoint) (uint32, error) { } func readProcMountsFrom(file io.Reader, out *[]MountPoint) (uint32, error) { - hash := adler32.New() + hash := fnv.New32a() scanner := bufio.NewReader(file) for { line, err := scanner.ReadString('\n') diff --git a/pkg/util/mount/mount_linux_test.go b/pkg/util/mount/mount_linux_test.go index 19cdb0ba22..e13cb7a0f9 100644 --- a/pkg/util/mount/mount_linux_test.go +++ b/pkg/util/mount/mount_linux_test.go @@ -29,20 +29,21 @@ func TestReadProcMountsFrom(t *testing.T) { /dev/1 /path/to/1 type1 flags 1 1 /dev/2 /path/to/2 type2 flags,1,2=3 2 2 ` + // NOTE: readProcMountsFrom has been updated to using fnv.New32a() hash, err := readProcMountsFrom(strings.NewReader(successCase), nil) if err != nil { t.Errorf("expected success") } - if hash != 0xa3522051 { - t.Errorf("expected 0xa3522051, got %#x", hash) + if hash != 0xa290ff0b { + t.Errorf("expected 0xa290ff0b, got %#x", hash) } mounts := []MountPoint{} hash, err = readProcMountsFrom(strings.NewReader(successCase), &mounts) if err != nil { t.Errorf("expected success") } - if hash != 0xa3522051 { - t.Errorf("expected 0xa3522051, got %#x", hash) + if hash != 0xa290ff0b { + t.Errorf("expected 0xa290ff0b, got %#x", hash) } if len(mounts) != 3 { t.Fatalf("expected 3 mounts, got %d", len(mounts)) diff --git a/plugin/pkg/scheduler/core/equivalence_cache.go b/plugin/pkg/scheduler/core/equivalence_cache.go index 7ea337bf84..7e4ebfd660 100644 --- a/plugin/pkg/scheduler/core/equivalence_cache.go +++ b/plugin/pkg/scheduler/core/equivalence_cache.go @@ -17,7 +17,7 @@ limitations under the License. package core import ( - "hash/adler32" + "hash/fnv" "github.com/golang/groupcache/lru" @@ -128,7 +128,7 @@ func (ec *EquivalenceCache) SendClearAllCacheReq() { // hashEquivalencePod returns the hash of equivalence pod. func (ec *EquivalenceCache) hashEquivalencePod(pod *v1.Pod) uint64 { equivalencePod := ec.getEquivalencePod(pod) - hash := adler32.New() + hash := fnv.New32a() hashutil.DeepHashObject(hash, equivalencePod) return uint64(hash.Sum32()) }