tx-lcn icon indicating copy to clipboard operation
tx-lcn copied to clipboard

关于5.0.2版本未修复bug临时解决方案

Open LemonCoo1 opened this issue 5 years ago • 4 comments

TC集群环境下,分布式事务回调用,会路由到非发起方机器上去

参考

TM端

同样采用替换源码的方式,复制出源码到同包名(自己新建)下

  1. 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());
  1. com.codingapi.txlcn.txmsg.netty.impl.NettyRpcClient.javacom.codingapi.txlcn.txmsg.RpcClient.java

添加方法

    @Override
    public String getModId(String remoteKey) {
        return SocketManager.getInstance().getModuleId(remoteKey);
    }
  1. com.codingapi.txlcn.txmsg.netty.bean.SocketManager.java
  1. 添加方法
    /**
     * 获取模块的唯一ID
     *
     * @param remoteKey 远程唯一标识
     * @return 模块名称
     */
    public String getModuleId(String remoteKey) {
        AppInfo appInfo = appNames.get(remoteKey);
        return appInfo == null ? null : appInfo.getLabelName();
    }

  1. 修改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;
    }

  1. 新增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;
    }

}

LemonCoo1 avatar Oct 31 '19 06:10 LemonCoo1

“不支持hystrix 线程池隔离问题” 这个是如何测试出来的呢

yizhishang avatar Nov 01 '19 06:11 yizhishang

“不支持hystrix 线程池隔离问题” 这个是如何测试出来的呢

嗯,这个表述的好像不太严谨,我使用的场景需要共享rquest线程变量,已去除。

LemonCoo1 avatar Nov 01 '19 06:11 LemonCoo1

按照你的方法问题已解决,感谢

zsfx avatar Nov 27 '19 12:11 zsfx

同服务多实例原来事务百分百失效 按这个改完后 有概率成功了 但是 还是有一半概率失败 不知道什么原因,所有服务都是单实例 成功率是百分百

qry521 avatar Aug 06 '20 07:08 qry521