This is an automated email from the ASF dual-hosted git repository.

qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 77563a6273 [IOTDB-3511] Show Region tool (#6315)
77563a6273 is described below

commit 77563a627304031c0a0148c895e3ae9769b12117
Author: 任宇华 <[email protected]>
AuthorDate: Sun Jun 19 09:16:21 2022 +0800

    [IOTDB-3511] Show Region tool (#6315)
---
 .../org/apache/iotdb/db/qp/sql/IdentifierParser.g4 |  2 +
 .../org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4   |  7 +-
 .../antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4  |  8 ++
 .../consensus/request/ConfigRequest.java           |  4 +
 .../consensus/request/ConfigRequestType.java       |  3 +-
 .../request/read/GetRegionLocationsReq.java        | 62 ++++++++++++++++
 .../consensus/response/RegionLocationsResp.java    | 49 ++++++++++++
 .../iotdb/confignode/manager/ConfigManager.java    | 14 ++++
 .../apache/iotdb/confignode/manager/Manager.java   |  4 +
 .../iotdb/confignode/manager/PartitionManager.java |  5 ++
 .../executor/ConfigRequestExecutor.java            |  3 +
 .../persistence/partition/PartitionInfo.java       | 25 +++++++
 .../partition/StorageGroupPartitionTable.java      | 39 ++++++++++
 .../thrift/ConfigNodeRPCServiceProcessor.java      | 15 ++++
 .../consensus/request/ConfigRequestSerDeTest.java  | 11 +++
 .../confignode/persistence/PartitionInfoTest.java  | 68 ++++++++++++++++-
 .../Maintenance-Tools/Maintenance-Command.md       | 67 ++++++++++++++++-
 .../Maintenance-Tools/Maintenance-Command.md       | 63 ++++++++++++++++
 .../apache/iotdb/commons/cluster/RegionStatus.java | 36 +++++++++
 .../apache/iotdb/db/client/ConfigNodeClient.java   | 28 +++++++
 .../java/org/apache/iotdb/db/conf/IoTDBConfig.java |  4 +
 .../iotdb/db/mpp/common/header/HeaderConstant.java | 24 ++++++
 .../plan/execution/config/ConfigTaskVisitor.java   |  6 ++
 .../mpp/plan/execution/config/ShowRegionTask.java  | 86 ++++++++++++++++++++++
 .../config/executor/ClusterConfigTaskExecutor.java | 35 ++++++---
 .../config/executor/IConfigTaskExecutor.java       |  3 +
 .../executor/StandaloneConfigTaskExecutor.java     | 14 +++-
 .../iotdb/db/mpp/plan/parser/ASTVisitor.java       | 18 +++++
 .../db/mpp/plan/statement/StatementVisitor.java    |  5 ++
 .../statement/metadata/ShowRegionStatement.java    | 54 ++++++++++++++
 thrift-commons/src/main/thrift/common.thrift       | 10 +++
 .../src/main/thrift/confignode.thrift              | 14 ++++
 32 files changed, 771 insertions(+), 15 deletions(-)

diff --git 
a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IdentifierParser.g4 
b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IdentifierParser.g4
index 284e04f9d9..a53415f3b8 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IdentifierParser.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IdentifierParser.g4
@@ -60,6 +60,7 @@ keyWords
     | CQ
     | CQS
     | CREATE
+    | DATA
     | DEBUG
     | DELETE
     | DESC
@@ -126,6 +127,7 @@ keyWords
     | QUERY
     | READONLY
     | REGEXP
+    | REGIONS
     | REMOVE
     | RENAME
     | RESAMPLE
diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 
b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
index 5f860bb65d..dec91253bb 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
@@ -43,7 +43,7 @@ ddlStatement
     | dropFunction | dropTrigger | dropContinuousQuery | dropSchemaTemplate
     | setTTL | unsetTTL | startTrigger | stopTrigger | setSchemaTemplate | 
unsetSchemaTemplate
     | showStorageGroup | showDevices | showTimeseries | showChildPaths | 
showChildNodes
-    | showFunctions | showTriggers | showContinuousQueries | showTTL | 
showAllTTL | showCluster
+    | showFunctions | showTriggers | showContinuousQueries | showTTL | 
showAllTTL | showCluster | showRegion
     | showSchemaTemplates | showNodesInSchemaTemplate
     | showPathsUsingSchemaTemplate | showPathsSetSchemaTemplate
     | countStorageGroup | countDevices | countTimeseries | countNodes
@@ -308,6 +308,11 @@ showCluster
     : SHOW CLUSTER
     ;
 
+// Show Region
+showRegion
+    : SHOW (SCHEMA | DATA)? REGIONS
+    ;
+
 // Show Schema Template
 showSchemaTemplates
     : SHOW SCHEMA? TEMPLATES
diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4 
b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4
index fc11251612..3778d51ae7 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4
@@ -153,6 +153,10 @@ CREATE
     : C R E A T E
     ;
 
+DATA
+    : D A T A
+    ;
+
 DEBUG
     : D E B U G
     ;
@@ -418,6 +422,10 @@ REGEXP
     : R E G E X P
     ;
 
+REGIONS
+    : R E G I O N S
+    ;
+
 REMOVE
     : R E M O V E
     ;
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigRequest.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigRequest.java
index f1c2e896c8..c2f651792b 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigRequest.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigRequest.java
@@ -25,6 +25,7 @@ import 
org.apache.iotdb.confignode.consensus.request.read.GetDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetNodePathsPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetOrCreateDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetOrCreateSchemaPartitionReq;
+import 
org.apache.iotdb.confignode.consensus.request.read.GetRegionLocationsReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetSchemaPartitionReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.request.write.ApplyConfigNodeReq;
@@ -189,6 +190,9 @@ public abstract class ConfigRequest implements 
IConsensusRequest {
         case GetNodePathsPartition:
           req = new GetNodePathsPartitionReq();
           break;
+        case GetRegionLocations:
+          req = new GetRegionLocationsReq();
+          break;
         default:
           throw new IOException("unknown PhysicalPlan type: " + typeNum);
       }
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigRequestType.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigRequestType.java
index a8f122e412..6d61a0e0b2 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigRequestType.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigRequestType.java
@@ -61,5 +61,6 @@ public enum ConfigRequestType {
   ApplyConfigNode,
   CreateFunction,
   DropFunction,
-  GetNodePathsPartition;
+  GetNodePathsPartition,
+  GetRegionLocations;
 }
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/GetRegionLocationsReq.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/GetRegionLocationsReq.java
new file mode 100644
index 0000000000..9ca74423d3
--- /dev/null
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/GetRegionLocationsReq.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.confignode.consensus.request.read;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
+import org.apache.iotdb.confignode.consensus.request.ConfigRequest;
+import org.apache.iotdb.confignode.consensus.request.ConfigRequestType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+public class GetRegionLocationsReq extends ConfigRequest {
+
+  private TConsensusGroupType regionType;
+
+  public GetRegionLocationsReq() {
+    super(ConfigRequestType.GetRegionLocations);
+  }
+
+  public GetRegionLocationsReq(TConsensusGroupType regionType) {
+    super(ConfigRequestType.GetRegionLocations);
+    this.regionType = regionType;
+  }
+
+  public TConsensusGroupType getRegionType() {
+    return regionType;
+  }
+
+  public void setRegionType(TConsensusGroupType regionType) {
+    this.regionType = regionType;
+  }
+
+  @Override
+  protected void serializeImpl(DataOutputStream stream) throws IOException {
+    stream.writeInt(getType().ordinal());
+    ReadWriteIOUtils.write(regionType.ordinal(), stream);
+  }
+
+  @Override
+  protected void deserializeImpl(ByteBuffer buffer) throws IOException {
+    regionType = 
TConsensusGroupType.values()[ReadWriteIOUtils.readInt(buffer)];
+  }
+}
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/RegionLocationsResp.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/RegionLocationsResp.java
new file mode 100644
index 0000000000..36867f119c
--- /dev/null
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/RegionLocationsResp.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.confignode.consensus.response;
+
+import org.apache.iotdb.common.rpc.thrift.TRegionLocation;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.consensus.common.DataSet;
+
+import java.util.List;
+
+public class RegionLocationsResp implements DataSet {
+
+  private TSStatus status;
+
+  private List<TRegionLocation> regionInfosList;
+
+  public TSStatus getStatus() {
+    return status;
+  }
+
+  public void setStatus(TSStatus status) {
+    this.status = status;
+  }
+
+  public List<TRegionLocation> getRegionInfosList() {
+    return regionInfosList;
+  }
+
+  public void setRegionInfosList(List<TRegionLocation> regionInfosList) {
+    this.regionInfosList = regionInfosList;
+  }
+}
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
index 7621a1e4ae..eeeaf9492b 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
@@ -37,6 +37,7 @@ import 
org.apache.iotdb.confignode.consensus.request.read.GetDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetNodePathsPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetOrCreateDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetOrCreateSchemaPartitionReq;
+import 
org.apache.iotdb.confignode.consensus.request.read.GetRegionLocationsReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetSchemaPartitionReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.request.write.ApplyConfigNodeReq;
@@ -51,6 +52,7 @@ import 
org.apache.iotdb.confignode.consensus.response.DataNodeConfigurationResp;
 import org.apache.iotdb.confignode.consensus.response.DataNodeInfosResp;
 import org.apache.iotdb.confignode.consensus.response.DataPartitionResp;
 import org.apache.iotdb.confignode.consensus.response.PermissionInfoResp;
+import org.apache.iotdb.confignode.consensus.response.RegionLocationsResp;
 import org.apache.iotdb.confignode.consensus.response.SchemaNodeManagementResp;
 import org.apache.iotdb.confignode.consensus.response.SchemaPartitionResp;
 import org.apache.iotdb.confignode.consensus.response.StorageGroupSchemaResp;
@@ -644,6 +646,18 @@ public class ConfigManager implements Manager {
     return udfManager;
   }
 
+  @Override
+  public DataSet showRegion(GetRegionLocationsReq getRegionsinfoReq) {
+    TSStatus status = confirmLeader();
+    if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+      return partitionManager.getRetionLocations(getRegionsinfoReq);
+    } else {
+      RegionLocationsResp regionResp = new RegionLocationsResp();
+      regionResp.setStatus(status);
+      return regionResp;
+    }
+  }
+
   public ProcedureManager getProcedureManager() {
     return procedureManager;
   }
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java
index a552b7f464..1ac8436e72 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java
@@ -25,6 +25,7 @@ import 
org.apache.iotdb.confignode.consensus.request.read.CountStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetDataNodeInfoReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetOrCreateDataPartitionReq;
+import 
org.apache.iotdb.confignode.consensus.request.read.GetRegionLocationsReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.request.write.ApplyConfigNodeReq;
 import org.apache.iotdb.confignode.consensus.request.write.RegisterDataNodeReq;
@@ -222,4 +223,7 @@ public interface Manager {
   TSStatus dropFunction(String udfName);
 
   void addMetrics();
+
+  /** Show (data/schema) regions */
+  DataSet showRegion(GetRegionLocationsReq getRegionsinfoReq);
 }
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/PartitionManager.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/PartitionManager.java
index 718960d541..ac1ae22eea 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/PartitionManager.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/PartitionManager.java
@@ -36,6 +36,7 @@ import 
org.apache.iotdb.confignode.consensus.request.read.GetDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetNodePathsPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetOrCreateDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetOrCreateSchemaPartitionReq;
+import 
org.apache.iotdb.confignode.consensus.request.read.GetRegionLocationsReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetSchemaPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.write.CreateDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.write.CreateSchemaPartitionReq;
@@ -462,6 +463,10 @@ public class PartitionManager {
     return executor.getSeriesPartitionSlot(devicePath);
   }
 
+  public DataSet getRetionLocations(GetRegionLocationsReq req) {
+    return getConsensusManager().read(req).getDataset();
+  }
+
   public ScheduledExecutorService getRegionCleaner() {
     return regionCleaner;
   }
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/executor/ConfigRequestExecutor.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/executor/ConfigRequestExecutor.java
index f990370a80..e524497b46 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/executor/ConfigRequestExecutor.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/executor/ConfigRequestExecutor.java
@@ -28,6 +28,7 @@ import 
org.apache.iotdb.confignode.consensus.request.read.CountStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetDataNodeInfoReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetNodePathsPartitionReq;
+import 
org.apache.iotdb.confignode.consensus.request.read.GetRegionLocationsReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetSchemaPartitionReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.request.write.ApplyConfigNodeReq;
@@ -130,6 +131,8 @@ public class ConfigRequestExecutor {
         return authorInfo.executeListRoleUsers((AuthorReq) req);
       case GetNodePathsPartition:
         return getSchemaNodeManagementPartition(req);
+      case GetRegionLocations:
+        return partitionInfo.getRegionLocations((GetRegionLocationsReq) req);
       default:
         throw new UnknownPhysicalPlanTypeException(req.getType());
     }
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java
index c4cd418ec7..70e5c217d5 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.confignode.persistence.partition;
 import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
 import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
 import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TRegionLocation;
 import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.common.rpc.thrift.TSeriesPartitionSlot;
@@ -31,6 +32,7 @@ import org.apache.iotdb.commons.partition.SchemaPartition;
 import org.apache.iotdb.commons.snapshot.SnapshotProcessor;
 import org.apache.iotdb.confignode.conf.ConfigNodeDescriptor;
 import org.apache.iotdb.confignode.consensus.request.read.GetDataPartitionReq;
+import 
org.apache.iotdb.confignode.consensus.request.read.GetRegionLocationsReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetSchemaPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.write.CreateDataPartitionReq;
 import org.apache.iotdb.confignode.consensus.request.write.CreateRegionsReq;
@@ -39,6 +41,7 @@ import 
org.apache.iotdb.confignode.consensus.request.write.DeleteStorageGroupReq
 import 
org.apache.iotdb.confignode.consensus.request.write.PreDeleteStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.request.write.SetStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.response.DataPartitionResp;
+import org.apache.iotdb.confignode.consensus.response.RegionLocationsResp;
 import org.apache.iotdb.confignode.consensus.response.SchemaNodeManagementResp;
 import org.apache.iotdb.confignode.consensus.response.SchemaPartitionResp;
 import org.apache.iotdb.confignode.exception.StorageGroupNotExistsException;
@@ -48,6 +51,7 @@ import org.apache.iotdb.db.service.metrics.enums.Metric;
 import org.apache.iotdb.db.service.metrics.enums.Tag;
 import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
 import org.apache.iotdb.metrics.utils.MetricLevel;
+import org.apache.iotdb.rpc.RpcUtils;
 import org.apache.iotdb.rpc.TSStatusCode;
 import org.apache.iotdb.tsfile.utils.Pair;
 import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
@@ -65,6 +69,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -419,6 +424,25 @@ public class PartitionInfo implements SnapshotProcessor {
     return schemaNodeManagementResp;
   }
 
+  /** Get region information */
+  public DataSet getRegionLocations(GetRegionLocationsReq regionsInfoReq) {
+    RegionLocationsResp regionResp = new RegionLocationsResp();
+    List<TRegionLocation> regionLocationList = new ArrayList<>();
+    if (storageGroupPartitionTables.isEmpty()) {
+      regionResp.setStatus(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS));
+      return regionResp;
+    }
+    storageGroupPartitionTables.forEach(
+        (storageGroup, storageGroupPartitionTable) -> {
+          storageGroupPartitionTable.getRegionInfos(regionsInfoReq, 
regionLocationList);
+        });
+    regionLocationList.sort(
+        Comparator.comparingInt(regionId -> 
regionId.getConsensusGroupId().getId()));
+    regionResp.setRegionInfosList(regionLocationList);
+    regionResp.setStatus(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS));
+    return regionResp;
+  }
+
   // ======================================================
   // Leader scheduling interfaces
   // ======================================================
