You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/02/24 06:59:37 UTC

[09/10] ignite git commit: Fix for TcpDiscoverySharedFsIpFinder to work with IPv6 addresses. - Fixes #495.

Fix for TcpDiscoverySharedFsIpFinder to work with IPv6 addresses. - Fixes #495.

Signed-off-by: shtykh_roman <rs...@yahoo.com>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/41a8e7e1
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/41a8e7e1
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/41a8e7e1

Branch: refs/heads/ignite-1232
Commit: 41a8e7e185d984715dd98bcc8d3cc0c415b8f2e1
Parents: eb5bce2
Author: shtykh_roman <rs...@yahoo.com>
Authored: Wed Feb 24 11:54:17 2016 +0900
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Wed Feb 24 11:54:17 2016 +0900

----------------------------------------------------------------------
 .../sharedfs/TcpDiscoverySharedFsIpFinder.java  | 35 +++++++++++++++++---
 .../TcpDiscoveryIpFinderAbstractSelfTest.java   | 15 +++++----
 2 files changed, 40 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/41a8e7e1/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/sharedfs/TcpDiscoverySharedFsIpFinder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/sharedfs/TcpDiscoverySharedFsIpFinder.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/sharedfs/TcpDiscoverySharedFsIpFinder.java
index 596d93f..e7fde76 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/sharedfs/TcpDiscoverySharedFsIpFinder.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/sharedfs/TcpDiscoverySharedFsIpFinder.java
@@ -71,6 +71,12 @@ public class TcpDiscoverySharedFsIpFinder extends TcpDiscoveryIpFinderAdapter {
     /** Delimiter to use between address and port tokens in file names. */
     public static final String DELIM = "#";
 
+    /** IPv6 colon delimiter. */
+    private static final String COLON_DELIM = ":";
+
+    /** IPv6 colon substitute. */
+    private static final String COLON_SUBST = "_";
+
     /** Grid logger. */
     @LoggerResource
     private IgniteLogger log;
@@ -198,7 +204,7 @@ public class TcpDiscoverySharedFsIpFinder extends TcpDiscoveryIpFinderAdapter {
                     try {
                         int port = Integer.parseInt(portStr);
 
-                        addr = new InetSocketAddress(addrStr, port);
+                        addr = new InetSocketAddress(denormalizeAddress(addrStr), port);
                     }
                     catch (IllegalArgumentException e) {
                         U.error(log, "Failed to parse file entry: " + fileName, e);
@@ -240,7 +246,8 @@ public class TcpDiscoverySharedFsIpFinder extends TcpDiscoveryIpFinderAdapter {
             for (InetSocketAddress addr : addrs) {
                 File file = new File(folder, name(addr));
 
-                file.delete();
+                if (!file.delete())
+                    throw new IgniteSpiException("Failed to delete file " + file.getName());
             }
         }
         catch (SecurityException e) {
@@ -259,15 +266,35 @@ public class TcpDiscoverySharedFsIpFinder extends TcpDiscoveryIpFinderAdapter {
 
         SB sb = new SB();
 
-        sb.a(addr.getAddress().getHostAddress())
+        sb.a(normalizeAddress(addr.getAddress().getHostAddress()))
             .a(DELIM)
             .a(addr.getPort());
 
         return sb.toString();
     }
 
+    /**
+     * Normalizes the host address by substituting colon delimiter with underscore.
+     *
+     * @param hostAddress Host address.
+     * @return Normalized host address that can be safely used in file names.
+     */
+    private String normalizeAddress(String hostAddress){
+        return hostAddress.replaceAll(COLON_DELIM, COLON_SUBST);
+    }
+
+    /**
+     * Reverts changes done with {@link TcpDiscoverySharedFsIpFinder#normalizeAddress}.
+     *
+     * @param hostAddress Host address.
+     * @return Standard host address.
+     */
+    private String denormalizeAddress(String hostAddress){
+        return hostAddress.replaceAll(COLON_SUBST, COLON_DELIM);
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(TcpDiscoverySharedFsIpFinder.class, this);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/41a8e7e1/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/TcpDiscoveryIpFinderAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/TcpDiscoveryIpFinderAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/TcpDiscoveryIpFinderAbstractSelfTest.java
index 06aadda..6f2201f 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/TcpDiscoveryIpFinderAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/TcpDiscoveryIpFinderAbstractSelfTest.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.spi.discovery.tcp.ipfinder;
 
 import java.lang.reflect.Field;
+import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.util.Arrays;
@@ -61,8 +62,10 @@ public abstract class TcpDiscoveryIpFinderAbstractSelfTest<T extends TcpDiscover
 
         InetSocketAddress node1 = new InetSocketAddress(InetAddress.getLocalHost(), 1000);
         InetSocketAddress node2 = new InetSocketAddress(InetAddress.getLocalHost(), 1001);
+        InetSocketAddress node3 = new InetSocketAddress(
+            Inet6Address.getByName("2001:0db8:85a3:08d3:1319:47ff:fe3b:7fd3"), 1002);
 
-        List<InetSocketAddress> initAddrs = Arrays.asList(node1, node2);
+        List<InetSocketAddress> initAddrs = Arrays.asList(node1, node2, node3);
 
         finder.registerAddresses(Collections.singletonList(node1));
 
@@ -70,13 +73,13 @@ public abstract class TcpDiscoveryIpFinderAbstractSelfTest<T extends TcpDiscover
 
         Collection<InetSocketAddress> addrs = finder.getRegisteredAddresses();
 
-        for (int i = 0; i < 5 && addrs.size() != 2; i++) {
+        for (int i = 0; i < 5 && addrs.size() != 3; i++) {
             U.sleep(1000);
 
             addrs = finder.getRegisteredAddresses();
         }
 
-        assertEquals("Wrong collection size", 2, addrs.size());
+        assertEquals("Wrong collection size", 3, addrs.size());
 
         for (InetSocketAddress addr : initAddrs)
             assert addrs.contains(addr) : "Address is missing (got inconsistent addrs collection): " + addr;
@@ -85,13 +88,13 @@ public abstract class TcpDiscoveryIpFinderAbstractSelfTest<T extends TcpDiscover
 
         addrs = finder.getRegisteredAddresses();
 
-        for (int i = 0; i < 5 && addrs.size() != 1; i++) {
+        for (int i = 0; i < 5 && addrs.size() != 2; i++) {
             U.sleep(1000);
 
             addrs = finder.getRegisteredAddresses();
         }
 
-        assertEquals("Wrong collection size", 1, addrs.size());
+        assertEquals("Wrong collection size", 2, addrs.size());
 
         finder.unregisterAddresses(finder.getRegisteredAddresses());
 
@@ -125,4 +128,4 @@ public abstract class TcpDiscoveryIpFinderAbstractSelfTest<T extends TcpDiscover
      * @throws Exception If any error occurs.
      */
     protected abstract T ipFinder() throws Exception;
-}
\ No newline at end of file
+}