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 80f4296 `SHOW READWRITE_SPLITTING READ RESOURCE` syntax adds delay
time display. (#16067)
80f4296 is described below
commit 80f4296888669065e8626d4f6ae9840978f8da30
Author: lanchengx <[email protected]>
AuthorDate: Tue Mar 15 16:54:54 2022 +0800
`SHOW READWRITE_SPLITTING READ RESOURCE` syntax adds delay time display.
(#16067)
* `SHOW READWRITE_SPLITTING READ RESOURCE` syntax adds delay time display.
* Rename
* Modify the default value of the query.
* Modify integration tests.
* Modify integration tests.
---
.../ReadwriteSplittingRuleQueryResultSet.java | 4 +-
...ShowReadwriteSplittingReadResourcesHandler.java | 67 ++++++++++------------
.../alter_readwrite_splitting_rules.xml | 4 +-
.../create_readwrite_splitting_rules.xml | 4 +-
.../show_readwrite_splitting_rules.xml | 20 +++----
.../show_readwrite_splitting_rules.xml | 20 +++----
.../show_readwrite_splitting_rules.xml | 2 +-
7 files changed, 56 insertions(+), 65 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSet.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwrite
[...]
index 0a1ad89..26c0fe9 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSet.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSet.java
@@ -85,10 +85,10 @@ public final class ReadwriteSplittingRuleQueryResultSet
implements DistSQLResult
Map<String, String> exportDataSources =
DYNAMIC.equalsIgnoreCase(dataSourceConfiguration.getType()) ?
exportableAutoAwareDataSource.get(name) : exportableDataSourceMap.get(name);
Optional<ShardingSphereAlgorithmConfiguration> loadBalancer =
Optional.ofNullable(loadBalancers.get(dataSourceConfiguration.getLoadBalancerName()));
return Arrays.asList(name,
-
dataSourceConfiguration.getAutoAwareDataSourceName().orElse(null),
+
dataSourceConfiguration.getAutoAwareDataSourceName().orElse(""),
getWriteDataSourceName(dataSourceConfiguration,
exportDataSources),
getReadDataSourceNames(dataSourceConfiguration,
exportDataSources),
- loadBalancer.map(TypedSPIConfiguration::getType).orElse(null),
+ loadBalancer.map(TypedSPIConfiguration::getType).orElse(""),
loadBalancer.map(each ->
PropertiesConverter.convert(each.getProps())).orElse(""));
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java
index c4d1dce..60034b5 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java
@@ -37,14 +37,12 @@ import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.Sho
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedHashSet;
import java.util.LinkedList;
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;
@@ -59,6 +57,8 @@ public final class ShowReadwriteSplittingReadResourcesHandler
extends QueryableR
private static final String STATUS = "status";
+ private static final String DELAY_TIME = "delay_time (ms)";
+
private static final String DISABLED = "disabled";
private static final String ENABLED = "enabled";
@@ -73,7 +73,7 @@ public final class ShowReadwriteSplittingReadResourcesHandler
extends QueryableR
@Override
protected Collection<String> getColumnNames() {
- return Arrays.asList(RESOURCE, STATUS);
+ return Arrays.asList(RESOURCE, STATUS, DELAY_TIME);
}
@Override
@@ -85,32 +85,30 @@ public final class
ShowReadwriteSplittingReadResourcesHandler extends QueryableR
if
(!ProxyContext.getInstance().getAllSchemaNames().contains(schemaName)) {
throw new SchemaNotExistedException(schemaName);
}
- MetaDataContexts metaDataContexts =
ProxyContext.getInstance().getContextManager().getMetaDataContexts();
+ MetaDataContexts metaDataContexts =
contextManager.getMetaDataContexts();
ShardingSphereMetaData metaData =
metaDataContexts.getMetaData(schemaName);
- Collection<Object> notShownResourceRows = new LinkedHashSet<>();
- Collection<List<Object>> enableResourceRows =
buildEnableResourceRows(metaData, notShownResourceRows);
- Collection<List<Object>> disabledResourceRows =
buildDisableResourceRows(schemaName,
metaDataContexts.getMetaDataPersistService().orElse(null),
notShownResourceRows);
- return mergeRows(enableResourceRows, disabledResourceRows,
notShownResourceRows);
+ Collection<String> allReadResources = getAllReadResources(metaData);
+ Collection<String> disabledReadResources =
getDisabledReadResources(schemaName,
metaDataContexts.getMetaDataPersistService().orElse(null));
+ return buildRows(allReadResources, disabledReadResources);
}
- private Collection<List<Object>> buildEnableResourceRows(final
ShardingSphereMetaData metaData, final Collection<Object> notShownResourceRows)
{
- LinkedList<String> configuredResourceRows =
getConfiguredResourceRows(metaData);
- Collection<String> autoAwareResourceRows =
getAutoAwareResourceRows(metaData, notShownResourceRows);
- return Stream.of(configuredResourceRows,
autoAwareResourceRows).flatMap(Collection::stream).distinct()
- .map(each -> buildRow(each,
ENABLED)).collect(Collectors.toCollection(LinkedList::new));
+ private Collection<String> getAllReadResources(final
ShardingSphereMetaData metaData) {
+ Collection<String> configuredResources =
getConfiguredReadResources(metaData);
+ Collection<String> autoAwareResources =
getAutoAwareReadResources(metaData);
+ return Stream.of(configuredResources,
autoAwareResources).flatMap(Collection::stream).distinct().collect(Collectors.toCollection(LinkedList::new));
}
- private LinkedList<String> getConfiguredResourceRows(final
ShardingSphereMetaData metaData) {
+ private Collection<String> getConfiguredReadResources(final
ShardingSphereMetaData metaData) {
Collection<ReadwriteSplittingRuleConfiguration> ruleConfiguration =
metaData.getRuleMetaData().findRuleConfiguration(ReadwriteSplittingRuleConfiguration.class);
return
ruleConfiguration.stream().map(ReadwriteSplittingRuleConfiguration::getDataSources).flatMap(Collection::stream).filter(Objects::nonNull)
.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)
{
+ private Collection<String> getAutoAwareReadResources(final
ShardingSphereMetaData metaData) {
Map<String, Map<String, String>> autoAwareResourceData =
getAutoAwareResourceData(metaData);
- return autoAwareResourceData.entrySet().stream().peek(entry ->
notShownResourceRows.add(entry.getValue().get(ExportableConstants.PRIMARY_DATA_SOURCE_NAME)))
- .map(entry ->
entry.getValue().get(ExportableConstants.REPLICA_DATA_SOURCE_NAMES)).filter(Objects::nonNull).map(this::deconstructString)
+ return autoAwareResourceData.values().stream()
+ .map(map ->
map.get(ExportableConstants.REPLICA_DATA_SOURCE_NAMES)).filter(Objects::nonNull).map(this::deconstructString)
.flatMap(Collection::stream).collect(Collectors.toCollection(LinkedList::new));
}
@@ -121,40 +119,33 @@ public final class
ShowReadwriteSplittingReadResourcesHandler extends QueryableR
.map(Map::entrySet).flatMap(Collection::stream).filter(entry
-> !entry.getValue().isEmpty()).collect(Collectors.toMap(Entry::getKey,
Entry::getValue));
}
- private Collection<List<Object>> buildDisableResourceRows(final String
schemaName, final MetaDataPersistService persistService, final
Collection<Object> notShownResourceRows) {
+ private Collection<String> getDisabledReadResources(final String
schemaName, final MetaDataPersistService persistService) {
if (null == persistService || null == persistService.getRepository()) {
return Collections.emptyList();
}
- Collection<List<Object>> result = Collections.emptyList();
- 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,
DISABLED)).collect(Collectors.toCollection(LinkedList::new));
+ //TODO API for getting disabled nodes needs to be adjusted
+ List<String> disableResources =
persistService.getRepository().getChildrenKeys(StorageStatusNode.getStatusPath(StorageNodeStatus.DISABLE));
+ if (!disableResources.isEmpty()) {
+ return
disableResources.stream().filter(Objects::nonNull).filter(each ->
schemaName.equals(each.split(DELIMITER)[0])).map(each ->
each.split(DELIMITER)[1])
+ .collect(Collectors.toCollection(LinkedList::new));
}
- return result;
+ return Collections.emptyList();
}
- private Collection<List<Object>> mergeRows(final Collection<List<Object>>
enableResourceRows, final Collection<List<Object>> disabledResourceRows, final
Collection<Object> notShownResourceRows) {
- Collection<List<Object>> result =
replaceDisableResourceRows(enableResourceRows, disabledResourceRows);
- return result.stream().filter(each ->
!notShownResourceRows.contains(getResourceName(each))).collect(Collectors.toCollection(LinkedList::new));
+ private Collection<List<Object>> buildRows(final Collection<String>
allReadResources, final Collection<String> disabledResourceRows) {
+ return allReadResources.stream().map(each -> buildRow(each,
getDelayTime(),
disabledResourceRows.contains(each))).collect(Collectors.toCollection(LinkedList::new));
}
- private Collection<List<Object>> replaceDisableResourceRows(final
Collection<List<Object>> enableResourceRows, final Collection<List<Object>>
disabledResourceRows) {
- Set<Object> disableResourceNames =
disabledResourceRows.stream().map(this::getResourceName).collect(Collectors.toSet());
- Collection<List<Object>> result =
enableResourceRows.stream().filter(each ->
!disableResourceNames.contains(getResourceName(each))).collect(Collectors.toCollection(LinkedList::new));
- result.addAll(disabledResourceRows);
- return result;
+ private String getDelayTime() {
+ //TODO Need to implement api to get delay time
+ return "";
}
private LinkedList<String> deconstructString(final String str) {
return new LinkedList<>(Arrays.asList(str.split(",")));
}
- private List<Object> buildRow(final String resource, final String status) {
- return Arrays.asList(resource, status);
- }
-
- private Object getResourceName(final List<Object> row) {
- return row.get(0);
+ private List<Object> buildRow(final String resource, final String
delayTime, final boolean isDisabled) {
+ return Arrays.asList(resource, isDisabled ? DISABLED : ENABLED,
delayTime);
}
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/dataset/empty_rules/alter_readwrite_splitting_rules.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/dataset/empty_rules/alter_readwrite_splitting_rules.xml
index 31714b0..0235120 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/dataset/empty_rules/alter_readwrite_splitting_rules.xml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/dataset/empty_rules/alter_readwrite_splitting_rules.xml
@@ -24,6 +24,6 @@
<column name="load_balancer_type" />
<column name="load_balancer_props" />
</metadata>
- <row values="readwrite_ds_0| null| encrypt_write_ds_0| encrypt_read_ds_0|
ROUND_ROBIN| " />
- <row values="readwrite_ds_1| null| encrypt_write_ds_1|
encrypt_read_ds_1,encrypt_read_ds_2| RANDOM| read_weight='2:1'" />
+ <row values="readwrite_ds_0| | encrypt_write_ds_0| encrypt_read_ds_0|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_1| | encrypt_write_ds_1|
encrypt_read_ds_1,encrypt_read_ds_2| RANDOM| read_weight='2:1'" />
</dataset>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/dataset/empty_rules/create_readwrite_splitting_rules.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/dataset/empty_rules/create_readwrite_splitting_rules.xml
index f68ce0c..6b605bb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/dataset/empty_rules/create_readwrite_splitting_rules.xml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/dataset/empty_rules/create_readwrite_splitting_rules.xml
@@ -24,6 +24,6 @@
<column name="load_balancer_type" />
<column name="load_balancer_props" />
</metadata>
- <row values="readwrite_ds_0| null| encrypt_write_ds_0| encrypt_read_ds_0|
ROUND_ROBIN| " />
- <row values="readwrite_ds_1| null| encrypt_write_ds_1| encrypt_read_ds_1|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_0| | encrypt_write_ds_0| encrypt_read_ds_0|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_1| | encrypt_write_ds_1| encrypt_read_ds_1|
ROUND_ROBIN| " />
</dataset>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting/show_readwrite_splitting_rules.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting/show_readwrite_splitting_rules.xml
index 846ac7d..55f633f 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting/show_readwrite_splitting_rules.xml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting/show_readwrite_splitting_rules.xml
@@ -24,14 +24,14 @@
<column name="load_balancer_type" />
<column name="load_balancer_props" />
</metadata>
- <row values="readwrite_ds_0| null| write_ds_0| read_ds_0| ROUND_ROBIN| " />
- <row values="readwrite_ds_1| null| write_ds_1| read_ds_1| ROUND_ROBIN| " />
- <row values="readwrite_ds_2| null| write_ds_2| read_ds_2| ROUND_ROBIN| " />
- <row values="readwrite_ds_3| null| write_ds_3| read_ds_3| ROUND_ROBIN| " />
- <row values="readwrite_ds_4| null| write_ds_4| read_ds_4| ROUND_ROBIN| " />
- <row values="readwrite_ds_5| null| write_ds_5| read_ds_5| ROUND_ROBIN| " />
- <row values="readwrite_ds_6| null| write_ds_6| read_ds_6| ROUND_ROBIN| " />
- <row values="readwrite_ds_7| null| write_ds_7| read_ds_7| ROUND_ROBIN| " />
- <row values="readwrite_ds_8| null| write_ds_8| read_ds_8| ROUND_ROBIN| " />
- <row values="readwrite_ds_9| null| write_ds_9| read_ds_9| ROUND_ROBIN| " />
+ <row values="readwrite_ds_0| | write_ds_0| read_ds_0| ROUND_ROBIN| " />
+ <row values="readwrite_ds_1| | write_ds_1| read_ds_1| ROUND_ROBIN| " />
+ <row values="readwrite_ds_2| | write_ds_2| read_ds_2| ROUND_ROBIN| " />
+ <row values="readwrite_ds_3| | write_ds_3| read_ds_3| ROUND_ROBIN| " />
+ <row values="readwrite_ds_4| | write_ds_4| read_ds_4| ROUND_ROBIN| " />
+ <row values="readwrite_ds_5| | write_ds_5| read_ds_5| ROUND_ROBIN| " />
+ <row values="readwrite_ds_6| | write_ds_6| read_ds_6| ROUND_ROBIN| " />
+ <row values="readwrite_ds_7| | write_ds_7| read_ds_7| ROUND_ROBIN| " />
+ <row values="readwrite_ds_8| | write_ds_8| read_ds_8| ROUND_ROBIN| " />
+ <row values="readwrite_ds_9| | write_ds_9| read_ds_9| ROUND_ROBIN| " />
</dataset>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/show_readwrite_splitting_rules.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/show_readwrite_splitting_rules.xml
index a8ad196..54268eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/show_readwrite_splitting_rules.xml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/show_readwrite_splitting_rules.xml
@@ -24,14 +24,14 @@
<column name="load_balancer_type" />
<column name="load_balancer_props" />
</metadata>
- <row values="readwrite_ds_0| null| encrypt_write_ds_0| encrypt_read_ds_0|
ROUND_ROBIN| " />
- <row values="readwrite_ds_1| null| encrypt_write_ds_1| encrypt_read_ds_1|
ROUND_ROBIN| " />
- <row values="readwrite_ds_2| null| encrypt_write_ds_2| encrypt_read_ds_2|
ROUND_ROBIN| " />
- <row values="readwrite_ds_3| null| encrypt_write_ds_3| encrypt_read_ds_3|
ROUND_ROBIN| " />
- <row values="readwrite_ds_4| null| encrypt_write_ds_4| encrypt_read_ds_4|
ROUND_ROBIN| " />
- <row values="readwrite_ds_5| null| encrypt_write_ds_5| encrypt_read_ds_5|
ROUND_ROBIN| " />
- <row values="readwrite_ds_6| null| encrypt_write_ds_6| encrypt_read_ds_6|
ROUND_ROBIN| " />
- <row values="readwrite_ds_7| null| encrypt_write_ds_7| encrypt_read_ds_7|
ROUND_ROBIN| " />
- <row values="readwrite_ds_8| null| encrypt_write_ds_8| encrypt_read_ds_8|
ROUND_ROBIN| " />
- <row values="readwrite_ds_9| null| encrypt_write_ds_9| encrypt_read_ds_9|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_0| | encrypt_write_ds_0| encrypt_read_ds_0|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_1| | encrypt_write_ds_1| encrypt_read_ds_1|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_2| | encrypt_write_ds_2| encrypt_read_ds_2|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_3| | encrypt_write_ds_3| encrypt_read_ds_3|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_4| | encrypt_write_ds_4| encrypt_read_ds_4|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_5| | encrypt_write_ds_5| encrypt_read_ds_5|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_6| | encrypt_write_ds_6| encrypt_read_ds_6|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_7| | encrypt_write_ds_7| encrypt_read_ds_7|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_8| | encrypt_write_ds_8| encrypt_read_ds_8|
ROUND_ROBIN| " />
+ <row values="readwrite_ds_9| | encrypt_write_ds_9| encrypt_read_ds_9|
ROUND_ROBIN| " />
</dataset>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/readwrite_splitting/show_readwrite_splitting_rules.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/readwrite_splitting/show_readwrite_splitting_rules.xml
index 6aaf540..8dd194f 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/readwrite_splitting/show_readwrite_splitting_rules.xml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rql/dataset/readwrite_splitting/show_readwrite_splitting_rules.xml
@@ -24,5 +24,5 @@
<column name="load_balancer_type" />
<column name="load_balancer_props" />
</metadata>
- <row values="write-read-ds| null| write_ds| read_0,read_1| null| " />
+ <row values="write-read-ds| | write_ds| read_0,read_1| | " />
</dataset>