ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ag...@apache.org
Subject ignite git commit: IGNITE-8515 Value of CacheGroupMetricsMXBean.getTotalAllocatedPages() is always 0
Date Wed, 06 Jun 2018 09:33:54 GMT
Repository: ignite
Updated Branches:
  refs/heads/master ecd8261f1 -> d638a095e


IGNITE-8515 Value of CacheGroupMetricsMXBean.getTotalAllocatedPages() is always 0

Signed-off-by: Andrey Gura <agura@apache.org>


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

Branch: refs/heads/master
Commit: d638a095e22e987dd0f5fb55271999494809a956
Parents: ecd8261
Author: Aleksey Plekhanov <plehanov.alex@gmail.com>
Authored: Wed Jun 6 12:22:09 2018 +0300
Committer: Andrey Gura <agura@apache.org>
Committed: Wed Jun 6 12:32:56 2018 +0300

----------------------------------------------------------------------
 .../cache/CacheGroupMetricsMXBeanImpl.java      | 12 ++--
 .../persistence/DataRegionMetricsImpl.java      | 24 ++++++--
 .../cache/CacheGroupMetricsMBeanTest.java       | 58 ++++++++++++++++++++
 3 files changed, 82 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d638a095/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsMXBeanImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsMXBeanImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsMXBeanImpl.java
