Skip to content

Commit b638a70

Browse files
authored
Pipe: Reduce the frequency of printing logs when AirGapConnector connection fails (apache#14949)
1 parent 56080ee commit b638a70

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/connector/protocol/IoTDBAirGapConnector.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
import java.net.SocketException;
4646
import java.util.ArrayList;
4747
import java.util.Arrays;
48+
import java.util.HashMap;
4849
import java.util.List;
50+
import java.util.Map;
4951
import java.util.zip.CRC32;
5052

5153
import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.CONNECTOR_AIR_GAP_E_LANGUAGE_ENABLE_DEFAULT_VALUE;
@@ -98,6 +100,8 @@ public String toString() {
98100
// The air gap connector does not use clientManager thus we put handshake type here
99101
protected boolean supportModsIfIsDataNodeReceiver = true;
100102

103+
private final Map<TEndPoint, Long> failLogTimes = new HashMap<>();
104+
101105
@Override
102106
public void customize(
103107
final PipeParameters parameters, final PipeConnectorRuntimeConfiguration configuration)
@@ -180,12 +184,19 @@ public void handshake() throws Exception {
180184
socket.setKeepAlive(true);
181185
sockets.set(i, socket);
182186
LOGGER.info("Successfully connected to target server ip: {}, port: {}.", ip, port);
187+
failLogTimes.remove(nodeUrls.get(i));
183188
} catch (final Exception e) {
184-
LOGGER.warn(
185-
"Failed to connect to target server ip: {}, port: {}, because: {}. Ignore it.",
186-
ip,
187-
port,
188-
e.getMessage());
189+
final TEndPoint endPoint = nodeUrls.get(i);
190+
final long currentTimeMillis = System.currentTimeMillis();
191+
final Long lastFailLogTime = failLogTimes.get(endPoint);
192+
if (lastFailLogTime == null || currentTimeMillis - lastFailLogTime > 60000) {
193+
failLogTimes.put(endPoint, currentTimeMillis);
194+
LOGGER.warn(
195+
"Failed to connect to target server ip: {}, port: {}, because: {}. Ignore it.",
196+
ip,
197+
port,
198+
e.getMessage());
199+
}
189200
continue;
190201
}
191202

0 commit comments

Comments
 (0)