-
Notifications
You must be signed in to change notification settings - Fork 8.9k
feature: Introduce Cleanup API for TableMetaRefreshHolder Instance
#7559
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
Conversation
Signed-off-by: yongjunhong <[email protected]>
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
| /** | ||
| * Shutdown all TableMetaRefreshHolder threads. | ||
| */ | ||
| public static void shutdown() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
DataSourceProxyshould proxy theclosemethod. Upon closing, it should remove itself from bothDefaultResourceManagerandTableMetaCacheFactory. Currently,TableMetaCacheFactory#removeHolderFromMapis 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)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so too
There was a problem hiding this comment.
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
DataSourceProxyshould proxy theclosemethod. Upon closing, it should remove itself from bothDefaultResourceManagerandTableMetaCacheFactory. Currently,TableMetaCacheFactory#removeHolderFromMapis 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]>
| * | ||
| */ | ||
| public class DataSourceProxy extends AbstractDataSourceProxy implements Resource { | ||
| public class DataSourceProxy extends AbstractDataSourceProxy implements Resource, AutoCloseable { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about implementing
AutoCloseableso 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in f111e69 !
Signed-off-by: yongjunhong <[email protected]>
a9a67e4 to
eea1fdd
Compare
| /** | ||
| * Represents a request to unregister a resource from the Resource Manager (RM). | ||
| */ | ||
| public class UnregisterRMRequest extends AbstractIdentifyRequest implements Serializable { |
There was a problem hiding this comment.
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.
Hi @slievrly, The above is a summary of our previous meeting. Do you have any additional comments or suggestions? |
Agree |
eea1fdd to
f111e69
Compare
Please take another look! |
For this tasks, I'll open a issue and get to work :) |
rm-datasource/src/main/java/org/apache/seata/rm/datasource/DataSourceProxy.java
Show resolved
Hide resolved
| } | ||
|
|
||
| public void close() throws Exception { | ||
| DefaultResourceManager.get().unregisterResource(this); |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 189b5c6 !
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK 👍🏻
…aSourceProxy.java Co-authored-by: funkye <[email protected]>
Signed-off-by: yongjunhong <[email protected]>
189b5c6 to
7d94fd1
Compare
Signed-off-by: yongjunhong <[email protected]>
7d94fd1 to
479cf7b
Compare
funky-eyes
left a comment
There was a problem hiding this 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.
funky-eyes
left a comment
There was a problem hiding this 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?
OK, go ahead. |
slievrly
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Please take a look at this question :) |
TableMetaRefreshHolder InstancesTableMetaRefreshHolder Instance
Signed-off-by: yongjunhong <[email protected]>
funky-eyes
left a comment
There was a problem hiding this 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?
Ⅰ. Describe what this PR did
Ⅱ. Does this pull request fix one issue?
#7523