typeClass() {
+ return Multiset.class;
+ }
+}
diff --git a/txlcn-common/src/test/java/com/codingapi/txlcn/common/util/id/IdTest.java b/txlcn-common/src/test/java/com/codingapi/txlcn/common/util/id/IdTest.java
new file mode 100644
index 000000000..fa8aec0fb
--- /dev/null
+++ b/txlcn-common/src/test/java/com/codingapi/txlcn/common/util/id/IdTest.java
@@ -0,0 +1,24 @@
+package com.codingapi.txlcn.common.util.id;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Description:
+ * Date: 19-2-22 下午3:35
+ *
+ * @author ujued
+ */
+@RunWith(JUnit4.class)
+public class IdTest {
+
+ @Test
+ public void testDefaultIdGen() {
+ IdGenInit.applyDefaultIdGen(12, 1);
+
+ for (int i = 0; i < 10; i++) {
+ System.out.println(RandomUtils.randomKey());
+ }
+ }
+}
diff --git a/txlcn-logger/pom.xml b/txlcn-logger/pom.xml
index abc479cde..0fc2b90ae 100644
--- a/txlcn-logger/pom.xml
+++ b/txlcn-logger/pom.xml
@@ -5,7 +5,7 @@
tx-lcn
com.codingapi.txlcn
- 5.0.1.RELEASE
+ 5.0.2.RELEASE
4.0.0
diff --git a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/AbstractTxLogger.java b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/AbstractTxLogger.java
index acb780458..103972c0d 100644
--- a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/AbstractTxLogger.java
+++ b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/AbstractTxLogger.java
@@ -15,13 +15,17 @@
*/
package com.codingapi.txlcn.logger;
+import com.codingapi.txlcn.common.util.SpringUtils;
import com.codingapi.txlcn.common.util.Transactions;
+import com.codingapi.txlcn.logger.db.LogDbProperties;
import com.codingapi.txlcn.logger.db.TxLog;
-import lombok.extern.slf4j.Slf4j;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -31,17 +35,42 @@
*
* @author ujued
*/
-@Slf4j
public abstract class AbstractTxLogger implements TxLogger {
- private ExecutorService loggerSaveService;
+ private final ExecutorService loggerSaveService;
- public AbstractTxLogger() {
+ private final Logger LOG;
+
+ private LogDbProperties logDbProperties;
+
+ public AbstractTxLogger(Class> className) {
this.loggerSaveService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+ this.LOG = LoggerFactory.getLogger(className);
}
@Override
public void trace(String groupId, String unitId, String tag, String content, Object... args) {
+ if (Objects.isNull(logDbProperties)) {
+ logDbProperties = SpringUtils.getBean(LogDbProperties.class);
+ }
+ if (logDbProperties.isEnabled() && !logDbProperties.isOnlyError()) {
+ saveTxLog(groupId, unitId, tag, content, args);
+ }
+ LOG.debug(content + " @group(" + groupId + ")", args);
+ }
+
+ @Override
+ public void error(String groupId, String unitId, String tag, String content, Object... args) {
+ if (Objects.isNull(logDbProperties)) {
+ logDbProperties = SpringUtils.getBean(LogDbProperties.class);
+ }
+ if (logDbProperties.isEnabled() && logDbProperties.isOnlyError()) {
+ saveTxLog(groupId, unitId, tag, content, args);
+ }
+ LOG.error(content + " @group(" + groupId + ")", args);
+ }
+
+ private void saveTxLog(String groupId, String unitId, String tag, String content, Object... args) {
TxLog txLog = new TxLog();
txLog.setContent(content);
txLog.setArgs(args);
@@ -50,9 +79,8 @@ public void trace(String groupId, String unitId, String tag, String content, Obj
txLog.setUnitId(StringUtils.isEmpty(unitId) ? "" : unitId);
txLog.setAppName(Transactions.APPLICATION_ID_WHEN_RUNNING);
txLog.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(new Date()));
- log.debug("{}: " + content, tag, args);
- this.loggerSaveService.execute(() -> saveTrace(txLog));
+ this.loggerSaveService.execute(() -> saveLog(txLog));
}
- public abstract void saveTrace(TxLog txLog);
+ public abstract void saveLog(TxLog txLog);
}
diff --git a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/DefaultTxLogger.java b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/DefaultTxLogger.java
index 28ea61820..54f1991e7 100644
--- a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/DefaultTxLogger.java
+++ b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/DefaultTxLogger.java
@@ -15,10 +15,13 @@
*/
package com.codingapi.txlcn.logger;
+import com.codingapi.txlcn.common.util.SpringUtils;
import com.codingapi.txlcn.logger.db.TxLog;
import com.codingapi.txlcn.logger.helper.TxLcnLogDbHelper;
import lombok.extern.slf4j.Slf4j;
+import java.util.Objects;
+
/**
* Description:
* Company: CodingApi
@@ -29,15 +32,28 @@
@Slf4j
public class DefaultTxLogger extends AbstractTxLogger {
- private final TxLcnLogDbHelper txLcnLogDbHelper;
+ private TxLcnLogDbHelper txLcnLogDbHelper;
- public DefaultTxLogger(TxLcnLogDbHelper txLcnLogDbHelper) {
- this.txLcnLogDbHelper = txLcnLogDbHelper;
+ private boolean needAware = true;
+
+ public DefaultTxLogger(Class> className) {
+ super(className);
}
+ public void setTxLcnLogDbHelper(TxLcnLogDbHelper txLcnLogDbHelper) {
+ this.txLcnLogDbHelper = txLcnLogDbHelper;
+ }
@Override
- public void saveTrace(TxLog txLog) {
- txLcnLogDbHelper.insert(txLog);
+ public void saveLog(TxLog txLog) {
+ if (needAware && Objects.isNull(txLcnLogDbHelper)) {
+ txLcnLogDbHelper = SpringUtils.getBean(TxLcnLogDbHelper.class);
+ needAware = false;
+ }
+ if (Objects.nonNull(txLcnLogDbHelper)) {
+ txLcnLogDbHelper.insert(txLog);
+ return;
+ }
+ log.warn("tx-logger db configure fail.");
}
}
diff --git a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/Slf4jTxLogger.java b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/Slf4jTxLogger.java
deleted file mode 100644
index 57d6513ea..000000000
--- a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/Slf4jTxLogger.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2017-2019 CodingApi .
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.codingapi.txlcn.logger;
-
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * 不开启日志输出的时候 空操作
- *
- * @author meetzy
- */
-@Slf4j
-public class Slf4jTxLogger implements TxLogger {
-
- @Override
- public void trace(String groupId, String unitId, String tag, String content, Object... args) {
- log.debug("{}: " + content, tag, args);
- }
-
- @Override
- public void info(String groupId, String unitId, String tag, String content, Object... args) {
- log.debug("{}: " + content, tag, args);
- }
-
- @Override
- public void error(String groupId, String unitId, String tag, String content, Object... args) {
- log.error("{}: " + content, tag, args);
- }
-}
diff --git a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/TxLogger.java b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/TxLogger.java
index c0b4c744f..bd6373147 100644
--- a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/TxLogger.java
+++ b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/TxLogger.java
@@ -26,6 +26,10 @@
*/
public interface TxLogger {
+ static TxLogger newLogger(Class> type) {
+ return new DefaultTxLogger(type);
+ }
+
/**
* trace log
*
@@ -33,45 +37,37 @@ public interface TxLogger {
* @param unitId unitId
* @param tag tag
* @param content content
- * @param args args
+ * @param args args
*/
void trace(String groupId, String unitId, String tag, String content, Object... args);
/**
- * 事务消息
+ * 事务日志
*
* @param groupId groupId
* @param unitId unitId
* @param content content
* @param args args
*/
- default void transactionInfo(String groupId, String unitId, String content, Object... args) {
- info(groupId, unitId, Transactions.TAG_TRANSACTION, content, args);
- }
-
- default void taskInfo(String groupId, String unitId, String content, Object... args) {
- info(groupId, unitId, Transactions.TAG_TASK, content, args);
+ default void txTrace(String groupId, String unitId, String content, Object... args) {
+ trace(groupId, unitId, Transactions.TAG_TRANSACTION, content, args);
}
/**
- * info log. todo
+ * 任务日志
*
* @param groupId groupId
* @param unitId unitId
- * @param tag tag
* @param content content
- * @param args args
+ * @param args args
*/
- default void info(String groupId, String unitId, String tag, String content, Object... args) {
- trace(groupId, unitId, tag, content, args);
+ default void taskTrace(String groupId, String unitId, String content, Object... args) {
+ trace(groupId, unitId, Transactions.TAG_TASK, content, args);
}
- default void error(String groupId, String unitId, String tag, String content, Object... args) {
- trace(groupId, unitId, tag, content, args);
- }
+ void error(String groupId, String unitId, String tag, String content, Object... args);
default void error(String tag, String content, Object... args) {
- error("", "", tag, content, args);
+ error("non", "non", tag, content, args);
}
-
}
diff --git a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/TxLoggerConfiguration.java b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/TxLoggerConfiguration.java
index 7421c7430..f908867f7 100644
--- a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/TxLoggerConfiguration.java
+++ b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/TxLoggerConfiguration.java
@@ -15,6 +15,7 @@
*/
package com.codingapi.txlcn.logger;
+import com.codingapi.txlcn.common.util.SpringUtils;
import com.codingapi.txlcn.logger.db.LogDbHelper;
import com.codingapi.txlcn.logger.db.LogDbProperties;
import com.codingapi.txlcn.logger.exception.TxLoggerException;
@@ -41,28 +42,20 @@ public class TxLoggerConfiguration {
@ConditionalOnProperty(name = "tx-lcn.logger.enabled", havingValue = "true")
class LoggerEnabledTrueConfig {
- @Bean
- @ConditionalOnMissingBean
- public TxLogger txLogger(TxLcnLogDbHelper txlcnLogDbHelper) {
- return new DefaultTxLogger(txlcnLogDbHelper);
- }
-
@Bean
public LogDbHelper logDbHelper(LogDbProperties logDbProperties) throws TxLoggerException {
return new LogDbHelper(logDbProperties);
}
}
- @Bean
- @ConditionalOnMissingBean
- public TxLogger txLogger() {
- return new Slf4jTxLogger();
- }
-
@Bean
@ConditionalOnMissingBean
public TxLcnLogDbHelper txLcnLoggerHelper() {
return new MysqlLoggerHelper();
}
+ @Bean
+ public SpringUtils springUtils() {
+ return new SpringUtils();
+ }
}
diff --git a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/db/LogDbProperties.java b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/db/LogDbProperties.java
index 38d7a24a9..9dd9adfdb 100644
--- a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/db/LogDbProperties.java
+++ b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/db/LogDbProperties.java
@@ -38,6 +38,8 @@ public class LogDbProperties extends HikariConfig {
private boolean enabled = false;
+ private boolean onlyError = true;
+
public LogDbProperties(@Autowired(required = false) DataSourceProperties dataSourceProperties) {
if (Objects.isNull(dataSourceProperties) ||
Objects.isNull(dataSourceProperties.getDriverClassName()) ||
diff --git a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/helper/MysqlLoggerHelper.java b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/helper/MysqlLoggerHelper.java
index 594d27abd..fec02e72b 100644
--- a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/helper/MysqlLoggerHelper.java
+++ b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/helper/MysqlLoggerHelper.java
@@ -59,12 +59,12 @@ public void init() {
if (logDbProperties.isEnabled()) {
String sql = "CREATE TABLE IF NOT EXISTS `t_logger` (\n" +
" `id` bigint(20) NOT NULL AUTO_INCREMENT,\n" +
- " `group_id` varchar(50) NOT NULL ,\n" +
- "\t`unit_id` varchar(50) NOT NULL ,\n" +
- "\t`tag` varchar(50) NOT NULL ,\n" +
- "\t`content` varchar(1024) NOT NULL ,\n" +
+ " `group_id` varchar(64) NOT NULL ,\n" +
+ " `unit_id` varchar(32) NOT NULL ,\n" +
+ " `tag` varchar(50) NOT NULL ,\n" +
+ " `content` varchar(1024) NOT NULL ,\n" +
" `create_time` varchar(30) NOT NULL,\n" +
- " `app_name` varchar(50) NOT NULL,\n" +
+ " `app_name` varchar(128) NOT NULL,\n" +
" PRIMARY KEY (`id`) USING BTREE\n" +
") ";
dbHelper.update(sql);
diff --git a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/model/Field.java b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/model/Field.java
index 555e67749..7048d2c6b 100644
--- a/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/model/Field.java
+++ b/txlcn-logger/src/main/java/com/codingapi/txlcn/logger/model/Field.java
@@ -22,5 +22,9 @@
* @author ujued
*/
public interface Field {
+ /**
+ * common is ok
+ * @return bool
+ */
boolean ok();
}
diff --git a/txlcn-tc/pom.xml b/txlcn-tc/pom.xml
index a3f0a0533..c47032c7a 100644
--- a/txlcn-tc/pom.xml
+++ b/txlcn-tc/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.txlcn
tx-lcn
- 5.0.1.RELEASE
+ 5.0.2.RELEASE
txlcn-tc
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/TCAutoConfiguration.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/TCAutoConfiguration.java
index 8a51f4217..be02cd499 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/TCAutoConfiguration.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/TCAutoConfiguration.java
@@ -16,13 +16,18 @@
package com.codingapi.txlcn.tc;
import com.codingapi.txlcn.common.runner.TxLcnApplicationRunner;
+import com.codingapi.txlcn.common.util.ApplicationInformation;
+import com.codingapi.txlcn.common.util.id.ModIdProvider;
import com.codingapi.txlcn.logger.TxLoggerConfiguration;
-import com.codingapi.txlcn.tc.config.DependenciesImportSelector;
import com.codingapi.txlcn.tc.config.EnableDistributedTransaction;
import com.codingapi.txlcn.tracing.TracingAutoConfiguration;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
+import org.springframework.core.env.ConfigurableEnvironment;
/**
* Description:
@@ -50,4 +55,11 @@ public class TCAutoConfiguration {
public ApplicationRunner txLcnApplicationRunner(ApplicationContext applicationContext) {
return new TxLcnApplicationRunner(applicationContext);
}
+
+ @Bean
+ @ConditionalOnMissingBean
+ public ModIdProvider modIdProvider(ConfigurableEnvironment environment,
+ @Autowired(required = false) ServerProperties serverProperties) {
+ return () -> ApplicationInformation.modId(environment, serverProperties);
+ }
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/aspect/weave/DTXLogicWeaver.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/aspect/weave/DTXLogicWeaver.java
index a889780cb..2d8511162 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/aspect/weave/DTXLogicWeaver.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/aspect/weave/DTXLogicWeaver.java
@@ -60,6 +60,7 @@ public Object runTransaction(DTXInfo dtxInfo, BusinessCallback business) throws
log.debug("<---- TxLcn start ---->");
DTXLocalContext dtxLocalContext = DTXLocalContext.getOrNew();
TxContext txContext;
+ // ---------- 保证每个模块在一个DTX下只会有一个TxContext ---------- //
if (globalContext.hasTxContext()) {
// 有事务上下文的获取父上下文
txContext = globalContext.txContext();
@@ -94,8 +95,9 @@ public Object runTransaction(DTXInfo dtxInfo, BusinessCallback business) throws
try {
return transactionServiceExecutor.transactionRunning(info);
} finally {
+ // 线程执行业务完毕清理本地数据
if (dtxLocalContext.isDestroy()) {
- // 获取事务上下文通知事务执行完毕
+ // 通知事务执行完毕
synchronized (txContext.getLock()) {
txContext.getLock().notifyAll();
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/config/EnableDistributedTransaction.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/config/EnableDistributedTransaction.java
index 2336c529d..757891e6f 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/config/EnableDistributedTransaction.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/config/EnableDistributedTransaction.java
@@ -25,7 +25,7 @@
* Date: 1/19/19
*
* @author ujued
- * @since 5.0.1.RELEASE
+ * @since 5.0.2.RELEASE
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/config/TxClientConfig.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/config/TxClientConfig.java
index 26b0e17d5..6dcd5089a 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/config/TxClientConfig.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/config/TxClientConfig.java
@@ -76,9 +76,9 @@ public TxClientConfig() {
private long tmRpcTimeout;
- private int machineId;
+ private long machineId;
- private void setMachineId(int machineId) {
+ private void setMachineId(long machineId) {
this.machineId = machineId;
}
@@ -98,7 +98,7 @@ public void applyDtxTime(long dtxTime) {
setDtxTime(dtxTime);
}
- public void applyMachineId(int machineId) {
+ public void applyMachineId(long machineId) {
setMachineId(machineId);
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXLocalContext.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXLocalContext.java
index 730a70015..748092d56 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXLocalContext.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXLocalContext.java
@@ -24,6 +24,8 @@
/**
* 分布式事务远程调用控制对象
+ * !!!不推荐用户业务使用,API变更性大,使用不当有可能造成事务流程出错 !!!
+ *
* Created by lorne on 2017/6/5.
*/
@Data
@@ -90,6 +92,7 @@ public class DTXLocalContext {
*
* @see TccTransactionCleanService#clear(java.lang.String, int, java.lang.String, java.lang.String)
*/
+ @Deprecated
private boolean justNow;
//////// private ///////////////////////
@@ -171,11 +174,11 @@ public static void makeNeverAppeared() {
/**
* 事务状态
- *
+ * @param userDtxState state
* @return 1 commit 0 rollback
*/
- public static int transactionState() {
+ public static int transactionState(int userDtxState) {
DTXLocalContext dtxLocalContext = Objects.requireNonNull(currentLocal.get(), "DTX can't be null.");
- return dtxLocalContext.userTransactionState == -1 ? dtxLocalContext.sysTransactionState : dtxLocalContext.userTransactionState;
+ return userDtxState == 1 ? dtxLocalContext.sysTransactionState : userDtxState;
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXLocalControl.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXLocalControl.java
index 98a7e67f1..f280df30f 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXLocalControl.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXLocalControl.java
@@ -50,6 +50,7 @@ default Object doBusinessCode(TxTransactionInfo info) throws Throwable {
*
* @param info info
* @param throwable throwable
+ * @throws TransactionException TransactionException
*/
default void onBusinessCodeError(TxTransactionInfo info, Throwable throwable) throws TransactionException {
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXServiceExecutor.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXServiceExecutor.java
index bbfd699b0..9d668753a 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXServiceExecutor.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/DTXServiceExecutor.java
@@ -36,18 +36,17 @@
@Slf4j
public class DTXServiceExecutor {
- private final TCGlobalContext globalContext;
+ private static final TxLogger txLogger = TxLogger.newLogger(DTXServiceExecutor.class);
- private final TxLogger txLogger;
+ private final TCGlobalContext globalContext;
private final TxLcnBeanHelper txLcnBeanHelper;
private final DTXPropagationResolver propagationResolver;
@Autowired
- public DTXServiceExecutor(TxLogger txLogger, TxLcnBeanHelper txLcnBeanHelper,
- TCGlobalContext globalContext, DTXPropagationResolver propagationResolver) {
- this.txLogger = txLogger;
+ public DTXServiceExecutor(TxLcnBeanHelper txLcnBeanHelper, TCGlobalContext globalContext,
+ DTXPropagationResolver propagationResolver) {
this.txLcnBeanHelper = txLcnBeanHelper;
this.globalContext = globalContext;
this.propagationResolver = propagationResolver;
@@ -85,14 +84,14 @@ public Object transactionRunning(TxTransactionInfo info) throws Throwable {
dtxLocalControl.preBusinessCode(info);
// 4.2 业务执行前
- txLogger.transactionInfo(
+ txLogger.txTrace(
info.getGroupId(), info.getUnitId(), "pre business code, unit type: {}", transactionType);
// 4.3 执行业务
Object result = dtxLocalControl.doBusinessCode(info);
// 4.4 业务执行成功
- txLogger.transactionInfo(info.getGroupId(), info.getUnitId(), "business success");
+ txLogger.txTrace(info.getGroupId(), info.getUnitId(), "business success");
dtxLocalControl.onBusinessCodeSuccess(info, result);
return result;
} catch (TransactionException e) {
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/TransactionCleanService.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/TransactionCleanService.java
index 7f0165328..78f0e2d49 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/TransactionCleanService.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/TransactionCleanService.java
@@ -28,9 +28,9 @@ public interface TransactionCleanService {
/**
* 事务清理业务
*
- * @param groupId groupId
+ * @param groupId groupId
* @param state 事务状态 1 提交 0 回滚
- * @param unitId unitId
+ * @param unitId unitId
* @param unitType 事务类型
* @throws TransactionClearException TransactionClearException
*/
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/checking/DefaultDTXExceptionHandler.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/checking/DefaultDTXExceptionHandler.java
index 561e2f6cb..3150570a2 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/checking/DefaultDTXExceptionHandler.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/checking/DefaultDTXExceptionHandler.java
@@ -16,9 +16,8 @@
package com.codingapi.txlcn.tc.core.checking;
import com.codingapi.txlcn.common.exception.*;
-import com.codingapi.txlcn.common.util.Transactions;
import com.codingapi.txlcn.logger.TxLogger;
-import com.codingapi.txlcn.tc.txmsg.TxMangerReporter;
+import com.codingapi.txlcn.tc.txmsg.TMReporter;
import com.codingapi.txlcn.tc.core.template.TransactionCleanTemplate;
import com.codingapi.txlcn.txmsg.params.TxExceptionParams;
import lombok.extern.slf4j.Slf4j;
@@ -38,18 +37,16 @@
@Slf4j
public class DefaultDTXExceptionHandler implements DTXExceptionHandler {
- private final TransactionCleanTemplate transactionCleanTemplate;
+ private static final TxLogger txLogger = TxLogger.newLogger(DefaultDTXExceptionHandler.class);
- private final TxMangerReporter txMangerReporter;
+ private final TransactionCleanTemplate transactionCleanTemplate;
- private final TxLogger txLogger;
+ private final TMReporter tmReporter;
@Autowired
- public DefaultDTXExceptionHandler(TransactionCleanTemplate transactionCleanTemplate,
- TxMangerReporter txMangerReporter, TxLogger txLogger) {
+ public DefaultDTXExceptionHandler(TransactionCleanTemplate transactionCleanTemplate, TMReporter tmReporter) {
this.transactionCleanTemplate = transactionCleanTemplate;
- this.txMangerReporter = txMangerReporter;
- this.txLogger = txLogger;
+ this.tmReporter = tmReporter;
}
@Override
@@ -71,8 +68,7 @@ public void handleJoinGroupBusinessException(Object params, Throwable ex) throws
try {
transactionCleanTemplate.clean(groupId, unitId, unitType, 0);
} catch (TransactionClearException e) {
- log.error("{} > clean transaction error.", unitType);
- txLogger.error(this.getClass().getSimpleName(), "clean transaction fail.");
+ txLogger.error(groupId, unitId, "join group", "clean [{}]transaction fail.", unitType);
}
throw new TransactionException(ex);
}
@@ -102,7 +98,7 @@ public void handleNotifyGroupBusinessException(Object params, Throwable ex) {
try {
transactionCleanTemplate.clean(groupId, unitId, transactionType, state);
} catch (TransactionClearException e) {
- log.error("{} > clean transaction error.", transactionType);
+ txLogger.error(groupId, unitId, "notify group", "{} > clean transaction error.", transactionType);
}
}
@@ -130,12 +126,12 @@ public void handleNotifyGroupMessageException(Object params, Throwable ex) {
String unitId = (String) paramList.get(2);
String transactionType = (String) paramList.get(3);
try {
- transactionCleanTemplate.compensationClean(groupId, unitId, transactionType, state);
+ transactionCleanTemplate.cleanWithoutAspectLog(groupId, unitId, transactionType, state);
} catch (TransactionClearException e) {
- log.error("{} > compensationClean transaction error.", transactionType);
+ txLogger.error(groupId, unitId, "notify group", "{} > cleanWithoutAspectLog transaction error.", transactionType);
}
// 上报Manager,上报直到成功.
- txMangerReporter.reportTransactionState(groupId, null, TxExceptionParams.NOTIFY_GROUP_ERROR, state);
+ tmReporter.reportTransactionState(groupId, null, TxExceptionParams.NOTIFY_GROUP_ERROR, state);
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/checking/SimpleDTXChecking.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/checking/SimpleDTXChecking.java
index b5260f440..70c200a4d 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/checking/SimpleDTXChecking.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/checking/SimpleDTXChecking.java
@@ -25,7 +25,7 @@
import com.codingapi.txlcn.tc.core.context.TxContext;
import com.codingapi.txlcn.tc.corelog.aspect.AspectLogger;
import com.codingapi.txlcn.tc.txmsg.ReliableMessenger;
-import com.codingapi.txlcn.tc.txmsg.TxMangerReporter;
+import com.codingapi.txlcn.tc.txmsg.TMReporter;
import com.codingapi.txlcn.tc.core.template.TransactionCleanTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
@@ -51,28 +51,26 @@ public class SimpleDTXChecking implements DTXChecking, DisposableBean {
private static final ScheduledExecutorService scheduledExecutorService =
Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
+ private static final TxLogger txLogger = TxLogger.newLogger(SimpleDTXChecking.class);
+
private TransactionCleanTemplate transactionCleanTemplate;
private final ReliableMessenger reliableMessenger;
private final TxClientConfig clientConfig;
- private final TxLogger txLogger;
-
private final AspectLogger aspectLogger;
- private final TxMangerReporter txMangerReporter;
+ private final TMReporter tmReporter;
private final TCGlobalContext globalContext;
@Autowired
- public SimpleDTXChecking(TxClientConfig clientConfig, AspectLogger aspectLogger, TxLogger txLogger,
- TxMangerReporter txMangerReporter, TCGlobalContext globalContext,
- ReliableMessenger reliableMessenger) {
+ public SimpleDTXChecking(TxClientConfig clientConfig, AspectLogger aspectLogger, TMReporter tmReporter,
+ TCGlobalContext globalContext, ReliableMessenger reliableMessenger) {
this.clientConfig = clientConfig;
this.aspectLogger = aspectLogger;
- this.txLogger = txLogger;
- this.txMangerReporter = txMangerReporter;
+ this.tmReporter = tmReporter;
this.globalContext = globalContext;
this.reliableMessenger = reliableMessenger;
}
@@ -83,19 +81,18 @@ public void setTransactionCleanTemplate(TransactionCleanTemplate transactionClea
@Override
public void startDelayCheckingAsync(String groupId, String unitId, String transactionType) {
- txLogger.taskInfo(groupId, unitId, "start delay checking task");
+ txLogger.taskTrace(groupId, unitId, "start delay checking task");
ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(() -> {
try {
TxContext txContext = globalContext.txContext(groupId);
if (Objects.nonNull(txContext)) {
synchronized (txContext.getLock()) {
- txLogger.info(groupId, unitId, Transactions.TAG_TASK,
- "checking waiting for business code finish.");
+ txLogger.taskTrace(groupId, unitId, "checking waiting for business code finish.");
txContext.getLock().wait();
}
}
int state = reliableMessenger.askTransactionState(groupId, unitId);
- txLogger.taskInfo(groupId, unitId, "ask transaction state {}", state);
+ txLogger.taskTrace(groupId, unitId, "ask transaction state {}", state);
if (state == -1) {
txLogger.error(this.getClass().getSimpleName(), "delay clean transaction error.");
onAskTransactionStateException(groupId, unitId, transactionType);
@@ -117,7 +114,7 @@ public void startDelayCheckingAsync(String groupId, String unitId, String transa
public void stopDelayChecking(String groupId, String unitId) {
ScheduledFuture scheduledFuture = delayTasks.get(groupId + unitId);
if (Objects.nonNull(scheduledFuture)) {
- txLogger.taskInfo(groupId, unitId, "cancel {}:{} checking.", groupId, unitId);
+ txLogger.taskTrace(groupId, unitId, "cancel {}:{} checking.", groupId, unitId);
scheduledFuture.cancel(true);
}
}
@@ -125,13 +122,13 @@ public void stopDelayChecking(String groupId, String unitId) {
private void onAskTransactionStateException(String groupId, String unitId, String transactionType) {
try {
// 通知TxManager事务补偿
- txMangerReporter.reportTransactionState(groupId, unitId, TxExceptionParams.ASK_ERROR, 0);
+ tmReporter.reportTransactionState(groupId, unitId, TxExceptionParams.ASK_ERROR, 0);
log.warn("{} > has compensation info!", transactionType);
// 事务回滚, 保留适当的补偿信息
- transactionCleanTemplate.compensationClean(groupId, unitId, transactionType, 0);
+ transactionCleanTemplate.cleanWithoutAspectLog(groupId, unitId, transactionType, 0);
} catch (TransactionClearException e) {
- log.error("{} > clean transaction error.", transactionType);
+ txLogger.error(groupId, unitId, Transactions.TAG_TASK, "{} > clean transaction error.", transactionType);
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/context/DefaultGlobalContext.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/context/DefaultGlobalContext.java
index 04490faec..37b1f3d87 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/context/DefaultGlobalContext.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/context/DefaultGlobalContext.java
@@ -193,6 +193,16 @@ public boolean isDTXTimeout() {
return (System.currentTimeMillis() - txContext().getCreateTime()) >= clientConfig.getDtxTime();
}
+ @Override
+ public int dtxState(String groupId) {
+ return this.attachmentCache.containsKey(groupId, "rollback-only") ? 0 : 1;
+ }
+
+ @Override
+ public void setRollbackOnly(String groupId) {
+ this.attachmentCache.attach(groupId, "rollback-only", true);
+ }
+
/**
* 清理事务时调用
*
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/context/TCGlobalContext.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/context/TCGlobalContext.java
index 4d78b055e..b848bf43a 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/context/TCGlobalContext.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/context/TCGlobalContext.java
@@ -33,34 +33,131 @@
*/
public interface TCGlobalContext {
+ /**
+ * set lcn connection
+ *
+ * @param groupId groupId
+ * @param connectionProxy connectionProxy
+ */
void setLcnConnection(String groupId, LcnConnectionProxy connectionProxy);
+ /**
+ * get lcn proxy
+ *
+ * @param groupId groupId
+ * @return connection proxy
+ * @throws TCGlobalContextException TCGlobalContextException
+ */
LcnConnectionProxy getLcnConnection(String groupId) throws TCGlobalContextException;
-
+ /**
+ * get tcc info
+ *
+ * @param unitId unitId
+ * @param supplier supplier
+ * @return tcc info
+ * @throws TransactionException TransactionException
+ */
TccTransactionInfo tccTransactionInfo(String unitId, Supplier supplier)
throws TransactionException;
+ /**
+ * txc type lock
+ *
+ * @param groupId groupId
+ * @param unitId unitId
+ * @param lockIdSet lockIdSet
+ */
void addTxcLockId(String groupId, String unitId, Set lockIdSet);
+ /**
+ * find txc lock set
+ *
+ * @param groupId groupId
+ * @param unitId unitId
+ * @return set
+ * @throws TCGlobalContextException TCGlobalContextException
+ */
Set findTxcLockSet(String groupId, String unitId) throws TCGlobalContextException;
+ /**
+ * table struct info
+ *
+ * @param table table
+ * @param structSupplier structSupplier
+ * @return table info
+ * @throws SQLException SQLException
+ */
TableStruct tableStruct(String table, Supplier structSupplier) throws SQLException;
+ /**
+ * clean group
+ *
+ * @param groupId groupId
+ */
void clearGroup(String groupId);
+ /**
+ * start tx
+ *
+ * @return tx context info
+ */
TxContext startTx();
+ /**
+ * get tx context info by groupId
+ *
+ * @param groupId groupId
+ * @return tx context info
+ */
TxContext txContext(String groupId);
+ /**
+ * get context info
+ *
+ * @return info
+ */
TxContext txContext();
+ /**
+ * del tx info
+ */
void destroyTx();
+ /**
+ * del tx info
+ *
+ * @param groupId groupId
+ */
void destroyTx(String groupId);
+ /**
+ * has tx context
+ *
+ * @return bool
+ */
boolean hasTxContext();
+ /**
+ * is time out
+ *
+ * @return bool
+ */
boolean isDTXTimeout();
+
+ /**
+ * 判断某个事务是否不允许提交
+ *
+ * @param groupId groupId
+ * @return result
+ */
+ int dtxState(String groupId);
+
+ /**
+ * 设置某个事务组不允许提交
+ *
+ * @param groupId groupId
+ */
+ void setRollbackOnly(String groupId);
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/template/TransactionCleanTemplate.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/template/TransactionCleanTemplate.java
index 15d6766a1..4a90d3575 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/template/TransactionCleanTemplate.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/template/TransactionCleanTemplate.java
@@ -15,14 +15,12 @@
*/
package com.codingapi.txlcn.tc.core.template;
-import com.codingapi.txlcn.tc.corelog.aspect.AspectLogger;
-import com.codingapi.txlcn.tc.support.TxLcnBeanHelper;
-import com.codingapi.txlcn.tc.core.checking.DTXChecking;
import com.codingapi.txlcn.common.exception.TransactionClearException;
-import com.codingapi.txlcn.common.util.Transactions;
import com.codingapi.txlcn.logger.TxLogger;
+import com.codingapi.txlcn.tc.core.checking.DTXChecking;
import com.codingapi.txlcn.tc.core.context.TCGlobalContext;
-import lombok.extern.slf4j.Slf4j;
+import com.codingapi.txlcn.tc.corelog.aspect.AspectLogger;
+import com.codingapi.txlcn.tc.support.TxLcnBeanHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -33,7 +31,6 @@
* @author ujued
*/
@Component
-@Slf4j
public class TransactionCleanTemplate {
private final TxLcnBeanHelper transactionBeanHelper;
@@ -42,19 +39,16 @@ public class TransactionCleanTemplate {
private final AspectLogger aspectLogger;
- private final TxLogger txLogger;
+ private static final TxLogger txLogger = TxLogger.newLogger(TransactionCleanTemplate.class);
private final TCGlobalContext globalContext;
@Autowired
- public TransactionCleanTemplate(TxLcnBeanHelper transactionBeanHelper,
- DTXChecking dtxChecking,
- AspectLogger aspectLogger,
- TxLogger txLogger, TCGlobalContext globalContext) {
+ public TransactionCleanTemplate(TxLcnBeanHelper transactionBeanHelper, DTXChecking dtxChecking,
+ AspectLogger aspectLogger, TCGlobalContext globalContext) {
this.transactionBeanHelper = transactionBeanHelper;
this.dtxChecking = dtxChecking;
this.aspectLogger = aspectLogger;
- this.txLogger = txLogger;
this.globalContext = globalContext;
}
@@ -68,19 +62,18 @@ public TransactionCleanTemplate(TxLcnBeanHelper transactionBeanHelper,
* @throws TransactionClearException TransactionClearException
*/
public void clean(String groupId, String unitId, String unitType, int state) throws TransactionClearException {
- txLogger.transactionInfo(groupId, unitId, "clean transaction");
+ txLogger.txTrace(groupId, unitId, "clean transaction");
try {
- transactionBeanHelper.loadTransactionCleanService(unitType).clear(
- groupId, state, unitId, unitType
- );
- } finally {
- globalContext.clearGroup(groupId);
-
- dtxChecking.stopDelayChecking(groupId, unitId);
-
+ cleanWithoutAspectLog(groupId, unitId, unitType, state);
+ aspectLogger.clearLog(groupId, unitId);
+ } catch (TransactionClearException e) {
+ if (!e.isNeedCompensation()) {
+ aspectLogger.clearLog(groupId, unitId);
+ }
+ } catch (Throwable throwable) {
aspectLogger.clearLog(groupId, unitId);
}
- txLogger.transactionInfo(groupId, unitId, "clean transaction over");
+ txLogger.txTrace(groupId, unitId, "clean transaction over");
}
/**
@@ -92,8 +85,7 @@ public void clean(String groupId, String unitId, String unitType, int state) thr
* @param state transactionState
* @throws TransactionClearException TransactionClearException
*/
- public void compensationClean(String groupId, String unitId, String unitType, int state) throws TransactionClearException {
- txLogger.transactionInfo(groupId, unitId, "clean compensation transaction");
+ public void cleanWithoutAspectLog(String groupId, String unitId, String unitType, int state) throws TransactionClearException {
try {
transactionBeanHelper.loadTransactionCleanService(unitType).clear(
groupId, state, unitId, unitType
@@ -103,6 +95,5 @@ public void compensationClean(String groupId, String unitId, String unitType, in
dtxChecking.stopDelayChecking(groupId, unitId);
}
-
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/template/TransactionControlTemplate.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/template/TransactionControlTemplate.java
index 67ea363e1..3e8cbb3f5 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/template/TransactionControlTemplate.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/template/TransactionControlTemplate.java
@@ -15,7 +15,9 @@
*/
package com.codingapi.txlcn.tc.core.template;
-import com.codingapi.txlcn.common.exception.*;
+import com.codingapi.txlcn.common.exception.LcnBusinessException;
+import com.codingapi.txlcn.common.exception.TransactionClearException;
+import com.codingapi.txlcn.common.exception.TransactionException;
import com.codingapi.txlcn.common.util.Transactions;
import com.codingapi.txlcn.logger.TxLogger;
import com.codingapi.txlcn.tc.aspect.TransactionInfo;
@@ -26,7 +28,6 @@
import com.codingapi.txlcn.tc.corelog.aspect.AspectLogger;
import com.codingapi.txlcn.tc.txmsg.ReliableMessenger;
import com.codingapi.txlcn.txmsg.exception.RpcException;
-import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -39,9 +40,10 @@
* @author ujued
*/
@Component
-@Slf4j
public class TransactionControlTemplate {
+ private static final TxLogger txLogger = TxLogger.newLogger(TransactionControlTemplate.class);
+
private final AspectLogger aspectLogger;
private final DTXChecking dtxChecking;
@@ -50,14 +52,12 @@ public class TransactionControlTemplate {
private final TransactionCleanTemplate transactionCleanTemplate;
- private final TxLogger txLogger;
-
private final ReliableMessenger reliableMessenger;
private final TCGlobalContext globalContext;
@Autowired
- public TransactionControlTemplate(AspectLogger aspectLogger, DTXChecking dtxChecking, TxLogger txLogger,
+ public TransactionControlTemplate(AspectLogger aspectLogger, DTXChecking dtxChecking,
DTXExceptionHandler dtxExceptionHandler,
TransactionCleanTemplate transactionCleanTemplate,
ReliableMessenger reliableMessenger, TCGlobalContext globalContext) {
@@ -65,7 +65,6 @@ public TransactionControlTemplate(AspectLogger aspectLogger, DTXChecking dtxChec
this.dtxChecking = dtxChecking;
this.dtxExceptionHandler = dtxExceptionHandler;
this.transactionCleanTemplate = transactionCleanTemplate;
- this.txLogger = txLogger;
this.reliableMessenger = reliableMessenger;
this.globalContext = globalContext;
}
@@ -75,7 +74,7 @@ public TransactionControlTemplate(AspectLogger aspectLogger, DTXChecking dtxChec
*
* @param groupId groupId
* @param unitId unitId
- * @param transactionInfo transactionInfo
+ * @param transactionInfo txTrace
* @param transactionType transactionType
* @throws TransactionException 创建group失败时抛出
*/
@@ -84,8 +83,8 @@ public void createGroup(String groupId, String unitId, TransactionInfo transacti
//创建事务组
try {
// 日志
- txLogger.transactionInfo(groupId, unitId,
- "create group > {} > groupId: {xid}, unitId: {uid}", transactionType);
+ txLogger.txTrace(groupId, unitId,
+ "create group > transaction type: {}", transactionType);
// 创建事务组消息
reliableMessenger.createGroup(groupId);
// 缓存发起方切面信息
@@ -97,7 +96,7 @@ public void createGroup(String groupId, String unitId, TransactionInfo transacti
// 创建事务组业务失败
dtxExceptionHandler.handleCreateGroupBusinessException(groupId, e.getCause());
}
- txLogger.transactionInfo(groupId, unitId, "create group over");
+ txLogger.txTrace(groupId, unitId, "create group over");
}
/**
@@ -106,17 +105,17 @@ public void createGroup(String groupId, String unitId, TransactionInfo transacti
* @param groupId groupId
* @param unitId unitId
* @param transactionType transactionType
- * @param transactionInfo transactionInfo
+ * @param transactionInfo txTrace
* @throws TransactionException 加入事务组失败时抛出
*/
public void joinGroup(String groupId, String unitId, String transactionType, TransactionInfo transactionInfo)
throws TransactionException {
try {
- txLogger.transactionInfo(groupId, unitId, "join group > {} > groupId: {xid}, unitId: {uid}", transactionType);
+ txLogger.txTrace(groupId, unitId, "join group > transaction type: {}", transactionType);
- reliableMessenger.joinGroup(groupId, unitId, transactionType, DTXLocalContext.transactionState());
+ reliableMessenger.joinGroup(groupId, unitId, transactionType, DTXLocalContext.transactionState(globalContext.dtxState(groupId)));
- txLogger.transactionInfo(groupId, unitId, "{xid} join group message over.");
+ txLogger.txTrace(groupId, unitId, "join group message over.");
// 异步检测
dtxChecking.startDelayCheckingAsync(groupId, unitId, transactionType);
@@ -128,7 +127,7 @@ public void joinGroup(String groupId, String unitId, String transactionType, Tra
} catch (LcnBusinessException e) {
dtxExceptionHandler.handleJoinGroupBusinessException(Arrays.asList(groupId, unitId, transactionType), e);
}
- txLogger.transactionInfo(groupId, unitId, "join logic group over");
+ txLogger.txTrace(groupId, unitId, "join group logic over");
}
/**
@@ -141,16 +140,14 @@ public void joinGroup(String groupId, String unitId, String transactionType, Tra
*/
public void notifyGroup(String groupId, String unitId, String transactionType, int state) {
try {
- txLogger.transactionInfo(
- groupId, unitId, "notify group > {} > groupId: {xid}, unitId: {uid}, state: {}.", transactionType, state);
+ txLogger.txTrace(
+ groupId, unitId, "notify group > transaction type: {}, state: {}.", transactionType, state);
if (globalContext.isDTXTimeout()) {
throw new LcnBusinessException("dtx timeout.");
}
- reliableMessenger.notifyGroup(groupId, state);
+ state = reliableMessenger.notifyGroup(groupId, state);
transactionCleanTemplate.clean(groupId, unitId, transactionType, state);
- log.debug("{} > close transaction group.", transactionType);
} catch (TransactionClearException e) {
- log.error("clear exception", e);
txLogger.trace(groupId, unitId, Transactions.TE, "clean transaction fail.");
} catch (RpcException e) {
dtxExceptionHandler.handleNotifyGroupMessageException(Arrays.asList(groupId, state, unitId, transactionType), e);
@@ -158,6 +155,6 @@ public void notifyGroup(String groupId, String unitId, String transactionType, i
// 关闭事务组失败
dtxExceptionHandler.handleNotifyGroupBusinessException(Arrays.asList(groupId, state, unitId, transactionType), e.getCause());
}
- txLogger.transactionInfo(groupId, unitId, "notify group exception state {}.", state);
+ txLogger.txTrace(groupId, unitId, "notify group exception state {}.", state);
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/lcn/control/LcnStartingTransaction.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/lcn/control/LcnStartingTransaction.java
index ba9d130fe..fafc0c4fa 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/lcn/control/LcnStartingTransaction.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/lcn/control/LcnStartingTransaction.java
@@ -19,6 +19,7 @@
import com.codingapi.txlcn.tc.core.DTXLocalContext;
import com.codingapi.txlcn.tc.core.TxTransactionInfo;
import com.codingapi.txlcn.tc.core.DTXLocalControl;
+import com.codingapi.txlcn.tc.core.context.TCGlobalContext;
import com.codingapi.txlcn.tc.core.template.TransactionControlTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,10 +34,13 @@ public class LcnStartingTransaction implements DTXLocalControl {
private final TransactionControlTemplate transactionControlTemplate;
+ private final TCGlobalContext globalContext;
+
@Autowired
- public LcnStartingTransaction(TransactionControlTemplate transactionControlTemplate) {
+ public LcnStartingTransaction(TransactionControlTemplate transactionControlTemplate, TCGlobalContext globalContext) {
this.transactionControlTemplate = transactionControlTemplate;
+ this.globalContext = globalContext;
}
@Override
@@ -63,6 +67,7 @@ public void onBusinessCodeSuccess(TxTransactionInfo info, Object result) {
public void postBusinessCode(TxTransactionInfo info) {
// RPC close DTX group
transactionControlTemplate.notifyGroup(
- info.getGroupId(), info.getUnitId(), info.getTransactionType(), DTXLocalContext.transactionState());
+ info.getGroupId(), info.getUnitId(), info.getTransactionType(),
+ DTXLocalContext.transactionState(globalContext.dtxState(info.getGroupId())));
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/tcc/control/TccStartingTransaction.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/tcc/control/TccStartingTransaction.java
index c3dddaf97..b01cb67d5 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/tcc/control/TccStartingTransaction.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/tcc/control/TccStartingTransaction.java
@@ -39,13 +39,13 @@ public class TccStartingTransaction implements DTXLocalControl {
private final TransactionControlTemplate transactionControlTemplate;
- private final TCGlobalContext context;
+ private final TCGlobalContext globalContext;
@Autowired
public TccStartingTransaction(TransactionControlTemplate transactionControlTemplate,
- TCGlobalContext context) {
+ TCGlobalContext globalContext) {
this.transactionControlTemplate = transactionControlTemplate;
- this.context = context;
+ this.globalContext = globalContext;
}
static TccTransactionInfo prepareTccInfo(TxTransactionInfo info) throws TransactionException {
@@ -81,7 +81,7 @@ static TccTransactionInfo prepareTccInfo(TxTransactionInfo info) throws Transact
public void preBusinessCode(TxTransactionInfo info) throws TransactionException {
// cache tcc info
try {
- context.tccTransactionInfo(info.getUnitId(), () -> prepareTccInfo(info))
+ globalContext.tccTransactionInfo(info.getUnitId(), () -> prepareTccInfo(info))
.setMethodParameter(info.getTransactionInfo().getArgumentValues());
} catch (Throwable throwable) {
throw new TransactionException(throwable);
@@ -110,6 +110,7 @@ public void onBusinessCodeSuccess(TxTransactionInfo info, Object result) {
@Override
public void postBusinessCode(TxTransactionInfo info) {
transactionControlTemplate.notifyGroup(
- info.getGroupId(), info.getUnitId(), info.getTransactionType(), DTXLocalContext.transactionState());
+ info.getGroupId(), info.getUnitId(), info.getTransactionType(),
+ DTXLocalContext.transactionState(globalContext.dtxState(info.getGroupId())));
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/tcc/control/TccTransactionCleanService.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/tcc/control/TccTransactionCleanService.java
index 81dd1aedf..0b8f012d3 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/tcc/control/TccTransactionCleanService.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/tcc/control/TccTransactionCleanService.java
@@ -16,11 +16,14 @@
package com.codingapi.txlcn.tc.core.transaction.tcc.control;
import com.codingapi.txlcn.common.exception.TransactionClearException;
+import com.codingapi.txlcn.common.util.Maps;
import com.codingapi.txlcn.tc.core.DTXLocalContext;
import com.codingapi.txlcn.tc.core.TccTransactionInfo;
import com.codingapi.txlcn.tc.core.TransactionCleanService;
import com.codingapi.txlcn.tc.core.context.TCGlobalContext;
-import com.codingapi.txlcn.tc.txmsg.TxMangerReporter;
+import com.codingapi.txlcn.tc.txmsg.TMReporter;
+import com.codingapi.txlcn.tracing.TracingConstants;
+import com.codingapi.txlcn.tracing.TracingContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@@ -41,28 +44,32 @@ public class TccTransactionCleanService implements TransactionCleanService {
private final ApplicationContext applicationContext;
- private final TxMangerReporter txMangerReporter;
+ private final TMReporter tmReporter;
private final TCGlobalContext globalContext;
@Autowired
public TccTransactionCleanService(ApplicationContext applicationContext,
- TxMangerReporter txMangerReporter, TCGlobalContext globalContext) {
+ TMReporter tmReporter, TCGlobalContext globalContext) {
this.applicationContext = applicationContext;
- this.txMangerReporter = txMangerReporter;
+ this.tmReporter = tmReporter;
this.globalContext = globalContext;
}
@Override
public void clear(String groupId, int state, String unitId, String unitType) throws TransactionClearException {
Method exeMethod;
+ boolean shouldDestroy = !TracingContext.tracing().hasGroup();
try {
TccTransactionInfo tccInfo = globalContext.tccTransactionInfo(unitId, null);
Object object = applicationContext.getBean(tccInfo.getExecuteClass());
- // 用户的 confirm or cancel method 可以用到这个
+ // 将要移除。
if (Objects.isNull(DTXLocalContext.cur())) {
DTXLocalContext.getOrNew().setJustNow(true);
}
+ if (shouldDestroy) {
+ TracingContext.init(Maps.of(TracingConstants.GROUP_ID, groupId, TracingConstants.APP_MAP, "{}"));
+ }
DTXLocalContext.getOrNew().setGroupId(groupId);
DTXLocalContext.cur().setUnitId(unitId);
exeMethod = tccInfo.getExecuteClass().getMethod(
@@ -73,7 +80,7 @@ public void clear(String groupId, int state, String unitId, String unitType) thr
log.debug("User confirm/cancel logic over.");
} catch (Throwable e) {
log.error("Tcc clean error.", e);
- txMangerReporter.reportTccCleanException(groupId, unitId, state);
+ tmReporter.reportTccCleanException(groupId, unitId, state);
}
} catch (Throwable e) {
throw new TransactionClearException(e.getMessage());
@@ -81,6 +88,9 @@ public void clear(String groupId, int state, String unitId, String unitType) thr
if (DTXLocalContext.cur().isJustNow()) {
DTXLocalContext.makeNeverAppeared();
}
+ if (shouldDestroy) {
+ TracingContext.tracing().destroy();
+ }
}
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/analy/TxcServiceImpl.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/analy/TxcServiceImpl.java
index 637ddff8c..462d233ac 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/analy/TxcServiceImpl.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/analy/TxcServiceImpl.java
@@ -273,8 +273,8 @@ public void cleanTxc(String groupId, String unitId) throws TxcLogicException {
@Override
public void undo(String groupId, String unitId) throws TxcLogicException {
DTXLocalContext.makeUnProxy();
+ List statementInfoList = new ArrayList<>();
try {
- List statementInfoList = new ArrayList<>();
List undoLogDOList = txcLogHelper.getUndoLogByGroupAndUnitId(groupId, unitId);
for (UndoLogDO undoLogDO : undoLogDOList) {
@@ -295,7 +295,9 @@ public void undo(String groupId, String unitId) throws TxcLogicException {
}
txcSqlExecutor.applyUndoLog(statementInfoList);
} catch (SQLException e) {
- throw new TxcLogicException(e);
+ TxcLogicException exception = new TxcLogicException(e);
+ exception.setAttachment(statementInfoList);
+ throw exception;
} finally {
DTXLocalContext.undoProxyStatus();
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcRunningTransaction.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcRunningTransaction.java
index fb233f310..d5100bd7d 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcRunningTransaction.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcRunningTransaction.java
@@ -17,7 +17,6 @@
import com.codingapi.txlcn.common.exception.TransactionClearException;
import com.codingapi.txlcn.common.exception.TransactionException;
-import com.codingapi.txlcn.common.exception.TxClientException;
import com.codingapi.txlcn.common.util.Transactions;
import com.codingapi.txlcn.logger.TxLogger;
import com.codingapi.txlcn.tc.core.DTXLocalContext;
@@ -43,14 +42,13 @@ public class TxcRunningTransaction implements DTXLocalControl {
private final TransactionControlTemplate transactionControlTemplate;
- private final TxLogger txLogger;
+ private static final TxLogger txLogger = TxLogger.newLogger(TxcRunningTransaction.class);
@Autowired
public TxcRunningTransaction(TransactionCleanTemplate transactionCleanTemplate,
- TransactionControlTemplate transactionControlTemplate, TxLogger txLogger) {
+ TransactionControlTemplate transactionControlTemplate) {
this.transactionCleanTemplate = transactionCleanTemplate;
this.transactionControlTemplate = transactionControlTemplate;
- this.txLogger = txLogger;
}
@Override
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcStartingTransaction.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcStartingTransaction.java
index ffc362d5a..b6dbd06fe 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcStartingTransaction.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcStartingTransaction.java
@@ -19,6 +19,7 @@
import com.codingapi.txlcn.tc.core.DTXLocalContext;
import com.codingapi.txlcn.tc.core.DTXLocalControl;
import com.codingapi.txlcn.tc.core.TxTransactionInfo;
+import com.codingapi.txlcn.tc.core.context.TCGlobalContext;
import com.codingapi.txlcn.tc.core.template.TransactionControlTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,9 +37,12 @@ public class TxcStartingTransaction implements DTXLocalControl {
private final TransactionControlTemplate transactionControlTemplate;
+ private final TCGlobalContext globalContext;
+
@Autowired
- public TxcStartingTransaction(TransactionControlTemplate transactionControlTemplate) {
+ public TxcStartingTransaction(TransactionControlTemplate transactionControlTemplate, TCGlobalContext globalContext) {
this.transactionControlTemplate = transactionControlTemplate;
+ this.globalContext = globalContext;
}
@Override
@@ -70,7 +74,7 @@ public void onBusinessCodeSuccess(TxTransactionInfo info, Object result) {
@Override
public void postBusinessCode(TxTransactionInfo info) {
- int state = DTXLocalContext.transactionState();
+ int state = DTXLocalContext.transactionState(globalContext.dtxState(info.getGroupId()));
// 关闭事务组
transactionControlTemplate.notifyGroup(info.getGroupId(), info.getUnitId(), info.getTransactionType(), state);
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcTransactionCleanService.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcTransactionCleanService.java
index 23a94d5ec..031af5134 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcTransactionCleanService.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/core/transaction/txc/control/TxcTransactionCleanService.java
@@ -19,10 +19,14 @@
import com.codingapi.txlcn.tc.core.TransactionCleanService;
import com.codingapi.txlcn.common.exception.TransactionClearException;
import com.codingapi.txlcn.common.exception.TxcLogicException;
+import com.codingapi.txlcn.tc.core.transaction.txc.analy.def.bean.StatementInfo;
+import com.codingapi.txlcn.tc.txmsg.TMReporter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.List;
+
/**
* Description:
* Date: 2018/12/13
@@ -35,23 +39,39 @@ public class TxcTransactionCleanService implements TransactionCleanService {
private final TxcService txcService;
+ private final TMReporter tmReporter;
+
@Autowired
- public TxcTransactionCleanService(TxcService txcService) {
+ public TxcTransactionCleanService(TxcService txcService, TMReporter tmReporter) {
this.txcService = txcService;
+ this.tmReporter = tmReporter;
}
@Override
public void clear(String groupId, int state, String unitId, String unitType) throws TransactionClearException {
+ boolean rethrowTxcException = false;
try {
// 若需要回滚读undo_log,进行回滚
if (state == 0) {
txcService.undo(groupId, unitId);
}
+ } catch (TxcLogicException e) {
+ @SuppressWarnings("unchecked")
+ List statementInfoList = (List) e.getAttachment();
+ tmReporter.reportTxcUndoException(groupId, unitId, statementInfoList);
+ rethrowTxcException = true;
+ log.debug("need compensation !");
+ }
+ try {
// 清理TXC
txcService.cleanTxc(groupId, unitId);
} catch (TxcLogicException e) {
throw new TransactionClearException(e);
}
+
+ if (rethrowTxcException) {
+ throw TransactionClearException.needCompensation();
+ }
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/H2DbHelper.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/H2DbHelper.java
index c9668f2da..9d3fa1afb 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/H2DbHelper.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/H2DbHelper.java
@@ -46,11 +46,10 @@ public class H2DbHelper implements DisposableBean {
public H2DbHelper(H2DbProperties h2DbProperties) {
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDriverClassName(org.h2.Driver.class.getName());
- log.info("Init H2 DATABASE at {}", h2DbProperties.getFilePath());
hikariConfig.setJdbcUrl(String.format("jdbc:h2:%s", h2DbProperties.getFilePath()));
hikariDataSource = new HikariDataSource(hikariConfig);
queryRunner = new QueryRunner(hikariDataSource);
- log.info("Init H2 DATABASE finished.");
+ log.info("Init H2 DATABASE at {}", h2DbProperties.getFilePath());
}
public QueryRunner queryRunner() {
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/aspect/AspectLogHelper.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/aspect/AspectLogHelper.java
index 73143d603..888b46b25 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/aspect/AspectLogHelper.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/aspect/AspectLogHelper.java
@@ -52,8 +52,8 @@ public void init() {
"(" +
"ID BIGINT NOT NULL AUTO_INCREMENT, " +
"UNIT_ID VARCHAR(32) NOT NULL," +
- "GROUP_ID VARCHAR(32) NOT NULL," +
- "METHOD_STR VARCHAR(300) NOT NULL ," +
+ "GROUP_ID VARCHAR(64) NOT NULL," +
+ "METHOD_STR VARCHAR(512) NOT NULL ," +
"BYTES BLOB NOT NULL," +
"GROUP_ID_HASH BIGINT NOT NULL," +
"UNIT_ID_HASH BIGINT NOT NULL," +
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/aspect/AsyncH2DBAspectLogger.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/aspect/AsyncH2DBAspectLogger.java
index 46ac89e43..25968a2c5 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/aspect/AsyncH2DBAspectLogger.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/aspect/AsyncH2DBAspectLogger.java
@@ -61,7 +61,6 @@ public AsyncH2DBAspectLogger(AspectLogHelper txLogHelper) {
public void trace(String groupId, String unitId, TransactionInfo transactionInfo) {
executorService.submit(() -> {
long t1 = System.currentTimeMillis();
- log.debug("event-save-start->{}", groupId);
byte[] bytes;
try {
bytes = SerializerContext.getInstance().serialize(transactionInfo);
@@ -80,7 +79,7 @@ public void trace(String groupId, String unitId, TransactionInfo transactionInfo
boolean res = txLogHelper.save(txLog);
long t2 = System.currentTimeMillis();
- log.debug("event-save-over ok:{} ->{},time:{}", res, groupId, (t2 - t1));
+ log.debug("async save aspect log. result: {} groupId: {}, used time: {}ms", res, groupId, (t2 - t1));
});
}
@@ -88,10 +87,9 @@ public void trace(String groupId, String unitId, TransactionInfo transactionInfo
public void clearLog(String groupId, String unitId) {
executorService.submit(() -> {
long t1 = System.currentTimeMillis();
- log.debug("event-clear-start->{}", groupId);
boolean res = txLogHelper.delete(groupId.hashCode(), unitId.hashCode());
long t2 = System.currentTimeMillis();
- log.debug("event-clear-over ok:{} ->{},time:{}", res, groupId, (t2 - t1));
+ log.debug("async clear aspect log. result:{}, groupId: {}, used time: {}ms", res, groupId, (t2 - t1));
});
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/txc/TxcLogHelper.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/txc/TxcLogHelper.java
index a63818c24..815f340ec 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/txc/TxcLogHelper.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/corelog/txc/TxcLogHelper.java
@@ -51,7 +51,7 @@ public void init() {
h2DbHelper.update("CREATE TABLE IF NOT EXISTS TXC_UNDO_LOG (" +
"ID BIGINT NOT NULL AUTO_INCREMENT, " +
"UNIT_ID VARCHAR(32) NOT NULL," +
- "GROUP_ID VARCHAR(32) NOT NULL," +
+ "GROUP_ID VARCHAR(64) NOT NULL," +
"SQL_TYPE INT NOT NULL," +
"ROLLBACK_INFO BLOB NOT NULL," +
"CREATE_TIME CHAR(23) NOT NULL, " +
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/DTXAspectSupport.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/DTXAspectSupport.java
index 10c8b16e4..8637760bb 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/DTXAspectSupport.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/DTXAspectSupport.java
@@ -18,18 +18,19 @@
import com.codingapi.txlcn.tc.core.DTXLocalContext;
/**
- * Description:
+ * Description: 将会在未来版本废弃。推荐使用 {@link DTXUserControls}
* Date: 19-1-16 下午4:21
*
* @author ujued
+ * @see DTXUserControls
*/
-
-public class DTXAspectSupport {
+@Deprecated
+public class DTXAspectSupport {
/**
* 回滚分布式事务
*/
public static void setRollbackOnly() {
- DTXLocalContext.cur().setUserTransactionState(0);
+ DTXUserControls.rollbackCurrentGroup();
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/DTXUserControls.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/DTXUserControls.java
new file mode 100644
index 000000000..c82526455
--- /dev/null
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/DTXUserControls.java
@@ -0,0 +1,40 @@
+package com.codingapi.txlcn.tc.support;
+
+import com.codingapi.txlcn.tc.core.context.TCGlobalContext;
+import com.codingapi.txlcn.tracing.TracingContext;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+import java.util.Objects;
+
+/**
+ * Description:
+ * Date: 19-2-21 上午10:57
+ *
+ * @author ujued
+ */
+@Component
+public class DTXUserControls implements ApplicationContextAware {
+
+ private static ApplicationContext applicationContext;
+
+ private static TCGlobalContext globalContext;
+
+ public static void rollbackGroup(String groupId) {
+ if (Objects.isNull(globalContext)) {
+ globalContext = applicationContext.getBean(TCGlobalContext.class);
+ }
+ globalContext.setRollbackOnly(groupId);
+ }
+
+ public static void rollbackCurrentGroup() {
+ rollbackGroup(TracingContext.tracing().groupId());
+ }
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ DTXUserControls.applicationContext = applicationContext;
+ }
+}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/listener/RpcEnvStatusListener.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/listener/RpcEnvStatusListener.java
index 0a6994d67..db2a17ddc 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/listener/RpcEnvStatusListener.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/listener/RpcEnvStatusListener.java
@@ -22,9 +22,22 @@
* @author ujued
*/
public interface RpcEnvStatusListener {
+ /**
+ * on connect
+ * @param remoteKey remoteKey
+ */
void onConnected(String remoteKey);
-
+
+ /**
+ * on init
+ *
+ * @param remoteKey remoteKey
+ */
void onInitialized(String remoteKey);
-
+
+ /**
+ * on connect fail
+ * @param remoteKey remoteKey
+ */
void onConnectFail(String remoteKey);
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/listener/TransactionListener.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/listener/TransactionListener.java
index fb917038a..b6eb8dc9b 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/listener/TransactionListener.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/support/listener/TransactionListener.java
@@ -24,10 +24,27 @@
* @author ujued
*/
public interface TransactionListener {
-
+
+ /**
+ * tx begin
+ *
+ * @param txTransactionInfo txTransactionInfo
+ */
void onTransactionBegin(TxTransactionInfo txTransactionInfo);
-
+
+ /**
+ * tx error
+ *
+ * @param txTransactionInfo txTransactionInfo
+ */
void onTransactionError(TxTransactionInfo txTransactionInfo);
-
+
+ /**
+ * tx clean
+ *
+ * @param groupId groupId
+ * @param unitId unitId
+ * @param transactionState transactionState
+ */
void onTransactionClean(String groupId, String unitId, int transactionState);
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/LoopMessenger.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/LoopMessenger.java
index 1b6809fa1..6d595e48e 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/LoopMessenger.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/LoopMessenger.java
@@ -66,7 +66,7 @@ public void releaseLocks(Set lockIdList) throws RpcException {
}
@Override
- public void notifyGroup(String groupId, int transactionState) throws RpcException, LcnBusinessException {
+ public int notifyGroup(String groupId, int transactionState) throws RpcException, LcnBusinessException {
NotifyGroupParams notifyGroupParams = new NotifyGroupParams();
notifyGroupParams.setGroupId(groupId);
notifyGroupParams.setState(transactionState);
@@ -76,6 +76,7 @@ public void notifyGroup(String groupId, int transactionState) throws RpcExceptio
if (!MessageUtils.statusOk(messageDto)) {
throw new LcnBusinessException(messageDto.loadBean(Throwable.class));
}
+ return messageDto.loadBean(Integer.class);
}
@Override
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/MessageCreator.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/MessageCreator.java
index c48130c37..469049a5d 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/MessageCreator.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/MessageCreator.java
@@ -71,7 +71,7 @@ public static MessageDto notifyGroup(NotifyGroupParams notifyGroupParams) {
/**
* 申请锁消息
- *
+ * @param groupId groupId
* @param locks locks
* @param lockType lockType
* @return message
@@ -166,14 +166,15 @@ public static MessageDto writeTxException(TxExceptionParams txExceptionParams) {
/**
* 初始化客户端请求
*
- * @param appName appName
+ * @param appName appName
+ * @param labelName labelName
* @return MessageDto
*/
- public static MessageDto initClient(String appName) {
+ public static MessageDto initClient(String appName, String labelName) {
InitClientParams initClientParams = new InitClientParams();
initClientParams.setAppName(appName);
+ initClientParams.setLabelName(labelName);
MessageDto messageDto = new MessageDto();
- messageDto.setGroupId(MessageConstants.ACTION_INIT_GROUPID);
messageDto.setData(initClientParams);
messageDto.setAction(MessageConstants.ACTION_INIT_CLIENT);
return messageDto;
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/ReliableMessenger.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/ReliableMessenger.java
index 5157867a8..dde70c087 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/ReliableMessenger.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/ReliableMessenger.java
@@ -53,10 +53,11 @@ public interface ReliableMessenger {
*
* @param groupId groupId
* @param transactionState 分布式事务状态
+ * @return dtx state
* @throws RpcException Non TM
* @throws LcnBusinessException TM Business Err
*/
- void notifyGroup(String groupId, int transactionState) throws RpcException, LcnBusinessException;
+ int notifyGroup(String groupId, int transactionState) throws RpcException, LcnBusinessException;
/**
* 加入事务组
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TCSideRpcInitCallBack.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TCSideRpcInitCallBack.java
index 9eb372331..d8851658a 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TCSideRpcInitCallBack.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TCSideRpcInitCallBack.java
@@ -15,8 +15,10 @@
*/
package com.codingapi.txlcn.tc.txmsg;
-import com.codingapi.txlcn.common.util.ApplicationInformation;
import com.codingapi.txlcn.common.util.id.IdGenInit;
+import com.codingapi.txlcn.common.util.id.ModIdProvider;
+import com.codingapi.txlcn.tc.config.TxClientConfig;
+import com.codingapi.txlcn.tc.support.listener.RpcEnvStatusListener;
import com.codingapi.txlcn.txmsg.RpcClient;
import com.codingapi.txlcn.txmsg.dto.MessageDto;
import com.codingapi.txlcn.txmsg.dto.RpcCmd;
@@ -24,14 +26,12 @@
import com.codingapi.txlcn.txmsg.listener.ClientInitCallBack;
import com.codingapi.txlcn.txmsg.listener.HeartbeatListener;
import com.codingapi.txlcn.txmsg.params.InitClientParams;
-import com.codingapi.txlcn.tc.config.TxClientConfig;
-import com.codingapi.txlcn.tc.support.listener.RpcEnvStatusListener;
import com.codingapi.txlcn.txmsg.util.MessageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
import java.util.List;
@@ -51,19 +51,22 @@ public class TCSideRpcInitCallBack implements ClientInitCallBack, HeartbeatListe
private final TxClientConfig txClientConfig;
- private final String modId;
-
private final List rpcEnvStatusListeners;
+ private final ModIdProvider modIdProvider;
+
+ private final String applicationName;
+
@Autowired
public TCSideRpcInitCallBack(RpcClient rpcClient, TxClientConfig txClientConfig,
ConfigurableEnvironment environment,
- @Autowired(required = false) ServerProperties serverProperties,
- List rpcEnvStatusListeners) {
+ List rpcEnvStatusListeners, ModIdProvider modIdProvider) {
this.rpcClient = rpcClient;
this.txClientConfig = txClientConfig;
- this.modId = ApplicationInformation.modId(environment, serverProperties);
this.rpcEnvStatusListeners = rpcEnvStatusListeners;
+ this.modIdProvider = modIdProvider;
+ String appName = environment.getProperty("spring.application.name");
+ this.applicationName = StringUtils.hasText(appName) ? appName : "application";
}
@Override
@@ -72,7 +75,8 @@ public void connected(String remoteKey) {
new Thread(() -> {
try {
log.info("Send init message to TM[{}]", remoteKey);
- MessageDto msg = rpcClient.request(remoteKey, MessageCreator.initClient(modId), 5000);
+ MessageDto msg = rpcClient.request(
+ remoteKey, MessageCreator.initClient(applicationName, modIdProvider.modId()), 5000);
if (MessageUtils.statusOk(msg)) {
//每一次建立连接时将会获取最新的时间
InitClientParams resParams = msg.loadBean(InitClientParams.class);
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TxMangerReporter.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TMReporter.java
similarity index 76%
rename from txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TxMangerReporter.java
rename to txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TMReporter.java
index 5e0ff6606..5bc0a77f2 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TxMangerReporter.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TMReporter.java
@@ -15,14 +15,15 @@
*/
package com.codingapi.txlcn.tc.txmsg;
-import com.codingapi.txlcn.common.util.Transactions;
import com.codingapi.txlcn.logger.TxLogger;
+import com.codingapi.txlcn.tc.core.transaction.txc.analy.def.bean.StatementInfo;
import com.codingapi.txlcn.txmsg.exception.RpcException;
import com.codingapi.txlcn.txmsg.params.TxExceptionParams;
-import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.List;
+
/**
* Description: 客户端上报Manager
* Date: 2018/12/29
@@ -30,19 +31,17 @@
* @author ujued
*/
@Component
-@Slf4j
-public class TxMangerReporter {
+public class TMReporter {
private final ReliableMessenger reliableMessenger;
- private final TxLogger txLogger;
+ private static final TxLogger txLogger = TxLogger.newLogger(TMReporter.class);
private static final String REPORT_ERROR_MESSAGE = "report transaction transactionState error";
@Autowired
- public TxMangerReporter(ReliableMessenger reliableMessenger, TxLogger txLogger) {
+ public TMReporter(ReliableMessenger reliableMessenger) {
this.reliableMessenger = reliableMessenger;
- this.txLogger = txLogger;
}
/**
@@ -82,7 +81,17 @@ private void report(TxExceptionParams exceptionParams) {
try {
reliableMessenger.request(MessageCreator.writeTxException(exceptionParams));
} catch (RpcException e) {
- txLogger.trace(exceptionParams.getGroupId(), exceptionParams.getUnitId(), Transactions.TE, REPORT_ERROR_MESSAGE);
+ txLogger.trace(exceptionParams.getGroupId(), exceptionParams.getUnitId(), "TM report", REPORT_ERROR_MESSAGE);
}
}
+
+ public void reportTxcUndoException(String groupId, String unitId, List statementInfoList) {
+ TxExceptionParams exceptionParams = new TxExceptionParams();
+ exceptionParams.setGroupId(groupId);
+ exceptionParams.setUnitId(unitId);
+ exceptionParams.setRegistrar(TxExceptionParams.TXC_UNDO_ERROR);
+ exceptionParams.setTransactionState(0);
+ exceptionParams.setRemark(statementInfoList.toString());
+ report(exceptionParams);
+ }
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TMSearcher.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TMSearcher.java
index 7c10ea8b0..1041a4449 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TMSearcher.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/TMSearcher.java
@@ -17,6 +17,7 @@
import com.codingapi.txlcn.common.util.ApplicationInformation;
import com.codingapi.txlcn.common.util.Transactions;
+import com.codingapi.txlcn.common.util.id.ModIdProvider;
import com.codingapi.txlcn.txmsg.RpcClientInitializer;
import com.codingapi.txlcn.txmsg.dto.TxManagerHost;
import com.codingapi.txlcn.txmsg.exception.RpcException;
@@ -53,10 +54,9 @@ public class TMSearcher {
@Autowired
public TMSearcher(RpcClientInitializer rpcClientInitializer, TxClientConfig clientConfig,
- ReliableMessenger reliableMessenger, ConfigurableEnvironment environment,
- @Autowired(required = false) ServerProperties serverProperties) {
+ ReliableMessenger reliableMessenger, ModIdProvider modIdProvider) {
// 1. util class init
- Transactions.setApplicationIdWhenRunning(ApplicationInformation.modId(environment, serverProperties));
+ Transactions.setApplicationIdWhenRunning(modIdProvider.modId());
// 2. TMSearcher init
RPC_CLIENT_INITIALIZER = rpcClientInitializer;
@@ -78,6 +78,7 @@ public static void search() {
return;
}
clusterCountLatch = new CountDownLatch(cluster.size() - knownTMClusterSize);
+ log.debug("wait connect size is {}", cluster.size() - knownTMClusterSize);
RPC_CLIENT_INITIALIZER.init(TxManagerHost.parserList(new ArrayList<>(cluster)), true);
clusterCountLatch.await(10, TimeUnit.SECONDS);
echoTMClusterSuccessful();
@@ -88,13 +89,14 @@ public static void search() {
/**
* 搜索到一个
+ * @return is searched one
*/
public static boolean searchedOne() {
if (Objects.nonNull(clusterCountLatch)) {
if (clusterCountLatch.getCount() == 0) {
- clusterCountLatch.countDown();
return false;
}
+ clusterCountLatch.countDown();
return true;
}
return false;
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/DefaultNotifiedUnitService.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/DefaultNotifiedUnitService.java
index 11cbaedcd..513400080 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/DefaultNotifiedUnitService.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/DefaultNotifiedUnitService.java
@@ -17,7 +17,6 @@
import com.codingapi.txlcn.common.exception.TransactionClearException;
import com.codingapi.txlcn.common.exception.TxClientException;
-import com.codingapi.txlcn.common.util.Transactions;
import com.codingapi.txlcn.logger.TxLogger;
import com.codingapi.txlcn.txmsg.params.NotifyUnitParams;
import com.codingapi.txlcn.tc.txmsg.RpcExecuteService;
@@ -37,16 +36,14 @@
*/
public class DefaultNotifiedUnitService implements RpcExecuteService {
- private final TransactionCleanTemplate transactionCleanTemplate;
+ private static final TxLogger txLogger = TxLogger.newLogger(DefaultNotifiedUnitService.class);
- private final TxLogger txLogger;
+ private final TransactionCleanTemplate transactionCleanTemplate;
private TCGlobalContext globalContext;
- public DefaultNotifiedUnitService(TransactionCleanTemplate transactionCleanTemplate,
- TxLogger txLogger, TCGlobalContext globalContext) {
+ public DefaultNotifiedUnitService(TransactionCleanTemplate transactionCleanTemplate, TCGlobalContext globalContext) {
this.transactionCleanTemplate = transactionCleanTemplate;
- this.txLogger = txLogger;
this.globalContext = globalContext;
}
@@ -58,7 +55,7 @@ public Serializable execute(TransactionCmd transactionCmd) throws TxClientExcept
TxContext txContext = globalContext.txContext(transactionCmd.getGroupId());
if (Objects.nonNull(txContext)) {
synchronized (txContext.getLock()) {
- txLogger.transactionInfo(transactionCmd.getGroupId(), notifyUnitParams.getUnitId(),
+ txLogger.txTrace(transactionCmd.getGroupId(), notifyUnitParams.getUnitId(),
"clean transaction cmd waiting for business code finish.");
txContext.getLock().wait();
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/DeleteAspectLogService.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/DeleteAspectLogService.java
new file mode 100644
index 000000000..3b18f045d
--- /dev/null
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/DeleteAspectLogService.java
@@ -0,0 +1,33 @@
+package com.codingapi.txlcn.tc.txmsg.transaction;
+
+import com.codingapi.txlcn.common.exception.TxClientException;
+import com.codingapi.txlcn.tc.corelog.aspect.AspectLogHelper;
+import com.codingapi.txlcn.tc.txmsg.RpcExecuteService;
+import com.codingapi.txlcn.tc.txmsg.TransactionCmd;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+
+/**
+ * Description:
+ * Date: 19-2-12 上午10:56
+ *
+ * @author ujued
+ */
+@Component("rpc_delete-aspect-log")
+public class DeleteAspectLogService implements RpcExecuteService {
+
+ private final AspectLogHelper aspectLogHelper;
+
+ @Autowired
+ public DeleteAspectLogService(AspectLogHelper aspectLogHelper) {
+ this.aspectLogHelper = aspectLogHelper;
+ }
+
+ @Override
+ public Serializable execute(TransactionCmd transactionCmd) throws TxClientException {
+ aspectLogHelper.delete(transactionCmd.getGroupId());
+ return null;
+ }
+}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/LcnNotifiedUnitService.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/LcnNotifiedUnitService.java
index 4f481ac1c..a52b4c83e 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/LcnNotifiedUnitService.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/LcnNotifiedUnitService.java
@@ -33,8 +33,7 @@
public class LcnNotifiedUnitService extends DefaultNotifiedUnitService {
@Autowired
- public LcnNotifiedUnitService(TransactionCleanTemplate transactionCleanTemplate,
- TCGlobalContext context, TxLogger txLogger) {
- super(transactionCleanTemplate, txLogger, context);
+ public LcnNotifiedUnitService(TransactionCleanTemplate transactionCleanTemplate, TCGlobalContext context) {
+ super(transactionCleanTemplate, context);
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/TccNotifiedUnitService.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/TccNotifiedUnitService.java
index 7591578e8..0a50b7aba 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/TccNotifiedUnitService.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/TccNotifiedUnitService.java
@@ -33,8 +33,7 @@
public class TccNotifiedUnitService extends DefaultNotifiedUnitService {
@Autowired
- public TccNotifiedUnitService(TransactionCleanTemplate transactionCleanTemplate,
- TCGlobalContext context, TxLogger txLogger) {
- super(transactionCleanTemplate, txLogger, context);
+ public TccNotifiedUnitService(TransactionCleanTemplate transactionCleanTemplate, TCGlobalContext context) {
+ super(transactionCleanTemplate, context);
}
}
diff --git a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/TxcNotifiedUnitService.java b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/TxcNotifiedUnitService.java
index 5c3b1a267..b51526085 100644
--- a/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/TxcNotifiedUnitService.java
+++ b/txlcn-tc/src/main/java/com/codingapi/txlcn/tc/txmsg/transaction/TxcNotifiedUnitService.java
@@ -15,7 +15,6 @@
*/
package com.codingapi.txlcn.tc.txmsg.transaction;
-import com.codingapi.txlcn.logger.TxLogger;
import com.codingapi.txlcn.tc.core.context.TCGlobalContext;
import com.codingapi.txlcn.tc.core.template.TransactionCleanTemplate;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,8 +30,7 @@
public class TxcNotifiedUnitService extends DefaultNotifiedUnitService {
@Autowired
- public TxcNotifiedUnitService(TransactionCleanTemplate transactionCleanTemplate,
- TCGlobalContext context, TxLogger txLogger) {
- super(transactionCleanTemplate, txLogger, context);
+ public TxcNotifiedUnitService(TransactionCleanTemplate transactionCleanTemplate, TCGlobalContext context) {
+ super(transactionCleanTemplate, context);
}
}
diff --git a/txlcn-tc/src/main/resources/banner.txt b/txlcn-tc/src/main/resources/banner.txt
index f7831994f..c178d6e08 100644
--- a/txlcn-tc/src/main/resources/banner.txt
+++ b/txlcn-tc/src/main/resources/banner.txt
@@ -7,4 +7,4 @@ ${AnsiColor.BRIGHT_GREEN}
| | / /^\ \ | |___| \__/\| |\ |
\_/ \/ \/ \_____/\____/\_| \_/
- TX-LCN TxClient version:5.0.1.RELEASE
+ TC version:5.0.2.RELEASE
diff --git a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/MiniConfiguration.java b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/MiniConfiguration.java
index fc0cf9f4b..3d655ae88 100644
--- a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/MiniConfiguration.java
+++ b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/MiniConfiguration.java
@@ -17,6 +17,7 @@
import com.codingapi.txlcn.tc.config.EnableDistributedTransaction;
import com.zaxxer.hikari.HikariDataSource;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
diff --git a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/RunTest.java b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/RunTest.java
new file mode 100644
index 000000000..e625bb036
--- /dev/null
+++ b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/RunTest.java
@@ -0,0 +1,22 @@
+package com.codingapi.txlcn.tc;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * Description:
+ * Date: 19-2-20 下午4:24
+ *
+ * @author ujued
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = {MiniConfiguration.class, TCAutoConfiguration.class})
+public class RunTest {
+
+ @Test
+ public void testTxc() throws InterruptedException {
+ Thread.sleep(10000);
+ }
+}
diff --git a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/Test.java b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/Test.java
new file mode 100644
index 000000000..4cd6cc490
--- /dev/null
+++ b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/Test.java
@@ -0,0 +1,17 @@
+package com.codingapi.txlcn.tc;
+
+import com.codingapi.txlcn.tc.core.transaction.txc.analy.util.SqlUtils;
+
+public class Test {
+ public static void main(String[] args) {
+
+ TestBean testBean = new TestBean();
+ System.out.println(testBean.getTime());
+ System.out.println(testBean.getTimestamp());
+ byte[] bytes = SqlUtils.objectToBlob(testBean);
+ TestBean testBean2 = SqlUtils.blobToObject(bytes,TestBean.class);
+ System.out.println("-----");
+ System.out.println(testBean2.getTime());
+ System.out.println(testBean2.getTimestamp());
+ }
+}
diff --git a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/TestBean.java b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/TestBean.java
new file mode 100644
index 000000000..b0f9492ed
--- /dev/null
+++ b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/TestBean.java
@@ -0,0 +1,33 @@
+package com.codingapi.txlcn.tc;
+
+import java.io.Serializable;
+import java.sql.Timestamp;
+import java.util.Date;
+
+public class TestBean implements Serializable {
+
+ private Date time;
+
+ private Timestamp timestamp;
+
+ public TestBean() {
+ this.time = new Date();
+ this.timestamp = new Timestamp(System.currentTimeMillis());
+ }
+
+ public Date getTime() {
+ return time;
+ }
+
+ public void setTime(Date time) {
+ this.time = time;
+ }
+
+ public Timestamp getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(Timestamp timestamp) {
+ this.timestamp = timestamp;
+ }
+}
diff --git a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/coprelog/AspectLogTest.java b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/coprelog/AspectLogTest.java
new file mode 100644
index 000000000..a0a8b94ac
--- /dev/null
+++ b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/coprelog/AspectLogTest.java
@@ -0,0 +1,37 @@
+package com.codingapi.txlcn.tc.coprelog;
+
+import com.codingapi.txlcn.common.util.id.RandomUtils;
+import com.codingapi.txlcn.tc.MiniConfiguration;
+import com.codingapi.txlcn.tc.aspect.TransactionInfo;
+import com.codingapi.txlcn.tc.corelog.aspect.AspectLogger;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * Description:
+ * Date: 19-2-12 上午10:06
+ *
+ * @author ujued
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = MiniConfiguration.class)
+public class AspectLogTest {
+
+ @Autowired
+ private AspectLogger aspectLogger;
+
+ @Test
+ public void testTrace() throws InterruptedException {
+ TransactionInfo transactionInfo = new TransactionInfo();
+ transactionInfo.setMethod("method");
+ transactionInfo.setMethodStr("method str");
+ transactionInfo.setParameterTypes(new Class[]{String.class, Integer.class});
+ transactionInfo.setTargetClazz(String.class);
+ transactionInfo.setArgumentValues(new Object[]{"1", 2});
+ aspectLogger.trace(RandomUtils.randomKey(), RandomUtils.randomKey(), transactionInfo);
+ Thread.sleep(1000);
+ }
+}
diff --git a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/coprelog/TxcLogTest.java b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/coprelog/TxcLogTest.java
new file mode 100644
index 000000000..10b0c9afc
--- /dev/null
+++ b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/coprelog/TxcLogTest.java
@@ -0,0 +1,17 @@
+package com.codingapi.txlcn.tc.coprelog;
+
+import com.codingapi.txlcn.tc.MiniConfiguration;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * Description:
+ * Date: 19-2-12 上午10:06
+ *
+ * @author ujued
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = MiniConfiguration.class)
+public class TxcLogTest {
+}
diff --git a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/TxcTest.java b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/txc/TxcTest.java
similarity index 93%
rename from txlcn-tc/src/test/java/com/codingapi/txlcn/tc/TxcTest.java
rename to txlcn-tc/src/test/java/com/codingapi/txlcn/tc/txc/TxcTest.java
index 466bed878..ae737c009 100644
--- a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/TxcTest.java
+++ b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/txc/TxcTest.java
@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.codingapi.txlcn.tc;
+package com.codingapi.txlcn.tc.txc;
+import com.codingapi.txlcn.tc.MiniConfiguration;
+import com.codingapi.txlcn.tc.TCAutoConfiguration;
import org.apache.commons.dbutils.QueryRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/RpcTest.java b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/txmsg/RpcTest.java
similarity index 97%
rename from txlcn-tc/src/test/java/com/codingapi/txlcn/tc/RpcTest.java
rename to txlcn-tc/src/test/java/com/codingapi/txlcn/tc/txmsg/RpcTest.java
index 76e1f5b8b..aa1d6190e 100644
--- a/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/RpcTest.java
+++ b/txlcn-tc/src/test/java/com/codingapi/txlcn/tc/txmsg/RpcTest.java
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.codingapi.txlcn.tc;
+package com.codingapi.txlcn.tc.txmsg;
import com.codingapi.txlcn.common.lock.DTXLocks;
+import com.codingapi.txlcn.tc.MiniConfiguration;
import com.codingapi.txlcn.txmsg.dto.MessageDto;
import com.codingapi.txlcn.txmsg.exception.RpcException;
import com.codingapi.txlcn.tc.txmsg.ReliableMessenger;
@@ -93,9 +94,6 @@ public void testCluster() throws RpcException {
messenger.request(new MessageDto());
}
- @Test
- public void testTxc() {
- }
}
diff --git a/txlcn-tm/pom.xml b/txlcn-tm/pom.xml
index b2d773ce4..15fc0ddff 100644
--- a/txlcn-tm/pom.xml
+++ b/txlcn-tm/pom.xml
@@ -6,11 +6,11 @@
com.codingapi.txlcn
tx-lcn
- 5.0.1.RELEASE
+ 5.0.2.RELEASE
txlcn-tm
- 5.0.1.RELEASE
+ 5.0.2.RELEASE
jar
@@ -30,7 +30,6 @@
txlcn-txmsg-netty
-
org.springframework.boot
spring-boot-starter-web
@@ -46,19 +45,14 @@
spring-boot-starter-mail
-
- org.mybatis.spring.boot
- mybatis-spring-boot-starter
-
-
mysql
mysql-connector-java
- com.github.pagehelper
- pagehelper-spring-boot-starter
+ org.springframework.boot
+ spring-boot-starter-data-jpa
@@ -107,10 +101,30 @@
+
- org.springframework.boot
- spring-boot-maven-plugin
+ com.spotify
+ docker-maven-plugin
+ 1.0.0
+
+ codingapi/txlcn-tm
+ ${project.basedir}/src/main/docker
+
+
+ /
+ ${project.build.directory}
+ ${project.build.finalName}.jar
+
+
+
+ 5.0.2
+
+
+ docker-hub
+ https://index.docker.io/v1/
+
+
-
\ No newline at end of file
+
diff --git a/txlcn-tm/src/main/docker/Dockerfile b/txlcn-tm/src/main/docker/Dockerfile
new file mode 100644
index 000000000..10107d51a
--- /dev/null
+++ b/txlcn-tm/src/main/docker/Dockerfile
@@ -0,0 +1,5 @@
+FROM frolvlad/alpine-oraclejdk8:slim
+RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone
+COPY txlcn-tm-5.0.2.RELEASE.jar tm.jar
+EXPOSE 7970 8070
+ENTRYPOINT ["java", "-jar", "/tm.jar"]
diff --git a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/TMAutoConfiguration.java b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/TMAutoConfiguration.java
index c41f0dc10..9de510945 100644
--- a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/TMAutoConfiguration.java
+++ b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/TMAutoConfiguration.java
@@ -16,6 +16,8 @@
package com.codingapi.txlcn.tm;
import com.codingapi.txlcn.common.runner.TxLcnApplicationRunner;
+import com.codingapi.txlcn.common.util.ApplicationInformation;
+import com.codingapi.txlcn.common.util.id.ModIdProvider;
import com.codingapi.txlcn.logger.TxLoggerConfiguration;
import com.codingapi.txlcn.txmsg.MessageConfiguration;
import com.codingapi.txlcn.tm.config.TxManagerConfig;
@@ -23,11 +25,16 @@
import com.codingapi.txlcn.tm.core.storage.FastStorageProvider;
import com.codingapi.txlcn.tm.core.storage.redis.RedisStorage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.client.RestTemplate;
@@ -44,7 +51,10 @@
* @author ujued
*/
@Configuration
+@ComponentScan
@Import({TxLoggerConfiguration.class, MessageConfiguration.class})
+@EnableJpaRepositories("com.codingapi.txlcn.tm.support.db.jpa")
+@EntityScan("com.codingapi.txlcn.tm.support.db.domain")
public class TMAutoConfiguration {
@Bean(destroyMethod = "shutdown")
@@ -84,4 +94,10 @@ public FastStorage fastStorage(FastStorageProvider fastStorageProvider) {
public TxLcnApplicationRunner txLcnApplicationRunner(ApplicationContext applicationContext) {
return new TxLcnApplicationRunner(applicationContext);
}
+
+ @Bean
+ @ConditionalOnMissingBean
+ public ModIdProvider modIdProvider(ConfigurableEnvironment environment, ServerProperties serverProperties) {
+ return () -> ApplicationInformation.modId(environment, serverProperties);
+ }
}
diff --git a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/cluster/TMAutoCluster.java b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/cluster/TMAutoCluster.java
index ac1884a26..96dd43b29 100644
--- a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/cluster/TMAutoCluster.java
+++ b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/cluster/TMAutoCluster.java
@@ -27,11 +27,13 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;
import java.net.ConnectException;
import java.util.List;
+import java.util.stream.Collectors;
/**
* Description:
@@ -66,7 +68,10 @@ public TMAutoCluster(FastStorage fastStorage, RestTemplate restTemplate, TxManag
public void init() throws Exception {
// 1. 通知 TC 建立连接
- List tmList = fastStorage.findTMProperties();
+ List tmList = fastStorage.findTMProperties().stream()
+ .filter(tmProperties ->
+ !tmProperties.getHost().equals(txManagerConfig.getHost()) || !tmProperties.getTransactionPort().equals(txManagerConfig.getPort()))
+ .collect(Collectors.toList());
for (TMProperties properties : tmList) {
NotifyConnectParams notifyConnectParams = new NotifyConnectParams();
notifyConnectParams.setHost(txManagerConfig.getHost());
@@ -94,11 +99,18 @@ public void init() throws Exception {
}
// 2. 保存TM 到快速存储
- TMProperties tmProperties = new TMProperties();
- tmProperties.setHttpPort(ApplicationInformation.serverPort(serverProperties));
- tmProperties.setHost(txManagerConfig.getHost());
- tmProperties.setTransactionPort(txManagerConfig.getPort());
- fastStorage.saveTMProperties(tmProperties);
+ if (StringUtils.hasText(txManagerConfig.getHost())) {
+ TMProperties tmProperties = new TMProperties();
+ tmProperties.setHttpPort(ApplicationInformation.serverPort(serverProperties));
+ tmProperties.setHost(txManagerConfig.getHost());
+ tmProperties.setTransactionPort(txManagerConfig.getPort());
+ fastStorage.saveTMProperties(tmProperties);
+ }
+ }
+
+ @Override
+ public void destroy() throws Exception {
+ fastStorage.removeTMProperties(txManagerConfig.getHost(), txManagerConfig.getPort());
}
@Override
diff --git a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/config/EnableTransactionManagerServer.java b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/config/EnableTransactionManagerServer.java
new file mode 100644
index 000000000..cb0d9caba
--- /dev/null
+++ b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/config/EnableTransactionManagerServer.java
@@ -0,0 +1,19 @@
+package com.codingapi.txlcn.tm.config;
+
+import com.codingapi.txlcn.tm.TMAutoConfiguration;
+import org.springframework.context.annotation.Import;
+
+import java.lang.annotation.*;
+
+/**
+ * Description:
+ * Date: 19-2-15 下午5:25
+ *
+ * @author ujued
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Documented
+@Import(value = {TMAutoConfiguration.class})
+public @interface EnableTransactionManagerServer {
+}
diff --git a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/config/TxManagerConfig.java b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/config/TxManagerConfig.java
index b965a075a..ff8de5b13 100644
--- a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/config/TxManagerConfig.java
+++ b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/config/TxManagerConfig.java
@@ -41,8 +41,6 @@ public class TxManagerConfig {
public TxManagerConfig(ServerProperties serverProperties) {
this.port = Objects.requireNonNull(serverProperties.getPort(), "TM http port not configured?") +
PORT_CHANGE_VALUE;
- this.adminKey = "codingapi";
- this.exUrl = "/provider/email-to/ujued@qq.com";
}
/**
@@ -73,12 +71,12 @@ public TxManagerConfig(ServerProperties serverProperties) {
/**
* 分布式事务超时时间(ms)
*/
- private long dtxTime = 36 * 1000;
+ private long dtxTime = 8 * 1000;
/**
* 后台密码
*/
- private String adminKey;
+ private String adminKey = "codingapi";
/**
* 是否允许异常回调
@@ -88,13 +86,23 @@ public TxManagerConfig(ServerProperties serverProperties) {
/**
* 异常回调地址
*/
- private String exUrl;
+ private String exUrl = "/provider/email-to/ujued@qq.com";
/**
* ID序列长度
*/
private int seqLen = 12;
+ private long machineId;
+
+ private void setMachineId(long machineId) {
+ this.machineId = machineId;
+ }
+
+ public void applyMachineId(long machineId) {
+ setMachineId(machineId);
+ }
+
public long getDtxLockTime() {
return dtxLockTime == -1 ? dtxTime : dtxLockTime;
}
diff --git a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/DTXContext.java b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/DTXContext.java
index fc49eea75..631730086 100644
--- a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/DTXContext.java
+++ b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/DTXContext.java
@@ -47,7 +47,7 @@ public interface DTXContext {
void resetTransactionState(int state) throws TransactionException;
/**
- * 获取该事务组事务单元列表
+ * 获取该事务组事务单元列表。从FastStorage获取。
*
* @return list
* @throws TransactionException TransactionException
diff --git a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/DefaultDTXContext.java b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/DefaultDTXContext.java
index c28e31650..88fdc1cbd 100644
--- a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/DefaultDTXContext.java
+++ b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/DefaultDTXContext.java
@@ -45,7 +45,8 @@ public void join(TransactionUnit transactionUnit) throws TransactionException {
try {
fastStorage.saveTransactionUnitToGroup(groupId, transactionUnit);
} catch (FastStorageException e) {
- throw new TransactionException("attempts to join the non-existent transaction group.");
+ throw new TransactionException("attempts to join the non-existent transaction group. ["
+ + transactionUnit.getUnitId() + '@' + transactionUnit.getModId() + ']');
}
}
diff --git a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/SimpleTransactionManager.java b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/SimpleTransactionManager.java
index 1f899306b..7fe4ae2cb 100644
--- a/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/SimpleTransactionManager.java
+++ b/txlcn-tm/src/main/java/com/codingapi/txlcn/tm/core/SimpleTransactionManager.java
@@ -44,23 +44,22 @@
@Component
public class SimpleTransactionManager implements TransactionManager {
+ private static final TxLogger txLogger = TxLogger.newLogger(SimpleTransactionManager.class);
+
private final RpcExceptionHandler rpcExceptionHandler;
private final RpcClient rpcClient;
- private final TxLogger txLogger;
-
private final TxExceptionService exceptionService;
private final DTXContextRegistry dtxContextRegistry;
@Autowired
- public SimpleTransactionManager(RpcExceptionHandler rpcExceptionHandler, RpcClient rpcClient, TxLogger txLogger,
+ public SimpleTransactionManager(RpcExceptionHandler rpcExceptionHandler, RpcClient rpcClient,
TxExceptionService exceptionService, DTXContextRegistry dtxContextRegistry) {
this.rpcExceptionHandler = rpcExceptionHandler;
this.exceptionService = exceptionService;
this.rpcClient = rpcClient;
- this.txLogger = txLogger;
this.dtxContextRegistry = dtxContextRegistry;
}
@@ -75,7 +74,6 @@ public void begin(String groupId) throws TransactionException {
@Override
public void join(DTXContext dtxContext, String unitId, String unitType, String modId, int userState) throws TransactionException {
- log.debug("unit:{} joined group:{}", unitId, dtxContext.getGroupId());
//手动回滚时设置状态为回滚状态 0
if (userState == 0) {
dtxContext.resetTransactionState(0);
@@ -118,14 +116,15 @@ public int transactionStateFromFastStorage(String groupId) {
}
private void notifyTransaction(DTXContext dtxContext, int transactionState) throws TransactionException {
- for (TransactionUnit transUnit : dtxContext.transactionUnits()) {
+ List transactionUnits = dtxContext.transactionUnits();
+ log.debug("group[{}]'s transaction units: {}", dtxContext.getGroupId(), transactionUnits);
+ for (TransactionUnit transUnit : transactionUnits) {
NotifyUnitParams notifyUnitParams = new NotifyUnitParams();
notifyUnitParams.setGroupId(dtxContext.getGroupId());
notifyUnitParams.setUnitId(transUnit.getUnitId());
notifyUnitParams.setUnitType(transUnit.getUnitType());
notifyUnitParams.setState(transactionState);
- txLogger.info(dtxContext.getGroupId(),
- notifyUnitParams.getUnitId(), Transactions.TAG_TRANSACTION, "notify %s's unit: %s",
+ txLogger.txTrace(dtxContext.getGroupId(), notifyUnitParams.getUnitId(), "notify {}'s unit: {}",
transUnit.getModId(), transUnit.getUnitId());
try {
List modChannelKeys = rpcClient.remoteKeys(transUnit.getModId());
@@ -145,7 +144,7 @@ private void notifyTransaction(DTXContext dtxContext, int transactionState) thro
List