@@ -595,6 +619,7 @@ public class PartitionInfo implements SnapshotProcessor {
     return result;
   }
 
+  @Override
   public boolean processTakeSnapshot(File snapshotDir) throws TException, 
IOException {
 
     File snapshotFile = new File(snapshotDir, snapshotFileName);
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/StorageGroupPartitionTable.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/StorageGroupPartitionTable.java
index d46447c46d..71a8f072e2 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/StorageGroupPartitionTable.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/StorageGroupPartitionTable.java
@@ -20,11 +20,14 @@ package org.apache.iotdb.confignode.persistence.partition;
 
 import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
 import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
+import org.apache.iotdb.common.rpc.thrift.TRegionLocation;
 import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
 import org.apache.iotdb.common.rpc.thrift.TSeriesPartitionSlot;
 import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot;
+import org.apache.iotdb.commons.cluster.RegionStatus;
 import org.apache.iotdb.commons.partition.DataPartitionTable;
 import org.apache.iotdb.commons.partition.SchemaPartitionTable;
+import 
org.apache.iotdb.confignode.consensus.request.read.GetRegionLocationsReq;
 import org.apache.iotdb.db.service.metrics.MetricsService;
 import org.apache.iotdb.db.service.metrics.enums.Metric;
 import org.apache.iotdb.db.service.metrics.enums.Tag;
@@ -361,6 +364,42 @@ public class StorageGroupPartitionTable {
     return result;
   }
 
+  public void getRegionInfos(
+      GetRegionLocationsReq regionsInfoReq, List<TRegionLocation> 
regionLocationList) {
+    regionInfoMap.forEach(
+        (consensusGroupId, regionGroup) -> {
+          TRegionReplicaSet replicaSet = regionGroup.getReplicaSet();
+          if (regionsInfoReq.getRegionType() == null) {
+            buildTRegionsInfo(regionLocationList, replicaSet, regionGroup);
+          } else if (regionsInfoReq.getRegionType().ordinal()
+              == replicaSet.getRegionId().getType().ordinal()) {
+            buildTRegionsInfo(regionLocationList, replicaSet, regionGroup);
+          }
+        });
+  }
+
+  private void buildTRegionsInfo(
+      List<TRegionLocation> regionLocationList,
+      TRegionReplicaSet replicaSet,
+      RegionGroup regionGroup) {
+    replicaSet
+        .getDataNodeLocations()
+        .forEach(
+            (dataNodeLocation) -> {
+              TRegionLocation tRegionInfos = new TRegionLocation();
+              tRegionInfos.setConsensusGroupId(replicaSet.getRegionId());
+              tRegionInfos.setStorageGroup(storageGroupName);
+              long slots = regionGroup.getCounter();
+              tRegionInfos.setSlots((int) slots);
+              tRegionInfos.setDataNodeId(dataNodeLocation.getDataNodeId());
+              
tRegionInfos.setRpcAddresss(dataNodeLocation.getExternalEndPoint().getIp());
+              
tRegionInfos.setRpcPort(dataNodeLocation.getExternalEndPoint().getPort());
+              // TODO: Wait for data migration. And then add the state
+              tRegionInfos.setStatus(RegionStatus.Up.getStatus());
+              regionLocationList.add(tRegionInfos);
+            });
+  }
+
   public void serialize(OutputStream outputStream, TProtocol protocol)
       throws IOException, TException {
     ReadWriteIOUtils.write(isPredeleted, outputStream);
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
index ccf897bac7..7ce56e438d 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
@@ -35,6 +35,7 @@ import 
org.apache.iotdb.confignode.consensus.request.read.CountStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetDataNodeInfoReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetOrCreateDataPartitionReq;
+import 
org.apache.iotdb.confignode.consensus.request.read.GetRegionLocationsReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.request.write.ApplyConfigNodeReq;
 import org.apache.iotdb.confignode.consensus.request.write.RegisterDataNodeReq;
@@ -48,6 +49,7 @@ import 
org.apache.iotdb.confignode.consensus.response.DataNodeConfigurationResp;
 import org.apache.iotdb.confignode.consensus.response.DataNodeInfosResp;
 import org.apache.iotdb.confignode.consensus.response.DataPartitionResp;
 import org.apache.iotdb.confignode.consensus.response.PermissionInfoResp;
+import org.apache.iotdb.confignode.consensus.response.RegionLocationsResp;
 import org.apache.iotdb.confignode.consensus.response.SchemaNodeManagementResp;
 import org.apache.iotdb.confignode.consensus.response.SchemaPartitionResp;
 import org.apache.iotdb.confignode.consensus.response.StorageGroupSchemaResp;
@@ -82,6 +84,8 @@ import 
org.apache.iotdb.confignode.rpc.thrift.TSetSchemaReplicationFactorReq;
 import org.apache.iotdb.confignode.rpc.thrift.TSetStorageGroupReq;
 import org.apache.iotdb.confignode.rpc.thrift.TSetTTLReq;
 import org.apache.iotdb.confignode.rpc.thrift.TSetTimePartitionIntervalReq;
+import org.apache.iotdb.confignode.rpc.thrift.TShowRegionReq;
+import org.apache.iotdb.confignode.rpc.thrift.TShowRegionResp;
 import org.apache.iotdb.confignode.rpc.thrift.TStorageGroupSchema;
 import org.apache.iotdb.confignode.rpc.thrift.TStorageGroupSchemaResp;
 import org.apache.iotdb.db.mpp.common.schematree.PathPatternTree;
@@ -445,6 +449,17 @@ public class ConfigNodeRPCServiceProcessor implements 
ConfigIService.Iface {
     return tsStatus;
   }
 
+  @Override
+  public TShowRegionResp showRegion(TShowRegionReq showRegionReq) throws 
TException {
+    GetRegionLocationsReq getRegionsinfoReq =
+        new GetRegionLocationsReq(showRegionReq.getConsensusGroupType());
+    RegionLocationsResp dataSet = (RegionLocationsResp) 
configManager.showRegion(getRegionsinfoReq);
+    TShowRegionResp showRegionResp = new TShowRegionResp();
+    showRegionResp.setStatus(dataSet.getStatus());
+    showRegionResp.setRegionInfoList(dataSet.getRegionInfosList());
+    return showRegionResp;
+  }
+
   public void handleClientExit() {}
 
   // TODO: Interfaces for data operations
diff --git 
a/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/ConfigRequestSerDeTest.java
 
b/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/ConfigRequestSerDeTest.java
index ad42e3d4ef..61a7381027 100644
--- 
a/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/ConfigRequestSerDeTest.java
+++ 
b/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/ConfigRequestSerDeTest.java
@@ -38,6 +38,7 @@ import 
org.apache.iotdb.confignode.consensus.request.read.GetDataNodeInfoReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetOrCreateDataPartitionReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetOrCreateSchemaPartitionReq;
+import 
org.apache.iotdb.confignode.consensus.request.read.GetRegionLocationsReq;
 import 
org.apache.iotdb.confignode.consensus.request.read.GetSchemaPartitionReq;
 import org.apache.iotdb.confignode.consensus.request.read.GetStorageGroupReq;
 import org.apache.iotdb.confignode.consensus.request.write.ApplyConfigNodeReq;
@@ -517,4 +518,14 @@ public class ConfigRequestSerDeTest {
         (DeleteProcedureReq) 
ConfigRequest.Factory.create(req0.serializeToByteBuffer());
     Assert.assertEquals(req0, req1);
   }
+
+  @Test
+  public void GetRegionLocaltionsReqTest() throws IOException {
+    GetRegionLocationsReq req0 = new GetRegionLocationsReq();
+    req0.setRegionType(TConsensusGroupType.DataRegion);
+    GetRegionLocationsReq req1 =
+        (GetRegionLocationsReq) 
ConfigRequest.Factory.create(req0.serializeToByteBuffer());
+    Assert.assertEquals(req0.getType(), req1.getType());
+    Assert.assertEquals(req0.getRegionType(), req1.getRegionType());
+  }
 }
diff --git 
a/confignode/src/test/java/org/apache/iotdb/confignode/persistence/PartitionInfoTest.java
 
b/confignode/src/test/java/org/apache/iotdb/confignode/persistence/PartitionInfoTest.java
index 007d599ad8..1e24f8f1ed 100644
--- 
a/confignode/src/test/java/org/apache/iotdb/confignode/persistence/PartitionInfoTest.java
+++ 
b/confignode/src/test/java/org/apache/iotdb/confignode/persistence/PartitionInfoTest.java
@@ -29,10 +29,12 @@ import 
org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot;
 import org.apache.iotdb.commons.partition.DataPartitionTable;
 import org.apache.iotdb.commons.partition.SchemaPartitionTable;
 import org.apache.iotdb.commons.partition.SeriesPartitionTable;
+import 
org.apache.iotdb.confignode.consensus.request.read.GetRegionLocationsReq;
 import 
org.apache.iotdb.confignode.consensus.request.write.CreateDataPartitionReq;
 import org.apache.iotdb.confignode.consensus.request.write.CreateRegionsReq;
 import 
org.apache.iotdb.confignode.consensus.request.write.CreateSchemaPartitionReq;
 import org.apache.iotdb.confignode.consensus.request.write.SetStorageGroupReq;
+import org.apache.iotdb.confignode.consensus.response.RegionLocationsResp;
 import org.apache.iotdb.confignode.persistence.partition.PartitionInfo;
 import org.apache.iotdb.confignode.rpc.thrift.TStorageGroupSchema;
 
@@ -58,7 +60,7 @@ public class PartitionInfoTest {
   private static PartitionInfo partitionInfo;
   private static final File snapshotDir = new File(BASE_OUTPUT_PATH, 
"snapshot");
 
-  enum testFlag {
+  public enum testFlag {
     DataPartition(20),
     SchemaPartition(30);
 
@@ -143,6 +145,70 @@ public class PartitionInfoTest {
     Assert.assertEquals(partitionInfo, partitionInfo1);
   }
 
+  @Test
+  public void testShowRegion() {
+    partitionInfo.generateNextRegionGroupId();
+
+    // Set StorageGroup
+    partitionInfo.setStorageGroup(new SetStorageGroupReq(new 
TStorageGroupSchema("root.test")));
+
+    // Create a SchemaRegion
+    CreateRegionsReq createRegionsReq = new CreateRegionsReq();
+    TRegionReplicaSet schemaRegionReplicaSet =
+        generateTRegionReplicaSet(
+            testFlag.SchemaPartition.getFlag(),
+            generateTConsensusGroupId(
+                testFlag.SchemaPartition.getFlag(), 
TConsensusGroupType.SchemaRegion));
+    createRegionsReq.addRegion("root.test", schemaRegionReplicaSet);
+    partitionInfo.createRegions(createRegionsReq);
+
+    // Create a DataRegion
+    createRegionsReq = new CreateRegionsReq();
+    TRegionReplicaSet dataRegionReplicaSet =
+        generateTRegionReplicaSet(
+            testFlag.DataPartition.getFlag(),
+            generateTConsensusGroupId(
+                testFlag.DataPartition.getFlag(), 
TConsensusGroupType.DataRegion));
+    createRegionsReq.addRegion("root.test", dataRegionReplicaSet);
+    partitionInfo.createRegions(createRegionsReq);
+
+    GetRegionLocationsReq regionReq = new GetRegionLocationsReq();
+    regionReq.setRegionType(null);
+    RegionLocationsResp regionLocations1 =
+        (RegionLocationsResp) partitionInfo.getRegionLocations(regionReq);
+    Assert.assertEquals(regionLocations1.getRegionInfosList().size(), 10);
+    regionLocations1
+        .getRegionInfosList()
+        .forEach(
+            (regionLocation) -> {
+              Assert.assertEquals(regionLocation.getRpcAddresss(), 
"127.0.0.1");
+            });
+
+    regionReq.setRegionType(TConsensusGroupType.SchemaRegion);
+    RegionLocationsResp regionLocations2 =
+        (RegionLocationsResp) partitionInfo.getRegionLocations(regionReq);
+    Assert.assertEquals(regionLocations2.getRegionInfosList().size(), 5);
+    regionLocations2
+        .getRegionInfosList()
+        .forEach(
+            (regionLocation) -> {
+              Assert.assertEquals(
+                  regionLocation.getConsensusGroupId().getType(), 
TConsensusGroupType.SchemaRegion);
+            });
+
+    regionReq.setRegionType(TConsensusGroupType.DataRegion);
+    RegionLocationsResp regionLocations3 =
+        (RegionLocationsResp) partitionInfo.getRegionLocations(regionReq);
+    Assert.assertEquals(regionLocations3.getRegionInfosList().size(), 5);
+    regionLocations3
+        .getRegionInfosList()
+        .forEach(
+            (regionLocation) -> {
+              Assert.assertEquals(
+                  regionLocation.getConsensusGroupId().getType(), 
TConsensusGroupType.DataRegion);
+            });
+  }
+
   private TRegionReplicaSet generateTRegionReplicaSet(
       int startFlag, TConsensusGroupId tConsensusGroupId) {
     TRegionReplicaSet tRegionReplicaSet = new TRegionReplicaSet();
diff --git a/docs/UserGuide/Maintenance-Tools/Maintenance-Command.md 
b/docs/UserGuide/Maintenance-Tools/Maintenance-Command.md
index 5d99fa63e5..09a1f36b07 100644
--- a/docs/UserGuide/Maintenance-Tools/Maintenance-Command.md
+++ b/docs/UserGuide/Maintenance-Tools/Maintenance-Command.md
@@ -113,4 +113,69 @@ To get the executing `queryId`,you can use the `show query 
processlist` comman
 | ---- | ------- | --------- |
 |      |         |           |
 
-The maximum display length of statement is 64 characters. For statements with 
more than 64 characters, the intercepted part will be displayed.
\ No newline at end of file
+The maximum display length of statement is 64 characters. For statements with 
more than 64 characters, the intercepted part will be displayed.
+
+
+
+## Monitoring tool for cluster Region distribution
+
+A cluster uses a Region as a unit for data replication and data management . 
The Region status and distribution is helpful for system operation and 
maintenance testing , as shown in the following scenario :
+
+-  Check which Datanodes are allocated to each Region in the cluster and 
whether the balance is correct.
+
+Currently, IoTDB supports Region query using the following SQL:
+
+- `SHOW REGIONS`: Show all Region
+- `SHOW SCHEMA REGIONS`: Show all SchemaRegion distribution
+- `SHOW DATA REGIONS`: Show all DataRegion distribution
+
+```sql
+IoTDB> show regions
++--------+------------+------+-------------+-----+----------+----------+----+
+|RegionId|        Type|Status|storage group|Slots|DataNodeId|HostAdress|Port|
++--------+------------+------+-------------+-----+----------+----------+----+
+|       0|SchemaRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|       1|SchemaRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       2|SchemaRegion|    Up|      root.sg|    1|         4| 127.0.0.1|6671|
+|       3|  DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       4|  DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       5|  DataRegion|    Up|      root.sg|    1|         1| 127.0.0.1|6667|
+|       6|  DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|       7|  DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|       8|  DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|       9|  DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|      10|  DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|      11|  DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|      12|  DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
++--------+------------+------+-------------+-----+----------+----------+----+
+Total line number = 13
+It costs 0.107s
+IoTDB> show schema regions
++--------+------------+------+-------------+-----+----------+----------+----+
+|RegionId|        Type|Status|storage group|Slots|DataNodeId|HostAdress|Port|
++--------+------------+------+-------------+-----+----------+----------+----+
+|       0|SchemaRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|       1|SchemaRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       2|SchemaRegion|    Up|      root.sg|    1|         4| 127.0.0.1|6671|
++--------+------------+------+-------------+-----+----------+----------+----+
+Total line number = 3
+It costs 0.009s
+IoTDB> show data regions
++--------+----------+------+-------------+-----+----------+----------+----+
+|RegionId|      Type|Status|storage group|Slots|DataNodeId|HostAdress|Port|
++--------+----------+------+-------------+-----+----------+----------+----+
+|       3|DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       4|DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       5|DataRegion|    Up|      root.sg|    1|         1| 127.0.0.1|6667|
+|       6|DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|       7|DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|       8|DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|       9|DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|      10|DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|      11|DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|      12|DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
++--------+----------+------+-------------+-----+----------+----------+----+
+Total line number = 10
+It costs 0.023s
+```
+
diff --git a/docs/zh/UserGuide/Maintenance-Tools/Maintenance-Command.md 
b/docs/zh/UserGuide/Maintenance-Tools/Maintenance-Command.md
index 70df0c7953..24d7b647cd 100644
--- a/docs/zh/UserGuide/Maintenance-Tools/Maintenance-Command.md
+++ b/docs/zh/UserGuide/Maintenance-Tools/Maintenance-Command.md
@@ -111,3 +111,66 @@ KILL QUERY <queryId>
 |      |         |           |
 
 其中 statement 最大显示长度为 64 字符。对于超过 64 字符的查询语句,将截取部分进行显示。
+
+## 集群 Region 分布监控工具
+
+集群中以 Region 作为数据复制和数据管理的单元,Region 的状态和分布对于系统运维和测试有很大帮助,如以下场景:
+
+- 查看集群中各个 Region 被分配到了哪些 DataNode,是否均衡
+
+当前 IoTDB 支持使用如下 SQL 查看 Region:
+
+- `SHOW REGIONS`: 展示所有 Region
+- `SHOW SCHEMA REGIONS`: 展示所有 SchemaRegion 分布
+- `SHOW DATA REGIONS`: 展示所有 DataRegion 分布
+
+```sql
+IoTDB> show regions
++--------+------------+------+-------------+-----+----------+----------+----+
+|RegionId|        Type|Status|storage group|Slots|DataNodeId|HostAdress|Port|
++--------+------------+------+-------------+-----+----------+----------+----+
+|       0|SchemaRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|       1|SchemaRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       2|SchemaRegion|    Up|      root.sg|    1|         4| 127.0.0.1|6671|
+|       3|  DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       4|  DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       5|  DataRegion|    Up|      root.sg|    1|         1| 127.0.0.1|6667|
+|       6|  DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|       7|  DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|       8|  DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|       9|  DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|      10|  DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|      11|  DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|      12|  DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
++--------+------------+------+-------------+-----+----------+----------+----+
+Total line number = 13
+It costs 0.107s
+IoTDB> show schema regions
++--------+------------+------+-------------+-----+----------+----------+----+
+|RegionId|        Type|Status|storage group|Slots|DataNodeId|HostAdress|Port|
++--------+------------+------+-------------+-----+----------+----------+----+
+|       0|SchemaRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|       1|SchemaRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       2|SchemaRegion|    Up|      root.sg|    1|         4| 127.0.0.1|6671|
++--------+------------+------+-------------+-----+----------+----------+----+
+Total line number = 3
+It costs 0.009s
+IoTDB> show data regions
++--------+----------+------+-------------+-----+----------+----------+----+
+|RegionId|      Type|Status|storage group|Slots|DataNodeId|HostAdress|Port|
++--------+----------+------+-------------+-----+----------+----------+----+
+|       3|DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       4|DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|       5|DataRegion|    Up|      root.sg|    1|         1| 127.0.0.1|6667|
+|       6|DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|       7|DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|       8|DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|       9|DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
+|      10|DataRegion|    Up|      root.sg|    0|         4| 127.0.0.1|6671|
+|      11|DataRegion|    Up|      root.sg|    0|         3| 127.0.0.1|6669|
+|      12|DataRegion|    Up|      root.sg|    0|         1| 127.0.0.1|6667|
++--------+----------+------+-------------+-----+----------+----------+----+
+Total line number = 10
+It costs 0.023s
+```
+
diff --git 
a/node-commons/src/main/java/org/apache/iotdb/commons/cluster/RegionStatus.java 
b/node-commons/src/main/java/org/apache/iotdb/commons/cluster/RegionStatus.java
new file mode 100644
index 0000000000..ca1282b6cf
--- /dev/null
+++ 
b/node-commons/src/main/java/org/apache/iotdb/commons/cluster/RegionStatus.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.cluster;
+
+/** Node status for showing regions */
+public enum RegionStatus {
+  // Node running properly
+  Up("Up");
+
+  private final String status;
+
+  RegionStatus(String status) {
+    this.status = status;
+  }
+
+  public String getStatus() {
+    return status;
+  }
+}
diff --git 
a/server/src/main/java/org/apache/iotdb/db/client/ConfigNodeClient.java 
b/server/src/main/java/org/apache/iotdb/db/client/ConfigNodeClient.java
index f295613b4e..1dfaf9bb4e 100644
--- a/server/src/main/java/org/apache/iotdb/db/client/ConfigNodeClient.java
+++ b/server/src/main/java/org/apache/iotdb/db/client/ConfigNodeClient.java
@@ -59,7 +59,10 @@ import 
org.apache.iotdb.confignode.rpc.thrift.TSetSchemaReplicationFactorReq;
 import org.apache.iotdb.confignode.rpc.thrift.TSetStorageGroupReq;
 import org.apache.iotdb.confignode.rpc.thrift.TSetTTLReq;
 import org.apache.iotdb.confignode.rpc.thrift.TSetTimePartitionIntervalReq;
+import org.apache.iotdb.confignode.rpc.thrift.TShowRegionReq;
+import org.apache.iotdb.confignode.rpc.thrift.TShowRegionResp;
 import org.apache.iotdb.confignode.rpc.thrift.TStorageGroupSchemaResp;
+import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.rpc.RpcTransportFactory;
 import org.apache.iotdb.rpc.TSStatusCode;
@@ -97,8 +100,12 @@ public class ConfigNodeClient implements 
ConfigIService.Iface, SyncThriftClient,
 
   private List<TEndPoint> configNodes;
 
+  private TEndPoint configNode;
+
   private int cursor = 0;
 
+  private IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig();
+
   ClientManager<PartitionRegionId, ConfigNodeClient> clientManager;
 
   PartitionRegionId partitionRegionId = ConfigNodeInfo.partitionRegionId;
@@ -140,6 +147,7 @@ public class ConfigNodeClient implements 
ConfigIService.Iface, SyncThriftClient,
               // as there is a try-catch already, we do not need to use 
TSocket.wrap
               endpoint.getIp(), endpoint.getPort(), (int) connectionTimeout);
       transport.open();
+      configNode = endpoint;
     } catch (TTransportException e) {
       throw new TException(e);
     }
@@ -223,6 +231,10 @@ public class ConfigNodeClient implements 
ConfigIService.Iface, SyncThriftClient,
       } else {
         configLeader = null;
       }
+      logger.warn(
+          "Failed to connect to ConfigNode {} from DataNode {},because the 
current node is not leader,try next node",
+          configNode,
+          config.getAddressAndPort());
       return true;
     }
     return false;
@@ -657,6 +669,22 @@ public class ConfigNodeClient implements 
ConfigIService.Iface, SyncThriftClient,
     throw new TException(MSG_RECONNECTION_FAIL);
   }
 
