未验证 提交 2fd13d13 编写于 作者: J Juan Pan(Trista) 提交者: GitHub

Merge pull request #7646 from menghaoranss/0928

Fixes NPE when create database by rdl & delete schema in config center when drop database
......@@ -249,7 +249,8 @@ public final class ConfigCenter {
private void persistSchema(final String schemaName, final boolean isDrop) {
String schemaNames = repository.get(node.getSchemasPath());
Collection<String> schemas = new LinkedHashSet<>(Splitter.on(",").splitToList(schemaNames));
Collection<String> schemas = Strings.isNullOrEmpty(schemaNames) ? new LinkedHashSet<>()
: new LinkedHashSet<>(Splitter.on(",").splitToList(schemaNames));
if (isDrop) {
schemas.remove(schemaName);
} else if (!schemas.contains(schemaName)) {
......@@ -357,6 +358,15 @@ public final class ConfigCenter {
return Optional.of(new RuleSchemaMetaDataYamlSwapper().swapToObject(YamlEngine.unmarshal(path, YamlRuleSchemaMetaData.class)));
}
/**
* Delete schema.
*
* @param schemaName schema name
*/
public void deleteSchema(final String schemaName) {
repository.delete(node.getSchemaNamePath(schemaName));
}
private boolean hasAuthentication() {
return !Strings.isNullOrEmpty(repository.get(node.getAuthenticationPath()));
}
......
......@@ -533,4 +533,11 @@ public final class ConfigCenterTest {
configCenter.renew(event);
verify(configurationRepository).persist(eq("/schemas/sharding_db/table"), anyString());
}
@Test
public void assertDeleteSchema() {
ConfigCenter configCenter = new ConfigCenter(configurationRepository);
configCenter.deleteSchema("sharding_db");
verify(configurationRepository).delete(eq("/schemas/sharding_db"));
}
}
......@@ -175,6 +175,7 @@ public final class GovernanceSchemaContexts implements SchemaContexts {
Map<String, SchemaContext> schemas = new HashMap<>(schemaContexts.getSchemaContextMap());
schemas.remove(event.getSchemaName());
schemaContexts = new StandardSchemaContexts(schemas, schemaContexts.getAuthentication(), schemaContexts.getProps(), schemaContexts.getDatabaseType());
governanceFacade.getConfigCenter().deleteSchema(event.getSchemaName());
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册