tx-lcn
tx-lcn copied to clipboard
关于5.0.2版本未修复bug临时解决方案
TC集群环境下,分布式事务回调用,会路由到非发起方机器上去
TM端
同样采用替换源码的方式,复制出源码到同包名(自己新建)下
-
com.codingapi.txlcn.tm.txmsg.transaction.JoinGroupExecuteService.java
把rpcClient.getAppName改成rpcClient.getModId
transactionManager.join(dtxContext, joinGroupParams.getUnitId(), joinGroupParams.getUnitType(),
rpcClient.getModId(transactionCmd.getRemoteKey()), joinGroupParams.getTransactionState());
-
com.codingapi.txlcn.txmsg.netty.impl.NettyRpcClient.java
及com.codingapi.txlcn.txmsg.RpcClient.java
添加方法
@Override
public String getModId(String remoteKey) {
return SocketManager.getInstance().getModuleId(remoteKey);
}
-
com.codingapi.txlcn.txmsg.netty.bean.SocketManager.java
- 添加方法
/**
* 获取模块的唯一ID
*
* @param remoteKey 远程唯一标识
* @return 模块名称
*/
public String getModuleId(String remoteKey) {
AppInfo appInfo = appNames.get(remoteKey);
return appInfo == null ? null : appInfo.getLabelName();
}
- 修改remoteKeys(5.0.2源码里面是removeKeys,估计是单词错误直接注释掉),根据modId取remoteKeys
/**
* 获取模块的远程标识keys
*
* @param modId 模块唯一识别Id
* @return remoteKeys
*/
public List<String> remoteKeys(String modId) {
List<String> allKeys = new ArrayList<>();
for (Channel channel : channels) {
if (modId.equals(getModuleIdFromChannel(channel))) {
allKeys.add(channel.remoteAddress().toString());
}
}
return allKeys;
}
- 新增getModuleIdFromChannel
/**
* 获取模块名称
*
* @param channel 管道信息
* @return 模块名称
*/
public String getModuleIdFromChannel(Channel channel) {
String key = channel.remoteAddress().toString();
return getModuleId(key);
}
TC端
在TC端,implement ModIdProvider确保每个tc都有唯一识别id即可。
@Component
public class MyModIdProvider implements ModIdProvider {
@Override
public String modId(){
InetAddress address = null;
try {
address = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return address.getHostAddress() + ":" + this.serverPort;
}
}
“不支持hystrix 线程池隔离问题” 这个是如何测试出来的呢
“不支持hystrix 线程池隔离问题” 这个是如何测试出来的呢
嗯,这个表述的好像不太严谨,我使用的场景需要共享rquest线程变量,已去除。
按照你的方法问题已解决,感谢
同服务多实例原来事务百分百失效 按这个改完后 有概率成功了 但是 还是有一半概率失败 不知道什么原因,所有服务都是单实例 成功率是百分百