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-gg-12639 Fill factor metric is not working with enabled persistence
Date Mon, 21 Aug 2017 18:54:31 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 08a87b6c9 -> b6174c99f


ignite-gg-12639 Fill factor metric is not working with enabled persistence

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/b6174c99
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b6174c99
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b6174c99

Branch: refs/heads/master
Commit: b6174c99fa96e03aa65db933260a204b0297d17a
Parents: 08a87b6
Author: Ilya Lantukh <ilantukh@gridgain.com>
Authored: Mon Aug 21 21:12:41 2017 +0300
Committer: Andrey Gura <agura@apache.org>
Committed: Mon Aug 21 21:27:51 2017 +0300

----------------------------------------------------------------------
 .../GridCacheDatabaseSharedManager.java         | 28 +++++++++++++++
 .../persistence/GridCacheOffheapManager.java    | 27 +++++++++++++++
 .../IgniteCacheDatabaseSharedManager.java       | 36 ++++++++++++++++++--
 .../cache/persistence/MemoryMetricsImpl.java    | 26 +++++++-------
 .../persistence/freelist/FreeListImpl.java      |  7 ++--
 5 files changed, 107 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b6174c99/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
index e32ecc6..58e28de 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
@@ -132,6 +132,7 @@ import org.apache.ignite.internal.util.typedef.internal.SB;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.internal.util.worker.GridWorker;
 import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.lang.IgniteOutClosure;
 import org.apache.ignite.mxbean.PersistenceMetricsMXBean;
 import org.apache.ignite.thread.IgniteThread;
 import org.apache.ignite.thread.IgniteThreadPoolExecutor;
@@ -515,6 +516,33 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
     }
 
     /** {@inheritDoc} */
