ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [23/27] ignite git commit: IGNITE-2409: Optimized client node check which was observed as a hotspot in several places.
Date Wed, 02 Mar 2016 18:26:51 GMT
IGNITE-2409: Optimized client node check which was observed as a hotspot in several places.


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

Branch: refs/heads/ignite-2407
Commit: 9200ec8bb950d303967bfd6a747f636c7c637370
Parents: ba677cc
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Wed Mar 2 14:13:12 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Mar 2 14:13:12 2016 +0300

----------------------------------------------------------------------
 .../discovery/GridDiscoveryManager.java         | 18 +++++++-------
 .../processors/cache/GridCacheUtils.java        | 13 ++++++++++
 .../tcp/internal/TcpDiscoveryNode.java          | 25 ++++++++++++++++++++
 3 files changed, 46 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9200ec8b/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..7b795d5 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
@@ -30,7 +30,6 @@ import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -112,7 +111,6 @@ import org.apache.ignite.spi.discovery.DiscoverySpiHistorySupport;
 import org.apache.ignite.spi.discovery.DiscoverySpiListener;
 import org.apache.ignite.spi.discovery.DiscoverySpiNodeAuthenticator;
 import org.apache.ignite.spi.discovery.DiscoverySpiOrderSupport;
-import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCheckFailedMessage;
 import org.apache.ignite.thread.IgniteThread;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentHashMap8;
@@ -166,14 +164,14 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
     protected static final int DISCOVERY_HISTORY_SIZE = 100;
 
     /** Predicate filtering out daemon nodes. */
-    private static final IgnitePredicate<ClusterNode> daemonFilter = new P1<ClusterNode>()
{
+    private static final IgnitePredicate<ClusterNode> FILTER_DAEMON = new P1<ClusterNode>()
{
         @Override public boolean apply(ClusterNode n) {
             return !n.isDaemon();
         }
     };
 
     /** Predicate filtering client nodes. */
-    private static final IgnitePredicate<ClusterNode> clientFilter = new P1<ClusterNode>()
{
+    private static final IgnitePredicate<ClusterNode> FILTER_CLI = new P1<ClusterNode>()
{
         @Override public boolean apply(ClusterNode n) {
             return CU.clientNode(n);
         }
@@ -567,7 +565,7 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
                             @Override public ClusterNode apply(ClusterNode e) {
                                 return e;
                             }
-                        }, daemonFilter)));
+                        }, FILTER_DAEMON)));
 
                     locJoinEvt.onDone(discoEvt);
 
@@ -1121,9 +1119,9 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
 
         Collection<ClusterNode> rmtNodes = discoCache.remoteNodes();
 
-        Collection<ClusterNode> srvNodes = F.view(discoCache.allNodes(), F.not(clientFilter));
+        Collection<ClusterNode> srvNodes = F.view(discoCache.allNodes(), F.not(FILTER_CLI));
 
-        Collection<ClusterNode> clientNodes = F.view(discoCache.allNodes(), clientFilter);
+        Collection<ClusterNode> clientNodes = F.view(discoCache.allNodes(), FILTER_CLI);
 
         ClusterNode locNode = discoCache.localNode();
 
@@ -1945,7 +1943,7 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
                 evt.eventNode(node);
                 evt.type(type);
 
-                evt.topologySnapshot(topVer, U.<ClusterNode, ClusterNode>arrayList(topSnapshot,
daemonFilter));
+                evt.topologySnapshot(topVer, U.<ClusterNode, ClusterNode>arrayList(topSnapshot,
FILTER_DAEMON));
 
                 if (type == EVT_NODE_METRICS_UPDATED)
                     evt.message("Metrics were updated: " + node);
