Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8977518AD2 for ; Wed, 10 Feb 2016 06:23:46 +0000 (UTC) Received: (qmail 33449 invoked by uid 500); 10 Feb 2016 06:23:46 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 33337 invoked by uid 500); 10 Feb 2016 06:23:46 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 32793 invoked by uid 99); 10 Feb 2016 06:23:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Feb 2016 06:23:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1121BE6990; Wed, 10 Feb 2016 06:23:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Wed, 10 Feb 2016 06:24:05 -0000 Message-Id: In-Reply-To: <0f8c50aa7bfb48a5b0a3a4aef358d4bc@git.apache.org> References: <0f8c50aa7bfb48a5b0a3a4aef358d4bc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [21/26] 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 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-2407 Commit: e2e216d7f1295dd350cc2e98a5b704e27aa92a41 Parents: fa246cd Author: vershov Authored: Mon Feb 8 21:54:48 2016 +0300 Committer: Alexey Goncharuk 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 implements EvictableEntry { 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 implements EvictableEntry { @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 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 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 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 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 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 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 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() { + @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);