You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2020/07/14 09:15:39 UTC

[ignite] 02/02: IGNITE-13227 Fix AssertionError on getting cache size from the mbean on the inactive cluster - Fixes #8005.

This is an automated email from the ASF dual-hosted git repository.

alexpl pushed a commit to branch ignite-2.9
in repository https://gitbox.apache.org/repos/asf/ignite.git

commit 7991f9335f38a893ceec3c567bf6b3adf5f68b17
Author: NSAmelchev <ns...@gmail.com>
AuthorDate: Tue Jul 14 14:01:45 2020 +0500

    IGNITE-13227 Fix AssertionError on getting cache size from the mbean on the inactive cluster - Fixes #8005.
    
    Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
    (cherry picked from commit 5cf15fc1b0e918d64423c0ada80f0c8927fc2df0)
---
 .../processors/cache/CacheMetricsImpl.java         | 34 +++++++++++++++-------
 .../processors/cache/CacheMetricsManageTest.java   | 17 ++++++++++-
 2 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
index fb3719b..663b296 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
@@ -1221,6 +1221,11 @@ public class CacheMetricsImpl implements CacheMetrics {
      * Calculates entries count/partitions count metrics using one iteration over local partitions for all metrics
      */
     public EntriesStatMetrics getEntriesStat() {
+        AffinityTopologyVersion topVer = cctx.affinity().affinityTopologyVersion();
+
+        if (AffinityTopologyVersion.NONE.equals(topVer))
+            return unknownEntriesStat();
+
         int owningPartCnt = 0;
         int movingPartCnt = 0;
         long offHeapEntriesCnt = 0L;
@@ -1249,8 +1254,6 @@ public class CacheMetricsImpl implements CacheMetrics {
                 }
             }
             else {
-                AffinityTopologyVersion topVer = cctx.affinity().affinityTopologyVersion();
-
                 IntSet primaries = ImmutableIntSet.wrap(cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer));
                 IntSet backups = ImmutableIntSet.wrap(cctx.affinity().backupPartitions(cctx.localNodeId(), topVer));
 
@@ -1283,14 +1286,7 @@ public class CacheMetricsImpl implements CacheMetrics {
             }
         }
         catch (Exception e) {
-            owningPartCnt = -1;
-            movingPartCnt = 0;
-            offHeapEntriesCnt = -1L;
-            offHeapPrimaryEntriesCnt = -1L;
-            offHeapBackupEntriesCnt = -1L;
-            heapEntriesCnt = -1L;
-            size = -1;
-            sizeLong = -1L;
+            return unknownEntriesStat();
         }
 
         isEmpty = (offHeapEntriesCnt == 0);
@@ -1311,6 +1307,24 @@ public class CacheMetricsImpl implements CacheMetrics {
         return stat;
     }
 
+    /** @return Instance of {@link EntriesStatMetrics} with default values in case of unknown metrics. */
+    private EntriesStatMetrics unknownEntriesStat() {
+        EntriesStatMetrics stat = new EntriesStatMetrics();
+
+        stat.offHeapEntriesCount(-1L);
+        stat.offHeapPrimaryEntriesCount(-1L);
+        stat.offHeapBackupEntriesCount(-1L);
+        stat.heapEntriesCount(-1L);
+        stat.size(-1);
+        stat.cacheSize(-1L);
+        stat.keySize(-1);
+        stat.isEmpty(false);
+        stat.totalPartitionsCount(-1);
+        stat.rebalancingPartitionsCount(0);
+
+        return stat;
+    }
+
     /** {@inheritDoc} */
     @Override public int getTotalPartitionsCount() {
         return getEntriesStat().totalPartitionsCount();
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsManageTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsManageTest.java
index c2c297c..26ba004 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsManageTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsManageTest.java
@@ -32,7 +32,6 @@ import javax.cache.Caching;
 import javax.management.MBeanServer;
 import javax.management.MBeanServerInvocationHandler;
 import javax.management.ObjectName;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
@@ -821,6 +820,22 @@ public class CacheMetricsManageTest extends GridCommonAbstractTest {
         txLatch.await();
     }
 
+    /** @throws Exception If failed. */
+    @Test
+    public void testCacheSizeOnInactiveCluster() throws Exception {
+        persistence = true;
+
+        IgniteEx grid = startGrid(0);
+
+        assertFalse(grid.cluster().state().active());
+
+        CacheMetricsMXBean mxBean = mxBean(0, CACHE1, CacheLocalMetricsMXBeanImpl.class);
+
+        long size = mxBean.getCacheSize();
+
+        assertEquals(-1, size);
+    }
+
     /**
      *
      */