+  @Override
+  public TShowRegionResp showRegion(TShowRegionReq req) throws TException {
+    for (int i = 0; i < RETRY_NUM; i++) {
+      try {
+        TShowRegionResp showRegionResp = client.showRegion(req);
+        if (!updateConfigNodeLeader(showRegionResp.getStatus())) {
+          return showRegionResp;
+        }
+      } catch (TException e) {
+        configLeader = null;
+      }
+      reconnect();
+    }
+    throw new TException(MSG_RECONNECTION_FAIL);
+  }
+
   @Override
   public TSStatus dropFunction(TDropFunctionReq req) throws TException {
     for (int i = 0; i < RETRY_NUM; i++) {
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java 
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index 50bc44f4a9..60d38e06d8 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -2920,4 +2920,8 @@ public class IoTDBConfig {
   public void setTriggerForwardMQTTPoolSize(int triggerForwardMQTTPoolSize) {
     this.triggerForwardMQTTPoolSize = triggerForwardMQTTPoolSize;
   }
+
+  public TEndPoint getAddressAndPort() {
+    return new TEndPoint(rpcAddress, rpcPort);
+  }
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/common/header/HeaderConstant.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/common/header/HeaderConstant.java
index e48e71754c..f92e9d93e6 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/common/header/HeaderConstant.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/common/header/HeaderConstant.java
@@ -69,6 +69,12 @@ public class HeaderConstant {
   public static final String COLUMN_FUNCTION_TYPE = "function type";
   public static final String COLUMN_FUNCTION_CLASS = "class name (UDF)";
 
+  // column names for show region statement
+  public static final String COLUMN_REGION_ID = "RegionId";
+  public static final String COLUMN_TYPE = "Type";
+  public static final String COLUMN_DATANODE_ID = "DataNodeId";
+  public static final String COLUMN_SLOTS = "Slots";
+
   // dataset header for schema statement
   public static final DatasetHeader showTimeSeriesHeader;
   public static final DatasetHeader showDevicesHeader;
@@ -94,6 +100,9 @@ public class HeaderConstant {
   // dataset header for show functions
   public static final DatasetHeader SHOW_FUNCTIONS_HEADER;
 
+  // dataset header for show region
+  public static final DatasetHeader showRegionHeader;
+
   static {
     countStorageGroupHeader =
         new DatasetHeader(
@@ -200,4 +209,19 @@ public class HeaderConstant {
                 new ColumnHeader(COLUMN_FUNCTION_CLASS, TSDataType.TEXT)),
             true);
   }
+
+  static {
+    showRegionHeader =
+        new DatasetHeader(
+            Arrays.asList(
+                new ColumnHeader(COLUMN_REGION_ID, TSDataType.INT32),
+                new ColumnHeader(COLUMN_TYPE, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_STATUS, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_STORAGE_GROUP, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_SLOTS, TSDataType.INT64),
+                new ColumnHeader(COLUMN_DATANODE_ID, TSDataType.INT32),
+                new ColumnHeader(COLUMN_HOST_ADDRESS, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_PORT, TSDataType.INT32)),
+            true);
+  }
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/ConfigTaskVisitor.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/ConfigTaskVisitor.java
index 03ee48af39..517b06208f 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/ConfigTaskVisitor.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/ConfigTaskVisitor.java
@@ -30,6 +30,7 @@ import 
org.apache.iotdb.db.mpp.plan.statement.metadata.SetStorageGroupStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.SetTTLStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowClusterStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowFunctionsStatement;
+import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowRegionStatement;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.ShowStorageGroupStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowTTLStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.UnSetTTLStatement;
@@ -123,5 +124,10 @@ public class ConfigTaskVisitor
     return new ShowFunctionsTask();
   }
 
+  @Override
+  public IConfigTask visitShowRegion(ShowRegionStatement showRegionStatement, 
TaskContext context) {
+    return new ShowRegionTask(showRegionStatement);
+  }
+
   public static class TaskContext {}
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/ShowRegionTask.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/ShowRegionTask.java
new file mode 100644
index 0000000000..e4447eb058
--- /dev/null
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/ShowRegionTask.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.plan.execution.config;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
+import org.apache.iotdb.common.rpc.thrift.TRegionLocation;
+import org.apache.iotdb.confignode.rpc.thrift.TShowRegionResp;
+import org.apache.iotdb.db.mpp.common.header.DatasetHeader;
+import org.apache.iotdb.db.mpp.common.header.HeaderConstant;
+import 
org.apache.iotdb.db.mpp.plan.execution.config.executor.IConfigTaskExecutor;
+import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowRegionStatement;
+import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.iotdb.tsfile.utils.Binary;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+
+public class ShowRegionTask implements IConfigTask {
+
+  private ShowRegionStatement showRegionStatement;
+
+  public ShowRegionTask() {}
+
+  public ShowRegionTask(ShowRegionStatement showRegionStatement) {
+    this.showRegionStatement = showRegionStatement;
+  }
+
+  @Override
+  public ListenableFuture<ConfigTaskResult> execute(IConfigTaskExecutor 
configTaskExecutor)
+      throws InterruptedException {
+    return configTaskExecutor.showRegion(showRegionStatement);
+  }
+
+  public static void buildTSBlock(
+      TShowRegionResp showRegionResp, SettableFuture<ConfigTaskResult> future) 
{
+    TsBlockBuilder builder = new 
TsBlockBuilder(HeaderConstant.showRegionHeader.getRespDataTypes());
+    if (showRegionResp.getRegionInfoList() != null) {
+      for (TRegionLocation regionLocation : 
showRegionResp.getRegionInfoList()) {
+        builder.getTimeColumnBuilder().writeLong(0L);
+        
builder.getColumnBuilder(0).writeInt(regionLocation.getConsensusGroupId().getId());
+        if (regionLocation.getConsensusGroupId().getType().ordinal()
+            == TConsensusGroupType.SchemaRegion.ordinal()) {
+          builder
+              .getColumnBuilder(1)
+              
.writeBinary(Binary.valueOf(String.valueOf(TConsensusGroupType.SchemaRegion)));
+        } else if (regionLocation.getConsensusGroupId().getType().ordinal()
+            == TConsensusGroupType.DataRegion.ordinal()) {
+          builder
+              .getColumnBuilder(1)
+              
.writeBinary(Binary.valueOf(String.valueOf(TConsensusGroupType.DataRegion)));
+        }
+        builder
+            .getColumnBuilder(2)
+            .writeBinary(
+                Binary.valueOf(
+                    regionLocation.getStatus() == null ? "" : 
regionLocation.getStatus()));
+        
builder.getColumnBuilder(3).writeBinary(Binary.valueOf(regionLocation.getStorageGroup()));
+        builder.getColumnBuilder(4).writeLong(regionLocation.getSlots());
+        builder.getColumnBuilder(5).writeInt(regionLocation.getDataNodeId());
+        
builder.getColumnBuilder(6).writeBinary(Binary.valueOf(regionLocation.getRpcAddresss()));
+        builder.getColumnBuilder(7).writeInt(regionLocation.getRpcPort());
+        builder.declarePosition();
+      }
+    }
+    DatasetHeader datasetHeader = HeaderConstant.showRegionHeader;
+    future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS, 
builder.build(), datasetHeader));
+  }
+}
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java
index 0975776ded..93c08bfb40 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java
@@ -31,6 +31,8 @@ import 
org.apache.iotdb.confignode.rpc.thrift.TDeleteStorageGroupsReq;
 import org.apache.iotdb.confignode.rpc.thrift.TDropFunctionReq;
 import org.apache.iotdb.confignode.rpc.thrift.TSetStorageGroupReq;
 import org.apache.iotdb.confignode.rpc.thrift.TSetTTLReq;
+import org.apache.iotdb.confignode.rpc.thrift.TShowRegionReq;
+import org.apache.iotdb.confignode.rpc.thrift.TShowRegionResp;
 import org.apache.iotdb.confignode.rpc.thrift.TStorageGroupSchema;
 import org.apache.iotdb.confignode.rpc.thrift.TStorageGroupSchemaResp;
 import org.apache.iotdb.db.client.ConfigNodeClient;
@@ -40,12 +42,14 @@ import 
org.apache.iotdb.db.mpp.plan.execution.config.ConfigTaskResult;
 import org.apache.iotdb.db.mpp.plan.execution.config.CountStorageGroupTask;
 import org.apache.iotdb.db.mpp.plan.execution.config.SetStorageGroupTask;
 import org.apache.iotdb.db.mpp.plan.execution.config.ShowClusterTask;
+import org.apache.iotdb.db.mpp.plan.execution.config.ShowRegionTask;
 import org.apache.iotdb.db.mpp.plan.execution.config.ShowStorageGroupTask;
 import org.apache.iotdb.db.mpp.plan.execution.config.ShowTTLTask;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.CountStorageGroupStatement;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.DeleteStorageGroupStatement;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.SetStorageGroupStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.SetTTLStatement;
+import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowRegionStatement;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.ShowStorageGroupStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowTTLStatement;
 import org.apache.iotdb.rpc.StatementExecutionException;
@@ -104,7 +108,6 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
         future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
       }
     } catch (TException | IOException e) {
-      LOGGER.error("Failed to connect to config node.");
       future.setException(e);
     }
     return future;
