Skip to content

Commit dae6438

Browse files
committed
use maphash for hashing node names
Signed-off-by: Ajay Mishra <ajmishra@nvidia.com>
1 parent f09297e commit dae6438

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

labeler/pkg/labeler/labeler.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package labeler
1717
import (
1818
"context"
1919
"fmt"
20+
"hash/maphash"
2021
"log/slog"
2122
"regexp"
2223
"strings"
@@ -64,8 +65,9 @@ const (
6465
)
6566

6667
var (
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

842844
func (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()

0 commit comments

Comments
 (0)