Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@YongGoose
Copy link
Member

@YongGoose YongGoose commented Jul 27, 2025

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

Ⅱ. Does this pull request fix one issue?

#7523

@codecov
Copy link

codecov bot commented Jul 27, 2025

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.03%. Comparing base (d1ae495) to head (e4e0473).
⚠️ Report is 1 commits behind head on 2.x.

Files with missing lines Patch % Lines
...m/datasource/sql/struct/TableMetaCacheFactory.java 83.33% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                2.x    #7559      +/-   ##
============================================
- Coverage     61.05%   61.03%   -0.02%     
+ Complexity      670      666       -4     
============================================
  Files          1316     1316              
  Lines         49804    49819      +15     
  Branches       5855     5858       +3     
============================================
+ Hits          30407    30408       +1     
- Misses        16689    16700      +11     
- Partials       2708     2711       +3     
Files with missing lines Coverage Δ
...rg/apache/seata/rm/datasource/DataSourceProxy.java 67.87% <100.00%> (+0.33%) ⬆️
...m/datasource/sql/struct/TableMetaCacheFactory.java 49.31% <83.33%> (+7.64%) ⬆️

... and 6 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

/**
* Shutdown all TableMetaRefreshHolder threads.
*/
public static void shutdown() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for us to use the publish-subscribe pattern, so that after the rm close message is published, TableMetaCache proceeds to shut down?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for us to use the publish-subscribe pattern, so that after the rm close message is published, TableMetaCache proceeds to shut down?

event

Something like this could work.

However, compared to explicitly calling the shutdown API when the RM is destroyed, I don’t see a significant advantage.

If we go with the approach where TableMetaCacheFactory implements a listener, we could consider making shutdown a private API.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When registering itself with the Seata-Server (TC), I believe that DataSourceProxy should proxy the close method. Upon closing, it should remove itself from both DefaultResourceManager and TableMetaCacheFactory. Currently, TableMetaCacheFactory#removeHolderFromMap is executed passively—only when refreshing table metadata encounters an exception due to a closed datasource does the removal occur. This approach, however, feels inelegant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When registering itself with the Seata-Server (TC), I believe that DataSourceProxy should proxy the close method. Upon closing, it should remove itself from both DefaultResourceManager and TableMetaCacheFactory. Currently, TableMetaCacheFactory#removeHolderFromMap is executed passively—only when refreshing table metadata encounters an exception due to a closed datasource does the removal occur. This approach, however, feels inelegant.

  • Out of curiosity, I don't seem to see any class that actually implements org.apache.seata.core.model.ResourceManager#unregisterResource(org.apache.seata.core.model.Resource).
org.apache.seata.common.exception.NotSupportYetException: unregister a resource
	at org.apache.seata.rm.datasource.DataSourceManager.unregisterResource(DataSourceManager.java:96)
	at org.apache.seata.rm.DefaultResourceManager.unregisterResource(DefaultResourceManager.java:125)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When registering itself with the Seata-Server (TC), I believe that DataSourceProxy should proxy the close method. Upon closing, it should remove itself from both DefaultResourceManager and TableMetaCacheFactory. Currently, TableMetaCacheFactory#removeHolderFromMap is executed passively—only when refreshing table metadata encounters an exception due to a closed datasource does the removal occur. This approach, however, feels inelegant.

  • Out of curiosity, I don't seem to see any class that actually implements org.apache.seata.core.model.ResourceManager#unregisterResource(org.apache.seata.core.model.Resource).
org.apache.seata.common.exception.NotSupportYetException: unregister a resource
	at org.apache.seata.rm.datasource.DataSourceManager.unregisterResource(DataSourceManager.java:96)
	at org.apache.seata.rm.DefaultResourceManager.unregisterResource(DefaultResourceManager.java:125)

Yes, that’s why we need to actually perform the unregisterResource operation on it.

Copy link
Member Author

@YongGoose YongGoose Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that’s why we need to actually perform the unregisterResource operation on it.

Shall we handle this together in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that’s why we need to actually perform the unregisterResource operation on it.

Shall we handle this together in this PR?

Ok

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please let me know if there’s anything I’m missing or need to improve in eea1fdd !

…eManager and TableMetaCacheFactory

Signed-off-by: yongjunhong <[email protected]>
Signed-off-by: yongjunhong <[email protected]>
Signed-off-by: yongjunhong <[email protected]>
Signed-off-by: yongjunhong <[email protected]>
@YongGoose YongGoose requested a review from funky-eyes August 15, 2025 14:24
*
*/
public class DataSourceProxy extends AbstractDataSourceProxy implements Resource {
public class DataSourceProxy extends AbstractDataSourceProxy implements Resource, AutoCloseable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about implementing AutoCloseable so that it can be automatically closed using a try-with-resources statement?

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about implementing AutoCloseable so that it can be automatically closed using a try-with-resources statement?

WDYT?

I don’t think it’s necessary, because the datasource itself already provides a close interface.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in f111e69 !

/**
* Represents a request to unregister a resource from the Resource Manager (RM).
*/
public class UnregisterRMRequest extends AbstractIdentifyRequest implements Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that I haven’t found anywhere on the server side that handles this request.

@funky-eyes
Copy link
Contributor