+    @Override protected IgniteOutClosure<Float> fillFactorProvider(final String memPlcName)
{
+        return new IgniteOutClosure<Float>() {
+            @Override public Float apply() {
+                long loadSize = 0L;
+                long totalSize = 0L;
+
+                for (CacheGroupContext grpCtx : cctx.cache().cacheGroups()) {
+                    if (!grpCtx.memoryPolicy().config().getName().equals(memPlcName))
+                        continue;
+
+                    assert grpCtx.offheap() instanceof GridCacheOffheapManager;
+
+                    T2<Long, Long> fillFactor = ((GridCacheOffheapManager)grpCtx.offheap()).fillFactor();
+
+                    loadSize += fillFactor.get1();
+                    totalSize += fillFactor.get2();
+                }
+
+                if (totalSize == 0)
+                    return (float) 0;
+
+                return (float) loadSize / totalSize;
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
     @Override public void readCheckpointAndRestoreMemory(List<DynamicCacheDescriptor>
cachesToStart) throws IgniteCheckedException {
         checkpointReadLock();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6174c99/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java
index 83a9f55..5cd12af 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java
@@ -66,6 +66,7 @@ import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.lang.GridCursor;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
@@ -597,6 +598,32 @@ public class GridCacheOffheapManager extends IgniteCacheOffheapManagerImpl
imple
     }
 
     /**
+     * Calculates fill factor of all partition data stores.
+     *
+     * @return Tuple (numenator, denominator).
+     */
+    T2<Long, Long> fillFactor() {
+        long loadSize = 0;
+        long totalSize = 0;
+
+        for (CacheDataStore store : partDataStores.values()) {
+            assert store instanceof GridCacheDataStore;
+
+            FreeListImpl freeList = ((GridCacheDataStore)store).freeList;
+
+            if (freeList == null)
+                continue;
+
+            T2<Long, Long> fillFactor = freeList.fillFactor();
+
+            loadSize += fillFactor.get1();
+            totalSize += fillFactor.get2();
+        }
+
+        return new T2<>(loadSize, totalSize);
+    }
+
+    /**
      *
      */
     private static class RebalanceIteratorAdapter implements IgniteRebalanceIterator {

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6174c99/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
index e07c51e..69feac8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
@@ -55,9 +55,11 @@ import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList
 import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList;
 import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
 import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.internal.LT;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.lang.IgniteOutClosure;
 import org.apache.ignite.mxbean.MemoryMetricsMXBean;
 import org.jetbrains.annotations.Nullable;
 
@@ -175,8 +177,6 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
                     0L,
                     true);
 
-            memMetrics.freeList(freeList);
-
             freeListMap.put(memPlcCfg.getName(), freeList);
         }
 
@@ -273,7 +273,7 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
         if (dfltMemPlcName == null)
             dfltMemPlcName = DFLT_MEM_PLC_DEFAULT_NAME;
 
-        MemoryMetricsImpl memMetrics = new MemoryMetricsImpl(memPlcCfg);
+        MemoryMetricsImpl memMetrics = new MemoryMetricsImpl(memPlcCfg, fillFactorProvider(memPlcName));
 
         MemoryPolicy memPlc = initMemory(memCfg, memPlcCfg, memMetrics);
 
@@ -289,6 +289,36 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     }
 
     /**
+     * Closure that can be used to compute fill factor for provided memory policy.
+     *
+     * @param memPlcName Memory policy name.
+     * @return Closure.
+     */
+    protected IgniteOutClosure<Float> fillFactorProvider(final String memPlcName) {
+        return new IgniteOutClosure<Float>() {
+            private FreeListImpl freeList;
+
+            @Override public Float apply() {
+                if (freeList == null) {
+                    FreeListImpl freeList0 = freeListMap.get(memPlcName);
+
+                    if (freeList0 == null)
+                        return (float) 0;
+
+                    freeList = freeList0;
+                }
+
+                T2<Long, Long> fillFactor = freeList.fillFactor();
+
+                if (fillFactor.get2() == 0)
+                    return (float) 0;
+
+                return (float) fillFactor.get1() / fillFactor.get2();
+            }
+        };
+    }
+
+    /**
      * @param memPlcsCfgs User-defined memory policy configurations.
      */
     private boolean hasCustomDefaultMemoryPolicy(MemoryPolicyConfiguration[] memPlcsCfgs)
{

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6174c99/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsImpl.java
index 271767c..3261874 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/MemoryMetricsImpl.java
@@ -19,9 +19,10 @@ package org.apache.ignite.internal.processors.cache.persistence;
 import org.apache.ignite.MemoryMetrics;
 import org.apache.ignite.configuration.MemoryPolicyConfiguration;
 import org.apache.ignite.internal.pagemem.PageMemory;
-import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeListImpl;
 import org.apache.ignite.internal.processors.cache.ratemetrics.HitRateMetrics;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteOutClosure;
+import org.jetbrains.annotations.Nullable;
 import org.jsr166.LongAdder8;
 
 /**
@@ -29,7 +30,7 @@ import org.jsr166.LongAdder8;
  */
 public class MemoryMetricsImpl implements MemoryMetrics {
     /** */
-    private FreeListImpl freeList;
+    private final IgniteOutClosure<Float> fillFactorProvider;
 
     /** */
     private final LongAdder8 totalAllocatedPages = new LongAdder8();
@@ -68,9 +69,17 @@ public class MemoryMetricsImpl implements MemoryMetrics {
 
     /**
      * @param memPlcCfg MemoryPolicyConfiguration.
-     */
+    */
     public MemoryMetricsImpl(MemoryPolicyConfiguration memPlcCfg) {
+        this(memPlcCfg, null);
+    }
+
+    /**
+     * @param memPlcCfg MemoryPolicyConfiguration.
+     */
+    public MemoryMetricsImpl(MemoryPolicyConfiguration memPlcCfg, @Nullable IgniteOutClosure<Float>
fillFactorProvider) {
         this.memPlcCfg = memPlcCfg;
+        this.fillFactorProvider = fillFactorProvider;
 
         metricsEnabled = memPlcCfg.isMetricsEnabled();
 
@@ -114,10 +123,10 @@ public class MemoryMetricsImpl implements MemoryMetrics {
 
     /** {@inheritDoc} */
     @Override public float getPagesFillFactor() {
-        if (!metricsEnabled || freeList == null)
+        if (!metricsEnabled || fillFactorProvider == null)
             return 0;
 
-        return freeList.fillFactor();
+        return fillFactorProvider.apply();
     }
 
     /** {@inheritDoc} */
@@ -274,11 +283,4 @@ public class MemoryMetricsImpl implements MemoryMetrics {
         allocRate = new HitRateMetrics((int) rateTimeInterval, subInts);
         pageReplaceRate = new HitRateMetrics((int) rateTimeInterval, subInts);
     }
-
-    /**
-     * @param freeList Free list.
-     */
-    void freeList(FreeListImpl freeList) {
-        this.freeList = freeList;
-    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6174c99/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeListImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeListImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeListImpl.java
index 53a33c1..3eb62ae 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeListImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/FreeListImpl.java
@@ -41,6 +41,7 @@ import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO;
 import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag;
 import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList;
 import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler;
+import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.internal.U;
 
 /**
@@ -359,8 +360,10 @@ public class FreeListImpl extends PagesList implements FreeList, ReuseList
{
 
     /**
      * Calculates average fill factor over FreeListImpl instance.
+     *
+     * @return Tuple (numenator, denominator).
      */
-    public float fillFactor() {
+    public T2<Long, Long> fillFactor() {
         long pageSize = pageSize();
 
         long totalSize = 0;
@@ -376,7 +379,7 @@ public class FreeListImpl extends PagesList implements FreeList, ReuseList
{
             totalSize += pages * pageSize;
         }
 
-        return totalSize == 0 ? -1L : ((float) loadSize / totalSize);
+        return totalSize == 0 ? new T2<>(0L, 0L) : new T2<>(loadSize, totalSize);
     }
 
     /** {@inheritDoc} */


Mime
View raw message