Skip to content

Commit d799098

Browse files
[To dev/1.3] Enhance "remove region" sql to handle the case of DataNode not exist (#15744)
* Enhance "remove region" sql to handle the case of DataNode not exist (#15728) * finish --------- Co-authored-by: Li Yu Heng <liyuheng55555@126.com>
1 parent 0dd2f8c commit d799098

4 files changed

Lines changed: 45 additions & 18 deletions

File tree

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

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
2424
import org.apache.iotdb.common.rpc.thrift.TDataNodeConfiguration;
2525
import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
26+
import org.apache.iotdb.common.rpc.thrift.TEndPoint;
2627
import org.apache.iotdb.common.rpc.thrift.TSStatus;
2728
import org.apache.iotdb.commons.cluster.NodeStatus;
2829
import org.apache.iotdb.commons.conf.CommonConfig;
@@ -136,6 +137,8 @@
136137
import org.slf4j.Logger;
137138
import org.slf4j.LoggerFactory;
138139

140+
import javax.annotation.Nullable;
141+
139142
import java.io.IOException;
140143
import java.nio.ByteBuffer;
141144
import java.util.ArrayList;
@@ -778,15 +781,11 @@ private TSStatus checkExtendRegion(
778781
private TSStatus checkRemoveRegion(
779782
TRemoveRegionReq req,
780783
TConsensusGroupId regionId,
781-
TDataNodeLocation targetDataNode,
784+
@Nullable TDataNodeLocation targetDataNode,
782785
TDataNodeLocation coordinator) {
783786
String failMessage =
784787
regionOperationCommonCheck(
785-
regionId,
786-
targetDataNode,
787-
Arrays.asList(
788-
new Pair<>("Target DataNode", targetDataNode),
789-
new Pair<>("Coordinator", coordinator)));
788+
regionId, targetDataNode, Arrays.asList(new Pair<>("Coordinator", coordinator)));
790789

791790
ConfigNodeConfig conf = ConfigNodeDescriptor.getInstance().getConf();
792791
if (configManager
@@ -796,11 +795,12 @@ private TSStatus checkRemoveRegion(
796795
.getDataNodeLocationsSize()
797796
== 1) {
798797
failMessage = String.format("%s only has 1 replica, it cannot be removed", regionId);
799-
} else if (configManager
800-
.getPartitionManager()
801-
.getAllReplicaSets(targetDataNode.getDataNodeId())
802-
.stream()
803-
.noneMatch(replicaSet -> replicaSet.getRegionId().equals(regionId))) {
798+
} else if (targetDataNode != null
799+
&& configManager
800+
.getPartitionManager()
801+
.getAllReplicaSets(targetDataNode.getDataNodeId())
802+
.stream()
803+
.noneMatch(replicaSet -> replicaSet.getRegionId().equals(regionId))) {
804804
failMessage =
805805
String.format(
806806
"Target DataNode %s doesn't contain Region %s", req.getDataNodeId(), regionId);
@@ -1131,6 +1131,23 @@ public TSStatus removeRegion(TRemoveRegionReq req) {
11311131
return status;
11321132
}
11331133

1134+
// SPECIAL CASE
1135+
if (targetDataNode == null) {
1136+
// If targetDataNode is null, it means the target DataNode does not exist in the
1137+
// NodeManager.
1138+
// In this case, simply clean up the partition table once and do nothing else.
1139+
LOGGER.warn(
1140+
"Remove region: Target DataNode {} not found, will simply clean up the partition table of region {} and do nothing else.",
1141+
req.getDataNodeId(),
1142+
req.getRegionId());
1143+
this.executor
1144+
.getEnvironment()
1145+
.getRegionMaintainHandler()
1146+
.removeRegionLocation(
1147+
regionId, buildFakeDataNodeLocation(req.getDataNodeId(), "FakeIpForRemoveRegion"));
1148+
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
1149+
}
1150+
11341151
// submit procedure
11351152
RemoveRegionPeerProcedure procedure =
11361153
new RemoveRegionPeerProcedure(regionId, coordinator, targetDataNode);
@@ -1142,6 +1159,12 @@ public TSStatus removeRegion(TRemoveRegionReq req) {
11421159
}
11431160
}
11441161

1162+
private static TDataNodeLocation buildFakeDataNodeLocation(int dataNodeId, String message) {
1163+
TEndPoint fakeEndPoint = new TEndPoint(message, -1);
1164+
return new TDataNodeLocation(
1165+
dataNodeId, fakeEndPoint, fakeEndPoint, fakeEndPoint, fakeEndPoint, fakeEndPoint);
1166+
}
1167+
11451168
// endregion
11461169

11471170
/**

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/DatabasePartitionTable.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ void addRegionNewLocation(TConsensusGroupId regionId, TDataNodeLocation node) {
538538
regionGroup.addRegionLocation(node);
539539
}
540540

541-
void removeRegionLocation(TConsensusGroupId regionId, TDataNodeLocation node) {
541+
void removeRegionLocation(TConsensusGroupId regionId, int nodeId) {
542542
RegionGroup regionGroup = regionGroupMap.get(regionId);
543543
if (regionGroup == null) {
544544
LOGGER.warn(
@@ -547,16 +547,18 @@ void removeRegionLocation(TConsensusGroupId regionId, TDataNodeLocation node) {
547547
databaseName);
548548
return;
549549
}
550-
if (!regionGroup.getReplicaSet().getDataNodeLocations().contains(node)) {
550+
if (regionGroup.getReplicaSet().getDataNodeLocations().stream()
551+
.map(TDataNodeLocation::getDataNodeId)
552+
.noneMatch(id -> id == nodeId)) {
551553
LOGGER.info(
552554
"Node is not in region locations when removeRegionOldLocation in {}, "
553555
+ "no need to remove it, node: {}, region: {}",
554556
databaseName,
555-
node,
557+
nodeId,
556558
regionId);
557559
return;
558560
}
559-
regionGroup.removeRegionLocation(node);
561+
regionGroup.removeRegionLocation(nodeId);
560562
}
561563

562564
/**

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ public TSStatus removeRegionLocation(RemoveRegionLocationPlan req) {
611611
.forEach(
612612
databasePartitionTable ->
613613
databasePartitionTable.removeRegionLocation(
614-
req.getRegionId(), req.getDeprecatedLocation()));
614+
req.getRegionId(), req.getDeprecatedLocation().getDataNodeId()));
615615
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
616616
}
617617

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/RegionGroup.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ public synchronized void addRegionLocation(TDataNodeLocation node) {
9595
replicaSet.getDataNodeLocations().sort(TDataNodeLocation::compareTo);
9696
}
9797

98-
public synchronized void removeRegionLocation(TDataNodeLocation node) {
99-
replicaSet.getDataNodeLocations().remove(node);
98+
public synchronized void removeRegionLocation(int nodeId) {
99+
replicaSet
100+
.getDataNodeLocations()
101+
.removeIf(tDataNodeLocation -> nodeId == tDataNodeLocation.getDataNodeId());
100102
replicaSet.getDataNodeLocations().sort(TDataNodeLocation::compareTo);
101103
}
102104

0 commit comments

Comments
 (0)