From 11c216bb3c8096cb774381b9e3bb906eaeb9e0be Mon Sep 17 00:00:00 2001 From: Zhenyu Luo Date: Thu, 27 Feb 2025 14:46:01 +0800 Subject: [PATCH] Pipe: Reduce the frequency of printing logs when AirGapConnector connection fails (#14949) (cherry picked from commit b638a70a4cc8de3ed33cc42bae12f9e259d61518) --- .../protocol/IoTDBAirGapConnector.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/connector/protocol/IoTDBAirGapConnector.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/connector/protocol/IoTDBAirGapConnector.java index c44461903d47f..01fcd45ffba11 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/connector/protocol/IoTDBAirGapConnector.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/connector/protocol/IoTDBAirGapConnector.java @@ -43,7 +43,9 @@ import java.net.SocketException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.zip.CRC32; import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.CONNECTOR_AIR_GAP_E_LANGUAGE_ENABLE_DEFAULT_VALUE; @@ -94,6 +96,8 @@ public String toString() { // The air gap connector does not use clientManager thus we put handshake type here protected boolean supportModsIfIsDataNodeReceiver = true; + private final Map failLogTimes = new HashMap<>(); + @Override public void customize( final PipeParameters parameters, final PipeConnectorRuntimeConfiguration configuration) @@ -176,12 +180,19 @@ public void handshake() throws Exception { socket.setKeepAlive(true); sockets.set(i, socket); LOGGER.info("Successfully connected to target server ip: {}, port: {}.", ip, port); + failLogTimes.remove(nodeUrls.get(i)); } catch (final Exception e) { - LOGGER.warn( - "Failed to connect to target server ip: {}, port: {}, because: {}. Ignore it.", - ip, - port, - e.getMessage()); + final TEndPoint endPoint = nodeUrls.get(i); + final long currentTimeMillis = System.currentTimeMillis(); + final Long lastFailLogTime = failLogTimes.get(endPoint); + if (lastFailLogTime == null || currentTimeMillis - lastFailLogTime > 60000) { + failLogTimes.put(endPoint, currentTimeMillis); + LOGGER.warn( + "Failed to connect to target server ip: {}, port: {}, because: {}. Ignore it.", + ip, + port, + e.getMessage()); + } continue; }