This is an automated email from the ASF dual-hosted git repository.

alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new cb02fe2f0b0 IGNITE-22573 Fix warnings of IpFinderCleaner - Fixes 
#11637.
cb02fe2f0b0 is described below

commit cb02fe2f0b0c2d84c76ac7ee1c365518c42cada8
Author: Julia Bakulina <[email protected]>
AuthorDate: Thu Nov 14 20:21:02 2024 +0300

    IGNITE-22573 Fix warnings of IpFinderCleaner - Fixes #11637.
    
    Signed-off-by: Aleksey Plekhanov <[email protected]>
---
 .../ignite/spi/discovery/tcp/ServerImpl.java       | 46 ++++++++++++++--------
 .../spi/discovery/tcp/TcpDiscoverySelfTest.java    | 33 +++++++++++++++-
 2 files changed, 61 insertions(+), 18 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
index fb62c61f96f..23fb86cc595 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
@@ -788,7 +788,7 @@ class ServerImpl extends TcpDiscoveryImpl {
         for (InetSocketAddress addr : spi.getEffectiveNodeAddresses(node)) {
             try {
                 // ID returned by the node should be the same as ID of the 
parameter for ping to succeed.
-                IgniteBiTuple<UUID, Boolean> t = pingNode(addr, node.id(), 
clientNodeId, 0);
+                IgniteBiTuple<UUID, Boolean> t = pingNode(addr, node.id(), 
clientNodeId, 0, true);
 
                 if (t == null)
                     // Remote node left topology.
@@ -820,6 +820,7 @@ class ServerImpl extends TcpDiscoveryImpl {
      * @param nodeId Node ID to ping. In case when client node ID is not null 
this node ID is an ID of the router node.
      * @param clientNodeId Client node ID.
      * @param timeout Timeout on operation in milliseconds. If 0, a value 
based on {@link TcpDiscoverySpi} is used.
+     * @param logError Boolean flag indicating whether information should be 
printed into the node log.
      * @return ID of the remote node and "client exists" flag if node alive or 
{@code null} if the remote node has
      *         left a topology during the ping process.
      * @throws IgniteCheckedException If an error occurs.
@@ -828,7 +829,8 @@ class ServerImpl extends TcpDiscoveryImpl {
         InetSocketAddress addr,
         @Nullable UUID nodeId,
         @Nullable UUID clientNodeId,
-        long timeout
+        long timeout,
+        boolean logError
     ) throws IgniteCheckedException {
         assert addr != null;
         assert timeout >= 0;
@@ -913,9 +915,11 @@ class ServerImpl extends TcpDiscoveryImpl {
                         return t;
                     }
                     catch (IOException | IgniteCheckedException e) {
+                        String errMsgPrefix = "Failed to ping node [nodeId=" + 
nodeId + ", address=" + addr + "]. ";
+
                         if (nodeId != null && !nodeAlive(nodeId)) {
-                            log.warning("Failed to ping node [nodeId=" + 
nodeId + "]. Node has left or is " +
-                                "leaving topology. Cause: " + e.getMessage());
+                            logPingError(errMsgPrefix + "Node has left or is 
leaving topology. " +
+                                "Cause: " + e.getMessage(), logError);
 
                             fut.onDone((IgniteBiTuple<UUID, Boolean>)null);
 
@@ -930,29 +934,30 @@ class ServerImpl extends TcpDiscoveryImpl {
                         reconCnt++;
 
                         if (!openedSock && reconCnt == 2) {
-                            log.warning("Failed to ping node [nodeId=" + 
nodeId + "]. Was unable to open the " +
-                                "socket at all. Cause: " + e.getMessage());
+                            logPingError(errMsgPrefix + "Was unable to open 
the socket at all. " +
+                                "Cause: " + e.getMessage(), logError);
 
                             break;
                         }
 
                         if 
(IgniteSpiOperationTimeoutHelper.checkFailureTimeoutReached(e)
                             && (spi.failureDetectionTimeoutEnabled() || 
timeout != 0)) {
-                            log.warning("Failed to ping node [nodeId=" + 
nodeId + "]. Reached the timeout " +
-                                (timeout == 0 ? spi.failureDetectionTimeout() 
: timeout) + "ms. Cause: " + e.getMessage());
+                            logPingError(errMsgPrefix + "Reached the timeout " 
+
+                                (timeout == 0 ? spi.failureDetectionTimeout() 
: timeout) +
+                                "ms. Cause: " + e.getMessage(), logError);
 
                             break;
                         }
                         else if (!spi.failureDetectionTimeoutEnabled() && 
reconCnt == spi.getReconnectCount()) {
-                            log.warning("Failed to ping node [nodeId=" + 
nodeId + "]. Reached the reconnection " +
-                                "count " + spi.getReconnectCount() + ". Cause: 
" + e.getMessage());
+                            logPingError(errMsgPrefix + "Reached the 
reconnection count spi.getReconnectCount(). " +
+                                "Cause: " + e.getMessage(), logError);
 
                             break;
                         }
 
                         if (spi.isNodeStopping0()) {
-                            log.warning("Failed to ping node [nodeId=" + 
nodeId + "]. Current node is " +
-                                "stopping. Cause: " + e.getMessage());
+                            logPingError(errMsgPrefix + "Current node is 
stopping. " +
+                                "Cause: " + e.getMessage(), logError);
 
                             break;
                         }
@@ -983,6 +988,14 @@ class ServerImpl extends TcpDiscoveryImpl {
         }
     }
 
+    /** */
+    private void logPingError(String msg, boolean logError) {
+        if (logError)
+            log.warning(msg);
+        else if (log.isDebugEnabled())
+            log.debug(msg);
+    }
+
     /**
      * Interrupts all existed 'ping' request for the given node.
      *
@@ -2272,7 +2285,7 @@ class ServerImpl extends TcpDiscoveryImpl {
 
                         if (res == null) {
                             try {
-                                res = pingNode(addr, null, null, 0) != null;
+                                res = pingNode(addr, null, null, 0, false) != 
null;
                             }
                             catch (IgniteCheckedException e) {
                                 if (log.isDebugEnabled())
@@ -7294,7 +7307,7 @@ class ServerImpl extends TcpDiscoveryImpl {
          * @param node Node to ping.
          * @param timeout Overall operation timeout.
          * @return An address successfully connected to. {@code Null} if no 
alive address was detected within the timeout.
-         * @see #pingNode(InetSocketAddress, UUID, UUID, long)
+         * @see #pingNode(InetSocketAddress, UUID, UUID, long, boolean)
          */
         private InetSocketAddress checkConnection(TcpDiscoveryNode node, int 
timeout) {
             IgniteSpiOperationTimeoutHelper timeoutHelper = new 
IgniteSpiOperationTimeoutHelper(timeout);
@@ -7330,7 +7343,8 @@ class ServerImpl extends TcpDiscoveryImpl {
 
                             try {
                                 if (liveAddrHolder.get() == null) {
-                                    UUID id = pingNode(addr, node.id(), null, 
timeoutHelper.nextTimeoutChunk(perAddrTimeout)).get1();
+                                    UUID id = pingNode(addr, node.id(), null, 
timeoutHelper.nextTimeoutChunk(perAddrTimeout),
+                                        true).get1();
 
                                     assert id == null || id.equals(node.id());
 
@@ -7573,7 +7587,7 @@ class ServerImpl extends TcpDiscoveryImpl {
             for (InetSocketAddress addr : spi.getEffectiveNodeAddresses(node)) 
{
                 try {
                     if (!(addr.getAddress().isLoopbackAddress() && 
locNode.socketAddresses().contains(addr))) {
-                        IgniteBiTuple<UUID, Boolean> t = pingNode(addr, 
node.id(), null, 0);
+                        IgniteBiTuple<UUID, Boolean> t = pingNode(addr, 
node.id(), null, 0, true);
 
                         if (t != null)
                             return true;
diff --git 
a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
index 10abda36e48..0e270ea5ca5 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
@@ -38,6 +38,7 @@ import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Pattern;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
@@ -136,6 +137,9 @@ public class TcpDiscoverySelfTest extends 
GridCommonAbstractTest {
     /** */
     private SegmentationPolicy segPlc;
 
+    /** */
+    private ListeningTestLogger testLog;
+
     /**
      * @throws Exception If fails.
      */
@@ -200,6 +204,12 @@ public class TcpDiscoverySelfTest extends 
GridCommonAbstractTest {
         if (nodeId != null)
             cfg.setNodeId(nodeId);
 
+        if (testLog != null) {
+            cfg.setGridLogger(testLog);
+
+            testLog = null;
+        }
+
         if (igniteInstanceName.contains("NonSharedIpFinder")) {
             TcpDiscoveryVmIpFinder finder = new TcpDiscoveryVmIpFinder();
 
@@ -2201,6 +2211,23 @@ public class TcpDiscoverySelfTest extends 
GridCommonAbstractTest {
      */
     @Test
     public void testFailedNodeRestoreConnection() throws Exception {
+        checkRestoreConnection(false);
+
+        setLoggerDebugLevel();
+
+        checkRestoreConnection(true);
+    }
+
+    /** @throws Exception If failed.*/
+    private void checkRestoreConnection(boolean logMsgExpected) throws 
Exception {
+        testLog = new ListeningTestLogger(log);
+
+        LogListener lsnr = LogListener
+            .matches(Pattern.compile("Failed to ping node \\[.*\\]\\. Reached 
the timeout"))
+            .build();
+
+        testLog.registerListener(lsnr);
+
         try {
             TestRestoreConnectedSpi.startTest = false;
 
@@ -2231,6 +2258,8 @@ public class TcpDiscoverySelfTest extends 
GridCommonAbstractTest {
                     assertEquals(3, node.cluster().nodes().size());
                 }
             }
+
+            assertEquals(logMsgExpected, lsnr.check());
         }
         finally {
             stopAllGrids();
@@ -2244,7 +2273,7 @@ public class TcpDiscoverySelfTest extends 
GridCommonAbstractTest {
     public void testCheckRingLatency() throws Exception {
         int hops = 1;
 
-        ListeningTestLogger testLog = new ListeningTestLogger(log);
+        testLog = new ListeningTestLogger(log);
 
         // We should discard ring check latency on server node.
         LogListener lsnr = LogListener.matches("Latency check has been 
discarded").times(hops).build();
@@ -2252,7 +2281,7 @@ public class TcpDiscoverySelfTest extends 
GridCommonAbstractTest {
         testLog.registerListener(lsnr);
 
         try {
-            IgniteEx node = 
startGrid(getConfiguration("server").setGridLogger(testLog));
+            IgniteEx node = startGrid(getConfiguration("server"));
 
             startGrid(getConfiguration("client").setClientMode(true));
 

Reply via email to