ignite-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [ignite] agura commented on a change in pull request #5676: IGNITE-10654 Print warn message in case of index creating with already existing fields.
Date Tue, 30 Jul 2019 11:37:43 GMT
agura commented on a change in pull request #5676: IGNITE-10654 Print warn message in case
of index creating with already existing fields.
URL: https://github.com/apache/ignite/pull/5676#discussion_r308666491
 
 

 ##########
 File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
 ##########
 @@ -209,6 +256,427 @@ public void testDynamicIndexesNoPersistence() throws Exception {
         }
     }
 
+    /**
+     * Test mixed dynamic and static caches with indexes creation.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testDynamicIdxOnStaticCacheWithIdxWithoutPersistence() throws Exception {
+        runDynamicIdxOnStaticCacheWithIdx(false);
+    }
+
+    /**
+     * Test mixed dynamic and static caches with indexes creation.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testDynamicIdxOnStaticCacheWithIdxWithPersistence() throws Exception {
+        runDynamicIdxOnStaticCacheWithIdx(true);
+    }
+
+    /** */
+    private void runDynamicIdxOnStaticCacheWithIdx(boolean persistEnabled) throws Exception
{
+        isPersistenceEnabled = persistEnabled;
+
+        inlineSize = 10;
+
+        createIdx = false;
+
+        indexes = Collections.singletonList(new QueryIndex("valStr"));
+
+        IgniteEx ig0 = startGrid(0);
+
+        createIdx = true;
+
+        startGrid(1);
+
+        if (persistEnabled)
+            ig0.cluster().active(true);
+
+        IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME);
+
+        populateCache();
+
+        String plan = cache.query(new SqlFieldsQuery("explain select * from Val where valStr
between 0 and ?")
+            .setArgs(100)).getAll().get(0).get(0).toString();
+
+        assertTrue(plan, plan.contains(SCAN_INDEX_NAME_SUFFIX));
+
+        stopAllGrids();
+
+        if (persistEnabled)
+            cleanPersistenceDir();
+
+        createStaticCache = false;
+
+        ig0 = startGrid(0);
+
+        if (persistEnabled)
+            ig0.cluster().active(true);
+
+        ig0.getOrCreateCache(DEFAULT_CACHE_NAME);
+
+        populateCache();
+
+        createStaticCache = true;
+
+        try {
+            startGrid(1);
+
+            fail("Exception wasn't thrown");
+        } catch (IgniteCheckedException e) {
+            // no op.
+        }
+    }
+
+    /**
+     * Test dynamic indexes creation with equal fields.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testEqualFieldsDynamicIndexesWithoutPersistence() throws Exception {
+        runEqualFieldsDynamicIndexes(false);
+    }
+
+    /**
+     * Test dynamic indexes creation with equal fields.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testEqualFieldsDynamicIndexesWithPersistence() throws Exception {
+        runEqualFieldsDynamicIndexes(true);
+    }
+
+    /** */
+    private void runEqualFieldsDynamicIndexes(boolean persistEnabled) throws Exception {
+        isPersistenceEnabled = persistEnabled;
+
+        indexes = Collections.singletonList(new QueryIndex("valStr"));
+
+        inlineSize = 10;
+
+        srvLog = new ListeningTestLogger(false, log);
+
+        clntLog = new ListeningTestLogger(false, log);
+
+        String msg1 = "Index with the given set or subset of columns already exists";
+
+        LogListener lsnr = LogListener.matches(msg1).andMatches(Pattern.compile(".*newIndexName=idx[0-9]")).build();
+
+        LogListener staticCachesLsnr = LogListener.matches(msg1).build();
+
+        srvLog.registerListener(staticCachesLsnr);
+
+        IgniteEx ig0 = startGrid(0);
+
+        if (persistEnabled)
+            ig0.cluster().active(true);
+
+        IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME);
+
+        populateCache();
+
+        cache.query(new SqlFieldsQuery("create index \"idx0\" on Val(valStr)"));
+
+        assertTrue(staticCachesLsnr.check());
+
+        srvLog.unregisterListener(staticCachesLsnr);
+
+        srvLog.registerListener(lsnr);
+
+        cache.query(new SqlFieldsQuery("create index \"idx1\" on Val(valStr, valLong)"));
+
+        cache.query(new SqlFieldsQuery("create index \"idx2\" on Val(valStr desc, valLong)"));
+
+        assertFalse(lsnr.check());
+
+        cache.query(new SqlFieldsQuery("create index \"idx3\" on Val(valStr, valLong)"));
+
+        cache.query(new SqlFieldsQuery("create index \"idx4\" on Val(valLong)"));
+
+        assertTrue(lsnr.check());
+
+        srvLog.unregisterListener(lsnr);
+
+        IgniteEx client = startGrid(CLIENT_NAME);
+
+        cache = client.cache(DEFAULT_CACHE_NAME);
+
+        LogListener lsnrIdx5 = LogListener.matches(msg1).andMatches("idx5").build();
+
+        srvLog.registerListener(lsnrIdx5);
+
+        cache.query(new SqlFieldsQuery("create index \"idx5\" on Val(valStr desc, valLong)"));
+
+        assertTrue(lsnrIdx5.check());
+
+        LogListener lsnrIdx7 = LogListener.matches(msg1).andMatches("idx7").build();
+
+        srvLog.registerListener(lsnrIdx7);
+
+        cache.query(new SqlFieldsQuery("create index \"idx6\" on Val(valLong)"));
+
+        cache.query(new SqlFieldsQuery("create index \"idx7\" on Val(keyStr, keyLong, keyPojo,
valLong)"));
+
+        assertFalse(lsnrIdx7.check());
+    }
+
+    /** */
+    private boolean checkIdxUsed(GridQueryProcessor qryProc, @Nullable String idxName, String
tblName, String... reqFlds) {
+        String sql = "explain select * from " + tblName + " where ";
+
+        for (int i = 0; i < reqFlds.length; ++i)
+            sql += reqFlds[i] + " > 0 " + ((i < reqFlds.length - 1) ? " and " : "");
+
+        String plan = qryProc.querySqlFields(new SqlFieldsQuery(sql), true)
+            .getAll().get(0).get(0).toString().toUpperCase();
+
+        return idxName != null ? (!plan.contains(SCAN_INDEX_NAME_SUFFIX) && plan.contains(idxName.toUpperCase()))
: !plan.contains(SCAN_INDEX_NAME_SUFFIX);
+    }
+
+    /** */
+    private boolean checkIdxAlreadyExistLog(GridQueryProcessor qryProc, String idxName, String
tblName, String... reqFlds) {
+        String msg0 = "Index with the given set or subset of columns already exists";
+
+        String sql = "create index \"" + idxName + "\" on " + tblName + "(";
+
+        for (int i = 0; i < reqFlds.length; ++i)
+            sql += reqFlds[i] + ((i < reqFlds.length - 1) ? ", " : ")");
+
+        LogListener lsnrIdx = LogListener.matches(msg0).andMatches(idxName).build();
+
+        srvLog.registerListener(lsnrIdx);
+
+        qryProc.querySqlFields(new SqlFieldsQuery(sql), true).getAll();
+
+        return lsnrIdx.check();
+    }
+
+    /** */
+    private void populateTable(GridQueryProcessor qryProc, String tblName, int consPkFldsNum,
String... reqFlds) {
+        assert consPkFldsNum <= reqFlds.length;
+
+        String sql = "CREATE TABLE " + tblName + " (";
+
+        String sqlIns = "INSERT INTO " + tblName + " (";
+
+        for (int i = 0; i < reqFlds.length; ++i) {
+            sql += reqFlds[i] + " VARCHAR, ";
+
+            sqlIns += reqFlds[i] + ((i < reqFlds.length - 1) ? ", " : ") values (");
+        }
+
+        if (consPkFldsNum > 0) {
+            sql += " CONSTRAINT PK_PERSON PRIMARY KEY (";
+
+            for (int i = 0; i < consPkFldsNum; ++i)
+                sql += reqFlds[i] + ((i < consPkFldsNum - 1) ? ", " : "))");
+        } else
 
 Review comment:
   `else` must be on the next line.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message