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 2022/12/19 08:38:49 UTC
[shardingsphere] branch master updated: Build cluster information (#22968)
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 8367221641d Build cluster information (#22968)
8367221641d is described below
commit 8367221641d7e66fbe81d8e110c49db26f4c19e7
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Mon Dec 19 16:38:42 2022 +0800
Build cluster information (#22968)
---
.../builder/dialect/MySQLShardingSphereDataBuilder.java | 13 +++++++++++--
.../dialect/PostgreSQLShardingSphereDataBuilder.java | 16 +++++++++++++---
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/MySQLShardingSphereDataBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/MySQLShardingSphereDataBuilder.java
index dc90ac0d40e..64d467448cf 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/MySQLShardingSphereDataBuilder.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/MySQLShardingSphereDataBuilder.java
@@ -17,17 +17,20 @@
package org.apache.shardingsphere.infra.metadata.data.builder.dialect;
+import org.apache.shardingsphere.infra.autogen.version.ShardingSphereVersion;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereDatabaseData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereSchemaData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereRowData;
import org.apache.shardingsphere.infra.metadata.data.builder.ShardingSphereDataBuilder;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
-import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Collections;
+import java.util.Map.Entry;
/**
* MySQL ShardingSphere data Builder.
@@ -37,6 +40,8 @@ public final class MySQLShardingSphereDataBuilder implements ShardingSphereDataB
private static final String SHARDING_SPHERE = "shardingsphere";
+ private static final String CLUSTER_INFORMATION = "cluster_information";
+
@Override
public ShardingSphereData build(final ShardingSphereMetaData metaData) {
ShardingSphereData result = new ShardingSphereData();
@@ -46,7 +51,11 @@ public final class MySQLShardingSphereDataBuilder implements ShardingSphereDataB
}
ShardingSphereSchemaData schemaData = new ShardingSphereSchemaData();
for (Entry<String, ShardingSphereTable> entry : shardingSphereSchema.get().getTables().entrySet()) {
- schemaData.getTableData().put(entry.getKey(), new ShardingSphereTableData(entry.getValue().getName()));
+ ShardingSphereTableData tableData = new ShardingSphereTableData(entry.getValue().getName());
+ if (CLUSTER_INFORMATION.equals(entry.getKey())) {
+ tableData.getRows().add(new ShardingSphereRowData(Collections.singletonList(ShardingSphereVersion.VERSION)));
+ }
+ schemaData.getTableData().put(entry.getKey(), tableData);
}
ShardingSphereDatabaseData databaseData = new ShardingSphereDatabaseData();
databaseData.getSchemaData().put(SHARDING_SPHERE, schemaData);
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/PostgreSQLShardingSphereDataBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/PostgreSQLShardingSphereDataBuilder.java
index e5779ccbfdd..0506a92363a 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/PostgreSQLShardingSphereDataBuilder.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/PostgreSQLShardingSphereDataBuilder.java
@@ -17,12 +17,14 @@
package org.apache.shardingsphere.infra.metadata.data.builder.dialect;
+import org.apache.shardingsphere.infra.autogen.version.ShardingSphereVersion;
import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereDatabaseData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereSchemaData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereRowData;
import org.apache.shardingsphere.infra.metadata.data.builder.ShardingSphereDataBuilder;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
@@ -43,9 +45,12 @@ public final class PostgreSQLShardingSphereDataBuilder implements ShardingSphere
private static final Map<String, Collection<String>> COLLECTED_SCHEMA_TABLES = new LinkedHashMap<>();
+ private static final Map<String, Collection<String>> INIT_DATA_SCHEMA_TABLES = new LinkedHashMap<>();
+
static {
COLLECTED_SCHEMA_TABLES.put("shardingsphere", Collections.singletonList("sharding_table_statistics"));
COLLECTED_SCHEMA_TABLES.put("pg_catalog", Arrays.asList("pg_class", "pg_namespace"));
+ INIT_DATA_SCHEMA_TABLES.put("shardingsphere", Collections.singletonList("cluster_information"));
}
@Override
@@ -64,7 +69,7 @@ public final class PostgreSQLShardingSphereDataBuilder implements ShardingSphere
private void appendSchemaData(final ShardingSphereDatabase shardingSphereDatabase, final ShardingSphereDatabaseData databaseData) {
for (Entry<String, ShardingSphereSchema> entry : shardingSphereDatabase.getSchemas().entrySet()) {
- if (COLLECTED_SCHEMA_TABLES.containsKey(entry.getKey())) {
+ if (COLLECTED_SCHEMA_TABLES.containsKey(entry.getKey()) || INIT_DATA_SCHEMA_TABLES.containsKey(entry.getKey())) {
ShardingSphereSchemaData schemaData = new ShardingSphereSchemaData();
appendTableData(entry, schemaData);
databaseData.getSchemaData().put(entry.getKey(), schemaData);
@@ -74,8 +79,13 @@ public final class PostgreSQLShardingSphereDataBuilder implements ShardingSphere
private void appendTableData(final Entry<String, ShardingSphereSchema> schemaEntry, final ShardingSphereSchemaData schemaData) {
for (Entry<String, ShardingSphereTable> entry : schemaEntry.getValue().getTables().entrySet()) {
- if (COLLECTED_SCHEMA_TABLES.get(schemaEntry.getKey()).contains(entry.getKey())) {
- schemaData.getTableData().put(entry.getKey(), new ShardingSphereTableData(entry.getValue().getName()));
+ ShardingSphereTableData tableData = new ShardingSphereTableData(entry.getValue().getName());
+ if (null != COLLECTED_SCHEMA_TABLES.get(schemaEntry.getKey()) && COLLECTED_SCHEMA_TABLES.get(schemaEntry.getKey()).contains(entry.getKey())) {
+ schemaData.getTableData().put(entry.getKey(), tableData);
+ }
+ if (null != INIT_DATA_SCHEMA_TABLES.get(schemaEntry.getKey()) && INIT_DATA_SCHEMA_TABLES.get(schemaEntry.getKey()).contains(entry.getKey())) {
+ tableData.getRows().add(new ShardingSphereRowData(Collections.singletonList(ShardingSphereVersion.VERSION)));
+ schemaData.getTableData().put(entry.getKey(), tableData);
}
}
}