You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2021/10/27 15:34:03 UTC
[shardingsphere] branch master updated: For #13083,
Migrate PR from Gitee to GitHub. (#13318)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 fc1fc9b For #13083, Migrate PR from Gitee to GitHub. (#13318)
fc1fc9b is described below
commit fc1fc9b30b5363636228189ce0d6ce994980c636
Author: yx9o <ya...@163.com>
AuthorDate: Wed Oct 27 23:33:18 2021 +0800
For #13083, Migrate PR from Gitee to GitHub. (#13318)
---
.../ClusterContextManagerCoordinator.java | 31 ++++++++++------------
.../ClusterContextManagerCoordinatorTest.java | 7 -----
2 files changed, 14 insertions(+), 24 deletions(-)
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java
index 27a833e..c284916 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java
@@ -37,7 +37,6 @@ import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilder;
import org.apache.shardingsphere.infra.metadata.schema.loader.SchemaLoader;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import org.apache.shardingsphere.infra.optimize.metadata.FederationSchemaMetaData;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceChangedEvent;
@@ -144,13 +143,13 @@ public final class ClusterContextManagerCoordinator {
public synchronized void renew(final SchemaChangedEvent event) {
String schemaName = event.getSchemaName();
Collection<TableMetaData> tableMetaDataList = event.getSchema().getTables().values();
- ShardingSphereMetaData kernelMetaData = new ShardingSphereMetaData(schemaName, contextManager.getMetaDataContexts().getMetaData(schemaName).getResource(),
- contextManager.getMetaDataContexts().getMetaData(schemaName).getRuleMetaData(), SchemaBuilder.buildKernelSchema(tableMetaDataList,
+ ShardingSphereMetaData kernelMetaData = new ShardingSphereMetaData(schemaName, contextManager.getMetaDataContexts().getMetaData(schemaName).getResource(),
+ contextManager.getMetaDataContexts().getMetaData(schemaName).getRuleMetaData(), SchemaBuilder.buildKernelSchema(tableMetaDataList,
contextManager.getMetaDataContexts().getMetaData(schemaName).getRuleMetaData().getRules()));
Map<String, ShardingSphereMetaData> kernelMetaDataMap = new HashMap<>(contextManager.getMetaDataContexts().getMetaDataMap());
kernelMetaDataMap.put(schemaName, kernelMetaData);
contextManager.getMetaDataContexts().getOptimizerContext().getMetaData().getSchemas().put(schemaName,
- new FederationSchemaMetaData(schemaName, SchemaBuilder.buildFederationSchema(tableMetaDataList,
+ new FederationSchemaMetaData(schemaName, SchemaBuilder.buildFederationSchema(tableMetaDataList,
contextManager.getMetaDataContexts().getMetaData(schemaName).getRuleMetaData().getRules()).getTables()));
contextManager.renewMetaDataContexts(rebuildMetaDataContexts(kernelMetaDataMap));
}
@@ -198,12 +197,11 @@ public final class ClusterContextManagerCoordinator {
@Subscribe
public synchronized void renew(final DisabledStateChangedEvent event) {
QualifiedSchema qualifiedSchema = event.getQualifiedSchema();
- Collection<ShardingSphereRule> rules = contextManager.getMetaDataContexts().getMetaDataMap().get(qualifiedSchema.getSchemaName()).getRuleMetaData().getRules();
- for (ShardingSphereRule each : rules) {
- if (each instanceof StatusContainedRule) {
- ((StatusContainedRule) each).updateStatus(new DataSourceNameDisabledEvent(qualifiedSchema.getDataSourceName(), event.isDisabled()));
- }
- }
+ contextManager.getMetaDataContexts().getMetaDataMap().get(qualifiedSchema.getSchemaName()).getRuleMetaData().getRules()
+ .stream()
+ .filter(each -> each instanceof StatusContainedRule)
+ .forEach(each -> ((StatusContainedRule) each)
+ .updateStatus(new DataSourceNameDisabledEvent(qualifiedSchema.getDataSourceName(), event.isDisabled())));
}
/**
@@ -214,12 +212,11 @@ public final class ClusterContextManagerCoordinator {
@Subscribe
public synchronized void renew(final PrimaryStateChangedEvent event) {
QualifiedSchema qualifiedSchema = event.getQualifiedSchema();
- Collection<ShardingSphereRule> rules = contextManager.getMetaDataContexts().getMetaDataMap().get(qualifiedSchema.getSchemaName()).getRuleMetaData().getRules();
- for (ShardingSphereRule each : rules) {
- if (each instanceof StatusContainedRule) {
- ((StatusContainedRule) each).updateStatus(new PrimaryDataSourceChangedEvent(qualifiedSchema.getSchemaName(), qualifiedSchema.getDataSourceName(), event.getPrimaryDataSourceName()));
- }
- }
+ contextManager.getMetaDataContexts().getMetaDataMap().get(qualifiedSchema.getSchemaName()).getRuleMetaData().getRules()
+ .stream()
+ .filter(each -> each instanceof StatusContainedRule)
+ .forEach(each -> ((StatusContainedRule) each)
+ .updateStatus(new PrimaryDataSourceChangedEvent(qualifiedSchema.getSchemaName(), qualifiedSchema.getDataSourceName(), event.getPrimaryDataSourceName())));
}
/**
@@ -376,7 +373,7 @@ public final class ClusterContextManagerCoordinator {
private TransactionRule getTransactionRule() {
Optional<TransactionRule> transactionRule = contextManager.getMetaDataContexts().getGlobalRuleMetaData().getRules().stream()
- .filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
+ .filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index 974f282..f331613 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -52,7 +52,6 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
import org.apache.shardingsphere.test.mock.MockedDataSource;
-import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
import org.junit.Before;
@@ -96,12 +95,6 @@ public final class ClusterContextManagerCoordinatorTest {
private ShardingSphereMetaData metaData;
@Mock
- private ShardingSphereTransactionManagerEngine engine;
-
- @Mock
- private Map<String, ShardingSphereTransactionManagerEngine> engines;
-
- @Mock
private ShardingSphereRuleMetaData globalRuleMetaData;
@SneakyThrows