You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/12/08 08:34:44 UTC

[13/30] ignite git commit: IGNITE-7106 Optimized cache metrics collection.

IGNITE-7106 Optimized cache metrics collection.


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

Branch: refs/heads/ignite-zk
Commit: d75101083a19b23aaac163cc15f29abf597dad29
Parents: ac6b872
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Wed Dec 6 21:33:34 2017 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Wed Dec 6 21:33:34 2017 +0700

----------------------------------------------------------------------
 .../ignite/internal/visor/cache/VisorCache.java | 94 +++++++++++++++-----
 .../visor/node/VisorNodeDataCollectorJob.java   |  9 +-
 .../node/VisorNodeDataCollectorTaskArg.java     | 47 +++++++++-
 .../internal/visor/query/VisorQueryTaskArg.java |  2 +-
 4 files changed, 125 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d7510108/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
index 5d7dfd3..63eb13c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
@@ -88,6 +88,9 @@ public class VisorCache extends VisorDataTransferObject {
     /** Cache metrics. */
     private VisorCacheMetrics metrics;
 
+    /** Cache system state. */
+    private boolean sys;
+
     /**
      * Create data transfer object for given cache.
      */
@@ -99,9 +102,10 @@ public class VisorCache extends VisorDataTransferObject {
      * Create data transfer object for given cache.
      *
      * @param ca Internal cache.
+     * @param collectMetrics Collect cache metrics flag.
      * @throws IgniteCheckedException If failed to create data transfer object.
      */
-    public VisorCache(IgniteEx ignite, GridCacheAdapter ca) throws IgniteCheckedException {
+    public VisorCache(IgniteEx ignite, GridCacheAdapter ca, boolean collectMetrics) throws IgniteCheckedException {
         assert ca != null;
 
         GridCacheContext cctx = ca.context();
@@ -119,28 +123,10 @@ public class VisorCache extends VisorDataTransferObject {
         partitions = ca.affinity().partitions();
         near = cctx.isNear();
 
-        metrics = new VisorCacheMetrics(ignite, name);
-    }
+        if (collectMetrics)
+            metrics = new VisorCacheMetrics(ignite, name);
 
-    /**
-     * @return New instance suitable to store in history.
-     */
-    public VisorCache history() {
-        VisorCache c = new VisorCache();
-
-        c.name = name;
-        c.mode = mode;
-        c.memorySize = memorySize;
-        c.indexesSize = indexesSize;
-        c.size = size;
-        c.nearSize = nearSize;
-        c.backupSize = backupSize;
-        c.primarySize = primarySize;
-        c.partitions = partitions;
-        c.metrics = metrics;
-        c.near = near;
-
-        return c;
+        sys = ignite.context().cache().systemCache(name);
     }
 
     /**
@@ -230,12 +216,73 @@ public class VisorCache extends VisorDataTransferObject {
     }
 
     /**
+     * @param metrics Cache metrics.
+     */
+    public void setMetrics(VisorCacheMetrics metrics) {
+        this.metrics = metrics;
+    }
+
+    /**
      * @return {@code true} if cache has near cache.
      */
     public boolean isNear() {
         return near;
     }
 
+    /**
+     * @return System cache flag.
+     */
+    public boolean isSystem() {
+        return sys;
+    }
+
+    /**
+     * @return Number of entries in cache in heap and off-heap.
+     */
+    public long size() {
+        return size + (metrics != null ? metrics.getOffHeapEntriesCount() : 0L);
+    }
+
+    /**
+     * @return Memory size allocated in off-heap.
+     */
+    public long offHeapAllocatedSize() {
+        return metrics != null ? metrics.getOffHeapAllocatedSize() : 0L;
+    }
+
+    /**
+     * @return Number of entries in heap memory.
+     */
+    public long heapEntriesCount() {
+        return metrics != null ? metrics.getHeapEntriesCount() : 0L;
+    }
+
+    /**
+     * @return Number of primary cache entries stored in off-heap memory.
+     */
+    public long offHeapPrimaryEntriesCount() {
+        return metrics != null ? metrics.getOffHeapPrimaryEntriesCount() : 0L;
+    }
+
+    /**
+     * @return Number of backup cache entries stored in off-heap memory.
+     */
+    public long offHeapBackupEntriesCount() {
+        return metrics != null ? metrics.getOffHeapBackupEntriesCount() : 0L;
+    }
+
+    /**
+     * @return Number of cache entries stored in off-heap memory.
+     */
+    public long offHeapEntriesCount() {
+        return metrics != null ? metrics.getOffHeapEntriesCount() : 0L;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte getProtocolVersion() {
+        return V2;
+    }
+
     /** {@inheritDoc} */
     @Override protected void writeExternalData(ObjectOutput out) throws IOException {
         U.writeString(out, name);
@@ -250,6 +297,7 @@ public class VisorCache extends VisorDataTransferObject {
         out.writeInt(partitions);
         out.writeBoolean(near);
         out.writeObject(metrics);
+        out.writeBoolean(sys);
     }
 
     /** {@inheritDoc} */
@@ -266,6 +314,8 @@ public class VisorCache extends VisorDataTransferObject {
         partitions = in.readInt();
         near = in.readBoolean();
         metrics = (VisorCacheMetrics)in.readObject();
+
+        sys = protoVer > V1 ? in.readBoolean() : metrics != null && metrics.isSystem();
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/d7510108/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorJob.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorJob.java
index 99d1132..7e921ad 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorJob.java
@@ -157,8 +157,11 @@ public class VisorNodeDataCollectorJob extends VisorJob<VisorNodeDataCollectorTa
         try {
             List<VisorMemoryMetrics> memoryMetrics = res.getMemoryMetrics();
 
-            for (DataRegionMetrics m : ignite.dataRegionMetrics())
-                memoryMetrics.add(new VisorMemoryMetrics(m));
+            // TODO: Should be really fixed in IGNITE-7111.
+            if (ignite.active()) {
+                for (DataRegionMetrics m : ignite.dataRegionMetrics())
+                    memoryMetrics.add(new VisorMemoryMetrics(m));
+            }
         }
         catch (Exception e) {
             res.setMemoryMetricsEx(new VisorExceptionWrapper(e));
@@ -192,7 +195,7 @@ public class VisorNodeDataCollectorJob extends VisorJob<VisorNodeDataCollectorTa
                         if (ca == null || !ca.context().started())
                             continue;
 
-                        resCaches.add(new VisorCache(ignite, ca));
+                        resCaches.add(new VisorCache(ignite, ca, arg.isCollectCacheMetrics()));
                     }
                     catch(IllegalStateException | IllegalArgumentException e) {
                         if (debug && ignite.log() != null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/d7510108/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorTaskArg.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorTaskArg.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorTaskArg.java
index c39318a..1876d06 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorTaskArg.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorNodeDataCollectorTaskArg.java
@@ -43,6 +43,9 @@ public class VisorNodeDataCollectorTaskArg extends VisorDataTransferObject {
     /** If {@code true} then collect information about system caches. */
     private boolean sysCaches;
 
+    /** If {@code false} then cache metrics will not be collected. */
+    private boolean collectCacheMetrics;
+
     /**
      * Default constructor.
      */
@@ -57,17 +60,37 @@ public class VisorNodeDataCollectorTaskArg extends VisorDataTransferObject {
      * @param evtOrderKey Event order key, unique for Visor instance.
      * @param evtThrottleCntrKey Event throttle counter key, unique for Visor instance.
      * @param sysCaches If {@code true} then collect information about system caches.
+     * @param collectCacheMetrics If {@code false} then cache metrics will not be collected.
      */
     public VisorNodeDataCollectorTaskArg(
         boolean taskMonitoringEnabled,
         String evtOrderKey,
         String evtThrottleCntrKey,
-        boolean sysCaches
+        boolean sysCaches,
+        boolean collectCacheMetrics
     ) {
         this.taskMonitoringEnabled = taskMonitoringEnabled;
         this.evtOrderKey = evtOrderKey;
         this.evtThrottleCntrKey = evtThrottleCntrKey;
         this.sysCaches = sysCaches;
+        this.collectCacheMetrics = collectCacheMetrics;
+    }
+
+    /**
+     * Create task arguments with given parameters.
+     *
+     * @param taskMonitoringEnabled If {@code true} then Visor should collect information about tasks.
+     * @param evtOrderKey Event order key, unique for Visor instance.
+     * @param evtThrottleCntrKey Event throttle counter key, unique for Visor instance.
+     * @param sysCaches If {@code true} then collect information about system caches.
+     */
+    public VisorNodeDataCollectorTaskArg(
+        boolean taskMonitoringEnabled,
+        String evtOrderKey,
+        String evtThrottleCntrKey,
+        boolean sysCaches
+    ) {
+        this(taskMonitoringEnabled, evtOrderKey, evtThrottleCntrKey, sysCaches, true);
     }
 
     /**
@@ -126,12 +149,32 @@ public class VisorNodeDataCollectorTaskArg extends VisorDataTransferObject {
         this.sysCaches = sysCaches;
     }
 
+    /**
+     * @return If {@code false} then cache metrics will not be collected.
+     */
+    public boolean isCollectCacheMetrics() {
+        return collectCacheMetrics;
+    }
+
+    /**
+     * @param collectCacheMetrics If {@code false} then cache metrics will not be collected.
+     */
+    public void setCollectCacheMetrics(boolean collectCacheMetrics) {
+        this.collectCacheMetrics = collectCacheMetrics;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte getProtocolVersion() {
+        return V2;
+    }
+
     /** {@inheritDoc} */
     @Override protected void writeExternalData(ObjectOutput out) throws IOException {
         out.writeBoolean(taskMonitoringEnabled);
         U.writeString(out, evtOrderKey);
         U.writeString(out, evtThrottleCntrKey);
         out.writeBoolean(sysCaches);
+        out.writeBoolean(collectCacheMetrics);
     }
 
     /** {@inheritDoc} */
@@ -140,6 +183,8 @@ public class VisorNodeDataCollectorTaskArg extends VisorDataTransferObject {
         evtOrderKey = U.readString(in);
         evtThrottleCntrKey = U.readString(in);
         sysCaches = in.readBoolean();
+
+        collectCacheMetrics = protoVer < V2 || in.readBoolean();
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/d7510108/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryTaskArg.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryTaskArg.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryTaskArg.java
index dd38332..e942880 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryTaskArg.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryTaskArg.java
@@ -181,7 +181,7 @@ public class VisorQueryTaskArg extends VisorDataTransferObject {
         loc = in.readBoolean();
         pageSize = in.readInt();
 
-        if (protoVer == V2)
+        if (protoVer > V1)
             lazy = in.readBoolean();
     }