关于5.0.2版本未修复bug临时解决方案
- Lingua principale
- Java
- Stelle
- 4.2k
- Fork
- 1.4k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
## TC集群环境下,分布式事务回调用,会路由到非发起方机器上去
[参考](https://github.com/codingapi/tx-lcn/issues/296)
### 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());
```
2. `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);
}
```
3. `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();
}
```
2) 修改remoteKeys(5.0.2源码里面是removeKeys,估计是单词错误直接注释掉),根据modId取remoteKeys
```
/**
* 获取模块的远程标识keys
*
* @param modId 模块唯一识别Id
* @return remoteKeys
*/
public List remoteKeys(String modId) {
List allKeys = new ArrayList<>();
for (Channel channel : channels) {
if (modId.equals(getModuleIdFromChannel(channel))) {
allKeys.add(channel.remoteAddress().toString());
}
}
return allKeys;
}
```
3) 新增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;
}
}
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Start with com.codingapi.txlcn.tm.txmsg.transaction.JoinGroupExecuteService.java and trace how NettyRpcClient, RpcClient, and SocketManager resolve module and remote IDs. Verify the routing behavior in a TC cluster, including ModIdProvider uniqueness, and confirm distributed transaction callbacks return to the initiating machine without the source replacement workaround.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- backend, distributed-systems
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100