ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [43/50] [abbrv] ignite git commit: IGNITE-2404: TcpDiscoverySpi.setLocalPortRange set 0 doesn't work. This closes #549 Reviewed and merged by Denis Magda (dmagda@gridgain.com)
Date Fri, 22 Apr 2016 12:30:25 GMT
IGNITE-2404: TcpDiscoverySpi.setLocalPortRange set 0 doesn't work. This closes #549
Reviewed and merged by Denis Magda (dmagda@gridgain.com)


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

Branch: refs/heads/ignite-db-x-10884
Commit: df21521930384f30007ac57d10637eec032e2053
Parents: a9d375e
Author: Ryan Zhao <ryan.zhao.cs@gmail.com>
Authored: Tue Apr 19 07:27:11 2016 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Tue Apr 19 07:27:11 2016 +0300

----------------------------------------------------------------------
 .../configuration/ConnectorConfiguration.java   |  3 ++
 .../configuration/IgniteConfiguration.java      |  3 ++
 .../processors/clock/GridClockServer.java       |  3 +-
 .../rest/protocols/tcp/GridTcpRestProtocol.java |  7 +++--
 .../communication/tcp/TcpCommunicationSpi.java  |  4 ++-
 .../ignite/spi/discovery/tcp/ServerImpl.java    | 32 ++++++++++----------
 .../spi/discovery/tcp/TcpDiscoverySpi.java      |  2 ++
 .../GridTcpCommunicationSpiConfigSelfTest.java  | 22 ++++++++++++++
 .../tcp/TcpDiscoverySpiConfigSelfTest.java      | 22 ++++++++++++++
 .../http/jetty/GridJettyRestProtocol.java       |  4 +--
 10 files changed, 79 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/df215219/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java