@@ -126,7 +129,6 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
       // build TSBlock
       ShowStorageGroupTask.buildTSBlock(storageGroupSchemaMap, future);
     } catch (TException | IOException e) {
-      LOGGER.error("Failed to connect to config node.");
       future.setException(e);
     }
     return future;
@@ -146,7 +148,6 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
       // build TSBlock
       CountStorageGroupTask.buildTSBlock(storageGroupNum, future);
     } catch (TException | IOException e) {
-      LOGGER.error("Failed to connect to config node.");
       future.setException(e);
     }
     return future;
@@ -173,7 +174,6 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
         future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
       }
     } catch (TException | IOException e) {
-      LOGGER.error("Failed to connect to config node.");
       future.setException(e);
     }
     return future;
@@ -198,7 +198,6 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
         future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
       }
     } catch (TException | IOException e) {
-      LOGGER.error("Failed to connect to config node.");
       future.setException(e);
     }
     return future;
@@ -218,7 +217,6 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
         future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
       }
     } catch (TException | IOException e) {
-      LOGGER.error("Failed to connect to config node.");
       future.setException(e);
     }
     return future;
@@ -246,7 +244,6 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
         future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
       }
     } catch (TException | IOException e) {
-      LOGGER.error("Failed to connect to config node.");
       future.setException(e);
     }
     return future;
