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 ce9dd99a6bff55248736952d6635b3f7b9e40c85 Author: zhaojinchao <[email protected]> AuthorDate: Fri Aug 9 10:41:51 2024 +0800 Remove unless code --- .../metadata/event/DatabaseAddedEvent.java | 32 ------------------ .../metadata/event/DatabaseDeletedEvent.java | 32 ------------------ .../metadata/watcher/MetaDataChangedListener.java | 18 +--------- .../subscriber/ListenerAssistedSubscriber.java | 1 + .../ResourceMetaDataChangedSubscriber.java | 22 ------------ .../subscriber/CacheEvictedSubscriberTest.java | 39 ---------------------- .../ResourceMetaDataChangedSubscriberTest.java | 35 ------------------- .../bootstrap/src/main/resources/conf/global.yaml | 22 ++++++------ 8 files changed, 13 insertions(+), 188 deletions(-) diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseAddedEvent.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseAddedEvent.java deleted file mode 100644 index 0c3c196ab61..00000000000 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseAddedEvent.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.mode.manager.cluster.coordinator.registry.metadata.event; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.rule.event.GovernanceEvent; - -/** - * Database added event. - */ -@RequiredArgsConstructor -@Getter -public final class DatabaseAddedEvent implements GovernanceEvent { - - private final String databaseName; -} diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseDeletedEvent.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseDeletedEvent.java deleted file mode 100644 index 1e0e61fe026..00000000000 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseDeletedEvent.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.mode.manager.cluster.coordinator.registry.metadata.event; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.rule.event.GovernanceEvent; - -/** - * Database deleted event. - */ -@RequiredArgsConstructor -@Getter -public final class DatabaseDeletedEvent implements GovernanceEvent { - - private final String databaseName; -} diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedListener.java index 0e0899faeae..65ff7235aba 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedListener.java @@ -37,8 +37,6 @@ import org.apache.shardingsphere.mode.event.schema.table.AlterTableEvent; import org.apache.shardingsphere.mode.event.schema.table.DropTableEvent; import org.apache.shardingsphere.mode.event.schema.view.AlterViewEvent; import org.apache.shardingsphere.mode.event.schema.view.DropViewEvent; -import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseAddedEvent; -import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseDeletedEvent; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaDeletedEvent; import org.apache.shardingsphere.mode.metadata.builder.RuleConfigurationEventBuilder; @@ -63,11 +61,7 @@ public final class MetaDataChangedListener implements DataChangedEventListener { private Optional<GovernanceEvent> createGovernanceEvent(final DataChangedEvent event) { String key = event.getKey(); - Optional<String> databaseName = DatabaseMetaDataNode.getDatabaseName(key); - if (databaseName.isPresent()) { - return createDatabaseChangedEvent(databaseName.get(), event); - } - databaseName = DatabaseMetaDataNode.getDatabaseNameBySchemaNode(key); + Optional<String> databaseName = DatabaseMetaDataNode.getDatabaseNameBySchemaNode(key); Optional<String> schemaName = DatabaseMetaDataNode.getSchemaName(key); if (databaseName.isPresent() && schemaName.isPresent()) { return createSchemaChangedEvent(databaseName.get(), schemaName.get(), event); @@ -90,16 +84,6 @@ public final class MetaDataChangedListener implements DataChangedEventListener { return ruleConfigurationEventBuilder.build(databaseName.get(), event); } - private Optional<GovernanceEvent> createDatabaseChangedEvent(final String databaseName, final DataChangedEvent event) { - if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) { - return Optional.of(new DatabaseAddedEvent(databaseName)); - } - if (Type.DELETED == event.getType()) { - return Optional.of(new DatabaseDeletedEvent(databaseName)); - } - return Optional.empty(); - } - private Optional<GovernanceEvent> createSchemaChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) { return Optional.of(new SchemaAddedEvent(databaseName, schemaName)); diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ListenerAssistedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ListenerAssistedSubscriber.java index 20d4ec5aae4..313955480c2 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ListenerAssistedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ListenerAssistedSubscriber.java @@ -52,6 +52,7 @@ public final class ListenerAssistedSubscriber { public synchronized void renew(final CreateDatabaseListenerAssistedEvent event) { listenerManager.addListener(DatabaseMetaDataNode.getDatabaseNamePath(event.getDatabaseName()), new MetaDataChangedListener(contextManager.getInstanceContext().getEventBusContext())); + contextManager.getResourceMetaDataContextManager().addDatabase(event.getDatabaseName()); contextManager.getMetaDataContexts().getPersistService().getListenerAssistedPersistService().deleteDatabaseNameListenerAssisted(event.getDatabaseName()); } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriber.java index 437dee21725..87184d02565 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriber.java @@ -25,8 +25,6 @@ import org.apache.shardingsphere.mode.event.schema.table.DropTableEvent; import org.apache.shardingsphere.mode.event.schema.view.AlterViewEvent; import org.apache.shardingsphere.mode.event.schema.view.DropViewEvent; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseAddedEvent; -import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseDeletedEvent; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaDeletedEvent; @@ -45,26 +43,6 @@ public final class ResourceMetaDataChangedSubscriber { contextManager.getInstanceContext().getEventBusContext().register(this); } - /** - * Renew to persist meta data. - * - * @param event database added event - */ - @Subscribe - public synchronized void renew(final DatabaseAddedEvent event) { - contextManager.getResourceMetaDataContextManager().addDatabase(event.getDatabaseName()); - } - - /** - * Renew to delete database. - * - * @param event database delete event - */ - @Subscribe - public synchronized void renew(final DatabaseDeletedEvent event) { - contextManager.getResourceMetaDataContextManager().dropDatabase(event.getDatabaseName()); - } - /** * Renew to added schema. * diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/CacheEvictedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/CacheEvictedSubscriberTest.java deleted file mode 100644 index 3100a4578cd..00000000000 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/CacheEvictedSubscriberTest.java +++ /dev/null @@ -1,39 +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.mode.manager.cluster.coordinator.subscriber; - -import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; -import org.apache.shardingsphere.infra.spi.type.ordered.cache.OrderedServicesCache; -import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseDeletedEvent; -import org.junit.jupiter.api.Test; - -import java.util.Collections; - -import static org.junit.jupiter.api.Assertions.assertFalse; - -class CacheEvictedSubscriberTest { - - @Test - void assertOnGovernanceEvent() { - EventBusContext eventBusContext = new EventBusContext(); - new CacheEvictedSubscriber(eventBusContext); - OrderedServicesCache.cacheServices(getClass(), Collections.emptyList(), Collections.emptyMap()); - eventBusContext.post(new DatabaseDeletedEvent("db")); - assertFalse(OrderedServicesCache.findCachedServices(getClass(), Collections.emptyList()).isPresent()); - } -} diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java index 6ca87662d91..9c9a0786e87 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java @@ -20,25 +20,19 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber; import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator; -import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter; import org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder; -import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseAddedEvent; -import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseDeletedEvent; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaDeletedEvent; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration; -import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -50,12 +44,9 @@ import org.mockito.quality.Strictness; import java.sql.SQLException; import java.util.Collections; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.mock; @@ -70,9 +61,6 @@ class ResourceMetaDataChangedSubscriberTest { private ContextManager contextManager; - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private MetaDataPersistService persistService; - @Mock(answer = Answers.RETURNS_DEEP_STUBS) private ShardingSphereDatabase database; @@ -101,29 +89,6 @@ class ResourceMetaDataChangedSubscriberTest { return Collections.singletonMap("db", database); } - @Test - void assertRenewForDatabaseAdded() { - when(persistService.getDataSourceUnitService().load("db_added")).thenReturn(createDataSourcePoolPropertiesMap()); - when(persistService.getDatabaseRulePersistService().load("db_added")).thenReturn(Collections.emptyList()); - subscriber.renew(new DatabaseAddedEvent("db_added")); - assertNotNull(contextManager.getMetaDataContexts().getMetaData().getDatabase("db_added").getResourceMetaData().getStorageUnits()); - } - - private Map<String, DataSourcePoolProperties> createDataSourcePoolPropertiesMap() { - MockedDataSource dataSource = new MockedDataSource(); - Map<String, DataSourcePoolProperties> result = new LinkedHashMap<>(3, 1F); - result.put("primary_ds", DataSourcePoolPropertiesCreator.create(dataSource)); - result.put("replica_ds_0", DataSourcePoolPropertiesCreator.create(dataSource)); - result.put("replica_ds_1", DataSourcePoolPropertiesCreator.create(dataSource)); - return result; - } - - @Test - void assertRenewForDatabaseDeleted() { - subscriber.renew(new DatabaseDeletedEvent("db")); - assertNull(contextManager.getMetaDataContexts().getMetaData().getDatabase("db")); - } - @Test void assertRenewForSchemaAdded() { subscriber.renew(new SchemaAddedEvent("db", "foo_schema")); diff --git a/proxy/bootstrap/src/main/resources/conf/global.yaml b/proxy/bootstrap/src/main/resources/conf/global.yaml index 11daea63448..3f339c1f812 100644 --- a/proxy/bootstrap/src/main/resources/conf/global.yaml +++ b/proxy/bootstrap/src/main/resources/conf/global.yaml @@ -21,17 +21,17 @@ # ###################################################################################################### -#mode: -# type: Cluster -# repository: -# type: ZooKeeper -# props: -# namespace: governance_ds -# server-lists: localhost:2181 -# retryIntervalMilliseconds: 500 -# timeToLiveSeconds: 60 -# maxRetries: 3 -# operationTimeoutMilliseconds: 500 +mode: + type: Cluster + repository: + type: ZooKeeper + props: + namespace: governance_ds + server-lists: localhost:2181 + retryIntervalMilliseconds: 500 + timeToLiveSeconds: 60 + maxRetries: 3 + operationTimeoutMilliseconds: 500 # #authority: # users:
