You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2024/10/22 05:58:14 UTC
(shardingsphere) 38/43: Optimize the rollback strategy for import database config failed (#15)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch fix-33341
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
commit 10a270bae8b341ab49ed6d55a561ed61a162f371
Author: Raigor <ra...@gmail.com>
AuthorDate: Mon Oct 14 10:53:28 2024 +0800
Optimize the rollback strategy for import database config failed (#15)
---
.../util/YamlDatabaseConfigurationImportExecutor.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
index 99b20135c6c..1e95e191f4f 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
@@ -46,6 +46,7 @@ import org.apache.shardingsphere.infra.util.SphereEx;
import org.apache.shardingsphere.infra.util.SphereEx.Type;
import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
+import org.apache.shardingsphere.metadata.persist.node.DatabaseMetaDataNode;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDataSourceConfiguration;
@@ -63,6 +64,7 @@ import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
+import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@@ -88,11 +90,21 @@ public final class YamlDatabaseConfigurationImportExecutor {
importDataSources(databaseName, yamlConfig.getDataSources());
importRules(databaseName, yamlConfig.getRules());
} catch (final ShardingSphereSQLException ex) {
- dropDatabase(databaseName);
+ dropDatabaseUntilSuccessful(databaseName);
throw ex;
}
}
+ private void dropDatabaseUntilSuccessful(final String databaseName) {
+ do {
+ dropDatabase(databaseName);
+ try {
+ TimeUnit.MILLISECONDS.sleep(200);
+ } catch (final InterruptedException ignored) {
+ }
+ } while (ProxyContext.getInstance().getContextManager().getMetaDataContexts().getPersistService().getRepository().isExisted(DatabaseMetaDataNode.getDatabaseNamePath(databaseName)));
+ }
+
private void checkDataSources(final String databaseName, final Map<String, YamlProxyDataSourceConfiguration> dataSources) {
ShardingSpherePreconditions.checkState(!dataSources.isEmpty(), () -> new EmptyStorageUnitException(databaseName));
}