You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/07/08 06:24:36 UTC
[GitHub] [shardingsphere] FlyingZC commented on a diff in pull request #18911: Support a Proxy instance uses one TM.
FlyingZC commented on code in PR #18911:
URL: https://github.com/apache/shardingsphere/pull/18911#discussion_r916499463
##########
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java:
##########
@@ -82,23 +88,39 @@ public synchronized void addResource(final ShardingSphereDatabase database) {
if (null == database) {
return;
}
- ShardingSphereTransactionManagerEngine previousEngine = resources.put(database.getName(), createTransactionManagerEngine(database));
- if (null != previousEngine) {
- closeEngine(previousEngine);
- }
+ databases.put(database.getName(), database);
+ rebuildEngine();
}
@Override
public synchronized void closeStaleResource(final String databaseName) {
- ShardingSphereTransactionManagerEngine engine = resources.remove(databaseName);
- if (null != engine) {
- closeEngine(engine);
+ if (!databases.containsKey(databaseName)) {
+ return;
}
+ databases.remove(databaseName);
+ rebuildEngine();
}
@Override
- public void closeStaleResources() {
- resources.values().forEach(this::closeEngine);
+ public synchronized void closeStaleResource() {
+ databases.clear();
+ closeEngine();
+ }
+
+ private void rebuildEngine() {
+ ShardingSphereTransactionManagerEngine previousEngine = transactionManagerEngine;
+ if (null != previousEngine) {
+ closeEngine(previousEngine);
+ }
+ transactionManagerEngine = createTransactionManagerEngine(databases);
+ }
+
+ private void closeEngine() {
+ ShardingSphereTransactionManagerEngine engine = transactionManagerEngine;
+ if (null != engine) {
+ transactionManagerEngine = new ShardingSphereTransactionManagerEngine();
+ closeEngine(engine);
Review Comment:
OK
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org