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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]