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 2024/10/22 05:57:41 UTC
(shardingsphere) 05/43: Add pool name for show storage units
This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch fix-33341
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
commit 73fdba54591b965a030ef52ace8ac1ffbe2d5627
Author: RaigorJiang <ra...@gmail.com>
AuthorDate: Tue Aug 6 19:50:15 2024 +0800
Add pool name for show storage units
---
infra/distsql-handler/pom.xml | 5 +++++
.../executor/rql/resource/ShowStorageUnitExecutor.java | 18 ++++++++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/infra/distsql-handler/pom.xml b/infra/distsql-handler/pom.xml
index 4633bdc1fe4..289273149be 100644
--- a/infra/distsql-handler/pom.xml
+++ b/infra/distsql-handler/pom.xml
@@ -47,6 +47,11 @@
<artifactId>shardingsphere-mode-core</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>com.zaxxer</groupId>
+ <artifactId>HikariCP</artifactId>
+ <scope>compile</scope>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowStorageUnitExecutor.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowStorageUnitExecutor.java
index bb9e7f702d9..1365745643c 100644
--- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowStorageUnitExecutor.java
+++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowStorageUnitExecutor.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.distsql.handler.executor.rql.resource;
+import com.zaxxer.hikari.HikariDataSource;
import lombok.Setter;
import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
@@ -30,6 +31,8 @@ import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryRes
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.util.SphereEx;
+import org.apache.shardingsphere.infra.util.SphereEx.Type;
import org.apache.shardingsphere.mode.manager.ContextManager;
import javax.sql.DataSource;
@@ -50,12 +53,14 @@ public final class ShowStorageUnitExecutor implements DistSQLQueryExecutor<ShowS
private ShardingSphereDatabase database;
+ @SphereEx(Type.MODIFY)
@Override
public Collection<String> getColumnNames(final ShowStorageUnitsStatement sqlStatement) {
return Arrays.asList("name", "type", "host", "port", "db", "connection_timeout_milliseconds", "idle_timeout_milliseconds",
- "max_lifetime_milliseconds", "max_pool_size", "min_pool_size", "read_only", "other_attributes");
+ "max_lifetime_milliseconds", "max_pool_size", "min_pool_size", "read_only", "other_attributes", "pool_name");
}
+ @SphereEx(Type.MODIFY)
@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowStorageUnitsStatement sqlStatement, final ContextManager contextManager) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
@@ -75,7 +80,7 @@ public final class ShowStorageUnitExecutor implements DistSQLQueryExecutor<ShowS
getStandardProperty(poolProps, "maxPoolSize"),
getStandardProperty(poolProps, "minPoolSize"),
getStandardProperty(poolProps, "readOnly"),
- customProps));
+ customProps, getPoolName(entry.getValue().getDataSource())));
}
return result;
}
@@ -120,6 +125,15 @@ public final class ShowStorageUnitExecutor implements DistSQLQueryExecutor<ShowS
return result;
}
+ @SphereEx
+ private String getPoolName(final DataSource dataSource) {
+ DataSource realDataSource = dataSource instanceof CatalogSwitchableDataSource ? ((CatalogSwitchableDataSource) dataSource).getDataSource() : dataSource;
+ if (realDataSource instanceof HikariDataSource) {
+ return ((HikariDataSource) realDataSource).getPoolName();
+ }
+ return "";
+ }
+
private String getStandardProperty(final Map<String, Object> standardProps, final String key) {
return standardProps.containsKey(key) && null != standardProps.get(key) ? standardProps.get(key).toString() : "";
}