You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/02/10 12:56:31 UTC

[44/50] [abbrv] ignite git commit: IGNITE-2509 - Fixed evictions for OFFHEAP_VALUES memory mode - Fixes #452.

IGNITE-2509 - Fixed evictions for OFFHEAP_VALUES memory mode - Fixes #452.

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


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

Branch: refs/heads/ignite-1786
Commit: e2e216d7f1295dd350cc2e98a5b704e27aa92a41
Parents: fa246cd
Author: vershov <ve...@gridgain.com>
Authored: Mon Feb 8 21:54:48 2016 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Mon Feb 8 21:54:48 2016 +0300

----------------------------------------------------------------------
 .../cache/CacheEvictableEntryImpl.java          |   4 +-
 .../GridCacheOffHeapValuesEvictionSelfTest.java | 171 +++++++++++++++++++
 .../ignite/testsuites/IgniteCacheTestSuite.java |   2 +
 3 files changed, 175 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e2e216d7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
index 7cea4f6..9f4d9d7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
@@ -103,7 +103,7 @@ public class CacheEvictableEntryImpl<K, V> implements EvictableEntry<K, V> {
 
             byte[] valBytes = null;
 
-            if (cctx.useOffheapEntry())
+            if (cctx.offheapTiered())
                 valBytes = cctx.offheap().get(cctx.swap().spaceName(), cached.partition(), key, keyBytes);
             else {
                 CacheObject cacheObj = cached.valueBytes();
@@ -231,4 +231,4 @@ public class CacheEvictableEntryImpl<K, V> implements EvictableEntry<K, V> {
     @Override public String toString() {
         return S.toString(CacheEvictableEntryImpl.class, this);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2e216d7/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
new file mode 100644
index 0000000..9baab33
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapValuesEvictionSelfTest.java
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheMemoryMode;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+
+/**
+ * Test for eviction with offHeap.
+ */
+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;
+
+    @Override protected int gridCount() {
+        return 1;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutOnHeap() throws Exception {
+        CacheConfiguration<Integer, Object> ccfg = cacheConfiguration(grid(0).name());
+        ccfg.setName("testPutOffHeapValues");
+        ccfg.setStatisticsEnabled(true);
+        ccfg.setOffHeapMaxMemory(MAX_MEMORY_SIZE);
+
+        FifoEvictionPolicy plc = new FifoEvictionPolicy();
+        plc.setMaxMemorySize(MAX_MEMORY_SIZE);
+
+        ccfg.setSwapEnabled(true);
+        ccfg.setMemoryMode(CacheMemoryMode.OFFHEAP_VALUES);
+
+        ccfg.setEvictionPolicy(plc);
+
+        final IgniteCache<Integer, Object> cache = grid(0).getOrCreateCache(ccfg);
+
+        fillCache(cache, getTestTimeout());
+
+        assertEquals(VALS_AMOUNT * THREAD_COUNT, cache.size(CachePeekMode.ALL));
+        assertEquals(0, cache.size(CachePeekMode.NEAR));
+        assertEquals(0, cache.size(CachePeekMode.OFFHEAP));
+        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));
+    }
+
+    /**
+     * swap disabled -> entries discarded
+     * @throws Exception If failed.
+     */
+    public void testPutOnHeapWithOffHeap() throws Exception {
+        final int PLC_MAX_SIZE = 50;
+
+        CacheConfiguration<Integer, Object> ccfg = cacheConfiguration(grid(0).name());
+        ccfg.setName("testPutOnHeapWithOffHeap");
+        ccfg.setStatisticsEnabled(true);
+        ccfg.setOffHeapMaxMemory(MAX_MEMORY_SIZE);
+
+        FifoEvictionPolicy plc = new FifoEvictionPolicy();
+        plc.setMaxMemorySize(MAX_MEMORY_SIZE);
+        plc.setMaxSize(PLC_MAX_SIZE);
+
+        ccfg.setSwapEnabled(false);
+        ccfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED);
+
+        ccfg.setEvictionPolicy(plc);
+
+        final IgniteCache<Integer, Object> cache = grid(0).getOrCreateCache(ccfg);
+
+        fillCache(cache, getTestTimeout());
+
+        assertEquals(cache.size(CachePeekMode.ONHEAP) + cache.size(CachePeekMode.OFFHEAP), cache.size(CachePeekMode.ALL));
+        assertEquals(0, cache.size(CachePeekMode.NEAR));
+        assertEquals(0, cache.size(CachePeekMode.SWAP));
+        assertTrue(PLC_MAX_SIZE >= cache.size(CachePeekMode.ONHEAP));
+        assertTrue(PLC_MAX_SIZE - 5 <= cache.size(CachePeekMode.ONHEAP));
+        assertTrue(MAX_VALS_AMOUNT >= cache.size(CachePeekMode.OFFHEAP));
+        assertTrue(MAX_VALS_AMOUNT - 5 <= cache.size(CachePeekMode.OFFHEAP));
+        assertEquals(cache.size(CachePeekMode.ALL) - cache.size(CachePeekMode.ONHEAP) - cache.size(CachePeekMode.OFFHEAP),
+            cache.size(CachePeekMode.SWAP));
+
+        assertTrue((MAX_VALS_AMOUNT + 5) * VAL_SIZE > cache.metrics().getOffHeapAllocatedSize());
+        assertTrue((MAX_VALS_AMOUNT - 5) * VAL_SIZE < cache.metrics().getOffHeapAllocatedSize());
+    }
+
+    /**
+     * swap enabled -> entries are not discarded
+     * @throws Exception
+     */
+    public void testOnHeapWithOffHeapSwap() throws Exception{
+        final int PLC_MAX_SIZE = 50;
+
+        CacheConfiguration<Integer, Object> ccfg = cacheConfiguration(grid(0).name());
+        ccfg.setName("testOnHeapWithOffHeapSwap");
+        ccfg.setStatisticsEnabled(true);
+        ccfg.setOffHeapMaxMemory(MAX_MEMORY_SIZE);
+
+        FifoEvictionPolicy plc = new FifoEvictionPolicy();
+        plc.setMaxMemorySize(MAX_MEMORY_SIZE);
+        plc.setMaxSize(PLC_MAX_SIZE);
+
+        ccfg.setSwapEnabled(true);
+        ccfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED);
+
+        ccfg.setEvictionPolicy(plc);
+
+        final IgniteCache<Integer, Object> cache = grid(0).getOrCreateCache(ccfg);
+
+        fillCache(cache, getTestTimeout());
+
+        assertEquals(cache.size(CachePeekMode.SWAP) + cache.size(CachePeekMode.ONHEAP) +
+            cache.size(CachePeekMode.OFFHEAP), cache.size(CachePeekMode.ALL));
+
+        assertTrue(PLC_MAX_SIZE >= cache.size(CachePeekMode.ONHEAP));
+        assertTrue(PLC_MAX_SIZE - 5 <= cache.size(CachePeekMode.ONHEAP));
+        assertTrue(MAX_VALS_AMOUNT >= cache.size(CachePeekMode.OFFHEAP));
+        assertTrue(MAX_VALS_AMOUNT - 5 <= cache.size(CachePeekMode.OFFHEAP));
+
+        assertTrue((MAX_VALS_AMOUNT + 5) * VAL_SIZE > cache.metrics().getOffHeapAllocatedSize());
+        assertTrue((MAX_VALS_AMOUNT - 5) * VAL_SIZE < cache.metrics().getOffHeapAllocatedSize());
+    }
+
+    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);
+
+        GridTestUtils.runMultiThreaded(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                final int start = keyStart.addAndGet(VALS_AMOUNT);
+
+                for (int i = start; i < start + VALS_AMOUNT; i++)
+                    cache.put(i, val);
+
+                latch.countDown();
+
+                return null;
+            }
+        }, THREAD_COUNT, "test");
+
+        latch.await(timeout, TimeUnit.MILLISECONDS);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2e216d7/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index 88d0834..90125b1 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -65,6 +65,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredAtomicS
 import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
 import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
 import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapValuesEvictionSelfTest;
 import org.apache.ignite.internal.processors.cache.GridCacheP2PUndeploySelfTest;
 import org.apache.ignite.internal.processors.cache.GridCachePartitionedLocalStoreSelfTest;
 import org.apache.ignite.internal.processors.cache.GridCachePartitionedOffHeapLocalStoreSelfTest;
@@ -247,6 +248,7 @@ public class IgniteCacheTestSuite extends TestSuite {
         suite.addTestSuite(GridCacheStorePutxSelfTest.class);
         suite.addTestSuite(GridCacheOffHeapMultiThreadedUpdateSelfTest.class);
         suite.addTestSuite(GridCacheOffHeapAtomicMultiThreadedUpdateSelfTest.class);
+        suite.addTestSuite(GridCacheOffHeapValuesEvictionSelfTest.class);
         suite.addTestSuite(GridCacheColocatedTxStoreExceptionSelfTest.class);
         suite.addTestSuite(GridCacheReplicatedTxStoreExceptionSelfTest.class);
         suite.addTestSuite(GridCacheLocalTxStoreExceptionSelfTest.class);