@@ -2469,7 +2467,7 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
         private DiscoCache(ClusterNode loc, Collection<ClusterNode> rmts) {
             this.loc = loc;
 
-            rmtNodes = Collections.unmodifiableList(new ArrayList<>(F.view(rmts, daemonFilter)));
+            rmtNodes = Collections.unmodifiableList(new ArrayList<>(F.view(rmts, FILTER_DAEMON)));
 
             assert !rmtNodes.contains(loc) : "Remote nodes collection shouldn't contain local
node" +
                 " [rmtNodes=" + rmtNodes + ", loc=" + loc + ']';
@@ -2592,7 +2590,7 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
             nearEnabledCaches = Collections.unmodifiableSet(nearEnabledSet);
 
             daemonNodes = Collections.unmodifiableList(new ArrayList<>(
-                F.view(F.concat(false, loc, rmts), F0.not(daemonFilter))));
+                F.view(F.concat(false, loc, rmts), F0.not(FILTER_DAEMON))));
 
             Map<UUID, ClusterNode> nodeMap = new HashMap<>(allNodes().size()
+ daemonNodes.size(), 1.0f);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/9200ec8b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index dce5357..25ea14c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -90,6 +90,7 @@ import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.lang.IgniteReducer;
 import org.apache.ignite.lifecycle.LifecycleAware;
 import org.apache.ignite.plugin.CachePluginConfiguration;
+import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
 import org.apache.ignite.spi.swapspace.noop.NoopSwapSpaceSpi;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
@@ -1649,6 +1650,18 @@ public class GridCacheUtils {
      * @return {@code True} if given node is client node (has flag {@link IgniteConfiguration#isClientMode()}
set).
      */
     public static boolean clientNode(ClusterNode node) {
+        if (node instanceof TcpDiscoveryNode)
+            return ((TcpDiscoveryNode)node).isCacheClient();
+        else
+            return clientNodeDirect(node);
+    }
+
+    /**
+     * @param node Node.
+     * @return {@code True} if given node is client node (has flag {@link IgniteConfiguration#isClientMode()}
set).
+     */
+    @SuppressWarnings("ConstantConditions")
+    public static boolean clientNodeDirect(ClusterNode node) {
         Boolean clientModeAttr = node.attribute(IgniteNodeAttributes.ATTR_CLIENT_MODE);
 
         assert clientModeAttr != null : node;

http://git-wip-us.apache.org/repos/asf/ignite/blob/9200ec8b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
index 362fa2f..0be0bea 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
@@ -32,6 +32,7 @@ import java.util.UUID;
 import org.apache.ignite.cache.CacheMetrics;
 import org.apache.ignite.cluster.ClusterMetrics;
 import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.ClusterMetricsSnapshot;
 import org.apache.ignite.internal.IgniteNodeAttributes;
 import org.apache.ignite.internal.processors.cache.CacheMetricsSnapshot;
@@ -39,6 +40,7 @@ import org.apache.ignite.internal.util.lang.GridMetadataAwareAdapter;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgnitePredicate;
@@ -132,6 +134,14 @@ public class TcpDiscoveryNode extends GridMetadataAwareAdapter implements
Cluste
     @GridToStringExclude
     private volatile transient InetSocketAddress lastSuccessfulAddr;
 
+    /** Cache client initialization flag. */
+    @GridToStringExclude
+    private transient volatile boolean cacheCliInit;
+
+    /** Cache client flag. */
+    @GridToStringExclude
+    private transient boolean cacheCli;
+
     /**
      * Public default no-arg constructor for {@link Externalizable} interface.
      */
@@ -501,6 +511,21 @@ public class TcpDiscoveryNode extends GridMetadataAwareAdapter implements
Cluste
         return node;
     }
 
+    /**
+     * Whether this node is cache client (see {@link IgniteConfiguration#isClientMode()}).
+     *
+     * @return {@code True if client}.
+     */
+    public boolean isCacheClient() {
+        if (!cacheCliInit) {
+            cacheCli = CU.clientNodeDirect(this);
+
+            cacheCliInit = true;
+        }
+
+        return cacheCli;
+    }
+
     /** {@inheritDoc} */
     @Override public int compareTo(@Nullable TcpDiscoveryNode node) {
         if (node == null)


Mime
View raw message