nacos-sdk-go
nacos-sdk-go copied to clipboard
CacheInstanceForRedo、CacheInstancesForRedo 等方法 key 粒度太大
考虑类似 nacos-sync 同步服务的场景,client 注册到 server 的 instances ip 可能不止一个且 ip 也各不相同,此时,这个 redo 逻辑就是错误的,粒度太大, 没考虑 cluster 以及 ip、端口号
func (c *ConnectionEventListener) CacheInstanceForRedo(serviceName, groupName string, instance model.Instance) {
key := util.GetGroupName(serviceName, groupName)
c.registeredInstanceCached.Set(key, instance)
}
func (c *ConnectionEventListener) CacheInstancesForRedo(serviceName, groupName string, instances []model.Instance) {
key := util.GetGroupName(serviceName, groupName)
c.registeredInstanceCached.Set(key, instances)
}
func (c *ConnectionEventListener) RemoveInstanceForRedo(serviceName, groupName string, instance model.Instance) {
key := util.GetGroupName(serviceName, groupName)
_, ok := c.registeredInstanceCached.Get(key)
if !ok {
return
}
c.registeredInstanceCached.Remove(key)
}
func (c *ConnectionEventListener) CacheSubscriberForRedo(fullServiceName, clusters string) {
key := util.GetServiceCacheKey(fullServiceName, clusters)
if !c.IsSubscriberCached(key) {
c.subscribes.Set(key, struct{}{})
}
}
建议至少将 CacheInstanceForRedo、CacheInstancesForRedo 的 key 改为:groupName@@serviceName@@cluster@@ip:port