mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Use fnv.New32a() in hash instead adler32
This commit is contained in:
parent
a57967f47b
commit
3bdc3f25ec
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"hash/adler32"
|
"hash/fnv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/golang/groupcache/lru"
|
"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,
|
// 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.
|
// they will have the same key.
|
||||||
func keyFunc(obj objectWithMeta) uint64 {
|
func keyFunc(obj objectWithMeta) uint64 {
|
||||||
hash := adler32.New()
|
hash := fnv.New32a()
|
||||||
hashutil.DeepHashObject(hash, &equivalenceLabelObj{
|
hashutil.DeepHashObject(hash, &equivalenceLabelObj{
|
||||||
namespace: obj.GetNamespace(),
|
namespace: obj.GetNamespace(),
|
||||||
labels: obj.GetLabels(),
|
labels: obj.GetLabels(),
|
||||||
|
@ -21,7 +21,7 @@ package mount
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/adler32"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -282,7 +282,7 @@ func readProcMounts(mountFilePath string, out *[]MountPoint) (uint32, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readProcMountsFrom(file io.Reader, out *[]MountPoint) (uint32, error) {
|
func readProcMountsFrom(file io.Reader, out *[]MountPoint) (uint32, error) {
|
||||||
hash := adler32.New()
|
hash := fnv.New32a()
|
||||||
scanner := bufio.NewReader(file)
|
scanner := bufio.NewReader(file)
|
||||||
for {
|
for {
|
||||||
line, err := scanner.ReadString('\n')
|
line, err := scanner.ReadString('\n')
|
||||||
|
@ -29,20 +29,21 @@ func TestReadProcMountsFrom(t *testing.T) {
|
|||||||
/dev/1 /path/to/1 type1 flags 1 1
|
/dev/1 /path/to/1 type1 flags 1 1
|
||||||
/dev/2 /path/to/2 type2 flags,1,2=3 2 2
|
/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)
|
hash, err := readProcMountsFrom(strings.NewReader(successCase), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success")
|
t.Errorf("expected success")
|
||||||
}
|
}
|
||||||
if hash != 0xa3522051 {
|
if hash != 0xa290ff0b {
|
||||||
t.Errorf("expected 0xa3522051, got %#x", hash)
|
t.Errorf("expected 0xa290ff0b, got %#x", hash)
|
||||||
}
|
}
|
||||||
mounts := []MountPoint{}
|
mounts := []MountPoint{}
|
||||||
hash, err = readProcMountsFrom(strings.NewReader(successCase), &mounts)
|
hash, err = readProcMountsFrom(strings.NewReader(successCase), &mounts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success")
|
t.Errorf("expected success")
|
||||||
}
|
}
|
||||||
if hash != 0xa3522051 {
|
if hash != 0xa290ff0b {
|
||||||
t.Errorf("expected 0xa3522051, got %#x", hash)
|
t.Errorf("expected 0xa290ff0b, got %#x", hash)
|
||||||
}
|
}
|
||||||
if len(mounts) != 3 {
|
if len(mounts) != 3 {
|
||||||
t.Fatalf("expected 3 mounts, got %d", len(mounts))
|
t.Fatalf("expected 3 mounts, got %d", len(mounts))
|
||||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"hash/adler32"
|
"hash/fnv"
|
||||||
|
|
||||||
"github.com/golang/groupcache/lru"
|
"github.com/golang/groupcache/lru"
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ func (ec *EquivalenceCache) SendClearAllCacheReq() {
|
|||||||
// hashEquivalencePod returns the hash of equivalence pod.
|
// hashEquivalencePod returns the hash of equivalence pod.
|
||||||
func (ec *EquivalenceCache) hashEquivalencePod(pod *v1.Pod) uint64 {
|
func (ec *EquivalenceCache) hashEquivalencePod(pod *v1.Pod) uint64 {
|
||||||
equivalencePod := ec.getEquivalencePod(pod)
|
equivalencePod := ec.getEquivalencePod(pod)
|
||||||
hash := adler32.New()
|
hash := fnv.New32a()
|
||||||
hashutil.DeepHashObject(hash, equivalencePod)
|
hashutil.DeepHashObject(hash, equivalencePod)
|
||||||
return uint64(hash.Sum32())
|
return uint64(hash.Sum32())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user