index a537e3d..58de40c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsMXBeanImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsMXBeanImpl.java
@@ -47,7 +47,7 @@ public class CacheGroupMetricsMXBeanImpl implements CacheGroupMetricsMXBean
{
     private final CacheGroupContext ctx;
 
     /** */
-    private final GroupAllocationTrucker groupPageAllocationTracker;
+    private final GroupAllocationTracker groupPageAllocationTracker;
 
     /** Interface describing a predicate of two integers. */
     private interface IntBiPredicate {
@@ -63,7 +63,7 @@ public class CacheGroupMetricsMXBeanImpl implements CacheGroupMetricsMXBean
{
     /**
      *
      */
-    public static class GroupAllocationTrucker implements AllocatedPageTracker {
+    public static class GroupAllocationTracker implements AllocatedPageTracker {
         /** */
         private final LongAdder totalAllocatedPages = new LongAdder();
 
@@ -71,9 +71,9 @@ public class CacheGroupMetricsMXBeanImpl implements CacheGroupMetricsMXBean
{
         private final AllocatedPageTracker delegate;
 
         /**
-         * @param delegate Delegate allocation trucker.
+         * @param delegate Delegate allocation tracker.
          */
-        public GroupAllocationTrucker(AllocatedPageTracker delegate) {
+        public GroupAllocationTracker(AllocatedPageTracker delegate) {
             this.delegate = delegate;
         }
 
@@ -88,7 +88,7 @@ public class CacheGroupMetricsMXBeanImpl implements CacheGroupMetricsMXBean
{
     /**
      *
      */
-    private static class NoopAllocationTrucker implements AllocatedPageTracker{
+    private static class NoopAllocationTracker implements AllocatedPageTracker{
         /** {@inheritDoc} */
         @Override public void updateTotalAllocatedPages(long delta) {
             // No-op.
@@ -112,7 +112,7 @@ public class CacheGroupMetricsMXBeanImpl implements CacheGroupMetricsMXBean
{
             this.groupPageAllocationTracker = dataRegionMetrics.getOrAllocateGroupPageAllocationTracker(ctx.groupId());
         }
         else
-            this.groupPageAllocationTracker = new GroupAllocationTrucker(new NoopAllocationTrucker());
+            this.groupPageAllocationTracker = new GroupAllocationTracker(new NoopAllocationTracker());
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/d638a095/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DataRegionMetricsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DataRegionMetricsImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DataRegionMetricsImpl.java
index a82f73b..f4e7a2c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DataRegionMetricsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DataRegionMetricsImpl.java
@@ -17,12 +17,13 @@
 package org.apache.ignite.internal.processors.cache.persistence;
 
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.LongAdder;
 import org.apache.ignite.DataRegionMetrics;
 import org.apache.ignite.configuration.DataRegionConfiguration;
 import org.apache.ignite.internal.pagemem.PageMemory;
-import org.apache.ignite.internal.processors.cache.CacheGroupMetricsMXBeanImpl.GroupAllocationTrucker;
+import org.apache.ignite.internal.processors.cache.CacheGroupMetricsMXBeanImpl.GroupAllocationTracker;
 import org.apache.ignite.internal.processors.cache.ratemetrics.HitRateMetrics;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteOutClosure;
@@ -39,7 +40,7 @@ public class DataRegionMetricsImpl implements DataRegionMetrics, AllocatedPageTr
     private final LongAdder totalAllocatedPages = new LongAdder();
 
     /** */
-    private final ConcurrentHashMap<Integer, GroupAllocationTrucker> groupAllocationTruckers
= new ConcurrentHashMap<>();
+    private final ConcurrentMap<Integer, GroupAllocationTracker> grpAllocationTrackers
= new ConcurrentHashMap<>();
 
     /**
      * Counter for number of pages occupied by large entries (one entry is larger than one
page).
@@ -375,13 +376,24 @@ public class DataRegionMetricsImpl implements DataRegionMetrics, AllocatedPageTr
     }
 
     /**
-     * Get or allocate group allocation trucker.
+     * Get or allocate group allocation tracker.
      *
      * @param grpId Group id.
-     * @return Group allocation trucker.
+     * @return Group allocation tracker.
      */
-    public GroupAllocationTrucker getOrAllocateGroupPageAllocationTracker(int grpId) {
-        return groupAllocationTruckers.getOrDefault(grpId, new GroupAllocationTrucker(this));
+    public GroupAllocationTracker getOrAllocateGroupPageAllocationTracker(int grpId) {
+        GroupAllocationTracker tracker = grpAllocationTrackers.get(grpId);
+
+        if (tracker == null) {
+            tracker = new GroupAllocationTracker(this);
+
+            GroupAllocationTracker old = grpAllocationTrackers.putIfAbsent(grpId, tracker);
+
+            if (old != null)
+                return old;
+        }
+
+        return tracker;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/d638a095/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsMBeanTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsMBeanTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsMBeanTest.java
index 04ed008..19b0203 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsMBeanTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsMBeanTest.java
@@ -31,12 +31,16 @@ import javax.management.MBeanServer;
 import javax.management.MBeanServerInvocationHandler;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteDataStreamer;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.affinity.AffinityFunction;
 import org.apache.ignite.cache.affinity.AffinityFunctionContext;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.events.Event;
 import org.apache.ignite.events.EventType;
@@ -53,6 +57,9 @@ import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
  */
 public class CacheGroupMetricsMBeanTest extends GridCommonAbstractTest implements Serializable
{
     /** */
+    private boolean pds = false;
+
+    /** */
     private static class RoundRobinVariableSizeAffinityFunction implements AffinityFunction
{
         /** {@inheritDoc} */
         @Override public void reset() {
@@ -143,9 +150,24 @@ public class CacheGroupMetricsMBeanTest extends GridCommonAbstractTest
implement
 
         cfg.setCacheConfiguration(cCfg1, cCfg2, cCfg3, cCfg4);
 
+        if (pds) {
+            cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+                    .setName("default")
+                    .setPersistenceEnabled(true)
+                    .setMetricsEnabled(true)
+                ).setMetricsEnabled(true)
+            );
+        }
+
         return cfg;
     }
 
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
     /**
      * Gets CacheGroupMetricsMXBean for given node and group name.
      *
@@ -213,6 +235,8 @@ public class CacheGroupMetricsMBeanTest extends GridCommonAbstractTest
implement
      * @throws Exception If failed.
      */
     public void testCacheGroupMetrics() throws Exception {
+        pds = false;
+
         startGrid(0);
         startGrid(1);
         startGrid(2);
@@ -308,4 +332,38 @@ public class CacheGroupMetricsMBeanTest extends GridCommonAbstractTest
implement
             evictLatch.countDown();
         }
     }
+
+    /**
+     * Test allocated pages counts for cache groups.
+     */
+    public void testAllocatedPages() throws Exception {
+        pds = true;
+
+        cleanPersistenceDir();
+
+        Ignite ignite = startGrid(0);
+
+        ignite.cluster().active(true);
+
+        CacheGroupMetricsMXBean mxBean0Grp1 = mxBean(0, "group1");
+        CacheGroupMetricsMXBean mxBean0Grp2 = mxBean(0, "group2");
+        CacheGroupMetricsMXBean mxBean0Grp3 = mxBean(0, "cache4");
+
+        long totalPages = ignite.dataRegionMetrics("default").getTotalAllocatedPages();
+
+        assertEquals(totalPages, mxBean0Grp1.getTotalAllocatedPages() + mxBean0Grp2.getTotalAllocatedPages()
+
+            mxBean0Grp3.getTotalAllocatedPages());
+
+        for (int cacheIdx = 1; cacheIdx <= 4; cacheIdx++) {
+            IgniteCache cache = ignite.cache("cache" + cacheIdx);
+
+            for (int i = 0; i < 10 * cacheIdx; i++)
+                cache.put(i, new byte[100]);
+        }
+
+        totalPages = ignite.dataRegionMetrics("default").getTotalAllocatedPages();
+
+        assertEquals(totalPages, mxBean0Grp1.getTotalAllocatedPages() + mxBean0Grp2.getTotalAllocatedPages()
+
+            mxBean0Grp3.getTotalAllocatedPages());
+    }
 }


Mime
View raw message