index 1bfcbe4..0ef5f86 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java
@@ -492,6 +492,9 @@ public class ConnectorConfiguration {
     /**
      * Gets number of ports to try if configured port is already in use.
      *
+     * If port range value is <tt>0</tt>, then implementation will try bind only
to the port provided by
+     * {@link #setPort(int)} method and fail if binding to this port did not succeed.
+     *
      * @return Number of ports to try.
      */
     public int getPortRange() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/df215219/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
index 1aa3920..e5bd05c 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
@@ -2178,6 +2178,9 @@ public class IgniteConfiguration {
     /**
      * Defines port range to try for time server start.
      *
+     * If port range value is <tt>0</tt>, then implementation will try bind only
to the port provided by
+     * {@link #setTimeServerPortBase(int)} method and fail if binding to this port did not
succeed.
+     *
      * @return Number of ports to try before server initialization fails.
      */
     public int getTimeServerPortRange() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/df215219/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockServer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockServer.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockServer.java
index b357e65..a1900c8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockServer.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockServer.java
@@ -64,7 +64,8 @@ public class GridClockServer {
 
         try {
             int startPort = ctx.config().getTimeServerPortBase();
-            int endPort = startPort + ctx.config().getTimeServerPortRange() - 1;
+            int portRange = ctx.config().getTimeServerPortRange();
+            int endPort = portRange == 0 ? startPort : startPort + portRange - 1;
 
             InetAddress locHost;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/df215219/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
index 8e08481..a4a51ea 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
@@ -134,10 +134,11 @@ public class GridTcpRestProtocol extends GridRestProtocolAdapter {
                 else
                     sslCtx = igniteFactory.create();
             }
+            int startPort = cfg.getPort();
+            int portRange = cfg.getPortRange();
+            int lastPort = portRange == 0 ? startPort : startPort + portRange - 1;
 
-            int lastPort = cfg.getPort() + cfg.getPortRange() - 1;
-
-            for (int port0 = cfg.getPort(); port0 <= lastPort; port0++) {
+            for (int port0 = startPort; port0 <= lastPort; port0++) {
                 if (startTcpServer(host, port0, lsnr, parser, sslCtx, cfg)) {
                     port = port0;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/df215219/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
index c0982bf..080437d 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
@@ -1591,7 +1591,9 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter
         IgniteCheckedException lastEx = null;
 
         // If configured TCP port is busy, find first available in range.
-        for (int port = locPort; port < locPort + locPortRange; port++) {
+        int lastPort = locPortRange == 0 ? locPort : locPort + locPortRange - 1;
+
+        for (int port = locPort; port <= lastPort; port++) {
             try {
                 MessageFactory msgFactory = new MessageFactory() {
                     private MessageFactory impl;

http://git-wip-us.apache.org/repos/asf/ignite/blob/df215219/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
----------------------------------------------------------------------
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 75430c6..572f540 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
@@ -4904,34 +4904,34 @@ class ServerImpl extends TcpDiscoveryImpl {
 
             setPriority(spi.threadPri);
 
-            for (port = spi.locPort; port < spi.locPort + spi.locPortRange; port++) {
+            int lastPort = spi.locPortRange == 0 ? spi.locPort : spi.locPort + spi.locPortRange
- 1;
+
+            for (port = spi.locPort; port <= lastPort; port++) {
                 try {
                     if (spi.isSslEnabled())
                         srvrSock = spi.sslSrvSockFactory.createServerSocket(port, 0, spi.locHost);
                     else
                         srvrSock = new ServerSocket(port, 0, spi.locHost);
 
-                    break;
+                    if (log.isInfoEnabled())
+                        log.info("Successfully bound to TCP port [port=" + port + ", localHost="
+ spi.locHost + ']');
+
+                    return;
                 }
                 catch (IOException e) {
-                    if (port < spi.locPort + spi.locPortRange - 1) {
-                        if (log.isDebugEnabled())
-                            log.debug("Failed to bind to local port (will try next port within
range) " +
-                                "[port=" + port + ", localHost=" + spi.locHost + ']');
+                    if (log.isDebugEnabled())
+                        log.debug("Failed to bind to local port (will try next port within
range) " +
+                            "[port=" + port + ", localHost=" + spi.locHost + ']');
 
-                        onException("Failed to bind to local port. " +
-                            "[port=" + port + ", localHost=" + spi.locHost + ']', e);
-                    }
-                    else {
-                        throw new IgniteSpiException("Failed to bind TCP server socket (possibly
all ports in range " +
-                            "are in use) [firstPort=" + spi.locPort + ", lastPort=" + (spi.locPort
+ spi.locPortRange - 1) +
-                            ", addr=" + spi.locHost + ']', e);
-                    }
+                    onException("Failed to bind to local port. " +
+                        "[port=" + port + ", localHost=" + spi.locHost + ']', e);
                 }
             }
 
-            if (log.isInfoEnabled())
-                log.info("Successfully bound to TCP port [port=" + port + ", localHost="
+ spi.locHost + ']');
+            // If free port wasn't found.
+            throw new IgniteSpiException("Failed to bind TCP server socket (possibly all
ports in range " +
+                "are in use) [firstPort=" + spi.locPort + ", lastPort=" + lastPort +
+                ", addr=" + spi.locHost + ']');
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/df215219/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
index d981609..4351c64 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
@@ -676,6 +676,8 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi,
T
      * Range for local ports. Local node will try to bind on first available port
      * starting from {@link #getLocalPort()} up until
      * <tt>{@link #getLocalPort()} {@code + locPortRange}</tt>.
+     * If port range value is <tt>0</tt>, then implementation will try bind only
to the port provided by
+     * {@link #setLocalPort(int)} method and fail if binding to this port did not succeed.
      * <p>
      * If not specified, default is {@link #DFLT_PORT_RANGE}.
      * <p>

http://git-wip-us.apache.org/repos/asf/ignite/blob/df215219/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
index 33944e4..b0353a6 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.ignite.spi.communication.tcp;
 
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.spi.GridSpiAbstractConfigTest;
 import org.apache.ignite.testframework.junits.spi.GridSpiTest;
 
@@ -45,4 +48,23 @@ public class GridTcpCommunicationSpiConfigSelfTest extends GridSpiAbstractConfig
         checkNegativeSpiProperty(new TcpCommunicationSpi(), "ackSendThreshold", -1);
         checkNegativeSpiProperty(new TcpCommunicationSpi(), "unacknowledgedMessagesBufferSize",
-1);
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLocalPortRange() throws Exception {
+        try {
+            IgniteConfiguration cfg = getConfiguration();
+
+            TcpCommunicationSpi spi = new TcpCommunicationSpi();
+
+            spi.setLocalPortRange(0);
+            cfg.setCommunicationSpi(spi);
+
+            startGrid(cfg.getGridName(), cfg);
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/df215219/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiConfigSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiConfigSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiConfigSelfTest.java
index bb5af60..24f47c9 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiConfigSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiConfigSelfTest.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.spi.discovery.tcp;
 
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.spi.GridSpiAbstractConfigTest;
 import org.apache.ignite.testframework.junits.spi.GridSpiTest;
 
@@ -43,4 +45,24 @@ public class TcpDiscoverySpiConfigSelfTest extends GridSpiAbstractConfigTest<Tcp
         checkNegativeSpiProperty(new TcpDiscoverySpi(), "maxMissedHeartbeats", 0);
         checkNegativeSpiProperty(new TcpDiscoverySpi(), "statisticsPrintFrequency", 0);
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLocalPortRange() throws Exception {
+        try {
+            IgniteConfiguration cfg = getConfiguration();
+
+            TcpDiscoverySpi spi = new TcpDiscoverySpi();
+
+            spi.setIpFinder(new TcpDiscoveryVmIpFinder(true));
+            spi.setLocalPortRange(0);
+            cfg.setDiscoverySpi(spi);
+
+            startGrid(cfg.getGridName(), cfg);
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/df215219/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
index ac49ef6..0440783 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
@@ -168,8 +168,8 @@ public class GridJettyRestProtocol extends GridRestProtocolAdapter {
         }
 
         int initPort = connector.getPort();
-
-        int lastPort = initPort + config().getPortRange() - 1;
+        int portRange = config().getPortRange();
+        int lastPort = portRange == 0 ? initPort : initPort + portRange - 1;
 
         for (port = initPort; port <= lastPort; port++) {
             connector.setPort(port);


Mime
View raw message