Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 27FDD200B84 for ; Tue, 20 Sep 2016 16:11:39 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 26847160AC5; Tue, 20 Sep 2016 14:11:39 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1B409160AA9 for ; Tue, 20 Sep 2016 16:11:37 +0200 (CEST) Received: (qmail 28885 invoked by uid 500); 20 Sep 2016 14:11:37 -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 28876 invoked by uid 99); 20 Sep 2016 14:11:37 -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; Tue, 20 Sep 2016 14:11:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2FC66E02DA; Tue, 20 Sep 2016 14:11:37 +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 Message-Id: <036bd12333854ed0a8e4466461aa32b6@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ignite git commit: ignite-2714 Cleanup GridOffHeapPartitionedMap when cache is destroyed Date: Tue, 20 Sep 2016 14:11:37 +0000 (UTC) archived-at: Tue, 20 Sep 2016 14:11:39 -0000 Repository: ignite Updated Branches: refs/heads/master f6d42f3e3 -> 78c371208 ignite-2714 Cleanup GridOffHeapPartitionedMap when cache is destroyed Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/78c37120 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/78c37120 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/78c37120 Branch: refs/heads/master Commit: 78c3712085e3cd617c659b9f3c2c8e93741a61d7 Parents: f6d42f3e Author: Andrey Martianov Authored: Tue Sep 20 17:11:23 2016 +0300 Committer: sboikov Committed: Tue Sep 20 17:11:23 2016 +0300 ---------------------------------------------------------------------- .../processors/cache/GridCacheSwapManager.java | 7 + .../offheap/GridOffHeapProcessor.java | 14 ++ .../cache/GridCacheOffHeapCleanupTest.java | 169 +++++++++++++++++++ .../testsuites/IgniteCacheTestSuite5.java | 3 + 4 files changed, 193 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/78c37120/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 fd0b471..8ba960a 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 @@ -138,6 +138,13 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter { initOffHeap(); } + + /** {@inheritDoc} */ + @Override protected void stop0(boolean cancel) { + if (offheapEnabled) + offheap.destruct(spaceName); + } + /** * */ http://git-wip-us.apache.org/repos/asf/ignite/blob/78c37120/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java index d9d4421..912b826 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java @@ -78,6 +78,20 @@ public class GridOffHeapProcessor extends GridProcessorAdapter { old.destruct(); } + /** + * Destructs offheap map for given space name. + * + * @param spaceName Space name. + * */ + public void destruct(@Nullable String spaceName) { + spaceName = maskNull(spaceName); + + GridOffHeapPartitionedMap map = offheap.remove(spaceName); + + if (map != null) + map.destruct(); + } + /** {@inheritDoc} */ @Override public void stop(boolean cancel) throws IgniteCheckedException { super.stop(cancel); http://git-wip-us.apache.org/repos/asf/ignite/blob/78c37120/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapCleanupTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapCleanupTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapCleanupTest.java new file mode 100644 index 0000000..ae94073 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapCleanupTest.java @@ -0,0 +1,169 @@ +/* + * 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 org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheMemoryMode; +import org.apache.ignite.cache.eviction.EvictionPolicy; +import org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED; +import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_VALUES; +import static org.apache.ignite.cache.CacheMemoryMode.ONHEAP_TIERED; + +/** + * Check offheap allocations are freed after cache destroy. + */ +public class GridCacheOffHeapCleanupTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String CACHE_NAME = "testCache"; + + /** Memory mode. */ + private CacheMemoryMode memoryMode; + + /** Eviction policy. */ + private EvictionPolicy evictionPlc; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + return cfg; + } + + /** + * Checks offheap resources are freed after cache destroy - ONHEAP_TIERED memory mode + * + * @throws Exception If failed. + */ + public void testCleanupOffheapAfterCacheDestroyOnheapTiered() throws Exception { + memoryMode = ONHEAP_TIERED; + + FifoEvictionPolicy evictionPlc0 = new FifoEvictionPolicy(); + evictionPlc0.setMaxSize(1); + + evictionPlc = evictionPlc0; + + checkCleanupOffheapAfterCacheDestroy(); + } + + /** + * Checks offheap resources are freed after cache destroy - OFFHEAP_TIERED memory mode + * + * @throws Exception If failed. + */ + public void testCleanupOffheapAfterCacheDestroyOffheapTiered() throws Exception { + memoryMode = OFFHEAP_TIERED; + evictionPlc = null; + + checkCleanupOffheapAfterCacheDestroy(); + } + + /** + * TODO: IGNITE-2714. + * + * Checks offheap resources are freed after cache destroy - OFFHEAP_VALUES memory mode + * + * @throws Exception If failed. + */ + public void _testCleanupOffheapAfterCacheDestroyOffheapValues() throws Exception { + memoryMode = OFFHEAP_VALUES; + evictionPlc = null; + + try (Ignite g = startGrid(0)) { + IgniteCache cache = g.getOrCreateCache(createCacheConfiguration()); + + cache.put(1, "value_1"); + cache.put(2, "value_2"); + + GridCacheContext ctx = GridTestUtils.cacheContext(cache); + GridUnsafeMemory unsafeMemory = ctx.unsafeMemory(); + + g.destroyCache(null); + + if (unsafeMemory != null) + assertEquals("Unsafe memory not freed", 0, unsafeMemory.allocatedSize()); + } + } + + /** + * Creates cache configuration. + * + * @return cache configuration. + * */ + private CacheConfiguration createCacheConfiguration() { + CacheConfiguration ccfg = new CacheConfiguration<>(); + + ccfg.setName(CACHE_NAME); + ccfg.setOffHeapMaxMemory(0); + ccfg.setMemoryMode(memoryMode); + ccfg.setEvictionPolicy(evictionPlc); + + return ccfg; + } + + /** + * Check offheap resources are freed after cache destroy. + * + * @throws Exception If failed. + */ + private void checkCleanupOffheapAfterCacheDestroy() throws Exception { + final String spaceName = "gg-swap-cache-" + CACHE_NAME; + + try (Ignite g = startGrid(0)) { + checkOffheapAllocated(spaceName, false); + + IgniteCache cache = g.getOrCreateCache(createCacheConfiguration()); + + cache.put(1, "value_1"); + cache.put(2, "value_2"); + + checkOffheapAllocated(spaceName, true); + + g.destroyCache(cache.getName()); + + checkOffheapAllocated(spaceName, false); + } + } + + /** + * Check is offheap allocated for given space name using internal API. + * + * @param spaceName Space name. + * @param allocated true, if we expected that offheap is allocated; false, otherwise. + * @throws Exception If failed. + * */ + private void checkOffheapAllocated(String spaceName, boolean allocated) throws Exception { + long offheapSize = grid(0).context().offheap().allocatedSize(spaceName); + + assertEquals("Unexpected offheap allocated size", allocated, (offheapSize >= 0)); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/78c37120/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java index 7582f5c..7f0e23c 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java @@ -25,6 +25,7 @@ import org.apache.ignite.internal.processors.cache.EntryVersionConsistencyReadTh import org.apache.ignite.internal.processors.cache.IgniteCachePutStackOverflowSelfTest; import org.apache.ignite.internal.processors.cache.IgniteCacheReadThroughEvictionsVariationsSuite; import org.apache.ignite.internal.processors.cache.IgniteCacheStoreCollectionTest; +import org.apache.ignite.internal.processors.cache.GridCacheOffHeapCleanupTest; import org.apache.ignite.internal.processors.cache.distributed.CacheLateAffinityAssignmentFairAffinityTest; import org.apache.ignite.internal.processors.cache.distributed.CacheLateAffinityAssignmentNodeJoinValidationTest; import org.apache.ignite.internal.processors.cache.distributed.CacheLateAffinityAssignmentTest; @@ -59,6 +60,8 @@ public class IgniteCacheTestSuite5 extends TestSuite { suite.addTest(IgniteCacheReadThroughEvictionsVariationsSuite.suite()); suite.addTestSuite(IgniteCacheTxIteratorSelfTest.class); + suite.addTestSuite(GridCacheOffHeapCleanupTest.class); + return suite; } }