@@ -267,7 +264,6 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
         future.setException(new StatementExecutionException(tsStatus));
       }
     } catch (IOException | TException e) {
-      LOGGER.error("Failed to connect to config node.");
       future.setException(e);
     }
     return future;
@@ -281,7 +277,6 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
         
CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.partitionRegionId)) {
       clusterNodeInfos = client.getAllClusterNodeInfos();
     } catch (TException | IOException e) {
-      LOGGER.error("Failed to connect to config node.");
       future.setException(e);
     }
     // build TSBlock
@@ -318,11 +313,31 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
         }
       }
     } catch (TException | IOException e) {
-      LOGGER.error("Failed to connect to config node.");
       future.setException(e);
     }
     // build TSBlock
     ShowTTLTask.buildTSBlock(storageGroupToTTL, future);
     return future;
   }
+
+  @Override
+  public SettableFuture<ConfigTaskResult> showRegion(ShowRegionStatement 
showRegionStatement) {
+    SettableFuture<ConfigTaskResult> future = SettableFuture.create();
+    TShowRegionResp showRegionResp = new TShowRegionResp();
+    TShowRegionReq showRegionReq = new TShowRegionReq();
+    showRegionReq.setConsensusGroupType(showRegionStatement.getRegionType());
+    try (ConfigNodeClient client =
+        
CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.partitionRegionId)) {
+      showRegionResp = client.showRegion(showRegionReq);
+      if (showRegionResp.getStatus().getCode() != 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+        future.setException(new 
StatementExecutionException(showRegionResp.getStatus()));
+        return future;
+      }
+    } catch (TException | IOException e) {
+      future.setException(e);
+    }
+    // build TSBlock
+    ShowRegionTask.buildTSBlock(showRegionResp, future);
+    return future;
+  }
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/IConfigTaskExecutor.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/IConfigTaskExecutor.java
index f49390553b..5d60904d5c 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/IConfigTaskExecutor.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/IConfigTaskExecutor.java
@@ -25,6 +25,7 @@ import 
org.apache.iotdb.db.mpp.plan.statement.metadata.CountStorageGroupStatemen
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.DeleteStorageGroupStatement;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.SetStorageGroupStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.SetTTLStatement;
+import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowRegionStatement;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.ShowStorageGroupStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowTTLStatement;
 
