You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2019/08/20 12:39:25 UTC

[ignite] branch master updated: IGNITE-12061 Fix inline size change. This closes #6770.

This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new dde8174  IGNITE-12061 Fix inline size change. This closes #6770.
dde8174 is described below

commit dde817424cbe49d80e236f3c5a3cc6c258250103
Author: zstan <st...@gmail.com>
AuthorDate: Tue Aug 20 15:39:09 2019 +0300

    IGNITE-12061 Fix inline size change. This closes #6770.
---
 .../cache/persistence/tree/BPlusTree.java          |  5 +-
 .../processors/query/h2/SchemaManager.java         |  6 ++
 .../processors/query/h2/database/H2Tree.java       |  8 ++-
 .../processors/query/h2/opt/GridH2Table.java       | 20 +++++-
 .../processors/cache/index/BasicIndexTest.java     | 80 ++++++++++++++++++++++
 .../DynamicIndexAbstractConcurrentSelfTest.java    |  7 +-
 .../cache/index/DynamicIndexAbstractSelfTest.java  | 17 +++++
 7 files changed, 136 insertions(+), 7 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
index 0850d40..a24896d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
@@ -98,6 +98,9 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
     /** Wrapper for tree pages operations. Noop by default. Override for test purposes. */
     public static volatile PageHandlerWrapper<Result> pageHndWrapper = (tree, hnd) -> hnd;
 
+    /** Destroy msg. */
+    public static final String CONC_DESTROY_MSG = "Tree is being concurrently destroyed: ";
+
     /** */
     private static volatile boolean interrupted;
 
