Skip to content
Permalink
Browse files
[IOTDB-3511] Show Region tool (#6315)
  • Loading branch information
RYH61 committed Jun 19, 2022
1 parent 1309eef commit 77563a627304031c0a0148c895e3ae9769b12117
Showing 32 changed files with 771 additions and 15 deletions.
@@ -60,6 +60,7 @@ keyWords
| CQ
| CQS
| CREATE
| DATA
| DEBUG
| DELETE
| DESC
@@ -126,6 +127,7 @@ keyWords
| QUERY
| READONLY
| REGEXP
| REGIONS
| REMOVE
| RENAME
| RESAMPLE
@@ -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
@@ -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
;
@@ -25,6 +25,7 @@
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 static ConfigRequest create(ByteBuffer buffer) throws IOException {
case GetNodePathsPartition:
req = new GetNodePathsPartitionReq();
break;
case GetRegionLocations:
req = new GetRegionLocationsReq();
break;
default:
throw new IOException("unknown PhysicalPlan type: " + typeNum);
}
@@ -61,5 +61,6 @@ public enum ConfigRequestType {
ApplyConfigNode,
CreateFunction,
DropFunction,
GetNodePathsPartition;
GetNodePathsPartition,
GetRegionLocations;
}
@@ -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)];
}
}
@@ -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;
}
}
@@ -37,6 +37,7 @@
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.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 UDFManager getUDFManager() {
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;
}
@@ -25,6 +25,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.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);
}
@@ -36,6 +36,7 @@
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 TSeriesPartitionSlot getSeriesPartitionSlot(String devicePath) {
return executor.getSeriesPartitionSlot(devicePath);
}

public DataSet getRetionLocations(GetRegionLocationsReq req) {
return getConsensusManager().read(req).getDataset();
}

public ScheduledExecutorService getRegionCleaner() {
return regionCleaner;
}
@@ -28,6 +28,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.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 DataSet executorQueryPlan(ConfigRequest req)
return authorInfo.executeListRoleUsers((AuthorReq) req);
case GetNodePathsPartition:
return getSchemaNodeManagementPartition(req);
case GetRegionLocations:
return partitionInfo.getRegionLocations((GetRegionLocationsReq) req);
default:
throw new UnknownPhysicalPlanTypeException(req.getType());
}
@@ -22,6 +22,7 @@
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.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.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.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.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 DataSet getSchemaNodeManagementPartition(List<String> matchedStorageGroup
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 @@ private int updateRegionMetric(TConsensusGroupType type) {
return result;
}

@Override
public boolean processTakeSnapshot(File snapshotDir) throws TException, IOException {

File snapshotFile = new File(snapshotDir, snapshotFileName);

0 comments on commit 77563a6

Please sign in to comment.