ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject [13/13] ignite git commit: GG-11124 Fixed
Date Fri, 29 Apr 2016 17:02:00 GMT
GG-11124 Fixed


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

Branch: refs/heads/ignite-db-x-gg-11124
Commit: 717939ab80ed07541184f475b4ab1ad4ebdae08a
Parents: edb1692
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Fri Apr 29 20:01:27 2016 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Fri Apr 29 20:01:27 2016 +0300

----------------------------------------------------------------------
 .../internal/managers/GridManagerAdapter.java   | 37 ++++++++--
 .../discovery/GridDiscoveryManager.java         | 21 ++++++
 .../org/apache/ignite/spi/IgniteSpiAdapter.java |  9 +++
 .../ignite/spi/discovery/DiscoverySpi.java      | 10 ++-
 .../ignite/spi/discovery/tcp/ServerImpl.java    | 11 ++-
 .../spi/discovery/tcp/TcpDiscoveryImpl.java     | 10 +++
 .../spi/discovery/tcp/TcpDiscoverySpi.java      | 74 ++++++++++++++------
 7 files changed, 145 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/717939ab/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
index 21a80c3..15016d6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
@@ -84,6 +84,9 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements
GridMan
     /** Checks is SPI implementation is {@code NO-OP} or not. */
     private final boolean enabled;
 
+    /** */
+    private boolean injected;
+
     /**
      * @param ctx Kernal context.
      * @param spis Specific SPI instance.
@@ -201,12 +204,13 @@ public abstract class GridManagerAdapter<T extends IgniteSpi>
implements GridMan
     }
 
     /**
-     * Starts wrapped SPI.
+     * Injects resources to SPI.
      *
-     * @throws IgniteCheckedException If wrapped SPI could not be started.
+     * @throws IgniteCheckedException
      */