@@ -1000,7 +1003,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
      */
     protected final void checkDestroyed() {
         if (destroyed.get())
-            throw new IllegalStateException("Tree is being concurrently destroyed: " + getName());
+            throw new IllegalStateException(CONC_DESTROY_MSG + getName());
     }
 
     /** {@inheritDoc} */
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/SchemaManager.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/SchemaManager.java
index 01c508a..25c0155 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/SchemaManager.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/SchemaManager.java
@@ -616,6 +616,12 @@ public class SchemaManager {
         throws IgniteCheckedException{
         String sql = H2Utils.indexDropSql(schemaName, idxName, ifExists);
 
+        GridH2Table tbl = dataTableForIndex(schemaName, idxName);
+
+        assert tbl != null;
+
+        tbl.setRemoveIndexOnDestroy(true);
+
         connMgr.executeStatement(schemaName, sql);
     }
 
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
index e526af1..2297b3d 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
@@ -59,6 +59,9 @@ import static org.apache.ignite.internal.processors.query.h2.database.InlineInde
  * H2 tree index implementation.
  */
 public class H2Tree extends BPlusTree<H2Row, H2Row> {
+    /** */
+    public static final String IGNITE_THROTTLE_INLINE_SIZE_CALCULATION = "IGNITE_THROTTLE_INLINE_SIZE_CALCULATION";
+
     /** Cache context. */
     private final GridCacheContext cctx;
 
@@ -105,7 +108,8 @@ public class H2Tree extends BPlusTree<H2Row, H2Row> {
     private final H2RowCache rowCache;
 
     /** How often real invocation of inline size calculation will be skipped. */
-    private static final int THROTTLE_INLINE_SIZE_CALCULATION = 1_000;
+    private final int inlineSizeThrottleThreshold =
+        IgniteSystemProperties.getInteger(IGNITE_THROTTLE_INLINE_SIZE_CALCULATION, 1_000);
 
     /** Counter of inline size calculation for throttling real invocations. */
     private final ThreadLocal<Long> inlineSizeCalculationCntr = ThreadLocal.withInitial(() -> 0L);
@@ -520,7 +524,7 @@ public class H2Tree extends BPlusTree<H2Row, H2Row> {
 
         inlineSizeCalculationCntr.set(++invokeCnt);
 
-        boolean throttle = invokeCnt % THROTTLE_INLINE_SIZE_CALCULATION != 0;
+        boolean throttle = invokeCnt % inlineSizeThrottleThreshold != 0;
 
         if (throttle)
             return;
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
index a4dfa16..dfc3e02 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
@@ -718,9 +718,8 @@ public class GridH2Table extends TableBase {
     public void update(CacheDataRow row, @Nullable CacheDataRow prevRow, boolean prevRowAvailable) throws IgniteCheckedException {
         assert desc != null;
 
-        H2CacheRow row0 = (H2CacheRow)desc.createRow(row);
-        H2CacheRow prevRow0 = prevRow != null ? (H2CacheRow)desc.createRow(prevRow) :
-            null;
+        H2CacheRow row0 = desc.createRow(row);
+        H2CacheRow prevRow0 = prevRow != null ? desc.createRow(prevRow) : null;
 
         row0.prepareValuesCache();
 
@@ -1052,6 +1051,8 @@ public class GridH2Table extends TableBase {
         lock(true);
 
         try {
+            ensureNotDestroyed();
+
             ArrayList<Index> idxs = new ArrayList<>(this.idxs);
 
             Index targetIdx = (h2Idx instanceof GridH2ProxyIndex) ?
@@ -1069,6 +1070,19 @@ public class GridH2Table extends TableBase {
                         idx.getSchema().findIndex(session, idx.getName()) != null)
                         database.removeSchemaObject(session, idx);
 
+                    GridCacheContext cctx0 = cacheInfo.cacheContext();
+
+                    if (cctx0 != null && idx instanceof GridH2IndexBase) {
+                        cctx0.shared().database().checkpointReadLock();
+
+                        try {
+                            ((GridH2IndexBase)idx).destroy(rmIndex);
+                        }
+                        finally {
+                            cctx0.shared().database().checkpointReadUnlock();
+                        }
+                    }
+
                     continue;
                 }
 
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
index 553d10a..57e7aef 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
@@ -48,10 +48,12 @@ import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.testframework.ListeningTestLogger;
 import org.apache.ignite.testframework.LogListener;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
 import org.jetbrains.annotations.Nullable;
 import org.junit.Test;
 
 import static org.apache.ignite.internal.processors.query.h2.opt.H2TableScanIndex.SCAN_INDEX_NAME_SUFFIX;
+import static org.apache.ignite.internal.processors.query.h2.database.H2Tree.IGNITE_THROTTLE_INLINE_SIZE_CALCULATION;
 
 /**
  * A set of basic tests for caches with indexes.
@@ -136,6 +138,9 @@ public class BasicIndexTest extends AbstractIndexingCommonTest {
         if (createStaticCache)
             igniteCfg.setCacheConfiguration(ccfg);
 
+        if (srvLog != null)
+            igniteCfg.setGridLogger(srvLog);
+
         if (isPersistenceEnabled) {
             igniteCfg.setDataStorageConfiguration(new DataStorageConfiguration()
                 .setDefaultDataRegionConfiguration(
@@ -763,6 +768,81 @@ public class BasicIndexTest extends AbstractIndexingCommonTest {
 
     /** */
     @Test
+    @WithSystemProperty(key = IGNITE_THROTTLE_INLINE_SIZE_CALCULATION, value = "1")
+    public void testInlineSizeChange() throws Exception {
+        isPersistenceEnabled = true;
+
+        indexes = Collections.singletonList(new QueryIndex("valStr"));
+
+        inlineSize = 33;
+
+        srvLog = new ListeningTestLogger(false, log);
+
+        String msg1 = "curSize=1";
+
+        String msg2 = "curSize=2";
+
+        String msg3 = "curSize=3";
+
+        LogListener lstn1 = LogListener.matches(msg1).build();
+
+        LogListener lstn2 = LogListener.matches(msg2).build();
+
+        LogListener lstn3 = LogListener.matches(msg3).build();
+
+        srvLog.registerListener(lstn1);
+
+        srvLog.registerListener(lstn2);
+
+        srvLog.registerListener(lstn3);
+
+        IgniteEx ig0 = startGrid(0);
+
+        ig0.cluster().active(true);
+
+        populateCache();
+
+        IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME);
+
+        cache.query(new SqlFieldsQuery("create index \"idx1\" on Val(valLong) INLINE_SIZE 1 PARALLEL 28"));
+
+        List<List<?>> res = cache.query(new SqlFieldsQuery("explain select * from Val where valLong > ?").setArgs(10)).getAll();
+
+        log.info("exp: " + res.get(0).get(0));
+
+        assertTrue(lstn1.check());
+
+        cache.query(new SqlFieldsQuery("drop index \"idx1\"")).getAll();
+
+        cache.query(new SqlFieldsQuery("create index \"idx1\" on Val(valLong) INLINE_SIZE 2 PARALLEL 28"));
+
+        cache.query(new SqlFieldsQuery("explain select * from Val where valLong > ?").setArgs(10)).getAll();
+
+        assertTrue(lstn2.check());
+
+        cache.query(new SqlFieldsQuery("drop index \"idx1\"")).getAll();
+
+        stopAllGrids();
+
+        ig0 = startGrid(0);
+
+        ig0.cluster().active(true);
+
+        cache = ig0.cache(DEFAULT_CACHE_NAME);
+
+        cache.query(new SqlFieldsQuery("create index \"idx1\" on Val(valLong) INLINE_SIZE 3 PARALLEL 28"));
+
+        cache.query(new SqlFieldsQuery("explain select * from Val where valLong > ?").setArgs(10)).getAll();
+
+        assertTrue(lstn3.check());
+
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** */
+    @Test
     public void testDynamicIndexesWithPersistence() throws Exception {
         isPersistenceEnabled = true;
 
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java
index 2d73d37..9672820 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java
@@ -620,7 +620,12 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde
                 while (!stopped.get()) {
                     Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
 
-                    assertSqlSimpleData(node, SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
+                    try {
+                        assertSqlSimpleData(node, SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
+                    }
+                    catch (Exception e) {
+                        awaitConcDestroyException(e);
+                    }
                 }
 
                 return null;
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java
index 7e97375..158d8c0 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java
@@ -49,6 +49,8 @@ import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.lang.IgnitePredicate;
 
+import static org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.CONC_DESTROY_MSG;
+
 /**
  * Tests for dynamic index creation.
  */
@@ -382,6 +384,21 @@ public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTes
     }
 
     /**
+     * Wait appropriate exception.
+     *
+     * @param e Exception to be processed.
+     * @throws Exception If failed.
+     */
+    protected void awaitConcDestroyException(Exception e) throws Exception {
+        for (Throwable th = e; th != null; th = th.getCause()) {
+            if (th.getMessage().contains(CONC_DESTROY_MSG))
+                return;
+        }
+
+        throw e;
+    }
+
+    /**
      * Assert SQL simple data state.
      *
      * @param node Node.