codingapi / codingapi/tx-lcn

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

Offen
#454 4 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
4.2k
Forks
1.4k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

## 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;
}

}
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginne mit com.codingapi.txlcn.tm.txmsg.transaction.JoinGroupExecuteService.java und verfolge, wie NettyRpcClient, RpcClient und SocketManager Modul- und Remote-IDs auflösen. Überprüfe das Routing-Verhalten in einem TC-Cluster, einschließlich der Eindeutigkeit von ModIdProvider, und bestätige, dass Callbacks verteilter Transaktionen zur initiierenden Maschine zurückkehren, ohne den Workaround zum Ersetzen der Quelle.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
backend, distributed-systems
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.