Skip to content

Commit

Permalink
Fix cache scheduled refresh issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwen5 committed Jul 9, 2024
1 parent feff649 commit 5b965de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 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 @@ -12,6 +12,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6627](https://github.com/apache/incubator-seata/pull/6627)] fix the issue of xaEnded not being reset
- [[#6626](https://github.com/apache/incubator-seata/pull/6626)] fix hsf ConsumerModel convert error
- [[#6642](https://github.com/apache/incubator-seata/pull/6642)] codecov token not found
- [[#6661](https://github.com/apache/incubator-seata/pull/6661)] fix `tableMeta` cache scheduled refresh issue

### optimize:
- [[#6499](https://github.com/apache/incubator-seata/pull/6499)] split the task thread pool for committing and rollbacking statuses
Expand Down Expand Up @@ -48,6 +49,7 @@ Thanks to these contributors for their code commits. Please report an unintended
- [ggbocoder](https://github.com/ggbocoder)
- [xjlgod](https://github.com/xjlgod)
- [xingfudeshi](https://github.com/xingfudeshi)
- [wuwen5](https://github.com/wuwen5)


Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
2 changes: 2 additions & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [[#6626](https://github.com/apache/incubator-seata/pull/6626)] 修复 hsf ConsumerModel 转换错误
- [[#6640](https://github.com/apache/incubator-seata/pull/6640)] 优化codecov相关配置
- [[#6642](https://github.com/apache/incubator-seata/pull/6642)] 修复codecov token找不到导致无法提交单测覆盖度报告
- [[#6661](https://github.com/apache/incubator-seata/pull/6661)] 修复`tableMeta`缓存定时刷新失效问题

### optimize:
- [[#6499](https://github.com/apache/incubator-seata/pull/6499)] 拆分 committing 和 rollbacking 状态的任务线程池
Expand Down Expand Up @@ -49,6 +50,7 @@
- [ggbocoder](https://github.com/ggbocoder)
- [xjlgod](https://github.com/xjlgod)
- [xingfudeshi](https://github.com/xingfudeshi)
- [wuwen5](https://github.com/wuwen5)


同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static void registerTableMeta(DataSourceProxy dataSourceProxy) {
*/
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);
}
Expand All @@ -110,28 +110,28 @@ static class TableMetaRefreshHolder {

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) {
&& 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);
Expand Down

0 comments on commit 5b965de

Please sign in to comment.