ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [29/50] [abbrv] ignite git commit: ignite-3560 Offheap resources cleanup on H2 table destroy.
Date Thu, 28 Jul 2016 11:06:54 GMT
ignite-3560 Offheap resources cleanup on H2 table destroy.


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

Branch: refs/heads/ignite-3553
Commit: 44cabd84152b5d956666b6c906eb43763ab7d72f
Parents: 856b536
Author: sboikov <sboikov@gridgain.com>
Authored: Tue Jul 26 10:41:50 2016 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Tue Jul 26 10:41:50 2016 +0300

----------------------------------------------------------------------
 .../processors/query/h2/IgniteH2Indexing.java   |  31 ++--
 .../cache/CacheIndexingOffheapCleanupTest.java  | 178 +++++++++++++++++++
 .../IgniteCacheWithIndexingTestSuite.java       |   2 +
 3 files changed, 196 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/44cabd84/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 535881e..e1b21e2 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -735,8 +735,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             U.close(stmt, log);
         }
 
-        if (tbl.luceneIdx != null)
-            U.closeQuiet(tbl.luceneIdx);
+        tbl.onDrop();
 
         tbl.schema.tbls.remove(tbl.name());
     }
@@ -1816,12 +1815,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
 //        unregisterMBean(); TODO https://issues.apache.org/jira/browse/IGNITE-2139
 
-        for (Schema schema : schemas.values()) {
-            for (TableDescriptor desc : schema.tbls.values()) {
-                if (desc.luceneIdx != null)
-                    U.closeQuiet(desc.luceneIdx);
-            }
-        }
+        for (Schema schema : schemas.values())
+            schema.onDrop();
 
         for (Connection c : conns)
             U.close(c, log);
@@ -2436,6 +2431,17 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         }
 
         /**
+         *
+         */
+        void onDrop() {
+            dataTables.remove(tbl.identifier(), tbl);
+
+            tbl.destroy();
+
+            U.closeQuiet(luceneIdx);
+        }
+
+        /**
          * @param tbl Table.
          * @param idxName Index name.
          * @param cols Columns.
@@ -2668,13 +2674,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
          * Called after the schema was dropped.
          */
         public void onDrop() {
-            for (TableDescriptor tblDesc : tbls.values()) {
-                GridH2Table tbl = tblDesc.tbl;
-
-                dataTables.remove(tbl.identifier(), tbl);
-
-                tbl.destroy();
-            }
+            for (TableDescriptor tblDesc : tbls.values())
+                tblDesc.onDrop();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/44cabd84/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIndexingOffheapCleanupTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIndexingOffheapCleanupTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIndexingOffheapCleanupTest.java
new file mode 100644
index 0000000..3d7e30a
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIndexingOffheapCleanupTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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.Map;
+import java.util.concurrent.ThreadLocalRandom;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.cache.query.annotations.QueryTextField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
+
+/**
+ *
+ */
+public class CacheIndexingOffheapCleanupTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        startGrid(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        super.afterTest();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCacheDestroy() throws Exception {
+        Ignite ignite = ignite(0);
+
+        for (int i = 0; i < 5; i++) {
+            log.info("Iteration: " + i);
+
+            IgniteCache cache = ignite.createCache(cacheConfiguration());
+
+            for (int k = 0; k < 100; k++)
+                cache.put(k, new TestType());
+
+            GridUnsafeMemory mem = schemaMemory(ignite, cache.getName());
+
+            assertTrue(mem.allocatedSize() > 0);
+
+            ignite.destroyCache(cache.getName());
+
+            assertEquals(0, mem.allocatedSize());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStopNode() throws Exception {
+        Ignite ignite = ignite(0);
+
+        IgniteCache cache = ignite.createCache(cacheConfiguration());
+
+        for (int k = 0; k < 100; k++)
+            cache.put(k, new TestType());
+
+        GridUnsafeMemory mem = schemaMemory(ignite, cache.getName());
+
+        assertTrue(mem.allocatedSize() > 0);
+
+        stopGrid(0);
+
+        assertEquals(0, mem.allocatedSize());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testUndeploy() throws Exception {
+        Ignite ignite = ignite(0);
+
+        IgniteCache cache = ignite.createCache(cacheConfiguration());
+
+        for (int k = 0; k < 100; k++)
+            cache.put(k, new TestType());
+
+        GridUnsafeMemory mem = schemaMemory(ignite, cache.getName());
+
+        assertTrue(mem.allocatedSize() > 0);
+
+        ((IgniteKernal)ignite).context().query().onUndeploy("cache", U.detectClassLoader(TestType.class));
+
+        assertEquals(0, mem.allocatedSize());
+    }
+
+    /**
+     * @param ignite Node.
+     * @param cacheName Cache name.
+     * @return Memory.
+     */
+    private GridUnsafeMemory schemaMemory(Ignite ignite, String cacheName) {
+        Map<String, Object> schemas = GridTestUtils.getFieldValue(((IgniteKernal)ignite).context().query(),
+            "idx",
+            "schemas");
+
+        assertNotNull(schemas);
+
+        Object schema = schemas.get("\"" + cacheName + "\"");
+
+        assertNotNull(schema);
+
+        GridUnsafeMemory mem = GridTestUtils.getFieldValue(schema, "offheap");
+
+        assertNotNull(mem);
+
+        return mem;
+    }
+
+    /**
+     * @return Cache configuration.
+     */
+    private CacheConfiguration cacheConfiguration() {
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        ccfg.setName("cache");
+        ccfg.setMemoryMode(OFFHEAP_TIERED);
+        ccfg.setIndexedTypes(Integer.class, TestType.class);
+
+        return ccfg;
+    }
+
+    /**
+     *
+     */
+    static class TestType {
+        /** */
+        @QuerySqlField(index = true)
+        private int v1;
+
+        /** */
+        @QuerySqlField(index = true)
+        private String v2;
+
+        /** */
+        @QueryTextField
+        private String v3;
+
+        /**
+         *
+         */
+        public TestType() {
+            int v = ThreadLocalRandom.current().nextInt();
+
+            v1 = v;
+            v2 = String.valueOf(v);
+            v3 = v2;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/44cabd84/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
index a85b7a6..5cdd744 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
@@ -20,6 +20,7 @@ package org.apache.ignite.testsuites;
 import junit.framework.TestSuite;
 import org.apache.ignite.internal.processors.cache.CacheConfigurationP2PTest;
 import org.apache.ignite.internal.processors.cache.CacheIndexStreamerTest;
+import org.apache.ignite.internal.processors.cache.CacheIndexingOffheapCleanupTest;
 import org.apache.ignite.internal.processors.cache.CacheOperationsWithExpirationTest;
 import org.apache.ignite.internal.processors.cache.CacheRandomOperationsMultithreadedTest;
 import org.apache.ignite.internal.processors.cache.GridCacheOffHeapAndSwapSelfTest;
@@ -76,6 +77,7 @@ public class IgniteCacheWithIndexingTestSuite extends TestSuite {
         suite.addTestSuite(CacheRandomOperationsMultithreadedTest.class);
         suite.addTestSuite(IgniteCacheStarvationOnRebalanceTest.class);
         suite.addTestSuite(CacheOperationsWithExpirationTest.class);
+        suite.addTestSuite(CacheIndexingOffheapCleanupTest.class);
 
         return suite;
     }


Mime
View raw message