This is an automated email from the ASF dual-hosted git repository. jianbin pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/develop by this push: new 4368ebc8dc bugfix: fix cache scheduled refresh issue (#6661) (#6663) 4368ebc8dc is described below commit 4368ebc8dc0391c2abe0d2b6df3566bbee3b0a92 Author: wuwen <wuwen...@aliyun.com> AuthorDate: Wed Jul 10 13:40:34 2024 +0800 bugfix: fix cache scheduled refresh issue (#6661) (#6663) --- changes/en-us/develop.md | 3 ++- changes/zh-cn/develop.md | 2 ++ .../rm/datasource/sql/struct/TableMetaCacheFactory.java | 14 +++++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/changes/en-us/develop.md b/changes/en-us/develop.md index 44801bc04e..e29d625f6e 100644 --- a/changes/en-us/develop.md +++ b/changes/en-us/develop.md @@ -15,6 +15,7 @@ Add changes here for all PR submitted to the develop branch. - [[#6409](https://github.com/seata/seata/pull/6409)] fix the failure of RemotingParser to prevent AT mode from executing. - [[#6628](https://github.com/seata/seata/pull/6628)] fix Alibaba Dubbo convert error. - [[#6632](https://github.com/seata/seata/pull/6632)] fix hsf ConsumerModel convert error. +- [[#6661](https://github.com/seata/seata/pull/6661)] fix `tableMeta` cache scheduled refresh issue ### optimize: - [[#6044](https://github.com/seata/seata/pull/6044)] optimize derivative product check base on mysql @@ -35,6 +36,6 @@ Thanks to these contributors for their code commits. Please report an unintended - [ptyin](https://github.com/ptyin) - [funky-eyes](https://github.com/funky-eyes) - [laywin](https://github.com/laywin) - +- [wuwen5](https://github.com/wuwen5) Also, we receive many valuable issues, questions and advices from our community. Thanks for you all. diff --git a/changes/zh-cn/develop.md b/changes/zh-cn/develop.md index 1320e42f5c..b8e5a9b844 100644 --- a/changes/zh-cn/develop.md +++ b/changes/zh-cn/develop.md @@ -15,6 +15,7 @@ - [[#6409](https://github.com/seata/seata/pull/6409)] 修复 RemotingParser 失败导致 AT 模式无法执行的问题 - [[#6628](https://github.com/seata/seata/pull/6628)] 修复 Alibaba Dubbo 转换错误 - [[#6632](https://github.com/seata/seata/pull/6632)] 修复 hsf ConsumerModel 转换错误 +- [[#6661](https://github.com/seata/seata/pull/6661)] 修复`tableMeta`缓存定时刷新失效问题 ### optimize: - [[#6044](https://github.com/seata/seata/pull/6044)] 优化MySQL衍生数据库判断逻辑 @@ -35,5 +36,6 @@ - [ptyin](https://github.com/ptyin) - [funky-eyes](https://github.com/funky-eyes) - [laywin](https://github.com/laywin) +- [wuwen5](https://github.com/wuwen5) 同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。 diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMetaCacheFactory.java b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMetaCacheFactory.java index 848ce37808..f5c297cdd3 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMetaCacheFactory.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableMetaCacheFactory.java @@ -93,7 +93,7 @@ public class TableMetaCacheFactory { */ public static void tableMetaRefreshEvent(String resourceId) { TableMetaRefreshHolder refreshHolder = TABLE_META_REFRESH_HOLDER_MAP.get(resourceId); - boolean offer = refreshHolder.tableMetaRefreshQueue.offer(System.currentTimeMillis()); + boolean offer = refreshHolder.tableMetaRefreshQueue.offer(System.nanoTime()); if (!offer) { LOGGER.error("table refresh event offer error:{}", resourceId); } @@ -110,28 +110,28 @@ public class TableMetaCacheFactory { TableMetaRefreshHolder(DataSourceProxy dataSource) { this.dataSource = dataSource; - this.lastRefreshFinishTime = System.currentTimeMillis() - TABLE_META_REFRESH_INTERVAL_TIME; + this.lastRefreshFinishTime = System.nanoTime() - TimeUnit.MILLISECONDS.toNanos(TABLE_META_REFRESH_INTERVAL_TIME); this.tableMetaRefreshQueue = new LinkedBlockingQueue<>(MAX_QUEUE_SIZE); tableMetaRefreshExecutor.execute(() -> { while (true) { // 1. check table meta - if (ENABLE_TABLE_META_CHECKER_ENABLE - && System.currentTimeMillis() - lastRefreshFinishTime > TABLE_META_CHECKER_INTERVAL) { + if (ENABLE_TABLE_META_CHECKER_ENABLE + && System.nanoTime() - lastRefreshFinishTime > TimeUnit.MILLISECONDS.toNanos(TABLE_META_CHECKER_INTERVAL)) { tableMetaRefreshEvent(dataSource.getResourceId()); } // 2. refresh table meta try { - Long eventTime = tableMetaRefreshQueue.take(); + Long eventTime = tableMetaRefreshQueue.poll(TABLE_META_REFRESH_INTERVAL_TIME, TimeUnit.MILLISECONDS); // if it has bean refreshed not long ago, skip - if (eventTime - lastRefreshFinishTime > TABLE_META_REFRESH_INTERVAL_TIME) { + if (eventTime != null && eventTime - lastRefreshFinishTime > TimeUnit.MILLISECONDS.toNanos(TABLE_META_REFRESH_INTERVAL_TIME)) { try (Connection connection = dataSource.getConnection()) { TableMetaCache tableMetaCache = TableMetaCacheFactory.getTableMetaCache(dataSource.getDbType()); tableMetaCache.refresh(connection, dataSource.getResourceId()); } - lastRefreshFinishTime = System.currentTimeMillis(); + lastRefreshFinishTime = System.nanoTime(); } } catch (Exception exx) { LOGGER.error("table refresh error:{}", exx.getMessage(), exx); --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org