Skip to content

Commit

Permalink
Merge branch '2.x' into dev-appdata-size-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
funky-eyes authored Nov 7, 2023
2 parents af0de0b + 4887871 commit 37ee18c
Show file tree
Hide file tree
Showing 17 changed files with 642 additions and 73 deletions.
8 changes: 8 additions & 0 deletions changes/en-us/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ The version is updated as follows:
- [[#5971](https://github.com/seata/seata/pull/5971)] fix some configurations that are not deprecated show "Deprecated"
- [[#5977](https://github.com/seata/seata/pull/5977)] fix that rpcserver is not closed when raftServer is closed
- [[#5954](https://github.com/seata/seata/pull/5954)] fix the issue of saved branch session status does not match the actual branch session status
- [[#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
- [[#5887](https://github.com/seata/seata/pull/5887)] fix global transaction hook repeat execute


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


### Contributors:
Expand Down Expand Up @@ -207,6 +212,9 @@ Thanks to these contributors for their code commits. Please report an unintended
- [iquanzhan](https://github.com/iquanzhan)
- [leizhiyuan](https://github.com/leizhiyuan)
- [Aruato](https://github.com/Aruato)
- [ptyin](https://github.com/ptyin)
- [jsbxyyx](https://github.com/jsbxyyx)


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

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


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


### Contributors:

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



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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ public void recordStateMachineFinished(StateMachineInstance machineInstance, Pro

protected void reportTransactionFinished(StateMachineInstance machineInstance, ProcessContext context) {
if (sagaTransactionalTemplate != null) {
GlobalTransaction globalTransaction = null;
try {
GlobalTransaction globalTransaction = getGlobalTransaction(machineInstance, context);
globalTransaction = getGlobalTransaction(machineInstance, context);
if (globalTransaction == null) {

throw new EngineExecutionException("Global transaction is not exists",
Expand Down Expand Up @@ -234,7 +235,7 @@ protected void reportTransactionFinished(StateMachineInstance machineInstance, P
// clear
RootContext.unbind();
RootContext.unbindBranchType();
sagaTransactionalTemplate.triggerAfterCompletion();
sagaTransactionalTemplate.triggerAfterCompletion(globalTransaction);
sagaTransactionalTemplate.cleanUp();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.seata.tm.TMClient;
import io.seata.tm.api.GlobalTransaction;
import io.seata.tm.api.GlobalTransactionContext;
import io.seata.tm.api.GlobalTransactionRole;
import io.seata.tm.api.TransactionalExecutor;
import io.seata.tm.api.TransactionalExecutor.ExecutionException;
import io.seata.tm.api.transaction.TransactionHook;
Expand Down Expand Up @@ -63,9 +64,9 @@ public class DefaultSagaTransactionalTemplate
@Override
public void commitTransaction(GlobalTransaction tx) throws TransactionalExecutor.ExecutionException {
try {
triggerBeforeCommit();
triggerBeforeCommit(tx);
tx.commit();
triggerAfterCommit();
triggerAfterCommit(tx);
} catch (TransactionException txe) {
// 4.1 Failed to commit
throw new TransactionalExecutor.ExecutionException(tx, txe, TransactionalExecutor.Code.CommitFailure);
Expand All @@ -75,19 +76,19 @@ public void commitTransaction(GlobalTransaction tx) throws TransactionalExecutor
@Override
public void rollbackTransaction(GlobalTransaction tx, Throwable ex)
throws TransactionException, TransactionalExecutor.ExecutionException {
triggerBeforeRollback();
triggerBeforeRollback(tx);
tx.rollback();
triggerAfterRollback();
triggerAfterRollback(tx);
// Successfully rolled back
}

@Override
public GlobalTransaction beginTransaction(TransactionInfo txInfo) throws TransactionalExecutor.ExecutionException {
GlobalTransaction tx = GlobalTransactionContext.getCurrentOrCreate();
try {
triggerBeforeBegin();
triggerBeforeBegin(tx);
tx.begin(txInfo.getTimeOut(), txInfo.getName());
triggerAfterBegin();
triggerAfterBegin(tx);
} catch (TransactionException txe) {
throw new TransactionalExecutor.ExecutionException(tx, txe, TransactionalExecutor.Code.BeginFailure);

Expand All @@ -105,7 +106,7 @@ public void reportTransaction(GlobalTransaction tx, GlobalStatus globalStatus)
throws TransactionalExecutor.ExecutionException {
try {
tx.globalReport(globalStatus);
triggerAfterCompletion();
triggerAfterCompletion(tx);
} catch (TransactionException txe) {

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

protected void triggerBeforeBegin() {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.beforeBegin();
} catch (Exception e) {
LOGGER.error("Failed execute beforeBegin in hook {}", e.getMessage(), e);
protected void triggerBeforeBegin(GlobalTransaction tx) {
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.beforeBegin();
} catch (Exception e) {
LOGGER.error("Failed execute beforeBegin in hook {}", e.getMessage(), e);
}
}
}
}

protected void triggerAfterBegin() {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.afterBegin();
} catch (Exception e) {
LOGGER.error("Failed execute afterBegin in hook {} ", e.getMessage(), e);
protected void triggerAfterBegin(GlobalTransaction tx) {
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.afterBegin();
} catch (Exception e) {
LOGGER.error("Failed execute afterBegin in hook {} ", e.getMessage(), e);
}
}
}
}

protected void triggerBeforeRollback() {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.beforeRollback();
} catch (Exception e) {
LOGGER.error("Failed execute beforeRollback in hook {} ", e.getMessage(), e);
protected void triggerBeforeRollback(GlobalTransaction tx) {
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.beforeRollback();
} catch (Exception e) {
LOGGER.error("Failed execute beforeRollback in hook {} ", e.getMessage(), e);
}
}
}
}

protected void triggerAfterRollback() {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.afterRollback();
} catch (Exception e) {
LOGGER.error("Failed execute afterRollback in hook {}", e.getMessage(), e);
protected void triggerAfterRollback(GlobalTransaction tx) {
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.afterRollback();
} catch (Exception e) {
LOGGER.error("Failed execute afterRollback in hook {}", e.getMessage(), e);
}
}
}
}

protected void triggerBeforeCommit() {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.beforeCommit();
} catch (Exception e) {
LOGGER.error("Failed execute beforeCommit in hook {}", e.getMessage(), e);
protected void triggerBeforeCommit(GlobalTransaction tx) {
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.beforeCommit();
} catch (Exception e) {
LOGGER.error("Failed execute beforeCommit in hook {}", e.getMessage(), e);
}
}
}
}

protected void triggerAfterCommit() {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.afterCommit();
} catch (Exception e) {
LOGGER.error("Failed execute afterCommit in hook {}", e.getMessage(), e);
protected void triggerAfterCommit(GlobalTransaction tx) {
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.afterCommit();
} catch (Exception e) {
LOGGER.error("Failed execute afterCommit in hook {}", e.getMessage(), e);
}
}
}
}

@Override
public void triggerAfterCompletion() {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.afterCompletion();
} catch (Exception e) {
LOGGER.error("Failed execute afterCompletion in hook {}", e.getMessage(), e);
public void triggerAfterCompletion(GlobalTransaction tx) {
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Launcher) {
for (TransactionHook hook : getCurrentHooks()) {
try {
hook.afterCompletion();
} catch (Exception e) {
LOGGER.error("Failed execute afterCompletion in hook {}", e.getMessage(), e);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ long branchRegister(String resourceId, String clientId, String xid, String appli
void branchReport(String xid, long branchId, BranchStatus status, String applicationData)
throws TransactionException;

void triggerAfterCompletion();
void triggerAfterCompletion(GlobalTransaction tx);

void cleanUp();
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public void start() {
@Override
public void destroy() {
this.close();
rpcServer = null;
RAFT_SERVER_MAP.clear();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public static void init() {
init(null);
}

public static void destroy() {
LOCK_MANAGER = null;
}

public static void init(LockMode lockMode) {
if (LOCK_MANAGER == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ public static void destroy() {
if (ROOT_SESSION_MANAGER != null) {
ROOT_SESSION_MANAGER.destroy();
}
SESSION_MANAGER_MAP = null;
}

@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ public static JedisPoolAbstract getJedisPoolInstance(JedisPoolAbstract... jedisP
Set<String> sentinels = new HashSet<>(SENTINEL_HOST_NUMBER);
String[] sentinelHosts = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_HOST).split(",");
Arrays.asList(sentinelHosts).forEach(sentinelHost -> sentinels.add(sentinelHost));
String sentinelPassword = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_PASSWORD);
if (StringUtils.isBlank(sentinelPassword)) {
sentinelPassword = null;
}
tempJedisPool = new JedisSentinelPool(masterName, sentinels, poolConfig, 60000, 60000, password, CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_DATABASE, DATABASE),
null, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_PASSWORD), null);
null, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, sentinelPassword, null);
} else if (mode.equals(ConfigurationKeys.REDIS_SINGLE_MODE)) {
String host = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SINGLE_HOST);
host = StringUtils.isBlank(host) ? CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_HOST, HOST) : host;
Expand Down
18 changes: 18 additions & 0 deletions server/src/main/java/io/seata/server/storage/redis/LuaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -31,20 +32,26 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisNoScriptException;

/**
* lua related utils
*
* @author conghuhu
*/
public class LuaParser {
private static final Logger LOGGER = LoggerFactory.getLogger(LuaParser.class);

private static final String WHITE_SPACE = " ";

private static final String ANNOTATION_LUA = "--";

private static final Map<String, String> LUA_FILE_MAP = new HashMap<>();

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

public final static class LuaResult implements Serializable {
Expand Down Expand Up @@ -123,6 +130,7 @@ public static Map<String, String> getEvalShaMapFromFile(String fileName) throws
} catch (IOException e) {
throw new IOException(e);
}
LUA_FILE_MAP.put(fileName, luaByFile.toString());
Map<String, String> resultMap = new ConcurrentHashMap<>(1);
try (Jedis jedis = JedisPooledFactory.getJedisInstance()) {
resultMap.put(fileName, jedis.scriptLoad(luaByFile.toString()));
Expand All @@ -149,4 +157,14 @@ public static <T> List<T> getListFromJson(String json, Class<T> classz) {
throw new StoreException(e.getMessage());
}
}

public static Object jedisEvalSha(Jedis jedis, String luaSHA, String luaFileName, List<String> keys, List<String> args) {
try {
return jedis.evalsha(luaSHA, keys, args);
} catch (JedisNoScriptException e) {
LOGGER.warn("try to reload the lua script and execute,jedis ex: " + e.getMessage());
jedis.scriptLoad(LUA_FILE_MAP.get(luaFileName));
return jedis.evalsha(luaSHA, keys, args);
}
}
}
Loading

0 comments on commit 37ee18c

Please sign in to comment.