  1. The functionality of UnregisterRMRequest should be separated into an individual PR, with the current PR focusing solely on resolving the issue where tableMetaRefresh does not terminate.
  2. In NettyClientChannelManager, cache the rpcContext for a channel based on the response from RegisterRMResponse, and also cache the server version number. You may refer to the design of the RpcContext class for this implementation.
  3. When checking the server version, if it is lower than 2.6.0, output a log indicating that UnregisterRMRequest is not supported by older server versions, and therefore, resources cannot be unregistered.
  4. RMClient should provide both destroy and destroyAll interfaces. The destroy interface should accept resource information, construct an UnregisterRMRequest, and send it to the server to unregister the resource. The destroyAll interface should proactively notify the server that the client node is going offline.
  5. These points can be split into multiple PRs to improve review efficiency and ensure that each PR is clear and focused.

Hi @slievrly, The above is a summary of our previous meeting. Do you have any additional comments or suggestions?

@YongGoose
Copy link
Member Author

5. These points can be split into multiple PRs to improve review efficiency and ensure that each PR is clear and focused.

Agree

@YongGoose
Copy link
Member Author

  1. The functionality of UnregisterRMRequest should be separated into an individual PR, with the current PR focusing solely on resolving the issue where tableMetaRefresh does not terminate.

Please take another look!
Reverted the commit to f111e69!

@YongGoose
Copy link
Member Author

YongGoose commented Aug 24, 2025

  • In NettyClientChannelManager, cache the rpcContext for a channel based on the response from RegisterRMResponse, and also cache the server version number. You may refer to the design of the RpcContext class for this implementation.
  • When checking the server version, if it is lower than 2.6.0, output a log indicating that UnregisterRMRequest is not supported by older server versions, and therefore, resources cannot be unregistered.
  • RMClient should provide both destroy and destroyAll interfaces. The destroy interface should accept resource information, construct an UnregisterRMRequest, and send it to the server to unregister the resource. The destroyAll interface should proactively notify the server that the client node is going offline.
  • These points can be split into multiple PRs to improve review efficiency and ensure that each PR is clear and focused.

For this tasks, I'll open a issue and get to work :)

@YongGoose YongGoose requested a review from funky-eyes August 24, 2025 05:53
@funky-eyes funky-eyes added this to the 2.6.0 milestone Aug 25, 2025
}

public void close() throws Exception {
DefaultResourceManager.get().unregisterResource(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unregisterResource method of DataSourceManager throws a NotSupportYetException with the message "unregister a resource".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s correct.
But wasn’t the implementation for that part planned to be done in a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s correct. But wasn’t the implementation for that part planned to be done in a separate PR?

So I think this line of code should be added in a separate PR, not in this one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 189b5c6 !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 189b5c6 !

I think there may have been a misunderstanding. I meant that the line
DefaultResourceManager.get().unregisterResource(this);
should be removed from this PR and only reintroduced once unregisterResource has been properly implemented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK 👍🏻

YongGoose and others added 2 commits August 25, 2025 15:55
Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rewrite the PR title and then register the pull request.

Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more question: should the TABLE_META_CACHE in AbstractTableMetaCache be cleared when a data source is closed? I also noticed TABLE_META_CACHE is shared globally — under multiple data sources, if different databases contain tables with the same name, could that cause metadata conflicts? In addition, when calling tableMetaCache.refresh the connection used is tied to a single database, and that connection cannot retrieve metadata for tables in other databases. @slievrly, could you please confirm whether the issues I described actually exist?

@funky-eyes funky-eyes requested a review from slievrly August 26, 2025 13:41
@slievrly
Copy link
Member

slievrly commented Sep 1, 2025

5. These points can be split into multiple PRs to improve review efficiency and ensure that each PR is clear and focused.

OK, go ahead.

Copy link
Member

@slievrly slievrly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@YongGoose
Copy link
Member Author

@slievrly

One more question: should the TABLE_META_CACHE in AbstractTableMetaCache be cleared when a data source is closed? I also noticed TABLE_META_CACHE is shared globally — under multiple data sources, if different databases contain tables with the same name, could that cause metadata conflicts? In addition, when calling tableMetaCache.refresh the connection used is tied to a single database, and that connection cannot retrieve metadata for tables in other databases.

Please take a look at this question :)

@YongGoose YongGoose changed the title Add Public API to Clear All TableMetaRefreshHolder Instances feature: Introduce Cleanup API for TableMetaRefreshHolder Instance Sep 13, 2025
Signed-off-by: yongjunhong <[email protected]>
Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

TODO:

One more question: should the TABLE_META_CACHE in AbstractTableMetaCache be cleared when a data source is closed? I also noticed TABLE_META_CACHE is shared globally — under multiple data sources, if different databases contain tables with the same name, could that cause metadata conflicts? In addition, when calling tableMetaCache.refresh the connection used is tied to a single database, and that connection cannot retrieve metadata for tables in other databases. @slievrly, could you please confirm whether the issues I described actually exist?

@funky-eyes funky-eyes merged commit 7accdf8 into apache:2.x Sep 22, 2025
16 of 18 checks passed
slievrly pushed a commit to slievrly/fescar that referenced this pull request Oct 21, 2025
YvCeung pushed a commit to YvCeung/incubator-seata that referenced this pull request Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants