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

bugfix: fix cache scheduled refresh issue (#6661) #6663

Merged
merged 1 commit into from
Jul 10, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
2 changes: 2 additions & 0 deletions changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -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衍生数据库判断逻辑
Expand All @@ -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和建议,非常感谢大家。
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) {
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);
Expand Down
Loading