File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package labeler
1717import (
1818 "context"
1919 "fmt"
20+ "hash/maphash"
2021 "log/slog"
2122 "regexp"
2223 "strings"
@@ -64,8 +65,9 @@ const (
6465)
6566
6667var (
67- dcgm4Regex = regexp .MustCompile (`.*dcgm:4\..*` )
68- dcgm3Regex = regexp .MustCompile (`.*dcgm:3\..*` )
68+ dcgm4Regex = regexp .MustCompile (`.*dcgm:4\..*` )
69+ dcgm3Regex = regexp .MustCompile (`.*dcgm:3\..*` )
70+ nodeLockHashSeed = maphash .MakeSeed ()
6971)
7072
7173// Labeler manages node labeling based on pod information
@@ -840,13 +842,8 @@ func (l *Labeler) updateNodeLabels(nodeName string) error {
840842}
841843
842844func (l * Labeler ) withNodeLock (nodeName string , fn func () error ) error {
843- hash := uint32 (2166136261 )
844- for idx := range len (nodeName ) {
845- hash ^= uint32 (nodeName [idx ])
846- hash *= 16777619
847- }
848-
849- mutex := & l .nodeLocks [hash % uint32 (len (l .nodeLocks ))]
845+ hash := maphash .String (nodeLockHashSeed , nodeName )
846+ mutex := & l .nodeLocks [hash % uint64 (len (l .nodeLocks ))]
850847
851848 mutex .Lock ()
852849 defer mutex .Unlock ()
You can’t perform that action at this time.
0 commit comments