Repository: ignite
Updated Branches:
  refs/heads/master 6d7847c7f -> 9ee7646ed


IGNITE-10172 Added a system property to disable cache metrics sending across 
discovery - Fixes #5416.

Signed-off-by: Alexey Goncharuk <[email protected]>


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

Branch: refs/heads/master
Commit: 9ee7646ed3a3ff662749050e469ed00d0d4279dd
Parents: 6d7847c
Author: Aleksey Plekhanov <[email protected]>
Authored: Fri Nov 30 20:16:19 2018 +0300
Committer: Alexey Goncharuk <[email protected]>
Committed: Fri Nov 30 20:16:19 2018 +0300

----------------------------------------------------------------------
 .../apache/ignite/IgniteSystemProperties.java   |  10 ++
 .../discovery/GridDiscoveryManager.java         |   8 ++
 .../CacheMetricsForClusterGroupSelfTest.java    | 101 ++++++++++++++++---
 3 files changed, 106 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9ee7646e/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java 
b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index d581e75..d70162a 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -1045,6 +1045,16 @@ public final class IgniteSystemProperties {
     public static final String IGNITE_DEFAULT_DATA_STORAGE_PAGE_SIZE = 
"IGNITE_DEFAULT_DATA_STORAGE_PAGE_SIZE";
 
     /**
+     * When set to {@code true}, cache metrics are not included into the 
discovery metrics update message (in this
+     * case message contains only cluster metrics). By default cache metrics 
are included into the message and
+     * calculated each time the message is sent.
+     * <p>
+     * Cache metrics sending can also be turned off by disabling statistics 
per each cache, but in this case some cache
+     * metrics will be unavailable via JMX too.
+     */
+    public static final String IGNITE_DISCOVERY_DISABLE_CACHE_METRICS_UPDATE = 
"IGNITE_DISCOVERY_DISABLE_CACHE_METRICS_UPDATE";
+
+    /**
      * Enforces singleton.
      */
     private IgniteSystemProperties() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/9ee7646e/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 9a0ca92..beb8d21 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
@@ -48,6 +48,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteClientDisconnectedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteInterruptedException;
+import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cache.CacheMetrics;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cluster.BaselineNode;
@@ -1093,6 +1094,10 @@ public class GridDiscoveryManager extends 
GridManagerAdapter<DiscoverySpi> {
      */
     public DiscoveryMetricsProvider createMetricsProvider() {
         return new DiscoveryMetricsProvider() {
+            /** Disable cache metrics update. */
+            private final boolean disableCacheMetricsUpdate = 
IgniteSystemProperties.getBoolean(
+                
IgniteSystemProperties.IGNITE_DISCOVERY_DISABLE_CACHE_METRICS_UPDATE, false);
+
             /** */
             private final long startTime = U.currentTimeMillis();
 
@@ -1104,6 +1109,9 @@ public class GridDiscoveryManager extends 
GridManagerAdapter<DiscoverySpi> {
             /** {@inheritDoc} */
             @Override public Map<Integer, CacheMetrics> cacheMetrics() {
                 try {
+                    if (disableCacheMetricsUpdate)
+                        return Collections.emptyMap();
+
                     /** Caches should not be accessed while state transition 
is in progress. */
                     if (ctx.state().clusterState().transition())
                         return Collections.emptyMap();

http://git-wip-us.apache.org/repos/asf/ignite/blob/9ee7646e/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 3f196a5..df60c42 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
@@ -21,6 +21,7 @@ import java.util.Collection;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cache.CacheMetrics;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
@@ -71,22 +72,15 @@ public class CacheMetricsForClusterGroupSelfTest extends 
GridCommonAbstractTest
         return cfg;
     }
 
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGrids(GRID_CNT);
-
-        daemon = true;
-
-        startGrid(GRID_CNT);
-    }
-
     /**
      * Test cluster group metrics in case of statistics enabled.
      */
     public void testMetricsStatisticsEnabled() throws Exception {
-        createCaches(true);
+        startGrids();
 
         try {
+            createCaches(true);
+
             populateCacheData(cache1, ENTRY_CNT_CACHE1);
             populateCacheData(cache2, ENTRY_CNT_CACHE2);
 
@@ -107,7 +101,7 @@ public class CacheMetricsForClusterGroupSelfTest extends 
GridCommonAbstractTest
             assertMetrics(cache2, true);
         }
         finally {
-            destroyCaches();
+            stopAllGrids();
         }
     }
 
@@ -117,9 +111,11 @@ public class CacheMetricsForClusterGroupSelfTest extends 
GridCommonAbstractTest
      * @throws Exception If failed.
      */
     public void testMetricsStatisticsDisabled() throws Exception {
-        createCaches(false);
+        startGrids();
 
         try {
+            createCaches(false);
+
             populateCacheData(cache1, ENTRY_CNT_CACHE1);
             populateCacheData(cache2, ENTRY_CNT_CACHE2);
 
@@ -140,11 +136,62 @@ public class CacheMetricsForClusterGroupSelfTest extends 
GridCommonAbstractTest
             assertMetrics(cache2, false);
         }
         finally {
-            destroyCaches();
+            stopAllGrids();
+        }
+    }
+
+    /**
+     * Tests that only local metrics are updating if discovery updates 
disabled.
+     */
+    public void testMetricsDiscoveryUpdatesDisabled() throws Exception {
+        
System.setProperty(IgniteSystemProperties.IGNITE_DISCOVERY_DISABLE_CACHE_METRICS_UPDATE,
 "true");
+
+        try {
+            startGrids();
+
+            try {
+                createCaches(true);
+
+                populateCacheData(cache1, ENTRY_CNT_CACHE1);
+                populateCacheData(cache2, ENTRY_CNT_CACHE2);
+
+                readCacheData(cache1, ENTRY_CNT_CACHE1);
+                readCacheData(cache2, ENTRY_CNT_CACHE2);
+
+                awaitMetricsUpdate();
+
+                Collection<ClusterNode> nodes = 
grid(0).cluster().forRemotes().nodes();
+
+                for (ClusterNode node : nodes) {
+                    Map<Integer, CacheMetrics> metrics = 
((IgniteClusterNode)node).cacheMetrics();
+                    assertNotNull(metrics);
+                    assertTrue(metrics.isEmpty());
+                }
+
+                assertOnlyLocalMetricsUpdating(CACHE1);
+                assertOnlyLocalMetricsUpdating(CACHE2);
+            }
+            finally {
+                stopAllGrids();
+            }
+        }
+        finally {
+            
System.setProperty(IgniteSystemProperties.IGNITE_DISCOVERY_DISABLE_CACHE_METRICS_UPDATE,
 "false");
         }
     }
 
     /**
+     * Start grids.
+     */
+    private void startGrids() throws Exception {
+        startGrids(GRID_CNT);
+
+        daemon = true;
+
+        startGrid(GRID_CNT);
+    }
+
+    /**
      * @param statisticsEnabled Statistics enabled.
      */
     private void createCaches(boolean statisticsEnabled) {
@@ -268,6 +315,34 @@ public class CacheMetricsForClusterGroupSelfTest extends 
GridCommonAbstractTest
     }
 
     /**
+     * Asserts that only local metrics are updating.
+     *
+     * @param cacheName Cache name.
+     */
+    private void assertOnlyLocalMetricsUpdating(String cacheName) {
+        for (int i = 0; i < GRID_CNT; i++) {
+            IgniteCache cache = grid(i).cache(cacheName);
+
+            CacheMetrics clusterMetrics = 
cache.metrics(grid(i).cluster().forCacheNodes(cacheName));
+            CacheMetrics locMetrics = cache.localMetrics();
+
+            assertEquals(clusterMetrics.name(), locMetrics.name());
+
+            assertEquals(0L, clusterMetrics.getCacheGets());
+            assertEquals(0L, cache.mxBean().getCacheGets());
+            assertEquals(locMetrics.getCacheGets(), 
cache.localMxBean().getCacheGets());
+
+            assertEquals(0L, clusterMetrics.getCachePuts());
+            assertEquals(0L, cache.mxBean().getCachePuts());
+            assertEquals(locMetrics.getCachePuts(), 
cache.localMxBean().getCachePuts());
+
+            assertEquals(0L, clusterMetrics.getCacheHits());
+            assertEquals(0L, cache.mxBean().getCacheHits());
+            assertEquals(locMetrics.getCacheHits(), 
cache.localMxBean().getCacheHits());
+        }
+    }
+
+    /**
      * @param ms Milliseconds.
      * @param f Function.
      * @param expectNonZero Check if each value is non-zero.

Reply via email to