This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 fdc504ca89d Remove CreateCompatibleEncryptTableEvent and
CreateShadowDataSourceEvent (#26734)
fdc504ca89d is described below
commit fdc504ca89d24bd6a31d3e081a9d452940358d49
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jul 2 22:41:26 2023 +0800
Remove CreateCompatibleEncryptTableEvent and CreateShadowDataSourceEvent
(#26734)
* Refactor ShadowDataSourceSubscriber
* Remove CreateCompatibleEncryptTableEvent
---
.../table/CreateCompatibleEncryptTableEvent.java | 32 --------------
.../datasource/CreateShadowDataSourceEvent.java | 30 -------------
.../creator/ShadowDataSourceEventCreator.java | 6 +--
.../subscriber/ShadowDataSourceSubscriber.java | 50 ++++++----------------
4 files changed, 13 insertions(+), 105 deletions(-)
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/event/compatible/table/CreateCompatibleEncryptTableEvent.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/event/compatible/table/CreateCompatibleEncryptTableEvent.java
deleted file mode 100644
index af4e53e1570..00000000000
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/event/compatible/table/CreateCompatibleEncryptTableEvent.java
+++ /dev/null
@@ -1,32 +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.encrypt.event.compatible.table;
-
-import
org.apache.shardingsphere.infra.rule.event.rule.create.CreateNamedRuleItemEvent;
-
-/**
- * Create compatible encrypt table event.
- * @deprecated compatible support will remove in next version.
- */
-@Deprecated
-public final class CreateCompatibleEncryptTableEvent extends
CreateNamedRuleItemEvent {
-
- public CreateCompatibleEncryptTableEvent(final String databaseName, final
String itemName, final String activeVersionKey, final String activeVersion) {
- super(databaseName, itemName, activeVersionKey, activeVersion);
- }
-}
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/datasource/CreateShadowDataSourceEvent.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/datasource/CreateShadowDataSourceEvent.java
deleted file mode 100644
index 172740f80e2..00000000000
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/datasource/CreateShadowDataSourceEvent.java
+++ /dev/null
@@ -1,30 +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.shadow.event.datasource;
-
-import
org.apache.shardingsphere.infra.rule.event.rule.create.CreateNamedRuleItemEvent;
-
-/**
- * Create shadow configuration event.
- */
-public final class CreateShadowDataSourceEvent extends
CreateNamedRuleItemEvent {
-
- public CreateShadowDataSourceEvent(final String databaseName, final String
itemName, final String activeVersionKey, final String activeVersion) {
- super(databaseName, itemName, activeVersionKey, activeVersion);
- }
-}
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/datasource/creator/ShadowDataSourceEventCreator.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/datasource/creator/ShadowDataSourceEventCreator.java
index dd9fcfb9df0..22440bd54c6 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/datasource/creator/ShadowDataSourceEventCreator.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/datasource/creator/ShadowDataSourceEventCreator.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
import org.apache.shardingsphere.mode.event.NamedRuleItemChangedEventCreator;
import
org.apache.shardingsphere.shadow.event.datasource.AlterShadowDataSourceEvent;
-import
org.apache.shardingsphere.shadow.event.datasource.CreateShadowDataSourceEvent;
import
org.apache.shardingsphere.shadow.event.datasource.DropShadowDataSourceEvent;
/**
@@ -32,10 +31,7 @@ public final class ShadowDataSourceEventCreator implements
NamedRuleItemChangedE
@Override
public RuleItemChangedEvent create(final String databaseName, final String
dataSourceName, final DataChangedEvent event) {
- if (Type.ADDED == event.getType()) {
- return new CreateShadowDataSourceEvent(databaseName,
dataSourceName, event.getKey(), event.getValue());
- }
- if (Type.UPDATED == event.getType()) {
+ if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) {
return new AlterShadowDataSourceEvent(databaseName,
dataSourceName, event.getKey(), event.getValue());
}
return new DropShadowDataSourceEvent(databaseName, dataSourceName);
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java
index 42fd6c6d514..d00e76d8455 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java
@@ -26,16 +26,13 @@ import
org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.subsciber.RuleChangedSubscriber;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
-import
org.apache.shardingsphere.shadow.event.datasource.CreateShadowDataSourceEvent;
import
org.apache.shardingsphere.shadow.event.datasource.AlterShadowDataSourceEvent;
import
org.apache.shardingsphere.shadow.event.datasource.DropShadowDataSourceEvent;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import
org.apache.shardingsphere.shadow.yaml.config.datasource.YamlShadowDataSourceConfiguration;
-import java.util.Optional;
-
/**
- * Shadow configuration subscriber.
+ * Shadow data source subscriber.
*/
@SuppressWarnings("UnstableApiUsage")
@Setter
@@ -44,53 +41,30 @@ public final class ShadowDataSourceSubscriber implements
RuleChangedSubscriber {
private ContextManager contextManager;
/**
- * Renew with add shadow configuration.
- *
- * @param event add shadow configuration event
- */
- @Subscribe
- public synchronized void renew(final CreateShadowDataSourceEvent event) {
- if
(!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey())))
{
- return;
- }
- ShadowDataSourceConfiguration needToAddedConfig =
swapShadowDataSourceRuleConfig(event.getItemName(),
-
contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(),
event.getActiveVersion()));
- Optional<ShadowRule> rule =
contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName()).getRuleMetaData().findSingleRule(ShadowRule.class);
- ShadowRuleConfiguration config;
- if (rule.isPresent()) {
- config = (ShadowRuleConfiguration) rule.get().getConfiguration();
- } else {
- config = new ShadowRuleConfiguration();
- }
- // TODO refactor DistSQL to only persist config
- config.getDataSources().removeIf(each ->
each.getName().equals(needToAddedConfig.getName()));
- config.getDataSources().add(needToAddedConfig);
- contextManager.getInstanceContext().getEventBusContext().post(new
DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
- }
-
- /**
- * Renew with alter shadow configuration.
+ * Renew with alter shadow data source.
*
- * @param event alter shadow configuration event
+ * @param event alter shadow data source event
*/
@Subscribe
public synchronized void renew(final AlterShadowDataSourceEvent event) {
if
(!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey())))
{
return;
}
+ String yamlContext =
contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(),
event.getActiveVersion());
+ ShadowDataSourceConfiguration toBeChangedConfig =
swapShadowDataSourceRuleConfig(event.getItemName(), yamlContext);
ShardingSphereDatabase database =
contextManager.getMetaDataContexts().getMetaData().getDatabases().get(event.getDatabaseName());
- ShadowDataSourceConfiguration needToAlteredConfig =
swapShadowDataSourceRuleConfig(event.getItemName(),
-
contextManager.getInstanceContext().getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(),
event.getActiveVersion()));
- ShadowRuleConfiguration config = (ShadowRuleConfiguration)
database.getRuleMetaData().getSingleRule(ShadowRule.class).getConfiguration();
- config.getDataSources().removeIf(each ->
each.getName().equals(event.getItemName()));
- config.getDataSources().add(needToAlteredConfig);
+ ShadowRuleConfiguration config =
database.getRuleMetaData().findSingleRule(ShadowRule.class)
+ .map(optional -> (ShadowRuleConfiguration)
optional.getConfiguration()).orElseGet(ShadowRuleConfiguration::new);
+ // TODO refactor DistSQL to only persist config
+ config.getDataSources().removeIf(each ->
each.getName().equals(toBeChangedConfig.getName()));
+ config.getDataSources().add(toBeChangedConfig);
contextManager.getInstanceContext().getEventBusContext().post(new
DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
}
/**
- * Renew with delete shadow configuration.
+ * Renew with delete shadow data source.
*
- * @param event delete shadow configuration event
+ * @param event delete shadow data source event
*/
@Subscribe
public synchronized void renew(final DropShadowDataSourceEvent event) {