ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [49/50] [abbrv] incubator-ignite git commit: ignite-366 Metrics for caches should work in clustered mode
Date Tue, 07 Apr 2015 23:59:15 GMT
ignite-366 Metrics for caches should work in clustered mode


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

Branch: refs/heads/ignite-366
Commit: e1540d5273fb5d130754c277872fdfeae622332f
Parents: 6c1c33e
Author: Andrey Gura <agura@gridgain.com>
Authored: Mon Apr 6 20:02:29 2015 +0300
Committer: agura <agura@gridgain.com>
Committed: Wed Apr 8 01:13:06 2015 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/cluster/ClusterNode.java  | 12 ---
 .../discovery/GridDiscoveryManager.java         |  3 +-
 .../processors/cache/CacheMetricsSnapshot.java  |  2 -
 .../processors/cache/IgniteCacheProxy.java      | 13 +++-
 .../spi/discovery/tcp/TcpDiscoverySpi.java      |  1 -
 .../tcp/internal/TcpDiscoveryNode.java          | 13 +++-
 .../messages/TcpDiscoveryHeartbeatMessage.java  |  3 +-
 .../ignite/internal/GridDiscoverySelfTest.java  |  5 --
 .../CacheMetricsForClusterGroupSelfTest.java    | 82 ++++++++++++++------
 .../ignite/p2p/GridP2PClassLoadingSelfTest.java |  5 --
 .../ignite/testframework/GridTestNode.java      |  5 --
 11 files changed, 86 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/modules/core/src/main/java/org/apache/ignite/cluster/ClusterNode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cluster/ClusterNode.java b/modules/core/src/main/java/org/apache/ignite/cluster/ClusterNode.java
