From ff4344a2a871b105b4d4ddab232bc1adab5586a4 Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Mon, 28 Oct 2024 17:03:15 +0800 Subject: [PATCH 1/6] Add database name for JDBC when execute SHWO COMPUTE NODES and SHOW COMPUTE NODE INFO --- .../circuit-breaker/show-compute-nodes.cn.md | 33 ++++++++++--------- .../circuit-breaker/show-compute-nodes.en.md | 33 ++++++++++--------- .../syntax/ral/show-compute-node-info.cn.md | 13 +++++--- .../syntax/ral/show-compute-node-info.en.md | 14 ++++---- .../infra/instance/ComputeNodeData.java | 2 ++ .../instance/metadata/InstanceMetaData.java | 9 +++++ .../metadata/InstanceMetaDataBuilder.java | 3 +- .../metadata/InstanceMetaDataFactory.java | 5 +-- .../metadata/jdbc/JDBCInstanceMetaData.java | 15 +++++++-- .../jdbc/JDBCInstanceMetaDataBuilder.java | 4 +-- .../proxy/ProxyInstanceMetaDataBuilder.java | 2 +- .../instance/yaml/YamlComputeNodeData.java | 2 ++ .../yaml/YamlComputeNodeDataSwapper.java | 3 +- .../metadata/InstanceMetaDataFactoryTest.java | 4 +-- .../jdbc/JDBCInstanceMetaDataBuilderTest.java | 2 +- .../ProxyInstanceMetaDataBuilderTest.java | 2 +- .../datasource/ShardingSphereDataSource.java | 2 +- .../service/ComputeNodePersistService.java | 5 +-- .../mode/manager/ContextManagerTest.java | 2 +- ...ComputeNodeOnlineDispatchEventBuilder.java | 2 +- .../ClusterContextManagerBuilderTest.java | 2 +- .../StandaloneContextManagerBuilderTest.java | 2 +- .../ShowComputeNodeInfoExecutor.java | 4 +-- .../queryable/ShowComputeNodesExecutor.java | 4 +-- .../ShowComputeNodeInfoExecutorTest.java | 1 + .../ShowComputeNodesExecutorTest.java | 2 ++ .../initializer/BootstrapInitializer.java | 2 +- 27 files changed, 106 insertions(+), 68 deletions(-) diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/circuit-breaker/show-compute-nodes.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/circuit-breaker/show-compute-nodes.cn.md index 3d8b34819da78..8c33d9df85546 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/circuit-breaker/show-compute-nodes.cn.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/circuit-breaker/show-compute-nodes.cn.md @@ -23,27 +23,28 @@ ShowComputeNodes ::= ### 返回值说明 -| 列 | 说明 | -|---------------|-----------| -| instance_id | 实例 id | -| instance_type | 实例类型 | -| host | 主机地址 | -| port | 端口号 | -| status | 实例状态 | -| mode_type | 模式类型 | -| worker_id | worker id | -| labels | 标签 | -| version | 版本 | +| 列 | 说明 | +|---------------|---------------------| +| instance_id | 实例 id | +| instance_type | 实例类型 | +| host | 主机地址 | +| port | 端口号 | +| status | 实例状态 | +| mode_type | 模式类型 | +| worker_id | worker id | +| labels | 标签 | +| version | 版本 | +| database_name | 当前连接逻辑库(仅对 JDBC 生效) | ### 示例 ```sql mysql> SHOW COMPUTE NODES; -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ -| instance_id | instance_type | host | port | status | mode_type | worker_id | labels | version | -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ -| 3e84d33e-cb97-42f2-b6ce-f78fea0ded89 | PROXY | 127.0.0.1 | 3307 | OK | Cluster | -1 | | 5.4.2 | -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ +| instance_id | instance_type | host | port | status | mode_type | worker_id | labels | version | database_name | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ +| 3e84d33e-cb97-42f2-b6ce-f78fea0ded89 | PROXY | 127.0.0.1 | 3307 | OK | Cluster | -1 | | 5.4.2 | logic_db | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ 1 row in set (0.01 sec) ``` diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/circuit-breaker/show-compute-nodes.en.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/circuit-breaker/show-compute-nodes.en.md index a603c863166c2..fdc82f8746a78 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/circuit-breaker/show-compute-nodes.en.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/circuit-breaker/show-compute-nodes.en.md @@ -22,27 +22,28 @@ ShowComputeNodes ::= ### Return Value Description -| Columns | Description | -|---------------|---------------| -| instance_id | instance id | -| instance_type | instance type | -| host | host | -| port | port | -| status | status | -| mode_type | mode type | -| worker_id | worker id | -| labels | labels | -| version | version | +| Columns | Description | +|---------------|------------------| +| instance_id | instance id | +| instance_type | instance type | +| host | host | +| port | port | +| status | status | +| mode_type | mode type | +| worker_id | worker id | +| labels | labels | +| version | version | +| database_name | database name (Only valid for JDBC) | ### Example ```sql mysql> SHOW COMPUTE NODES; -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ -| instance_id | instance_type | host | port | status | mode_type | worker_id | labels | version | -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ -| 3e84d33e-cb97-42f2-b6ce-f78fea0ded89 | PROXY | 127.0.0.1 | 3307 | OK | Cluster | -1 | | 5.4.2 | -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ +| instance_id | instance_type | host | port | status | mode_type | worker_id | labels | version | database_name | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ +| 3e84d33e-cb97-42f2-b6ce-f78fea0ded89 | PROXY | 127.0.0.1 | 3307 | OK | Cluster | -1 | | 5.4.2 | logic_db | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ 1 row in set (0.01 sec) ``` diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.cn.md index ece44283b1374..5b689b1dfe950 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.cn.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.cn.md @@ -32,6 +32,8 @@ ShowComputeNodeInfo ::= | mode_type | proxy 实例模式 | | worker_id | worker id | | labels | 标签 | +| version | 版本 | +| database_name | 当前连接逻辑库(仅对 JDBC 生效) | ### 示例 @@ -43,11 +45,12 @@ SHOW COMPUTE NODE INFO; ```sql mysql> SHOW COMPUTE NODE INFO; -+--------------------------------------+---------------+------+--------+-----------+-----------+--------+ -| instance_id | host | port | status | mode_type | worker_id | labels | -+--------------------------------------+---------------+------+--------+-----------+-----------+--------+ -| 734bb036-b15d-4af0-be87-2372d8b6a0cd | 192.168.5.163 | 3307 | OK | Cluster | -1 | | -+--------------------------------------+---------------+------+--------+-----------+-----------+--------+ +mysql> SHOW COMPUTE NODES; ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ +| instance_id | instance_type | host | port | status | mode_type | worker_id | labels | version | database_name | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ +| 3e84d33e-cb97-42f2-b6ce-f78fea0ded89 | PROXY | 127.0.0.1 | 3307 | OK | Cluster | -1 | | 5.4.2 | logic_db | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ 1 row in set (0.01 sec) ``` diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.en.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.en.md index ecf153831224e..fb55310ad8517 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.en.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.en.md @@ -31,6 +31,8 @@ ShowComputeNodeInfo ::= | mode_type | proxy instance mode | | worker_id | worker id | | labels | labels | +| version | version | +| database_name | database name (Only valid for JDBC) | ### Example @@ -41,12 +43,12 @@ SHOW COMPUTE NODE INFO; ``` ```sql -mysql> SHOW COMPUTE NODE INFO; -+--------------------------------------+---------------+------+--------+-----------+-----------+--------+ -| instance_id | host | port | status | mode_type | worker_id | labels | -+--------------------------------------+---------------+------+--------+-----------+-----------+--------+ -| 734bb036-b15d-4af0-be87-2372d8b6a0cd | 192.168.5.163 | 3307 | OK | Cluster | -1 | | -+--------------------------------------+---------------+------+--------+-----------+-----------+--------+ +mysql> SHOW COMPUTE NODES; ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ +| instance_id | instance_type | host | port | status | mode_type | worker_id | labels | version | database_name | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ +| 3e84d33e-cb97-42f2-b6ce-f78fea0ded89 | PROXY | 127.0.0.1 | 3307 | OK | Cluster | -1 | | 5.4.2 | logic_db | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ 1 row in set (0.01 sec) ``` diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeData.java index bda98e86435c1..0f3d8c779a9f2 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeData.java @@ -30,4 +30,6 @@ public final class ComputeNodeData { private final String attribute; private final String version; + + private final String databaseName; } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaData.java index baf666227096e..8d21aba6588fb 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaData.java @@ -56,4 +56,13 @@ public interface InstanceMetaData { * @return version */ String getVersion(); + + /** + * Get database name + * + * @return database name + */ + default String getDatabaseName() { + return ""; + } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataBuilder.java index e58be85c826a0..a157cefba0bbf 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataBuilder.java @@ -30,7 +30,8 @@ public interface InstanceMetaDataBuilder extends TypedSPI { * Build instance meta data. * * @param port port + * @param databaseName database name * @return built instance meta data */ - InstanceMetaData build(int port); + InstanceMetaData build(int port, String databaseName); } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactory.java index 4f2929797c2db..4fe6a173fba27 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactory.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactory.java @@ -35,9 +35,10 @@ public final class InstanceMetaDataFactory { * @param instanceType instance type * @param attributes attributes * @param version version + * @param databaseName database name * @return created instance meta data */ - public static InstanceMetaData create(final String instanceId, final InstanceType instanceType, final String attributes, final String version) { - return InstanceType.JDBC == instanceType ? new JDBCInstanceMetaData(instanceId, attributes, version) : new ProxyInstanceMetaData(instanceId, attributes, version); + public static InstanceMetaData create(final String instanceId, final InstanceType instanceType, final String attributes, final String version, final String databaseName) { + return InstanceType.JDBC == instanceType ? new JDBCInstanceMetaData(instanceId, attributes, version, databaseName) : new ProxyInstanceMetaData(instanceId, attributes, version); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaData.java index 989a7c29697be..1174a0650122a 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaData.java @@ -35,16 +35,20 @@ public final class JDBCInstanceMetaData implements InstanceMetaData { private final String version; - public JDBCInstanceMetaData(final String id) { + private final String databaseName; + + public JDBCInstanceMetaData(final String id, final String databaseName) { this.id = id; ip = IpUtils.getIp(); version = ShardingSphereVersion.VERSION; + this.databaseName = databaseName; } - public JDBCInstanceMetaData(final String id, final String attributes, final String version) { + public JDBCInstanceMetaData(final String id, final String attributes, final String version, final String databaseName) { this.id = id; ip = attributes; this.version = version; + this.databaseName = databaseName; } @Override @@ -56,4 +60,11 @@ public InstanceType getType() { public String getAttributes() { return ip; } + + @Override + public String getDatabaseName() { + return databaseName; + } + + } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaDataBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaDataBuilder.java index b055be7991d1d..031daded56250 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaDataBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaDataBuilder.java @@ -28,8 +28,8 @@ public final class JDBCInstanceMetaDataBuilder implements InstanceMetaDataBuilder { @Override - public InstanceMetaData build(final int port) { - return new JDBCInstanceMetaData(UUID.randomUUID().toString()); + public InstanceMetaData build(final int port, final String databaseName) { + return new JDBCInstanceMetaData(UUID.randomUUID().toString(), databaseName); } @Override diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/proxy/ProxyInstanceMetaDataBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/proxy/ProxyInstanceMetaDataBuilder.java index b01721fa66778..3ee4332b4e577 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/proxy/ProxyInstanceMetaDataBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/proxy/ProxyInstanceMetaDataBuilder.java @@ -28,7 +28,7 @@ public final class ProxyInstanceMetaDataBuilder implements InstanceMetaDataBuilder { @Override - public InstanceMetaData build(final int port) { + public InstanceMetaData build(final int port, final String databaseName) { return new ProxyInstanceMetaData(UUID.randomUUID().toString(), port); } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeData.java index 36d782c616ec1..efc857e49181a 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeData.java @@ -31,4 +31,6 @@ public final class YamlComputeNodeData implements YamlConfiguration { private String attribute; private String version; + + private String databaseName; } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeDataSwapper.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeDataSwapper.java index e53e0ef7e21d0..f2e7916d34f77 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeDataSwapper.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeDataSwapper.java @@ -30,11 +30,12 @@ public YamlComputeNodeData swapToYamlConfiguration(final ComputeNodeData data) { YamlComputeNodeData result = new YamlComputeNodeData(); result.setAttribute(data.getAttribute()); result.setVersion(data.getVersion()); + result.setDatabaseName(data.getVersion()); return result; } @Override public ComputeNodeData swapToObject(final YamlComputeNodeData yamlConfig) { - return new ComputeNodeData(yamlConfig.getAttribute(), yamlConfig.getVersion()); + return new ComputeNodeData(yamlConfig.getAttribute(), yamlConfig.getVersion(), yamlConfig.getDatabaseName()); } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactoryTest.java index bbb091b153acd..de5e15a5b6d4d 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactoryTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactoryTest.java @@ -28,7 +28,7 @@ class InstanceMetaDataFactoryTest { @Test void assertCreateJDBCInstanceMetaDataWithInstanceId() { - InstanceMetaData actual = InstanceMetaDataFactory.create("foo_id", InstanceType.JDBC, "127.0.0.1", "foo_version"); + InstanceMetaData actual = InstanceMetaDataFactory.create("foo_id", InstanceType.JDBC, "127.0.0.1", "foo_version", "foo_db"); assertThat(actual.getId(), is("foo_id")); assertNotNull(actual.getIp()); assertThat(actual.getAttributes(), is("127.0.0.1")); @@ -38,7 +38,7 @@ void assertCreateJDBCInstanceMetaDataWithInstanceId() { @Test void assertCreateProxyInstanceMetaDataWithInstanceId() { - ProxyInstanceMetaData actual = (ProxyInstanceMetaData) InstanceMetaDataFactory.create("foo_id", InstanceType.PROXY, "127.0.0.1@3307", "foo_version"); + ProxyInstanceMetaData actual = (ProxyInstanceMetaData) InstanceMetaDataFactory.create("foo_id", InstanceType.PROXY, "127.0.0.1@3307", "foo_version", "foo_db"); assertThat(actual.getId(), is("foo_id")); assertThat(actual.getIp(), is("127.0.0.1")); assertThat(actual.getPort(), is(3307)); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaDataBuilderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaDataBuilderTest.java index c93933b127d28..8cb711c71b809 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaDataBuilderTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaDataBuilderTest.java @@ -31,6 +31,6 @@ class JDBCInstanceMetaDataBuilderTest { @Test void assertBuild() { - assertThat(instanceMetaDataBuilder.build(3306).getType(), is(InstanceType.JDBC)); + assertThat(instanceMetaDataBuilder.build(3306, "foo_db").getType(), is(InstanceType.JDBC)); } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/proxy/ProxyInstanceMetaDataBuilderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/proxy/ProxyInstanceMetaDataBuilderTest.java index 9008359eb9b58..baff6466d5b9e 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/proxy/ProxyInstanceMetaDataBuilderTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/proxy/ProxyInstanceMetaDataBuilderTest.java @@ -31,6 +31,6 @@ class ProxyInstanceMetaDataBuilderTest { @Test void assertBuild() { - assertThat(instanceMetaDataBuilder.build(3306).getType(), is(InstanceType.PROXY)); + assertThat(instanceMetaDataBuilder.build(3306, "").getType(), is(InstanceType.PROXY)); } } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java index b4c91965a3a4a..be7951f6c60d3 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java @@ -65,7 +65,7 @@ public ShardingSphereDataSource(final String databaseName, final ModeConfigurati private ContextManager createContextManager(final ModeConfiguration modeConfig, final Map dataSourceMap, final Collection ruleConfigs, final Properties props) throws SQLException { - InstanceMetaData instanceMetaData = TypedSPILoader.getService(InstanceMetaDataBuilder.class, "JDBC").build(-1); + InstanceMetaData instanceMetaData = TypedSPILoader.getService(InstanceMetaDataBuilder.class, "JDBC").build(-1, databaseName); Collection globalRuleConfigs = ruleConfigs.stream().filter(GlobalRuleConfiguration.class::isInstance).collect(Collectors.toList()); Collection databaseRuleConfigs = new LinkedList<>(ruleConfigs); databaseRuleConfigs.removeAll(globalRuleConfigs); diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/ComputeNodePersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/ComputeNodePersistService.java index a130733c01676..1c6c4387f1156 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/ComputeNodePersistService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/ComputeNodePersistService.java @@ -56,7 +56,8 @@ public final class ComputeNodePersistService { public void registerOnline(final ComputeNodeInstance computeNodeInstance) { String instanceId = computeNodeInstance.getMetaData().getId(); repository.persistEphemeral(ComputeNode.getOnlineInstanceNodePath(instanceId, computeNodeInstance.getMetaData().getType()), YamlEngine.marshal( - new YamlComputeNodeDataSwapper().swapToYamlConfiguration(new ComputeNodeData(computeNodeInstance.getMetaData().getAttributes(), computeNodeInstance.getMetaData().getVersion())))); + new YamlComputeNodeDataSwapper().swapToYamlConfiguration(new ComputeNodeData(computeNodeInstance.getMetaData().getAttributes(), + computeNodeInstance.getMetaData().getVersion(), computeNodeInstance.getMetaData().getDatabaseName())))); repository.persistEphemeral(ComputeNode.getComputeNodeStateNodePath(instanceId), computeNodeInstance.getState().getCurrentState().name()); persistInstanceLabels(instanceId, computeNodeInstance.getLabels()); } @@ -136,7 +137,7 @@ private Collection loadComputeNodeInstances(final InstanceT continue; } ComputeNodeData computeNodeData = new YamlComputeNodeDataSwapper().swapToObject(YamlEngine.unmarshal(value, YamlComputeNodeData.class)); - result.add(loadComputeNodeInstance(InstanceMetaDataFactory.create(each, instanceType, computeNodeData.getAttribute(), computeNodeData.getVersion()))); + result.add(loadComputeNodeInstance(InstanceMetaDataFactory.create(each, instanceType, computeNodeData.getAttribute(), computeNodeData.getVersion(), computeNodeData.getDatabaseName()))); } return result; } diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java index 8a3fd8d987ca3..5797530910f85 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java @@ -162,7 +162,7 @@ void assertReloadTableWithDataSourceName() { @Test void assertGetPreSelectedDatabaseNameWithJDBC() { - when(computeNodeInstanceContext.getInstance()).thenReturn(new ComputeNodeInstance(new JDBCInstanceMetaData("foo_id"), Collections.emptyList())); + when(computeNodeInstanceContext.getInstance()).thenReturn(new ComputeNodeInstance(new JDBCInstanceMetaData("foo_id", "foo_db"), Collections.emptyList())); when(metaDataContexts.getMetaData().getDatabases()).thenReturn(Collections.singletonMap("foo_db", mock(ShardingSphereDatabase.class))); assertThat(contextManager.getPreSelectedDatabaseName(), is("foo_db")); } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeOnlineDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeOnlineDispatchEventBuilder.java index 79f540ecc193f..6e6b7dc9e3248 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeOnlineDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeOnlineDispatchEventBuilder.java @@ -64,7 +64,7 @@ private Optional createInstanceEvent(final DataChangedEvent event } ComputeNodeData computeNodeData = new YamlComputeNodeDataSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlComputeNodeData.class)); InstanceMetaData instanceMetaData = InstanceMetaDataFactory.create( - matcher.group(2), InstanceType.valueOf(matcher.group(1).toUpperCase()), computeNodeData.getAttribute(), computeNodeData.getVersion()); + matcher.group(2), InstanceType.valueOf(matcher.group(1).toUpperCase()), computeNodeData.getAttribute(), computeNodeData.getVersion(), computeNodeData.getDatabaseName()); if (Type.ADDED == event.getType()) { return Optional.of(new InstanceOnlineEvent(instanceMetaData)); } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilderTest.java index 765d53891c315..ada4bea9f1128 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilderTest.java @@ -63,7 +63,7 @@ void assertBuildWithNullRepositoryConfiguration() { @Test void assertBuildForJDBC() throws SQLException { - assertBuild(new JDBCInstanceMetaData("foo")); + assertBuild(new JDBCInstanceMetaData("foo", "foo_db")); } @Test diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTest.java index ffbc159fc85b4..f03294c51ce69 100644 --- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTest.java +++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTest.java @@ -52,7 +52,7 @@ void assertBuildWithDefault() throws SQLException { @SuppressWarnings("resource") void assertBuild(final ContextManagerBuilder builder) throws SQLException { - InstanceMetaData instanceMetaData = new JDBCInstanceMetaData("foo"); + InstanceMetaData instanceMetaData = new JDBCInstanceMetaData("foo", "foo_db"); ContextManager actual = builder.build(new ContextManagerBuilderParameter(createModeConfiguration(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), Collections.emptyList(), instanceMetaData, false), mock(EventBusContext.class)); assertThat(actual.getComputeNodeInstanceContext().getInstance().getMetaData(), is(instanceMetaData)); diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutor.java index 11451ae65e5e6..831dfd8175e9b 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutor.java @@ -36,7 +36,7 @@ public final class ShowComputeNodeInfoExecutor implements DistSQLQueryExecutor getColumnNames(final ShowComputeNodeInfoStatement sqlStatement) { - return Arrays.asList("instance_id", "host", "port", "status", "mode_type", "worker_id", "labels", "version"); + return Arrays.asList("instance_id", "host", "port", "status", "mode_type", "worker_id", "labels", "version", "database_name"); } @Override @@ -47,7 +47,7 @@ public Collection getRows(final ShowComputeNodeInfoStat return Collections.singletonList(new LocalDataQueryResultRow(instanceMetaData.getId(), instanceMetaData.getIp(), instanceMetaData instanceof ProxyInstanceMetaData ? ((ProxyInstanceMetaData) instanceMetaData).getPort() : -1, instance.getState().getCurrentState(), modeType, instance.getWorkerId(), String.join(",", instance.getLabels()), - instanceMetaData.getVersion())); + instanceMetaData.getVersion(), instanceMetaData.getDatabaseName())); } @Override diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutor.java index b833a9eddbfc9..c78adb2bb52f7 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutor.java @@ -37,7 +37,7 @@ public final class ShowComputeNodesExecutor implements DistSQLQueryExecutor getColumnNames(final ShowComputeNodesStatement sqlStatement) { - return Arrays.asList("instance_id", "instance_type", "host", "port", "status", "mode_type", "worker_id", "labels", "version"); + return Arrays.asList("instance_id", "instance_type", "host", "port", "status", "mode_type", "worker_id", "labels", "version", "database_name"); } @Override @@ -53,7 +53,7 @@ private LocalDataQueryResultRow buildRow(final ComputeNodeInstance instance, fin InstanceMetaData instanceMetaData = instance.getMetaData(); return new LocalDataQueryResultRow(instanceMetaData.getId(), instanceMetaData.getType(), instanceMetaData.getIp(), instanceMetaData instanceof ProxyInstanceMetaData ? ((ProxyInstanceMetaData) instanceMetaData).getPort() : -1, - instance.getState().getCurrentState(), modeType, instance.getWorkerId(), labels, instanceMetaData.getVersion()); + instance.getState().getCurrentState(), modeType, instance.getWorkerId(), labels, instanceMetaData.getVersion(), instanceMetaData.getDatabaseName()); } @Override diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutorTest.java index be8685bde14a3..f3dbc10ca625d 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutorTest.java @@ -55,6 +55,7 @@ void assertExecute() { assertThat(row.getCell(6), is("0")); assertThat(row.getCell(7), is("")); assertThat(row.getCell(8), is("foo_version")); + assertThat(row.getCell(9), is("")); } private ComputeNodeInstanceContext createInstanceContext() { diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutorTest.java index 699683dd202dc..89d8fb6ca05d2 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutorTest.java @@ -59,6 +59,7 @@ void assertExecuteWithStandaloneMode() { assertThat(row.getCell(7), is("0")); assertThat(row.getCell(8), is("")); assertThat(row.getCell(9), is("foo_version")); + assertThat(row.getCell(10), is("")); } @Test @@ -79,6 +80,7 @@ void assertExecuteWithClusterMode() { assertThat(row.getCell(7), is("1")); assertThat(row.getCell(8), is("")); assertThat(row.getCell(9), is("foo_version")); + assertThat(row.getCell(10), is("")); } private ComputeNodeInstanceContext createStandaloneInstanceContext() { diff --git a/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java b/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java index 428bd797cf3b8..25fb984fbb04e 100644 --- a/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java +++ b/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java @@ -56,7 +56,7 @@ public void init(final YamlProxyConfiguration yamlConfig, final int port, final } private ContextManager createContextManager(final ProxyConfiguration proxyConfig, final ModeConfiguration modeConfig, final int port, final boolean force) throws SQLException { - InstanceMetaData instanceMetaData = TypedSPILoader.getService(InstanceMetaDataBuilder.class, "Proxy").build(port); + InstanceMetaData instanceMetaData = TypedSPILoader.getService(InstanceMetaDataBuilder.class, "Proxy").build(port, ""); ContextManagerBuilderParameter param = new ContextManagerBuilderParameter(modeConfig, proxyConfig.getDatabaseConfigurations(), proxyConfig.getGlobalConfiguration().getDataSources(), proxyConfig.getGlobalConfiguration().getRules(), proxyConfig.getGlobalConfiguration().getProperties(), proxyConfig.getGlobalConfiguration().getLabels(), instanceMetaData, force); return TypedSPILoader.getService(ContextManagerBuilder.class, null == modeConfig ? null : modeConfig.getType()).build(param, new EventBusContext()); From 690822a178c65a854ed00e8ba244b954177c4cbb Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Mon, 28 Oct 2024 17:07:15 +0800 Subject: [PATCH 2/6] Fix E2E --- .../ral/dataset/empty_rules/cluster/show_compute_node_info.xml | 3 ++- .../ral/dataset/empty_rules/cluster/show_compute_nodes.xml | 3 ++- .../dataset/empty_rules/standalone/show_compute_node_info.xml | 3 ++- .../ral/dataset/empty_rules/standalone/show_compute_nodes.xml | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_node_info.xml b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_node_info.xml index 9171e4b2eabac..61b81a0d2322e 100644 --- a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_node_info.xml +++ b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_node_info.xml @@ -25,6 +25,7 @@ + - + diff --git a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_nodes.xml b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_nodes.xml index cd6ce8d041818..45f44d371595b 100644 --- a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_nodes.xml +++ b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_nodes.xml @@ -26,6 +26,7 @@ + - + diff --git a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml index 8c7f25dc6f75c..0ee850be50aee 100644 --- a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml +++ b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml @@ -25,6 +25,7 @@ + - + diff --git a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_nodes.xml b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_nodes.xml index 41af8c773c607..8176ae868d78b 100644 --- a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_nodes.xml +++ b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_nodes.xml @@ -26,6 +26,7 @@ + - + From 70e884db5935644514fe6c7bf27c82fdaac5b2f3 Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Mon, 28 Oct 2024 17:28:54 +0800 Subject: [PATCH 3/6] Fix checkstyle --- .../infra/instance/metadata/InstanceMetaData.java | 2 +- .../infra/instance/metadata/jdbc/JDBCInstanceMetaData.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaData.java index 8d21aba6588fb..31e8674768760 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaData.java @@ -58,7 +58,7 @@ public interface InstanceMetaData { String getVersion(); /** - * Get database name + * Get database name. * * @return database name */ diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaData.java index 1174a0650122a..10a60d961ef70 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/jdbc/JDBCInstanceMetaData.java @@ -66,5 +66,4 @@ public String getDatabaseName() { return databaseName; } - } From 3e7e4966f6ef21c802156faa152965378ee859b2 Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Mon, 28 Oct 2024 17:33:11 +0800 Subject: [PATCH 4/6] Update release note --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index e60548a2520d6..d794a91d093af 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -15,6 +15,7 @@ 1. Add arguments not null check when creating RouteUnit - [#33382](https://github.com/apache/shardingsphere/pull/33382) 1. Add index columns not empty judgement for IndexColumnTokenGenerator - [#33384](https://github.com/apache/shardingsphere/pull/33384) 1. SQL Parser: Support parsing Doris STRRIGHT - [#33393](https://github.com/apache/shardingsphere/pull/33393) +1. JDBC: Add show database name for JDBC when execute SHOW COMPUTE NODES and SHOW COMPUTE NODE INFO - [#33437](https://github.com/apache/shardingsphere/pull/33437) ### Bug Fixes From 53e65f32d720aee49c9622c1c6b3e5474719427e Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Mon, 28 Oct 2024 17:42:20 +0800 Subject: [PATCH 5/6] Update --- RELEASE-NOTES.md | 2 +- .../syntax/ral/show-compute-node-info.cn.md | 11 +++++----- .../syntax/ral/show-compute-node-info.en.md | 11 +++++----- .../ShowComputeNodeInfoExecutor.java | 4 ++-- .../ShowComputeNodeInfoExecutorTest.java | 1 - .../src/main/resources/conf/global.yaml | 22 +++++++++---------- .../cluster/show_compute_node_info.xml | 3 +-- .../standalone/show_compute_node_info.xml | 3 +-- 8 files changed, 26 insertions(+), 31 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index d794a91d093af..dc1a84afae79b 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -15,7 +15,7 @@ 1. Add arguments not null check when creating RouteUnit - [#33382](https://github.com/apache/shardingsphere/pull/33382) 1. Add index columns not empty judgement for IndexColumnTokenGenerator - [#33384](https://github.com/apache/shardingsphere/pull/33384) 1. SQL Parser: Support parsing Doris STRRIGHT - [#33393](https://github.com/apache/shardingsphere/pull/33393) -1. JDBC: Add show database name for JDBC when execute SHOW COMPUTE NODES and SHOW COMPUTE NODE INFO - [#33437](https://github.com/apache/shardingsphere/pull/33437) +1. JDBC: Add show database name for JDBC when execute SHOW COMPUTE NODES - [#33437](https://github.com/apache/shardingsphere/pull/33437) ### Bug Fixes diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.cn.md index 5b689b1dfe950..7ad3580909996 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.cn.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.cn.md @@ -33,7 +33,6 @@ ShowComputeNodeInfo ::= | worker_id | worker id | | labels | 标签 | | version | 版本 | -| database_name | 当前连接逻辑库(仅对 JDBC 生效) | ### 示例 @@ -46,11 +45,11 @@ SHOW COMPUTE NODE INFO; ```sql mysql> SHOW COMPUTE NODE INFO; mysql> SHOW COMPUTE NODES; -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ -| instance_id | instance_type | host | port | status | mode_type | worker_id | labels | version | database_name | -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ -| 3e84d33e-cb97-42f2-b6ce-f78fea0ded89 | PROXY | 127.0.0.1 | 3307 | OK | Cluster | -1 | | 5.4.2 | logic_db | -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ +| instance_id | instance_type | host | port | status | mode_type | worker_id | labels | version | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ +| 3e84d33e-cb97-42f2-b6ce-f78fea0ded89 | PROXY | 127.0.0.1 | 3307 | OK | Cluster | -1 | | 5.4.2 | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ 1 row in set (0.01 sec) ``` diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.en.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.en.md index fb55310ad8517..f996c879b9293 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.en.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/ral/show-compute-node-info.en.md @@ -32,7 +32,6 @@ ShowComputeNodeInfo ::= | worker_id | worker id | | labels | labels | | version | version | -| database_name | database name (Only valid for JDBC) | ### Example @@ -44,11 +43,11 @@ SHOW COMPUTE NODE INFO; ```sql mysql> SHOW COMPUTE NODES; -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ -| instance_id | instance_type | host | port | status | mode_type | worker_id | labels | version | database_name | -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ -| 3e84d33e-cb97-42f2-b6ce-f78fea0ded89 | PROXY | 127.0.0.1 | 3307 | OK | Cluster | -1 | | 5.4.2 | logic_db | -+--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+--------------+ ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ +| instance_id | instance_type | host | port | status | mode_type | worker_id | labels | version | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ +| 3e84d33e-cb97-42f2-b6ce-f78fea0ded89 | PROXY | 127.0.0.1 | 3307 | OK | Cluster | -1 | | 5.4.2 | ++--------------------------------------+---------------+------------+------+--------+------------+-----------+--------+----------+ 1 row in set (0.01 sec) ``` diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutor.java index 831dfd8175e9b..11451ae65e5e6 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutor.java @@ -36,7 +36,7 @@ public final class ShowComputeNodeInfoExecutor implements DistSQLQueryExecutor getColumnNames(final ShowComputeNodeInfoStatement sqlStatement) { - return Arrays.asList("instance_id", "host", "port", "status", "mode_type", "worker_id", "labels", "version", "database_name"); + return Arrays.asList("instance_id", "host", "port", "status", "mode_type", "worker_id", "labels", "version"); } @Override @@ -47,7 +47,7 @@ public Collection getRows(final ShowComputeNodeInfoStat return Collections.singletonList(new LocalDataQueryResultRow(instanceMetaData.getId(), instanceMetaData.getIp(), instanceMetaData instanceof ProxyInstanceMetaData ? ((ProxyInstanceMetaData) instanceMetaData).getPort() : -1, instance.getState().getCurrentState(), modeType, instance.getWorkerId(), String.join(",", instance.getLabels()), - instanceMetaData.getVersion(), instanceMetaData.getDatabaseName())); + instanceMetaData.getVersion())); } @Override diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutorTest.java index f3dbc10ca625d..be8685bde14a3 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeInfoExecutorTest.java @@ -55,7 +55,6 @@ void assertExecute() { assertThat(row.getCell(6), is("0")); assertThat(row.getCell(7), is("")); assertThat(row.getCell(8), is("foo_version")); - assertThat(row.getCell(9), is("")); } private ComputeNodeInstanceContext createInstanceContext() { diff --git a/proxy/bootstrap/src/main/resources/conf/global.yaml b/proxy/bootstrap/src/main/resources/conf/global.yaml index 11daea63448fc..3f339c1f812f8 100644 --- a/proxy/bootstrap/src/main/resources/conf/global.yaml +++ b/proxy/bootstrap/src/main/resources/conf/global.yaml @@ -21,17 +21,17 @@ # ###################################################################################################### -#mode: -# type: Cluster -# repository: -# type: ZooKeeper -# props: -# namespace: governance_ds -# server-lists: localhost:2181 -# retryIntervalMilliseconds: 500 -# timeToLiveSeconds: 60 -# maxRetries: 3 -# operationTimeoutMilliseconds: 500 +mode: + type: Cluster + repository: + type: ZooKeeper + props: + namespace: governance_ds + server-lists: localhost:2181 + retryIntervalMilliseconds: 500 + timeToLiveSeconds: 60 + maxRetries: 3 + operationTimeoutMilliseconds: 500 # #authority: # users: diff --git a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_node_info.xml b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_node_info.xml index 61b81a0d2322e..9171e4b2eabac 100644 --- a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_node_info.xml +++ b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/cluster/show_compute_node_info.xml @@ -25,7 +25,6 @@ - - + diff --git a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml index 0ee850be50aee..8c7f25dc6f75c 100644 --- a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml +++ b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/standalone/show_compute_node_info.xml @@ -25,7 +25,6 @@ - - + From 429f12c23ec6843154b80804005e563c23560caa Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Mon, 28 Oct 2024 17:46:21 +0800 Subject: [PATCH 6/6] Fix database name param --- .../infra/instance/yaml/YamlComputeNodeDataSwapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeDataSwapper.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeDataSwapper.java index f2e7916d34f77..e451277a1c5fa 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeDataSwapper.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/yaml/YamlComputeNodeDataSwapper.java @@ -30,7 +30,7 @@ public YamlComputeNodeData swapToYamlConfiguration(final ComputeNodeData data) { YamlComputeNodeData result = new YamlComputeNodeData(); result.setAttribute(data.getAttribute()); result.setVersion(data.getVersion()); - result.setDatabaseName(data.getVersion()); + result.setDatabaseName(data.getDatabaseName()); return result; }