codingapi / codingapi/tx-lcn

事务没有回滚,TM报redis异常

Open
#445 14 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
4.2k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

- [x] I have searched the [issues](https://github.com/codingapi/tx-lcn/issues) of this repository and believe that this is not a duplicate.

### 1. Bug Description
只要出发分布式事务,TM就报redis异常:
![image](https://user-images.githubusercontent.com/17718166/66646067-abca9100-ec57-11e9-9948-38a4aaf83e31.png)

我的TM配置:
```
spring:
profiles:
active: dev
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/tx-manager?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username: admin
password: 123456
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.ddl-auto: update
redis:
password:
timeout: 10000ms
cluster:
max-redirects: 3 # 获取失败 最大重定向次数
nodes:
- 127.0.0.1:6380
- 127.0.0.1:6381
- 127.0.0.1:6382
lettuce:
pool:
max-active: 1000 #连接池最大连接数(使用负值表示没有限制)
max-idle: 20 # 连接池中的最大空闲连接
min-idle: 5 # 连接池中的最小空闲连接
max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
tx-lcn:
logger:
enabled: true
driver-class-name: com.mysql.jdbc.Driver
jdbc-url: jdbc:mysql://127.0.0.1:3306/tx-manager?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username: admin
password: 123456
manager:
admin-key: admin
port: 9119
dtx-time: 60000
heart-time: 5000
```
### 2. Environment:
- JDK version: 1.8
- OS: win10
- TX-LCN version: last
- Others:

### 3. Exception Stacktrace

```
org.springframework.data.redis.RedisSystemException: Unknown redis exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy141 cannot be cast to io.lettuce.core.api.sync.RedisCommands
at org.springframework.data.redis.FallbackExceptionTranslationStrategy.getFallback(FallbackExceptionTranslationStrategy.java:53)
at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:43)
at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:268)
at org.springframework.data.redis.connection.lettuce.LettuceConnection.discard(LettuceConnection.java:623)
at org.springframework.data.redis.connection.DefaultStringRedisConnection.discard(DefaultStringRedisConnection.java:273)
at org.springframework.data.redis.core.RedisTemplate.lambda$discard$22(RedisTemplate.java:1019)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
at org.springframework.data.redis.core.RedisTemplate.discard(RedisTemplate.java:1018)
at com.codingapi.txlcn.tm.core.storage.redis.RedisStorage.refreshMachines(RedisStorage.java:269)
at com.codingapi.txlcn.tm.support.service.impl.ManagerServiceImpl.refreshMachines(ManagerServiceImpl.java:86)
at com.codingapi.txlcn.tm.txmsg.EnsureIdGenEngine.onTmReceivedHeart(EnsureIdGenEngine.java:61)
at com.codingapi.txlcn.txmsg.netty.handler.RpcCmdDecoder.channelRead0(RpcCmdDecoder.java:61)
at com.codingapi.txlcn.txmsg.netty.handler.RpcCmdDecoder.channelRead0(RpcCmdDecoder.java:40)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:337)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:337)
at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:337)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:337)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1408)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:930)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:677)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:612)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:529)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:491)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy141 cannot be cast to io.lettuce.core.api.sync.RedisCommands
at org.springframework.data.redis.connection.lettuce.LettuceConnection.getDedicatedRedisCommands(LettuceConnection.java:946)
at org.springframework.data.redis.connection.lettuce.LettuceConnection.discard(LettuceConnection.java:621)
... 39 more
```

### 4. Tour Idea

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in com.codingapi.txlcn.tm.core.storage.redis.RedisStorage.refreshMachines at line 269, then trace the call through ManagerServiceImpl.refreshMachines and EnsureIdGenEngine.onTmReceivedHeart. Reproduce the failure with the provided Redis cluster configuration and inspect the Lettuce discard stack trace. Done means the ClassCastException no longer occurs during heartbeat handling and the distributed transaction rollback completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis, spring
Domain
backend, databases, distributed-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.