Skip to content

Commit 37ee18c

Browse files
authored
Merge branch '2.x' into dev-appdata-size-limit
2 parents af0de0b + 4887871 commit 37ee18c

17 files changed

Lines changed: 642 additions & 73 deletions

File tree

changes/en-us/2.0.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ The version is updated as follows:
8383
- [[#5971](https://github.com/seata/seata/pull/5971)] fix some configurations that are not deprecated show "Deprecated"
8484
- [[#5977](https://github.com/seata/seata/pull/5977)] fix that rpcserver is not closed when raftServer is closed
8585
- [[#5954](https://github.com/seata/seata/pull/5954)] fix the issue of saved branch session status does not match the actual branch session status
86+
- [[#5990](https://github.com/seata/seata/pull/5990)] fix the issue that the Lua script is not synchronized when the redis sentinel master node is down
87+
- [[#5887](https://github.com/seata/seata/pull/5887)] fix global transaction hook repeat execute
8688

8789

8890
### optimize:
@@ -172,6 +174,9 @@ The version is updated as follows:
172174
- [[#5863](https://github.com/seata/seata/pull/5863)] fix unit test in java 21
173175
- [[#5986](https://github.com/seata/seata/pull/5986)] fix zookeeper UT failed
174176
- [[#5995](https://github.com/seata/seata/pull/5995)] add test cases for RaftClusterMetadataMsg
177+
- [[#6001](https://github.com/seata/seata/pull/6001)] add test cases for RaftMsgExecute under branch package
178+
- [[#5996](https://github.com/seata/seata/pull/5996)] add test cases for RaftMsgExecute under global package
179+
- [[#6003](https://github.com/seata/seata/pull/6003)] add test cases for RaftMsgExecute under lock package
175180

176181

177182
### Contributors:
@@ -207,6 +212,9 @@ Thanks to these contributors for their code commits. Please report an unintended
207212
- [iquanzhan](https://github.com/iquanzhan)
208213
- [leizhiyuan](https://github.com/leizhiyuan)
209214
- [Aruato](https://github.com/Aruato)
215+
- [ptyin](https://github.com/ptyin)
216+
- [jsbxyyx](https://github.com/jsbxyyx)
217+
210218

211219
Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
212220

changes/zh-cn/2.0.0.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
8282
- [[#5971](https://github.com/seata/seata/pull/5971)] 修复某些未弃用的配置显示"已弃用"
8383
- [[#5977](https://github.com/seata/seata/pull/5977)] 修复当raft server关闭时,rpc server未关闭的问题
8484
- [[#5954](https://github.com/seata/seata/pull/5954)] 修复保存的分支会话状态与实际的分支会话状态不一致的问题
85+
- [[#5990](https://github.com/seata/seata/pull/5990)] 修复redis sentinel master node 宕机时,lua脚本未同步的问题
86+
- [[#5887](https://github.com/seata/seata/pull/5887)] 修复全局事务钩子重复执行
8587

8688

8789
### optimize:
@@ -173,6 +175,10 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
173175
- [[#5863](https://github.com/seata/seata/pull/5863)] 修复单元测试在Java21下无法正常运行的问题。
174176
- [[#5986](https://github.com/seata/seata/pull/5986)] 修复 zookeeper 单测失败问题
175177
- [[#5995](https://github.com/seata/seata/pull/5995)] 添加 RaftClusterMetadataMsg 模块的单元测试用例
178+
- [[#6001](https://github.com/seata/seata/pull/6001)] 添加 RaftMsgExecute 模块 branch 包下的单元测试用例
179+
- [[#5996](https://github.com/seata/seata/pull/5996)] 添加 RaftMsgExecute 模块 global 包下的单元测试用例
180+
- [[#6003](https://github.com/seata/seata/pull/6003)] 添加 RaftMsgExecute 模块 lock 包下的单元测试用例
181+
176182

177183
### Contributors:
178184

@@ -208,6 +214,10 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
208214
- [leizhiyuan](https://github.com/leizhiyuan)
209215
- [Aruato](https://github.com/Aruato)
210216
- [ggbocoder](https://github.com/ggbocoder)
217+
- [ptyin](https://github.com/ptyin)
218+
- [jsbxyyx](https://github.com/jsbxyyx)
219+
220+
211221

212222
同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
213223

saga/seata-saga-engine-store/src/main/java/io/seata/saga/engine/store/db/DbAndReportTcStateLogStore.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ public void recordStateMachineFinished(StateMachineInstance machineInstance, Pro
197197

198198
protected void reportTransactionFinished(StateMachineInstance machineInstance, ProcessContext context) {
199199
if (sagaTransactionalTemplate != null) {
200+
GlobalTransaction globalTransaction = null;
200201
try {
201-
GlobalTransaction globalTransaction = getGlobalTransaction(machineInstance, context);
202+
globalTransaction = getGlobalTransaction(machineInstance, context);
202203
if (globalTransaction == null) {
203204

204205
throw new EngineExecutionException("Global transaction is not exists",
@@ -234,7 +235,7 @@ protected void reportTransactionFinished(StateMachineInstance machineInstance, P
234235
// clear
235236
RootContext.unbind();
236237
RootContext.unbindBranchType();
237-
sagaTransactionalTemplate.triggerAfterCompletion();
238+
sagaTransactionalTemplate.triggerAfterCompletion(globalTransaction);
238239
sagaTransactionalTemplate.cleanUp();
239240
}
240241
}

saga/seata-saga-tm/src/main/java/io/seata/saga/tm/DefaultSagaTransactionalTemplate.java

Lines changed: 64 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.seata.tm.TMClient;
3131
import io.seata.tm.api.GlobalTransaction;
3232
import io.seata.tm.api.GlobalTransactionContext;
33+
import io.seata.tm.api.GlobalTransactionRole;
3334
import io.seata.tm.api.TransactionalExecutor;
3435
import io.seata.tm.api.TransactionalExecutor.ExecutionException;
3536
import io.seata.tm.api.transaction.TransactionHook;
@@ -63,9 +64,9 @@ public class DefaultSagaTransactionalTemplate
6364
@Override
6465
public void commitTransaction(GlobalTransaction tx) throws TransactionalExecutor.ExecutionException {
6566
try {
66-
triggerBeforeCommit();
67+
triggerBeforeCommit(tx);
6768
tx.commit();
68-
triggerAfterCommit();
69+
triggerAfterCommit(tx);
6970
} catch (TransactionException txe) {
7071
// 4.1 Failed to commit
7172
throw new TransactionalExecutor.ExecutionException(tx, txe, TransactionalExecutor.Code.CommitFailure);
@@ -75,19 +76,19 @@ public void commitTransaction(GlobalTransaction tx) throws TransactionalExecutor
7576
@Override
7677
public void rollbackTransaction(GlobalTransaction tx, Throwable ex)
7778
throws TransactionException, TransactionalExecutor.ExecutionException {
78-
triggerBeforeRollback();
79+
triggerBeforeRollback(tx);
7980
tx.rollback();
80-
triggerAfterRollback();
81+
triggerAfterRollback(tx);
8182
// Successfully rolled back
8283
}
8384

8485
@Override
8586
public GlobalTransaction beginTransaction(TransactionInfo txInfo) throws TransactionalExecutor.ExecutionException {
8687
GlobalTransaction tx = GlobalTransactionContext.getCurrentOrCreate();
8788
try {
88-
triggerBeforeBegin();
89+
triggerBeforeBegin(tx);
8990
tx.begin(txInfo.getTimeOut(), txInfo.getName());
90-
triggerAfterBegin();
91+
triggerAfterBegin(tx);
9192
} catch (TransactionException txe) {
9293
throw new TransactionalExecutor.ExecutionException(tx, txe, TransactionalExecutor.Code.BeginFailure);
9394

@@ -105,7 +106,7 @@ public void reportTransaction(GlobalTransaction tx, GlobalStatus globalStatus)
105106
throws TransactionalExecutor.ExecutionException {
106107
try {
107108
tx.globalReport(globalStatus);
108-
triggerAfterCompletion();
109+
triggerAfterCompletion(tx);
109110
} catch (TransactionException txe) {
110111

111112
throw new TransactionalExecutor.ExecutionException(tx, txe, TransactionalExecutor.Code.ReportFailure);
@@ -125,73 +126,87 @@ public void branchReport(String xid, long branchId, BranchStatus status, String
125126
DefaultResourceManager.get().branchReport(BranchType.SAGA, xid, branchId, status, applicationData);
126127
}
127128

128-
protected void triggerBeforeBegin() {
129-
for (TransactionHook hook : getCurrentHooks()) {
130-
try {
131-
hook.beforeBegin();
132-
} catch (Exception e) {
133-
LOGGER.error("Failed execute beforeBegin in hook {}", e.getMessage(), e);
129+
protected void triggerBeforeBegin(GlobalTransaction tx) {
130+
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
131+
for (TransactionHook hook : getCurrentHooks()) {
132+
try {
133+
hook.beforeBegin();
134+
} catch (Exception e) {
135+
LOGGER.error("Failed execute beforeBegin in hook {}", e.getMessage(), e);
136+
}
134137
}
135138
}
136139
}
137140

138-
protected void triggerAfterBegin() {
139-
for (TransactionHook hook : getCurrentHooks()) {
140-
try {
141-
hook.afterBegin();
142-
} catch (Exception e) {
143-
LOGGER.error("Failed execute afterBegin in hook {} ", e.getMessage(), e);
141+
protected void triggerAfterBegin(GlobalTransaction tx) {
142+
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
143+
for (TransactionHook hook : getCurrentHooks()) {
144+
try {
145+
hook.afterBegin();
146+
} catch (Exception e) {
147+
LOGGER.error("Failed execute afterBegin in hook {} ", e.getMessage(), e);
148+
}
144149
}
145150
}
146151
}
147152

148-
protected void triggerBeforeRollback() {
149-
for (TransactionHook hook : getCurrentHooks()) {
150-
try {
151-
hook.beforeRollback();
152-
} catch (Exception e) {
153-
LOGGER.error("Failed execute beforeRollback in hook {} ", e.getMessage(), e);
153+
protected void triggerBeforeRollback(GlobalTransaction tx) {
154+
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
155+
for (TransactionHook hook : getCurrentHooks()) {
156+
try {
157+
hook.beforeRollback();
158+
} catch (Exception e) {
159+
LOGGER.error("Failed execute beforeRollback in hook {} ", e.getMessage(), e);
160+
}
154161
}
155162
}
156163
}
157164

158-
protected void triggerAfterRollback() {
159-
for (TransactionHook hook : getCurrentHooks()) {
160-
try {
161-
hook.afterRollback();
162-
} catch (Exception e) {
163-
LOGGER.error("Failed execute afterRollback in hook {}", e.getMessage(), e);
165+
protected void triggerAfterRollback(GlobalTransaction tx) {
166+
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
167+
for (TransactionHook hook : getCurrentHooks()) {
168+
try {
169+
hook.afterRollback();
170+
} catch (Exception e) {
171+
LOGGER.error("Failed execute afterRollback in hook {}", e.getMessage(), e);
172+
}
164173
}
165174
}
166175
}
167176

168-
protected void triggerBeforeCommit() {
169-
for (TransactionHook hook : getCurrentHooks()) {
170-
try {
171-
hook.beforeCommit();
172-
} catch (Exception e) {
173-
LOGGER.error("Failed execute beforeCommit in hook {}", e.getMessage(), e);
177+
protected void triggerBeforeCommit(GlobalTransaction tx) {
178+
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
179+
for (TransactionHook hook : getCurrentHooks()) {
180+
try {
181+
hook.beforeCommit();
182+
} catch (Exception e) {
183+
LOGGER.error("Failed execute beforeCommit in hook {}", e.getMessage(), e);
184+
}
174185
}
175186
}
176187
}
177188

178-
protected void triggerAfterCommit() {
179-
for (TransactionHook hook : getCurrentHooks()) {
180-
try {
181-
hook.afterCommit();
182-
} catch (Exception e) {
183-
LOGGER.error("Failed execute afterCommit in hook {}", e.getMessage(), e);
189+
protected void triggerAfterCommit(GlobalTransaction tx) {
190+
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
191+
for (TransactionHook hook : getCurrentHooks()) {
192+
try {
193+
hook.afterCommit();
194+
} catch (Exception e) {
195+
LOGGER.error("Failed execute afterCommit in hook {}", e.getMessage(), e);
196+
}
184197
}
185198
}
186199
}
187200

188201
@Override
189-
public void triggerAfterCompletion() {
190-
for (TransactionHook hook : getCurrentHooks()) {
191-
try {
192-
hook.afterCompletion();
193-
} catch (Exception e) {
194-
LOGGER.error("Failed execute afterCompletion in hook {}", e.getMessage(), e);
202+
public void triggerAfterCompletion(GlobalTransaction tx) {
203+
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
204+
for (TransactionHook hook : getCurrentHooks()) {
205+
try {
206+
hook.afterCompletion();
207+
} catch (Exception e) {
208+
LOGGER.error("Failed execute afterCompletion in hook {}", e.getMessage(), e);
209+
}
195210
}
196211
}
197212
}

saga/seata-saga-tm/src/main/java/io/seata/saga/tm/SagaTransactionalTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ long branchRegister(String resourceId, String clientId, String xid, String appli
4848
void branchReport(String xid, long branchId, BranchStatus status, String applicationData)
4949
throws TransactionException;
5050

51-
void triggerAfterCompletion();
51+
void triggerAfterCompletion(GlobalTransaction tx);
5252

5353
void cleanUp();
5454
}

server/src/main/java/io/seata/server/cluster/raft/RaftServerFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public void start() {
160160
@Override
161161
public void destroy() {
162162
this.close();
163+
rpcServer = null;
164+
RAFT_SERVER_MAP.clear();
163165
}
164166

165167
@Override

server/src/main/java/io/seata/server/lock/LockerManagerFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public static void init() {
5252
init(null);
5353
}
5454

55+
public static void destroy() {
56+
LOCK_MANAGER = null;
57+
}
5558

5659
public static void init(LockMode lockMode) {
5760
if (LOCK_MANAGER == null) {

server/src/main/java/io/seata/server/session/SessionHolder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ public static void destroy() {
383383
if (ROOT_SESSION_MANAGER != null) {
384384
ROOT_SESSION_MANAGER.destroy();
385385
}
386+
SESSION_MANAGER_MAP = null;
386387
}
387388

388389
@FunctionalInterface

server/src/main/java/io/seata/server/storage/redis/JedisPooledFactory.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,12 @@ public static JedisPoolAbstract getJedisPoolInstance(JedisPoolAbstract... jedisP
9898
Set<String> sentinels = new HashSet<>(SENTINEL_HOST_NUMBER);
9999
String[] sentinelHosts = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_HOST).split(",");
100100
Arrays.asList(sentinelHosts).forEach(sentinelHost -> sentinels.add(sentinelHost));
101+
String sentinelPassword = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_PASSWORD);
102+
if (StringUtils.isBlank(sentinelPassword)) {
103+
sentinelPassword = null;
104+
}
101105
tempJedisPool = new JedisSentinelPool(masterName, sentinels, poolConfig, 60000, 60000, password, CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_DATABASE, DATABASE),
102-
null, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_PASSWORD), null);
106+
null, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, sentinelPassword, null);
103107
} else if (mode.equals(ConfigurationKeys.REDIS_SINGLE_MODE)) {
104108
String host = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SINGLE_HOST);
105109
host = StringUtils.isBlank(host) ? CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_HOST, HOST) : host;

server/src/main/java/io/seata/server/storage/redis/LuaParser.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.io.InputStreamReader;
2323
import java.io.Serializable;
24+
import java.util.HashMap;
2425
import java.util.List;
2526
import java.util.Map;
2627
import java.util.concurrent.ConcurrentHashMap;
@@ -31,20 +32,26 @@
3132
import com.fasterxml.jackson.core.JsonProcessingException;
3233
import com.fasterxml.jackson.core.type.TypeReference;
3334
import com.fasterxml.jackson.databind.ObjectMapper;
35+
import org.slf4j.Logger;
36+
import org.slf4j.LoggerFactory;
3437
import redis.clients.jedis.Jedis;
3538
import redis.clients.jedis.exceptions.JedisDataException;
39+
import redis.clients.jedis.exceptions.JedisNoScriptException;
3640

3741
/**
3842
* lua related utils
3943
*
4044
* @author conghuhu
4145
*/
4246
public class LuaParser {
47+
private static final Logger LOGGER = LoggerFactory.getLogger(LuaParser.class);
4348

4449
private static final String WHITE_SPACE = " ";
4550

4651
private static final String ANNOTATION_LUA = "--";
4752

53+
private static final Map<String, String> LUA_FILE_MAP = new HashMap<>();
54+
4855
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
4956

5057
public final static class LuaResult implements Serializable {
@@ -123,6 +130,7 @@ public static Map<String, String> getEvalShaMapFromFile(String fileName) throws
123130
} catch (IOException e) {
124131
throw new IOException(e);
125132
}
133+
LUA_FILE_MAP.put(fileName, luaByFile.toString());
126134
Map<String, String> resultMap = new ConcurrentHashMap<>(1);
127135
try (Jedis jedis = JedisPooledFactory.getJedisInstance()) {
128136
resultMap.put(fileName, jedis.scriptLoad(luaByFile.toString()));
@@ -149,4 +157,14 @@ public static <T> List<T> getListFromJson(String json, Class<T> classz) {
149157
throw new StoreException(e.getMessage());
150158
}
151159
}
160+
161+
public static Object jedisEvalSha(Jedis jedis, String luaSHA, String luaFileName, List<String> keys, List<String> args) {
162+
try {
163+
return jedis.evalsha(luaSHA, keys, args);
164+
} catch (JedisNoScriptException e) {
165+
LOGGER.warn("try to reload the lua script and execute,jedis ex: " + e.getMessage());
166+
jedis.scriptLoad(LUA_FILE_MAP.get(luaFileName));
167+
return jedis.evalsha(luaSHA, keys, args);
168+
}
169+
}
152170
}

0 commit comments

Comments
 (0)