Skip to content

Commit f6b2d07

Browse files
authored
Added nodes/config_nodes/data_nodes table for information_schema & Fixed the header of show ainodes
1 parent 1c1574f commit f6b2d07

12 files changed

Lines changed: 512 additions & 6 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeBasicIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private void errorTest(String sql, String errorMessage) {
107107
@Test
108108
public void aiNodeConnectionTest() {
109109
String sql = "SHOW AINODES";
110-
String title = "NodeID,Status,RpcAddress,RpcPort";
110+
String title = "NodeID,Status,InternalAddress,InternalPort";
111111
try (Connection connection = EnvFactory.getEnv().getConnection();
112112
Statement statement = connection.createStatement()) {
113113

integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@ public void testInformationSchema() throws SQLException {
394394
"models,INF,",
395395
"functions,INF,",
396396
"configurations,INF,",
397-
"keywords,INF,")));
397+
"keywords,INF,",
398+
"nodes,INF,",
399+
"config_nodes,INF,",
400+
"data_nodes,INF,")));
398401

399402
TestUtils.assertResultSetEqual(
400403
statement.executeQuery("desc databases"),
@@ -513,6 +516,39 @@ public void testInformationSchema() throws SQLException {
513516
statement.executeQuery("desc keywords"),
514517
"ColumnName,DataType,Category,",
515518
new HashSet<>(Arrays.asList("word,STRING,TAG,", "reserved,INT32,ATTRIBUTE,")));
519+
TestUtils.assertResultSetEqual(
520+
statement.executeQuery("desc nodes"),
521+
"ColumnName,DataType,Category,",
522+
new HashSet<>(
523+
Arrays.asList(
524+
"node_id,INT32,TAG,",
525+
"node_type,STRING,ATTRIBUTE,",
526+
"status,STRING,ATTRIBUTE,",
527+
"internal_address,STRING,ATTRIBUTE,",
528+
"internal_port,INT32,ATTRIBUTE,",
529+
"version,STRING,ATTRIBUTE,",
530+
"build_info,STRING,ATTRIBUTE,")));
531+
TestUtils.assertResultSetEqual(
532+
statement.executeQuery("desc config_nodes"),
533+
"ColumnName,DataType,Category,",
534+
new HashSet<>(
535+
Arrays.asList(
536+
"node_id,INT32,TAG,",
537+
"config_consensus_port,INT32,ATTRIBUTE,",
538+
"role,STRING,ATTRIBUTE,")));
539+
TestUtils.assertResultSetEqual(
540+
statement.executeQuery("desc data_nodes"),
541+
"ColumnName,DataType,Category,",
542+
new HashSet<>(
543+
Arrays.asList(
544+
"node_id,INT32,TAG,",
545+
"data_region_num,INT32,ATTRIBUTE,",
546+
"schema_region_num,INT32,ATTRIBUTE,",
547+
"rpc_address,STRING,ATTRIBUTE,",
548+
"rpc_port,INT32,ATTRIBUTE,",
549+
"mpp_port,INT32,ATTRIBUTE,",
550+
"data_consensus_port,INT32,ATTRIBUTE,",
551+
"schema_consensus_port,INT32,ATTRIBUTE,")));
516552

517553
// Only root user is allowed
518554
Assert.assertThrows(SQLException.class, () -> statement.execute("select * from regions"));
@@ -522,6 +558,10 @@ public void testInformationSchema() throws SQLException {
522558
SQLException.class, () -> statement.execute("select * from subscriptions"));
523559
Assert.assertThrows(
524560
SQLException.class, () -> statement.execute("select * from configurations"));
561+
Assert.assertThrows(SQLException.class, () -> statement.execute("select * from nodes"));
562+
Assert.assertThrows(
563+
SQLException.class, () -> statement.execute("select * from config_nodes"));
564+
Assert.assertThrows(SQLException.class, () -> statement.execute("select * from data_nodes"));
525565

526566
// No auth needed
527567
TestUtils.assertResultSetEqual(
@@ -599,12 +639,15 @@ public void testInformationSchema() throws SQLException {
599639
"information_schema,functions,INF,USING,null,SYSTEM VIEW,",
600640
"information_schema,configurations,INF,USING,null,SYSTEM VIEW,",
601641
"information_schema,keywords,INF,USING,null,SYSTEM VIEW,",
642+
"information_schema,nodes,INF,USING,null,SYSTEM VIEW,",
643+
"information_schema,config_nodes,INF,USING,null,SYSTEM VIEW,",
644+
"information_schema,data_nodes,INF,USING,null,SYSTEM VIEW,",
602645
"test,test,INF,USING,test,BASE TABLE,",
603646
"test,view_table,100,USING,null,VIEW FROM TREE,")));
604647
TestUtils.assertResultSetEqual(
605648
statement.executeQuery("count devices from tables where status = 'USING'"),
606649
"count(devices),",
607-
Collections.singleton("16,"));
650+
Collections.singleton("19,"));
608651
TestUtils.assertResultSetEqual(
609652
statement.executeQuery(
610653
"select * from columns where table_name = 'queries' or database = 'test'"),
@@ -687,6 +730,21 @@ public void testInformationSchema() throws SQLException {
687730
"select * from information_schema.keywords where reserved > 0 limit 1"),
688731
"word,reserved,",
689732
Collections.singleton("AINODES,1,"));
733+
734+
TestUtils.assertResultSetEqual(
735+
statement.executeQuery("select distinct(status) from information_schema.nodes"),
736+
"status,",
737+
Collections.singleton("Running,"));
738+
739+
TestUtils.assertResultSetEqual(
740+
statement.executeQuery("select count(*) from information_schema.config_nodes"),
741+
"_col0,",
742+
Collections.singleton(EnvFactory.getEnv().getConfigNodeWrapperList().size() + ","));
743+
744+
TestUtils.assertResultSetEqual(
745+
statement.executeQuery("select data_region_num from information_schema.data_nodes"),
746+
"data_region_num,",
747+
Collections.singleton("0,"));
690748
}
691749
}
692750

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@
224224
import org.apache.iotdb.confignode.rpc.thrift.TShowAINodesResp;
225225
import org.apache.iotdb.confignode.rpc.thrift.TShowCQResp;
226226
import org.apache.iotdb.confignode.rpc.thrift.TShowClusterResp;
227+
import org.apache.iotdb.confignode.rpc.thrift.TShowConfigNodes4InformationSchemaResp;
227228
import org.apache.iotdb.confignode.rpc.thrift.TShowConfigNodesResp;
229+
import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodes4InformationSchemaResp;
228230
import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodesResp;
229231
import org.apache.iotdb.confignode.rpc.thrift.TShowDatabaseResp;
230232
import org.apache.iotdb.confignode.rpc.thrift.TShowModelReq;
@@ -1887,6 +1889,19 @@ public TShowDataNodesResp showDataNodes() {
18871889
}
18881890
}
18891891

