ignite-5722 Cache entries stay in onheap after scan query execution for OFFHEAP_TIRED cache with expiry policy
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c0c6c2f9 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c0c6c2f9 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c0c6c2f9 Branch: refs/heads/ignite-5578 Commit: c0c6c2f9f41605820f2a9a226c6847daee1ba95d Parents: 1b2b26a Author: agura <ag...@gridgain.com> Authored: Tue Jul 11 16:24:54 2017 +0300 Committer: agura <ag...@gridgain.com> Committed: Fri Jul 14 16:11:51 2017 +0300 ---------------------------------------------------------------------- .../cache/query/GridCacheQueryManager.java | 6 +- .../ScanQueryOffheapExpiryPolicySelfTest.java | 114 +++++++++++++++++++ .../IgniteCacheQuerySelfTestSuite2.java | 3 + 3 files changed, 122 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/c0c6c2f9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java index 4307d26..f8342b3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java @@ -3035,7 +3035,11 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte entry.unswap(); - return entry.peek(true, true, topVer, expiryPlc); + CacheObject cacheObj = entry.peek(true, true, topVer, expiryPlc); + + cctx.evicts().touch(entry, topVer); + + return cacheObj; } catch (GridCacheEntryRemovedException ignore) { // No-op. http://git-wip-us.apache.org/repos/asf/ignite/blob/c0c6c2f9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/ScanQueryOffheapExpiryPolicySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/ScanQueryOffheapExpiryPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/ScanQueryOffheapExpiryPolicySelfTest.java new file mode 100644 index 0000000..080558e --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/ScanQueryOffheapExpiryPolicySelfTest.java @@ -0,0 +1,114 @@ +/* + * 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.query; + +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.query.ScanQuery; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import javax.cache.expiry.CreatedExpiryPolicy; +import javax.cache.expiry.Duration; +import java.util.concurrent.TimeUnit; + +import static org.apache.ignite.cache.CachePeekMode.OFFHEAP; +import static org.apache.ignite.cache.CachePeekMode.ONHEAP; + +/** + * + */ +public class ScanQueryOffheapExpiryPolicySelfTest extends GridCommonAbstractTest { + + /** Nodes count. */ + private static final int NODES_CNT = 2; + + /** Entries count */ + private static final int ENTRIES_CNT = 1024; + + /** CAche name. */ + private static final String CACHE_NAME = "cache"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = defaultCacheConfiguration(); + + ccfg.setName(CACHE_NAME); + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setBackups(1); + ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 10))); + + cfg.setCacheConfiguration(ccfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + startGridsMultiThreaded(NODES_CNT); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + + stopAllGrids(); + } + + /** + * @throws Exception If failed. + */ + public void testEntriesMovedFromOnHeap() throws Exception { + Ignite ignite0 = grid(0); + Ignite ignite1 = grid(1); + + IgniteCache<Integer, Integer> cache0 = ignite0.cache(CACHE_NAME); + IgniteCache<Integer, Integer> cache1 = ignite1.cache(CACHE_NAME); + + populateCache(cache0); + + assertEquals(0, cache0.localSize(ONHEAP)); + assertEquals(0, cache1.localSize(ONHEAP)); + + assertEquals(ENTRIES_CNT, cache0.localSize(OFFHEAP) + cache1.localSize(OFFHEAP)); + + cache0.query(new ScanQuery<>()).getAll(); + cache1.query(new ScanQuery<>()).getAll(); + + assertEquals(0, cache0.localSize(ONHEAP)); + assertEquals(0, cache1.localSize(ONHEAP)); + + assertEquals(ENTRIES_CNT, cache0.localSize(OFFHEAP) + cache1.localSize(OFFHEAP)); + } + + /** + * @param cache Cache instance. + */ + private static void populateCache(IgniteCache<Integer, Integer> cache) { + for (int i = 0; i < ENTRIES_CNT; i++) + cache.put(i, i); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/c0c6c2f9/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java index 4d82bf9..8fe7f77 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java @@ -34,6 +34,7 @@ import org.apache.ignite.internal.processors.cache.index.DynamicIndexPartitioned import org.apache.ignite.internal.processors.cache.index.DynamicIndexPartitionedTransactionalConcurrentSelfTest; import org.apache.ignite.internal.processors.cache.index.DynamicIndexReplicatedAtomicConcurrentSelfTest; import org.apache.ignite.internal.processors.cache.index.DynamicIndexReplicatedTransactionalConcurrentSelfTest; +import org.apache.ignite.internal.processors.cache.query.ScanQueryOffheapExpiryPolicySelfTest; import org.apache.ignite.internal.processors.query.IgniteCacheGroupsCompareQueryTest; import org.apache.ignite.internal.processors.query.IgniteCacheGroupsSqlDistributedJoinSelfTest; import org.apache.ignite.internal.processors.query.IgniteCacheGroupsSqlSegmentedIndexMultiNodeSelfTest; @@ -62,6 +63,8 @@ public class IgniteCacheQuerySelfTestSuite2 extends TestSuite { suite.addTestSuite(IgniteCacheQueryEvictsMultiThreadedSelfTest.class); + suite.addTestSuite(ScanQueryOffheapExpiryPolicySelfTest.class); + suite.addTestSuite(IgniteCacheCrossCacheJoinRandomTest.class); suite.addTestSuite(IgniteCacheClientQueryReplicatedNodeRestartSelfTest.class); suite.addTestSuite(IgniteCacheQueryNodeFailTest.class);