This is an automated email from the ASF dual-hosted git repository.
panjuan 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 5a27050 Use direct call to instead of event post on
RuleDefinitionBackendHandler (#11496)
5a27050 is described below
commit 5a270500f9259994ba182c090d89f64c4563ac2a
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jul 25 15:46:45 2021 +0800
Use direct call to instead of event post on RuleDefinitionBackendHandler
(#11496)
---
.../governance/core/registry/RegistryCenter.java | 2 -
.../core/registry/SQLNotificationEvent.java | 24 ---------
...eConfigurationsAlteredSQLNotificationEvent.java | 37 --------------
.../subscriber/SchemaRuleRegistrySubscriber.java | 47 ------------------
.../SchemaRuleRegistrySubscriberTest.java | 57 ----------------------
.../rdl/rule/RuleDefinitionBackendHandler.java | 10 ++--
6 files changed, 4 insertions(+), 173 deletions(-)
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
index 015a2d8..6a261cb 100644
---
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
@@ -22,7 +22,6 @@ import
org.apache.shardingsphere.governance.core.GovernanceInstance;
import
org.apache.shardingsphere.governance.core.lock.service.LockRegistryService;
import
org.apache.shardingsphere.governance.core.registry.cache.subscriber.ScalingRegistrySubscriber;
import
org.apache.shardingsphere.governance.core.registry.config.subscriber.GlobalRuleRegistrySubscriber;
-import
org.apache.shardingsphere.governance.core.registry.config.subscriber.SchemaRuleRegistrySubscriber;
import
org.apache.shardingsphere.governance.core.registry.metadata.subscriber.SchemaMetaDataRegistrySubscriber;
import
org.apache.shardingsphere.governance.core.registry.process.subscriber.ProcessRegistrySubscriber;
import
org.apache.shardingsphere.governance.core.registry.state.service.DataSourceStatusRegistryService;
@@ -62,7 +61,6 @@ public final class RegistryCenter {
private void createSubscribers(final RegistryCenterRepository repository) {
new SchemaMetaDataRegistrySubscriber(repository);
new GlobalRuleRegistrySubscriber(repository);
- new SchemaRuleRegistrySubscriber(repository);
new DataSourceStatusRegistrySubscriber(repository);
new ScalingRegistrySubscriber(repository);
new ProcessRegistrySubscriber(repository);
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/SQLNotificationEvent.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/SQLNotificationEvent.java
deleted file mode 100644
index 2ed668a..0000000
---
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/SQLNotificationEvent.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.governance.core.registry;
-
-/**
- * SQL notification event.
- */
-public interface SQLNotificationEvent {
-}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/config/event/rule/RuleConfigurationsAlteredSQLNotificationEvent.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/config/event/rule/RuleConfigurationsAlteredSQLNotificationEvent.java
deleted file mode 100644
index 39631e5..0000000
---
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/config/event/rule/RuleConfigurationsAlteredSQLNotificationEvent.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.governance.core.registry.config.event.rule;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.governance.core.registry.SQLNotificationEvent;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-
-import java.util.Collection;
-
-/**
- * Rule configurations altered SQL notification event.
- */
-@RequiredArgsConstructor
-@Getter
-public final class RuleConfigurationsAlteredSQLNotificationEvent implements
SQLNotificationEvent {
-
- private final String schemaName;
-
- private final Collection<RuleConfiguration> ruleConfigurations;
-}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/config/subscriber/SchemaRuleRegistrySubscriber.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/config/subscriber/SchemaRuleRegistrySubscriber.java
deleted file mode 100644
index a6195b6..0000000
---
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/config/subscriber/SchemaRuleRegistrySubscriber.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.governance.core.registry.config.subscriber;
-
-import com.google.common.eventbus.Subscribe;
-import
org.apache.shardingsphere.governance.core.registry.config.event.rule.RuleConfigurationsAlteredSQLNotificationEvent;
-import
org.apache.shardingsphere.infra.config.persist.service.impl.SchemaRulePersistService;
-import
org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
-
-/**
- * Schema rule registry subscriber.
- */
-public final class SchemaRuleRegistrySubscriber {
-
- private final SchemaRulePersistService persistService;
-
- public SchemaRuleRegistrySubscriber(final RegistryCenterRepository
repository) {
- persistService = new SchemaRulePersistService(repository);
- ShardingSphereEventBus.getInstance().register(this);
- }
-
- /**
- * Update rule configurations for alter.
- *
- * @param event rule configurations altered event
- */
- @Subscribe
- public void update(final RuleConfigurationsAlteredSQLNotificationEvent
event) {
- persistService.persist(event.getSchemaName(),
event.getRuleConfigurations());
- }
-}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/config/subscriber/SchemaRuleRegistrySubscriberTest.java
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/config/subscriber/SchemaRuleRegistrySubscriberTest.java
deleted file mode 100644
index 117da5f..0000000
---
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/config/subscriber/SchemaRuleRegistrySubscriberTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.governance.core.registry.config.subscriber;
-
-import
org.apache.shardingsphere.governance.core.registry.config.event.rule.RuleConfigurationsAlteredSQLNotificationEvent;
-import
org.apache.shardingsphere.infra.config.persist.service.impl.SchemaRulePersistService;
-import
org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.lang.reflect.Field;
-import java.util.Collections;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class SchemaRuleRegistrySubscriberTest {
-
- private SchemaRuleRegistrySubscriber schemaRuleRegistrySubscriber;
-
- @Mock
- private SchemaRulePersistService persistService;
-
- @Before
- public void setUp() throws ReflectiveOperationException {
- schemaRuleRegistrySubscriber = new
SchemaRuleRegistrySubscriber(mock(RegistryCenterRepository.class));
- Field field =
schemaRuleRegistrySubscriber.getClass().getDeclaredField("persistService");
- field.setAccessible(true);
- field.set(schemaRuleRegistrySubscriber, persistService);
- }
-
- @Test
- public void assertUpdate() {
- RuleConfigurationsAlteredSQLNotificationEvent event = new
RuleConfigurationsAlteredSQLNotificationEvent("foo_db",
Collections.emptyList());
- schemaRuleRegistrySubscriber.update(event);
- verify(persistService).persist(event.getSchemaName(),
event.getRuleConfigurations());
- }
-}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
index 4d8a9c5..a6f5458 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
@@ -18,14 +18,12 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.rule;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.RuleDefinitionStatement;
-import
org.apache.shardingsphere.governance.core.registry.config.event.rule.RuleConfigurationsAlteredSQLNotificationEvent;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import
org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater;
import
org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater;
import
org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
@@ -60,7 +58,7 @@ public final class RuleDefinitionBackendHandler<T extends
RuleDefinitionStatemen
RuleConfiguration currentRuleConfig =
findCurrentRuleConfiguration(schemaName, ruleConfigClass).orElse(null);
ruleDefinitionUpdater.checkSQLStatement(schemaName, sqlStatement,
currentRuleConfig,
ProxyContext.getInstance().getMetaData(schemaName).getResource());
processSQLStatement(schemaName, sqlStatement, ruleDefinitionUpdater,
currentRuleConfig);
- postRuleConfigurationChange(schemaName);
+ persistRuleConfigurationChange(schemaName);
return new UpdateResponseHeader(sqlStatement);
}
@@ -109,8 +107,8 @@ public final class RuleDefinitionBackendHandler<T extends
RuleDefinitionStatemen
}
}
- private void postRuleConfigurationChange(final String schemaName) {
- ShardingSphereEventBus.getInstance().post(
- new RuleConfigurationsAlteredSQLNotificationEvent(schemaName,
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations()));
+ private void persistRuleConfigurationChange(final String schemaName) {
+
ProxyContext.getInstance().getMetaDataContexts().getConfigCenter().getSchemaRuleService().persist(
+ schemaName,
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations());
}
}