You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/06/22 04:47:30 UTC
[shardingsphere] branch master updated: Support startup with empty logic database (#18507)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 741754dc04d Support startup with empty logic database (#18507)
741754dc04d is described below
commit 741754dc04d242c7f58157396282dfd944013669
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Wed Jun 22 12:47:16 2022 +0800
Support startup with empty logic database (#18507)
* Support startup with empty logic database
* Support startup with empty logic database
---
.../mode/metadata/persist/MetaDataPersistService.java | 10 ++++++++--
.../metadata/persist/service/SchemaMetaDataPersistService.java | 9 +++++++++
.../persist/service/SchemaMetaDataPersistServiceTest.java | 6 ++++++
.../proxy/backend/config/ProxyConfigurationLoader.java | 1 -
4 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java
index 63a27d47825..c71ad28a7c7 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java
@@ -86,8 +86,14 @@ public final class MetaDataPersistService {
propsService.persist(props, isOverwrite);
for (Entry<String, ? extends DatabaseConfiguration> entry : schemaConfigs.entrySet()) {
String databaseName = entry.getKey();
- dataSourceService.persist(databaseName, getDataSourcePropertiesMap(entry.getValue().getDataSources()), isOverwrite);
- databaseRulePersistService.persist(databaseName, entry.getValue().getRuleConfigurations(), isOverwrite);
+ Map<String, DataSourceProperties> dataSourcePropertiesMap = getDataSourcePropertiesMap(entry.getValue().getDataSources());
+ Collection<RuleConfiguration> ruleConfigurations = entry.getValue().getRuleConfigurations();
+ if (dataSourcePropertiesMap.isEmpty() && ruleConfigurations.isEmpty()) {
+ schemaMetaDataService.persistDatabase(databaseName);
+ } else {
+ dataSourceService.persist(databaseName, getDataSourcePropertiesMap(entry.getValue().getDataSources()), isOverwrite);
+ databaseRulePersistService.persist(databaseName, entry.getValue().getRuleConfigurations(), isOverwrite);
+ }
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistService.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistService.java
index 3649a80fa31..19cc54ce4cc 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistService.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistService.java
@@ -114,6 +114,15 @@ public final class SchemaMetaDataPersistService {
repository.delete(DatabaseMetaDataNode.getDatabaseNamePath(databaseName));
}
+ /**
+ * Persist database name.
+ *
+ * @param databaseName database name
+ */
+ public void persistDatabase(final String databaseName) {
+ repository.persist(DatabaseMetaDataNode.getDatabaseNamePath(databaseName), "");
+ }
+
/**
* Delete schema.
*
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistServiceTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistServiceTest.java
index 5752a17a9f2..5999d810ba0 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistServiceTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistServiceTest.java
@@ -68,6 +68,12 @@ public final class SchemaMetaDataPersistServiceTest {
verify(repository).delete("/metadata/foo_db");
}
+ @Test
+ public void assertPersistDatabase() {
+ new SchemaMetaDataPersistService(repository).persistDatabase("foo_db");
+ verify(repository).persist("/metadata/foo_db", "");
+ }
+
@Test
public void assertLoad() {
SchemaMetaDataPersistService schemaMetaDataPersistService = new SchemaMetaDataPersistService(repository);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java
index 95a05905348..409653c101e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java
@@ -105,7 +105,6 @@ public final class ProxyConfigurationLoader {
result.setDatabaseName(result.getSchemaName());
}
Preconditions.checkNotNull(result.getDatabaseName(), "Property `databaseName` in file `%s` is required.", yamlFile.getName());
- Preconditions.checkState(!result.getDataSources().isEmpty(), "Data sources configuration in file `%s` is required.", yamlFile.getName());
return Optional.of(result);
}