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/22 07:17:53 UTC

[shardingsphere] branch master updated: [DistSQL] `show readwrite_splitting read resources` repeated display. (#13217)

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 4a580de  [DistSQL] `show readwrite_splitting read resources` repeated display. (#13217)
4a580de is described below

commit 4a580de930e79092778a9c9b84d7bc26195e3e91
Author: lanchengx <52...@users.noreply.github.com>
AuthorDate: Fri Oct 22 02:17:11 2021 -0500

    [DistSQL] `show readwrite_splitting read resources` repeated display. (#13217)
    
    * fixed: `show readwrite_splitting read resources` repeat display.
    
    * fixed: `show readwrite_splitting read resources` repeat display.
---
 ...howReadwriteSplittingReadResourcesExecutor.java | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

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 6f7155d..6bda0c1 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
@@ -78,21 +78,21 @@ public final class ShowReadwriteSplittingReadResourcesExecutor extends AbstractS
             throw new SchemaNotExistedException(schemaName);
         }
         ShardingSphereMetaData metaData = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName);
-        Collection<List<Object>> rows = buildInstanceRows(metaData, ENABLE);
+        Collection<List<Object>> rows = buildResourceRows(metaData, ENABLE);
         MetaDataPersistService persistService = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataPersistService().orElse(null);
         if (null == persistService || null == persistService.getRepository()) {
             return new MultipleLocalDataMergedResult(rows);
         }
-        Collection<List<Object>> disableInstanceRows = buildInstanceRows(persistService, DISABLE);
-        return new MultipleLocalDataMergedResult(mergeRows(rows, disableInstanceRows));
+        Collection<List<Object>> disabledResourceRows = buildResourceRows(persistService, DISABLE);
+        return new MultipleLocalDataMergedResult(mergeRows(rows, disabledResourceRows));
     }
     
-    private Collection<List<Object>> buildInstanceRows(final ShardingSphereMetaData metaData, final String status) {
+    private Collection<List<Object>> buildResourceRows(final ShardingSphereMetaData metaData, final String status) {
         Set<String> allResources = metaData.getResource().getDataSources().keySet();
         return allResources.stream().map(each -> buildRow(each, status)).collect(Collectors.toCollection(LinkedList::new));
     }
     
-    private Collection<List<Object>> buildInstanceRows(final MetaDataPersistService persistService, final String status) {
+    private Collection<List<Object>> buildResourceRows(final MetaDataPersistService persistService, final String status) {
         List<String> instanceIds = persistService.getRepository().getChildrenKeys(StorageStatusNode.getStatusPath(status.equals(DISABLE) ? StorageNodeStatus.DISABLE : StorageNodeStatus.PRIMARY));
         if (!instanceIds.isEmpty()) {
             return instanceIds.stream().filter(Objects::nonNull).map(each -> each.split(DELIMITER)[1]).map(each -> buildRow(each, status)).collect(Collectors.toCollection(LinkedList::new));
@@ -100,15 +100,19 @@ public final class ShowReadwriteSplittingReadResourcesExecutor extends AbstractS
         return Collections.emptyList();
     }
     
-    private Collection<List<Object>> mergeRows(final Collection<List<Object>> rows, final Collection<List<Object>> disableInstanceRow) {
+    private Collection<List<Object>> mergeRows(final Collection<List<Object>> rows, final Collection<List<Object>> disabledResourceRows) {
         Collection<List<Object>> result;
-        Set<Object> disableResource = disableInstanceRow.stream().flatMap(Collection::stream).filter(each -> !each.equals(DISABLE)).collect(Collectors.toSet());
-        result = rows.stream().filter(each -> !disableResource.contains(each)).collect(Collectors.toCollection(LinkedList::new));
-        result.addAll(disableInstanceRow);
+        Set<Object> disabledResourceNames = disabledResourceRows.stream().map(each -> getResourceName(each)).collect(Collectors.toSet());
+        result = rows.stream().filter(each -> !disabledResourceNames.contains(getResourceName(each))).collect(Collectors.toCollection(LinkedList::new));
+        result.addAll(disabledResourceRows);
         return result;
     }
     
     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);
+    }
 }