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 f15d1c6 Differentiate between dynamic and static data when exporting.
(#15302)
f15d1c6 is described below
commit f15d1c6ccbe1dfab0c766a14dfbd8347ccb4bfdc
Author: lanchengx <[email protected]>
AuthorDate: Wed Feb 9 12:46:21 2022 +0800
Differentiate between dynamic and static data when exporting. (#15302)
* Modify constant name.
* Complete TODO.
* Differentiate between dynamic and static data when exporting.
* Rename class.
* Add static variable.
---
.../rule/ReadwriteSplittingRule.java | 18 ++++++++++++------
.../common/show/executor/ShowInstanceExecutor.java | 8 ++++----
.../ShowReadwriteSplittingReadResourcesExecutor.java | 19 ++++++++++---------
...yResultSet.java => SchemaRulesCountResultSet.java} | 4 ++--
...hardingsphere.infra.distsql.query.DistSQLResultSet | 2 +-
...etTest.java => SchemaRulesCountResultSetTest.java} | 8 ++++----
6 files changed, 33 insertions(+), 26 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
index 8eebc99..e1f0ab1 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
@@ -55,6 +55,10 @@ public final class ReadwriteSplittingRule implements
SchemaRule, DataSourceConta
ShardingSphereServiceLoader.register(ReadwriteSplittingType.class);
}
+ private static final String DYNAMIC = "DYNAMIC";
+
+ private static final String STATIC = "STATIC";
+
private final Map<String, ReplicaLoadBalanceAlgorithm> loadBalancers = new
LinkedHashMap<>();
private final Map<String, ReadwriteSplittingDataSourceRule>
dataSourceRules;
@@ -123,18 +127,20 @@ public final class ReadwriteSplittingRule implements
SchemaRule, DataSourceConta
@Override
public Map<String, Supplier<Object>> getExportedMethods() {
Map<String, Supplier<Object>> result = new HashMap<>(3, 1);
- result.put(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE,
this::exportDataSourceNames);
+ result.put(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE,
() -> exportDataSource(DYNAMIC));
result.put(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE_NAME,
this::exportAutoAwareDataSourceNames);
- result.put(ExportableConstants.EXPORTABLE_KEY_DATA_SOURCE,
this::exportDataSourceNames);
+ result.put(ExportableConstants.EXPORTABLE_KEY_DATA_SOURCE, () ->
exportDataSource(STATIC));
return result;
}
- private Map<String, Map<String, String>> exportDataSourceNames() {
+ private Map<String, Map<String, String>> exportDataSource(final String
readwriteSplittingType) {
Map<String, Map<String, String>> result = new
HashMap<>(dataSourceRules.size(), 1);
dataSourceRules.forEach((name, dataSourceRule) -> {
- Map<String, String> dataSources = dataSourceRule.getDataSources();
- if (!dataSources.isEmpty()) {
- result.put(dataSourceRule.getName(), dataSources);
+ if
(readwriteSplittingType.equalsIgnoreCase(dataSourceRule.getReadwriteSplittingType().getType()))
{
+ Map<String, String> dataSources =
dataSourceRule.getDataSources();
+ if (!dataSources.isEmpty()) {
+ result.put(dataSourceRule.getName(), dataSources);
+ }
}
});
return result;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowInstanceExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowInstanceExecutor.java
index 87c090c..8e5021e 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowInstanceExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowInstanceExecutor.java
@@ -51,11 +51,11 @@ public final class ShowInstanceExecutor extends
AbstractShowExecutor {
private static final String STATUS = "status";
- private static final String DISABLE = "disable";
+ private static final String DISABLED = "disabled";
private static final String LABELS = "labels";
- private static final String ENABLE = "enable";
+ private static final String ENABLED = "enabled";
@Override
protected List<QueryHeader> createQueryHeaders() {
@@ -80,7 +80,7 @@ public final class ShowInstanceExecutor extends
AbstractShowExecutor {
private Collection<List<Object>> buildInstanceRows() {
List<List<Object>> result = new LinkedList<>();
InstanceId instanceId =
ProxyContext.getInstance().getContextManager().getInstanceContext().getInstance().getInstanceDefinition().getInstanceId();
- result.add(buildRow(instanceId.getId(), ENABLE,
Collections.emptyList()));
+ result.add(buildRow(instanceId.getId(), ENABLED,
Collections.emptyList()));
return result;
}
@@ -103,6 +103,6 @@ public final class ShowInstanceExecutor extends
AbstractShowExecutor {
}
private String getStatus(final Collection<String> computeNodeStatus) {
- return computeNodeStatus.isEmpty() ||
!computeNodeStatus.contains(ComputeNodeStatus.CIRCUIT_BREAK.name()) ? ENABLE :
DISABLE;
+ return computeNodeStatus.isEmpty() ||
!computeNodeStatus.contains(ComputeNodeStatus.CIRCUIT_BREAK.name()) ? ENABLED :
DISABLED;
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
index 2a1c3fe..a54347a 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
@@ -31,6 +31,8 @@ import
org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
import
org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
+import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
import
org.apache.shardingsphere.sharding.merge.dal.common.MultipleLocalDataMergedResult;
@@ -44,6 +46,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -60,9 +63,9 @@ public final class
ShowReadwriteSplittingReadResourcesExecutor extends AbstractS
private static final String STATUS = "status";
- private static final String DISABLE = "disable";
+ private static final String DISABLED = "disabled";
- private static final String ENABLE = "enable";
+ private static final String ENABLED = "enabled";
private final ShowReadwriteSplittingReadResourcesStatement sqlStatement;
@@ -96,16 +99,14 @@ public final class
ShowReadwriteSplittingReadResourcesExecutor extends AbstractS
LinkedList<String> configuredResourceRows =
getConfiguredResourceRows(metaData);
Collection<String> autoAwareResourceRows =
getAutoAwareResourceRows(metaData, notShownResourceRows);
return Stream.of(configuredResourceRows,
autoAwareResourceRows).flatMap(Collection::stream).distinct()
- .map(each -> buildRow(each,
ENABLE)).collect(Collectors.toCollection(LinkedList::new));
+ .map(each -> buildRow(each,
ENABLED)).collect(Collectors.toCollection(LinkedList::new));
}
- // TODO Fix it.
private LinkedList<String> getConfiguredResourceRows(final
ShardingSphereMetaData metaData) {
-/* Collection<ReadwriteSplittingRuleConfiguration> ruleConfiguration =
metaData.getRuleMetaData().findRuleConfiguration(ReadwriteSplittingRuleConfiguration.class);
+ Collection<ReadwriteSplittingRuleConfiguration> ruleConfiguration =
metaData.getRuleMetaData().findRuleConfiguration(ReadwriteSplittingRuleConfiguration.class);
return
ruleConfiguration.stream().map(ReadwriteSplittingRuleConfiguration::getDataSources).flatMap(Collection::stream).filter(Objects::nonNull)
-
.map(ReadwriteSplittingDataSourceRuleConfiguration::getReadDataSourceNames)
-
.flatMap(Collection::stream).collect(Collectors.toCollection(LinkedList::new));*/
- return new LinkedList<>();
+
.map(ReadwriteSplittingDataSourceRuleConfiguration::getReadDataSourceNames).filter(Optional::isPresent)
+ .map(each ->
deconstructString(each.get())).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedList::new));
}
private Collection<String> getAutoAwareResourceRows(final
ShardingSphereMetaData metaData, final Collection<Object> notShownResourceRows)
{
@@ -130,7 +131,7 @@ public final class
ShowReadwriteSplittingReadResourcesExecutor extends AbstractS
List<String> instanceIds =
persistService.getRepository().getChildrenKeys(StorageStatusNode.getStatusPath(StorageNodeStatus.DISABLE));
if (!instanceIds.isEmpty()) {
return instanceIds.stream().filter(Objects::nonNull).filter(each
-> schemaName.equals(each.split(DELIMITER)[0])).map(each ->
each.split(DELIMITER)[1])
- .map(each -> buildRow(each,
DISABLE)).collect(Collectors.toCollection(LinkedList::new));
+ .map(each -> buildRow(each,
DISABLED)).collect(Collectors.toCollection(LinkedList::new));
}
return result;
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/rule/SchemaRulesQueryResultSet.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/rule/SchemaRulesCountResultSet.java
similarity index 98%
rename from
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/rule/SchemaRulesQueryResultSet.java
rename to
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/rule/SchemaRulesCountResultSet.java
index b47f1e0..b38b8ee 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/rule/SchemaRulesQueryResultSet.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/rule/SchemaRulesCountResultSet.java
@@ -43,7 +43,7 @@ import java.util.function.Function;
/**
* Result set for count schema rules.
*/
-public final class SchemaRulesQueryResultSet implements DistSQLResultSet {
+public final class SchemaRulesCountResultSet implements DistSQLResultSet {
private static final int DEFAULT_COUNT = 0;
@@ -90,7 +90,7 @@ public final class SchemaRulesQueryResultSet implements
DistSQLResultSet {
} else {
addDefaultData(dataMap);
}
- this.data = dataMap.values().iterator();
+ data = dataMap.values().iterator();
}
private void addSingleTableData(final Map<String, Collection<Object>>
dataMap, final Collection<SingleTableRule> rules) {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
index b4f8c88..c4c1457 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
@@ -18,5 +18,5 @@
org.apache.shardingsphere.proxy.backend.text.distsql.rql.resource.DataSourceQueryResultSet
org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.SingleTableQueryResultSet
org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.SingleTableRulesQueryResultSet
-org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.SchemaRulesQueryResultSet
+org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.SchemaRulesCountResultSet
org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.RulesUsedResourceQueryResultSet
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/SchemaRulesQueryResultSetTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/SchemaRulesCountResultSetTest.java
similarity index 97%
rename from
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/SchemaRulesQueryResultSetTest.java
rename to
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/SchemaRulesCountResultSetTest.java
index c161546..fc737b1 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/SchemaRulesQueryResultSetTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/SchemaRulesCountResultSetTest.java
@@ -26,7 +26,7 @@ import
org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.SchemaRulesQueryResultSet;
+import
org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.SchemaRulesCountResultSet;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -53,7 +53,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
-public final class SchemaRulesQueryResultSetTest {
+public final class SchemaRulesCountResultSetTest {
@Mock
private ShardingSphereMetaData shardingSphereMetaData;
@@ -101,7 +101,7 @@ public final class SchemaRulesQueryResultSetTest {
@Test
public void assertGetRowData() {
- DistSQLResultSet resultSet = new SchemaRulesQueryResultSet();
+ DistSQLResultSet resultSet = new SchemaRulesCountResultSet();
resultSet.init(shardingSphereMetaData,
mock(CountSchemaRulesStatement.class));
Collection<Object> actual = resultSet.getRowData();
assertThat(actual.size(), is(3));
@@ -149,7 +149,7 @@ public final class SchemaRulesQueryResultSetTest {
@Test
public void assertGetRowDataWithoutConfiguration() {
- DistSQLResultSet resultSet = new SchemaRulesQueryResultSet();
+ DistSQLResultSet resultSet = new SchemaRulesCountResultSet();
when(shardingSphereMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.emptyList());
resultSet.init(shardingSphereMetaData,
mock(CountSchemaRulesStatement.class));
Collection<Object> actual = resultSet.getRowData();