ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [01/18] ignite git commit: IGNITE-2509 - Fixed offheap metrics - Fixes #470.
Date Mon, 15 Feb 2016 13:35:25 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-2604 9dc37255d -> 155af4982


IGNITE-2509 - Fixed offheap metrics - Fixes #470.

Signed-off-by: Alexey Goncharuk <alexey.goncharuk@gmail.com>


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

Branch: refs/heads/ignite-2604
Commit: 763bf578e9f510e50bdfa6b9e51ea25348bfd2e9
Parents: 35b0e6b
Author: vershov <vershov@gridgain.com>
Authored: Fri Feb 12 12:51:50 2016 +0300
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Fri Feb 12 12:51:50 2016 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/cache/CacheMemoryMode.java   |  2 ++
 .../processors/cache/GridCacheAdapter.java         |  7 +++++++
 .../processors/cache/GridCacheSwapManager.java     |  3 ++-
 .../internal/GridAffinityNoCacheSelfTest.java      |  4 +++-
 .../GridCacheOffHeapValuesEvictionSelfTest.java    | 17 +++++++++++++++--
 5 files changed, 29 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/763bf578/modules/core/src/main/java/org/apache/ignite/cache/CacheMemoryMode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheMemoryMode.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheMemoryMode.java
index a596824..0133327 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheMemoryMode.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheMemoryMode.java
@@ -56,6 +56,8 @@ public enum CacheMemoryMode {
      * Entry keys will be stored on heap memory, and values will be stored in offheap memory.
Note
      * that in this mode entries can be evicted only to swap. The evictions will happen according
      * to configured {@link EvictionPolicy}.
+     * <p/>
+     * Size returned by {@link CachePeekMode#OFFHEAP} is always zero, for this mode.
      */
     OFFHEAP_VALUES,
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/763bf578/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 84eb0b8..3fac207 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -54,6 +54,7 @@ import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cache.CacheEntry;
 import org.apache.ignite.cache.CacheInterceptor;
+import org.apache.ignite.cache.CacheMemoryMode;
 import org.apache.ignite.cache.CacheMetrics;
 import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.cache.affinity.Affinity;
@@ -4121,6 +4122,12 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K,
V
 
     /** {@inheritDoc} */
     @Override public long offHeapAllocatedSize() {
+        if (ctx.config().getMemoryMode() == CacheMemoryMode.OFFHEAP_VALUES) {
+            assert ctx.unsafeMemory() != null;
+
+            return ctx.unsafeMemory().allocatedSize();
+        }
+
         GridCacheSwapManager swapMgr = ctx.swap();
 
         return swapMgr != null ? swapMgr.offHeapAllocatedSize() : -1;

http://git-wip-us.apache.org/repos/asf/ignite/blob/763bf578/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index 37b5e15..cbf09bc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentMap;
 import javax.cache.Cache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheMemoryMode;
 import org.apache.ignite.internal.managers.swapspace.GridSwapSpaceManager;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException;
@@ -85,7 +86,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
     /** Flag to indicate if swap is enabled. */
     private boolean swapEnabled;
 
-    /** Flag to indicate if offheap is enabled. */
+    /** Flag to indicate if offheap is enabled. {@link CacheMemoryMode#OFFHEAP_VALUES} treated
as offheap disabled. */
     private boolean offheapEnabled;
 
     /** Swap listeners. */

http://git-wip-us.apache.org/repos/asf/ignite/blob/763bf578/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
index 6fb1280..5561f35 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
@@ -101,13 +101,15 @@ public class GridAffinityNoCacheSelfTest extends GridCommonAbstractTest
{
     /**
      * @param key Key.
      */
-    private void checkAffinityImplCacheDeleted(Object key) {
+    private void checkAffinityImplCacheDeleted(Object key) throws InterruptedException{
         IgniteEx grid = grid(0);
 
         final String cacheName = "cacheToBeDeleted";
 
         grid(1).getOrCreateCache(cacheName);
 
+        awaitPartitionMapExchange();
+
         Affinity<Object> affinity = grid.affinity(cacheName);
 
         assertTrue(affinity instanceof GridCacheAffinityImpl);

http://git-wip-us.apache.org/repos/asf/ignite/blob/763bf578/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapValuesEvictionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapValuesEvictionSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapValuesEvictionSelfTest.java
index 9baab33..0efd89b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapValuesEvictionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapValuesEvictionSelfTest.java
@@ -33,12 +33,18 @@ import org.apache.ignite.testframework.GridTestUtils;
  */
 public class GridCacheOffHeapValuesEvictionSelfTest extends GridCacheAbstractSelfTest {
 
+    /** */
     private static final int VAL_SIZE = 512 * 1024; // bytes
+    /** */
     private static final int MAX_VALS_AMOUNT = 100;
+    /** */
     private static final int MAX_MEMORY_SIZE = MAX_VALS_AMOUNT * VAL_SIZE;
+    /** */
     private static final int VALS_AMOUNT = MAX_VALS_AMOUNT * 2;
+    /** */
     private static final int THREAD_COUNT = 4;
 
+    /** {@inheritDoc} */
     @Override protected int gridCount() {
         return 1;
     }
@@ -46,7 +52,7 @@ public class GridCacheOffHeapValuesEvictionSelfTest extends GridCacheAbstractSel
     /**
      * @throws Exception If failed.
      */
-    public void testPutOnHeap() throws Exception {
+    public void testPutValuesOffHeap() throws Exception {
         CacheConfiguration<Integer, Object> ccfg = cacheConfiguration(grid(0).name());
         ccfg.setName("testPutOffHeapValues");
         ccfg.setStatisticsEnabled(true);
@@ -70,6 +76,10 @@ public class GridCacheOffHeapValuesEvictionSelfTest extends GridCacheAbstractSel
         assertTrue(MAX_VALS_AMOUNT >= cache.size(CachePeekMode.ONHEAP));
         assertTrue(MAX_VALS_AMOUNT - 5 <= cache.size(CachePeekMode.ONHEAP));
         assertEquals(cache.size(CachePeekMode.ALL) - cache.size(CachePeekMode.ONHEAP), cache.size(CachePeekMode.SWAP));
+
+        assertTrue((MAX_VALS_AMOUNT + 5) * VAL_SIZE > cache.metrics().getOffHeapAllocatedSize());
+        assertTrue((MAX_VALS_AMOUNT - 5) * VAL_SIZE < cache.metrics().getOffHeapAllocatedSize());
+        assertTrue(cache.metrics().getOffHeapAllocatedSize() >= cache.size(CachePeekMode.ONHEAP)
* VAL_SIZE);
     }
 
     /**
@@ -109,6 +119,7 @@ public class GridCacheOffHeapValuesEvictionSelfTest extends GridCacheAbstractSel
 
         assertTrue((MAX_VALS_AMOUNT + 5) * VAL_SIZE > cache.metrics().getOffHeapAllocatedSize());
         assertTrue((MAX_VALS_AMOUNT - 5) * VAL_SIZE < cache.metrics().getOffHeapAllocatedSize());
+        assertTrue(cache.metrics().getOffHeapAllocatedSize() >= cache.size(CachePeekMode.OFFHEAP)
* VAL_SIZE);
     }
 
     /**
@@ -146,12 +157,14 @@ public class GridCacheOffHeapValuesEvictionSelfTest extends GridCacheAbstractSel
 
         assertTrue((MAX_VALS_AMOUNT + 5) * VAL_SIZE > cache.metrics().getOffHeapAllocatedSize());
         assertTrue((MAX_VALS_AMOUNT - 5) * VAL_SIZE < cache.metrics().getOffHeapAllocatedSize());
+        assertTrue(cache.metrics().getOffHeapAllocatedSize() >= cache.size(CachePeekMode.OFFHEAP)
* VAL_SIZE);
     }
 
+    /** Fill cache with values. */
     private static void fillCache(final IgniteCache<Integer, Object> cache, long timeout)
throws Exception{
         final byte[] val = new byte[VAL_SIZE];
         final AtomicInteger keyStart = new AtomicInteger(0);
-        final CountDownLatch latch = new CountDownLatch(4);
+        final CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
 
         GridTestUtils.runMultiThreaded(new Callable<Void>() {
             @Override public Void call() throws Exception {


Mime
View raw message