index 2c7fd46..cda2d56 100644
--- a/modules/core/src/main/java/org/apache/ignite/cluster/ClusterNode.java
+++ b/modules/core/src/main/java/org/apache/ignite/cluster/ClusterNode.java
@@ -149,18 +149,6 @@ public interface ClusterNode {
     public ClusterMetrics metrics();
 
     /**
-     * Gets collections of cache metrics for this node. Note that node cache metrics are
constantly updated
-     * and provide up to date information about caches.
-     * <p>
-     * Cache metrics are updated with some delay which is directly related to heartbeat
-     * frequency. For example, when used with default
-     * {@link org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi} the update will happen
every {@code 2} seconds.
-     *
-     * @return Runtime metrics snapshots for this node.
-     */
-    public Map<Integer, CacheMetrics> cacheMetrics();
-
-    /**
      * Gets all node attributes. Attributes are assigned to nodes at startup
      * via {@link org.apache.ignite.configuration.IgniteConfiguration#getUserAttributes()}
method.
      * <p>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/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 15b6ba9..88e3cc9 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
@@ -657,7 +657,8 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
                 Map<Integer, CacheMetrics> metrics = U.newHashMap(caches.size());
 
                 for (GridCacheAdapter<?, ?> cache : caches)
-                    metrics.put(cache.context().cacheId(), cache.metrics());
+                    if (cache.configuration().isStatisticsEnabled())
+                        metrics.put(cache.context().cacheId(), cache.metrics());
 
                 return metrics;
             }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
index 61ca68b..5ed7c73 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
@@ -263,8 +263,6 @@ public class CacheMetricsSnapshot implements CacheMetrics, Externalizable
{
      * @param metrics Metrics for merge.
      */
     public CacheMetricsSnapshot(CacheMetrics loc, Collection<CacheMetrics> metrics)
{
-        A.notEmpty(metrics, "metrics");
-
         id = loc.id();
         cacheName = loc.name();
         isEmpty = loc.isEmpty();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index e0e3972..dda1c7b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -33,6 +33,7 @@ import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.mxbean.*;
+import org.apache.ignite.spi.discovery.tcp.internal.*;
 import org.jetbrains.annotations.*;
 
 import javax.cache.*;
@@ -146,8 +147,16 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K,
V
         try {
             List<CacheMetrics> metrics = new ArrayList<>(grp.nodes().size());
 
-            for (ClusterNode node : grp.nodes())
-                metrics.add(node.cacheMetrics().get(context().cacheId()));
+            for (ClusterNode node : grp.nodes()) {
+                Map<Integer, CacheMetrics> nodeCacheMetrics = ((TcpDiscoveryNode)node).cacheMetrics();
+
+                if (nodeCacheMetrics != null) {
+                    CacheMetrics e = nodeCacheMetrics.get(context().cacheId());
+
+                    if (e != null)
+                        metrics.add(e);
+                }
+            }
 
             return new CacheMetricsSnapshot(ctx.cache().metrics(), metrics);
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/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 57a8869..18d6194 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
@@ -5154,7 +5154,6 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements
TcpDiscov
                     metrics = hbMsg.metrics().get(nodeId).metrics();
 
                     hbMsg.removeMetrics(nodeId);
-
                     hbMsg.removeCacheMetrics(nodeId);
 
                     assert !hbMsg.hasMetrics();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/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 3cafd4f..9be1207 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
@@ -214,8 +214,17 @@ public class TcpDiscoveryNode extends GridMetadataAwareAdapter implements
Cluste
         this.metrics = metrics;
     }
 
-    /** {@inheritDoc} */
-    @Override public Map<Integer, CacheMetrics> cacheMetrics() {
+    /**
+     * Gets collections of cache metrics for this node. Note that node cache metrics are
constantly updated
+     * and provide up to date information about caches.
+     * <p>
+     * Cache metrics are updated with some delay which is directly related to heartbeat
+     * frequency. For example, when used with default
+     * {@link org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi} the update will happen
every {@code 2} seconds.
+     *
+     * @return Runtime metrics snapshots for this node.
+     */
+    public Map<Integer, CacheMetrics> cacheMetrics() {
         if (metricsProvider != null)
             cacheMetrics = metricsProvider.cacheMetrics();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryHeartbeatMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryHeartbeatMessage.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryHeartbeatMessage.java
index 05268d3..4b8d46c 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryHeartbeatMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryHeartbeatMessage.java
@@ -103,7 +103,8 @@ public class TcpDiscoveryHeartbeatMessage extends TcpDiscoveryAbstractMessage
{
         assert metrics != null;
         assert !this.cacheMetrics.containsKey(nodeId);
 
-        this.cacheMetrics.put(nodeId, metrics);
+        if (!F.isEmpty(metrics))
+            this.cacheMetrics.put(nodeId, metrics);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/modules/core/src/test/java/org/apache/ignite/internal/GridDiscoverySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridDiscoverySelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/GridDiscoverySelfTest.java
index 96a1729..4a2483d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridDiscoverySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridDiscoverySelfTest.java
@@ -376,11 +376,6 @@ public class GridDiscoverySelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override public Map<Integer, CacheMetrics> cacheMetrics() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
         @Nullable @Override public Map<String, Object> attributes() {
             return null;
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsForClusterGroupSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsForClusterGroupSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsForClusterGroupSelfTest.java
index a3ffca9..9ebcf46 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsForClusterGroupSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsForClusterGroupSelfTest.java
@@ -19,13 +19,18 @@ package org.apache.ignite.internal.processors.cache;
 
 import org.apache.ignite.*;
 import org.apache.ignite.cache.*;
+import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.lang.*;
+import org.apache.ignite.spi.discovery.tcp.internal.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
 
 /**
  * Test for cluster wide cache metrics.
  */
-public class CacheMetricsForClusterGroupSelfTest extends GridCacheAbstractSelfTest {
+public class CacheMetricsForClusterGroupSelfTest extends GridCommonAbstractTest {
     /** Grid count. */
     private static final int GRID_CNT = 3;
 
@@ -42,30 +47,45 @@ public class CacheMetricsForClusterGroupSelfTest extends GridCacheAbstractSelfTe
     private static final int ENTRY_CNT_CACHE2 = 500;
 
     /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return GRID_CNT;
+    @Override protected void beforeTest() throws Exception {
+        startGrids(GRID_CNT);
     }
 
     /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        super.beforeTest();
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
 
-        CacheConfiguration ccfg1 = defaultCacheConfiguration();
-        ccfg1.setName(CACHE1);
-        ccfg1.setStatisticsEnabled(true);
+    /**
+     * Test cluster group metrics in case of statistics enabled.
+     */
+    public void testMetricsStatisticsEnabled() throws Exception {
+        createCaches(true);
 
-        CacheConfiguration ccfg2 = defaultCacheConfiguration();
-        ccfg2.setName(CACHE2);
-        ccfg2.setStatisticsEnabled(true);
+        populateCacheData(CACHE1, ENTRY_CNT_CACHE1);
+        populateCacheData(CACHE2, ENTRY_CNT_CACHE2);
 
-        grid(0).getOrCreateCache(ccfg1);
-        grid(0).getOrCreateCache(ccfg2);
+        readCacheData(CACHE1, ENTRY_CNT_CACHE1);
+        readCacheData(CACHE2, ENTRY_CNT_CACHE2);
+
+        // Wait for heartbeat message
+        Thread.sleep(3000);
+
+        Collection<ClusterNode> nodes = grid(0).cluster().forRemotes().nodes();
+
+        for (ClusterNode node : nodes)
+            assertNotNull(((TcpDiscoveryNode)node).cacheMetrics());
+
+        assertMetrics(CACHE1);
+        assertMetrics(CACHE2);
     }
 
     /**
-     * Test cluster group metrics.
+     * Test cluster group metrics in case of statistics disabled.
      */
-    public void testMetrics() throws Exception {
+    public void testMetricsStatisticsDisabled() throws Exception {
+        createCaches(false);
+
         populateCacheData(CACHE1, ENTRY_CNT_CACHE1);
         populateCacheData(CACHE2, ENTRY_CNT_CACHE2);
 
@@ -75,8 +95,26 @@ public class CacheMetricsForClusterGroupSelfTest extends GridCacheAbstractSelfTe
         // Wait for heartbeat message
         Thread.sleep(3000);
 
-        assertMetrics(CACHE1);
-        assertMetrics(CACHE2);
+        Collection<ClusterNode> nodes = grid(0).cluster().forRemotes().nodes();
+
+        for (ClusterNode node : nodes)
+            assertNull(((TcpDiscoveryNode)node).cacheMetrics());
+    }
+
+    /**
+     * @param statisticsEnabled Statistics enabled.
+     */
+    private void createCaches(boolean statisticsEnabled) {
+        CacheConfiguration ccfg1 = defaultCacheConfiguration();
+        ccfg1.setName(CACHE1);
+        ccfg1.setStatisticsEnabled(statisticsEnabled);
+
+        CacheConfiguration ccfg2 = defaultCacheConfiguration();
+        ccfg2.setName(CACHE2);
+        ccfg2.setStatisticsEnabled(statisticsEnabled);
+
+        grid(0).getOrCreateCache(ccfg1);
+        grid(0).getOrCreateCache(ccfg2);
     }
 
     /**
@@ -107,16 +145,16 @@ public class CacheMetricsForClusterGroupSelfTest extends GridCacheAbstractSelfTe
     private void assertMetrics(String name) {
         CacheMetrics metrics = grid(0).cache(name).metrics(grid(0).cluster().forCacheNodes(name));
 
-        CacheMetrics[] ms = new CacheMetrics[gridCount()];
+        CacheMetrics[] ms = new CacheMetrics[GRID_CNT];
 
-        for (int i = 0; i < gridCount(); i++)
+        for (int i = 0; i < GRID_CNT; i++)
             ms[i] = grid(i).cache(name).metrics();
 
         // Static metrics
-        for (int i = 0; i < gridCount(); i++)
+        for (int i = 0; i < GRID_CNT; i++)
             assertEquals(metrics.id(), ms[i].id());
 
-        for (int i = 0; i < gridCount(); i++)
+        for (int i = 0; i < GRID_CNT; i++)
             assertEquals(metrics.name(), ms[i].name());
 
         // Dynamic metrics
@@ -146,7 +184,7 @@ public class CacheMetricsForClusterGroupSelfTest extends GridCacheAbstractSelfTe
     private long sum(CacheMetrics[] ms, IgniteClosure<CacheMetrics, Long> f) {
         long res = 0;
 
-        for (int i = 0; i < gridCount(); i++)
+        for (int i = 0; i < GRID_CNT; i++)
             res += f.apply(ms[i]);
 
         return res;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PClassLoadingSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PClassLoadingSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PClassLoadingSelfTest.java
index c0e55b1..1a529a5 100644
--- a/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PClassLoadingSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PClassLoadingSelfTest.java
@@ -116,11 +116,6 @@ public class GridP2PClassLoadingSelfTest extends GridCommonAbstractTest
{
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override public Map<Integer, CacheMetrics> cacheMetrics() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
         @Nullable @Override public Map<String, Object> attributes() {
             return null;
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1540d52/modules/core/src/test/java/org/apache/ignite/testframework/GridTestNode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestNode.java
b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestNode.java
index 58c2401..ded19d0 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestNode.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestNode.java
@@ -191,11 +191,6 @@ public class GridTestNode extends GridMetadataAwareAdapter implements
ClusterNod
     }
 
     /** {@inheritDoc} */
-    @Override public Map<Integer, CacheMetrics> cacheMetrics() {
-        return cacheMetrics;
-    }
-
-    /** {@inheritDoc} */
     @Override public long order() {
         return order != 0 ? order : (metrics == null ? -1 : metrics.getStartTime());
     }


Mime
View raw message