diff --git a/manager/rpcserver/manager_server_v1.go b/manager/rpcserver/manager_server_v1.go index 5efffd5e8d4..27991cb3571 100644 --- a/manager/rpcserver/manager_server_v1.go +++ b/manager/rpcserver/manager_server_v1.go @@ -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()) diff --git a/manager/rpcserver/manager_server_v2.go b/manager/rpcserver/manager_server_v2.go index bcf8ec69e31..9de5ce882ac 100644 --- a/manager/rpcserver/manager_server_v2.go +++ b/manager/rpcserver/manager_server_v2.go @@ -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()) diff --git a/pkg/redis/redis.go b/pkg/redis/redis.go index 4780c729785..b16fa546b2a 100644 --- a/pkg/redis/redis.go +++ b/pkg/redis/redis.go @@ -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. diff --git a/pkg/redis/redis_test.go b/pkg/redis/redis_test.go index 8c31ed8206e..5bd21835ad6 100644 --- a/pkg/redis/redis_test.go +++ b/pkg/redis/redis_test.go @@ -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)) }) } }