You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2024/05/19 13:57:39 UTC
(shardingsphere) branch master updated: Refactor ShowTablesExecutor, fix sort without like filter (#31305)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 6cf5e7e5259 Refactor ShowTablesExecutor, fix sort without like filter (#31305)
6cf5e7e5259 is described below
commit 6cf5e7e5259fb6b3aa4fdeaa86d38cd08da0e57a
Author: Raigor <ra...@gmail.com>
AuthorDate: Sun May 19 21:57:32 2024 +0800
Refactor ShowTablesExecutor, fix sort without like filter (#31305)
* Refactor ShowTablesExecutor, fix sort without like filter
* Fix StateChangedSubscriberTest
---
.../coordinator/subscriber/StateChangedSubscriberTest.java | 9 +++++----
.../backend/mysql/handler/admin/executor/ShowTablesExecutor.java | 9 ++++++---
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
index 4466440750e..cb0ebc565b3 100644
--- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
+++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
@@ -38,10 +38,10 @@ import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.event.ClusterLockDeletedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.event.ClusterStateEvent;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ComputeNodeInstanceStateChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOfflineEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOnlineEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.LabelsEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ComputeNodeInstanceStateChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.WorkerIdEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -64,6 +64,7 @@ import java.util.LinkedList;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
+import java.util.concurrent.CopyOnWriteArrayList;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -166,14 +167,14 @@ class StateChangedSubscriberTest {
InstanceOnlineEvent instanceOnlineEvent1 = new InstanceOnlineEvent(instanceMetaData1);
subscriber.renew(instanceOnlineEvent1);
assertThat(contextManager.getInstanceContext().getAllClusterComputeNodeInstances().size(), is(1));
- assertThat(((LinkedList<ComputeNodeInstance>) contextManager.getInstanceContext().getAllClusterComputeNodeInstances()).get(0).getMetaData(), is(instanceMetaData1));
+ assertThat(((CopyOnWriteArrayList<ComputeNodeInstance>) contextManager.getInstanceContext().getAllClusterComputeNodeInstances()).get(0).getMetaData(), is(instanceMetaData1));
InstanceMetaData instanceMetaData2 = new ProxyInstanceMetaData("foo_instance_3308", 3308);
InstanceOnlineEvent instanceOnlineEvent2 = new InstanceOnlineEvent(instanceMetaData2);
subscriber.renew(instanceOnlineEvent2);
assertThat(contextManager.getInstanceContext().getAllClusterComputeNodeInstances().size(), is(2));
- assertThat(((LinkedList<ComputeNodeInstance>) contextManager.getInstanceContext().getAllClusterComputeNodeInstances()).get(1).getMetaData(), is(instanceMetaData2));
+ assertThat(((CopyOnWriteArrayList<ComputeNodeInstance>) contextManager.getInstanceContext().getAllClusterComputeNodeInstances()).get(1).getMetaData(), is(instanceMetaData2));
subscriber.renew(instanceOnlineEvent1);
assertThat(contextManager.getInstanceContext().getAllClusterComputeNodeInstances().size(), is(2));
- assertThat(((LinkedList<ComputeNodeInstance>) contextManager.getInstanceContext().getAllClusterComputeNodeInstances()).get(1).getMetaData(), is(instanceMetaData1));
+ assertThat(((CopyOnWriteArrayList<ComputeNodeInstance>) contextManager.getInstanceContext().getAllClusterComputeNodeInstances()).get(1).getMetaData(), is(instanceMetaData1));
}
}
diff --git a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutor.java b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutor.java
index 4c1478dee34..23464dd4ead 100644
--- a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutor.java
+++ b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutor.java
@@ -97,10 +97,13 @@ public final class ShowTablesExecutor implements DatabaseAdminQueryExecutor {
private Collection<ShardingSphereTable> getTables(final String databaseName) {
Collection<ShardingSphereTable> tables = ProxyContext.getInstance().getContextManager().getDatabase(databaseName).getSchema(databaseName).getTables().values();
+ Collection<ShardingSphereTable> filteredTables = filterByLike(tables);
+ return filteredTables.stream().sorted(Comparator.comparing(ShardingSphereTable::getName)).collect(Collectors.toList());
+ }
+
+ private Collection<ShardingSphereTable> filterByLike(final Collection<ShardingSphereTable> tables) {
Optional<Pattern> likePattern = getLikePattern();
- return likePattern.isPresent()
- ? tables.stream().filter(each -> likePattern.get().matcher(each.getName()).matches()).sorted(Comparator.comparing(ShardingSphereTable::getName)).collect(Collectors.toList())
- : tables;
+ return likePattern.isPresent() ? tables.stream().filter(each -> likePattern.get().matcher(each.getName()).matches()).collect(Collectors.toList()) : tables;
}
private Optional<Pattern> getLikePattern() {