Skip to content

Commit b4644ba

Browse files
authored
fix: improve DataNode reachability check in ensureNodeStatus (#17446)
1 parent 2e77bf4 commit b4644ba

File tree

1 file changed

+23
-4
lines changed
  • integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env

1 file changed

+23
-4
lines changed

integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@
7070
import org.apache.iotdb.session.pool.SessionPool;
7171
import org.apache.iotdb.session.pool.TableSessionPoolBuilder;
7272

73+
import org.apache.thrift.TConfiguration;
7374
import org.apache.thrift.TException;
75+
import org.apache.thrift.transport.TSocket;
7476
import org.apache.thrift.transport.TTransportException;
7577
import org.slf4j.Logger;
7678

@@ -1402,7 +1404,7 @@ public void shutdownForciblyAllDataNodes() {
14021404

14031405
@Override
14041406
public void ensureNodeStatus(
1405-
final List<BaseNodeWrapper> nodes, final List<NodeStatus> targetStatus)
1407+
final List<BaseNodeWrapper> nodes, final List<NodeStatus> targetStatusList)
14061408
throws IllegalStateException {
14071409
Throwable lastException = null;
14081410
for (int i = 0; i < retryCount; i++) {
@@ -1430,20 +1432,37 @@ public void ensureNodeStatus(
14301432
+ node.getClientRpcEndPoint().getPort(),
14311433
node.getDataNodeId()));
14321434
for (int j = 0; j < nodes.size(); j++) {
1433-
final String endpoint = nodes.get(j).getIpAndPortString();
1435+
BaseNodeWrapper nodeWrapper = nodes.get(j);
1436+
String ipAndPortString = nodeWrapper.getIpAndPortString();
1437+
final String endpoint = ipAndPortString;
14341438
if (!nodeIds.containsKey(endpoint)) {
14351439
// Node not exist
14361440
// Notice: Never modify this line, since the NodeLocation might be modified in IT
14371441
errorMessages.add("The node " + nodes.get(j).getIpAndPortString() + " is not found!");
14381442
continue;
14391443
}
14401444
final String status = showClusterResp.getNodeStatus().get(nodeIds.get(endpoint));
1441-
if (!targetStatus.get(j).getStatus().equals(status)) {
1445+
final NodeStatus targetStatus = targetStatusList.get(j);
1446+
if (!targetStatus.getStatus().equals(status)) {
14421447
// Error status
14431448
errorMessages.add(
14441449
String.format(
14451450
"Node %s is in status %s, but expected %s",
1446-
endpoint, status, targetStatus.get(j)));
1451+
endpoint, status, targetStatusList.get(j)));
1452+
continue;
1453+
}
1454+
if (nodeWrapper instanceof DataNodeWrapper && targetStatus.equals(NodeStatus.Running)) {
1455+
final String[] ipPort = nodeWrapper.getIpAndPortString().split(":");
1456+
final String ip = ipPort[0];
1457+
final int port = Integer.parseInt(ipPort[1]);
1458+
try (TSocket socket = new TSocket(new TConfiguration(), ip, port, 1000)) {
1459+
socket.open();
1460+
} catch (final TTransportException e) {
1461+
errorMessages.add(
1462+
String.format(
1463+
"DataNode %s is not reachable: %s",
1464+
nodeWrapper.getIpAndPortString(), e.getMessage()));
1465+
}
14471466
}
14481467
}
14491468
if (errorMessages.isEmpty()) {

0 commit comments

Comments
 (0)