sunshineallaround commented on issue #6127: URL: https://github.com/apache/incubator-seata/issues/6127#issuecomment-3269155557
1. 我项目里面使用的是1.7.0版本,也是遇到No available service问题,是在发起分布式事务请求的时候出现的,即是TM向TC注册全局事务,然后报的错误。 通过看源码:List<InetSocketAddress> inetSocketAddressList = RegistryFactory.getInstance().aliveLookup(transactionServiceGroup); 这行代码是去获取可用的seata-server服务列表,进入内部 return CURRENT_ADDRESS_MAP.computeIfAbsent(transactionServiceGroup, k -> new ArrayList<>());是直接从缓存中拿服务列表,如果服务列表为空,那么就会报No available service。 2. 然后我通过启动项目debug,seata-client启动的时候会有一个List<InetSocketAddress> lookup(String key) throws Exception;方法获取seata-server服务,如果服务为空则会返回一个空的集合,CLUSTER_ADDRESS_MAP这个缓存里面会缓存默认的default为key,value为new ArrayList();项目是可以正常启动的。我理解这里正常启动也可以,不能完全说是问题,起码没有在调用没有分布式事务的接口,业务可以正常走的通的。 当然没有可用的seata-server服务,无非是有三个原因:1. seata-client优先于seata-server启动;2. seata-server注册到nacos失败;3. 网络原因导致项目启动会获取失败。 虽然有一个异步线程可以去重新去nacos上面获取seata-server,但是NacosRegistryServiceImpl的lookup(String key)里面171行有一行代码if (!LISTENER_SERVICE_MAP.containsKey(clusterName))判断缓存里面是否包含当前集群名称,如果已经包含了,默 认是从缓存里面拿,但是前面也说到了,缓存里面是一个空的List,即使后面 seata-server启动成功并且注册到nacos上面,但是即使不停的重试都是拿不到seata-server的服务信息,因为重试都是一直去缓存中拿的空集合。除非是重启seata-client才行。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
