Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: support oracle on delete tccfence logs #5124

Merged
merged 5 commits into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/en-us/develop.md
Expand Up @@ -74,6 +74,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#5051](https://github.com/seata/seata/pull/5051)] undo log dirty throw BranchRollbackFailed_Unretriable
- [[#5075](https://github.com/seata/seata/pull/5075)] intercept the InsertOnDuplicateUpdate statement which has no primary key and unique index value
- [[#5104](https://github.com/seata/seata/pull/5104)] remove the druid dependency in ConnectionProxy
- [[#5124](https://github.com/seata/seata/pull/5124)] support oracle on delete tccfence logs


### test:
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/develop.md
Expand Up @@ -73,6 +73,7 @@
- [[#5051](https://github.com/seata/seata/pull/5051)] 回滚时undolog产生脏写需要抛出不再重试(BranchRollbackFailed_Unretriable)的异常
- [[#5075](https://github.com/seata/seata/pull/5075)] 拦截没有主键及唯一索引值的insert on duplicate update语句
- [[#5104](https://github.com/seata/seata/pull/5104)] ConnectionProxy脱离对druid的依赖
- [[#5124](https://github.com/seata/seata/pull/5124)] 支持oracle删除tccfence记录表

### test:
- [[#4411](https://github.com/seata/seata/pull/4411)] 测试Oracle数据库AT模式下类型支持
Expand Down
17 changes: 17 additions & 0 deletions tcc/src/main/java/io/seata/rm/tcc/TCCFenceHandler.java
Expand Up @@ -17,6 +17,7 @@

import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Set;
Expand Down Expand Up @@ -294,6 +295,12 @@ public static int deleteFenceByDate(Date datetime) {
int total = 0;
try {
connection = DataSourceUtils.getConnection(dataSource);
if (isOracle(connection)) {
// delete by date if DB is oracle
return TCC_FENCE_DAO.deleteTCCFenceDOByDate(connection, datetime);
}

//delete by id if DB is not oracle
while (true) {
Set<String> xidSet = TCC_FENCE_DAO.queryEndStatusXidsByDate(connection, datetime, LIMIT_DELETE);
if (xidSet.isEmpty()) {
Expand All @@ -312,6 +319,16 @@ public static int deleteFenceByDate(Date datetime) {

}

private static boolean isOracle(Connection connection) {
wangliang181230 marked this conversation as resolved.
Show resolved Hide resolved
try {
String url = connection.getMetaData().getURL();
return url.toLowerCase().contains(":oracle:");
} catch (SQLException e) {
LOGGER.error("get db type fail", e);
}
return false;
}

private static void initLogCleanExecutor() {
logCleanExecutor = new ThreadPoolExecutor(MAX_THREAD_CLEAN, MAX_THREAD_CLEAN, Integer.MAX_VALUE,
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(),
Expand Down
4 changes: 2 additions & 2 deletions tcc/src/main/java/io/seata/rm/tcc/store/TCCFenceStore.java
Expand Up @@ -85,10 +85,10 @@ public interface TCCFenceStore {
* Delete tcc fence by datetime.
* @param conn the connection
* @param datetime datetime
* @param limit limit
* @return the deleted row count
*/
int deleteTCCFenceDOByDate(Connection conn, Date datetime, int limit);
int deleteTCCFenceDOByDate(Connection conn, Date datetime);


/**
* Set LogTable Name
Expand Down
Expand Up @@ -192,13 +192,12 @@ public int deleteTCCFenceDO(Connection conn, List<String> xids) {
}

@Override
public int deleteTCCFenceDOByDate(Connection conn, Date datetime, int limit) {
public int deleteTCCFenceDOByDate(Connection conn, Date datetime) {
PreparedStatement ps = null;
try {
String sql = TCCFenceStoreSqls.getDeleteSQLByDateAndStatus(logTableName);
ps = conn.prepareStatement(sql);
ps.setTimestamp(1, new Timestamp(datetime.getTime()));
ps.setInt(2, limit);
return ps.executeUpdate();
} catch (SQLException e) {
throw new StoreException(e);
Expand Down
Expand Up @@ -84,8 +84,7 @@ private TCCFenceStoreSqls() {
*/
protected static final String DELETE_BY_DATE_AND_STATUS = "delete from " + LOCAL_TCC_LOG_PLACEHOLD
+ " where gmt_modified < ? "
+ " and status in (" + TCCFenceConstant.STATUS_COMMITTED + " , " + TCCFenceConstant.STATUS_ROLLBACKED + " , " + TCCFenceConstant.STATUS_SUSPENDED + ")"
+ " limit ?";
+ " and status in (" + TCCFenceConstant.STATUS_COMMITTED + " , " + TCCFenceConstant.STATUS_ROLLBACKED + " , " + TCCFenceConstant.STATUS_SUSPENDED + ")";

public static String getInsertLocalTCCLogSQL(String localTccTable) {
return INSERT_LOCAL_TCC_LOG.replace(LOCAL_TCC_LOG_PLACEHOLD, localTccTable);
Expand Down