-    protected final void startSpi() throws IgniteCheckedException {
-        Collection<String> names = U.newHashSet(spis.length);
+    protected void inject() throws IgniteCheckedException {
+        if (injected)
+            return;
 
         for (T spi : spis) {
             // Inject all spi resources.
@@ -214,6 +218,27 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements
GridMan
 
             // Inject SPI internal objects.
             inject(spi);
+        }
+
+        injected = true;
+    }
+
+    /**
+     * Starts wrapped SPI.
+     *
+     * @throws IgniteCheckedException If wrapped SPI could not be started.
+     */
+    protected final void startSpi() throws IgniteCheckedException {
+        Collection<String> names = U.newHashSet(spis.length);
+
+        for (T spi : spis) {
+            if (!injected) {
+                // Inject all spi resources.
+                ctx.resource().inject(spi);
+
+                // Inject SPI internal objects.
+                inject(spi);
+            }
 
             try {
                 Map<String, Object> retval = spi.getNodeAttributes();
@@ -263,6 +288,8 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements
GridMan
             if (log.isDebugEnabled())
                 log.debug("SPI module started OK: " + spi.getClass().getName());
         }
+
+        injected = true;
     }
 
     /**
@@ -629,4 +656,4 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements
GridMan
     @Override public final String toString() {
         return S.toString(GridManagerAdapter.class, this, "name", getClass().getName());
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/717939ab/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
index b55ffb0..1e826de 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
@@ -257,6 +257,9 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
     /** */
     private final CountDownLatch startLatch = new CountDownLatch(1);
 
+    /** */
+    private Object consistentId;
+
     /** @param ctx Context. */
     public GridDiscoveryManager(GridKernalContext ctx) {
         super(ctx, ctx.config().getDiscoverySpi());
@@ -1703,6 +1706,24 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
         return locNode == null ? getSpi().getLocalNode() : locNode;
     }
 
+    /**
+     * @return Consistent ID.
+     */
+    public Object consistentId() {
+        if (consistentId == null) {
+            try {
+                inject();
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException("Failed to init consisten ID.", e);
+            }
+
+            consistentId = getSpi().consistentId();
+        }
+
+        return consistentId;
+    }
+
     /** @return Topology version. */
     public long topologyVersion() {
         return topSnap.get().topVer.topologyVersion();

http://git-wip-us.apache.org/repos/asf/ignite/blob/717939ab/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
index 1cb202c..3f27ecb 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
@@ -164,6 +164,15 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
     }
 
     /**
+     * Gets ignite instance.
+     *
+     * @return Ignite instance.
+     */
+    public Ignite ignite() {
+        return ignite;
+    }
+
+    /**
      * Sets SPI name.
      *
      * @param name SPI name.

http://git-wip-us.apache.org/repos/asf/ignite/blob/717939ab/modules/core/src/main/java/org/apache/ignite/spi/discovery/DiscoverySpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/DiscoverySpi.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/DiscoverySpi.java
index 8c23d92..d285575 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/DiscoverySpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/DiscoverySpi.java
@@ -48,6 +48,14 @@ import org.jetbrains.annotations.Nullable;
  */
 public interface DiscoverySpi extends IgniteSpi {
     /**
+     * Gets consistent ID.
+     *
+     * @return Consistent ID of this Ignite instance or {@code null} if not applicable.
+     * @throws IgniteSpiException If failed.
+     */
+    @Nullable public Object consistentId() throws IgniteSpiException;
+
+    /**
      * Gets collection of remote nodes in grid or empty collection if no remote nodes found.
      *
      * @return Collection of remote nodes.
@@ -147,7 +155,7 @@ public interface DiscoverySpi extends IgniteSpi {
     /**
      * Sends custom message across the ring.
      * @param msg Custom message.
-     * @throws IgniteException if failed to marshal evt.
+     * @throws IgniteException if failed to sent the event message.
      */
     public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/717939ab/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 0106b0a..6a8af73 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
@@ -275,6 +275,14 @@ class ServerImpl extends TcpDiscoveryImpl {
     }
 
     /** {@inheritDoc} */
+    @Override public int boundPort() throws IgniteSpiException {
+        if (tcpSrvr == null)
+            tcpSrvr = new TcpServer();
+
+        return tcpSrvr.port;
+    }
+
+    /** {@inheritDoc} */
     @Override public void spiStart(String gridName) throws IgniteSpiException {
         synchronized (mux) {
             spiState = DISCONNECTED;
@@ -297,7 +305,8 @@ class ServerImpl extends TcpDiscoveryImpl {
         msgWorker = new RingMessageWorker();
         msgWorker.start();
 
-        tcpSrvr = new TcpServer();
+        if (tcpSrvr == null)
+            tcpSrvr = new TcpServer();
 
         spi.initLocalNode(tcpSrvr.port, true);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/717939ab/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
index 1aef728..a96c84f 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
@@ -211,6 +211,16 @@ abstract class TcpDiscoveryImpl {
     public abstract void spiStart(@Nullable String gridName) throws IgniteSpiException;
 
     /**
+     * Will start TCP server if applicable and not started yet.
+     *
+     * @return Port this instance bound to.
+     * @throws IgniteSpiException If failed.
+     */
+    public int boundPort() throws IgniteSpiException {
+        return 0;
+    }
+
+    /**
      * @throws IgniteSpiException If failed.
      */
     public abstract void spiStop() throws IgniteSpiException;

http://git-wip-us.apache.org/repos/asf/ignite/blob/717939ab/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 0d41cd2..cb8c04f 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
@@ -407,6 +407,12 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi,
T
     /** */
     private boolean clientReconnectDisabled;
 
+    /** */
+    private Object consistentId;
+
+    /** Local node addresses. */
+    private IgniteBiTuple<Collection<String>, Collection<String>> addrs;
+
     /** {@inheritDoc} */
     @Override public String getSpiState() {
         return impl.getSpiState();
@@ -965,20 +971,45 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi,
T
         locNodeVer = ver;
     }
 
+    /** {@inheritDoc} */
+    @Nullable @Override public Object consistentId() throws IgniteSpiException {
+        if (consistentId == null) {
+            initializeImpl();
+
+            initAddresses();
+
+            List<String> sortedAddrs = new ArrayList<>(addrs.get1());
+
+            Collections.sort(sortedAddrs);
+
+            consistentId = U.consistentId(sortedAddrs, impl.boundPort());
+        }
+
+        return consistentId;
+    }
+
+    /**
+     *
+     */
+    private void initAddresses() {
+        if (addrs == null) {
+            try {
+                addrs = U.resolveLocalAddresses(locHost);
+            }
+            catch (IOException | IgniteCheckedException e) {
+                throw new IgniteSpiException("Failed to resolve local host to set of external
addresses: " + locHost,
+                    e);
+            }
+        }
+    }
+
     /**
      * @param srvPort Server port.
      * @param addExtAddrAttr If {@code true} adds {@link #ATTR_EXT_ADDRS} attribute.
      */
     protected void initLocalNode(int srvPort, boolean addExtAddrAttr) {
         // Init local node.
-        IgniteBiTuple<Collection<String>, Collection<String>> addrs;
-
-        try {
-            addrs = U.resolveLocalAddresses(locHost);
-        }
-        catch (IOException | IgniteCheckedException e) {
-            throw new IgniteSpiException("Failed to resolve local host to set of external
addresses: " + locHost, e);
-        }
+        initAddresses();
 
         locNode = new TcpDiscoveryNode(
             ignite.configuration().getNodeId(),
@@ -987,7 +1018,7 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi,
T
             srvPort,
             metricsProvider,
             locNodeVer,
-            ignite.configuration().getConsistentId());
+            (Serializable)consistentId());
 
         if (addExtAddrAttr) {
             Collection<InetSocketAddress> extAddrs = addrRslvr == null ? null :
@@ -1727,6 +1758,20 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi,
T
 
     /** {@inheritDoc} */
     @Override public void spiStart(@Nullable String gridName) throws IgniteSpiException {
+        initializeImpl();
+
+        registerMBean(gridName, this, TcpDiscoverySpiMBean.class);
+
+        impl.spiStart(gridName);
+    }
+
+    /**
+     *
+     */
+    private void initializeImpl() {
+        if (impl != null)
+            return;
+
         initFailureDetectionTimeout();
 
         if (!forceSrvMode && (Boolean.TRUE.equals(ignite.configuration().isClientMode())))
{
@@ -1820,8 +1865,6 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi,
T
         if (netTimeout < 3000)
             U.warn(log, "Network timeout is too low (at least 3000 ms recommended): " + netTimeout);
 
-        registerMBean(gridName, this, TcpDiscoverySpiMBean.class);
-
         if (ipFinder instanceof TcpDiscoveryMulticastIpFinder) {
             TcpDiscoveryMulticastIpFinder mcastIpFinder = ((TcpDiscoveryMulticastIpFinder)ipFinder);
 
@@ -1830,8 +1873,6 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi,
T
         }
 
         cfgNodeId = ignite.configuration().getNodeId();
-
-        impl.spiStart(gridName);
     }
 
     /** {@inheritDoc} */
@@ -1872,13 +1913,6 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi,
T
     }
 
     /**
-     * @return Ignite instance.
-     */
-    Ignite ignite() {
-        return ignite;
-    }
-
-    /**
      * @return {@code True} if node is stopping.
      */
     boolean isNodeStopping0() {


Mime
View raw message