Skip to content

Commit

Permalink
Merge branch '2.x' of https://github.com/seata/seata into 2024/mq-npe
Browse files Browse the repository at this point in the history
# Conflicts:
#	changes/en-us/2.x.md
#	changes/zh-cn/2.x.md
  • Loading branch information
Bughue committed Dec 4, 2024
2 parents 55ed7d8 + 6cdb847 commit d9697cd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
2 changes: 2 additions & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7010](https://github.com/apache/incubator-seata/pull/7010)] fix error while the "context" is key word in DM8 when delete undolog
- [[#7022](https://github.com/apache/incubator-seata/pull/7022)] fix `store.mode` property in `application.raft.example.yml`
- [[#7025](https://github.com/apache/incubator-seata/pull/7025)] fix vGroupMappingManager is NOT init
- [[#7044](https://github.com/apache/incubator-seata/pull/7044)] fix tableMeta refresh after closed
-
### optimize:
- [[#6826](https://github.com/apache/incubator-seata/pull/6826)] remove the branch registration operation of the XA read-only transaction
Expand Down Expand Up @@ -57,6 +58,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7027](https://github.com/apache/incubator-seata/pull/7027)] raft mode maintains the reload logic consistent with the file
- [[#6891](https://github.com/apache/incubator-seata/pull/6891)] add StateType Enum
- [[#7040](https://github.com/apache/incubator-seata/pull/7040)] optimize the print info in ConfigurationFactory
- [[#7046](https://github.com/apache/incubator-seata/pull/7046)] remove the dependency conflict for spring-webmvc
- [[#7043](https://github.com/apache/incubator-seata/pull/7043)] finish rollback if sendResult/msg not found

### refactor:
Expand Down
2 changes: 2 additions & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- [[#7010](https://github.com/apache/incubator-seata/pull/7010)] 修复使用达梦数据库时删除undolog发生SQL语法错误
- [[#7022](https://github.com/apache/incubator-seata/pull/7022)] 修复 `application.raft.example.yml``store.mode`属性
- [[#7025](https://github.com/apache/incubator-seata/pull/7025)] 修复vGroupMappingManager未初始化的问题
- [[#7044](https://github.com/apache/incubator-seata/pull/7044)] 修复TableMeta在数据源关闭后刷新错误问题

### optimize:
- [[#6826](https://github.com/apache/incubator-seata/pull/6826)] 移除只读XA事务的分支注册操作
Expand Down Expand Up @@ -60,6 +61,7 @@
- [[#7027](https://github.com/apache/incubator-seata/pull/7027)] raft模式下reload行为与file保持一致
- [[#6891](https://github.com/apache/incubator-seata/pull/6891)] 增加 StateType 类型
- [[#7040](https://github.com/apache/incubator-seata/pull/7040)] 优化ConfigurationFactory加载的打印信息
- [[#7046](https://github.com/apache/incubator-seata/pull/7046)] 去除spring-webmvc的依赖冲突
- [[#7043](https://github.com/apache/incubator-seata/pull/7043)] 在获取不到mq的sendResult时,直接完成回滚

### refactor:
Expand Down
7 changes: 0 additions & 7 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
<kotlin-coroutines.version>1.7.3</kotlin-coroutines.version>

<!-- # for web -->
<spring-webmvc.version>5.3.26</spring-webmvc.version>
<tomcat-embed.version>9.0.90</tomcat-embed.version>

<!-- # for test -->
Expand Down Expand Up @@ -880,12 +879,6 @@
<version>${rocketmq-version}</version>
</dependency>

<!-- web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-webmvc.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.seata.rm.datasource.sql.struct;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -29,6 +30,7 @@
import org.apache.seata.common.loader.EnhancedServiceLoader;
import org.apache.seata.common.thread.NamedThreadFactory;
import org.apache.seata.common.util.CollectionUtils;
import org.apache.seata.common.util.StringUtils;
import org.apache.seata.config.ConfigurationFactory;
import org.apache.seata.rm.datasource.DataSourceProxy;
import org.apache.seata.sqlparser.struct.TableMetaCache;
Expand Down Expand Up @@ -99,6 +101,14 @@ public static void tableMetaRefreshEvent(String resourceId) {
}
}

/**
* Remove the TableMetaRefreshHolder from the map.
*/
private static void removeHolderFromMap(String resourceId) {
TABLE_META_REFRESH_HOLDER_MAP.remove(resourceId);
LOGGER.info("Removed TableMetaRefreshHolder for resourceId: {}", resourceId);
}

static class TableMetaRefreshHolder {
private long lastRefreshFinishTime;
private DataSourceProxy dataSource;
Expand Down Expand Up @@ -133,6 +143,16 @@ static class TableMetaRefreshHolder {
}
lastRefreshFinishTime = System.nanoTime();
}
} catch (SQLException ex) {
if (isDataSourceClosedException(ex)) {
LOGGER.info("DataSource is closed, exiting refresh task for resourceId: {}", dataSource.getResourceId());
removeHolderFromMap(dataSource.getResourceId());
return;
} else {
// other error, avoid high CPU usage due to infinite loops caused by database exceptions
LOGGER.error("Table refresh SQL error: {}", ex.getMessage(), ex);
lastRefreshFinishTime = System.nanoTime();
}
} catch (Exception exx) {
LOGGER.error("table refresh error:{}", exx.getMessage(), exx);
// Avoid high CPU usage due to infinite loops caused by database exceptions
Expand All @@ -142,7 +162,20 @@ static class TableMetaRefreshHolder {
});
}



/**
* Helper method to determine if the exception is caused by the data source being closed.
*
* @param ex the SQLException to check
* @return true if the exception indicates the data source is closed; false otherwise
*/
private boolean isDataSourceClosedException(SQLException ex) {
String message = ex.getMessage().toLowerCase();
String sqlState = ex.getSQLState();
// Most jdbc drivers use '08006' as the datasource close code.
if ("08006".equals(sqlState)) {
return true;
}
return StringUtils.isNotBlank(message) && message.contains("datasource") && message.contains("close");
}
}
}

0 comments on commit d9697cd

Please sign in to comment.