1892+
@Override
1893+
public TShowDataNodes4InformationSchemaResp showDataNodes4InformationSchema() {
1894+
final TSStatus status = confirmLeader();
1895+
final TShowDataNodes4InformationSchemaResp resp = new TShowDataNodes4InformationSchemaResp();
1896+
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
1897+
return resp.setDataNodesInfoList(
1898+
nodeManager.getRegisteredDataNodeInfoList4InformationSchema())
1899+
.setStatus(StatusUtils.OK);
1900+
} else {
1901+
return resp.setStatus(status);
1902+
}
1903+
}
1904+
18901905
@Override
18911906
public TShowConfigNodesResp showConfigNodes() {
18921907
TSStatus status = confirmLeader();
@@ -1899,6 +1914,20 @@ public TShowConfigNodesResp showConfigNodes() {
18991914
}
19001915
}
19011916

1917+
@Override
1918+
public TShowConfigNodes4InformationSchemaResp showConfigNodes4InformationSchema() {
1919+
final TSStatus status = confirmLeader();
1920+
final TShowConfigNodes4InformationSchemaResp resp =
1921+
new TShowConfigNodes4InformationSchemaResp();
1922+
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
1923+
return resp.setConfigNodesInfoList(
1924+
nodeManager.getRegisteredConfigNodeInfo4InformationSchema())
1925+
.setStatus(StatusUtils.OK);
1926+
} else {
1927+
return resp.setStatus(status);
1928+
}
1929+
}
1930+
19021931
@Override
19031932
public TShowDatabaseResp showDatabase(final TGetDatabaseReq req) {
19041933
final TSStatus status = confirmLeader();

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/IManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@
138138
import org.apache.iotdb.confignode.rpc.thrift.TShowAINodesResp;
139139
import org.apache.iotdb.confignode.rpc.thrift.TShowCQResp;
140140
import org.apache.iotdb.confignode.rpc.thrift.TShowClusterResp;
141+
import org.apache.iotdb.confignode.rpc.thrift.TShowConfigNodes4InformationSchemaResp;
141142
import org.apache.iotdb.confignode.rpc.thrift.TShowConfigNodesResp;
143+
import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodes4InformationSchemaResp;
142144
import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodesResp;
143145
import org.apache.iotdb.confignode.rpc.thrift.TShowDatabaseResp;
144146
import org.apache.iotdb.confignode.rpc.thrift.TShowModelReq;
@@ -627,9 +629,15 @@ TDataPartitionTableResp getOrCreateDataPartition(
627629
/** Show DataNodes. */
628630
TShowDataNodesResp showDataNodes();
629631

632+
/** Show DataNodes for information schema. */
633+
TShowDataNodes4InformationSchemaResp showDataNodes4InformationSchema();
634+
630635
/** Show ConfigNodes. */
631636
TShowConfigNodesResp showConfigNodes();
632637

638+
/** Show ConfigNodes for information schema. */
639+
TShowConfigNodes4InformationSchemaResp showConfigNodes4InformationSchema();
640+
633641
/**
634642
* Show StorageGroup.
635643
*

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@
8181
import org.apache.iotdb.confignode.rpc.thrift.TAINodeRestartResp;
8282
import org.apache.iotdb.confignode.rpc.thrift.TCQConfig;
8383
import org.apache.iotdb.confignode.rpc.thrift.TConfigNodeInfo;
84+
import org.apache.iotdb.confignode.rpc.thrift.TConfigNodeInfo4InformationSchema;
8485
import org.apache.iotdb.confignode.rpc.thrift.TConfigNodeRegisterReq;
8586
import org.apache.iotdb.confignode.rpc.thrift.TConfigNodeRegisterResp;
8687
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeInfo;
88+
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeInfo4InformationSchema;
8789
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRegisterReq;
8890
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRestartReq;
8991
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRestartResp;
@@ -736,6 +738,70 @@ public List<TDataNodeInfo> getRegisteredDataNodeInfoList() {
736738
return dataNodeInfoList;
737739
}
738740

741+
public List<TDataNodeInfo4InformationSchema> getRegisteredDataNodeInfoList4InformationSchema() {
742+
final List<TDataNodeInfo4InformationSchema> dataNodeInfoList = new ArrayList<>();
743+
final List<TDataNodeConfiguration> registeredDataNodes = this.getRegisteredDataNodes();
744+
if (registeredDataNodes != null) {
745+
registeredDataNodes.forEach(
746+
registeredDataNode -> {
747+
TDataNodeInfo4InformationSchema dataNodeInfo = new TDataNodeInfo4InformationSchema();
748+
int dataNodeId = registeredDataNode.getLocation().getDataNodeId();
749+
dataNodeInfo.setDataNodeId(dataNodeId);
750+
dataNodeInfo.setRpcAddress(
751+
registeredDataNode.getLocation().getClientRpcEndPoint().getIp());
752+
dataNodeInfo.setRpcPort(
753+
registeredDataNode.getLocation().getClientRpcEndPoint().getPort());
754+
dataNodeInfo.setDataRegionNum(0);
755+
dataNodeInfo.setSchemaRegionNum(0);
756+
dataNodeInfo.setMppPort(
757+
registeredDataNode.getLocation().getMPPDataExchangeEndPoint().getPort());
758+
dataNodeInfo.setDataConsensusPort(
759+
registeredDataNode.getLocation().getDataRegionConsensusEndPoint().getPort());
760+
dataNodeInfo.setSchemaConsensusPort(
761+
registeredDataNode.getLocation().getSchemaRegionConsensusEndPoint().getPort());
762+
dataNodeInfoList.add(dataNodeInfo);
763+
});
764+
}
765+
766+
// Map<DataNodeId, DataRegionNum>
767+
final Map<Integer, AtomicInteger> dataRegionNumMap = new HashMap<>();
768+
// Map<DataNodeId, SchemaRegionNum>
769+
final Map<Integer, AtomicInteger> schemaRegionNumMap = new HashMap<>();
770+
final List<TRegionReplicaSet> regionReplicaSets = getPartitionManager().getAllReplicaSets();
771+
regionReplicaSets.forEach(
772+
regionReplicaSet ->
773+
regionReplicaSet
774+
.getDataNodeLocations()
775+
.forEach(
776+
dataNodeLocation -> {
777+
switch (regionReplicaSet.getRegionId().getType()) {
778+
case SchemaRegion:
779+
schemaRegionNumMap
780+
.computeIfAbsent(
781+
dataNodeLocation.getDataNodeId(), key -> new AtomicInteger())
782+
.getAndIncrement();
783+
break;
784+
case DataRegion:
785+
default:
786+
dataRegionNumMap
787+
.computeIfAbsent(
788+
dataNodeLocation.getDataNodeId(), key -> new AtomicInteger())
789+
.getAndIncrement();
790+
}
791+
}));
792+
final AtomicInteger zero = new AtomicInteger(0);
793+
dataNodeInfoList.forEach(
794+
(dataNodesInfo -> {
795+
dataNodesInfo.setSchemaRegionNum(
796+
schemaRegionNumMap.getOrDefault(dataNodesInfo.getDataNodeId(), zero).get());
797+
dataNodesInfo.setDataRegionNum(
798+
dataRegionNumMap.getOrDefault(dataNodesInfo.getDataNodeId(), zero).get());
799+
}));
800+
801+
dataNodeInfoList.sort(Comparator.comparingInt(TDataNodeInfo4InformationSchema::getDataNodeId));
802+
return dataNodeInfoList;
803+
}
804+
739805
public int getDataNodeCpuCoreCount() {
740806
return nodeInfo.getDataNodeTotalCpuCoreCount();
741807
}
@@ -771,6 +837,28 @@ public List<TConfigNodeInfo> getRegisteredConfigNodeInfoList() {
771837
return configNodeInfoList;
772838
}
773839

840+
public List<TConfigNodeInfo4InformationSchema> getRegisteredConfigNodeInfo4InformationSchema() {
841+
final List<TConfigNodeInfo4InformationSchema> configNodeInfoList = new ArrayList<>();
842+
final List<TConfigNodeLocation> registeredConfigNodes = this.getRegisteredConfigNodes();
843+
if (registeredConfigNodes != null) {
844+
registeredConfigNodes.forEach(
845+
configNodeLocation -> {
846+
final TConfigNodeInfo4InformationSchema info = new TConfigNodeInfo4InformationSchema();
847+
final int configNodeId = configNodeLocation.getConfigNodeId();
848+
info.setConfigNodeId(configNodeId);
849+
info.setConsensusPort(configNodeLocation.getConsensusEndPoint().getPort());
850+
info.setRoleType(
851+
configNodeLocation.getConfigNodeId() == ConfigNodeHeartbeatCache.CURRENT_NODE_ID
852+
? RegionRoleType.Leader.name()
853+
: RegionRoleType.Follower.name());
854+
configNodeInfoList.add(info);
855+
});
856+
}
857+
configNodeInfoList.sort(
858+
Comparator.comparingInt(TConfigNodeInfo4InformationSchema::getConfigNodeId));
859+
return configNodeInfoList;
860+
}
861+
774862
/**
775863
* Only leader use this interface, record the new ConfigNode's information.
776864
*

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@
193193
import org.apache.iotdb.confignode.rpc.thrift.TShowAINodesResp;
194194
import org.apache.iotdb.confignode.rpc.thrift.TShowCQResp;
195195
import org.apache.iotdb.confignode.rpc.thrift.TShowClusterResp;
196+
import org.apache.iotdb.confignode.rpc.thrift.TShowConfigNodes4InformationSchemaResp;
196197
import org.apache.iotdb.confignode.rpc.thrift.TShowConfigNodesResp;
198+
import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodes4InformationSchemaResp;
197199
import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodesResp;
198200
import org.apache.iotdb.confignode.rpc.thrift.TShowDatabaseResp;
199201
import org.apache.iotdb.confignode.rpc.thrift.TShowModelReq;
@@ -1032,11 +1034,21 @@ public TShowDataNodesResp showDataNodes() {
10321034
return configManager.showDataNodes();
10331035
}
10341036

1037+
@Override
1038+
public TShowDataNodes4InformationSchemaResp showDataNodes4InformationSchema() {
1039+
return configManager.showDataNodes4InformationSchema();
1040+
}
1041+
10351042
@Override
10361043
public TShowConfigNodesResp showConfigNodes() {
10371044
return configManager.showConfigNodes();
10381045
}
10391046

1047+
@Override
1048+
public TShowConfigNodes4InformationSchemaResp showConfigNodes4InformationSchema() {
1049+
return configManager.showConfigNodes4InformationSchema();
1050+
}
1051+
10401052
@Override
10411053
public TShowDatabaseResp showDatabase(TGetDatabaseReq req) {
10421054
return configManager.showDatabase(req);

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/ConfigNodeClient.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@
151151
import org.apache.iotdb.confignode.rpc.thrift.TShowAINodesResp;
152152
import org.apache.iotdb.confignode.rpc.thrift.TShowCQResp;
153153
import org.apache.iotdb.confignode.rpc.thrift.TShowClusterResp;
154+
import org.apache.iotdb.confignode.rpc.thrift.TShowConfigNodes4InformationSchemaResp;
154155
import org.apache.iotdb.confignode.rpc.thrift.TShowConfigNodesResp;
156+
import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodes4InformationSchemaResp;
155157
import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodesResp;
156158
import org.apache.iotdb.confignode.rpc.thrift.TShowDatabaseResp;
157159
import org.apache.iotdb.confignode.rpc.thrift.TShowModelReq;
@@ -843,12 +845,27 @@ public TShowDataNodesResp showDataNodes() throws TException {
843845
() -> client.showDataNodes(), resp -> !updateConfigNodeLeader(resp.status));
844846
}
845847

848+
@Override
849+
public TShowDataNodes4InformationSchemaResp showDataNodes4InformationSchema() throws TException {
850+
return executeRemoteCallWithRetry(
851+
() -> client.showDataNodes4InformationSchema(),
852+
resp -> !updateConfigNodeLeader(resp.status));
853+
}
854+
846855
@Override
847856
public TShowConfigNodesResp showConfigNodes() throws TException {
848857
return executeRemoteCallWithRetry(
849858
() -> client.showConfigNodes(), resp -> !updateConfigNodeLeader(resp.status));
850859
}
851860

861+
@Override
862+
public TShowConfigNodes4InformationSchemaResp showConfigNodes4InformationSchema()
863+
throws TException {
864+
return executeRemoteCallWithRetry(
865+
() -> client.showConfigNodes4InformationSchema(),
866+
resp -> !updateConfigNodeLeader(resp.status));
867+
}
868+
852869
@Override
853870
public TShowDatabaseResp showDatabase(TGetDatabaseReq req) throws TException {
854871
return executeRemoteCallWithRetry(

0 commit comments

Comments
 (0)