apache / apache/incubator-seata

redis updateGlobalTransactionDO unwatch need to be optimized

Open
#4,854 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
26k
Forks
8.8k
Avg merge
1d 8h
Merged PRs (30d)
4

Description

## Why you need it?
Is your feature request related to a problem? Please describe in details
redis模式里的updateGlobalTransactionDO在处理redis事务时使用了watch,但是使用unwatch的写法不统一,有些在抛出异常或者return之前执行了unwatch,有些则没有。需要搞清楚unwatch是不是必须的,然后保持写法一致

## How it could be?
A clear and concise description of what you want to happen. You can explain more about input of the feature, and output of it.
考虑到这个以下2件事

- watch+multi在redis服务端的原理是:watch命令对某个client操作的key打标记,在进行multi.exec命令时会检查同一client同一key是否有标记,有则拒绝整个exec
- jedis client目前的获取写法是twr写法,在抛出异常或者return时会被close掉,他的close实际上是returnResource给pool ,看源码可以看到里面会重置状态,发送unwatch命令
image
image

建议把返回之前的unwatch都去掉,不用引起误解。
如果我们觉得这样改动有风险,也可以统一把unwatch放在finally里面实现,因为update核心逻辑比较复杂,夹杂这个很难维护而且容易遗漏

## Other related information
Add any other context or screenshots about the feature request here.

Contributor guide

Open the contributing guide

Research direction

Start at updateGlobalTransactionDO in the Redis mode and trace every Jedis watch, return, exception, and try-with-resources path. Read how returning a pooled Jedis instance resets state and sends UNWATCH, then determine a consistent cleanup policy and verify that Redis transaction behavior is unchanged across all paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis
Domain
database, distributed-systems
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 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.