Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CacheInstanceForRedo、CacheInstancesForRedo 等方法 key 粒度太大 #780

Open
ijustyce opened this issue Oct 14, 2024 · 0 comments
Open

Comments

@ijustyce
Copy link
Contributor

考虑类似 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

@ijustyce ijustyce changed the title CacheInstanceForRedo、CacheInstancesForRedo 等 4 个方法 key 粒度太大 CacheInstanceForRedo、CacheInstancesForRedo 等方法 key 粒度太大 Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant