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

agura pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 21d2f68  IGNITE-12197 Fixed method of getting value of persistent 
enabled in CacheGroupMetricsImpl
21d2f68 is described below

commit 21d2f6839a0e35f234b2de5b5157d49bdfe97aa7
Author: Andrey Gura <ag...@apache.org>
AuthorDate: Wed Sep 18 20:08:06 2019 +0300

    IGNITE-12197 Fixed method of getting value of persistent enabled in 
CacheGroupMetricsImpl
---
 .../processors/cache/CacheGroupMetricsImpl.java    | 45 ++++++++++------------
 .../internal/processors/metric/MetricRegistry.java |  8 ++--
 2 files changed, 24 insertions(+), 29 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsImpl.java
index 6d2253c..e82e451 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupMetricsImpl.java
@@ -27,6 +27,8 @@ import java.util.Set;
 import java.util.UUID;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
 import org.apache.ignite.internal.pagemem.store.PageStore;
 import org.apache.ignite.internal.processors.affinity.AffinityAssignment;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
@@ -40,6 +42,7 @@ import 
org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabase
 import org.apache.ignite.internal.processors.metric.MetricRegistry;
 import org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric;
 import org.apache.ignite.internal.processors.metric.impl.LongAdderMetric;
+import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.spi.metric.LongMetric;
 
 import static 
org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
@@ -58,7 +61,7 @@ public class CacheGroupMetricsImpl {
     private final CacheGroupContext ctx;
 
     /** */
-    private final LongAdderMetric groupPageAllocationTracker;
+    private final LongAdderMetric grpPageAllocationTracker;
 
     /** */
     private final LongMetric storageSize;
@@ -81,26 +84,23 @@ public class CacheGroupMetricsImpl {
     public CacheGroupMetricsImpl(CacheGroupContext ctx) {
         this.ctx = ctx;
 
+        CacheConfiguration cacheCfg = ctx.config();
+
+        DataStorageConfiguration dsCfg = 
ctx.shared().kernalContext().config().getDataStorageConfiguration();
+
+        boolean persistentEnabled = CU.isPersistentCache(cacheCfg, dsCfg);
+
         MetricRegistry mreg = 
ctx.shared().kernalContext().metric().registry(metricGroupName());
 
         mreg.register("Caches", this::getCaches, List.class, null);
 
-        if (isPDSEnabled()) {
-            mreg.register("StorageSize",
-                () -> database().forGroupPageStores(ctx, PageStore::size),
-                "Storage space allocated for group, in bytes.");
+        storageSize = mreg.register("StorageSize",
+            () -> persistentEnabled ? database().forGroupPageStores(ctx, 
PageStore::size) : 0,
+            "Storage space allocated for group, in bytes.");
 
-            mreg.register("SparseStorageSize",
-                () -> database().forGroupPageStores(ctx, 
PageStore::getSparseSize),
-                "Storage space allocated for group adjusted for possible 
sparsity, in bytes.");
-
-            storageSize = mreg.findMetric("StorageSize");
-            sparseStorageSize = mreg.findMetric("SparseStorageSize");
-        }
-        else {
-            storageSize = null;
-            sparseStorageSize = null;
-        }
+        sparseStorageSize = mreg.register("SparseStorageSize",
+            () -> persistentEnabled ? database().forGroupPageStores(ctx, 
PageStore::getSparseSize) : 0,
+            "Storage space allocated for group adjusted for possible sparsity, 
in bytes.");
 
         idxBuildCntPartitionsLeft = 
mreg.longMetric("IndexBuildCountPartitionsLeft",
             "Number of partitions need processed for finished indexes create 
or rebuilding.");
@@ -111,11 +111,11 @@ public class CacheGroupMetricsImpl {
         if (region != null) {
             DataRegionMetricsImpl dataRegionMetrics = 
ctx.dataRegion().memoryMetrics();
 
-            this.groupPageAllocationTracker =
+            grpPageAllocationTracker =
                 
dataRegionMetrics.getOrAllocateGroupPageAllocationTracker(ctx.cacheOrGroupName());
         }
         else
-            this.groupPageAllocationTracker = new LongAdderMetric("NO_OP", 
null);
+            grpPageAllocationTracker = new LongAdderMetric("NO_OP", null);
     }
 
     /** Callback for initializing metrics after topology was initialized. */
@@ -401,7 +401,7 @@ public class CacheGroupMetricsImpl {
     /** */
     public Map<Integer, List<String>> getAffinityPartitionsAssignmentMap() {
         if (ctx.affinity().lastVersion().topologyVersion() < 0)
-            return Collections.EMPTY_MAP;
+            return Collections.emptyMap();
 
         AffinityAssignment assignment = 
ctx.affinity().cachedAffinity(AffinityTopologyVersion.NONE);
 
@@ -444,7 +444,7 @@ public class CacheGroupMetricsImpl {
 
     /** */
     public long getTotalAllocatedPages() {
-        return groupPageAllocationTracker.value();
+        return grpPageAllocationTracker.value();
     }
 
     /** */
@@ -474,11 +474,6 @@ public class CacheGroupMetricsImpl {
         return (GridCacheDatabaseSharedManager)ctx.shared().database();
     }
 
-    /** @return {@code True} if persistent is enabled. */
-    private boolean isPDSEnabled() {
-        return ctx.shared().database() instanceof 
GridCacheDatabaseSharedManager;
-    }
-
     /** @return Metric group name. */
     private String metricGroupName() {
         return metricName(CACHE_GROUP_METRICS_PREFIX, ctx.cacheOrGroupName());
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/MetricRegistry.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/MetricRegistry.java
index 4a6f0f2..7dee8e4 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/MetricRegistry.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/MetricRegistry.java
@@ -42,7 +42,6 @@ import 
org.apache.ignite.internal.processors.metric.impl.ObjectGauge;
 import org.apache.ignite.internal.processors.metric.impl.ObjectMetricImpl;
 import org.apache.ignite.spi.metric.BooleanMetric;
 import org.apache.ignite.spi.metric.IntMetric;
-import org.apache.ignite.spi.metric.LongMetric;
 import org.apache.ignite.spi.metric.Metric;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -156,14 +155,15 @@ public class MetricRegistry implements Iterable<Metric> {
     }
 
     /**
-     * Registers {@link LongMetric} which value will be queried from the 
specified supplier.
+     * Registers {@link LongGauge} which value will be queried from the 
specified supplier.
      *
      * @param name Name.
      * @param supplier Supplier.
      * @param desc Description.
+     * @return Metric of type {@link LongGauge}.
      */
-    public void register(String name, LongSupplier supplier, @Nullable String 
desc) {
-        addMetric(name, new LongGauge(metricName(grpName, name), desc, 
nonThrowableSupplier(supplier, log)));
+    public LongGauge register(String name, LongSupplier supplier, @Nullable 
String desc) {
+        return addMetric(name, new LongGauge(metricName(grpName, name), desc, 
nonThrowableSupplier(supplier, log)));
     }
 
     /**

Reply via email to