Skip to content

Commit

Permalink
feat: add client version for MakeSchedulersKeyForPeerInManager (#3711)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Dec 17, 2024
1 parent 5511c07 commit a370da1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion manager/rpcserver/manager_server_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func (s *managerServerV1) ListSchedulers(ctx context.Context, req *managerv1.Lis

// Cache hit.
var pbListSchedulersResponse managerv1.ListSchedulersResponse
cacheKey := pkgredis.MakeSchedulersKeyForPeerInManager(req.Hostname, req.Ip)
cacheKey := pkgredis.MakeSchedulersKeyForPeerInManager(req.Hostname, req.Ip, req.Version)

if err := s.cache.Get(ctx, cacheKey, &pbListSchedulersResponse); err != nil {
log.Warnf("%s cache miss because of %s", cacheKey, err.Error())
Expand Down
2 changes: 1 addition & 1 deletion manager/rpcserver/manager_server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func (s *managerServerV2) ListSchedulers(ctx context.Context, req *managerv2.Lis

// Cache hit.
var pbListSchedulersResponse managerv2.ListSchedulersResponse
cacheKey := pkgredis.MakeSchedulersKeyForPeerInManager(req.Hostname, req.Ip)
cacheKey := pkgredis.MakeSchedulersKeyForPeerInManager(req.Hostname, req.Ip, req.Version)

if err := s.cache.Get(ctx, cacheKey, &pbListSchedulersResponse); err != nil {
log.Warnf("%s cache miss because of %s", cacheKey, err.Error())
Expand Down
4 changes: 2 additions & 2 deletions pkg/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func MakeSeedPeersKeyForPeerInManager(hostname, ip string) string {
}

// MakeSchedulersKeyForPeerInManager make schedulers key for peer in manager.
func MakeSchedulersKeyForPeerInManager(hostname, ip string) string {
return MakeKeyInManager(PeersNamespace, fmt.Sprintf("%s-%s:schedulers", hostname, ip))
func MakeSchedulersKeyForPeerInManager(hostname, ip, version string) string {
return MakeKeyInManager(PeersNamespace, fmt.Sprintf("%s-%s-%s:schedulers", hostname, ip, version))
}

// MakeSchedulerClusterKeyInManager make distributed rate limiter key in manager.
Expand Down
27 changes: 21 additions & 6 deletions pkg/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,48 +352,63 @@ func Test_MakeSchedulersKeyForPeerInManager(t *testing.T) {
name string
hostname string
ip string
version string
expect func(t *testing.T, s string)
}{
{
name: "make scheduler key for peer in manager",
hostname: "bar",
ip: "127.0.0.1",
version: "0.1.0",
expect: func(t *testing.T, s string) {
assert := assert.New(t)
assert.Equal(s, "manager:peers:bar-127.0.0.1:schedulers")
assert.Equal(s, "manager:peers:bar-127.0.0.1-0.1.0:schedulers")
},
},
{
name: "hostname is empty",
hostname: "",
ip: "127.0.0.1",
version: "0.1.0",
expect: func(t *testing.T, s string) {
assert := assert.New(t)
assert.Equal(s, "manager:peers:-127.0.0.1:schedulers")
assert.Equal(s, "manager:peers:-127.0.0.1-0.1.0:schedulers")
},
},
{
name: "ip is empty",
hostname: "bar",
ip: "",
version: "0.1.0",
expect: func(t *testing.T, s string) {
assert := assert.New(t)
assert.Equal(s, "manager:peers:bar-:schedulers")
assert.Equal(s, "manager:peers:bar--0.1.0:schedulers")
},
},
{
name: "hostname and ip are empty",
name: "version is empty",
hostname: "bar",
ip: "127.0.0.1",
version: "",
expect: func(t *testing.T, s string) {
assert := assert.New(t)
assert.Equal(s, "manager:peers:bar-127.0.0.1-:schedulers")
},
},
{
name: "hostname, ip and version are empty",
hostname: "",
ip: "",
version: "",
expect: func(t *testing.T, s string) {
assert := assert.New(t)
assert.Equal(s, "manager:peers:-:schedulers")
assert.Equal(s, "manager:peers:--:schedulers")
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
tc.expect(t, MakeSchedulersKeyForPeerInManager(tc.hostname, tc.ip))
tc.expect(t, MakeSchedulersKeyForPeerInManager(tc.hostname, tc.ip, tc.version))
})
}
}
Expand Down

0 comments on commit a370da1

Please sign in to comment.