@@ -58,4 +59,6 @@ public interface IConfigTaskExecutor {
   SettableFuture<ConfigTaskResult> showCluster();
 
   SettableFuture<ConfigTaskResult> showTTL(ShowTTLStatement showTTLStatement);
+
+  SettableFuture<ConfigTaskResult> showRegion(ShowRegionStatement 
showRegionStatement);
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/StandaloneConfigTaskExecutor.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/StandaloneConfigTaskExecutor.java
index b4970523bc..dd6b760e93 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/StandaloneConfigTaskExecutor.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/StandaloneConfigTaskExecutor.java
@@ -36,6 +36,7 @@ import 
org.apache.iotdb.db.mpp.plan.statement.metadata.CountStorageGroupStatemen
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.DeleteStorageGroupStatement;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.SetStorageGroupStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.SetTTLStatement;
+import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowRegionStatement;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.ShowStorageGroupStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowTTLStatement;
 import org.apache.iotdb.rpc.RpcUtils;
@@ -222,7 +223,7 @@ public class StandaloneConfigTaskExecutor implements 
IConfigTaskExecutor {
         new StatementExecutionException(
             RpcUtils.getStatus(
                 TSStatusCode.EXECUTE_STATEMENT_ERROR,
-                "Executing this command in standalone mode is not 
supported")));
+                "Executing show cluster in standalone mode is not 
supported")));
     return future;
   }
 
@@ -256,4 +257,15 @@ public class StandaloneConfigTaskExecutor implements 
IConfigTaskExecutor {
     ShowTTLTask.buildTSBlock(storageGroupToTTL, future);
     return future;
   }
+
+  @Override
+  public SettableFuture<ConfigTaskResult> showRegion(ShowRegionStatement 
showRegionStatement) {
+    SettableFuture<ConfigTaskResult> future = SettableFuture.create();
+    future.setException(
+        new StatementExecutionException(
+            RpcUtils.getStatus(
+                TSStatusCode.EXECUTE_STATEMENT_ERROR,
+                "Executing show regions in standalone mode is not 
supported")));
+    return future;
+  }
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
index f33b9dbc8f..cba94ec4f2 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
@@ -19,6 +19,7 @@
 
 package org.apache.iotdb.db.mpp.plan.parser;
 
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
 import org.apache.iotdb.commons.conf.IoTDBConstant;
 import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.path.PartialPath;
@@ -95,6 +96,7 @@ import 
org.apache.iotdb.db.mpp.plan.statement.metadata.ShowChildPathsStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowClusterStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowDevicesStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowFunctionsStatement;
+import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowRegionStatement;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.ShowStorageGroupStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowTTLStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowTimeSeriesStatement;
@@ -2217,4 +2219,20 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
     flushStatement.setStorageGroups(storageGroups);
     return flushStatement;
   }
+
+  // show region
+
+  @Override
+  public Statement visitShowRegion(IoTDBSqlParser.ShowRegionContext ctx) {
+    ShowRegionStatement showRegionStatement = new ShowRegionStatement();
+    // TODO: Maybe add a show partition region in the future
+    if (ctx.DATA() != null) {
+      showRegionStatement.setRegionType(TConsensusGroupType.DataRegion);
+    } else if (ctx.SCHEMA() != null) {
+      showRegionStatement.setRegionType(TConsensusGroupType.SchemaRegion);
+    } else {
+      showRegionStatement.setRegionType(null);
+    }
+    return showRegionStatement;
+  }
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/StatementVisitor.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/StatementVisitor.java
index 601ca5e260..7f28d05552 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/StatementVisitor.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/StatementVisitor.java
@@ -50,6 +50,7 @@ import 
org.apache.iotdb.db.mpp.plan.statement.metadata.ShowChildPathsStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowClusterStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowDevicesStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowFunctionsStatement;
+import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowRegionStatement;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.ShowStorageGroupStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowTTLStatement;
 import org.apache.iotdb.db.mpp.plan.statement.metadata.ShowTimeSeriesStatement;
@@ -251,4 +252,8 @@ public abstract class StatementVisitor<R, C> {
   public R visitFlush(FlushStatement flushStatement, C context) {
     return visitStatement(flushStatement, context);
   }
+
+  public R visitShowRegion(ShowRegionStatement showRegionStatement, C context) 
{
+    return visitStatement(showRegionStatement, context);
+  }
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/metadata/ShowRegionStatement.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/metadata/ShowRegionStatement.java
new file mode 100644
index 0000000000..42f690856b
--- /dev/null
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/metadata/ShowRegionStatement.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.plan.statement.metadata;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
+import org.apache.iotdb.db.mpp.plan.analyze.QueryType;
+import org.apache.iotdb.db.mpp.plan.statement.IConfigStatement;
+import org.apache.iotdb.db.mpp.plan.statement.StatementVisitor;
+
+public class ShowRegionStatement extends ShowStatement implements 
IConfigStatement {
+
+  public ShowRegionStatement() {}
+
+  public ShowRegionStatement(TConsensusGroupType regionType) {
+    this.regionType = regionType;
+  }
+
+  private TConsensusGroupType regionType;
+
+  public TConsensusGroupType getRegionType() {
+    return regionType;
+  }
+
+  public void setRegionType(TConsensusGroupType regionType) {
+    this.regionType = regionType;
+  }
+
+  @Override
+  public QueryType getQueryType() {
+    return QueryType.READ;
+  }
+
+  @Override
+  public <R, C> R accept(StatementVisitor<R, C> visitor, C context) {
+    return visitor.visitShowRegion(this, context);
+  }
+}
diff --git a/thrift-commons/src/main/thrift/common.thrift 
b/thrift-commons/src/main/thrift/common.thrift
index e314a6327a..b81273d0a5 100644
--- a/thrift-commons/src/main/thrift/common.thrift
+++ b/thrift-commons/src/main/thrift/common.thrift
@@ -77,6 +77,16 @@ struct TDataNodeLocation {
   6: required TEndPoint schemaRegionConsensusEndPoint
 }
 
+struct TRegionLocation {
+  1: required TConsensusGroupId consensusGroupId
+  2: required string storageGroup
+  3: required i32 dataNodeId;
+  4: required string rpcAddresss;
+  5: required i32 rpcPort;
+  6: required i64 slots;
+  7: optional string status;
+}
+
 struct THeartbeatReq {
   1: required i64 heartbeatTimestamp
 }
diff --git a/thrift-confignode/src/main/thrift/confignode.thrift 
b/thrift-confignode/src/main/thrift/confignode.thrift
index 05a1c548ea..9f4eb968c1 100644
--- a/thrift-confignode/src/main/thrift/confignode.thrift
+++ b/thrift-confignode/src/main/thrift/confignode.thrift
@@ -229,6 +229,16 @@ struct TDropFunctionReq {
   1: required string udfName
 }
 
+// show regions
+struct TShowRegionReq {
+  1: optional common.TConsensusGroupType consensusGroupType;
+}
+
+struct TShowRegionResp {
+  1: required common.TSStatus status
+  2: optional list<common.TRegionLocation> regionInfoList;
+}
+
 service ConfigIService {
 
   /* DataNode */
@@ -304,5 +314,9 @@ service ConfigIService {
 
   common.TSStatus flush(common.TFlushReq req)
 
+  /* Show Region */
+
+  TShowRegionResp showRegion(TShowRegionReq req)
+
 }
 

Reply via email to