You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/05/29 14:32:10 UTC

[01/22] ignite git commit: IGNITE-5287: Simplified CacheConfiguration.sqlEscapeAll handling. This closes #2004.

Repository: ignite
Updated Branches:
  refs/heads/ignite-5075 3733f6aaa -> 9db0d4862


http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java
index 7e3473f..cc6fb9a 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java
@@ -22,7 +22,6 @@ import org.apache.ignite.Ignition;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.QueryIndex;
-import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
@@ -30,13 +29,10 @@ import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
 import org.apache.ignite.internal.processors.query.IgniteSQLException;
 import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
-import org.apache.ignite.internal.util.GridStringBuilder;
-import org.apache.ignite.internal.util.typedef.internal.SB;
 
 import javax.cache.CacheException;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
@@ -189,10 +185,10 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
     private void checkCreate(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
         initialize(mode, atomicityMode, near);
 
-        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
 
         dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
 
         assertSchemaException(new RunnableX() {
             @Override public void run() throws Exception {
@@ -201,7 +197,7 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
         }, IgniteQueryErrorCode.INDEX_ALREADY_EXISTS);
 
         dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true);
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
 
         assertSimpleIndexOperations(SQL_SIMPLE_FIELD_1);
 
@@ -273,10 +269,10 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
     private void checkCreateComposite(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
         initialize(mode, atomicityMode, near);
 
-        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1), field(alias(FIELD_NAME_2)));
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED), field(alias(FIELD_NAME_2_ESCAPED)));
 
         dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1), field(alias(FIELD_NAME_2)));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1_ESCAPED), field(alias(FIELD_NAME_2_ESCAPED)));
 
         assertCompositeIndexOperations(SQL_COMPOSITE);
 
@@ -348,7 +344,7 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
     private void checkCreateNotCache(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
         initialize(mode, atomicityMode, near);
 
-        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
 
         try {
             String cacheName = randomString();
@@ -434,7 +430,7 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
     private void checkCreateNoTable(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
         initialize(mode, atomicityMode, near);
 
-        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
 
         assertSchemaException(new RunnableX() {
             @Override public void run() throws Exception {
@@ -589,7 +585,7 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
 
         assertSchemaException(new RunnableX() {
             @Override public void run() throws Exception {
-                QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_2));
+                QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_2_ESCAPED));
 
                 dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
             }
@@ -597,10 +593,10 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
 
         assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
 
-        QueryIndex idx = index(IDX_NAME_1, field(alias(FIELD_NAME_2)));
+        QueryIndex idx = index(IDX_NAME_1, field(alias(FIELD_NAME_2_ESCAPED)));
 
         dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(alias(FIELD_NAME_2)));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(alias(FIELD_NAME_2_ESCAPED)));
 
         assertSimpleIndexOperations(SQL_SIMPLE_FIELD_2);
 
@@ -673,20 +669,20 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
         initialize(mode, atomicityMode, near);
 
         // Create target index.
-        QueryIndex idx1 = index(IDX_NAME_1, field(FIELD_NAME_1));
+        QueryIndex idx1 = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
 
         dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx1, false);
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
 
         assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
 
         assertSimpleIndexOperations(SQL_SIMPLE_FIELD_1);
 
         // Create another index which must stay intact afterwards.
-        QueryIndex idx2 = index(IDX_NAME_2, field(alias(FIELD_NAME_2)));
+        QueryIndex idx2 = index(IDX_NAME_2, field(alias(FIELD_NAME_2_ESCAPED)));
 
         dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx2, false);
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2)));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2_ESCAPED)));
 
         // Load some data.
         loadInitialData();
@@ -700,7 +696,7 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
         assertIndexNotUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
 
         // Make sure the second index is still there.
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2)));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2_ESCAPED)));
     }
 
     /**
@@ -875,7 +871,7 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
                 node.getOrCreateCache(cacheConfiguration().setCacheMode(LOCAL));
         }
 
-        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+        final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
 
         assertSchemaException(new RunnableX() {
             @Override public void run() throws Exception {
@@ -1028,30 +1024,7 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
      */
     private void dynamicIndexCreate(String cacheName, String tblName, QueryIndex idx, boolean ifNotExists)
         throws Exception {
-        GridStringBuilder sql = new SB("CREATE INDEX ")
-            .a(ifNotExists ? "IF NOT EXISTS " : "")
-            .a("\"" + idx.getName() + "\"")
-            .a(" ON ")
-            .a(tblName)
-            .a(" (");
-
-        boolean first = true;
-
-        for (Map.Entry<String, Boolean> fieldEntry : idx.getFields().entrySet()) {
-            if (first)
-                first = false;
-            else
-                sql.a(", ");
-
-            String name = fieldEntry.getKey();
-            boolean asc = fieldEntry.getValue();
-
-            sql.a("\"" + name + "\"").a(" ").a(asc ? "ASC" : "DESC");
-        }
-
-        sql.a(')');
-
-        executeSql(cacheName, sql.toString());
+        dynamicIndexCreate(node(), cacheName, tblName, idx, ifNotExists);
     }
 
     /**
@@ -1063,20 +1036,6 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst
      * @throws Exception if failed.
      */
     private void dynamicIndexDrop(String cacheName, String idxName, boolean ifExists) throws Exception {
-        String sql = "DROP INDEX " + (ifExists ? "IF EXISTS " : "") + "\"" + idxName + "\"";
-
-        executeSql(cacheName, sql);
-    }
-
-    /**
-     * Execute SQL.
-     *
-     * @param cacheName Cache name.
-     * @param sql SQL.
-     */
-    private void executeSql(String cacheName, String sql) {
-        log.info("Executing DDL: " + sql);
-
-        node().cache(cacheName).query(new SqlFieldsQuery(sql)).getAll();
+        dynamicIndexDrop(node(), cacheName, idxName, ifExists);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java
----------------------------------------------------------------------
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 3600022..5d93c12 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
@@ -169,7 +169,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde
         // Test migration from normal server to non-affinity server.
         blockIndexing(srv2Id);
 
-        QueryIndex idx2 = index(IDX_NAME_2, field(alias(FIELD_NAME_2)));
+        QueryIndex idx2 = index(IDX_NAME_2, field(aliasUnescaped(FIELD_NAME_2)));
 
         IgniteInternalFuture<?> idxFut2 =
             queryProcessor(cli).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx2, false);
@@ -183,7 +183,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde
 
         idxFut2.get();
 
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2)));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(aliasUnescaped(FIELD_NAME_2)));
         assertIndexUsed(IDX_NAME_2, SQL_SIMPLE_FIELD_2, SQL_ARG_1);
         assertSqlSimpleData(SQL_SIMPLE_FIELD_2, KEY_AFTER - SQL_ARG_1);
     }
@@ -205,7 +205,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde
         blockIndexing(srv1);
 
         QueryIndex idx1 = index(IDX_NAME_1, field(FIELD_NAME_1));
-        QueryIndex idx2 = index(IDX_NAME_2, field(alias(FIELD_NAME_2)));
+        QueryIndex idx2 = index(IDX_NAME_2, field(aliasUnescaped(FIELD_NAME_2)));
 
         IgniteInternalFuture<?> idxFut1 =
             queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx1, false);
@@ -227,7 +227,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde
         idxFut2.get();
 
         assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2)));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(aliasUnescaped(FIELD_NAME_2)));
 
         Thread.sleep(100);
 
@@ -354,7 +354,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde
         for (Ignite node : Ignition.allGrids()) {
             IgniteCache<BinaryObject, BinaryObject> nodeCache = node.cache(CACHE_NAME).withKeepBinary();
 
-            SqlQuery qry = new SqlQuery(tableName(ValueClass.class), SQL_SIMPLE_FIELD_1).setArgs(SQL_ARG_1);
+            SqlQuery qry = new SqlQuery(typeName(ValueClass.class), SQL_SIMPLE_FIELD_1).setArgs(SQL_ARG_1);
 
             List<Cache.Entry<BinaryObject, BinaryObject>> res = nodeCache.query(qry).getAll();
 
@@ -676,11 +676,11 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde
         assertIndexNotUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
 
         // Update existing index.
-        QueryIndex idx = index(IDX_NAME_2, field(alias(FIELD_NAME_2)));
+        QueryIndex idx = index(IDX_NAME_2, field(aliasUnescaped(FIELD_NAME_2)));
 
         queryProcessor(srv).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, false).get();
 
-        assertIndex(cli, true, CACHE_NAME, TBL_NAME, IDX_NAME_2, field(alias(FIELD_NAME_2)));
+        assertIndex(cli, true, CACHE_NAME, TBL_NAME, IDX_NAME_2, field(aliasUnescaped(FIELD_NAME_2)));
         assertIndexUsed(IDX_NAME_2, SQL_SIMPLE_FIELD_2, SQL_ARG_2);
 
         reconnectClientNode(srv, cli, restartCache, new RunnableX() {
@@ -688,13 +688,13 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde
                 if (!restartCache)
                     queryProcessor(srv).dynamicIndexDrop(CACHE_NAME, CACHE_NAME, IDX_NAME_2, false).get();
 
-                final QueryIndex idx = index(IDX_NAME_2, field(FIELD_NAME_1), field(alias(FIELD_NAME_2)));
+                final QueryIndex idx = index(IDX_NAME_2, field(FIELD_NAME_1), field(aliasUnescaped(FIELD_NAME_2)));
 
                 queryProcessor(srv).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, false);
             }
         });
 
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(FIELD_NAME_1), field(alias(FIELD_NAME_2)));
+        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, field(FIELD_NAME_1), field(aliasUnescaped(FIELD_NAME_2)));
         assertIndexUsed(IDX_NAME_2, SQL_COMPOSITE, SQL_ARG_1, SQL_ARG_2);
     }
 
@@ -1029,6 +1029,16 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde
     }
 
     /**
+     * Get unescaped field alias.
+     *
+     * @param field Field.
+     * @return Alias.
+     */
+    private static String aliasUnescaped(String field) {
+        return alias(field).toUpperCase();
+    }
+
+    /**
      * Blocking indexing processor.
      */
     private static class BlockingIndexing extends IgniteH2Indexing {

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java
----------------------------------------------------------------------
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 fc765a4..5a58965 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
@@ -60,15 +60,15 @@ public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTes
     protected static final int KEY_AFTER = 200;
 
     /** SQL to check index on the field 1. */
-    protected static final String SQL_SIMPLE_FIELD_1 = "SELECT * FROM " + TBL_NAME + " WHERE " + FIELD_NAME_1 + " >= ?";
+    protected static final String SQL_SIMPLE_FIELD_1 = "SELECT * FROM " + TBL_NAME + " WHERE " + FIELD_NAME_1_ESCAPED + " >= ?";
 
     /** SQL to check composite index */
-    protected static final String SQL_COMPOSITE = "SELECT * FROM " + TBL_NAME + " WHERE " + FIELD_NAME_1 +
-        " >= ? AND " + alias(FIELD_NAME_2) + " >= ?";
+    protected static final String SQL_COMPOSITE = "SELECT * FROM " + TBL_NAME + " WHERE " + FIELD_NAME_1_ESCAPED +
+        " >= ? AND " + alias(FIELD_NAME_2_ESCAPED) + " >= ?";
 
     /** SQL to check index on the field 2. */
     protected static final String SQL_SIMPLE_FIELD_2 =
-        "SELECT * FROM " + TBL_NAME + " WHERE " + alias(FIELD_NAME_2) + " >= ?";
+        "SELECT * FROM " + TBL_NAME + " WHERE " + alias(FIELD_NAME_2_ESCAPED) + " >= ?";
 
     /** Argument for simple SQL (1). */
     protected static final int SQL_ARG_1 = 40;
@@ -165,12 +165,12 @@ public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTes
         entity.addQueryField(FIELD_KEY_ALIAS, entity.getKeyType(), null);
 
         entity.addQueryField(FIELD_KEY, Long.class.getName(), null);
-        entity.addQueryField(FIELD_NAME_1, Long.class.getName(), null);
-        entity.addQueryField(FIELD_NAME_2, Long.class.getName(), null);
+        entity.addQueryField(FIELD_NAME_1_ESCAPED, Long.class.getName(), null);
+        entity.addQueryField(FIELD_NAME_2_ESCAPED, Long.class.getName(), null);
 
         entity.setKeyFields(Collections.singleton(FIELD_KEY));
 
-        entity.setAliases(Collections.singletonMap(FIELD_NAME_2, alias(FIELD_NAME_2)));
+        entity.setAliases(Collections.singletonMap(FIELD_NAME_2_ESCAPED, alias(FIELD_NAME_2_ESCAPED)));
 
         ccfg.setQueryEntities(Collections.singletonList(entity));
 
@@ -264,8 +264,8 @@ public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTes
      */
     protected static BinaryObject value(Ignite ignite, long id) {
         return ignite.binary().builder(ValueClass.class.getName())
-            .setField(FIELD_NAME_1, id)
-            .setField(FIELD_NAME_2, id)
+            .setField(FIELD_NAME_1_ESCAPED, id)
+            .setField(FIELD_NAME_2_ESCAPED, id)
             .build();
     }
 
@@ -388,7 +388,7 @@ public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTes
      * @param expSize Expected size.
      */
     protected static void assertSqlSimpleData(Ignite node, String sql, int expSize) {
-        SqlQuery qry = new SqlQuery(tableName(ValueClass.class), sql).setArgs(SQL_ARG_1);
+        SqlQuery qry = new SqlQuery(typeName(ValueClass.class), sql).setArgs(SQL_ARG_1);
 
         List<Cache.Entry<BinaryObject, BinaryObject>> res = node.cache(CACHE_NAME).withKeepBinary().query(qry).getAll();
 
@@ -397,8 +397,8 @@ public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTes
         for (Cache.Entry<BinaryObject, BinaryObject> entry : res) {
             long id = entry.getKey().field(FIELD_KEY);
 
-            long field1 = entry.getValue().field(FIELD_NAME_1);
-            long field2 = entry.getValue().field(FIELD_NAME_2);
+            long field1 = entry.getValue().field(FIELD_NAME_1_ESCAPED);
+            long field2 = entry.getValue().field(FIELD_NAME_2_ESCAPED);
 
             assertTrue(field1 >= SQL_ARG_1);
 
@@ -420,7 +420,7 @@ public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTes
      * @param expSize Expected size.
      */
     protected static void assertSqlCompositeData(Ignite node, String sql, int expSize) {
-        SqlQuery qry = new SqlQuery(tableName(ValueClass.class), sql).setArgs(SQL_ARG_1, SQL_ARG_2);
+        SqlQuery qry = new SqlQuery(typeName(ValueClass.class), sql).setArgs(SQL_ARG_1, SQL_ARG_2);
 
         List<Cache.Entry<BinaryObject, BinaryObject>> res = node.cache(CACHE_NAME).withKeepBinary().query(qry).getAll();
 
@@ -429,8 +429,8 @@ public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTes
         for (Cache.Entry<BinaryObject, BinaryObject> entry : res) {
             long id = entry.getKey().field(FIELD_KEY);
 
-            long field1 = entry.getValue().field(FIELD_NAME_1);
-            long field2 = entry.getValue().field(FIELD_NAME_2);
+            long field1 = entry.getValue().field(FIELD_NAME_1_ESCAPED);
+            long field2 = entry.getValue().field(FIELD_NAME_2_ESCAPED);
 
             assertTrue(field1 >= SQL_ARG_2);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java
index cf563cc..85b4e8c 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java
@@ -66,7 +66,7 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
 
         client().getOrCreateCache(cacheConfiguration());
 
-        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
+        assertNoIndex(CACHE_NAME, TBL_NAME_ESCAPED, IDX_NAME_1_ESCAPED);
 
         IgniteCache<KeyClass, ValueClass> cache = client().cache(CACHE_NAME);
 
@@ -90,8 +90,8 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
 
         assertSize(3);
 
-        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\""
-            + FIELD_NAME_1 + "\" ASC)")).getAll();
+        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1_ESCAPED + "\" ON \"" + TBL_NAME_ESCAPED + "\"(\""
+            + FIELD_NAME_1_ESCAPED + "\" ASC)")).getAll();
 
         // Test that local queries on all nodes use new index.
         for (int i = 0 ; i < 4; i++) {
@@ -124,12 +124,13 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
     public void testCreateIndexWithDuplicateName() {
         final IgniteCache<KeyClass, ValueClass> cache = cache();
 
-        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\""
-            + FIELD_NAME_1 + "\" ASC)"));
+        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1_ESCAPED + "\" ON \"" + TBL_NAME_ESCAPED + "\"(\""
+            + FIELD_NAME_1_ESCAPED + "\" ASC)"));
 
         assertSqlException(new RunnableX() {
             @Override public void run() throws Exception {
-                cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\"id\" ASC)"));
+                cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1_ESCAPED + "\" ON \"" +
+                    TBL_NAME_ESCAPED + "\"(\"id\" ASC)"));
             }
         }, IgniteQueryErrorCode.INDEX_ALREADY_EXISTS);
     }
@@ -140,11 +141,11 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
     public void testCreateIndexIfNotExists() {
         final IgniteCache<KeyClass, ValueClass> cache = cache();
 
-        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\""
-            + FIELD_NAME_1 + "\" ASC)"));
+        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1_ESCAPED + "\" ON \"" + TBL_NAME_ESCAPED + "\"(\""
+            + FIELD_NAME_1_ESCAPED + "\" ASC)"));
 
-        cache.query(new SqlFieldsQuery("CREATE INDEX IF NOT EXISTS \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME +
-            "\"(\"id\" ASC)"));
+        cache.query(new SqlFieldsQuery("CREATE INDEX IF NOT EXISTS \"" + IDX_NAME_1_ESCAPED + "\" ON \"" +
+            TBL_NAME_ESCAPED + "\"(\"id\" ASC)"));
     }
 
     /**
@@ -155,12 +156,12 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
 
         assertSize(3);
 
-        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\""
-            + FIELD_NAME_1 + "\" ASC)"));
+        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1_ESCAPED + "\" ON \"" + TBL_NAME_ESCAPED + "\"(\""
+            + FIELD_NAME_1_ESCAPED + "\" ASC)"));
 
         assertSize(3);
 
-        cache.query(new SqlFieldsQuery("DROP INDEX \"" + IDX_NAME_1 + "\""));
+        cache.query(new SqlFieldsQuery("DROP INDEX \"" + IDX_NAME_1_ESCAPED + "\""));
 
         // Test that no local queries on all nodes use new index.
         for (int i = 0 ; i < 4; i++) {
@@ -187,7 +188,7 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
 
         assertSqlException(new RunnableX() {
             @Override public void run() throws Exception {
-                cache.query(new SqlFieldsQuery("DROP INDEX \"" + IDX_NAME_1 + "\""));
+                cache.query(new SqlFieldsQuery("DROP INDEX \"" + IDX_NAME_1_ESCAPED + "\""));
             }
         }, IgniteQueryErrorCode.INDEX_NOT_FOUND);
     }
@@ -198,7 +199,7 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
     public void testDropMissingIndexIfExists() {
         final IgniteCache<KeyClass, ValueClass> cache = cache();
 
-        cache.query(new SqlFieldsQuery("DROP INDEX IF EXISTS \"" + IDX_NAME_1 + "\""));
+        cache.query(new SqlFieldsQuery("DROP INDEX IF EXISTS \"" + IDX_NAME_1_ESCAPED + "\""));
     }
 
     /**
@@ -209,8 +210,8 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
 
         assertColumnValues("val1", "val2", "val3");
 
-        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1 + "\" ON \"" + TBL_NAME + "\"(\""
-            + FIELD_NAME_1 + "\" ASC)"));
+        cache.query(new SqlFieldsQuery("CREATE INDEX \"" + IDX_NAME_1_ESCAPED + "\" ON \"" + TBL_NAME_ESCAPED + "\"(\""
+            + FIELD_NAME_1_ESCAPED + "\" ASC)"));
 
         assertColumnValues("val1", "val2", "val3");
 
@@ -222,7 +223,7 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
 
         assertColumnValues("someVal", "val1", "val3");
 
-        cache.query(new SqlFieldsQuery("DROP INDEX \"" + IDX_NAME_1 + "\""));
+        cache.query(new SqlFieldsQuery("DROP INDEX \"" + IDX_NAME_1_ESCAPED + "\""));
 
         assertColumnValues("someVal", "val1", "val3");
     }
@@ -237,9 +238,8 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
         for (String v : vals)
             expRes.add(Collections.singletonList(v));
 
-        assertEquals(expRes, cache().query(new SqlFieldsQuery("SELECT \"" + FIELD_NAME_1 + "\" FROM \"" + TBL_NAME +
-            "\" ORDER BY \"id\""))
-            .getAll());
+        assertEquals(expRes, cache().query(new SqlFieldsQuery("SELECT \"" + FIELD_NAME_1_ESCAPED + "\" FROM \"" +
+            TBL_NAME_ESCAPED + "\" ORDER BY \"id\"")).getAll());
     }
 
     /**
@@ -332,12 +332,12 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT
         entity.setValueType(ValueClass.class.getName());
 
         entity.addQueryField("id", Long.class.getName(), null);
-        entity.addQueryField(FIELD_NAME_1, String.class.getName(), null);
-        entity.addQueryField(FIELD_NAME_2, String.class.getName(), null);
+        entity.addQueryField(FIELD_NAME_1_ESCAPED, String.class.getName(), null);
+        entity.addQueryField(FIELD_NAME_2_ESCAPED, String.class.getName(), null);
 
         entity.setKeyFields(Collections.singleton("id"));
 
-        entity.setAliases(Collections.singletonMap(FIELD_NAME_2, alias(FIELD_NAME_2)));
+        entity.setAliases(Collections.singletonMap(FIELD_NAME_2_ESCAPED, alias(FIELD_NAME_2_ESCAPED)));
 
         ccfg.setQueryEntities(Collections.singletonList(entity));
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java
index 71244bb..33478a2 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.internal.processors.cache.index;
 
-import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteClientDisconnectedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.Ignition;
@@ -28,6 +27,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.processors.query.QueryUtils;
 import org.apache.ignite.internal.util.lang.GridAbsPredicate;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.lang.IgniteFuture;
@@ -466,18 +466,21 @@ public class SchemaExchangeSelfTest extends AbstractSchemaSelfTest {
             @Override public void run() {
                 assertTrue(node2.context().clientDisconnected());
 
-                final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
+                final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
 
                 try {
-                    queryProcessor(node1).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, false).get();
+                    dynamicIndexCreate(node1, CACHE_NAME, TBL_NAME, idx, false);
                 }
-                catch (IgniteCheckedException e) {
+                catch (Exception e) {
                     throw new IgniteException(e);
                 }
             }
         });
 
-        assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
+        assertIndex(CACHE_NAME,
+            QueryUtils.normalizeObjectName(TBL_NAME, true),
+            QueryUtils.normalizeObjectName(IDX_NAME_1, false),
+            field(QueryUtils.normalizeObjectName(FIELD_NAME_1_ESCAPED, false)));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
index b79a064..4672290 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
@@ -93,8 +93,10 @@ public class IgniteSqlSchemaIndexingTest extends GridCommonAbstractTest {
             @Override public Object call() throws Exception {
                 final CacheConfiguration cfg = cacheConfig("InSensitiveCache", true, Integer.class, Integer.class)
                     .setSqlSchema("InsensitiveCache");
+
                 final CacheConfiguration collisionCfg = cacheConfig("InsensitiveCache", true, Integer.class, Integer.class)
                     .setSqlSchema("Insensitivecache");
+
                 IgniteConfiguration icfg = new IgniteConfiguration()
                     .setLocalHost("127.0.0.1")
                     .setCacheConfiguration(cfg, collisionCfg);
@@ -158,7 +160,7 @@ public class IgniteSqlSchemaIndexingTest extends GridCommonAbstractTest {
             .setSqlEscapeAll(true);
 
         final CacheConfiguration<Integer, Fact> cfgEsc = cacheConfig("escapedSchema", true, Integer.class, Fact.class)
-            .setSqlSchema("\"SchemaName2\"")
+            .setSqlSchema("SchemaName2")
             .setSqlEscapeAll(true);
 
         escapeCheckSchemaName(ignite(0).createCache(cfg), log, cfg.getSqlSchema());

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
index f98f41b..4bb6a3a 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
@@ -615,9 +615,9 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest {
             c1.put(5, new Person2(3, "p3"));
 
             String select = "select o.name n1, p.name n2 from Person2 p, \"org\".Organization o" +
-                            " where p.orgId = o._key and o._key=1" +
-                            " union select o.name n1, p.name n2 from Person2 p, \"org\".Organization o" +
-                            " where p.orgId = o._key and o._key=2";
+                " where p.orgId = o._key and o._key=1" +
+                " union select o.name n1, p.name n2 from Person2 p, \"org\".Organization o" +
+                " where p.orgId = o._key and o._key=2";
 
             String plan = c1.query(new SqlFieldsQuery("explain " + select)
                 .setDistributedJoins(true).setEnforceJoinOrder(true))
@@ -1615,11 +1615,11 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest {
     public void testJoinWithSubquery() throws Exception {
         IgniteCache<Integer, Contract> c1 = ignite(0).createCache(
             cacheConfig("Contract", true,
-            Integer.class, Contract.class));
+                Integer.class, Contract.class));
 
         IgniteCache<Integer, PromoContract> c2 = ignite(0).createCache(
             cacheConfig("PromoContract", true,
-            Integer.class, PromoContract.class));
+                Integer.class, PromoContract.class));
 
         for (int i = 0; i < 100; i++) {
             int coId = i % 10;

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
index 97db2c4..5ac02a5 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
@@ -692,6 +692,16 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         @Override public String valueFieldName() {
             return null;
         }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public String keyFieldAlias() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public String valueFieldAlias() {
+            return null;
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/BaseH2CompareQueryTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/BaseH2CompareQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/BaseH2CompareQueryTest.java
index 1324b72..9a3f64d 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/BaseH2CompareQueryTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/BaseH2CompareQueryTest.java
@@ -130,7 +130,7 @@ public class BaseH2CompareQueryTest extends AbstractH2CompareQueryTest {
             insertInDb(org);
         }
 
-       // Adresses.
+        // Adresses.
         List<Address> addreses = new ArrayList<>();
 
         for (int i = 0; i < ADDR_CNT; i++) {
@@ -259,13 +259,13 @@ public class BaseH2CompareQueryTest extends AbstractH2CompareQueryTest {
 
         List<List<?>> res = compareQueryRes0(cachePers,
             "select avg(old) from \"pers\".Person left join \"addr\".Address " +
-            " on Person.addrId = Address.id where lower(Address.street) = lower(?)", addStreet);
+                " on Person.addrId = Address.id where lower(Address.street) = lower(?)", addStreet);
 
         assertNotSame(0, res);
 
         compareQueryRes0(cachePers,
             "select avg(old) from \"pers\".Person join \"addr\".Address on Person.addrId = Address.id " +
-            "where lower(Address.street) = lower(?)", addStreet);
+                "where lower(Address.street) = lower(?)", addStreet);
 
         compareQueryRes0(cachePers,
             "select avg(old) from \"pers\".Person left join \"addr\".Address " +
@@ -274,7 +274,7 @@ public class BaseH2CompareQueryTest extends AbstractH2CompareQueryTest {
 
         compareQueryRes0(cachePers,
             "select avg(old) from \"pers\".Person, \"addr\".Address where Person.addrId = Address.id " +
-            "and lower(Address.street) = lower(?)", addStreet);
+                "and lower(Address.street) = lower(?)", addStreet);
 
         compareQueryRes0(cachePers, "select firstName, date from \"pers\".Person");
         compareQueryRes0(cachePers, "select distinct firstName, date from \"pers\".Person");
@@ -483,8 +483,8 @@ public class BaseH2CompareQueryTest extends AbstractH2CompareQueryTest {
      */
     public void testOrdered() throws Exception {
         compareOrderedQueryRes0(cachePers, "select firstName, lastName" +
-                " from \"pers\".Person" +
-                " order by lastName, firstName");
+            " from \"pers\".Person" +
+            " order by lastName, firstName");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java
index 26a0a68..50b71b5 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java
@@ -435,7 +435,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest {
             st.setObject(++i, o.orderId);
             st.setObject(++i, o.parentAlgo);
 
-           st.executeUpdate();
+            st.executeUpdate();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/resources/org/apache/ignite/internal/processors/query/h2/sql/bigQuery.sql
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/resources/org/apache/ignite/internal/processors/query/h2/sql/bigQuery.sql b/modules/indexing/src/test/resources/org/apache/ignite/internal/processors/query/h2/sql/bigQuery.sql
index d441e3f..ac70026 100644
--- a/modules/indexing/src/test/resources/org/apache/ignite/internal/processors/query/h2/sql/bigQuery.sql
+++ b/modules/indexing/src/test/resources/org/apache/ignite/internal/processors/query/h2/sql/bigQuery.sql
@@ -21,9 +21,9 @@ from (
   from (
 	select  date, orderId, rootOrderId, origOrderId, archSeq, alias 
 	from "custord".CustOrder where alias='CUSTOM'
-	
+
 	union all
-	
+
 	select  date, orderId, rootOrderId, refOrderId as origOrderId, archSeq, alias
 	from "replord".ReplaceOrder where alias='CUSTOM'
   ) co,
@@ -45,9 +45,9 @@ from (
     and h.origOrderId = co.origOrderId and h.date = co.date
     and co.archSeq = h.maxArchSeq
 	and co.alias='CUSTOM'
-) cop 
+) cop
 inner join (
-  select e.date, e.rootOrderId as eRootOrderId, e.rootOrderId, sum(e.execShares) as execShares, 
+  select e.date, e.rootOrderId as eRootOrderId, e.rootOrderId, sum(e.execShares) as execShares,
 	sum(e.execShares*e.price)/sum(e.execShares) as price,
 	case when min(e.lastMkt) = max(e.lastMkt) then min(e.lastMkt) else min('XOFF') end as execMeet
   from "exec".Exec e


[15/22] ignite git commit: IGNITE-5315 .NET: Fix LINQ, examples, and cache configuration to account for IGNITE-5287 (SqlEscapeAll)

Posted by sb...@apache.org.
IGNITE-5315 .NET: Fix LINQ, examples, and cache configuration to account for IGNITE-5287 (SqlEscapeAll)

This closes #2023


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

Branch: refs/heads/ignite-5075
Commit: f5bbc71d4c1cd1a01b08dbc5c5df892bd2f55316
Parents: e0b2053
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Mon May 29 15:53:37 2017 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Mon May 29 15:53:37 2017 +0300

----------------------------------------------------------------------
 .../Apache.Ignite.Core.Tests.csproj             |   1 +
 .../Cache/CacheConfigurationTest.cs             |   6 +-
 .../Cache/Query/CacheLinqTest.cs                | 131 ++++++++++++++-----
 .../Cache/Query/CacheLinqTestSqlEscapeAll.cs    |  34 +++++
 .../Apache.Ignite.Core.csproj                   |   1 +
 .../Cache/Configuration/QueryEntity.cs          |  64 +++++++--
 .../Impl/Cache/IQueryEntityInternal.cs          |  31 +++++
 .../Impl/CacheFieldsQueryProvider.cs            |   9 ++
 .../Impl/CacheQueryExpressionVisitor.cs         |  76 ++++++++---
 .../Apache.Ignite.Linq/Impl/ExpressionWalker.cs |   7 +-
 10 files changed, 295 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f5bbc71d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index f27e774..974f858 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -102,6 +102,7 @@
     <Compile Include="Cache\Query\CacheDmlQueriesTest.cs" />
     <Compile Include="Cache\CacheAbstractTransactionalTest.cs" />
     <Compile Include="Cache\Query\CacheDmlQueriesTestSimpleName.cs" />
+    <Compile Include="Cache\Query\CacheLinqTestSqlEscapeAll.cs" />
     <Compile Include="Cache\Query\CacheLinqTestSimpleName.cs" />
     <Compile Include="Cache\Query\CacheQueriesTestSimpleName.cs" />
     <Compile Include="Cache\Query\Continuous\ContinuousQueryTest.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/f5bbc71d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
index cf70970..7935cc3 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
@@ -401,10 +401,11 @@ namespace Apache.Ignite.Core.Tests.Cache
                 return;
             }
 
-            Assert.AreEqual(x.Count, y.Count);
+            // Resulting configuration may include additional aliases.
+            Assert.LessOrEqual(x.Count, y.Count);
 
             for (var i = 0; i < x.Count; i++)
-                AssertConfigsAreEqual(x.ElementAt(i), y.ElementAt(i));
+                AssertConfigsAreEqual(x.ElementAt(i), y.FirstOrDefault(a => a.FullName == x.ElementAt(i).FullName));
         }
 
         /// <summary>
@@ -517,6 +518,7 @@ namespace Apache.Ignite.Core.Tests.Cache
                     {
                         KeyTypeName = "Integer",
                         ValueTypeName = "java.lang.String",
+                        TableName = "Table1",
                         Fields = new[]
                         {
                             new QueryField("length", typeof(int)), 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f5bbc71d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
index b603d75..04ce965 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
@@ -142,6 +142,14 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         }
 
         /// <summary>
+        /// Gets the SqlEscapeAll setting.
+        /// </summary>
+        protected virtual bool GetSqlEscapeAll()
+        {
+            return false;
+        }
+
+        /// <summary>
         /// Fixture tear down.
         /// </summary>
         [TestFixtureTearDown]
@@ -941,7 +949,10 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         public void TestNumerics()
         {
             var cache = Ignition.GetIgnite()
-                    .GetOrCreateCache<int, Numerics>(new CacheConfiguration("numerics", typeof (Numerics)));
+                    .GetOrCreateCache<int, Numerics>(new CacheConfiguration("numerics", typeof (Numerics))
+                {
+                    SqlEscapeAll = GetSqlEscapeAll()
+                });
 
             for (var i = 0; i < 100; i++)
                 cache[i] = new Numerics(((double) i - 50)/3);
@@ -1221,10 +1232,14 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         public void TestPrimitiveCache()
         {
             // Create partitioned cache
-            var cache =
-                Ignition.GetIgnite()
-                    .GetOrCreateCache<int, string>(new CacheConfiguration("primitiveCache",
-                        new QueryEntity(typeof (int), typeof (string))) {CacheMode = CacheMode.Replicated});
+            var cache = Ignition.GetIgnite()
+                .GetOrCreateCache<int, string>(
+                    new CacheConfiguration("primitiveCache",
+                        new QueryEntity(typeof(int), typeof(string)))
+                    {
+                        CacheMode = CacheMode.Replicated,
+                        SqlEscapeAll = GetSqlEscapeAll()
+                    });
 
             var qry = cache.AsCacheQueryable();
 
@@ -1246,7 +1261,10 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         {
             // Create partitioned cache
             var cache =
-                Ignition.GetIgnite().GetOrCreateCache<int, int>(new CacheConfiguration("partCache", typeof (int)));
+                Ignition.GetIgnite().GetOrCreateCache<int, int>(new CacheConfiguration("partCache", typeof (int))
+                {
+                    SqlEscapeAll = GetSqlEscapeAll()
+                });
 
             // Populate
             const int count = 100;
@@ -1284,8 +1302,13 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             Assert.AreEqual(cache.Ignite, query.Ignite);
 
             var fq = query.GetFieldsQuery();
-            Assert.AreEqual("select _T0._key, _T0._val from \"person_org\".Person as _T0 where (_T0._key > ?)", 
+
+            Assert.AreEqual(
+                GetSqlEscapeAll()
+                    ? "select _T0._KEY, _T0._VAL from \"person_org\".\"Person\" as _T0 where (_T0.\"_KEY\" > ?)"
+                    : "select _T0._KEY, _T0._VAL from \"person_org\".Person as _T0 where (_T0._KEY > ?)",
                 fq.Sql);
+
             Assert.AreEqual(new[] {10}, fq.Arguments);
             Assert.IsTrue(fq.Local);
             Assert.AreEqual(PersonCount - 11, cache.QueryFields(fq).GetAll().Count);
@@ -1297,11 +1320,17 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             Assert.AreEqual(TimeSpan.FromSeconds(2.5), fq.Timeout);
 
             var str = query.ToString();
-            Assert.AreEqual("CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " +
-                            "[Sql=select _T0._key, _T0._val from \"person_org\".Person as _T0 where " +
-                            "(_T0._key > ?), Arguments=[10], " +
-                            "Local=True, PageSize=999, EnableDistributedJoins=False, EnforceJoinOrder=True, " +
-                            "Timeout=00:00:02.5000000, ReplicatedOnly=True, Colocated=True]]", str);
+            Assert.AreEqual(GetSqlEscapeAll()
+                ? "CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " +
+                  "[Sql=select _T0._KEY, _T0._VAL from \"person_org\".\"Person\" as _T0 where " +
+                  "(_T0.\"_KEY\" > ?), Arguments=[10], " +
+                  "Local=True, PageSize=999, EnableDistributedJoins=False, EnforceJoinOrder=True, " +
+                  "Timeout=00:00:02.5000000, ReplicatedOnly=True, Colocated=True]]"
+                : "CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " +
+                  "[Sql=select _T0._KEY, _T0._VAL from \"person_org\".Person as _T0 where " +
+                  "(_T0._KEY > ?), Arguments=[10], " +
+                  "Local=True, PageSize=999, EnableDistributedJoins=False, EnforceJoinOrder=True, " +
+                  "Timeout=00:00:02.5000000, ReplicatedOnly=True, Colocated=True]]", str);
 
             // Check fields query
             var fieldsQuery = (ICacheQueryable) cache.AsCacheQueryable().Select(x => x.Value.Name);
@@ -1310,17 +1339,26 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             Assert.AreEqual(cache.Ignite, fieldsQuery.Ignite);
 
             fq = fieldsQuery.GetFieldsQuery();
-            Assert.AreEqual("select _T0.Name from \"person_org\".Person as _T0", fq.Sql);
+            Assert.AreEqual(GetSqlEscapeAll()
+                    ? "select _T0.\"Name\" from \"person_org\".\"Person\" as _T0"
+                    : "select _T0.NAME from \"person_org\".Person as _T0",
+                fq.Sql);
+
             Assert.IsFalse(fq.Local);
             Assert.AreEqual(SqlFieldsQuery.DefaultPageSize, fq.PageSize);
             Assert.IsFalse(fq.EnableDistributedJoins);
             Assert.IsFalse(fq.EnforceJoinOrder);
 
             str = fieldsQuery.ToString();
-            Assert.AreEqual("CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " +
-                            "[Sql=select _T0.Name from \"person_org\".Person as _T0, Arguments=[], Local=False, " +
-                            "PageSize=1024, EnableDistributedJoins=False, EnforceJoinOrder=False, " +
-                            "Timeout=00:00:00, ReplicatedOnly=False, Colocated=False]]", str);
+            Assert.AreEqual(GetSqlEscapeAll()
+                ? "CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " +
+                  "[Sql=select _T0.\"Name\" from \"person_org\".\"Person\" as _T0, Arguments=[], Local=False, " +
+                  "PageSize=1024, EnableDistributedJoins=False, EnforceJoinOrder=False, " +
+                  "Timeout=00:00:00, ReplicatedOnly=False, Colocated=False]]"
+                : "CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " +
+                  "[Sql=select _T0.NAME from \"person_org\".Person as _T0, Arguments=[], Local=False, " +
+                  "PageSize=1024, EnableDistributedJoins=False, EnforceJoinOrder=False, " +
+                  "Timeout=00:00:00, ReplicatedOnly=False, Colocated=False]]", str);
             
             // Check distributed joins flag propagation
             var distrQuery = cache.AsCacheQueryable(new QueryOptions {EnableDistributedJoins = true})
@@ -1331,12 +1369,19 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             Assert.IsTrue(query.GetFieldsQuery().EnableDistributedJoins);
 
             str = distrQuery.ToString();
-            Assert.AreEqual("CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " +
-                            "[Sql=select _T0._key, _T0._val from \"person_org\".Person as _T0 where " +
-                            "(((_T0._key > ?) and (_T0.age1 > ?)) " +
-                            "and (_T0.Name like \'%\' || ? || \'%\') ), Arguments=[10, 20, x], Local=False, " +
-                            "PageSize=1024, EnableDistributedJoins=True, EnforceJoinOrder=False, " +
-                            "Timeout=00:00:00, ReplicatedOnly=False, Colocated=False]]", str);
+            Assert.AreEqual(GetSqlEscapeAll()
+                ? "CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " +
+                  "[Sql=select _T0._KEY, _T0._VAL from \"person_org\".\"Person\" as _T0 where " +
+                  "(((_T0.\"_KEY\" > ?) and (_T0.\"age1\" > ?)) " +
+                  "and (_T0.\"Name\" like \'%\' || ? || \'%\') ), Arguments=[10, 20, x], Local=False, " +
+                  "PageSize=1024, EnableDistributedJoins=True, EnforceJoinOrder=False, " +
+                  "Timeout=00:00:00, ReplicatedOnly=False, Colocated=False]]"
+                : "CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " +
+                  "[Sql=select _T0._KEY, _T0._VAL from \"person_org\".Person as _T0 where " +
+                  "(((_T0._KEY > ?) and (_T0.AGE1 > ?)) " +
+                  "and (_T0.NAME like \'%\' || ? || \'%\') ), Arguments=[10, 20, x], Local=False, " +
+                  "PageSize=1024, EnableDistributedJoins=True, EnforceJoinOrder=False, " +
+                  "Timeout=00:00:00, ReplicatedOnly=False, Colocated=False]]", str);
         }
 
         /// <summary>
@@ -1377,12 +1422,18 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
 
             // Create and populate partitioned caches
             var personCache = ignite.CreateCache<int, Person>(new CacheConfiguration("partitioned_persons",
-                new QueryEntity(typeof(int), typeof(Person))));
+                new QueryEntity(typeof(int), typeof(Person)))
+            {
+                SqlEscapeAll = GetSqlEscapeAll()
+            });
 
             personCache.PutAll(GetSecondPersonCache().ToDictionary(x => x.Key, x => x.Value));
 
             var roleCache = ignite.CreateCache<int, Role>(new CacheConfiguration("partitioned_roles",
-                    new QueryEntity(typeof(int), typeof(Role))));
+                    new QueryEntity(typeof(int), typeof(Role)))
+            {
+                SqlEscapeAll = GetSqlEscapeAll()
+            });
 
             roleCache.PutAll(GetRoleCache().ToDictionary(x => x.Key.Foo, x => x.Value));
 
@@ -1432,7 +1483,10 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         {
             // Use new cache to avoid touching static data.
             var cache = Ignition.GetIgnite().CreateCache<int, Person>(new CacheConfiguration("deleteAllTest",
-                    new QueryEntity(typeof(int), typeof(Person))));
+                    new QueryEntity(typeof(int), typeof(Person)))
+            {
+                SqlEscapeAll = GetSqlEscapeAll()
+            });
 
             Enumerable.Range(1, 10).ToList().ForEach(x => cache.Put(x, new Person(x, x.ToString())));
             
@@ -1491,7 +1545,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         /// Gets the person cache.
         /// </summary>
         /// <returns></returns>
-        private static ICache<int, Person> GetPersonCache()
+        private ICache<int, Person> GetPersonCache()
         {
             return GetCacheOf<Person>();
         }
@@ -1500,7 +1554,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         /// Gets the org cache.
         /// </summary>
         /// <returns></returns>
-        private static ICache<int, Organization> GetOrgCache()
+        private ICache<int, Organization> GetOrgCache()
         {
             return GetCacheOf<Organization>();
         }
@@ -1508,7 +1562,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         /// <summary>
         /// Gets the cache.
         /// </summary>
-        private static ICache<int, T> GetCacheOf<T>()
+        private ICache<int, T> GetCacheOf<T>()
         {
             return Ignition.GetIgnite()
                 .GetOrCreateCache<int, T>(new CacheConfiguration(PersonOrgCacheName,
@@ -1527,23 +1581,31 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
                             new QueryField("MyValue", typeof(T)),
                         }
                     },
-                    new QueryEntity(typeof (int), typeof (Organization))) {CacheMode = CacheMode.Replicated});
+                    new QueryEntity(typeof (int), typeof (Organization)))
+                {
+                    CacheMode = CacheMode.Replicated,
+                    SqlEscapeAll = GetSqlEscapeAll()
+                });
         }
 
         /// <summary>
         /// Gets the role cache.
         /// </summary>
-        private static ICache<RoleKey, Role> GetRoleCache()
+        private ICache<RoleKey, Role> GetRoleCache()
         {
             return Ignition.GetIgnite()
                 .GetOrCreateCache<RoleKey, Role>(new CacheConfiguration(RoleCacheName,
-                    new QueryEntity(typeof (RoleKey), typeof (Role))) {CacheMode = CacheMode.Replicated});
+                    new QueryEntity(typeof (RoleKey), typeof (Role)))
+                {
+                    CacheMode = CacheMode.Replicated,
+                    SqlEscapeAll = GetSqlEscapeAll()
+                });
         }
 
         /// <summary>
         /// Gets the second person cache.
         /// </summary>
-        private static ICache<int, Person> GetSecondPersonCache()
+        private ICache<int, Person> GetSecondPersonCache()
         {
             return Ignition.GetIgnite()
                 .GetOrCreateCache<int, Person>(
@@ -1553,7 +1615,8 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
                             TableName = "CustomPersons"
                         })
                     {
-                        CacheMode = CacheMode.Replicated
+                        CacheMode = CacheMode.Replicated,
+                        SqlEscapeAll = GetSqlEscapeAll()
                     });
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f5bbc71d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTestSqlEscapeAll.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTestSqlEscapeAll.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTestSqlEscapeAll.cs
new file mode 100644
index 0000000..7473be9
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTestSqlEscapeAll.cs
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Cache.Query
+{
+    using NUnit.Framework;
+
+    /// <summary>
+    /// LINQ test with simple name mapper.
+    /// </summary>
+    [TestFixture]
+    public class CacheLinqTestSqlEscapeAll : CacheLinqTest
+    {
+        /** <inheritdoc /> */
+        protected override bool GetSqlEscapeAll()
+        {
+            return true;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/f5bbc71d/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
index 25b9603..9ce9dd2 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -198,6 +198,7 @@
     <Compile Include="Impl\Binary\ReflectionUtils.cs" />
     <Compile Include="Cache\Affinity\AffinityFunctionBase.cs" />
     <Compile Include="Impl\Binary\TypeNameParser.cs" />
+    <Compile Include="Impl\Cache\IQueryEntityInternal.cs" />
     <Compile Include="Impl\Cache\MemoryMetrics.cs" />
     <Compile Include="Impl\Cache\Store\CacheStore.cs" />
     <Compile Include="Impl\Cache\Store\ICacheStoreInternal.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/f5bbc71d/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
index b6163ee..58e5af9 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
@@ -27,13 +27,14 @@ namespace Apache.Ignite.Core.Cache.Configuration
     using System.Reflection;
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Impl.Binary;
+    using Apache.Ignite.Core.Impl.Cache;
     using Apache.Ignite.Core.Log;
 
     /// <summary>
     /// Query entity is a description of cache entry (composed of key and value) 
     /// in a way of how it must be indexed and can be queried.
     /// </summary>
-    public class QueryEntity
+    public class QueryEntity : IQueryEntityInternal
     {
         /** */
         private Type _keyType;
@@ -47,6 +48,11 @@ namespace Apache.Ignite.Core.Cache.Configuration
         /** */
         private string _keyTypeName;
 
+        /** */
+        private Dictionary<string, string> _aliasMap;
+
+        private ICollection<QueryAlias> _aliases;
+
         /// <summary>
         /// Initializes a new instance of the <see cref="QueryEntity"/> class.
         /// </summary>
@@ -180,7 +186,15 @@ namespace Apache.Ignite.Core.Cache.Configuration
         /// Example: {"parent.name" -> "parentName"}.
         /// </summary>
         [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
-        public ICollection<QueryAlias> Aliases { get; set; }
+        public ICollection<QueryAlias> Aliases
+        {
+            get { return _aliases; }
+            set
+            {
+                _aliases = value;
+                _aliasMap = null;
+            }
+        }
 
         /// <summary>
         /// Gets or sets the query indexes.
@@ -189,6 +203,32 @@ namespace Apache.Ignite.Core.Cache.Configuration
         public ICollection<QueryIndex> Indexes { get; set; }
 
         /// <summary>
+        /// Gets the alias by field name, or null when no match found.
+        /// This method constructs a dictionary lazily to perform lookups.
+        /// </summary>
+        string IQueryEntityInternal.GetAlias(string fieldName)
+        {
+            if (Aliases == null || Aliases.Count == 0)
+            {
+                return null;
+            }
+
+            // PERF: No ToDictionary.
+            if (_aliasMap == null)
+            {
+                _aliasMap = new Dictionary<string, string>(Aliases.Count, StringComparer.InvariantCulture);
+
+                foreach (var alias in Aliases)
+                {
+                    _aliasMap[alias.FullName] = alias.Alias;
+                }
+            }
+
+            string res;
+            return _aliasMap.TryGetValue(fieldName, out res) ? res : null;
+        }
+
+        /// <summary>
         /// Initializes a new instance of the <see cref="QueryEntity"/> class.
         /// </summary>
         /// <param name="reader">The reader.</param>
@@ -372,14 +412,17 @@ namespace Apache.Ignite.Core.Cache.Configuration
                 {
                     var columnName = attr.Name ?? memberInfo.Key.Name;
 
-                    // No dot notation for indexes
+                    // Dot notation is required for nested SQL fields.
+                    if (parentPropName != null)
+                    {
+                        columnName = parentPropName + "." + columnName;
+                    }
+
                     if (attr.IsIndexed)
+                    {
                         indexes.Add(new QueryIndexEx(columnName, attr.IsDescending, QueryIndexType.Sorted,
                             attr.IndexGroups));
-
-                    // Dot notation is required for nested SQL fields
-                    if (parentPropName != null)
-                        columnName = parentPropName + "." + columnName;
+                    }
 
                     fields.Add(new QueryField(columnName, memberInfo.Value) {IsKeyField = isKey});
 
@@ -390,11 +433,12 @@ namespace Apache.Ignite.Core.Cache.Configuration
                 {
                     var columnName = attr.Name ?? memberInfo.Key.Name;
 
-                    // No dot notation for FullText index names
-                    indexes.Add(new QueryIndexEx(columnName, false, QueryIndexType.FullText, null));
-
                     if (parentPropName != null)
+                    {
                         columnName = parentPropName + "." + columnName;
+                    }
+
+                    indexes.Add(new QueryIndexEx(columnName, false, QueryIndexType.FullText, null));
 
                     fields.Add(new QueryField(columnName, memberInfo.Value) {IsKeyField = isKey});
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f5bbc71d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/IQueryEntityInternal.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/IQueryEntityInternal.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/IQueryEntityInternal.cs
new file mode 100644
index 0000000..c312a52
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/IQueryEntityInternal.cs
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Impl.Cache
+{
+    /// <summary>
+    /// Extended QueryEntity interface for internal needs.
+    /// </summary>
+    public interface IQueryEntityInternal
+    {
+        /// <summary>
+        /// Gets the alias by field name, or null when no match found.
+        /// This method constructs a dictionary lazily to perform lookups.
+        /// </summary>
+        string GetAlias(string fieldName);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f5bbc71d/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs
index c665fe7..cce89fd 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs
@@ -217,6 +217,7 @@ namespace Apache.Ignite.Linq.Impl
                 return EscapeTableName(validTableNames[0]);
             }
 
+            // Try with full type name (this works when TableName is not set).
             var valueTypeName = cacheValueType.FullName;
 
             if (validTableNames.Contains(valueTypeName, StringComparer.OrdinalIgnoreCase))
@@ -224,6 +225,14 @@ namespace Apache.Ignite.Linq.Impl
                 return EscapeTableName(valueTypeName);
             }
 
+            // Remove namespace and nested class qualification and try again.
+            valueTypeName = EscapeTableName(valueTypeName);
+
+            if (validTableNames.Contains(valueTypeName, StringComparer.OrdinalIgnoreCase))
+            {
+                return valueTypeName;
+            }
+
             throw new CacheException(string.Format("Table name cannot be inferred for cache '{0}', " +
                                                    "please use AsCacheQueryable overload with tableName parameter. " +
                                                    "Valid table names: {1}", _cacheConfiguration.Name ?? "null",

http://git-wip-us.apache.org/repos/asf/ignite/blob/f5bbc71d/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryExpressionVisitor.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryExpressionVisitor.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryExpressionVisitor.cs
index 8fa0b5d..1b42aad 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryExpressionVisitor.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryExpressionVisitor.cs
@@ -29,6 +29,7 @@ namespace Apache.Ignite.Linq.Impl
     using System.Reflection;
     using Apache.Ignite.Core.Cache;
     using Apache.Ignite.Core.Cache.Configuration;
+    using Apache.Ignite.Core.Impl.Cache;
     using Apache.Ignite.Core.Impl.Common;
     using Remotion.Linq;
     using Remotion.Linq.Clauses;
@@ -278,10 +279,10 @@ namespace Apache.Ignite.Linq.Impl
             // Count, sum, max, min expect a single field or *
             // In other cases we need both parts of cache entry
             var format = _includeAllFields
-                ? "{0}.*, {0}._key, {0}._val"
+                ? "{0}.*, {0}._KEY, {0}._VAL"
                 : _useStar
                     ? "{0}.*"
-                    : "{0}._key, {0}._val";
+                    : "{0}._KEY, {0}._VAL";
 
             var tableName = Aliases.GetTableAlias(expression);
 
@@ -308,7 +309,7 @@ namespace Apache.Ignite.Linq.Impl
 
             if (queryable != null)
             {
-                var fieldName = GetFieldName(expression, queryable);
+                var fieldName = GetEscapedFieldName(expression, queryable);
 
                 ResultBuilder.AppendFormat("{0}.{1}", Aliases.GetTableAlias(expression), fieldName);
             }
@@ -319,9 +320,21 @@ namespace Apache.Ignite.Linq.Impl
         }
 
         /// <summary>
-        /// Gets the name of the field from a member expression.
+        /// Gets the name of the field from a member expression, with quotes when necessary.
         /// </summary>
-        private static string GetFieldName(MemberExpression expression, ICacheQueryableInternal queryable)
+        private static string GetEscapedFieldName(MemberExpression expression, ICacheQueryableInternal queryable)
+        {
+            var sqlEscapeAll = queryable.CacheConfiguration.SqlEscapeAll;
+            var fieldName = GetFieldName(expression, queryable);
+
+            return sqlEscapeAll ? string.Format("\"{0}\"", fieldName) : fieldName;
+        }
+
+        /// <summary>
+        /// Gets the name of the field from a member expression, with quotes when necessary.
+        /// </summary>
+        private static string GetFieldName(MemberExpression expression, ICacheQueryableInternal queryable,
+            bool ignoreAlias = false)
         {
             var fieldName = GetMemberFieldName(expression.Member);
 
@@ -329,20 +342,18 @@ namespace Apache.Ignite.Linq.Impl
             var cacheCfg = queryable.CacheConfiguration;
 
             if (cacheCfg.QueryEntities == null || cacheCfg.QueryEntities.All(x => x.Aliases == null))
-                return fieldName;  // There are no aliases defined - early exit
+            {
+                // There are no aliases defined - early exit.
+                return fieldName;
+            }
 
             // Find query entity by key-val types
-            var keyValTypes = queryable.ElementType.GetGenericArguments();
-
-            Debug.Assert(keyValTypes.Length == 2);
-
-            var entity = cacheCfg.QueryEntities.FirstOrDefault(e =>
-                e.Aliases != null &&
-                (e.KeyType == keyValTypes[0] || e.KeyTypeName == keyValTypes[0].FullName) &&
-                (e.ValueType == keyValTypes[1] || e.ValueTypeName == keyValTypes[1].FullName));
+            var entity = GetQueryEntity(queryable, cacheCfg);
 
             if (entity == null)
+            {
                 return fieldName;
+            }
 
             // There are some aliases for the current query type
             // Calculate full field name and look for alias
@@ -351,15 +362,44 @@ namespace Apache.Ignite.Linq.Impl
 
             while ((member = member.Expression as MemberExpression) != null &&
                    member.Member.DeclaringType != queryable.ElementType)
-                fullFieldName = GetFieldName(member, queryable) + "." + fullFieldName;
+            {
+                fullFieldName = GetFieldName(member, queryable, true) + "." + fullFieldName;
+            }
 
-            var alias = entity.Aliases.Where(x => x.FullName == fullFieldName)
-                .Select(x => x.Alias).FirstOrDefault();
+            var alias = ignoreAlias ? null : ((IQueryEntityInternal)entity).GetAlias(fullFieldName);
 
             return alias ?? fieldName;
         }
 
         /// <summary>
+        /// Finds matching query entity in the cache configuration.
+        /// </summary>
+        private static QueryEntity GetQueryEntity(ICacheQueryableInternal queryable, CacheConfiguration cacheCfg)
+        {
+            if (cacheCfg.QueryEntities.Count == 1)
+            {
+                return cacheCfg.QueryEntities.Single();
+            }
+
+            var keyValTypes = queryable.ElementType.GetGenericArguments();
+
+            Debug.Assert(keyValTypes.Length == 2);
+
+            // PERF: No LINQ.
+            foreach (var e in cacheCfg.QueryEntities)
+            {
+                if (e.Aliases != null
+                    && (e.KeyType == keyValTypes[0] || e.KeyTypeName == keyValTypes[0].FullName)
+                    && (e.ValueType == keyValTypes[1] || e.ValueTypeName == keyValTypes[1].FullName))
+                {
+                    return e;
+                }
+            }
+            
+            return null;
+        }
+
+        /// <summary>
         /// Gets the name of the member field.
         /// </summary>
         [SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", 
@@ -377,7 +417,7 @@ namespace Apache.Ignite.Linq.Impl
                 if (m.DeclaringType != null &&
                     m.DeclaringType.IsGenericType &&
                     m.DeclaringType.GetGenericTypeDefinition() == typeof (ICacheEntry<,>))
-                    return "_" + m.Name.ToLowerInvariant().Substring(0, 3);
+                    return "_" + m.Name.ToUpperInvariant().Substring(0, 3);
 
                 var qryFieldAttr = m.GetCustomAttributes(true)
                     .OfType<QuerySqlFieldAttribute>().FirstOrDefault();

http://git-wip-us.apache.org/repos/asf/ignite/blob/f5bbc71d/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/ExpressionWalker.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/ExpressionWalker.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/ExpressionWalker.cs
index 4407f96..f00a13b 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/ExpressionWalker.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/ExpressionWalker.cs
@@ -176,7 +176,12 @@ namespace Apache.Ignite.Linq.Impl
         {
             Debug.Assert(queryable != null);
 
-            return string.Format("\"{0}\".{1}", queryable.CacheConfiguration.Name, queryable.TableName);
+            var cacheCfg = queryable.CacheConfiguration;
+
+            return string.Format(cacheCfg.SqlEscapeAll
+                    ? "\"{0}\".\"{1}\""
+                    : "\"{0}\".{1}",
+                cacheCfg.Name, queryable.TableName);
         }
     }
 }


[09/22] ignite git commit: IGNITE-5313: Removed usages of H2Schema.cacheName with cache-agnostic analogs. The last usage is to be removed as a part of IGNITE-5319. This closes #2021.

Posted by sb...@apache.org.
IGNITE-5313: Removed usages of H2Schema.cacheName with cache-agnostic analogs. The last usage is to be removed as a part of IGNITE-5319. This closes #2021.


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

Branch: refs/heads/ignite-5075
Commit: fb12f0facc13b90e701cd77d290dccdb827b13a4
Parents: aad3b0c
Author: devozerov <vo...@gridgain.com>
Authored: Sun May 28 14:20:03 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Sun May 28 14:20:03 2017 +0300

----------------------------------------------------------------------
 .../ignite/internal/GridKernalContext.java      |  1 +
 .../ignite/internal/GridKernalContextImpl.java  |  1 +
 .../internal/binary/BinaryEnumObjectImpl.java   |  6 +--
 .../internal/binary/BinaryObjectImpl.java       |  6 +--
 .../binary/BinaryObjectOffheapImpl.java         |  6 +--
 .../internal/processors/cache/CacheObject.java  |  6 +--
 .../cache/CacheObjectByteArrayImpl.java         |  6 +--
 .../processors/cache/CacheObjectImpl.java       |  6 +--
 .../processors/cache/GridCacheContext.java      |  8 ----
 .../processors/cache/KeyCacheObjectImpl.java    |  6 +--
 .../binary/CacheObjectBinaryProcessorImpl.java  | 23 +++++------
 .../processors/query/GridQueryProcessor.java    | 13 ++++++
 .../internal/GridAffinityNoCacheSelfTest.java   |  7 ++--
 .../IgniteIncompleteCacheObjectSelfTest.java    |  8 ++--
 .../database/FreeListImplSelfTest.java          |  7 ++--
 .../query/h2/DmlStatementsProcessor.java        |  5 ++-
 .../query/h2/H2ResultSetIterator.java           |  4 +-
 .../processors/query/h2/H2RowDescriptor.java    | 19 ++++-----
 .../processors/query/h2/H2TableDescriptor.java  | 22 +++++++---
 .../processors/query/h2/H2TableEngine.java      |  2 +-
 .../processors/query/h2/IgniteH2Indexing.java   | 42 +++++---------------
 .../query/h2/opt/GridH2ValueCacheObject.java    | 32 ++++++---------
 .../query/h2/twostep/GridMapQueryExecutor.java  | 16 +++-----
 .../h2/twostep/GridReduceQueryExecutor.java     |  2 +-
 .../query/h2/twostep/msg/GridH2CacheObject.java | 39 +++---------------
 .../h2/GridIndexingSpiAbstractSelfTest.java     |  6 +--
 26 files changed, 126 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
index 7a01200..ef4001f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
@@ -33,6 +33,7 @@ import org.apache.ignite.internal.managers.failover.GridFailoverManager;
 import org.apache.ignite.internal.managers.indexing.GridIndexingManager;
 import org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerManager;
 import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
 import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
 import org.apache.ignite.internal.processors.closure.GridClosureProcessor;

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
index 262c5eb..42a9b2c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
@@ -47,6 +47,7 @@ import org.apache.ignite.internal.managers.indexing.GridIndexingManager;
 import org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerManager;
 import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
 import org.apache.ignite.internal.processors.cache.CacheConflictResolutionManager;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
index 6a1ad6e..12a0fc3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
@@ -286,7 +286,7 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] valueBytes(CacheObjectContext cacheCtx) throws IgniteCheckedException {
+    @Override public byte[] valueBytes(CacheObjectValueContext cacheCtx) throws IgniteCheckedException {
         if (valBytes != null)
             return valBytes;
 
@@ -335,12 +335,12 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
     }
 
     /** {@inheritDoc} */
-    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+    @Override public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException {
         this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.kernalContext().cacheObjects()).binaryContext();
     }
 
     /** {@inheritDoc} */
-    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException {
         // No-op.
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index d0d0699..adbb9cb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -146,7 +146,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public byte[] valueBytes(CacheObjectValueContext ctx) throws IgniteCheckedException {
         if (detached())
             return array();
 
@@ -188,12 +188,12 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
     }
 
     /** {@inheritDoc} */
-    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+    @Override public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException {
         this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.kernalContext().cacheObjects()).binaryContext();
     }
 
     /** {@inheritDoc} */
-    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException {
         // No-op.
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
index 0a0a7b1..3e73e58 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@ -450,7 +450,7 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public byte[] valueBytes(CacheObjectValueContext ctx) throws IgniteCheckedException {
         throw new UnsupportedOperationException();
     }
 
@@ -460,12 +460,12 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
     }
 
     /** {@inheritDoc} */
-    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+    @Override public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException {
         throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
-    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException {
         throw new UnsupportedOperationException();
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
index 8faaa03..3bc2a6d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
@@ -50,7 +50,7 @@ public interface CacheObject extends Message {
      * @return Value bytes.
      * @throws IgniteCheckedException If failed.
      */
-    public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException;
+    public byte[] valueBytes(CacheObjectValueContext ctx) throws IgniteCheckedException;
 
     /**
      * @param ctx Cache object context.
@@ -111,11 +111,11 @@ public interface CacheObject extends Message {
      * @param ldr Class loader.
      * @throws IgniteCheckedException If failed.
      */
-    public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException;
+    public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException;
 
     /**
      * @param ctx Context.
      * @throws IgniteCheckedException If failed.
      */
-    public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException;
+    public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
index 6a13f8d..414bebb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
@@ -57,7 +57,7 @@ public class CacheObjectByteArrayImpl implements CacheObject, Externalizable {
     }
 
     /** {@inheritDoc} */
-    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+    @Override public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException {
         // No-op.
     }
 
@@ -70,7 +70,7 @@ public class CacheObjectByteArrayImpl implements CacheObject, Externalizable {
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public byte[] valueBytes(CacheObjectValueContext ctx) throws IgniteCheckedException {
         return val;
     }
 
@@ -114,7 +114,7 @@ public class CacheObjectByteArrayImpl implements CacheObject, Externalizable {
     }
 
     /** {@inheritDoc} */
-    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException {
         // No-op.
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
index 76f354a..2124a97 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
@@ -101,7 +101,7 @@ public class CacheObjectImpl extends CacheObjectAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public byte[] valueBytes(CacheObjectValueContext ctx) throws IgniteCheckedException {
         if (valBytes == null)
             valBytes = ctx.kernalContext().cacheObjects().marshal(ctx, val);
 
@@ -109,7 +109,7 @@ public class CacheObjectImpl extends CacheObjectAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException {
         assert val != null || valBytes != null;
 
         if (valBytes == null)
@@ -117,7 +117,7 @@ public class CacheObjectImpl extends CacheObjectAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+    @Override public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException {
         assert val != null || valBytes != null;
 
         if (val == null && ctx.storeValue())

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index e637122..4c1d615 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -1417,14 +1417,6 @@ public class GridCacheContext<K, V> implements Externalizable {
     }
 
     /**
-     * @return {@code True} if should use offheap (PageMemory) index.
-     */
-    public boolean offheapIndex() {
-        // TODO GG-10884.
-        return true;
-    }
-
-    /**
      * @return {@code True} if store read-through mode is enabled.
      */
     public boolean readThrough() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
index c50672b..1f4e790 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
@@ -73,7 +73,7 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public byte[] valueBytes(CacheObjectValueContext ctx) throws IgniteCheckedException {
         if (valBytes == null)
             valBytes = ctx.kernalContext().cacheObjects().marshal(ctx, val);
 
@@ -178,13 +178,13 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
     }
 
     /** {@inheritDoc} */
-    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+    @Override public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException {
         if (valBytes == null)
             valBytes = ctx.kernalContext().cacheObjects().marshal(ctx, val);
     }
 
     /** {@inheritDoc} */
-    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+    @Override public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException {
         if (val == null) {
             assert valBytes != null;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
index 5567809..a2d319f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
@@ -499,7 +499,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
         BinaryMetadataHolder holder = metadataLocCache.get(typeId);
 
         if (ctx.clientNode()) {
-            if (holder == null || (holder != null && !holder.metadata().hasSchema(schemaId))) {
+            if (holder == null || !holder.metadata().hasSchema(schemaId)) {
                 try {
                     transport.requestUpToDateMetadata(typeId).get();
 
@@ -737,7 +737,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
     /** {@inheritDoc} */
     @Override public byte[] marshal(CacheObjectValueContext ctx, Object val) throws IgniteCheckedException {
-        if (!((CacheObjectBinaryContext)ctx).binaryEnabled() || binaryMarsh == null)
+        if (!ctx.binaryEnabled() || binaryMarsh == null)
             return super.marshal(ctx, val);
 
         byte[] arr = binaryMarsh.marshal(val);
@@ -750,20 +750,16 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     /** {@inheritDoc} */
     @Override public Object unmarshal(CacheObjectValueContext ctx, byte[] bytes, ClassLoader clsLdr)
         throws IgniteCheckedException {
-        if (!((CacheObjectBinaryContext)ctx).binaryEnabled() || binaryMarsh == null)
+        if (!ctx.binaryEnabled() || binaryMarsh == null)
             return super.unmarshal(ctx, bytes, clsLdr);
 
         return binaryMarsh.unmarshal(bytes, clsLdr);
     }
 
     /** {@inheritDoc} */
-    @Override public KeyCacheObject toCacheKeyObject(
-        CacheObjectContext ctx,
-        @Nullable GridCacheContext cctx,
-        Object obj,
-        boolean userObj
-    ) {
-        if (!((CacheObjectBinaryContext)ctx).binaryEnabled())
+    @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, @Nullable GridCacheContext cctx,
+        Object obj, boolean userObj) {
+        if (!ctx.binaryEnabled())
             return super.toCacheKeyObject(ctx, cctx, obj, userObj);
 
         if (obj instanceof KeyCacheObject) {
@@ -794,7 +790,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     /** {@inheritDoc} */
     @Nullable @Override public CacheObject toCacheObject(CacheObjectContext ctx, @Nullable Object obj,
         boolean userObj) {
-        if (!((CacheObjectBinaryContext)ctx).binaryEnabled())
+        if (!ctx.binaryEnabled())
             return super.toCacheObject(ctx, obj, userObj);
 
         if (obj == null || obj instanceof CacheObject)
@@ -819,7 +815,8 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     }
 
     /** {@inheritDoc} */
-    @Override public KeyCacheObject toKeyCacheObject(CacheObjectContext ctx, byte type, byte[] bytes) throws IgniteCheckedException {
+    @Override public KeyCacheObject toKeyCacheObject(CacheObjectContext ctx, byte type, byte[] bytes)
+        throws IgniteCheckedException {
         if (type == BinaryObjectImpl.TYPE_BINARY)
             return new BinaryObjectImpl(binaryContext(), bytes, 0);
 
@@ -828,7 +825,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
     /** {@inheritDoc} */
     @Override public Object unwrapTemporary(GridCacheContext ctx, Object obj) throws BinaryObjectException {
-        if (!((CacheObjectBinaryContext)ctx.cacheObjectContext()).binaryEnabled())
+        if (!ctx.cacheObjectContext().binaryEnabled())
             return obj;
 
         if (obj instanceof BinaryObjectOffheapImpl)

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 65151c7..f3da6d0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -145,6 +145,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     /** */
     private final GridQueryIndexing idx;
 
+    /** Value object context. */
+    private final CacheQueryObjectValueContext valCtx;
+
     /** All indexes. */
     private final ConcurrentMap<QueryIndexKey, QueryIndexDescriptorImpl> idxs = new ConcurrentHashMap<>();
 
@@ -203,6 +206,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         else
             idx = INDEXING.inClassPath() ? U.<GridQueryIndexing>newInstance(INDEXING.className()) : null;
 
+        valCtx = new CacheQueryObjectValueContext(ctx);
+
         ioLsnr = new GridMessageListener() {
             @Override public void onMessage(UUID nodeId, Object msg) {
                 if (msg instanceof SchemaOperationStatusMessage) {
@@ -2375,6 +2380,14 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }
     }
 
+
+    /**
+     * @return Value object context.
+     */
+    public CacheQueryObjectValueContext objectContext() {
+        return valCtx;
+    }
+
     /**
      * @param ver Version.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
index e144325..a974cdb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
@@ -243,7 +243,7 @@ public class GridAffinityNoCacheSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+        @Override public byte[] valueBytes(CacheObjectValueContext ctx) throws IgniteCheckedException {
             throw new UnsupportedOperationException();
         }
 
@@ -284,12 +284,13 @@ public class GridAffinityNoCacheSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+        @Override public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr)
+            throws IgniteCheckedException {
             throw new UnsupportedOperationException();
         }
 
         /** {@inheritDoc} */
-        @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+        @Override public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException {
             throw new UnsupportedOperationException();
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteIncompleteCacheObjectSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteIncompleteCacheObjectSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteIncompleteCacheObjectSelfTest.java
index 77b6836..5b6d7f3 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteIncompleteCacheObjectSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteIncompleteCacheObjectSelfTest.java
@@ -107,7 +107,7 @@ public class IgniteIncompleteCacheObjectSelfTest extends GridCommonAbstractTest
         }
 
         /** {@inheritDoc} */
-        @Override public byte[] valueBytes(final CacheObjectContext ctx) throws IgniteCheckedException {
+        @Override public byte[] valueBytes(final CacheObjectValueContext ctx) throws IgniteCheckedException {
             return new byte[0];
         }
 
@@ -148,13 +148,13 @@ public class IgniteIncompleteCacheObjectSelfTest extends GridCommonAbstractTest
         }
 
         /** {@inheritDoc} */
-        @Override public void finishUnmarshal(final CacheObjectContext ctx,
-            final ClassLoader ldr) throws IgniteCheckedException {
+        @Override public void finishUnmarshal(final CacheObjectValueContext ctx, final ClassLoader ldr)
+            throws IgniteCheckedException {
             // No-op
         }
 
         /** {@inheritDoc} */
-        @Override public void prepareMarshal(final CacheObjectContext ctx) throws IgniteCheckedException {
+        @Override public void prepareMarshal(final CacheObjectValueContext ctx) throws IgniteCheckedException {
             // No-op
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
index a487218..7ccddb7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
@@ -469,7 +469,7 @@ public class FreeListImplSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+        @Override public byte[] valueBytes(CacheObjectValueContext ctx) throws IgniteCheckedException {
             return data;
         }
 
@@ -517,12 +517,13 @@ public class FreeListImplSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+        @Override public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr)
+            throws IgniteCheckedException {
             assert false;
         }
 
         /** {@inheritDoc} */
-        @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+        @Override public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException {
             assert false;
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
index 352fe85..d48c373 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
@@ -282,7 +282,8 @@ public class DmlStatementsProcessor {
             QueryCursorImpl<List<?>> stepCur = new QueryCursorImpl<>(new Iterable<List<?>>() {
                 @Override public Iterator<List<?>> iterator() {
                     try {
-                        return new GridQueryCacheObjectsIterator(res.iterator(), idx.valueContext(), cctx.keepBinary());
+                        return new GridQueryCacheObjectsIterator(res.iterator(), idx.objectContext(),
+                            cctx.keepBinary());
                     }
                     catch (IgniteCheckedException e) {
                         throw new IgniteException(e);
@@ -372,7 +373,7 @@ public class DmlStatementsProcessor {
             cur = new QueryCursorImpl<>(new Iterable<List<?>>() {
                 @Override public Iterator<List<?>> iterator() {
                     try {
-                        return new GridQueryCacheObjectsIterator(res.iterator(), idx.valueContext(), cctx.keepBinary());
+                        return new GridQueryCacheObjectsIterator(res.iterator(), idx.objectContext(), cctx.keepBinary());
                     }
                     catch (IgniteCheckedException e) {
                         throw new IgniteException(e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2ResultSetIterator.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2ResultSetIterator.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2ResultSetIterator.java
index 494f069..7b447dc 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2ResultSetIterator.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2ResultSetIterator.java
@@ -120,9 +120,7 @@ public abstract class H2ResultSetIterator<T> extends GridCloseableIteratorAdapte
                     if (val instanceof GridH2ValueCacheObject) {
                         GridH2ValueCacheObject valCacheObj = (GridH2ValueCacheObject)values[c];
 
-                        GridCacheContext cctx = valCacheObj.getCacheContext();
-
-                        row[c] = valCacheObj.getObject(cctx != null && cctx.needValueCopy());
+                        row[c] = valCacheObj.getObject(true);
                     }
                     else
                         row[c] = val.getObject();

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
index fbc9d6c..327ca14 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
@@ -218,9 +218,9 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
             CacheObject co = (CacheObject)obj;
 
             if (type == Value.JAVA_OBJECT)
-                return new GridH2ValueCacheObject(idx.cacheContext(schema.cacheName()), co);
+                return new GridH2ValueCacheObject(co, idx.objectContext());
 
-            obj = co.value(idx.objectContext(schema.cacheName()), false);
+            obj = co.value(idx.objectContext(), false);
         }
 
         switch (type) {
@@ -280,8 +280,7 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
 
     /** {@inheritDoc} */
     @Override public GridH2Row createRow(KeyCacheObject key, int partId, @Nullable CacheObject val,
-        GridCacheVersion ver,
-        long expirationTime) throws IgniteCheckedException {
+        GridCacheVersion ver, long expirationTime) throws IgniteCheckedException {
         GridH2Row row;
 
         try {
@@ -298,15 +297,11 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
                 "or configure key type as common super class for all actual keys for this value type.", e);
         }
 
-        GridCacheContext cctx = idx.cacheContext(schema.cacheName());
+        row.ver = ver;
 
-        if (cctx.offheapIndex()) {
-            row.ver = ver;
-
-            row.key = key;
-            row.val = val;
-            row.partId = partId;
-        }
+        row.key = key;
+        row.val = val;
+        row.partId = partId;
 
         return row;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
index 2440788..eedfc3a 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
@@ -59,6 +59,9 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
     /** */
     private final H2Schema schema;
 
+    /** Cache name. */
+    private final String cacheName;
+
     /** */
     private GridH2Table tbl;
 
@@ -74,11 +77,13 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
      * @param idx Indexing.
      * @param schema Schema.
      * @param type Type descriptor.
+     * @param cacheName Cache name.
      */
-    H2TableDescriptor(IgniteH2Indexing idx, H2Schema schema, GridQueryTypeDescriptor type) {
+    H2TableDescriptor(IgniteH2Indexing idx, H2Schema schema, GridQueryTypeDescriptor type, String cacheName) {
         this.idx = idx;
         this.type = type;
         this.schema = schema;
+        this.cacheName = cacheName;
 
         fullTblName = H2Utils.withQuotes(schema.schemaName()) + "." + H2Utils.withQuotes(type.tableName());
     }
@@ -140,6 +145,13 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
     }
 
     /**
+     * @return Cache name.
+     */
+    String cacheName() {
+        return cacheName;
+    }
+
+    /**
      * @return Type.
      */
     GridQueryTypeDescriptor type() {
@@ -167,7 +179,7 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
     H2RowFactory rowFactory(GridH2RowDescriptor rowDesc) {
         GridCacheContext cctx = schema.cacheContext();
 
-        if (cctx.affinityNode() && cctx.offheapIndex())
+        if (cctx.affinityNode())
             return new H2RowFactory(rowDesc, cctx);
 
         return null;
@@ -209,7 +221,7 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
 
         if (type().valueClass() == String.class) {
             try {
-                luceneIdx = new GridLuceneIndex(idx.kernalContext(), schema.offheap(), schema.cacheName(), type);
+                luceneIdx = new GridLuceneIndex(idx.kernalContext(), schema.offheap(), tbl.cacheName(), type);
             }
             catch (IgniteCheckedException e1) {
                 throw new IgniteException(e1);
@@ -222,7 +234,7 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
 
         if (textIdx != null) {
             try {
-                luceneIdx = new GridLuceneIndex(idx.kernalContext(), schema.offheap(), schema.cacheName(), type);
+                luceneIdx = new GridLuceneIndex(idx.kernalContext(), schema.offheap(), tbl.cacheName(), type);
             }
             catch (IgniteCheckedException e1) {
                 throw new IgniteException(e1);
@@ -319,7 +331,7 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
     private Index createHashIndex(H2Schema schema, GridH2Table tbl, String idxName, List<IndexColumn> cols) {
         GridCacheContext cctx = schema.cacheContext();
 
-        if (cctx.affinityNode() && cctx.offheapIndex()) {
+        if (cctx.affinityNode()) {
             assert pkHashIdx == null : pkHashIdx;
 
             pkHashIdx = new H2PkHashIndex(cctx, tbl, idxName, cols);

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableEngine.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableEngine.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableEngine.java
index 4cf5166..db34064 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableEngine.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableEngine.java
@@ -82,7 +82,7 @@ public class H2TableEngine implements TableEngine {
 
     /** {@inheritDoc} */
     @Override public TableBase createTable(CreateTableData createTblData) {
-        resTbl0 = new GridH2Table(createTblData, rowDesc0, rowFactory0, tblDesc0, tblDesc0.schema().cacheName());
+        resTbl0 = new GridH2Table(createTblData, rowDesc0, rowFactory0, tblDesc0, tblDesc0.cacheName());
 
         return resTbl0;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/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 508c8be..1e19954 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
@@ -62,7 +62,6 @@ import org.apache.ignite.internal.jdbc2.JdbcSqlFieldsQuery;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheEntryImpl;
 import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheAffinityManager;
@@ -579,27 +578,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             tbl.luceneIndex().store(k, v, ver, expirationTime);
     }
 
-    /**
-     * @param cacheName Cache name.
-     * @return Cache object context.
-     */
-    public CacheObjectContext objectContext(String cacheName) {
-        GridCacheContext cctx = cacheContext(cacheName);
-
-        return cctx != null ? cctx.cacheObjectContext() : null;
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @return Cache object context.
-     */
-    public GridCacheContext cacheContext(String cacheName) {
-        if (ctx == null)
-            return null;
-
-        return ctx.cache().internalCache(cacheName).context();
-    }
-
     /** {@inheritDoc} */
     @Override public void remove(String cacheName,
         GridQueryTypeDescriptor type,
@@ -1118,7 +1096,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             QueryCursorImpl<List<?>> cursor = new QueryCursorImpl<>(new Iterable<List<?>>() {
                 @Override public Iterator<List<?>> iterator() {
                     try {
-                        return new GridQueryCacheObjectsIterator(res.iterator(), valueContext(), keepBinary);
+                        return new GridQueryCacheObjectsIterator(res.iterator(), objectContext(), keepBinary);
                     }
                     catch (IgniteCheckedException e) {
                         throw new IgniteException(e);
@@ -1443,10 +1421,10 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 if (tblCnt > 0) {
                     caches0.add(cctx.cacheId());
 
-                    for (QueryTable table : twoStepQry.tables()) {
-                        String tblCacheName = cacheName(table.schema());
+                    for (QueryTable tblKey : twoStepQry.tables()) {
+                        GridH2Table tbl = dataTable(tblKey);
 
-                        int cacheId = CU.cacheId(tblCacheName);
+                        int cacheId = CU.cacheId(tbl.cacheName());
 
                         caches0.add(cacheId);
                     }
@@ -1600,7 +1578,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
         H2Schema schema = schemas.get(schemaName);
 
-        H2TableDescriptor tbl = new H2TableDescriptor(this, schema, type);
+        H2TableDescriptor tbl = new H2TableDescriptor(this, schema, type, cacheName);
 
         try {
             Connection conn = connectionForThread(schemaName);
@@ -1837,7 +1815,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
         Cursor cursor = hashIdx.find((Session)null, null, null);
 
-        int cacheId = CU.cacheId(tbl.schema().cacheName());
+        int cacheId = CU.cacheId(cacheName);
 
         GridCacheContext cctx = ctx.cache().context().cacheContext(cacheId);
 
@@ -2036,10 +2014,10 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /**
-     * @return Value context.
+     * @return Value object context.
      */
-    public CacheObjectValueContext valueContext() {
-        return valCtx;
+    public CacheObjectValueContext objectContext() {
+        return ctx.query().objectContext();
     }
 
     /**
@@ -2243,7 +2221,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         H2Schema rmv = schemas.remove(schema);
 
         if (rmv != null) {
-            cacheName2schema.remove(rmv.cacheName());
+            cacheName2schema.remove(cacheName);
             mapQryExec.onCacheStop(cacheName);
             dmlProc.onCacheStop(cacheName);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
index a2f5c88..d18668f 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
@@ -22,8 +22,7 @@ import java.sql.SQLException;
 import java.sql.Types;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.h2.message.DbException;
 import org.h2.util.JdbcUtils;
 import org.h2.util.Utils;
@@ -38,18 +37,20 @@ public class GridH2ValueCacheObject extends Value {
     /** */
     private CacheObject obj;
 
-    /** */
-    private GridCacheContext<?,?> cctx;
+    /** Object value context. */
+    private CacheObjectValueContext valCtx;
 
     /**
-     * @param cctx Cache context.
+     * Constructor.
+     *
      * @param obj Object.
+     * @param valCtx Object value context.
      */
-    public GridH2ValueCacheObject(GridCacheContext<?,?> cctx, CacheObject obj) {
+    public GridH2ValueCacheObject(CacheObject obj, CacheObjectValueContext valCtx) {
         assert obj != null;
 
         this.obj = obj;
-        this.cctx = cctx; // Allowed to be null in tests.
+        this.valCtx = valCtx;
     }
 
     /**
@@ -60,10 +61,10 @@ public class GridH2ValueCacheObject extends Value {
     }
 
     /**
-     * @return Cache context.
+     * @return Value context.
      */
-    public GridCacheContext<?,?> getCacheContext() {
-        return cctx;
+    public CacheObjectValueContext valueContext() {
+        return valCtx;
     }
 
     /** {@inheritDoc} */
@@ -96,19 +97,12 @@ public class GridH2ValueCacheObject extends Value {
         return Utils.cloneByteArray(getBytesNoCopy());
     }
 
-    /**
-     * @return Cache object context.
-     */
-    private CacheObjectContext objectContext() {
-        return cctx == null ? null : cctx.cacheObjectContext();
-    }
-
     /** {@inheritDoc} */
     @Override public byte[] getBytesNoCopy() {
         if (obj.cacheObjectType() == CacheObject.TYPE_REGULAR) {
             // Result must be the same as `marshaller.marshall(obj.value(coctx, false));`
             try {
-                return obj.valueBytes(objectContext());
+                return obj.valueBytes(valCtx);
             }
             catch (IgniteCheckedException e) {
                 throw DbException.convert(e);
@@ -129,7 +123,7 @@ public class GridH2ValueCacheObject extends Value {
      * @return Value.
      */
     public Object getObject(boolean cpy) {
-        return obj.isPlatformType() ? obj.value(objectContext(), cpy) : obj;
+        return obj.isPlatformType() ? obj.value(valCtx, cpy) : obj;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
index b7bdde5..afaf68d 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
@@ -1146,17 +1146,13 @@ public class GridMapQueryExecutor {
                         if (val instanceof GridH2ValueCacheObject) {
                             GridH2ValueCacheObject valCacheObj = (GridH2ValueCacheObject)val;
 
-                            GridCacheContext cctx = valCacheObj.getCacheContext();
-
-                            if (cctx != null && cctx.needValueCopy()) {
-                                row[j] = new GridH2ValueCacheObject(valCacheObj.getCacheContext(), valCacheObj.getCacheObject()) {
-                                    @Override public Object getObject() {
-                                        return getObject(true);
-                                    }
-                                };
+                            row[j] = new GridH2ValueCacheObject(valCacheObj.getCacheObject(), h2.objectContext()) {
+                                @Override public Object getObject() {
+                                    return getObject(true);
+                                }
+                            };
 
-                                copied = true;
-                            }
+                            copied = true;
                         }
                     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
index 8d9d953..9445534 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
@@ -818,7 +818,7 @@ public class GridReduceQueryExecutor {
                     continue;
                 }
 
-                return new GridQueryCacheObjectsIterator(resIter, h2.valueContext(), keepPortable);
+                return new GridQueryCacheObjectsIterator(resIter, h2.objectContext(), keepPortable);
             }
             catch (IgniteCheckedException | RuntimeException e) {
                 U.closeQuiet(r.connection());

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2CacheObject.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2CacheObject.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2CacheObject.java
index d0e8cb6..bc3b7a3 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2CacheObject.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2CacheObject.java
@@ -21,7 +21,7 @@ import java.nio.ByteBuffer;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject;
 import org.apache.ignite.plugin.extensions.communication.MessageReader;
 import org.apache.ignite.plugin.extensions.communication.MessageWriter;
@@ -32,9 +32,6 @@ import org.h2.value.Value;
  */
 public class GridH2CacheObject extends GridH2ValueMessage {
     /** */
-    private int cacheId;
-
-    /** */
     private CacheObject obj;
 
     /**
@@ -51,26 +48,16 @@ public class GridH2CacheObject extends GridH2ValueMessage {
     public GridH2CacheObject(GridH2ValueCacheObject v) throws IgniteCheckedException {
         this.obj = v.getCacheObject();
 
-        GridCacheContext<?,?> cctx = v.getCacheContext();
-
-        if (cctx != null) {
-            this.cacheId = cctx.cacheId();
-
-            obj.prepareMarshal(cctx.cacheObjectContext());
-        }
+        obj.prepareMarshal(v.valueContext());
     }
 
     /** {@inheritDoc} */
     @Override public Value value(GridKernalContext ctx) throws IgniteCheckedException {
-        GridCacheContext<?,?> cctx = null;
+        CacheObjectValueContext valCtx = ctx.query().objectContext();
 
-        if (ctx != null) {
-            cctx = ctx.cache().context().cacheContext(cacheId);
+        obj.finishUnmarshal(valCtx, ctx.cache().context().deploy().globalLoader());
 
-            obj.finishUnmarshal(cctx.cacheObjectContext(), cctx.deploy().globalLoader());
-        }
-
-        return new GridH2ValueCacheObject(cctx, obj);
+        return new GridH2ValueCacheObject(obj, valCtx);
     }
 
     /** {@inheritDoc} */
@@ -85,14 +72,6 @@ public class GridH2CacheObject extends GridH2ValueMessage {
 
         switch (reader.state()) {
             case 0:
-                cacheId = reader.readInt("cacheId");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 1:
                 obj = reader.readMessage("obj");
 
                 if (!reader.isLastRead())
@@ -121,12 +100,6 @@ public class GridH2CacheObject extends GridH2ValueMessage {
 
         switch (writer.state()) {
             case 0:
-                if (!writer.writeInt("cacheId", cacheId))
-                    return false;
-
-                writer.incrementState();
-
-            case 1:
                 if (!writer.writeMessage("obj", obj))
                     return false;
 
@@ -144,7 +117,7 @@ public class GridH2CacheObject extends GridH2ValueMessage {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 2;
+        return 1;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/fb12f0fa/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
index 1f73dcb..73a7191 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
@@ -742,7 +742,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         }
 
         /** {@inheritDoc} */
-        @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+        @Override public byte[] valueBytes(CacheObjectValueContext ctx) throws IgniteCheckedException {
             return JdbcUtils.serialize(val, null);
         }
 
@@ -788,12 +788,12 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         }
 
         /** {@inheritDoc} */
-        @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+        @Override public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException {
             throw new UnsupportedOperationException();
         }
 
         /** {@inheritDoc} */
-        @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+        @Override public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException {
             throw new UnsupportedOperationException();
         }
 


[11/22] ignite git commit: IGNITE-5200 Reworked webpack build.

Posted by sb...@apache.org.
IGNITE-5200 Reworked webpack build.


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

Branch: refs/heads/ignite-5075
Commit: 88fd1a63f0fe8b856cbb42c750a9f3b4efced530
Parents: 52e14ac
Author: Andrey Novikov <an...@gridgain.com>
Authored: Mon May 29 10:11:24 2017 +0700
Committer: Andrey Novikov <an...@gridgain.com>
Committed: Mon May 29 10:11:24 2017 +0700

----------------------------------------------------------------------
 modules/web-console/frontend/.babelrc           |   9 +-
 modules/web-console/frontend/.gitignore         |   1 -
 modules/web-console/frontend/app/app.js         |  18 +-
 .../components/web-console-header/component.js  |   6 +-
 .../app/modules/agent/AgentManager.service.js   |   2 -
 .../frontend/gulpfile.babel.js/index.js         |  26 ---
 .../frontend/gulpfile.babel.js/paths.js         |  64 ------
 .../frontend/gulpfile.babel.js/tasks/build.js   |  21 --
 .../frontend/gulpfile.babel.js/tasks/bundle.js  |  36 ----
 .../frontend/gulpfile.babel.js/tasks/clean.js   |  32 ---
 .../frontend/gulpfile.babel.js/tasks/copy.js    |  33 ---
 .../gulpfile.babel.js/tasks/ignite-modules.js   |  55 -----
 .../frontend/gulpfile.babel.js/tasks/watch.js   |  30 ---
 .../gulpfile.babel.js/webpack/common.js         | 205 -------------------
 .../webpack/environments/development.js         |  60 ------
 .../webpack/environments/production.js          |  41 ----
 .../webpack/environments/test.js                |  44 ----
 .../frontend/gulpfile.babel.js/webpack/index.js |  36 ----
 .../frontend/ignite_modules/index.js            |   7 +-
 modules/web-console/frontend/package.json       | 104 ++++------
 .../frontend/test/karma.conf.babel.js           |  13 +-
 modules/web-console/frontend/test/karma.conf.js |   2 +-
 .../frontend/webpack/webpack.common.js          | 188 +++++++++++++++++
 .../frontend/webpack/webpack.dev.babel.js       | 100 +++++++++
 .../frontend/webpack/webpack.prod.babel.js      |  64 ++++++
 .../frontend/webpack/webpack.test.js            |  33 +++
 26 files changed, 449 insertions(+), 781 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/.babelrc
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/.babelrc b/modules/web-console/frontend/.babelrc
index a1d48c1..da16f08 100644
--- a/modules/web-console/frontend/.babelrc
+++ b/modules/web-console/frontend/.babelrc
@@ -1,9 +1,4 @@
 {
-  "presets": ["angular"],
-  "plugins": [[
-    "transform-builtin-extend", {
-      "globals": ["Error", "Array"],
-      "approximate": true
-    }
-  ]]
+  "presets": ["es2015", "stage-1"],
+  "plugins": ["add-module-exports"]
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/.gitignore
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/.gitignore b/modules/web-console/frontend/.gitignore
index 27138f6..296d61c 100644
--- a/modules/web-console/frontend/.gitignore
+++ b/modules/web-console/frontend/.gitignore
@@ -4,5 +4,4 @@
 .npmrc
 build/*
 node_modules
-ignite_modules_temp/*
 public/stylesheets/*.css

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/app/app.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/app/app.js b/modules/web-console/frontend/app/app.js
index e32b1ad..df58f0e 100644
--- a/modules/web-console/frontend/app/app.js
+++ b/modules/web-console/frontend/app/app.js
@@ -103,11 +103,11 @@ import hasPojo from './filters/hasPojo.filter';
 import uiGridSubcategories from './filters/uiGridSubcategories.filter';
 
 // Controllers
-import caches from 'controllers/caches-controller';
-import clusters from 'controllers/clusters-controller';
-import domains from 'controllers/domains-controller';
-import igfs from 'controllers/igfs-controller';
-import profile from 'controllers/profile-controller';
+import caches from '../controllers/caches-controller';
+import clusters from '../controllers/clusters-controller';
+import domains from '../controllers/domains-controller';
+import igfs from '../controllers/igfs-controller';
+import profile from '../controllers/profile-controller';
 import auth from './controllers/auth.controller';
 import resetPassword from './controllers/reset-password.controller';
 
@@ -121,7 +121,7 @@ import webConsoleFooter from './components/web-console-footer';
 import igniteIcon from './components/ignite-icon';
 
 // Inject external modules.
-import 'ignite_modules_temp/index';
+import IgniteModules from 'IgniteModules/index';
 
 import baseTemplate from 'views/base.pug';
 
@@ -175,12 +175,12 @@ angular
     'ignite-console.loading',
     // Ignite configuration module.
     'ignite-console.config',
-    // Ignite modules.
-    'ignite-console.modules',
     // Components
     webConsoleHeader.name,
     webConsoleFooter.name,
-    igniteIcon.name
+    igniteIcon.name,
+    // Ignite modules.
+    IgniteModules.name
 ])
 // Directives.
 .directive(...igniteAutoFocus)

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/app/components/web-console-header/component.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/app/components/web-console-header/component.js b/modules/web-console/frontend/app/components/web-console-header/component.js
index 339ec46..364037f 100644
--- a/modules/web-console/frontend/app/components/web-console-header/component.js
+++ b/modules/web-console/frontend/app/components/web-console-header/component.js
@@ -21,7 +21,7 @@ import './style.scss';
 export default {
     template,
     controller: class {
-        static $inject = ['$scope', '$state', 'IgniteBranding'];
+        static $inject = ['$rootScope', '$scope', '$state', 'IgniteBranding'];
 
         static webAgentDownloadVisibleStates = [
             'base.configuration',
@@ -29,8 +29,8 @@ export default {
             'base.settings'
         ];
 
-        constructor($scope, $state, branding) {
-            Object.assign(this, {$scope, $state, branding});
+        constructor($rootScope, $scope, $state, branding) {
+            Object.assign(this, {$rootScope, $scope, $state, branding});
         }
 
         $onInit() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/app/modules/agent/AgentManager.service.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js
index c511242..3344ef2 100644
--- a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js
+++ b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js
@@ -15,8 +15,6 @@
  * limitations under the License.
  */
 
-import io from 'socket.io-client'; // eslint-disable-line no-unused-vars
-
 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
 
 const maskNull = (val) => _.isNil(val) ? 'null' : val;

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/index.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/index.js b/modules/web-console/frontend/gulpfile.babel.js/index.js
deleted file mode 100644
index 95602a1..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/index.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.
- */
-
-import gulp from 'gulp';
-import requireDir from 'require-dir';
-
-// Require all tasks in gulpfile.js/tasks, including subfolders.
-requireDir('./tasks', { recurse: true });
-
-// Default no-arg task.
-gulp.task('default', ['build']);
-

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/paths.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/paths.js b/modules/web-console/frontend/gulpfile.babel.js/paths.js
deleted file mode 100644
index 0007c18..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/paths.js
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.
- */
-
-import path from 'path';
-
-const rootDir = path.resolve('./');
-const srcDir = path.resolve('app');
-const destDir = path.resolve('build');
-
-const igniteModulesDir = process.env.IGNITE_MODULES ? path.join(path.normalize(process.env.IGNITE_MODULES), 'frontend') : './ignite_modules';
-const igniteModulesTemp = path.resolve('ignite_modules_temp');
-
-const appModulePaths = [
-    igniteModulesDir + '/index.js',
-    igniteModulesDir + '/**/main.js',
-    igniteModulesDir + '/**/module.js',
-    igniteModulesDir + '/**/app/modules/*.js',
-    igniteModulesDir + '/**/app/modules/**/*.js',
-    igniteModulesDir + '/**/app/modules/**/*.pug',
-    igniteModulesDir + '/**/*.pug',
-    igniteModulesDir + '/**/*.tpl.pug',
-    igniteModulesDir + '/**/app/**/*.js',
-    igniteModulesDir + '/**/app/**/*.css',
-    igniteModulesDir + '/**/app/**/*.scss',
-    igniteModulesDir + '/**/app/data/*.json'
-];
-
-const resourcePaths = [
-    './public/**/*.svg',
-    './public/**/*.png',
-    './public/*.ico'
-];
-
-const resourceModulePaths = [
-    igniteModulesDir + '/**/images/*.png',
-    igniteModulesDir + '/**/images/*.svg',
-    igniteModulesDir + '/*.ico'
-];
-
-export {
-    rootDir,
-    srcDir,
-    destDir,
-    igniteModulesDir,
-    igniteModulesTemp,
-
-    resourcePaths,
-    resourceModulePaths,
-    appModulePaths
-};

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/tasks/build.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/tasks/build.js b/modules/web-console/frontend/gulpfile.babel.js/tasks/build.js
deleted file mode 100644
index 149b076..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/tasks/build.js
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.
- */
-
-import gulp from 'gulp';
-import sequence from 'gulp-sequence';
-
-gulp.task('build', (cb) => sequence(['clean', 'clean:ignite-modules-temp'], 'ignite:modules', ['copy:resource'], 'bundle', cb));

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/tasks/bundle.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/tasks/bundle.js b/modules/web-console/frontend/gulpfile.babel.js/tasks/bundle.js
deleted file mode 100644
index d42a711..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/tasks/bundle.js
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.
- */
-
-import gulp from 'gulp';
-import webpack from 'webpack';
-import webpackConfig from '../webpack';
-import WebpackDevServer from 'webpack-dev-server';
-
-gulp.task('bundle', (cb) => {
-    const devServerConfig = webpackConfig.devServer;
-
-    delete webpackConfig.devServer;
-
-    if (process.env.NODE_ENV === 'development') {
-        // Important! Call webpack and WebpackDevServer must be inline.
-        new WebpackDevServer(webpack(webpackConfig), devServerConfig)
-            .listen(devServerConfig.port, devServerConfig.host, cb);
-    }
-    else
-        webpack(webpackConfig, cb);
-});
-

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/tasks/clean.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/tasks/clean.js b/modules/web-console/frontend/gulpfile.babel.js/tasks/clean.js
deleted file mode 100644
index c9104b2..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/tasks/clean.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.
- */
-
-import gulp from 'gulp';
-import clean from 'gulp-rimraf';
-
-import { destDir, igniteModulesTemp } from '../paths';
-
-// Clean build folder, remove files.
-gulp.task('clean', () =>
-    gulp.src(`${destDir}/*`, {read: false})
-        .pipe(clean({ force: true }))
-);
-
-gulp.task('clean:ignite-modules-temp', () =>
-    gulp.src(igniteModulesTemp, {read: false})
-        .pipe(clean({ force: true }))
-);

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/tasks/copy.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/tasks/copy.js b/modules/web-console/frontend/gulpfile.babel.js/tasks/copy.js
deleted file mode 100644
index 59373a8..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/tasks/copy.js
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.
- */
-
-import gulp from 'gulp';
-import sequence from 'gulp-sequence';
-
-import { destDir, resourcePaths, resourceModulePaths } from '../paths';
-
-gulp.task('copy:resource', (cb) => sequence('copy:resource:app', 'copy:resource:ignite_modules', cb));
-
-gulp.task('copy:resource:app', () =>
-    gulp.src(resourcePaths)
-        .pipe(gulp.dest(destDir))
-);
-
-gulp.task('copy:resource:ignite_modules', () =>
-    gulp.src(resourceModulePaths)
-        .pipe(gulp.dest(`${destDir}/ignite_modules`))
-);

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/tasks/ignite-modules.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/tasks/ignite-modules.js b/modules/web-console/frontend/gulpfile.babel.js/tasks/ignite-modules.js
deleted file mode 100644
index b97de7c..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/tasks/ignite-modules.js
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.
- */
-
-import gulp from 'gulp';
-import inject from 'gulp-inject';
-import clean from 'gulp-rimraf';
-import sequence from 'gulp-sequence';
-import {appModulePaths, igniteModulesTemp} from '../paths';
-
-gulp.task('ignite:modules', (cb) => sequence('ignite:modules:copy', 'ignite:modules:inject', cb));
-
-gulp.task('ignite:modules:copy', () =>
-    gulp.src(appModulePaths)
-        .pipe(gulp.dest(igniteModulesTemp))
-);
-
-gulp.task('ignite:modules:inject', () =>
-    gulp.src(`${igniteModulesTemp}/index.js`)
-        .pipe(inject(gulp.src([`${igniteModulesTemp}/**/main.js`]), {
-            starttag: '/* ignite:modules */',
-            endtag: '/* endignite */',
-            transform: (filePath) => {
-                const igniteModuleName = filePath.replace(/.*ignite_modules_temp\/([^\/]+).*/mgi, '$1');
-
-                // Return file contents as string.
-                return `import './${igniteModuleName}/main';`;
-            }
-        }))
-        .pipe(inject(gulp.src([`${igniteModulesTemp}/**/main.js`]), {
-            starttag: '/* ignite-console:modules */',
-            endtag: '/* endignite */',
-            transform: (filePath, file, i) => {
-                const igniteModuleName = filePath.replace(/.*ignite_modules_temp\/([^\/]+).*/mgi, '$1');
-
-                // Return file contents as string.
-                return (i ? ',' : '') + `'ignite-console.${igniteModuleName}'`;
-            }
-        }))
-        .pipe(clean({force: true}))
-        .pipe(gulp.dest(igniteModulesTemp))
-);

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/tasks/watch.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/tasks/watch.js b/modules/web-console/frontend/gulpfile.babel.js/tasks/watch.js
deleted file mode 100644
index 9a02b88..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/tasks/watch.js
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.
- */
-
-import gulp from 'gulp';
-import sequence from 'gulp-sequence';
-
-import { resourcePaths, resourceModulePaths, appModulePaths } from '../paths';
-
-gulp.task('watch:ignite-modules', (cb) => sequence('clean:ignite-modules-temp', 'ignite:modules', cb));
-
-// Build + watch task.
-gulp.task('watch', ['build'], () => {
-    gulp.watch(resourcePaths, ['copy:resource:app']);
-    gulp.watch(resourceModulePaths, ['copy:resource:ignite_modules']);
-    gulp.watch(appModulePaths, ['watch:ignite-modules']);
-});

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/webpack/common.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/webpack/common.js b/modules/web-console/frontend/gulpfile.babel.js/webpack/common.js
deleted file mode 100644
index 75b0ef4..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/webpack/common.js
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * 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.
- */
-
-import path from 'path';
-import fs from 'fs';
-import webpack from 'webpack';
-
-import ProgressBarPlugin from 'progress-bar-webpack-plugin';
-import eslintFormatter from 'eslint-friendly-formatter';
-
-import HtmlWebpackPlugin from 'html-webpack-plugin';
-
-import ExtractTextPlugin from 'extract-text-webpack-plugin';
-
-import {srcDir, destDir, rootDir, igniteModulesDir} from '../paths';
-
-const viewsDir = path.resolve('views');
-const imagesDir = path.resolve('public/images');
-const iconsDir = path.resolve('public/images/icons');
-
-const NODE_ENV = process.env.NODE_ENV || 'production';
-const development = NODE_ENV === 'development';
-const node_modules_path = path.resolve('node_modules');
-
-let favicon = 'build/ignite_modules/favicon.ico';
-
-try {
-    fs.accessSync(path.join(igniteModulesDir, 'favicon.ico'), fs.F_OK);
-} catch (ignore) {
-    favicon = 'build/favicon.ico';
-}
-
-export default {
-    cache: true,
-    node: {
-        fs: 'empty'
-    },
-    // Entry points.
-    entry: {
-        polyfill: 'babel-polyfill',
-        vendor: path.join(srcDir, 'vendor.js'),
-        app: path.join(srcDir, 'app.js')
-    },
-
-    // Output system.
-    output: {
-        path: destDir,
-        filename: '[name].js'
-    },
-
-    // Resolves modules.
-    resolve: {
-        extensions: [
-            '.js'
-        ],
-        modules: [
-            srcDir,
-            rootDir,
-            node_modules_path
-        ],
-        // A list of module source folders.
-        alias: {
-            app: srcDir,
-            views: viewsDir,
-            images: imagesDir
-        }
-    },
-
-    // Resolve loader use postfix.
-    resolveLoader: {
-        moduleExtensions: ['-loader']
-    },
-
-    module: {
-        rules: [
-            {
-                test: /\.json$/,
-                loader: 'json'
-            },
-
-            // Exclude tpl.pug files to import in bundle.
-            {
-                test: /^(?:(?!tpl\.pug$).)*\.pug$/, // TODO: check this regexp for correct.
-                loader: `pug-html?basedir=${rootDir}`
-            },
-
-            // Render .tpl.pug files to assets folder.
-            {
-                test: /\.tpl\.pug$/,
-                use: [
-                    'file?exports=false&name=assets/templates/[name].[hash].html',
-                    `pug-html?exports=false&basedir=${rootDir}`
-                ]
-            },
-            {
-                test: /\.js$/,
-                enforce: 'pre',
-                exclude: [node_modules_path],
-                use: [{
-                    loader: 'eslint',
-                    options: {
-                        failOnWarning: false,
-                        failOnError: false,
-                        formatter: eslintFormatter
-                    }
-                }]
-            },
-            {
-                test: /\.js$/,
-                exclude: [node_modules_path],
-                use: [{
-                    loader: 'babel',
-                    options: {
-                        cacheDirectory: true,
-                        plugins: [
-                            'transform-runtime',
-                            'add-module-exports'
-                        ],
-                        presets: ['angular']
-                    }
-                }]
-            },
-            {
-                test: /\.css$/,
-                use: development ? ['style', 'css'] : ExtractTextPlugin.extract({
-                    fallback: 'style',
-                    use: ['css']
-                })
-            },
-            {
-                test: /\.scss$/,
-                use: development ? ['style', 'css', 'sass'] : ExtractTextPlugin.extract({
-                    fallback: 'style-loader',
-                    use: ['css', 'sass']
-                })
-            },
-            {
-                test: /\.(ttf|eot|svg|woff(2)?)(\?v=[\d.]+)?(\?[a-z0-9#-]+)?$/,
-                exclude: [iconsDir],
-                loader: 'file?name=assets/fonts/[name].[ext]'
-            },
-            {
-                test: /.*\.svg$/,
-                include: [iconsDir],
-                use: ['svg-sprite-loader']
-            },
-            {
-                test: /\.(jpe?g|png|gif)$/i,
-                loader: 'file?name=assets/images/[name]_[hash].[ext]'
-            },
-            {
-                test: require.resolve('jquery'),
-                use: [
-                    'expose-loader?$',
-                    'expose-loader?jQuery'
-                ]
-            },
-            {
-                test: require.resolve('nvd3'),
-                use: ['expose-loader?nv']
-            }
-        ]
-    },
-
-    // Load plugins.
-    plugins: [
-        new webpack.LoaderOptionsPlugin({
-            options: {
-                pug: {
-                    basedir: rootDir
-                },
-                target: 'web'
-            }
-        }),
-        new webpack.ProvidePlugin({
-            $: 'jquery',
-            jQuery: 'jquery',
-            _: 'lodash',
-            nv: 'nvd3'
-        }),
-        new webpack.DefinePlugin({NODE_ENV: JSON.stringify(NODE_ENV)}),
-        new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}),
-        new webpack.optimize.AggressiveMergingPlugin({moveToParents: true}),
-        new HtmlWebpackPlugin({
-            template: './views/index.pug',
-            favicon
-        }),
-        new ExtractTextPlugin({filename: 'assets/css/[name].css', allChunks: true}),
-        new ProgressBarPlugin()
-    ]
-};

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/development.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/development.js b/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/development.js
deleted file mode 100644
index 28ecc13..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/development.js
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.
- */
-
-import {destDir} from '../../paths';
-
-const backendPort = 3000;
-const devServerPort = process.env.PORT || 9000;
-const devServerHost = process.env.HOST || '0.0.0.0';
-
-export default {
-    devtool: 'source-map',
-    watch: true,
-    devServer: {
-        compress: true,
-        historyApiFallback: true,
-        contentBase: destDir,
-        // hot: true,
-        inline: true,
-        proxy: {
-            '/socket.io': {
-                target: `http://localhost:${backendPort}`,
-                ws: true
-            },
-            '/agents': {
-                target: `http://localhost:${backendPort}`,
-                ws: true
-            },
-            '/api/v1/*': {
-                target: `http://localhost:${backendPort}`,
-                pathRewrite: {
-                    '^/api/v1': ''
-                }
-            }
-        },
-        watchOptions: {
-            aggregateTimeout: 1000,
-            poll: 2000
-        },
-        stats: {
-            colors: true,
-            chunks: false
-        },
-        host: devServerHost,
-        port: devServerPort
-    }
-};

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/production.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/production.js b/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/production.js
deleted file mode 100644
index cbbe9ca..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/production.js
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.
- */
-
-
-import webpack from 'webpack';
-
-import {destDir} from '../../paths';
-
-const plugins = [
-    new webpack.optimize.UglifyJsPlugin({
-        path: destDir,
-        minimize: true,
-        warnings: false,
-        sourceMap: false,
-        mangle: true
-    })
-];
-
-export default {
-    bail: true, // Cancel build on error.
-    devtool: 'cheap-source-map',
-    output: {
-        publicPath: '/',
-        filename: '[name].[chunkhash].js'
-    },
-    plugins
-};

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/test.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/test.js b/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/test.js
deleted file mode 100644
index 0cb9b77..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/webpack/environments/test.js
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.
- */
-
-import webpack from 'webpack';
-
-const NODE_ENV = process.env.NODE_ENV || 'production';
-
-export default {
-    cache: true,
-    node: {
-        fs: 'empty'
-    },
-
-    // Entry points.
-    entry: null,
-
-    // Output system.
-    output: null,
-
-    // Load plugins.
-    plugins: [
-        new webpack.ProvidePlugin({
-            $: 'jquery',
-            jQuery: 'jquery',
-            _: 'lodash',
-            nv: 'nvd3'
-        }),
-        new webpack.DefinePlugin({NODE_ENV: JSON.stringify(NODE_ENV)})
-    ]
-};

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/gulpfile.babel.js/webpack/index.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/gulpfile.babel.js/webpack/index.js b/modules/web-console/frontend/gulpfile.babel.js/webpack/index.js
deleted file mode 100644
index 3caf06c..0000000
--- a/modules/web-console/frontend/gulpfile.babel.js/webpack/index.js
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.
- */
-
-import _ from 'lodash';
-import commonConfig from './common';
-import devConfig from './environments/development';
-import prodConfig from './environments/production';
-
-// TODO check test config
-import testConfig from './environments/test';
-
-const env = process.env.NODE_ENV || 'production';
-
-// Config by environments.
-const configs = {
-    production: prodConfig,
-    development: devConfig,
-    test: testConfig
-};
-
-// Load config file by environment
-export default _.merge(commonConfig, configs[env]);

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/ignite_modules/index.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/ignite_modules/index.js b/modules/web-console/frontend/ignite_modules/index.js
index c38d2d4..21ccf6a 100644
--- a/modules/web-console/frontend/ignite_modules/index.js
+++ b/modules/web-console/frontend/ignite_modules/index.js
@@ -17,11 +17,6 @@
 
 import angular from 'angular';
 
-/* ignite:modules */
-/* endignite */
-
-angular
+export default angular
 .module('ignite-console.modules', [
-    /* ignite-console:modules */
-    /* endignite */
 ]);

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/package.json
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/package.json b/modules/web-console/frontend/package.json
index 31a34f2..b20089a 100644
--- a/modules/web-console/frontend/package.json
+++ b/modules/web-console/frontend/package.json
@@ -4,10 +4,11 @@
   "description": "Interactive Web console for configuration, executing SQL queries and monitoring of Apache Ignite Cluster",
   "private": true,
   "scripts": {
-    "dev": "cross-env NODE_ENV=development gulp watch",
-    "build": "cross-env NODE_ENV=production gulp build",
-    "test": "cross-env NODE_ENV=test karma start ./test/karma.conf.js",
-    "eslint": "eslint --format node_modules/eslint-friendly-formatter gulpfile.babel.js/ app/ controllers/ ignite_modules/ ignite_modules_temp/ -- --eff-by-issue"
+    "start": "webpack-dev-server --config ./webpack/webpack.dev.babel.js",
+    "dev": "npm start",
+    "build": "webpack --config ./webpack/webpack.prod.babel.js",
+    "test": "karma start ./test/karma.conf.js",
+    "eslint": "eslint --format node_modules/eslint-friendly-formatter gulpfile.babel.js/ app/ controllers/ ignite_modules/ -- --eff-by-issue"
   },
   "author": "",
   "contributors": [
@@ -20,8 +21,8 @@
   "keywords": "grid",
   "homepage": "https://ignite.apache.org/",
   "engines": {
-    "npm": "^3.x.x",
-    "node": "^4.x.x"
+    "npm": "3.x.x",
+    "node": "4.x.x"
   },
   "os": [
     "darwin",
@@ -48,55 +49,57 @@
     "angular-tree-control": "0.2.28",
     "angular-ui-grid": "4.0.4",
     "angular-ui-router": "0.4.2",
+    "babel-core": "6.24.1",
+    "babel-eslint": "7.2.3",
+    "babel-loader": "7.0.0",
+    "babel-plugin-add-module-exports": "0.2.1",
+    "babel-plugin-transform-runtime": "6.23.0",
+    "babel-polyfill": "6.23.0",
+    "babel-preset-es2015": "6.24.1",
+    "babel-preset-stage-1": "6.24.1",
+    "babel-runtime": "6.23.0",
     "bootstrap-sass": "3.3.7",
     "brace": "0.10.0",
-    "es6-promise": "4.1.0",
+    "copy-webpack-plugin": "4.0.1",
+    "css-loader": "0.28.3",
+    "eslint": "3.19.0",
+    "eslint-friendly-formatter": "3.0.0",
+    "eslint-loader": "1.7.1",
+    "expose-loader": "0.7.3",
+    "extract-text-webpack-plugin": "2.1.0",
+    "file-loader": "0.11.1",
     "file-saver": "1.3.3",
     "font-awesome": "4.7.0",
-    "glob": "7.1.1",
+    "glob": "7.1.2",
+    "html-loader": "0.4.5",
+    "html-webpack-plugin": "2.28.0",
     "jquery": "3.2.1",
+    "json-loader": "0.5.4",
     "jszip": "3.1.3",
     "lodash": "4.17.4",
+    "node-sass": "4.5.3",
     "nvd3": "1.8.4",
+    "progress-bar-webpack-plugin": "1.9.3",
+    "pug-html-loader": "1.1.0",
+    "pug-loader": "2.3.0",
     "raleway-webfont": "3.0.1",
+    "resolve-url-loader": "2.0.2",
     "roboto-font": "0.1.0",
     "rxjs": "5.4.0",
+    "sass-loader": "6.0.5",
     "socket.io-client": "1.7.3",
-    "ui-router-metatags": "1.0.3"
+    "style-loader": "0.18.1",
+    "svg-sprite-loader": "^3.0.2",
+    "ui-router-metatags": "1.0.3",
+    "webpack": "2.6.1",
+    "webpack-dev-server": "2.4.5",
+    "webpack-merge": "4.1.0",
+    "worker-loader": "0.8.0"
   },
   "devDependencies": {
-    "assets-webpack-plugin": "3.5.1",
-    "autoprefixer": "6.7.7",
-    "babel-core": "6.24.1",
-    "babel-eslint": "7.2.1",
-    "babel-loader": "6.4.1",
-    "babel-plugin-add-module-exports": "0.2.1",
-    "babel-plugin-transform-builtin-extend": "1.1.2",
-    "babel-plugin-transform-runtime": "6.23.0",
-    "babel-polyfill": "6.23.0",
-    "babel-preset-angular": "6.0.15",
-    "babel-preset-es2015": "6.24.1",
-    "babel-runtime": "6.23.0",
     "chai": "3.5.0",
-    "cross-env": "4.0.0",
-    "css-loader": "0.28.0",
-    "eslint": "3.19.0",
-    "eslint-friendly-formatter": "2.0.7",
-    "eslint-loader": "1.7.1",
-    "expose-loader": "0.7.3",
-    "extract-text-webpack-plugin": "2.1.0",
-    "file-loader": "0.11.1",
-    "gulp": "3.9.1",
-    "gulp-eslint": "3.0.1",
-    "gulp-inject": "4.2.0",
-    "gulp-rimraf": "0.2.1",
-    "gulp-sequence": "0.4.6",
-    "gulp-util": "3.0.8",
-    "html-loader": "0.4.5",
-    "html-webpack-plugin": "2.28.0",
-    "jasmine-core": "2.5.2",
-    "json-loader": "0.5.4",
-    "karma": "1.6.0",
+    "jasmine-core": "2.6.2",
+    "karma": "1.7.0",
     "karma-babel-preprocessor": "6.0.1",
     "karma-jasmine": "1.1.0",
     "karma-mocha": "1.3.0",
@@ -104,25 +107,8 @@
     "karma-phantomjs-launcher": "1.0.4",
     "karma-teamcity-reporter": "1.0.0",
     "karma-webpack": "2.0.3",
-    "mocha": "3.2.0",
+    "mocha": "3.4.2",
     "mocha-teamcity-reporter": "1.1.1",
-    "ngtemplate-loader": "1.3.1",
-    "node-sass": "4.5.2",
-    "phantomjs-prebuilt": "2.1.14",
-    "postcss-loader": "1.3.3",
-    "progress-bar-webpack-plugin": "1.9.3",
-    "pug-html-loader": "1.1.0",
-    "pug-loader": "2.3.0",
-    "require-dir": "0.3.1",
-    "resolve-url-loader": "2.0.2",
-    "sass-loader": "6.0.3",
-    "style-loader": "0.16.1",
-    "svg-sprite-loader": "2.1.0",
-    "url": "0.11.0",
-    "url-loader": "0.5.8",
-    "webpack": "2.3.3",
-    "webpack-dev-server": "2.4.2",
-    "webpack-stream": "3.2.0",
-    "worker-loader": "0.8.0"
+    "phantomjs-prebuilt": "2.1.14"
   }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/test/karma.conf.babel.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/test/karma.conf.babel.js b/modules/web-console/frontend/test/karma.conf.babel.js
index aa6b11c..1651c30 100644
--- a/modules/web-console/frontend/test/karma.conf.babel.js
+++ b/modules/web-console/frontend/test/karma.conf.babel.js
@@ -15,21 +15,14 @@
  * limitations under the License.
  */
 
-import webpack from '../gulpfile.babel.js/webpack';
 import path from 'path';
 
-const basePath = path.resolve('./');
-
-// Webpack chunk plugin has to be removed during test runs due to incompatibility issues,
-// otherwise tests would not run at all.
-// https://github.com/webpack-contrib/karma-webpack/issues/24#issuecomment-257613167
-const chunkPluginIndex = webpack.plugins.findIndex((plugin) => plugin.chunkNames);
-webpack.plugins.splice(chunkPluginIndex, 1);
+import testCfg from '../webpack/webpack.test';
 
 export default (config) => {
     config.set({
         // Base path that will be used to resolve all patterns (eg. files, exclude).
-        basePath,
+        basePath: path.resolve('./'),
 
         // Frameworks to use available frameworks: https://npmjs.org/browse/keyword/karma-adapter
         frameworks: ['mocha'],
@@ -53,7 +46,7 @@ export default (config) => {
             'test/**/*.js': ['webpack']
         },
 
-        webpack,
+        webpack: testCfg,
 
         webpackMiddleware: {
             noInfo: true

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/test/karma.conf.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/test/karma.conf.js b/modules/web-console/frontend/test/karma.conf.js
index a8b1b11..e354482 100644
--- a/modules/web-console/frontend/test/karma.conf.js
+++ b/modules/web-console/frontend/test/karma.conf.js
@@ -16,4 +16,4 @@
  */
 
 require('babel-core/register');
-module.exports = require('./karma.conf.babel.js').default;
+module.exports = require('./karma.conf.babel.js');

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/webpack/webpack.common.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/webpack/webpack.common.js b/modules/web-console/frontend/webpack/webpack.common.js
new file mode 100644
index 0000000..ca7f672
--- /dev/null
+++ b/modules/web-console/frontend/webpack/webpack.common.js
@@ -0,0 +1,188 @@
+/*
+ * 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.
+ */
+
+import path from 'path';
+import webpack from 'webpack';
+
+import transformRuntime from 'babel-plugin-transform-runtime';
+import presetEs2015 from 'babel-preset-es2015';
+import presetStage1 from 'babel-preset-stage-1';
+
+import CopyWebpackPlugin from 'copy-webpack-plugin';
+import ExtractTextPlugin from 'extract-text-webpack-plugin';
+import HtmlWebpackPlugin from 'html-webpack-plugin';
+import ProgressBarPlugin from 'progress-bar-webpack-plugin';
+
+const basedir = path.resolve('./');
+const contentBase = path.resolve('public');
+const node_modules = path.resolve('node_modules');
+
+const app = path.resolve('app');
+const IgniteModules = process.env.IGNITE_MODULES ? path.join(process.env.IGNITE_MODULES, 'frontend') : path.resolve('ignite_modules');
+
+export default {
+    cache: true,
+    node: {
+        fs: 'empty'
+    },
+    // Entry points.
+    entry: {
+        polyfill: 'babel-polyfill',
+        vendor: path.join(app, 'vendor.js'),
+        app: path.join(app, 'app.js')
+    },
+
+    // Output system.
+    output: {
+        path: path.resolve('build'),
+        filename: '[name].[chunkhash].js',
+        publicPath: '/',
+        sourceMapFilename: '[name].[chunkhash].map'
+    },
+
+    // Resolves modules.
+    resolve: {
+        modules: [node_modules],
+        // A list of module source folders.
+        alias: {
+            app,
+            images: path.resolve('public/images'),
+            views: path.resolve('views'),
+            IgniteModules
+        }
+    },
+
+    // Resolve loader use postfix.
+    resolveLoader: {
+        modules: [
+            node_modules
+        ],
+        moduleExtensions: ['-loader']
+    },
+
+    module: {
+        rules: [
+            {
+                test: /\.json$/,
+                loader: 'json'
+            },
+            // Exclude tpl.pug files to import in bundle.
+            {
+                test: /^(?:(?!tpl\.pug$).)*\.pug$/, // TODO: check this regexp for correct.
+                loader: `pug-html?basedir=${basedir}`
+            },
+
+            // Render .tpl.pug files to assets folder.
+            {
+                test: /\.tpl\.pug$/,
+                use: [
+                    'file?exports=false&name=assets/templates/[name].[hash].html',
+                    `pug-html?exports=false&basedir=${basedir}`
+                ]
+            },
+            {
+                test: /\.js$/,
+                enforce: 'pre',
+                exclude: [node_modules],
+                use: [{
+                    loader: 'eslint',
+                    options: {
+                        failOnWarning: false,
+                        failOnError: false,
+                        formatter: 'eslint-friendly-formatter'
+                    }
+                }]
+            },
+            {
+                test: /\.js$/,
+                exclude: [node_modules],
+                use: [{
+                    loader: 'babel-loader',
+                    options: {
+                        cacheDirectory: true,
+                        plugins: [
+                            transformRuntime
+                        ],
+                        presets: [
+                            presetEs2015,
+                            presetStage1
+                        ]
+                    }
+                }]
+            },
+            {
+                test: /\.(ttf|eot|svg|woff(2)?)(\?v=[\d.]+)?(\?[a-z0-9#-]+)?$/,
+                exclude: [contentBase],
+                loader: 'file?name=assets/fonts/[name].[ext]'
+            },
+            {
+                test: /.*\.svg$/,
+                include: [contentBase],
+                use: ['svg-sprite-loader']
+            },
+            {
+                test: /\.(jpe?g|png|gif)$/i,
+                loader: 'file?name=assets/images/[name]_[hash].[ext]'
+            },
+            {
+                test: require.resolve('jquery'),
+                use: [
+                    'expose-loader?$',
+                    'expose-loader?jQuery'
+                ]
+            },
+            {
+                test: require.resolve('nvd3'),
+                use: ['expose-loader?nv']
+            }
+        ]
+    },
+
+    // Load plugins.
+    plugins: [
+        new webpack.LoaderOptionsPlugin({
+            options: {
+                pug: {
+                    basedir
+                },
+                target: 'web'
+            }
+        }),
+        new webpack.ProvidePlugin({
+            $: 'jquery',
+            jQuery: 'jquery',
+            _: 'lodash',
+            nv: 'nvd3',
+            io: 'socket.io-client'
+        }),
+        new webpack.optimize.AggressiveMergingPlugin({moveToParents: true}),
+        new HtmlWebpackPlugin({
+            template: './views/index.pug'
+        }),
+        new ExtractTextPlugin({filename: 'assets/css/[name].css', allChunks: true}),
+        new CopyWebpackPlugin([
+            { context: 'public', from: '**/*.png' },
+            { context: 'public', from: '**/*.svg' },
+            { context: 'public', from: '**/*.ico' },
+            // Ignite modules.
+            { context: IgniteModules, from: '**/*.png', force: true },
+            { context: IgniteModules, from: '**/*.svg', force: true },
+            { context: IgniteModules, from: '**/*.ico', force: true }
+        ]),
+        new ProgressBarPlugin()
+    ]
+};

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/webpack/webpack.dev.babel.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/webpack/webpack.dev.babel.js b/modules/web-console/frontend/webpack/webpack.dev.babel.js
new file mode 100644
index 0000000..dc5cd41
--- /dev/null
+++ b/modules/web-console/frontend/webpack/webpack.dev.babel.js
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+
+import webpack from 'webpack';
+import merge from 'webpack-merge';
+
+import path from 'path';
+
+import commonCfg from './webpack.common';
+
+import ExtractTextPlugin from 'extract-text-webpack-plugin';
+
+const backendPort = process.env.BACKEND_PORT || 3000;
+const devServerPort = process.env.PORT || 9000;
+const devServerHost = process.env.HOST || '0.0.0.0';
+
+export default merge(commonCfg, {
+    devtool: 'source-map',
+    watch: true,
+    module: {
+        rules: [
+            {
+                test: /\.css$/,
+                use: ['style', 'css']
+            },
+            {
+                test: /\.scss$/,
+                // Version without extract plugin fails on some machines. https://github.com/sass/node-sass/issues/1895
+                use: ExtractTextPlugin.extract({
+                    fallback: 'style-loader',
+                    use: [
+                        {
+                            loader: 'css',
+                            options: {
+                                sourceMap: true
+                            }
+                        },
+                        {
+                            loader: 'sass',
+                            options: {
+                                sourceMap: true
+                            }
+                        }
+                    ]
+                })
+            }
+        ]
+    },
+    devServer: {
+        compress: true,
+        historyApiFallback: true,
+        disableHostCheck: true,
+        contentBase: path.resolve('build'),
+        // hot: true,
+        inline: true,
+        proxy: {
+            '/socket.io': {
+                target: `http://localhost:${backendPort}`,
+                ws: true
+            },
+            '/agents': {
+                target: `http://localhost:${backendPort}`,
+                ws: true
+            },
+            '/api/v1/*': {
+                target: `http://localhost:${backendPort}`,
+                pathRewrite: {
+                    '^/api/v1': ''
+                }
+            }
+        },
+        watchOptions: {
+            aggregateTimeout: 1000,
+            poll: 2000
+        },
+        stats: {
+            colors: true,
+            chunks: false
+        },
+        host: devServerHost,
+        port: devServerPort
+    },
+    plugins: [
+        new webpack.optimize.CommonsChunkPlugin({name: 'vendor'})
+    ]
+});

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/webpack/webpack.prod.babel.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/webpack/webpack.prod.babel.js b/modules/web-console/frontend/webpack/webpack.prod.babel.js
new file mode 100644
index 0000000..f18a3ba
--- /dev/null
+++ b/modules/web-console/frontend/webpack/webpack.prod.babel.js
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+import webpack from 'webpack';
+import merge from 'webpack-merge';
+
+import ExtractTextPlugin from 'extract-text-webpack-plugin';
+
+import commonCfg from './webpack.common';
+
+export default merge(commonCfg, {
+    bail: true, // Cancel build on error.
+    devtool: 'cheap-source-map',
+    module: {
+        rules: [
+            {
+                test: /\.css$/,
+                use: ExtractTextPlugin.extract({
+                    fallback: 'style',
+                    use: ['css']
+                })
+            },
+            {
+                test: /\.scss$/,
+                use: ExtractTextPlugin.extract({
+                    fallback: 'style-loader',
+                    use: ['css', 'sass']
+                })
+            }
+        ]
+    },
+    plugins: [
+        new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}),
+        new webpack.LoaderOptionsPlugin({
+            minimize: true,
+            debug: false
+        }),
+        new webpack.optimize.UglifyJsPlugin({
+            beautify: false,
+            mangle: {
+                screw_ie8: true,
+                keep_fnames: true
+            },
+            compress: {
+                screw_ie8: true
+            },
+            comments: false
+        })
+    ]
+});

http://git-wip-us.apache.org/repos/asf/ignite/blob/88fd1a63/modules/web-console/frontend/webpack/webpack.test.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/webpack/webpack.test.js b/modules/web-console/frontend/webpack/webpack.test.js
new file mode 100644
index 0000000..36d2650
--- /dev/null
+++ b/modules/web-console/frontend/webpack/webpack.test.js
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+import merge from 'webpack-merge';
+
+import commonCfg from './webpack.common';
+
+export default merge(commonCfg, {
+    cache: true,
+    node: {
+        fs: 'empty'
+    },
+
+    // Entry points.
+    entry: null,
+
+    // Output system.
+    output: null
+});


[07/22] ignite git commit: IGNITE-5311: Added ability to get CacheObject value without CacheObjectContext. This closes #2019.

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
index a31263f..8d9d953 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
@@ -37,7 +37,6 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 import javax.cache.CacheException;
@@ -100,7 +99,6 @@ import org.jsr166.ConcurrentHashMap8;
 
 import static java.util.Collections.singletonList;
 import static org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion.NONE;
-import static org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SQL_FIELDS;
 import static org.apache.ignite.internal.processors.cache.query.GridCacheSqlQuery.EMPTY_PARAMS;
 import static org.apache.ignite.internal.processors.query.h2.opt.DistributedJoinMode.OFF;
 import static org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryType.REDUCE;
@@ -132,7 +130,7 @@ public class GridReduceQueryExecutor {
     private final AtomicLong qryIdGen;
 
     /** */
-    private final ConcurrentMap<Long, QueryRun> runs = new ConcurrentHashMap8<>();
+    private final ConcurrentMap<Long, ReduceQueryRun> runs = new ConcurrentHashMap8<>();
 
     /** */
     private volatile List<GridThreadLocalTable> fakeTbls = Collections.emptyList();
@@ -191,8 +189,8 @@ public class GridReduceQueryExecutor {
             @Override public void onEvent(final Event evt) {
                 UUID nodeId = ((DiscoveryEvent)evt).eventNode().id();
 
-                for (QueryRun r : runs.values()) {
-                    for (GridMergeIndex idx : r.idxs) {
+                for (ReduceQueryRun r : runs.values()) {
+                    for (GridMergeIndex idx : r.indexes()) {
                         if (idx.hasSource(nodeId)) {
                             handleNodeLeft(r, nodeId);
 
@@ -208,7 +206,7 @@ public class GridReduceQueryExecutor {
      * @param r Query run.
      * @param nodeId Left node ID.
      */
-    private void handleNodeLeft(QueryRun r, UUID nodeId) {
+    private void handleNodeLeft(ReduceQueryRun r, UUID nodeId) {
         // Will attempt to retry. If reduce query was started it will fail on next page fetching.
         retry(r, h2.readyTopologyVersion(), nodeId);
     }
@@ -248,7 +246,7 @@ public class GridReduceQueryExecutor {
      * @param msg Message.
      */
     private void onFail(ClusterNode node, GridQueryFailResponse msg) {
-        QueryRun r = runs.get(msg.queryRequestId());
+        ReduceQueryRun r = runs.get(msg.queryRequestId());
 
         fail(r, node.id(), msg.error(), msg.failCode());
     }
@@ -258,7 +256,7 @@ public class GridReduceQueryExecutor {
      * @param nodeId Failed node ID.
      * @param msg Error message.
      */
-    private void fail(QueryRun r, UUID nodeId, String msg, byte failCode) {
+    private void fail(ReduceQueryRun r, UUID nodeId, String msg, byte failCode) {
         if (r != null) {
             CacheException e = new CacheException("Failed to execute map query on the node: " + nodeId + ", " + msg);
 
@@ -278,21 +276,21 @@ public class GridReduceQueryExecutor {
         final int qry = msg.query();
         final int seg = msg.segmentId();
 
-        final QueryRun r = runs.get(qryReqId);
+        final ReduceQueryRun r = runs.get(qryReqId);
 
         if (r == null) // Already finished with error or canceled.
             return;
 
-        final int pageSize = r.pageSize;
+        final int pageSize = r.pageSize();
 
-        GridMergeIndex idx = r.idxs.get(msg.query());
+        GridMergeIndex idx = r.indexes().get(msg.query());
 
         GridResultPage page;
 
         try {
             page = new GridResultPage(ctx, node.id(), msg) {
                 @Override public void fetchNextPage() {
-                    Object errState = r.state.get();
+                    Object errState = r.state();
 
                     if (errState != null) {
                         CacheException err0 = errState instanceof CacheException ? (CacheException)errState : null;
@@ -335,7 +333,7 @@ public class GridReduceQueryExecutor {
         if (msg.retry() != null)
             retry(r, msg.retry(), node.id());
         else if (msg.page() == 0) // Do count down on each first page received.
-            r.latch.countDown();
+            r.latch().countDown();
     }
 
     /**
@@ -343,7 +341,7 @@ public class GridReduceQueryExecutor {
      * @param retryVer Retry version.
      * @param nodeId Node ID.
      */
-    private void retry(QueryRun r, AffinityTopologyVersion retryVer, UUID nodeId) {
+    private void retry(ReduceQueryRun r, AffinityTopologyVersion retryVer, UUID nodeId) {
         r.state(retryVer, nodeId);
     }
 
@@ -501,7 +499,7 @@ public class GridReduceQueryExecutor {
     }
 
     /**
-     * @param cctx Cache context.
+     * @param schemaName Schema name.
      * @param qry Query.
      * @param keepPortable Keep portable.
      * @param enforceJoinOrder Enforce join order of tables.
@@ -512,7 +510,7 @@ public class GridReduceQueryExecutor {
      * @return Rows iterator.
      */
     public Iterator<List<?>> query(
-        GridCacheContext<?, ?> cctx,
+        String schemaName,
         GridCacheTwoStepQuery qry,
         boolean keepPortable,
         boolean enforceJoinOrder,
@@ -541,10 +539,8 @@ public class GridReduceQueryExecutor {
 
             final long qryReqId = qryIdGen.incrementAndGet();
 
-            final String cacheName = cctx.name();
-
-            final QueryRun r = new QueryRun(qryReqId, qry.originalSql(), cacheName,
-                h2.connectionForCache(cacheName), qry.mapQueries().size(), qry.pageSize(),
+            final ReduceQueryRun r = new ReduceQueryRun(qryReqId, qry.originalSql(), schemaName,
+                h2.connectionForSchema(schemaName), qry.mapQueries().size(), qry.pageSize(),
                 U.currentTimeMillis(), cancel);
 
             AffinityTopologyVersion topVer = h2.readyTopologyVersion();
@@ -633,7 +629,7 @@ public class GridReduceQueryExecutor {
                     GridMergeTable tbl;
 
                     try {
-                        tbl = createMergeTable(r.conn, mapQry, qry.explain());
+                        tbl = createMergeTable(r.connection(), mapQry, qry.explain());
                     }
                     catch (IgniteCheckedException e) {
                         throw new IgniteException(e);
@@ -641,7 +637,7 @@ public class GridReduceQueryExecutor {
 
                     idx = tbl.getMergeIndex();
 
-                    fakeTable(r.conn, tblIdx++).innerTable(tbl);
+                    fakeTable(r.connection(), tblIdx++).innerTable(tbl);
                 }
                 else
                     idx = GridMergeIndexUnsorted.createDummy(ctx);
@@ -659,13 +655,13 @@ public class GridReduceQueryExecutor {
                 else
                     idx.setSources(nodes, segmentsPerIndex);
 
-                idx.setPageSize(r.pageSize);
+                idx.setPageSize(r.pageSize());
 
-                r.idxs.add(idx);
+                r.indexes().add(idx);
             }
 
-            r.latch = new CountDownLatch(isReplicatedOnly ? 1 :
-                (r.idxs.size() - replicatedQrysCnt) * nodes.size() * segmentsPerIndex + replicatedQrysCnt);
+            r.latch(new CountDownLatch(isReplicatedOnly ? 1 :
+                (r.indexes().size() - replicatedQrysCnt) * nodes.size() * segmentsPerIndex + replicatedQrysCnt));
 
             runs.put(qryReqId, r);
 
@@ -719,7 +715,7 @@ public class GridReduceQueryExecutor {
                         new GridH2QueryRequest()
                                 .requestId(qryReqId)
                                 .topologyVersion(topVer)
-                                .pageSize(r.pageSize)
+                                .pageSize(r.pageSize())
                                 .caches(qry.cacheIds())
                                 .tables(distributedJoins ? qry.tables() : null)
                                 .partitions(convert(partsMap))
@@ -731,7 +727,7 @@ public class GridReduceQueryExecutor {
                         false)) {
                     awaitAllReplies(r, nodes, cancel);
 
-                    Object state = r.state.get();
+                    Object state = r.state();
 
                     if (state != null) {
                         if (state instanceof CacheException) {
@@ -764,7 +760,7 @@ public class GridReduceQueryExecutor {
                         List<List<?>> res = new ArrayList<>();
 
                         // Simple UNION ALL can have multiple indexes.
-                        for (GridMergeIndex idx : r.idxs) {
+                        for (GridMergeIndex idx : r.indexes()) {
                             Cursor cur = idx.findInStream(null, null);
 
                             while (cur.next()) {
@@ -788,21 +784,19 @@ public class GridReduceQueryExecutor {
 
                         UUID locNodeId = ctx.localNodeId();
 
-                        H2Utils.setupConnection(r.conn, false, enforceJoinOrder);
+                        H2Utils.setupConnection(r.connection(), false, enforceJoinOrder);
 
                         GridH2QueryContext.set(new GridH2QueryContext(locNodeId, locNodeId, qryReqId, REDUCE)
-                            .pageSize(r.pageSize).distributedJoinMode(OFF));
+                            .pageSize(r.pageSize()).distributedJoinMode(OFF));
 
                         try {
-                            String schema = h2.schema(cacheName);
-
                             if (qry.explain())
-                                return explainPlan(r.conn, schema, qry, params);
+                                return explainPlan(r.connection(), schemaName, qry, params);
 
                             GridCacheSqlQuery rdc = qry.reduceQuery();
 
-                            ResultSet res = h2.executeSqlQueryWithTimer(schema,
-                                r.conn,
+                            ResultSet res = h2.executeSqlQueryWithTimer(schemaName,
+                                r.connection(),
                                 rdc.query(),
                                 F.asList(rdc.parameters(params)),
                                 false, // The statement will cache some extra thread local objects.
@@ -824,10 +818,10 @@ public class GridReduceQueryExecutor {
                     continue;
                 }
 
-                return new GridQueryCacheObjectsIterator(resIter, cctx, keepPortable);
+                return new GridQueryCacheObjectsIterator(resIter, h2.valueContext(), keepPortable);
             }
             catch (IgniteCheckedException | RuntimeException e) {
-                U.closeQuiet(r.conn);
+                U.closeQuiet(r.connection());
 
                 if (e instanceof CacheException) {
                     if (wasCancelled((CacheException)e))
@@ -898,7 +892,7 @@ public class GridReduceQueryExecutor {
      * @param distributedJoins Distributed join flag.
      */
     private void cancelRemoteQueriesIfNeeded(Collection<ClusterNode> nodes,
-        QueryRun r,
+        ReduceQueryRun r,
         long qryReqId,
         boolean distributedJoins)
     {
@@ -906,7 +900,7 @@ public class GridReduceQueryExecutor {
         if (distributedJoins)
             send(nodes, new GridQueryCancelRequest(qryReqId), null, false);
         else {
-            for (GridMergeIndex idx : r.idxs) {
+            for (GridMergeIndex idx : r.indexes()) {
                 if (!idx.fetchedAll()) {
                     send(nodes, new GridQueryCancelRequest(qryReqId), null, false);
 
@@ -922,9 +916,9 @@ public class GridReduceQueryExecutor {
      * @param cancel Query cancel.
      * @throws IgniteInterruptedCheckedException If interrupted.
      */
-    private void awaitAllReplies(QueryRun r, Collection<ClusterNode> nodes, GridQueryCancel cancel)
+    private void awaitAllReplies(ReduceQueryRun r, Collection<ClusterNode> nodes, GridQueryCancel cancel)
         throws IgniteInterruptedCheckedException, QueryCancelledException {
-        while (!U.await(r.latch, 500, TimeUnit.MILLISECONDS)) {
+        while (!U.await(r.latch(), 500, TimeUnit.MILLISECONDS)) {
 
             cancel.checkCancelled();
 
@@ -932,7 +926,7 @@ public class GridReduceQueryExecutor {
                 if (!ctx.discovery().alive(node)) {
                     handleNodeLeft(r, node.id());
 
-                    assert r.latch.getCount() == 0;
+                    assert r.latch().getCount() == 0;
 
                     return;
                 }
@@ -1420,7 +1414,7 @@ public class GridReduceQueryExecutor {
         CacheException err = new CacheException("Query was cancelled, client node disconnected.",
             new IgniteClientDisconnectedException(reconnectFut, "Client node disconnected."));
 
-        for (Map.Entry<Long, QueryRun> e : runs.entrySet())
+        for (Map.Entry<Long, ReduceQueryRun> e : runs.entrySet())
             e.getValue().disconnected(err);
     }
 
@@ -1435,9 +1429,9 @@ public class GridReduceQueryExecutor {
 
         long curTime = U.currentTimeMillis();
 
-        for (QueryRun run : runs.values()) {
-            if (run.qry.longQuery(curTime, duration))
-                res.add(run.qry);
+        for (ReduceQueryRun run : runs.values()) {
+            if (run.queryInfo().longQuery(curTime, duration))
+                res.add(run.queryInfo());
         }
 
         return res;
@@ -1450,77 +1444,10 @@ public class GridReduceQueryExecutor {
      */
     public void cancelQueries(Collection<Long> queries) {
         for (Long qryId : queries) {
-            QueryRun run = runs.get(qryId);
+            ReduceQueryRun run = runs.get(qryId);
 
             if (run != null)
-                run.qry.cancel();
-        }
-    }
-
-    /**
-     * Query run.
-     */
-    private static class QueryRun {
-        /** */
-        private final GridRunningQueryInfo qry;
-
-        /** */
-        private final List<GridMergeIndex> idxs;
-
-        /** */
-        private CountDownLatch latch;
-
-        /** */
-        private final JdbcConnection conn;
-
-        /** */
-        private final int pageSize;
-
-        /** Can be either CacheException in case of error or AffinityTopologyVersion to retry if needed. */
-        private final AtomicReference<Object> state = new AtomicReference<>();
-
-        /**
-         * @param id Query ID.
-         * @param qry Query text.
-         * @param cache Cache where query was executed.
-         * @param conn Connection.
-         * @param idxsCnt Number of indexes.
-         * @param pageSize Page size.
-         * @param startTime Start time.
-         * @param cancel Query cancel handler.
-         */
-        private QueryRun(Long id, String qry, String cache, Connection conn, int idxsCnt, int pageSize, long startTime, GridQueryCancel cancel) {
-            this.qry = new GridRunningQueryInfo(id, qry, SQL_FIELDS, cache, startTime, cancel, false);
-            this.conn = (JdbcConnection)conn;
-            this.idxs = new ArrayList<>(idxsCnt);
-            this.pageSize = pageSize > 0 ? pageSize : GridCacheTwoStepQuery.DFLT_PAGE_SIZE;
-        }
-
-        /**
-         * @param o Fail state object.
-         * @param nodeId Node ID.
-         */
-        void state(Object o, @Nullable UUID nodeId) {
-            assert o != null;
-            assert o instanceof CacheException || o instanceof AffinityTopologyVersion : o.getClass();
-
-            if (!state.compareAndSet(null, o))
-                return;
-
-            while (latch.getCount() != 0) // We don't need to wait for all nodes to reply.
-                latch.countDown();
-
-            CacheException e = o instanceof CacheException ? (CacheException) o : null;
-
-            for (GridMergeIndex idx : idxs) // Fail all merge indexes.
-                idx.fail(nodeId, e);
-        }
-
-        /**
-         * @param e Error.
-         */
-        void disconnected(CacheException e) {
-            state(e, null);
+                run.queryInfo().cancel();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/ReduceQueryRun.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/ReduceQueryRun.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/ReduceQueryRun.java
new file mode 100644
index 0000000..73bb002
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/ReduceQueryRun.java
@@ -0,0 +1,157 @@
+/*
+ * 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.query.h2.twostep;
+
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery;
+import org.apache.ignite.internal.processors.query.GridQueryCancel;
+import org.apache.ignite.internal.processors.query.GridRunningQueryInfo;
+import org.h2.jdbc.JdbcConnection;
+import org.jetbrains.annotations.Nullable;
+
+import javax.cache.CacheException;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SQL_FIELDS;
+
+/**
+ * Query run.
+ */
+class ReduceQueryRun {
+    /** */
+    private final GridRunningQueryInfo qry;
+
+    /** */
+    private final List<GridMergeIndex> idxs;
+
+    /** */
+    private CountDownLatch latch;
+
+    /** */
+    private final JdbcConnection conn;
+
+    /** */
+    private final int pageSize;
+
+    /** Can be either CacheException in case of error or AffinityTopologyVersion to retry if needed. */
+    private final AtomicReference<Object> state = new AtomicReference<>();
+
+    /**
+     * Constructor.
+     *
+     * @param id Query ID.
+     * @param qry Query text.
+     * @param schemaName Schema name.
+     * @param conn Connection.
+     * @param idxsCnt Number of indexes.
+     * @param pageSize Page size.
+     * @param startTime Start time.
+     * @param cancel Query cancel handler.
+     */
+    ReduceQueryRun(Long id, String qry, String schemaName, Connection conn, int idxsCnt, int pageSize, long startTime,
+        GridQueryCancel cancel) {
+        this.qry = new GridRunningQueryInfo(id, qry, SQL_FIELDS, schemaName, startTime, cancel, false);
+
+        this.conn = (JdbcConnection)conn;
+
+        this.idxs = new ArrayList<>(idxsCnt);
+
+        this.pageSize = pageSize > 0 ? pageSize : GridCacheTwoStepQuery.DFLT_PAGE_SIZE;
+    }
+
+    /**
+     * @param o Fail state object.
+     * @param nodeId Node ID.
+     */
+    void state(Object o, @Nullable UUID nodeId) {
+        assert o != null;
+        assert o instanceof CacheException || o instanceof AffinityTopologyVersion : o.getClass();
+
+        if (!state.compareAndSet(null, o))
+            return;
+
+        while (latch.getCount() != 0) // We don't need to wait for all nodes to reply.
+            latch.countDown();
+
+        CacheException e = o instanceof CacheException ? (CacheException) o : null;
+
+        for (GridMergeIndex idx : idxs) // Fail all merge indexes.
+            idx.fail(nodeId, e);
+    }
+
+    /**
+     * @param e Error.
+     */
+    void disconnected(CacheException e) {
+        state(e, null);
+    }
+
+    /**
+     * @return Query info.
+     */
+    GridRunningQueryInfo queryInfo() {
+        return qry;
+    }
+
+    /**
+     * @return Page size.
+     */
+    int pageSize() {
+        return pageSize;
+    }
+
+    /**
+     * @return Connection.
+     */
+    JdbcConnection connection() {
+        return conn;
+    }
+
+    /**
+     * @return State.
+     */
+    Object state() {
+        return state.get();
+    }
+
+    /**
+     * @return Indexes.
+     */
+    List<GridMergeIndex> indexes() {
+        return idxs;
+    }
+
+    /**
+     * @return Latch.
+     */
+    CountDownLatch latch() {
+        return latch;
+    }
+
+    /**
+     * @param latch Latch.
+     */
+    void latch(CountDownLatch latch) {
+        this.latch = latch;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
index 5ac02a5..1f73dcb 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
@@ -41,6 +41,7 @@ import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.query.GridQueryFieldsResult;
 import org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor;
@@ -726,7 +727,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+        @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
             return (T)val;
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
index 5939b59..b66a343 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
@@ -870,7 +870,9 @@ public class GridQueryParsingTest extends GridCommonAbstractTest {
 
         IgniteH2Indexing idx = U.field(qryProcessor, "idx");
 
-        return (JdbcConnection)idx.connectionForCache(DEFAULT_CACHE_NAME);
+        String schemaName = idx.schema(DEFAULT_CACHE_NAME);
+
+        return (JdbcConnection)idx.connectionForSchema(schemaName);
     }
 
     /**


[05/22] ignite git commit: Fixed CacheClientBinaryQueryExample.

Posted by sb...@apache.org.
Fixed CacheClientBinaryQueryExample.


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

Branch: refs/heads/ignite-5075
Commit: e59d3890ce4d50b6627e731c13dad36ae05959b4
Parents: b673bdb
Author: devozerov <vo...@gridgain.com>
Authored: Sat May 27 21:05:26 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Sat May 27 21:05:26 2017 +0300

----------------------------------------------------------------------
 .../examples/binary/datagrid/CacheClientBinaryQueryExample.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e59d3890/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
index 11c00e9..c2d4964 100644
--- a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
@@ -149,9 +149,9 @@ public class CacheClientBinaryQueryExample {
         employeeEntity.setIndexes(Arrays.asList(
             new QueryIndex("name"),
             new QueryIndex("salary"),
-            new QueryIndex("zip"),
+            new QueryIndex("addr.zip"),
             new QueryIndex("organizationId"),
-            new QueryIndex("street", QueryIndexType.FULLTEXT)
+            new QueryIndex("addr.street", QueryIndexType.FULLTEXT)
         ));
 
         return employeeEntity;


[16/22] ignite git commit: Get rid of portable flag in Ignite

Posted by sb...@apache.org.
Get rid of portable flag in Ignite


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

Branch: refs/heads/ignite-5075
Commit: 827b7f61faf65406040f2f66349044cf91638b8c
Parents: f5bbc71
Author: Konstantin Dudkov <kd...@ya.ru>
Authored: Mon May 29 16:00:35 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Mon May 29 16:01:25 2017 +0300

----------------------------------------------------------------------
 .../cache/query/GridCacheQueryRequest.java      | 14 ++--
 .../BinaryAtomicCacheLocalEntriesSelfTest.java  | 30 +++++++
 .../BinaryTxCacheLocalEntriesSelfTest.java      | 84 ++++++++++++++++++++
 .../BinaryAtomicCacheLocalEntriesSelfTest.java  | 30 -------
 .../BinaryTxCacheLocalEntriesSelfTest.java      | 84 --------------------
 .../IgniteBinaryObjectsTestSuite.java           |  4 +-
 .../h2/twostep/GridReduceQueryExecutor.java     | 10 +--
 7 files changed, 128 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/827b7f61/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java
index bc32c60..00ddff8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java
@@ -114,7 +114,7 @@ public class GridCacheQueryRequest extends GridCacheMessage implements GridCache
     private boolean all;
 
     /** */
-    private boolean keepPortable;
+    private boolean keepBinary;
 
     /** */
     private UUID subjId;
@@ -195,7 +195,7 @@ public class GridCacheQueryRequest extends GridCacheMessage implements GridCache
         this.incBackups = incBackups;
         this.fields = fields;
         this.all = all;
-        this.keepPortable = keepBinary;
+        this.keepBinary = keepBinary;
         this.subjId = subjId;
         this.taskHash = taskHash;
         this.topVer = topVer;
@@ -265,7 +265,7 @@ public class GridCacheQueryRequest extends GridCacheMessage implements GridCache
         this.incBackups = incBackups;
         this.args = args;
         this.incMeta = incMeta;
-        this.keepPortable = keepBinary;
+        this.keepBinary = keepBinary;
         this.subjId = subjId;
         this.taskHash = taskHash;
         this.topVer = topVer;
@@ -460,7 +460,7 @@ public class GridCacheQueryRequest extends GridCacheMessage implements GridCache
      * @return Whether to keep binary.
      */
     public boolean keepBinary() {
-        return keepPortable;
+        return keepBinary;
     }
 
     /**
@@ -480,7 +480,7 @@ public class GridCacheQueryRequest extends GridCacheMessage implements GridCache
     /**
      * @return partition.
      */
-    public int partition() {
+    @Override public int partition() {
         return part;
     }
 
@@ -560,7 +560,7 @@ public class GridCacheQueryRequest extends GridCacheMessage implements GridCache
                 writer.incrementState();
 
             case 13:
-                if (!writer.writeBoolean("keepPortable", keepPortable))
+                if (!writer.writeBoolean("keepBinary", keepBinary))
                     return false;
 
                 writer.incrementState();
@@ -716,7 +716,7 @@ public class GridCacheQueryRequest extends GridCacheMessage implements GridCache
                 reader.incrementState();
 
             case 13:
-                keepPortable = reader.readBoolean("keepPortable");
+                keepBinary = reader.readBoolean("keepBinary");
 
                 if (!reader.isLastRead())
                     return false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/827b7f61/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/BinaryAtomicCacheLocalEntriesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/BinaryAtomicCacheLocalEntriesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/BinaryAtomicCacheLocalEntriesSelfTest.java
new file mode 100644
index 0000000..d68b236
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/BinaryAtomicCacheLocalEntriesSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+
+/**
+ *
+ */
+public class BinaryAtomicCacheLocalEntriesSelfTest extends BinaryTxCacheLocalEntriesSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/827b7f61/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/BinaryTxCacheLocalEntriesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/BinaryTxCacheLocalEntriesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/BinaryTxCacheLocalEntriesSelfTest.java
new file mode 100644
index 0000000..3528161
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/BinaryTxCacheLocalEntriesSelfTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
+
+/**
+ *
+ */
+public class BinaryTxCacheLocalEntriesSelfTest extends GridCacheAbstractSelfTest {
+    /** */
+    private static final String FIELD = "user-name";
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 2;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
+        CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);
+
+        ccfg.setStoreKeepBinary(true);
+
+        return ccfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLocalEntries() throws Exception {
+        IgniteCache<Integer, BinaryObject> cache = grid(0).cache(DEFAULT_CACHE_NAME).withKeepBinary();
+
+        final int ENTRY_CNT = 10;
+
+        for (int i = 0; i < ENTRY_CNT; i++)
+            cache.put(i, userObject("user-" + i));
+
+        assertEquals(ENTRY_CNT, cache.localSize(CachePeekMode.ALL));
+
+        for (int i = 0; i < gridCount(); i++)
+            jcache(i).withKeepBinary().localEntries();
+
+        cache.removeAll();
+    }
+
+    /**
+     * @param userName User name.
+     * @return Binary object.
+     */
+    private BinaryObject userObject(String userName) {
+        return grid(0).binary().builder("orders").setField(FIELD, userName).build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/827b7f61/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/BinaryAtomicCacheLocalEntriesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/BinaryAtomicCacheLocalEntriesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/BinaryAtomicCacheLocalEntriesSelfTest.java
deleted file mode 100644
index 41a4286..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/BinaryAtomicCacheLocalEntriesSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
-* 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.portable;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-
-/**
- *
- */
-public class BinaryAtomicCacheLocalEntriesSelfTest extends BinaryTxCacheLocalEntriesSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return CacheAtomicityMode.ATOMIC;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/827b7f61/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/BinaryTxCacheLocalEntriesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/BinaryTxCacheLocalEntriesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/BinaryTxCacheLocalEntriesSelfTest.java
deleted file mode 100644
index e89c73d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/BinaryTxCacheLocalEntriesSelfTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
-* 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.portable;
-
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.cache.CachePeekMode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
-
-/**
- *
- */
-public class BinaryTxCacheLocalEntriesSelfTest extends GridCacheAbstractSelfTest {
-    /** */
-    private static final String FIELD = "user-name";
-
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 2;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
-        CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);
-
-        ccfg.setStoreKeepBinary(true);
-
-        return ccfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLocalEntries() throws Exception {
-        IgniteCache<Integer, BinaryObject> cache = grid(0).cache(DEFAULT_CACHE_NAME).withKeepBinary();
-
-        final int ENTRY_CNT = 10;
-
-        for (int i = 0; i < ENTRY_CNT; i++)
-            cache.put(i, userObject("user-" + i));
-
-        assertEquals(ENTRY_CNT, cache.localSize(CachePeekMode.ALL));
-
-        for (int i = 0; i < gridCount(); i++)
-            jcache(i).withKeepBinary().localEntries();
-
-        cache.removeAll();
-    }
-
-    /**
-     * @param userName User name.
-     * @return Binary object.
-     */
-    private BinaryObject userObject(String userName) {
-        return grid(0).binary().builder("orders").setField(FIELD, userName).build();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/827b7f61/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
index c8f0ebe..d9e8594 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
@@ -51,7 +51,9 @@ import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderNonCompac
 import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderNonCompactSimpleNameLowerCaseMappersSelfTest;
 import org.apache.ignite.internal.binary.streams.BinaryHeapStreamByteOrderSelfTest;
 import org.apache.ignite.internal.binary.streams.BinaryOffheapStreamByteOrderSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.BinaryAtomicCacheLocalEntriesSelfTest;
 import org.apache.ignite.internal.processors.cache.binary.BinaryMetadataUpdatesFlowTest;
+import org.apache.ignite.internal.processors.cache.binary.BinaryTxCacheLocalEntriesSelfTest;
 import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectMetadataExchangeMultinodeTest;
 import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectUserClassloaderSelfTest;
 import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryStoreBinariesDefaultMappersSelfTest;
@@ -67,8 +69,6 @@ import org.apache.ignite.internal.processors.cache.binary.distributed.replicated
 import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsAtomicLocalSelfTest;
 import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsLocalSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteBinaryMetadataUpdateChangingTopologySelfTest;
-import org.apache.ignite.internal.processors.cache.portable.BinaryAtomicCacheLocalEntriesSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.BinaryTxCacheLocalEntriesSelfTest;
 
 /**
  * Test for binary objects stored in cache.

http://git-wip-us.apache.org/repos/asf/ignite/blob/827b7f61/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
index 9445534..5c8870e 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
@@ -22,6 +22,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -32,7 +33,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
-import java.util.Arrays;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -404,7 +404,7 @@ public class GridReduceQueryExecutor {
 
             List<ClusterNode> partNodes = assignment.get(partId);
 
-            if (partNodes.size() > 0) {
+            if (!partNodes.isEmpty()) {
                 ClusterNode prim = partNodes.get(0);
 
                 if (!needPartsFilter) {
@@ -501,7 +501,7 @@ public class GridReduceQueryExecutor {
     /**
      * @param schemaName Schema name.
      * @param qry Query.
-     * @param keepPortable Keep portable.
+     * @param keepBinary Keep binary.
      * @param enforceJoinOrder Enforce join order of tables.
      * @param timeoutMillis Timeout in milliseconds.
      * @param cancel Query cancel.
@@ -512,7 +512,7 @@ public class GridReduceQueryExecutor {
     public Iterator<List<?>> query(
         String schemaName,
         GridCacheTwoStepQuery qry,
-        boolean keepPortable,
+        boolean keepBinary,
         boolean enforceJoinOrder,
         int timeoutMillis,
         GridQueryCancel cancel,
@@ -818,7 +818,7 @@ public class GridReduceQueryExecutor {
                     continue;
                 }
 
-                return new GridQueryCacheObjectsIterator(resIter, h2.objectContext(), keepPortable);
+                return new GridQueryCacheObjectsIterator(resIter, h2.objectContext(), keepBinary);
             }
             catch (IgniteCheckedException | RuntimeException e) {
                 U.closeQuiet(r.connection());


[18/22] ignite git commit: Continuous queries fixes: - flush backup queue on exchange end (otherwise we don't really wait for all current operations) - on coordinator apply counters after all single messages received (otherwise extra counter increments a

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
index e7706dd..e5347c8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
@@ -24,17 +24,12 @@ import java.io.ObjectOutput;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.NavigableSet;
 import java.util.Set;
-import java.util.TreeMap;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicLong;
 import javax.cache.event.CacheEntryEvent;
 import javax.cache.event.CacheEntryEventFilter;
 import javax.cache.event.CacheEntryUpdatedListener;
@@ -42,23 +37,22 @@ import javax.cache.event.EventType;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.events.CacheQueryExecutedEvent;
 import org.apache.ignite.events.CacheQueryReadEvent;
 import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.IgniteDeploymentCheckedException;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
 import org.apache.ignite.internal.managers.communication.GridIoPolicy;
-import org.apache.ignite.internal.managers.deployment.GridDeployment;
 import org.apache.ignite.internal.managers.deployment.GridDeploymentInfo;
-import org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheAffinityManager;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition;
 import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicAbstractUpdateFuture;
 import org.apache.ignite.internal.processors.cache.query.CacheQueryType;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager.JCacheQueryLocalListener;
@@ -67,9 +61,6 @@ import org.apache.ignite.internal.processors.continuous.GridContinuousBatch;
 import org.apache.ignite.internal.processors.continuous.GridContinuousHandler;
 import org.apache.ignite.internal.processors.continuous.GridContinuousQueryBatch;
 import org.apache.ignite.internal.processors.platform.cache.query.PlatformContinuousQueryFilter;
-import org.apache.ignite.internal.util.GridConcurrentSkipListSet;
-import org.apache.ignite.internal.util.GridLongList;
-import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.CI1;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.T2;
@@ -81,7 +72,6 @@ import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.thread.IgniteStripedThreadPoolExecutor;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentLinkedDeque8;
 
 import static org.apache.ignite.events.EventType.EVT_CACHE_QUERY_EXECUTED;
 import static org.apache.ignite.events.EventType.EVT_CACHE_QUERY_OBJECT_READ;
@@ -94,7 +84,12 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
     private static final long serialVersionUID = 0L;
 
     /** */
-    private static final int BACKUP_ACK_THRESHOLD = 100;
+    static final int BACKUP_ACK_THRESHOLD =
+        IgniteSystemProperties.getInteger("IGNITE_CONTINUOUS_QUERY_BACKUP_ACK_THRESHOLD", 100);
+
+    /** */
+    static final int LSNR_MAX_BUF_SIZE =
+        IgniteSystemProperties.getInteger("IGNITE_CONTINUOUS_QUERY_LISTENER_MAX_BUFFER_SIZE", 10_000);
 
     /** Cache name. */
     private String cacheName;
@@ -109,7 +104,7 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
     private CacheEntryEventSerializableFilter<K, V> rmtFilter;
 
     /** Deployable object for filter. */
-    private DeployableObject rmtFilterDep;
+    private CacheContinuousQueryDeployableObject rmtFilterDep;
 
     /** Internal flag. */
     private boolean internal;
@@ -132,9 +127,6 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
     /** Whether to skip primary check for REPLICATED cache. */
     private transient boolean skipPrimaryCheck;
 
-    /** Backup queue. */
-    private transient volatile Collection<CacheContinuousQueryEntry> backupQueue;
-
     /** */
     private boolean locCache;
 
@@ -142,13 +134,13 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
     private boolean keepBinary;
 
     /** */
-    private transient ConcurrentMap<Integer, PartitionRecovery> rcvs;
+    private transient ConcurrentMap<Integer, CacheContinuousQueryPartitionRecovery> rcvs;
 
     /** */
-    private transient ConcurrentMap<Integer, EntryBuffer> entryBufs;
+    private transient ConcurrentMap<Integer, CacheContinuousQueryEventBuffer> entryBufs;
 
     /** */
-    private transient AcknowledgeBuffer ackBuf;
+    private transient CacheContinuousQueryAcknowledgeBuffer ackBuf;
 
     /** */
     private transient int cacheId;
@@ -163,6 +155,9 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
     private transient volatile AffinityTopologyVersion initTopVer;
 
     /** */
+    private transient volatile boolean nodeLeft;
+
+    /** */
     private transient boolean ignoreClsNotFound;
 
     /** */
@@ -337,9 +332,7 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
 
         entryBufs = new ConcurrentHashMap<>();
 
-        backupQueue = new ConcurrentLinkedDeque8<>();
-
-        ackBuf = new AcknowledgeBuffer();
+        ackBuf = new CacheContinuousQueryAcknowledgeBuffer();
 
         rcvs = new ConcurrentHashMap<>();
 
@@ -409,7 +402,7 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
                     ctx.asyncCallbackPool().execute(clsr, evt.partitionId());
                 }
                 else {
-                    final boolean notify = filter(evt, primary);
+                    final boolean notify = filter(evt);
 
                     if (log.isDebugEnabled())
                         log.debug("Filter invoked for event [evt=" + evt + ", primary=" + primary
@@ -429,6 +422,8 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
                             }, sync);
                         }
                     }
+                    else
+                        handleBackupEntry(cctx, evt.entry());
                 }
             }
 
@@ -438,50 +433,38 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
             }
 
             @Override public void cleanupBackupQueue(Map<Integer, Long> updateCntrs) {
-                Collection<CacheContinuousQueryEntry> backupQueue0 = backupQueue;
-
-                if (backupQueue0 != null) {
-                    Iterator<CacheContinuousQueryEntry> it = backupQueue0.iterator();
-
-                    while (it.hasNext()) {
-                        CacheContinuousQueryEntry backupEntry = it.next();
+                for (Map.Entry<Integer, Long> e : updateCntrs.entrySet()) {
+                    CacheContinuousQueryEventBuffer buf = entryBufs.get(e.getKey());
 
-                        Long updateCntr = updateCntrs.get(backupEntry.partition());
-
-                        if (updateCntr != null && backupEntry.updateCounter() <= updateCntr)
-                            it.remove();
-                    }
+                    if (buf != null)
+                        buf.cleanupBackupQueue(e.getValue());
                 }
             }
 
             @Override public void flushBackupQueue(GridKernalContext ctx, AffinityTopologyVersion topVer) {
                 assert topVer != null;
 
-                Collection<CacheContinuousQueryEntry> backupQueue0 = backupQueue;
+                try {
+                    GridCacheContext<K, V> cctx = cacheContext(ctx);
 
-                if (backupQueue0 == null)
-                    return;
+                    ClusterNode node = ctx.discovery().node(nodeId);
 
-                try {
-                    ClusterNode nodeId0 = ctx.discovery().node(nodeId);
+                    for (Map.Entry<Integer, CacheContinuousQueryEventBuffer> bufE : entryBufs.entrySet()) {
+                        CacheContinuousQueryEventBuffer buf = bufE.getValue();
 
-                    if (nodeId0 != null) {
-                        GridCacheContext<K, V> cctx = cacheContext(ctx);
+                        Collection<CacheContinuousQueryEntry> backupQueue = buf.flushOnExchange();
 
-                        for (CacheContinuousQueryEntry e : backupQueue0) {
-                            if (!e.isFiltered())
-                                prepareEntry(cctx, nodeId, e);
+                        if (backupQueue != null && node != null) {
+                            for (CacheContinuousQueryEntry e : backupQueue) {
+                                e.markBackup();
 
-                            e.topologyVersion(topVer);
-                        }
+                                if (!e.isFiltered())
+                                    prepareEntry(cctx, nodeId, e);
+                            }
 
-                        ctx.continuous().addBackupNotification(nodeId, routineId, backupQueue0, topic);
+                            ctx.continuous().addBackupNotification(nodeId, routineId, backupQueue, topic);
+                        }
                     }
-                    else
-                        // Node which start CQ leave topology. Not needed to put data to backup queue.
-                        backupQueue = null;
-
-                    backupQueue0.clear();
                 }
                 catch (IgniteCheckedException e) {
                     U.error(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY),
@@ -505,14 +488,7 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
             }
 
             @Override public void onPartitionEvicted(int part) {
-                Collection<CacheContinuousQueryEntry> backupQueue0 = backupQueue;
-
-                if (backupQueue0 != null) {
-                    for (Iterator<CacheContinuousQueryEntry> it = backupQueue0.iterator(); it.hasNext(); ) {
-                        if (it.next().partition() == part)
-                            it.remove();
-                    }
-                }
+                entryBufs.remove(part);
             }
 
             @Override public boolean oldValueRequired() {
@@ -739,17 +715,16 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
                 Collections.<CacheEntryEvent<? extends K, ? extends V>>emptyList();
         }
 
-        PartitionRecovery rec = getOrCreatePartitionRecovery(ctx, e.partition(), e.topologyVersion());
+        CacheContinuousQueryPartitionRecovery rec = getOrCreatePartitionRecovery(ctx, e.partition(), e.topologyVersion());
 
         return rec.collectEntries(e, cctx, cache);
     }
 
     /**
-     * @param primary Primary.
      * @param evt Query event.
      * @return {@code True} if event passed filter otherwise {@code true}.
      */
-    public boolean filter(CacheContinuousQueryEvent evt, boolean primary) {
+    public boolean filter(CacheContinuousQueryEvent evt) {
         CacheContinuousQueryEntry entry = evt.entry();
 
         boolean notify = !entry.isFiltered();
@@ -765,15 +740,6 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
         if (!notify)
             entry.markFiltered();
 
-        if (!primary && !internal && entry.updateCounter() != -1L /* Skip init query and expire entries */) {
-            entry.markBackup();
-
-            Collection<CacheContinuousQueryEntry> backupQueue0 = backupQueue;
-
-            if (backupQueue0 != null)
-                backupQueue0.add(entry.forBackupQueue());
-        }
-
         return notify;
     }
 
@@ -811,13 +777,13 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
                 if (!entry.isFiltered())
                     prepareEntry(cctx, nodeId, entry);
 
-                CacheContinuousQueryEntry e = handleEntry(entry);
+                Object entryOrList = handleEntry(cctx, entry);
 
-                if (e != null) {
+                if (entryOrList != null) {
                     if (log.isDebugEnabled())
-                        log.debug("Send the following event to listener: " + e);
+                        log.debug("Send the following event to listener: " + entryOrList);
 
-                    ctx.continuous().addNotification(nodeId, routineId, entry, topic, sync, true);
+                    ctx.continuous().addNotification(nodeId, routineId, entryOrList, topic, sync, true);
                 }
             }
         }
@@ -865,7 +831,7 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
         if (internal)
             return;
 
-        for (PartitionRecovery rec : rcvs.values())
+        for (CacheContinuousQueryPartitionRecovery rec : rcvs.values())
             rec.resetTopologyCache();
     }
 
@@ -875,12 +841,12 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
      * @param topVer Topology version for current operation.
      * @return Partition recovery.
      */
-    @NotNull private PartitionRecovery getOrCreatePartitionRecovery(GridKernalContext ctx,
+    @NotNull private CacheContinuousQueryPartitionRecovery getOrCreatePartitionRecovery(GridKernalContext ctx,
         int partId,
         AffinityTopologyVersion topVer) {
         assert topVer != null && topVer.topologyVersion() > 0 : topVer;
 
-        PartitionRecovery rec = rcvs.get(partId);
+        CacheContinuousQueryPartitionRecovery rec = rcvs.get(partId);
 
         if (rec == null) {
             T2<Long, Long> partCntrs = null;
@@ -905,10 +871,10 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
             else if (initUpdCntrs != null)
                 partCntrs = initUpdCntrs.get(partId);
 
-            rec = new PartitionRecovery(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), topVer,
+            rec = new CacheContinuousQueryPartitionRecovery(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), topVer,
                 partCntrs != null ? partCntrs.get2() : null);
 
-            PartitionRecovery oldRec = rcvs.putIfAbsent(partId, rec);
+            CacheContinuousQueryPartitionRecovery oldRec = rcvs.putIfAbsent(partId, rec);
 
             if (oldRec != null)
                 rec = oldRec;
@@ -918,10 +884,24 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
     }
 
     /**
+     * @param cctx Cache context.
+     * @param e Entry.
+     */
+    private void handleBackupEntry(final GridCacheContext cctx, CacheContinuousQueryEntry e) {
+        if (internal || e.updateCounter() == -1L || nodeLeft) // Skip internal query and expire entries.
+            return;
+
+        CacheContinuousQueryEventBuffer buf = partitionBuffer(cctx, e.partition());
+
+        buf.processEntry(e.copyWithDataReset(), true);
+    }
+
+    /**
+     * @param cctx Cache context.
      * @param e Entry.
      * @return Entry.
      */
-    private CacheContinuousQueryEntry handleEntry(CacheContinuousQueryEntry e) {
+    private Object handleEntry(final GridCacheContext cctx, CacheContinuousQueryEntry e) {
         assert e != null;
         assert entryBufs != null;
 
@@ -934,354 +914,52 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
 
         // Initial query entry.
         // This events should be fired immediately.
-        if (e.updateCounter() == -1)
+        if (e.updateCounter() == -1L)
             return e;
 
-        EntryBuffer buf = entryBufs.get(e.partition());
+        CacheContinuousQueryEventBuffer buf = partitionBuffer(cctx, e.partition());
 
-        if (buf == null) {
-            buf = new EntryBuffer();
-
-            EntryBuffer oldRec = entryBufs.putIfAbsent(e.partition(), buf);
-
-            if (oldRec != null)
-                buf = oldRec;
-        }
-
-        return buf.handle(e);
+        return buf.processEntry(e, false);
     }
 
     /**
-     *
+     * @param cctx Cache context.
+     * @param part Partition.
+     * @return Event buffer.
      */
-    private static class PartitionRecovery {
-        /** Event which means hole in sequence. */
-        private static final CacheContinuousQueryEntry HOLE = new CacheContinuousQueryEntry();
-
-        /** */
-        private final static int MAX_BUFF_SIZE = 100;
-
-        /** */
-        private IgniteLogger log;
-
-        /** */
-        private long lastFiredEvt;
-
-        /** */
-        private AffinityTopologyVersion curTop = AffinityTopologyVersion.NONE;
-
-        /** */
-        private final Map<Long, CacheContinuousQueryEntry> pendingEvts = new TreeMap<>();
-
-        /**
-         * @param log Logger.
-         * @param topVer Topology version.
-         * @param initCntr Update counters.
-         */
-        PartitionRecovery(IgniteLogger log, AffinityTopologyVersion topVer, @Nullable Long initCntr) {
-            this.log = log;
-
-            if (initCntr != null) {
-                assert topVer.topologyVersion() > 0 : topVer;
-
-                this.lastFiredEvt = initCntr;
-
-                curTop = topVer;
-            }
-        }
-
-        /**
-         * Resets cached topology.
-         */
-        void resetTopologyCache() {
-            curTop = AffinityTopologyVersion.NONE;
-        }
-
-        /**
-         * Add continuous entry.
-         *
-         * @param cctx Cache context.
-         * @param cache Cache.
-         * @param entry Cache continuous query entry.
-         * @return Collection entries which will be fired. This collection should contains only non-filtered events.
-         */
-        <K, V> Collection<CacheEntryEvent<? extends K, ? extends V>> collectEntries(
-            CacheContinuousQueryEntry entry,
-            GridCacheContext cctx,
-            IgniteCache cache
-        ) {
-            assert entry != null;
-
-            if (entry.topologyVersion() == null) { // Possible if entry is sent from old node.
-                assert entry.updateCounter() == 0L : entry;
-
-                return F.<CacheEntryEvent<? extends K, ? extends V>>
-                    asList(new CacheContinuousQueryEvent<K, V>(cache, cctx, entry));
-            }
-
-            List<CacheEntryEvent<? extends K, ? extends V>> entries;
-
-            synchronized (pendingEvts) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Handling event [lastFiredEvt=" + lastFiredEvt +
-                        ", curTop=" + curTop +
-                        ", entUpdCnt=" + entry.updateCounter() +
-                        ", partId=" + entry.partition() +
-                        ", pendingEvts=" + pendingEvts + ']');
-                }
-
-                // Received first event.
-                if (curTop == AffinityTopologyVersion.NONE) {
-                    lastFiredEvt = entry.updateCounter();
-
-                    curTop = entry.topologyVersion();
-
-                    if (log.isDebugEnabled()) {
-                        log.debug("First event [lastFiredEvt=" + lastFiredEvt +
-                            ", curTop=" + curTop +
-                            ", entUpdCnt=" + entry.updateCounter() +
-                            ", partId=" + entry.partition() + ']');
-                    }
-
-                    return !entry.isFiltered() ?
-                        F.<CacheEntryEvent<? extends K, ? extends V>>
-                            asList(new CacheContinuousQueryEvent<K, V>(cache, cctx, entry)) :
-                        Collections.<CacheEntryEvent<? extends K, ? extends V>>emptyList();
-                }
-
-                if (curTop.compareTo(entry.topologyVersion()) < 0) {
-                    if (entry.updateCounter() == 1L && !entry.isBackup()) {
-                        entries = new ArrayList<>(pendingEvts.size());
-
-                        for (CacheContinuousQueryEntry evt : pendingEvts.values()) {
-                            if (evt != HOLE && !evt.isFiltered())
-                                entries.add(new CacheContinuousQueryEvent<K, V>(cache, cctx, evt));
-                        }
-
-                        pendingEvts.clear();
-
-                        curTop = entry.topologyVersion();
-
-                        lastFiredEvt = entry.updateCounter();
-
-                        if (!entry.isFiltered())
-                            entries.add(new CacheContinuousQueryEvent<K, V>(cache, cctx, entry));
+    private CacheContinuousQueryEventBuffer partitionBuffer(final GridCacheContext cctx, int part) {
+        CacheContinuousQueryEventBuffer buf = entryBufs.get(part);
 
-                        if (log.isDebugEnabled())
-                            log.debug("Partition was lost [lastFiredEvt=" + lastFiredEvt +
-                                ", curTop=" + curTop +
-                                ", entUpdCnt=" + entry.updateCounter() +
-                                ", partId=" + entry.partition() +
-                                ", pendingEvts=" + pendingEvts + ']');
-
-                        return entries;
-                    }
-
-                    curTop = entry.topologyVersion();
-                }
-
-                // Check duplicate.
-                if (entry.updateCounter() > lastFiredEvt) {
-                    pendingEvts.put(entry.updateCounter(), entry);
-
-                    // Put filtered events.
-                    if (entry.filteredEvents() != null) {
-                        for (long cnrt : entry.filteredEvents()) {
-                            if (cnrt > lastFiredEvt)
-                                pendingEvts.put(cnrt, HOLE);
-                        }
-                    }
-                }
-                else {
-                    if (log.isDebugEnabled())
-                        log.debug("Skip duplicate continuous query message: " + entry);
-
-                    return Collections.emptyList();
-                }
-
-                if (pendingEvts.isEmpty()) {
-                    if (log.isDebugEnabled()) {
-                        log.debug("Nothing sent to listener [lastFiredEvt=" + lastFiredEvt +
-                            ", curTop=" + curTop +
-                            ", entUpdCnt=" + entry.updateCounter() +
-                            ", partId=" + entry.partition() + ']');
-                    }
-
-                    return Collections.emptyList();
-                }
-
-                Iterator<Map.Entry<Long, CacheContinuousQueryEntry>> iter = pendingEvts.entrySet().iterator();
-
-                entries = new ArrayList<>();
-
-                if (pendingEvts.size() >= MAX_BUFF_SIZE) {
-                    for (int i = 0; i < MAX_BUFF_SIZE - (MAX_BUFF_SIZE / 10); i++) {
-                        Map.Entry<Long, CacheContinuousQueryEntry> e = iter.next();
-
-                        if (e.getValue() != HOLE && !e.getValue().isFiltered())
-                            entries.add(new CacheContinuousQueryEvent<K, V>(cache, cctx, e.getValue()));
-
-                        lastFiredEvt = e.getKey();
-
-                        iter.remove();
-                    }
-
-                    if (log.isDebugEnabled()) {
-                        log.debug("Pending events reached max of buffer size [lastFiredEvt=" + lastFiredEvt +
-                            ", curTop=" + curTop +
-                            ", entUpdCnt=" + entry.updateCounter() +
-                            ", partId=" + entry.partition() +
-                            ", pendingEvts=" + pendingEvts + ']');
-                    }
-                }
-                else {
-                    // Elements are consistently.
-                    while (iter.hasNext()) {
-                        Map.Entry<Long, CacheContinuousQueryEntry> e = iter.next();
-
-                        if (e.getKey() == lastFiredEvt + 1) {
-                            ++lastFiredEvt;
+        if (buf == null) {
+            buf = new CacheContinuousQueryEventBuffer(part) {
+                @Override protected long currentPartitionCounter() {
+                    GridDhtLocalPartition locPart = cctx.topology().localPartition(part, null, false);
 
-                            if (e.getValue() != HOLE && !e.getValue().isFiltered())
-                                entries.add(new CacheContinuousQueryEvent<K, V>(cache, cctx, e.getValue()));
+                    if (locPart == null)
+                        return -1L;
 
-                            iter.remove();
-                        }
-                        else
-                            break;
-                    }
+                    return locPart.updateCounter();
                 }
-            }
-
-            if (log.isDebugEnabled()) {
-                log.debug("Will send to listener the following events [entries=" + entries +
-                    ", lastFiredEvt=" + lastFiredEvt +
-                    ", curTop=" + curTop +
-                    ", entUpdCnt=" + entry.updateCounter() +
-                    ", partId=" + entry.partition() +
-                    ", pendingEvts=" + pendingEvts + ']');
-            }
-
-            return entries;
-        }
-    }
-
-    /**
-     *
-     */
-    private static class EntryBuffer {
-        /** */
-        private final static int MAX_BUFF_SIZE = 100;
+            };
 
-        /** */
-        private final GridConcurrentSkipListSet<Long> buf = new GridConcurrentSkipListSet<>();
-
-        /** */
-        private AtomicLong lastFiredCntr = new AtomicLong();
-
-        /**
-         * @param newVal New value.
-         * @return Old value if previous value less than new value otherwise {@code -1}.
-         */
-        private long updateFiredCounter(long newVal) {
-            long prevVal = lastFiredCntr.get();
-
-            while (prevVal < newVal) {
-                if (lastFiredCntr.compareAndSet(prevVal, newVal))
-                    return prevVal;
-                else
-                    prevVal = lastFiredCntr.get();
-            }
+            CacheContinuousQueryEventBuffer oldBuf = entryBufs.putIfAbsent(part, buf);
 
-            return prevVal >= newVal ? -1 : prevVal;
+            if (oldBuf != null)
+                buf = oldBuf;
         }
 
-        /**
-         * Add continuous entry.
-         *
-         * @param e Cache continuous query entry.
-         * @return Collection entries which will be fired.
-         */
-        public CacheContinuousQueryEntry handle(CacheContinuousQueryEntry e) {
-            assert e != null;
-
-            if (e.isFiltered()) {
-                Long last = buf.lastx();
-                Long first = buf.firstx();
-
-                if (last != null && first != null && last - first >= MAX_BUFF_SIZE) {
-                    NavigableSet<Long> prevHoles = buf.subSet(first, true, last, true);
-
-                    GridLongList filteredEvts = new GridLongList((int)(last - first));
-
-                    int size = 0;
-
-                    Long cntr;
-
-                    while ((cntr = prevHoles.pollFirst()) != null) {
-                        filteredEvts.add(cntr);
-
-                        ++size;
-                    }
-
-                    filteredEvts.truncate(size, true);
-
-                    e.filteredEvents(filteredEvts);
-
-                    return e;
-                }
-
-                if (lastFiredCntr.get() > e.updateCounter() || e.updateCounter() == 1)
-                    return e;
-                else {
-                    buf.add(e.updateCounter());
-
-                    // Double check. If another thread sent a event with counter higher than this event.
-                    if (lastFiredCntr.get() > e.updateCounter() && buf.contains(e.updateCounter())) {
-                        buf.remove(e.updateCounter());
-
-                        return e;
-                    }
-                    else
-                        return null;
-                }
-            }
-            else {
-                long prevVal = updateFiredCounter(e.updateCounter());
-
-                if (prevVal == -1)
-                    return e;
-                else {
-                    NavigableSet<Long> prevHoles = buf.subSet(prevVal, true, e.updateCounter(), true);
-
-                    GridLongList filteredEvts = new GridLongList((int)(e.updateCounter() - prevVal));
-
-                    int size = 0;
-
-                    Long cntr;
-
-                    while ((cntr = prevHoles.pollFirst()) != null) {
-                        filteredEvts.add(cntr);
-
-                        ++size;
-                    }
-
-                    filteredEvts.truncate(size, true);
-
-                    e.filteredEvents(filteredEvts);
-
-                    return e;
-                }
-            }
-        }
+        return buf;
     }
 
     /** {@inheritDoc} */
     @Override public void onNodeLeft() {
-        Collection<CacheContinuousQueryEntry> backupQueue0 = backupQueue;
+        nodeLeft = true;
 
-        if (backupQueue0 != null)
-            backupQueue = null;
+        for (Map.Entry<Integer, CacheContinuousQueryEventBuffer> bufE : entryBufs.entrySet()) {
+            CacheContinuousQueryEventBuffer buf = bufE.getValue();
+
+            buf.flushOnExchange();
+        }
     }
 
     /** {@inheritDoc} */
@@ -1290,7 +968,7 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
         assert ctx.config().isPeerClassLoadingEnabled();
 
         if (rmtFilter != null && !U.isGrid(rmtFilter.getClass()))
-            rmtFilterDep = new DeployableObject(rmtFilter, ctx);
+            rmtFilterDep = new CacheContinuousQueryDeployableObject(rmtFilter, ctx);
     }
 
     /** {@inheritDoc} */
@@ -1411,7 +1089,7 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
         boolean b = in.readBoolean();
 
         if (b)
-            rmtFilterDep = (DeployableObject)in.readObject();
+            rmtFilterDep = (CacheContinuousQueryDeployableObject)in.readObject();
         else
             rmtFilter = (CacheEntryEventSerializableFilter<K, V>)in.readObject();
 
@@ -1436,95 +1114,6 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
         return ctx.cache().<K, V>context().cacheContext(cacheId);
     }
 
-    /** */
-    private static class AcknowledgeBuffer {
-        /** */
-        private int size;
-
-        /** */
-        @GridToStringInclude
-        private Map<Integer, Long> updateCntrs = new HashMap<>();
-
-        /** */
-        @GridToStringInclude
-        private Set<AffinityTopologyVersion> topVers = U.newHashSet(1);
-
-        /**
-         * @param batch Batch.
-         * @return Non-null tuple if acknowledge should be sent to backups.
-         */
-        @SuppressWarnings("unchecked")
-        @Nullable synchronized IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>>
-        onAcknowledged(GridContinuousBatch batch) {
-            assert batch instanceof GridContinuousQueryBatch;
-
-            size += ((GridContinuousQueryBatch)batch).entriesCount();
-
-            Collection<CacheContinuousQueryEntry> entries = (Collection)batch.collect();
-
-            for (CacheContinuousQueryEntry e : entries)
-                addEntry(e);
-
-            return size >= BACKUP_ACK_THRESHOLD ? acknowledgeData() : null;
-        }
-
-        /**
-         * @param e Entry.
-         * @return Non-null tuple if acknowledge should be sent to backups.
-         */
-        @Nullable synchronized IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>>
-        onAcknowledged(CacheContinuousQueryEntry e) {
-            size++;
-
-            addEntry(e);
-
-            return size >= BACKUP_ACK_THRESHOLD ? acknowledgeData() : null;
-        }
-
-        /**
-         * @param e Entry.
-         */
-        private void addEntry(CacheContinuousQueryEntry e) {
-            topVers.add(e.topologyVersion());
-
-            Long cntr0 = updateCntrs.get(e.partition());
-
-            if (cntr0 == null || e.updateCounter() > cntr0)
-                updateCntrs.put(e.partition(), e.updateCounter());
-        }
-
-        /**
-         * @return Non-null tuple if acknowledge should be sent to backups.
-         */
-        @Nullable synchronized IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>>
-            acknowledgeOnTimeout() {
-            return size > 0 ? acknowledgeData() : null;
-        }
-
-        /**
-         * @return Tuple with acknowledge information.
-         */
-        private IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>> acknowledgeData() {
-            assert size > 0;
-
-            Map<Integer, Long> cntrs = new HashMap<>(updateCntrs);
-
-            IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>> res =
-                new IgniteBiTuple<>(cntrs, topVers);
-
-            topVers = U.newHashSet(1);
-
-            size = 0;
-
-            return res;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(AcknowledgeBuffer.class, this);
-        }
-    }
-
     /**
      *
      */
@@ -1560,44 +1149,38 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
 
         /** {@inheritDoc} */
         @Override public void run() {
-            final boolean notify = filter(evt, primary);
-
-            if (!primary())
-                return;
+            final boolean notify = filter(evt);
 
-            if (fut == null) {
-                onEntryUpdate(evt, notify, nodeId.equals(ctx.localNodeId()), recordIgniteEvt);
+            if (primary || skipPrimaryCheck) {
+                if (fut == null) {
+                    onEntryUpdate(evt, notify, nodeId.equals(ctx.localNodeId()), recordIgniteEvt);
 
-                return;
-            }
+                    return;
+                }
 
-            if (fut.isDone()) {
-                if (fut.error() != null)
-                    evt.entry().markFiltered();
+                if (fut.isDone()) {
+                    if (fut.error() != null)
+                        evt.entry().markFiltered();
 
-                onEntryUpdate(evt, notify, nodeId.equals(ctx.localNodeId()), recordIgniteEvt);
-            }
-            else {
-                fut.listen(new CI1<IgniteInternalFuture<?>>() {
-                    @Override public void apply(IgniteInternalFuture<?> f) {
-                        if (f.error() != null)
-                            evt.entry().markFiltered();
-
-                        ctx.asyncCallbackPool().execute(new Runnable() {
-                            @Override public void run() {
-                                onEntryUpdate(evt, notify, nodeId.equals(ctx.localNodeId()), recordIgniteEvt);
-                            }
-                        }, evt.entry().partition());
-                    }
-                });
+                    onEntryUpdate(evt, notify, nodeId.equals(ctx.localNodeId()), recordIgniteEvt);
+                }
+                else {
+                    fut.listen(new CI1<IgniteInternalFuture<?>>() {
+                        @Override public void apply(IgniteInternalFuture<?> f) {
+                            if (f.error() != null)
+                                evt.entry().markFiltered();
+
+                            ctx.asyncCallbackPool().execute(new Runnable() {
+                                @Override public void run() {
+                                    onEntryUpdate(evt, notify, nodeId.equals(ctx.localNodeId()), recordIgniteEvt);
+                                }
+                            }, evt.entry().partition());
+                        }
+                    });
+                }
             }
-        }
-
-        /**
-         * @return {@code True} if event fired on this node.
-         */
-        private boolean primary() {
-            return primary || skipPrimaryCheck;
+            else
+                handleBackupEntry(cacheContext(ctx), evt.entry());
         }
 
         /** {@inheritDoc} */
@@ -1606,82 +1189,4 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
         }
     }
 
-    /**
-     * Deployable object.
-     */
-    protected static class DeployableObject implements Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Serialized object. */
-        private byte[] bytes;
-
-        /** Deployment class name. */
-        private String clsName;
-
-        /** Deployment info. */
-        private GridDeploymentInfo depInfo;
-
-        /**
-         * Required by {@link Externalizable}.
-         */
-        public DeployableObject() {
-            // No-op.
-        }
-
-        /**
-         * @param obj Object.
-         * @param ctx Kernal context.
-         * @throws IgniteCheckedException In case of error.
-         */
-        protected DeployableObject(Object obj, GridKernalContext ctx) throws IgniteCheckedException {
-            assert obj != null;
-            assert ctx != null;
-
-            Class cls = U.detectClass(obj);
-
-            clsName = cls.getName();
-
-            GridDeployment dep = ctx.deploy().deploy(cls, U.detectClassLoader(cls));
-
-            if (dep == null)
-                throw new IgniteDeploymentCheckedException("Failed to deploy object: " + obj);
-
-            depInfo = new GridDeploymentInfoBean(dep);
-
-            bytes = U.marshal(ctx, obj);
-        }
-
-        /**
-         * @param nodeId Node ID.
-         * @param ctx Kernal context.
-         * @return Deserialized object.
-         * @throws IgniteCheckedException In case of error.
-         */
-        <T> T unmarshal(UUID nodeId, GridKernalContext ctx) throws IgniteCheckedException {
-            assert ctx != null;
-
-            GridDeployment dep = ctx.deploy().getGlobalDeployment(depInfo.deployMode(), clsName, clsName,
-                depInfo.userVersion(), nodeId, depInfo.classLoaderId(), depInfo.participants(), null);
-
-            if (dep == null)
-                throw new IgniteDeploymentCheckedException("Failed to obtain deployment for class: " + clsName);
-
-            return U.unmarshal(ctx, bytes, U.resolveClassLoader(dep.classLoader(), ctx.config()));
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            U.writeByteArray(out, bytes);
-            U.writeString(out, clsName);
-            out.writeObject(depInfo);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            bytes = U.readByteArray(in);
-            clsName = U.readString(in);
-            depInfo = (GridDeploymentInfo)in.readObject();
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandlerV2.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandlerV2.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandlerV2.java
index 7aef4dd..e48d22e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandlerV2.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandlerV2.java
@@ -44,7 +44,7 @@ public class CacheContinuousQueryHandlerV2<K, V> extends CacheContinuousQueryHan
     private Factory<? extends CacheEntryEventFilter> rmtFilterFactory;
 
     /** Deployable object for filter factory. */
-    private DeployableObject rmtFilterFactoryDep;
+    private CacheContinuousQueryDeployableObject rmtFilterFactoryDep;
 
     /** Event types for JCache API. */
     private byte types;
@@ -122,7 +122,7 @@ public class CacheContinuousQueryHandlerV2<K, V> extends CacheContinuousQueryHan
         super.p2pMarshal(ctx);
 
         if (rmtFilterFactory != null && !U.isGrid(rmtFilterFactory.getClass()))
-            rmtFilterFactoryDep = new DeployableObject(rmtFilterFactory, ctx);
+            rmtFilterFactoryDep = new CacheContinuousQueryDeployableObject(rmtFilterFactory, ctx);
     }
 
     /** {@inheritDoc} */
@@ -167,7 +167,7 @@ public class CacheContinuousQueryHandlerV2<K, V> extends CacheContinuousQueryHan
         boolean b = in.readBoolean();
 
         if (b)
-            rmtFilterFactoryDep = (DeployableObject)in.readObject();
+            rmtFilterFactoryDep = (CacheContinuousQueryDeployableObject)in.readObject();
         else
             rmtFilterFactory = (Factory)in.readObject();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
index acf351f..1a655e9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
@@ -193,7 +193,8 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
                 lsnr.keepBinary(),
                 partId,
                 updCntr,
-                topVer);
+                topVer,
+                (byte)0);
 
             CacheContinuousQueryEvent evt = new CacheContinuousQueryEvent<>(
                 cctx.kernalContext().cache().jcache(cctx.name()), cctx, e0);
@@ -339,7 +340,8 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
                 lsnr.keepBinary(),
                 partId,
                 updateCntr,
-                topVer);
+                topVer,
+                (byte)0);
 
             IgniteCacheProxy jcache = cctx.kernalContext().cache().jcacheProxy(cctx.name());
 
@@ -400,7 +402,8 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
                     lsnr.keepBinary(),
                     e.partition(),
                     -1,
-                    null);
+                    null,
+                    (byte)0);
 
                 CacheContinuousQueryEvent evt = new CacheContinuousQueryEvent(
                     cctx.kernalContext().cache().jcache(cctx.name()), cctx, e0);
@@ -568,9 +571,9 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
     }
 
     /**
-     * @param topVer Topology version.
+     * @param topVer Finished exchange topology version.
      */
-    public void beforeExchange(AffinityTopologyVersion topVer) {
+    public void flushBackupQueue(AffinityTopologyVersion topVer) {
         for (CacheContinuousQueryListener lsnr : lsnrs.values())
             lsnr.flushBackupQueue(cctx.kernalContext(), topVer);
     }
@@ -703,7 +706,8 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
                                     keepBinary,
                                     0,
                                     -1,
-                                    null);
+                                    null,
+                                    (byte)0);
 
                                 next = new CacheContinuousQueryEvent<>(
                                     cctx.kernalContext().cache().jcache(cctx.name()),

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryPartitionRecovery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryPartitionRecovery.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryPartitionRecovery.java
new file mode 100644
index 0000000..e210c24
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryPartitionRecovery.java
@@ -0,0 +1,267 @@
+/*
+ * 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.continuous;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import javax.cache.event.CacheEntryEvent;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.LT;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ *
+ */
+class CacheContinuousQueryPartitionRecovery {
+    /** Event which means hole in sequence. */
+    private static final CacheContinuousQueryEntry HOLE;
+
+    static  {
+        HOLE = new CacheContinuousQueryEntry();
+
+        HOLE.markFiltered();
+    }
+
+    /** */
+    private final static int MAX_BUFF_SIZE = CacheContinuousQueryHandler.LSNR_MAX_BUF_SIZE;
+
+    /** */
+    private IgniteLogger log;
+
+    /** */
+    private long lastFiredEvt;
+
+    /** */
+    private AffinityTopologyVersion curTop = AffinityTopologyVersion.NONE;
+
+    /** */
+    private final TreeMap<Long, CacheContinuousQueryEntry> pendingEvts = new TreeMap<>();
+
+    /**
+     * @param log Logger.
+     * @param topVer Topology version.
+     * @param initCntr Update counters.
+     */
+    CacheContinuousQueryPartitionRecovery(IgniteLogger log, AffinityTopologyVersion topVer, @Nullable Long initCntr) {
+        this.log = log;
+
+        if (initCntr != null) {
+            assert topVer.topologyVersion() > 0 : topVer;
+
+            this.lastFiredEvt = initCntr;
+
+            curTop = topVer;
+        }
+    }
+
+    /**
+     * Resets cached topology.
+     */
+    void resetTopologyCache() {
+        curTop = AffinityTopologyVersion.NONE;
+    }
+
+    /**
+     * Add continuous entry.
+     *
+     * @param cctx Cache context.
+     * @param cache Cache.
+     * @param entry Cache continuous query entry.
+     * @return Collection entries which will be fired. This collection should contains only non-filtered events.
+     */
+    <K, V> Collection<CacheEntryEvent<? extends K, ? extends V>> collectEntries(
+        CacheContinuousQueryEntry entry,
+        GridCacheContext cctx,
+        IgniteCache cache
+    ) {
+        assert entry != null;
+
+        if (entry.topologyVersion() == null) { // Possible if entry is sent from old node.
+            assert entry.updateCounter() == 0L : entry;
+
+            return F.<CacheEntryEvent<? extends K, ? extends V>>
+                asList(new CacheContinuousQueryEvent<K, V>(cache, cctx, entry));
+        }
+
+        List<CacheEntryEvent<? extends K, ? extends V>> entries;
+
+        synchronized (pendingEvts) {
+            if (log.isDebugEnabled()) {
+                log.debug("Handling event [lastFiredEvt=" + lastFiredEvt +
+                    ", curTop=" + curTop +
+                    ", entUpdCnt=" + entry.updateCounter() +
+                    ", partId=" + entry.partition() +
+                    ", pendingEvts=" + pendingEvts + ']');
+            }
+
+            // Received first event.
+            if (curTop == AffinityTopologyVersion.NONE) {
+                lastFiredEvt = entry.updateCounter();
+
+                curTop = entry.topologyVersion();
+
+                if (log.isDebugEnabled()) {
+                    log.debug("First event [lastFiredEvt=" + lastFiredEvt +
+                        ", curTop=" + curTop +
+                        ", entUpdCnt=" + entry.updateCounter() +
+                        ", partId=" + entry.partition() + ']');
+                }
+
+                return !entry.isFiltered() ?
+                    F.<CacheEntryEvent<? extends K, ? extends V>>
+                        asList(new CacheContinuousQueryEvent<K, V>(cache, cctx, entry)) :
+                    Collections.<CacheEntryEvent<? extends K, ? extends V>>emptyList();
+            }
+
+            if (curTop.compareTo(entry.topologyVersion()) < 0) {
+                if (entry.updateCounter() == 1L && !entry.isBackup()) {
+                    entries = new ArrayList<>(pendingEvts.size());
+
+                    for (CacheContinuousQueryEntry evt : pendingEvts.values()) {
+                        if (evt != HOLE && !evt.isFiltered())
+                            entries.add(new CacheContinuousQueryEvent<K, V>(cache, cctx, evt));
+                    }
+
+                    pendingEvts.clear();
+
+                    curTop = entry.topologyVersion();
+
+                    lastFiredEvt = entry.updateCounter();
+
+                    if (!entry.isFiltered())
+                        entries.add(new CacheContinuousQueryEvent<K, V>(cache, cctx, entry));
+
+                    if (log.isDebugEnabled())
+                        log.debug("Partition was lost [lastFiredEvt=" + lastFiredEvt +
+                            ", curTop=" + curTop +
+                            ", entUpdCnt=" + entry.updateCounter() +
+                            ", partId=" + entry.partition() +
+                            ", pendingEvts=" + pendingEvts + ']');
+
+                    return entries;
+                }
+
+                curTop = entry.topologyVersion();
+            }
+
+            // Check duplicate.
+            if (entry.updateCounter() > lastFiredEvt)
+                pendingEvts.put(entry.updateCounter(), entry);
+            else {
+                if (log.isDebugEnabled())
+                    log.debug("Skip duplicate continuous query message: " + entry);
+
+                return Collections.emptyList();
+            }
+
+            if (pendingEvts.isEmpty()) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Nothing sent to listener [lastFiredEvt=" + lastFiredEvt +
+                        ", curTop=" + curTop +
+                        ", entUpdCnt=" + entry.updateCounter() +
+                        ", partId=" + entry.partition() + ']');
+                }
+
+                return Collections.emptyList();
+            }
+
+            Iterator<Map.Entry<Long, CacheContinuousQueryEntry>> iter = pendingEvts.entrySet().iterator();
+
+            entries = new ArrayList<>();
+
+            if (pendingEvts.size() >= MAX_BUFF_SIZE) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Pending events reached max of buffer size [lastFiredEvt=" + lastFiredEvt +
+                        ", curTop=" + curTop +
+                        ", entUpdCnt=" + entry.updateCounter() +
+                        ", partId=" + entry.partition() +
+                        ", pendingEvts=" + pendingEvts + ']');
+                }
+
+                LT.warn(log, "Pending events reached max of buffer size [cache=" + cctx.name() +
+                    ", bufSize=" + MAX_BUFF_SIZE +
+                    ", partId=" + entry.partition() + ']');
+
+                for (int i = 0; i < MAX_BUFF_SIZE - (MAX_BUFF_SIZE / 10); i++) {
+                    Map.Entry<Long, CacheContinuousQueryEntry> e = iter.next();
+
+                    if (e.getValue() != HOLE && !e.getValue().isFiltered())
+                        entries.add(new CacheContinuousQueryEvent<K, V>(cache, cctx, e.getValue()));
+
+                    lastFiredEvt = e.getKey();
+
+                    iter.remove();
+                }
+            }
+            else {
+                boolean skippedFiltered = false;
+
+                while (iter.hasNext()) {
+                    Map.Entry<Long, CacheContinuousQueryEntry> e = iter.next();
+
+                    CacheContinuousQueryEntry pending = e.getValue();
+
+                    long filtered = pending.filteredCount();
+
+                    boolean fire = e.getKey() == lastFiredEvt + 1;;
+
+                    if (!fire && filtered > 0)
+                        fire = e.getKey() - filtered <= lastFiredEvt + 1;
+
+                    if (fire) {
+                        lastFiredEvt = e.getKey();
+
+                        if (e.getValue() != HOLE && !e.getValue().isFiltered())
+                            entries.add(new CacheContinuousQueryEvent<K, V>(cache, cctx, pending));
+
+                        iter.remove();
+                    }
+                    else {
+                        if (pending.isFiltered())
+                            skippedFiltered = true;
+                        else
+                            break;
+                    }
+                }
+
+                if (skippedFiltered)
+                    pendingEvts.headMap(lastFiredEvt).clear();
+            }
+        }
+
+        if (log.isDebugEnabled()) {
+            log.debug("Will send to listener the following events [entries=" + entries +
+                ", lastFiredEvt=" + lastFiredEvt +
+                ", curTop=" + curTop +
+                ", entUpdCnt=" + entry.updateCounter() +
+                ", partId=" + entry.partition() +
+                ", pendingEvts=" + pendingEvts + ']');
+        }
+
+        return entries;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousBatchAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousBatchAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousBatchAdapter.java
index 4540de1..597eae8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousBatchAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousBatchAdapter.java
@@ -25,7 +25,7 @@ import org.jsr166.ConcurrentLinkedDeque8;
  */
 public class GridContinuousBatchAdapter implements GridContinuousBatch {
     /** Buffer. */
-    private final ConcurrentLinkedDeque8<Object> buf = new ConcurrentLinkedDeque8<>();
+    protected final ConcurrentLinkedDeque8<Object> buf = new ConcurrentLinkedDeque8<>();
 
     /** {@inheritDoc} */
     @Override public void add(Object obj) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
index abcd8ea..a72dcd6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
@@ -75,7 +75,6 @@ import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgniteFuture;
 import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.lang.IgnitePredicate;
-import org.apache.ignite.lang.IgniteProductVersion;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.marshaller.Marshaller;
 import org.apache.ignite.plugin.extensions.communication.Message;
@@ -872,10 +871,10 @@ public class GridContinuousProcessor extends GridProcessorAdapter {
                 sendNotification(nodeId, routineId, null, toSnd, orderedTopic, true, null);
         }
         else {
-            LocalRoutineInfo localRoutineInfo = locInfos.get(routineId);
+            LocalRoutineInfo locRoutineInfo = locInfos.get(routineId);
 
-            if (localRoutineInfo != null)
-                localRoutineInfo.handler().notifyCallback(nodeId, routineId, objs, ctx);
+            if (locRoutineInfo != null)
+                locRoutineInfo.handler().notifyCallback(nodeId, routineId, objs, ctx);
         }
     }
 
@@ -897,7 +896,7 @@ public class GridContinuousProcessor extends GridProcessorAdapter {
         throws IgniteCheckedException {
         assert nodeId != null;
         assert routineId != null;
-        assert !msg || obj instanceof Message : obj;
+        assert !msg || (obj instanceof Message || obj instanceof Collection) : obj;
 
         assert !nodeId.equals(ctx.localNodeId());
 
@@ -917,7 +916,13 @@ public class GridContinuousProcessor extends GridProcessorAdapter {
                 syncMsgFuts.put(futId, fut);
 
                 try {
-                    sendNotification(nodeId, routineId, futId, F.asList(obj), null, msg, null);
+                    sendNotification(nodeId,
+                        routineId,
+                        futId,
+                        obj instanceof Collection ? (Collection)obj : F.asList(obj),
+                        null,
+                        msg,
+                        null);
 
                     info.hnd.onBatchAcknowledged(routineId, info.add(obj), ctx);
                 }
@@ -1563,7 +1568,7 @@ public class GridContinuousProcessor extends GridProcessorAdapter {
         GridContinuousBatch addAll(Collection<?> objs) {
             assert objs != null;
 
-            GridContinuousBatch toSnd = null;
+            GridContinuousBatch toSnd;
 
             lock.writeLock().lock();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousQueryBatch.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousQueryBatch.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousQueryBatch.java
index c5d854b..0eba44b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousQueryBatch.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousQueryBatch.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.continuous;
 
+import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryEntry;
@@ -31,11 +32,20 @@ public class GridContinuousQueryBatch extends GridContinuousBatchAdapter {
     /** {@inheritDoc} */
     @Override public void add(Object obj) {
         assert obj != null;
-        assert obj instanceof CacheContinuousQueryEntry;
+        assert obj instanceof CacheContinuousQueryEntry || obj instanceof List;
 
-        super.add(obj);
+        if (obj instanceof CacheContinuousQueryEntry) {
+            buf.add(obj);
 
-        size.addAndGet(((CacheContinuousQueryEntry)obj).size());
+            size.incrementAndGet();
+        }
+        else {
+            List<Object> objs = (List<Object>)obj;
+
+            buf.addAll(objs);
+
+            size.addAndGet(objs.size());
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverAtomicSelfTest.java
index 3cab9e0..d505d19 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverAtomicSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverAtomicSelfTest.java
@@ -25,7 +25,6 @@ import org.apache.ignite.cache.CacheMode;
  */
 public class CacheContinuousQueryAsyncFailoverAtomicSelfTest
     extends CacheContinuousQueryFailoverAbstractSelfTest {
-
     /** {@inheritDoc} */
     @Override protected CacheMode cacheMode() {
         return CacheMode.PARTITIONED;

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryConcurrentPartitionUpdateTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryConcurrentPartitionUpdateTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryConcurrentPartitionUpdateTest.java
new file mode 100644
index 0000000..9c7c836
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryConcurrentPartitionUpdateTest.java
@@ -0,0 +1,304 @@
+/*
+ * 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.continuous;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryUpdatedListener;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
+import org.apache.ignite.internal.util.typedef.internal.U;
+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.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class CacheContinuousQueryConcurrentPartitionUpdateTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private boolean client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+        cfg.setClientMode(client);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        super.afterTest();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConcurrentUpdatePartitionAtomic() throws Exception {
+        concurrentUpdatePartition(ATOMIC);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConcurrentUpdatePartitionTx() throws Exception {
+        concurrentUpdatePartition(TRANSACTIONAL);
+    }
+
+    /**
+     * @param atomicityMode Cache atomicity mode.
+     * @throws Exception If failed.
+     */
+    private void concurrentUpdatePartition(CacheAtomicityMode atomicityMode) throws Exception {
+        Ignite srv = startGrid(0);
+
+        client = true;
+
+        Ignite client = startGrid(1);
+
+        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
+
+        ccfg.setWriteSynchronizationMode(FULL_SYNC);
+        ccfg.setAtomicityMode(atomicityMode);
+
+        IgniteCache clientCache = client.createCache(ccfg);
+
+        final AtomicInteger evtCnt = new AtomicInteger();
+
+        ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
+
+        qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
+            @Override public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
+                for (CacheEntryEvent evt : evts) {
+                    assertNotNull(evt.getKey());
+                    assertNotNull(evt.getValue());
+
+                    evtCnt.incrementAndGet();
+                }
+            }
+        });
+
+        clientCache.query(qry);
+
+        Affinity<Integer> aff = srv.affinity(DEFAULT_CACHE_NAME);
+
+        final List<Integer> keys = new ArrayList<>();
+
+        final int KEYS = 10;
+
+        for (int i = 0; i < 100_000; i++) {
+            if (aff.partition(i) == 0) {
+                keys.add(i);
+
+                if (keys.size() == KEYS)
+                    break;
+            }
+        }
+
+        assertEquals(KEYS, keys.size());
+
+        final int THREADS = 10;
+        final int UPDATES = 1000;
+
+        final IgniteCache<Object, Object> srvCache = srv.cache(DEFAULT_CACHE_NAME);
+
+        for (int i = 0; i < 15; i++) {
+            log.info("Iteration: " + i);
+
+            GridTestUtils.runMultiThreaded(new Callable<Void>() {
+                @Override public Void call() throws Exception {
+                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+                    for (int i = 0; i < UPDATES; i++)
+                        srvCache.put(keys.get(rnd.nextInt(KEYS)), i);
+
+                    return null;
+                }
+            }, THREADS, "update");
+
+            GridTestUtils.waitForCondition(new GridAbsPredicate() {
+                @Override public boolean apply() {
+                    log.info("Events: " + evtCnt.get());
+
+                    return evtCnt.get() >= THREADS * UPDATES;
+                }
+            }, 5000);
+
+            assertEquals(THREADS * UPDATES, evtCnt.get());
+
+            evtCnt.set(0);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConcurrentUpdatesAndQueryStartAtomic() throws Exception {
+        concurrentUpdatesAndQueryStart(ATOMIC);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConcurrentUpdatesAndQueryStartTx() throws Exception {
+        concurrentUpdatesAndQueryStart(TRANSACTIONAL);
+    }
+
+    /**
+     * @param atomicityMode Cache atomicity mode.
+     * @throws Exception If failed.
+     */
+    private void concurrentUpdatesAndQueryStart(CacheAtomicityMode atomicityMode) throws Exception {
+        Ignite srv = startGrid(0);
+
+        client = true;
+
+        Ignite client = startGrid(1);
+
+        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
+
+        ccfg.setWriteSynchronizationMode(FULL_SYNC);
+        ccfg.setAtomicityMode(atomicityMode);
+
+        IgniteCache clientCache = client.createCache(ccfg);
+
+        Affinity<Integer> aff = srv.affinity(DEFAULT_CACHE_NAME);
+
+        final List<Integer> keys = new ArrayList<>();
+
+        final int KEYS = 10;
+
+        for (int i = 0; i < 100_000; i++) {
+            if (aff.partition(i) == 0) {
+                keys.add(i);
+
+                if (keys.size() == KEYS)
+                    break;
+            }
+        }
+
+        assertEquals(KEYS, keys.size());
+
+        final int THREADS = 10;
+        final int UPDATES = 1000;
+
+        for (int i = 0; i < 5; i++) {
+            log.info("Iteration: " + i);
+
+            ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
+
+            final AtomicInteger evtCnt = new AtomicInteger();
+
+            qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
+                @Override public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
+                    for (CacheEntryEvent evt : evts) {
+                        assertNotNull(evt.getKey());
+                        assertNotNull(evt.getValue());
+
+                        if ((Integer)evt.getValue() >= 0)
+                            evtCnt.incrementAndGet();
+                    }
+                }
+            });
+
+            QueryCursor cur;
+
+            final IgniteCache<Object, Object> srvCache = srv.cache(DEFAULT_CACHE_NAME);
+
+            final AtomicBoolean stop = new AtomicBoolean();
+
+            try {
+                IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
+                    @Override public Void call() throws Exception {
+                        ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+                        while (!stop.get())
+                            srvCache.put(keys.get(rnd.nextInt(KEYS)), rnd.nextInt(100) - 200);
+
+                        return null;
+                    }
+                }, THREADS, "update");
+
+                U.sleep(1000);
+
+                cur = clientCache.query(qry);
+
+                U.sleep(1000);
+
+                stop.set(true);
+
+                fut.get();
+            }
+            finally {
+                stop.set(true);
+            }
+
+            GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
+                @Override public Void call() throws Exception {
+                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+                    for (int i = 0; i < UPDATES; i++)
+                        srvCache.put(keys.get(rnd.nextInt(KEYS)), i);
+
+                    return null;
+                }
+            }, THREADS, "update");
+
+
+            GridTestUtils.waitForCondition(new GridAbsPredicate() {
+                @Override public boolean apply() {
+                    log.info("Events: " + evtCnt.get());
+
+                    return evtCnt.get() >= THREADS * UPDATES;
+                }
+            }, 5000);
+
+            assertEquals(THREADS * UPDATES, evtCnt.get());
+
+            cur.close();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBufferTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBufferTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBufferTest.java
new file mode 100644
index 0000000..382f166
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBufferTest.java
@@ -0,0 +1,217 @@
+/*
+ * 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.continuous;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.CyclicBarrier;
+import javax.cache.event.EventType;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+@SuppressWarnings("unchecked")
+public class CacheContinuousQueryEventBufferTest extends GridCommonAbstractTest {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBuffer1() throws Exception {
+        testBuffer(1);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBuffer2() throws Exception {
+        for (int i = 0; i < 10; i++) {
+            log.info("Iteration: " + i);
+
+            testBuffer(10);
+        }
+    }
+
+    /**
+     * @param threads Threads number.
+     * @throws Exception If failed.
+     */
+    private void testBuffer(int threads) throws Exception {
+        long seed = System.nanoTime();
+
+        Random rnd = new Random(seed);
+
+        log.info("Start test, seed: " + seed);
+
+        for (int i = 0; i < 10; i++) {
+            int cnt = rnd.nextInt(10_000) + 1;
+
+            testBuffer(rnd, new CacheContinuousQueryEventBuffer(0), cnt, 1, 0.5f, threads);
+            testBuffer(rnd, new CacheContinuousQueryEventBuffer(0), cnt, 1, 0.9f, threads);
+            testBuffer(rnd, new CacheContinuousQueryEventBuffer(0), cnt, 1, 0.99f, threads);
+            testBuffer(rnd, new CacheContinuousQueryEventBuffer(0), cnt, 1, 0.01f, threads);
+            testBuffer(rnd, new CacheContinuousQueryEventBuffer(0), cnt, 1, 0.f, threads);
+        }
+
+        CacheContinuousQueryEventBuffer b = new CacheContinuousQueryEventBuffer(0);
+
+        long cntr = 1;
+
+        for (int i = 0; i < 10; i++) {
+            int cnt = rnd.nextInt(10_000) + 1;
+            float ratio = rnd.nextFloat();
+
+            testBuffer(rnd, b, cnt, cntr, ratio, threads);
+
+            cntr += cnt;
+        }
+    }
+
+    /**
+     * @param rnd Random.
+     * @param b Buffer.
+     * @param cnt Entries count.
+     * @param cntr Current counter.
+     * @param filterRatio Filtered events ratio.
+     * @param threads Threads number.
+     * @throws Exception If failed.
+     */
+    private void testBuffer(Random rnd,
+        final CacheContinuousQueryEventBuffer b,
+        int cnt,
+        long cntr,
+        float filterRatio,
+        int threads)
+        throws Exception
+    {
+        List<CacheContinuousQueryEntry> expEntries = new ArrayList<>();
+
+        List<CacheContinuousQueryEntry> entries = new ArrayList<>();
+
+        long filtered = b.currentFiltered();
+
+        for (int i = 0; i < cnt; i++) {
+            CacheContinuousQueryEntry entry = new CacheContinuousQueryEntry(
+                0,
+                EventType.CREATED,
+                null,
+                null,
+                null,
+                false,
+                0,
+                cntr,
+                null,
+                (byte)0);
+
+            entries.add(entry);
+
+            if (rnd.nextFloat() < filterRatio) {
+                entry.markFiltered();
+
+                filtered++;
+            }
+            else {
+                CacheContinuousQueryEntry expEntry = new CacheContinuousQueryEntry(
+                    0,
+                    EventType.CREATED,
+                    null,
+                    null,
+                    null,
+                    false,
+                    0,
+                    cntr,
+                    null,
+                    (byte)0);
+
+                expEntry.filteredCount(filtered);
+
+                expEntries.add(expEntry);
+
+                filtered = 0;
+            }
+
+            cntr++;
+        }
+
+        Collections.shuffle(entries, rnd);
+
+        List<CacheContinuousQueryEntry> actualEntries = new ArrayList<>(expEntries.size());
+
+        if (threads == 1) {
+            for (int i = 0; i < entries.size(); i++) {
+                Object o = entries.get(i);
+
+                Object res = b.processEntry((CacheContinuousQueryEntry)o, false);
+
+                if (res != null) {
+                    if (res instanceof CacheContinuousQueryEntry)
+                        actualEntries.add((CacheContinuousQueryEntry)res);
+                    else
+                        actualEntries.addAll((List<CacheContinuousQueryEntry>)res);
+                }
+            }
+        }
+        else {
+            final CyclicBarrier barrier = new CyclicBarrier(threads);
+
+            final ConcurrentLinkedQueue<CacheContinuousQueryEntry> q = new ConcurrentLinkedQueue<>(entries);
+
+            final ConcurrentSkipListMap<Long, CacheContinuousQueryEntry> act0 = new ConcurrentSkipListMap<>();
+
+            GridTestUtils.runMultiThreaded(new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    barrier.await();
+
+                    Object o;
+
+                    while ((o = q.poll()) != null) {
+                        Object res = b.processEntry((CacheContinuousQueryEntry)o, false);
+
+                        if (res != null) {
+                            if (res instanceof CacheContinuousQueryEntry)
+                                act0.put(((CacheContinuousQueryEntry)res).updateCounter(), (CacheContinuousQueryEntry)res);
+                            else {
+                                for (CacheContinuousQueryEntry e : ((List<CacheContinuousQueryEntry>)res))
+                                    act0.put(e.updateCounter(), e);
+                            }
+                        }
+                    }
+
+                    return null;
+                }
+            }, threads, "test");
+
+            actualEntries.addAll(act0.values());
+        }
+
+        assertEquals(expEntries.size(), actualEntries.size());
+
+        for (int i = 0; i < expEntries.size(); i++) {
+            CacheContinuousQueryEntry expEvt = expEntries.get(i);
+            CacheContinuousQueryEntry actualEvt = actualEntries.get(i);
+
+            assertEquals(expEvt.updateCounter(), actualEvt.updateCounter());
+            assertEquals(expEvt.filteredCount(), actualEvt.filteredCount());
+        }
+    }
+}


[03/22] ignite git commit: IGNITE-5304: SQL: decoupled DDL from schema. This closes #2017.

Posted by sb...@apache.org.
IGNITE-5304: SQL: decoupled DDL from schema. This closes #2017.


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

Branch: refs/heads/ignite-5075
Commit: 40851c7ff44c0ec97d9cca53923c8db0a38f78cd
Parents: 427ca69
Author: devozerov <vo...@gridgain.com>
Authored: Sat May 27 15:07:01 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Sat May 27 15:07:01 2017 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryIndexing.java     |  9 ++-
 .../processors/query/GridQueryProcessor.java    | 32 +++++-----
 .../processors/query/QueryIndexKey.java         | 28 +++------
 .../processors/query/h2/IgniteH2Indexing.java   | 32 +++++-----
 .../query/h2/ddl/DdlStatementsProcessor.java    | 66 ++++++++++++--------
 .../DynamicIndexAbstractConcurrentSelfTest.java |  8 +--
 6 files changed, 83 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/40851c7f/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
index 77c581c..9d66c0a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
@@ -142,27 +142,26 @@ public interface GridQueryIndexing {
     /**
      * Create new index locally.
      *
-     * @param cacheName Cache name.
+     * @param schemaName Schema name.
      * @param tblName Table name.
      * @param idxDesc Index descriptor.
      * @param ifNotExists Ignore operation if index exists (instead of throwing an error).
      * @param cacheVisitor Cache visitor
      * @throws IgniteCheckedException if failed.
      */
-    public void dynamicIndexCreate(String cacheName, String tblName, QueryIndexDescriptorImpl idxDesc,
+    public void dynamicIndexCreate(String schemaName, String tblName, QueryIndexDescriptorImpl idxDesc,
         boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor) throws IgniteCheckedException;
 
     /**
      * Remove index from the cache.
      *
-     * @param cacheName cache name.
+     * @param schemaName Schema name.
      * @param idxName Index name.
      * @param ifExists Ignore operation if index does not exist (instead of throwing an error).
      * @throws IgniteCheckedException If failed.
      */
     @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
-    public void dynamicIndexDrop(String cacheName, String idxName, boolean ifExists)
-        throws IgniteCheckedException;
+    public void dynamicIndexDrop(String schemaName, String idxName, boolean ifExists) throws IgniteCheckedException;
 
     /**
      * Registers cache.

http://git-wip-us.apache.org/repos/asf/ignite/blob/40851c7f/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 3233fd2..76cde17 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -933,7 +933,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             if (err == null) {
                 String idxName = op0.index().getName();
 
-                QueryIndexKey idxKey = new QueryIndexKey(cacheName, idxName);
+                QueryIndexKey idxKey = new QueryIndexKey(op.schemaName(), idxName);
 
                 if (idxs.get(idxKey) != null) {
                     if (op0.ifNotExists())
@@ -948,7 +948,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             String idxName = op0.indexName();
 
-            QueryIndexDescriptorImpl oldIdx = idxs.get(new QueryIndexKey(cacheName, idxName));
+            QueryIndexDescriptorImpl oldIdx = idxs.get(new QueryIndexKey(op.schemaName(), idxName));
 
             if (oldIdx == null) {
                 if (op0.ifExists())
@@ -1159,7 +1159,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             if (log.isDebugEnabled())
                 log.debug("Local operation finished successfully [opId=" + op.id() + ']');
 
-            String cacheName = op.cacheName();
+            String schemaName = op.schemaName();
 
             try {
                 if (op instanceof SchemaIndexCreateOperation) {
@@ -1169,7 +1169,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                     QueryIndexDescriptorImpl idxDesc = type.index(op0.indexName());
 
-                    QueryIndexKey idxKey = new QueryIndexKey(cacheName, op0.indexName());
+                    QueryIndexKey idxKey = new QueryIndexKey(schemaName, op0.indexName());
 
                     idxs.put(idxKey, idxDesc);
                 }
@@ -1180,7 +1180,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                     QueryUtils.processDynamicIndexChange(op0.indexName(), null, type);
 
-                    QueryIndexKey idxKey = new QueryIndexKey(cacheName, op0.indexName());
+                    QueryIndexKey idxKey = new QueryIndexKey(schemaName, op0.indexName());
 
                     idxs.remove(idxKey);
                 }
@@ -1251,12 +1251,12 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 SchemaIndexCacheVisitor visitor =
                     new SchemaIndexCacheVisitorImpl(this, cache.context(), cacheName, op0.tableName(), cancelTok);
 
-                idx.dynamicIndexCreate(cacheName, op0.tableName(), idxDesc, op0.ifNotExists(), visitor);
+                idx.dynamicIndexCreate(op0.schemaName(), op0.tableName(), idxDesc, op0.ifNotExists(), visitor);
             }
             else if (op instanceof SchemaIndexDropOperation) {
                 SchemaIndexDropOperation op0 = (SchemaIndexDropOperation) op;
 
-                idx.dynamicIndexDrop(cacheName, op0.indexName(), op0.ifExists());
+                idx.dynamicIndexDrop(op0.schemaName(), op0.indexName(), op0.ifExists());
             }
             else
                 throw new SchemaOperationException("Unsupported operation: " + op);
@@ -1293,10 +1293,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         CacheConfiguration<?, ?> newCfg = new CacheConfiguration<>(templateCfg);
 
         newCfg.setName(entity.getTableName());
-
         newCfg.setQueryEntities(Collections.singleton(entity));
 
-        // We want to preserve user specified names as they are
+        // Preserve user specified names as they are.
         newCfg.setSqlEscapeAll(true);
 
         boolean res = ctx.grid().getOrCreateCache0(newCfg).get2();
@@ -1308,14 +1307,14 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     /**
      * Drop table by destroying its cache if it's an 1:1 per cache table.
      *
-     * @param schemaName Schema name.
+     * @param cacheName Cache name.
      * @param tblName Table name.
      * @param ifExists Quietly ignore this command if table does not exist.
      * @throws SchemaOperationException if {@code ifExists} is {@code false} and cache was not found.
      */
     @SuppressWarnings("unchecked")
-    public void dynamicTableDrop(String schemaName, String tblName, boolean ifExists) throws SchemaOperationException {
-        boolean res = ctx.grid().destroyCache0(tblName);
+    public void dynamicTableDrop(String cacheName, String tblName, boolean ifExists) throws SchemaOperationException {
+        boolean res = ctx.grid().destroyCache0(cacheName);
 
         if (!res && !ifExists)
             throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, tblName);
@@ -1352,13 +1351,14 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                         types.put(altTypeId, desc);
 
                     for (QueryIndexDescriptorImpl idx : desc.indexes0()) {
-                        QueryIndexKey idxKey = new QueryIndexKey(cacheName, idx.name());
+                        QueryIndexKey idxKey = new QueryIndexKey(schemaName, idx.name());
 
                         QueryIndexDescriptorImpl oldIdx = idxs.putIfAbsent(idxKey, idx);
 
                         if (oldIdx != null) {
                             throw new IgniteException("Duplicate index name [cache=" + cacheName +
-                                ", idxName=" + idx.name() + ", existingTable=" + oldIdx.typeDescriptor().tableName() +
+                                ", schemaName=" + schemaName + ", idxName=" + idx.name() +
+                                ", existingTable=" + oldIdx.typeDescriptor().tableName() +
                                 ", table=" + desc.tableName() + ']');
                         }
                     }
@@ -1409,9 +1409,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             while (idxIt.hasNext()) {
                 Map.Entry<QueryIndexKey, QueryIndexDescriptorImpl> idxEntry = idxIt.next();
 
-                QueryIndexKey idxKey = idxEntry.getKey();
-
-                if (F.eq(cacheName, idxKey.cacheName()))
+                if (F.eq(cacheName, idxEntry.getValue().typeDescriptor().cacheName()))
                     idxIt.remove();
             }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/40851c7f/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
index 7fdb805..fea6594 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
@@ -29,8 +29,8 @@ public class QueryIndexKey implements Serializable {
     /** */
     private static final long serialVersionUID = 0L;
 
-    /** Cache name. */
-    private final String cacheName;
+    /** Schema name. */
+    private final String schemaName;
 
     /** Name. */
     private final String name;
@@ -38,31 +38,17 @@ public class QueryIndexKey implements Serializable {
     /**
      * Constructor.
      *
-     * @param cacheName Cache name.
+     * @param schemaName Schema name.
      * @param name Name.
      */
-    public QueryIndexKey(String cacheName, String name) {
-        this.cacheName = cacheName;
+    public QueryIndexKey(String schemaName, String name) {
+        this.schemaName = schemaName;
         this.name = name;
     }
 
-    /**
-     * @return Cache name.
-     */
-    public String cacheName() {
-        return cacheName;
-    }
-
-    /**
-     * @return Name.
-     */
-    public String name() {
-        return name;
-    }
-
     /** {@inheritDoc} */
     @Override public int hashCode() {
-        return 31 * (cacheName != null ? cacheName.hashCode() : 0) + (name != null ? name.hashCode() : 0);
+        return 31 * (schemaName != null ? schemaName.hashCode() : 0) + (name != null ? name.hashCode() : 0);
     }
 
     /** {@inheritDoc} */
@@ -75,7 +61,7 @@ public class QueryIndexKey implements Serializable {
 
         QueryIndexKey other = (QueryIndexKey)o;
 
-        return F.eq(name, other.name) && F.eq(cacheName, other.cacheName);
+        return F.eq(name, other.name) && F.eq(schemaName, other.schemaName);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/40851c7f/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 71d3ad5..0291b0a 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
@@ -670,12 +670,12 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     /**
      * Add initial user index.
      *
-     * @param cacheName Cache name.
+     * @param schemaName Schema name.
      * @param desc Table descriptor.
      * @param h2Idx User index.
      * @throws IgniteCheckedException If failed.
      */
-    private void addInitialUserIndex(String cacheName, H2TableDescriptor desc, GridH2IndexBase h2Idx)
+    private void addInitialUserIndex(String schemaName, H2TableDescriptor desc, GridH2IndexBase h2Idx)
         throws IgniteCheckedException {
         GridH2Table h2Tbl = desc.table();
 
@@ -684,7 +684,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         try {
             String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, false);
 
-            executeSql(cacheName, sql);
+            executeSql(schemaName, sql);
         }
         catch (Exception e) {
             // Rollback and re-throw.
@@ -695,12 +695,10 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /** {@inheritDoc} */
-    @Override public void dynamicIndexCreate(final String cacheName, final String tblName,
+    @Override public void dynamicIndexCreate(final String schemaName, final String tblName,
         final QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor)
         throws IgniteCheckedException {
         // Locate table.
-        String schemaName = schema(cacheName);
-
         H2Schema schema = schemas.get(schemaName);
 
         H2TableDescriptor desc = (schema != null ? schema.tableByName(tblName) : null);
@@ -740,7 +738,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             // prepared statements are re-built.
             String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, ifNotExists);
 
-            executeSql(cacheName, sql);
+            executeSql(schemaName, sql);
         }
         catch (Exception e) {
             // Rollback and re-throw.
@@ -752,25 +750,23 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
     /** {@inheritDoc} */
     @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
-    @Override public void dynamicIndexDrop(final String cacheName, String idxName, boolean ifExists)
+    @Override public void dynamicIndexDrop(final String schemaName, String idxName, boolean ifExists)
         throws IgniteCheckedException{
-        String schemaName = schema(cacheName);
-
         String sql = H2Utils.indexDropSql(schemaName, idxName, ifExists);
 
-        executeSql(cacheName, sql);
+        executeSql(schemaName, sql);
     }
 
     /**
      * Execute DDL command.
      *
-     * @param cacheName Cache name.
+     * @param schemaName Schema name.
      * @param sql SQL.
      * @throws IgniteCheckedException If failed.
      */
-    private void executeSql(String cacheName, String sql) throws IgniteCheckedException {
+    private void executeSql(String schemaName, String sql) throws IgniteCheckedException {
         try {
-            Connection conn = connectionForCache(cacheName);
+            Connection conn = connectionForSchema(schemaName);
 
             try (PreparedStatement stmt = prepareStatement(conn, sql, false)) {
                 stmt.execute();
@@ -1609,7 +1605,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         try {
             Connection conn = connectionForThread(schemaName);
 
-            createTable(cacheName, schema, tbl, conn);
+            createTable(schemaName, schema, tbl, conn);
 
             schema.add(tbl);
         }
@@ -1653,14 +1649,14 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     /**
      * Create db table by using given table descriptor.
      *
-     * @param cacheName Cache name.
+     * @param schemaName Schema name.
      * @param schema Schema.
      * @param tbl Table descriptor.
      * @param conn Connection.
      * @throws SQLException If failed to create db table.
      * @throws IgniteCheckedException If failed.
      */
-    private void createTable(String cacheName, H2Schema schema, H2TableDescriptor tbl, Connection conn)
+    private void createTable(String schemaName, H2Schema schema, H2TableDescriptor tbl, Connection conn)
         throws SQLException, IgniteCheckedException {
         assert schema != null;
         assert tbl != null;
@@ -1693,7 +1689,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         GridH2Table h2Tbl = H2TableEngine.createTable(conn, sql.toString(), rowDesc, rowFactory, tbl);
 
         for (GridH2IndexBase usrIdx : tbl.createUserIndexes())
-            addInitialUserIndex(cacheName, tbl, usrIdx);
+            addInitialUserIndex(schemaName, tbl, usrIdx);
 
         if (dataTables.putIfAbsent(h2Tbl.identifier(), h2Tbl) != null)
             throw new IllegalStateException("Table already exists: " + h2Tbl.identifierString());

http://git-wip-us.apache.org/repos/asf/ignite/blob/40851c7f/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
index 7157d1f..e324ed9 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
@@ -88,34 +88,34 @@ public class DdlStatementsProcessor {
         throws IgniteCheckedException {
         assert stmt instanceof JdbcPreparedStatement;
 
-        IgniteInternalFuture fut;
+        IgniteInternalFuture fut = null;
 
         try {
-            GridSqlStatement gridStmt = new GridSqlQueryParser(false).parse(GridSqlQueryParser.prepared(stmt));
+            GridSqlStatement stmt0 = new GridSqlQueryParser(false).parse(GridSqlQueryParser.prepared(stmt));
 
-            if (gridStmt instanceof GridSqlCreateIndex) {
-                GridSqlCreateIndex createIdx = (GridSqlCreateIndex)gridStmt;
+            if (stmt0 instanceof GridSqlCreateIndex) {
+                GridSqlCreateIndex cmd = (GridSqlCreateIndex)stmt0;
 
                 QueryIndex newIdx = new QueryIndex();
 
-                newIdx.setName(createIdx.index().getName());
+                newIdx.setName(cmd.index().getName());
 
-                newIdx.setIndexType(createIdx.index().getIndexType());
+                newIdx.setIndexType(cmd.index().getIndexType());
 
                 LinkedHashMap<String, Boolean> flds = new LinkedHashMap<>();
 
-                GridH2Table tbl = idx.dataTable(createIdx.schemaName(), createIdx.tableName());
+                GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
 
                 if (tbl == null)
                     throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND,
-                        createIdx.tableName());
+                        cmd.tableName());
 
                 assert tbl.rowDescriptor() != null;
 
                 // Let's replace H2's table and property names by those operated by GridQueryProcessor.
                 GridQueryTypeDescriptor typeDesc = tbl.rowDescriptor().type();
 
-                for (Map.Entry<String, Boolean> e : createIdx.index().getFields().entrySet()) {
+                for (Map.Entry<String, Boolean> e : cmd.index().getFields().entrySet()) {
                     GridQueryProperty prop = typeDesc.property(e.getKey());
 
                     if (prop == null)
@@ -126,39 +126,51 @@ public class DdlStatementsProcessor {
 
                 newIdx.setFields(flds);
 
-                fut = ctx.query().dynamicIndexCreate(tbl.cacheName(), createIdx.schemaName(), typeDesc.tableName(),
-                    newIdx, createIdx.ifNotExists());
+                fut = ctx.query().dynamicIndexCreate(tbl.cacheName(), cmd.schemaName(), typeDesc.tableName(),
+                    newIdx, cmd.ifNotExists());
             }
-            else if (gridStmt instanceof GridSqlDropIndex) {
-                GridSqlDropIndex dropIdx = (GridSqlDropIndex)gridStmt;
+            else if (stmt0 instanceof GridSqlDropIndex) {
+                GridSqlDropIndex cmd = (GridSqlDropIndex)stmt0;
 
-                GridH2Table tbl = idx.dataTableForIndex(dropIdx.schemaName(), dropIdx.indexName());
+                GridH2Table tbl = idx.dataTableForIndex(cmd.schemaName(), cmd.indexName());
 
                 if (tbl != null)
-                    fut = ctx.query().dynamicIndexDrop(tbl.cacheName(), dropIdx.schemaName(), dropIdx.indexName(),
-                        dropIdx.ifExists());
+                    fut = ctx.query().dynamicIndexDrop(tbl.cacheName(), cmd.schemaName(), cmd.indexName(),
+                        cmd.ifExists());
                 else {
-                    if (dropIdx.ifExists())
+                    if (cmd.ifExists())
                         fut = new GridFinishedFuture();
                     else
                         throw new SchemaOperationException(SchemaOperationException.CODE_INDEX_NOT_FOUND,
-                            dropIdx.indexName());
+                            cmd.indexName());
                 }
             }
-            else if (gridStmt instanceof GridSqlCreateTable) {
-                GridSqlCreateTable createTbl = (GridSqlCreateTable)gridStmt;
+            else if (stmt0 instanceof GridSqlCreateTable) {
+                GridSqlCreateTable cmd = (GridSqlCreateTable)stmt0;
 
-                ctx.query().dynamicTableCreate(createTbl.schemaName(), toQueryEntity(createTbl),
-                    createTbl.templateCacheName(), createTbl.ifNotExists());
+                GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
 
-                fut = null;
+                if (tbl != null) {
+                    if (!cmd.ifNotExists())
+                        throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_EXISTS,
+                            cmd.tableName());
+                }
+                else
+                    ctx.query().dynamicTableCreate(cmd.schemaName(), toQueryEntity(cmd), cmd.templateCacheName(),
+                        cmd.ifNotExists());
             }
-            else if (gridStmt instanceof GridSqlDropTable) {
-                GridSqlDropTable dropTbl = (GridSqlDropTable)gridStmt;
+            else if (stmt0 instanceof GridSqlDropTable) {
+                GridSqlDropTable cmd = (GridSqlDropTable)stmt0;
 
-                ctx.query().dynamicTableDrop(dropTbl.schemaName(), dropTbl.tableName(), dropTbl.ifExists());
+                GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
 
-                fut = null;
+                if (tbl == null) {
+                    if (!cmd.ifExists())
+                        throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND,
+                            cmd.tableName());
+                }
+                else
+                    ctx.query().dynamicTableDrop(tbl.cacheName(), cmd.tableName(), cmd.ifExists());
             }
             else
                 throw new IgniteSQLException("Unsupported DDL operation: " + sql,

http://git-wip-us.apache.org/repos/asf/ignite/blob/40851c7f/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java
----------------------------------------------------------------------
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 5d93c12..9936a81 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
@@ -1043,20 +1043,20 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde
      */
     private static class BlockingIndexing extends IgniteH2Indexing {
         /** {@inheritDoc} */
-        @Override public void dynamicIndexCreate(@NotNull String cacheName, String tblName,
+        @Override public void dynamicIndexCreate(@NotNull String schemaName, String tblName,
             QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor)
             throws IgniteCheckedException {
             awaitIndexing(ctx.localNodeId());
 
-            super.dynamicIndexCreate(cacheName, tblName, idxDesc, ifNotExists, cacheVisitor);
+            super.dynamicIndexCreate(schemaName, tblName, idxDesc, ifNotExists, cacheVisitor);
         }
 
         /** {@inheritDoc} */
-        @Override public void dynamicIndexDrop(@NotNull String cacheName, String idxName, boolean ifExists)
+        @Override public void dynamicIndexDrop(@NotNull String schemaName, String idxName, boolean ifExists)
             throws IgniteCheckedException{
             awaitIndexing(ctx.localNodeId());
 
-            super.dynamicIndexDrop(cacheName, idxName, ifExists);
+            super.dynamicIndexDrop(schemaName, idxName, ifExists);
         }
     }
 }


[20/22] ignite git commit: Merge remote-tracking branch 'remotes/origin/master' into ignite-5075

Posted by sb...@apache.org.
Merge remote-tracking branch 'remotes/origin/master' into ignite-5075

# Conflicts:
#	modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
#	modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
#	modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java


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

Branch: refs/heads/ignite-5075
Commit: 9284f8050fd8f83e496f874c144cc0b326da1f0e
Parents: 3733f6a 42293fa
Author: sboikov <sb...@gridgain.com>
Authored: Mon May 29 16:47:26 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon May 29 16:47:26 2017 +0300

----------------------------------------------------------------------
 .../datagrid/CacheClientBinaryQueryExample.java |   4 +-
 .../internal/jdbc2/JdbcNoDefaultCacheTest.java  |   2 -
 .../cache/affinity/AffinityKeyMapper.java       |   3 +
 .../configuration/CacheConfiguration.java       |  11 +
 .../ignite/internal/GridKernalContext.java      |   1 +
 .../ignite/internal/GridKernalContextImpl.java  |   1 +
 .../internal/binary/BinaryEnumObjectImpl.java   |  11 +-
 .../internal/binary/BinaryObjectImpl.java       |  24 +-
 .../binary/BinaryObjectOffheapImpl.java         |   9 +-
 .../internal/processors/cache/CacheObject.java  |   8 +-
 .../processors/cache/CacheObjectAdapter.java    |   4 +-
 .../cache/CacheObjectByteArrayImpl.java         |   8 +-
 .../processors/cache/CacheObjectContext.java    | 197 +----
 .../processors/cache/CacheObjectImpl.java       |  31 +-
 .../processors/cache/CacheObjectUtils.java      | 173 +++++
 .../cache/CacheObjectValueContext.java          |  50 ++
 .../processors/cache/ClusterCachesInfo.java     |   9 +-
 .../processors/cache/GridCacheContext.java      |  12 +-
 .../processors/cache/GridCacheEventManager.java |   2 +-
 .../processors/cache/GridCacheIoManager.java    |   6 +-
 .../processors/cache/GridCacheMapEntry.java     |   7 +-
 .../GridCachePartitionExchangeManager.java      |   2 +-
 .../processors/cache/GridCacheProcessor.java    |  16 +-
 .../processors/cache/KeyCacheObjectImpl.java    |  10 +-
 .../cache/binary/CacheObjectBinaryContext.java  |   6 +-
 .../binary/CacheObjectBinaryProcessorImpl.java  |  28 +-
 .../cache/database/CacheDataRowAdapter.java     |   8 +-
 .../dht/GridClientPartitionTopology.java        |  31 +-
 .../dht/GridDhtPartitionTopology.java           |   9 +-
 .../dht/GridDhtPartitionTopologyImpl.java       |  59 +-
 .../GridDhtPartitionsExchangeFuture.java        |  50 +-
 .../cache/distributed/near/GridNearTxLocal.java |   3 +-
 .../cache/query/GridCacheQueryRequest.java      |  14 +-
 .../CacheContinuousQueryAcknowledgeBuffer.java  | 120 +++
 .../CacheContinuousQueryDeployableObject.java   | 110 +++
 .../continuous/CacheContinuousQueryEntry.java   | 117 ++-
 .../CacheContinuousQueryEventBuffer.java        | 483 ++++++++++++
 .../continuous/CacheContinuousQueryHandler.java | 733 +++----------------
 .../CacheContinuousQueryHandlerV2.java          |   6 +-
 .../continuous/CacheContinuousQueryManager.java |  16 +-
 .../CacheContinuousQueryPartitionRecovery.java  | 267 +++++++
 .../cache/transactions/TxDeadlock.java          |   7 +-
 .../cacheobject/IgniteCacheObjectProcessor.java |   6 +-
 .../IgniteCacheObjectProcessorImpl.java         |  39 +-
 .../continuous/GridContinuousBatchAdapter.java  |   2 +-
 .../continuous/GridContinuousProcessor.java     |  19 +-
 .../continuous/GridContinuousQueryBatch.java    |  16 +-
 .../query/CacheQueryObjectValueContext.java     |  64 ++
 .../query/GridQueryCacheObjectsIterator.java    |  16 +-
 .../processors/query/GridQueryIndexing.java     |  18 +-
 .../processors/query/GridQueryProcessor.java    |  80 +-
 .../query/GridQueryTypeDescriptor.java          |  15 +
 .../processors/query/GridRunningQueryInfo.java  |  16 +-
 .../processors/query/QueryIndexKey.java         |  28 +-
 .../internal/processors/query/QuerySchema.java  |   2 +-
 .../query/QueryTypeDescriptorImpl.java          |   9 +
 .../internal/processors/query/QueryUtils.java   | 268 +++++--
 .../query/property/QueryBinaryProperty.java     |   2 +-
 .../query/VisorRunningQueriesCollectorTask.java |   2 +-
 .../internal/GridAffinityNoCacheSelfTest.java   |  10 +-
 .../IgniteIncompleteCacheObjectSelfTest.java    |  10 +-
 .../BinaryAtomicCacheLocalEntriesSelfTest.java  |  30 +
 .../BinaryTxCacheLocalEntriesSelfTest.java      |  84 +++
 .../BinaryAtomicCacheLocalEntriesSelfTest.java  |  30 -
 .../BinaryTxCacheLocalEntriesSelfTest.java      |  84 ---
 ...tinuousQueryAsyncFailoverAtomicSelfTest.java |   1 -
 ...nuousQueryConcurrentPartitionUpdateTest.java | 304 ++++++++
 .../CacheContinuousQueryEventBufferTest.java    | 217 ++++++
 ...ContinuousQueryFailoverAbstractSelfTest.java |  79 +-
 ...niteCacheContinuousQueryBackupQueueTest.java |  13 +-
 ...eCacheContinuousQueryImmutableEntryTest.java |   6 +-
 .../database/FreeListImplSelfTest.java          |  10 +-
 .../IgniteBinaryObjectsTestSuite.java           |   4 +-
 .../query/h2/H2IndexingAbstractGeoSelfTest.java |  26 +-
 .../query/h2/H2IndexingBinaryGeoSelfTest.java   |  30 -
 .../H2IndexingBinarySegmentedGeoSelfTest.java   |  30 -
 .../query/h2/H2IndexingGeoSelfTest.java         |   2 +-
 .../h2/H2IndexingSegmentedGeoSelfTest.java      |   2 +-
 .../testsuites/GeoSpatialIndexingTestSuite.java |   5 -
 .../query/h2/DmlStatementsProcessor.java        |  32 +-
 .../processors/query/h2/H2DmlPlanKey.java       |  66 ++
 .../query/h2/H2ResultSetIterator.java           |   4 +-
 .../processors/query/h2/H2RowDescriptor.java    |  27 +-
 .../internal/processors/query/h2/H2Schema.java  |  46 +-
 .../processors/query/h2/H2TableDescriptor.java  |  52 +-
 .../processors/query/h2/H2TableEngine.java      |   2 +-
 .../query/h2/H2TwoStepCachedQuery.java          |  18 +-
 .../query/h2/H2TwoStepCachedQueryKey.java       |  19 +-
 .../internal/processors/query/h2/H2Utils.java   |  79 +-
 .../processors/query/h2/IgniteH2Indexing.java   | 201 ++---
 .../query/h2/ddl/DdlStatementsProcessor.java    |  66 +-
 .../processors/query/h2/opt/GridH2Table.java    |   6 +-
 .../query/h2/opt/GridH2ValueCacheObject.java    |  32 +-
 .../query/h2/opt/GridLuceneIndex.java           |   2 +-
 .../query/h2/twostep/GridMapQueryExecutor.java  |  20 +-
 .../h2/twostep/GridReduceQueryExecutor.java     | 167 ++---
 .../query/h2/twostep/ReduceQueryRun.java        | 157 ++++
 .../query/h2/twostep/msg/GridH2CacheObject.java |  39 +-
 .../IgniteCacheInsertSqlQuerySelfTest.java      |  27 +-
 .../cache/index/AbstractSchemaSelfTest.java     | 123 +++-
 .../DynamicIndexAbstractBasicSelfTest.java      |  77 +-
 .../DynamicIndexAbstractConcurrentSelfTest.java |  36 +-
 .../index/DynamicIndexAbstractSelfTest.java     |  30 +-
 .../index/H2DynamicIndexAbstractSelfTest.java   |  48 +-
 .../cache/index/SchemaExchangeSelfTest.java     |  13 +-
 .../query/IgniteSqlSchemaIndexingTest.java      |   4 +-
 .../query/IgniteSqlSplitterSelfTest.java        |  61 +-
 .../h2/GridIndexingSpiAbstractSelfTest.java     |  19 +-
 .../query/h2/sql/BaseH2CompareQueryTest.java    |  12 +-
 .../query/h2/sql/GridQueryParsingTest.java      |   4 +-
 .../query/h2/sql/H2CompareBigQueryTest.java     |   2 +-
 .../IgniteCacheQuerySelfTestSuite3.java         |   5 +
 .../processors/query/h2/sql/bigQuery.sql        |   8 +-
 .../Apache.Ignite.Core.Tests.csproj             |   1 +
 .../Cache/CacheConfigurationTest.cs             |   6 +-
 .../Cache/Query/CacheLinqTest.cs                | 131 +++-
 .../Cache/Query/CacheLinqTestSqlEscapeAll.cs    |  34 +
 .../Apache.Ignite.Core.csproj                   |   1 +
 .../Cache/Configuration/QueryEntity.cs          |  64 +-
 .../Impl/Cache/IQueryEntityInternal.cs          |  31 +
 .../Impl/CacheFieldsQueryProvider.cs            |   9 +
 .../Impl/CacheQueryExpressionVisitor.cs         |  76 +-
 .../Apache.Ignite.Linq/Impl/ExpressionWalker.cs |   7 +-
 modules/web-console/frontend/.babelrc           |   9 +-
 modules/web-console/frontend/.gitignore         |   1 -
 modules/web-console/frontend/app/app.js         |  18 +-
 .../components/web-console-header/component.js  |   6 +-
 .../app/modules/agent/AgentManager.service.js   |   2 -
 .../frontend/gulpfile.babel.js/index.js         |  26 -
 .../frontend/gulpfile.babel.js/paths.js         |  64 --
 .../frontend/gulpfile.babel.js/tasks/build.js   |  21 -
 .../frontend/gulpfile.babel.js/tasks/bundle.js  |  36 -
 .../frontend/gulpfile.babel.js/tasks/clean.js   |  32 -
 .../frontend/gulpfile.babel.js/tasks/copy.js    |  33 -
 .../gulpfile.babel.js/tasks/ignite-modules.js   |  55 --
 .../frontend/gulpfile.babel.js/tasks/watch.js   |  30 -
 .../gulpfile.babel.js/webpack/common.js         | 205 ------
 .../webpack/environments/development.js         |  60 --
 .../webpack/environments/production.js          |  41 --
 .../webpack/environments/test.js                |  44 --
 .../frontend/gulpfile.babel.js/webpack/index.js |  36 -
 .../frontend/ignite_modules/index.js            |   7 +-
 modules/web-console/frontend/package.json       | 104 ++-
 .../frontend/test/karma.conf.babel.js           |  13 +-
 modules/web-console/frontend/test/karma.conf.js |   2 +-
 .../frontend/webpack/webpack.common.js          | 188 +++++
 .../frontend/webpack/webpack.dev.babel.js       | 100 +++
 .../frontend/webpack/webpack.prod.babel.js      |  64 ++
 .../frontend/webpack/webpack.test.js            |  33 +
 149 files changed, 4387 insertions(+), 2954 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
index 25f70da,c372037..287a30d
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
@@@ -820,10 -717,13 +820,15 @@@ class ClusterCachesInfo 
                      desc = desc0;
                  }
  
 -                if (locCfg != null || joinDiscoData.startCaches() || CU.affinityNode(ctx.discovery().localNode(), cfg.getNodeFilter())) {
 +                if (locCfg != null ||
 +                    joinDiscoData.startCaches() ||
-                     CU.affinityNode(ctx.discovery().localNode(), desc.groupDescriptor().config().getNodeFilter()))
-                     locJoinStartCaches.add(new T2<>(desc, nearCfg));
++                    CU.affinityNode(ctx.discovery().localNode(), desc.groupDescriptor().config().getNodeFilter())) {
+                     // Move system and internal caches first.
+                     if (desc.cacheType().userCache())
+                         locJoinStartCaches.add(new T2<>(desc, nearCfg));
+                     else
+                         locJoinStartCaches.add(0, new T2<>(desc, nearCfg));
+                 }
              }
          }
      }

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
index 96ae0b9,2eec8f6..5c466f4
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
@@@ -1300,15 -1306,15 +1300,15 @@@ public class GridCachePartitionExchange
  
                      GridDhtPartitionTopology top = null;
  
 -                    if (cacheCtx == null)
 -                        top = clientTops.get(cacheId);
 -                    else if (!cacheCtx.isLocal())
 -                        top = cacheCtx.topology();
 +                    if (grp == null)
 +                        top = clientTops.get(grpId);
 +                    else if (!grp.isLocal())
 +                        top = grp.topology();
  
                      if (top != null) {
-                         updated |= top.update(null, entry.getValue(), null) != null;
+                         updated |= top.update(null, entry.getValue()) != null;
  
 -                        cctx.affinity().checkRebalanceState(top, cacheId);
 +                        cctx.affinity().checkRebalanceState(top, grpId);
                      }
                  }
  

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
index 6725773,72c5bbc..bc6f8c7
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
@@@ -55,11 -55,10 +55,11 @@@ import org.apache.ignite.internal.pagem
  import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
  import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache;
  import org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage;
 +import org.apache.ignite.internal.processors.cache.CacheGroupInfrastructure;
  import org.apache.ignite.internal.processors.cache.CacheInvalidStateException;
+ import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask;
  import org.apache.ignite.internal.processors.cache.ClusterState;
  import org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch;
- import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask;
  import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
  import org.apache.ignite.internal.processors.cache.ExchangeActions;
  import org.apache.ignite.internal.processors.cache.GridCacheContext;
@@@ -1138,9 -1111,21 +1145,21 @@@ public class GridDhtPartitionsExchangeF
      @Override public boolean onDone(@Nullable AffinityTopologyVersion res, @Nullable Throwable err) {
          boolean realExchange = !dummy && !forcePreload;
  
+         if (err == null &&
+             realExchange &&
+             !cctx.kernalContext().clientNode() &&
+             (serverNodeDiscoveryEvent() || affChangeMsg != null)) {
+             for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
+                 if (!cacheCtx.affinityNode() || cacheCtx.isLocal())
+                     continue;
+ 
+                 cacheCtx.continuousQueries().flushBackupQueue(exchId.topologyVersion());
+             }
+        }
+ 
          if (err == null && realExchange) {
 -            for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
 -                if (cacheCtx.isLocal())
 +            for (CacheGroupInfrastructure grp : cctx.cache().cacheGroups()) {
 +                if (grp.isLocal())
                      continue;
  
                  try {
@@@ -1824,13 -1816,13 +1862,13 @@@
          msgs.put(node.id(), msg);
  
          for (Map.Entry<Integer, GridDhtPartitionMap> entry : msg.partitions().entrySet()) {
 -            Integer cacheId = entry.getKey();
 -            GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
 +            Integer grpId = entry.getKey();
 +            CacheGroupInfrastructure grp = cctx.cache().cacheGroup(grpId);
  
 -            GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() :
 -                cctx.exchange().clientTopology(cacheId, this);
 +            GridDhtPartitionTopology top = grp != null ? grp.topology() :
 +                cctx.exchange().clientTopology(grpId, this);
  
-             top.update(exchId, entry.getValue(), msg.partitionUpdateCounters(grpId));
+             top.update(exchId, entry.getValue());
          }
      }
  

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
index bc75858,c327820..569200d
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
@@@ -17,18 -17,8 +17,19 @@@
  
  package org.apache.ignite.internal.processors.query;
  
 +import java.lang.reflect.Method;
 +import java.math.BigDecimal;
 +import java.sql.Time;
 +import java.sql.Timestamp;
 +import java.util.Collection;
 +import java.util.HashSet;
 +import java.util.List;
 +import java.util.Map;
 +import java.util.Set;
 +import java.util.UUID;
 +import java.util.concurrent.TimeUnit;
  import org.apache.ignite.IgniteCheckedException;
+ import org.apache.ignite.IgniteException;
  import org.apache.ignite.cache.QueryEntity;
  import org.apache.ignite.cache.QueryIndex;
  import org.apache.ignite.cache.QueryIndexType;
@@@ -59,14 -63,15 +60,14 @@@ import static org.apache.ignite.IgniteS
   * Utility methods for queries.
   */
  public class QueryUtils {
 -
      /** Field name for key. */
-     public static final String KEY_FIELD_NAME = "_key";
+     public static final String KEY_FIELD_NAME = "_KEY";
  
      /** Field name for value. */
-     public static final String VAL_FIELD_NAME = "_val";
+     public static final String VAL_FIELD_NAME = "_VAL";
  
      /** Version field name. */
-     public static final String VER_FIELD_NAME = "_ver";
+     public static final String VER_FIELD_NAME = "_VER";
  
      /** Discovery history size. */
      private static final int DISCO_HIST_SIZE = getInteger(IGNITE_INDEXING_DISCOVERY_HISTORY_SIZE, 1000);

http://git-wip-us.apache.org/repos/asf/ignite/blob/9284f805/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
----------------------------------------------------------------------


[06/22] ignite git commit: IGNITE-5312: Changed cache name to schema name in H2TwoStepCachedQueryKey. This closes #2020.

Posted by sb...@apache.org.
IGNITE-5312: Changed cache name to schema name in H2TwoStepCachedQueryKey. This closes #2020.


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

Branch: refs/heads/ignite-5075
Commit: 858e5b729b621efef057c1919273463ebdcb133d
Parents: e59d389
Author: devozerov <vo...@gridgain.com>
Authored: Sat May 27 21:07:54 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Sat May 27 21:07:54 2017 +0300

----------------------------------------------------------------------
 .../query/h2/H2TwoStepCachedQuery.java           | 18 ++++++++++++++++--
 .../query/h2/H2TwoStepCachedQueryKey.java        | 19 ++++++-------------
 .../processors/query/h2/IgniteH2Indexing.java    | 19 +++++++++++--------
 3 files changed, 33 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/858e5b72/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TwoStepCachedQuery.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TwoStepCachedQuery.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TwoStepCachedQuery.java
index dd1b44c..6139869 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TwoStepCachedQuery.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TwoStepCachedQuery.java
@@ -28,10 +28,10 @@ import java.util.List;
  */
 public class H2TwoStepCachedQuery {
     /** */
-    final List<GridQueryFieldMetadata> meta;
+    private final List<GridQueryFieldMetadata> meta;
 
     /** */
-    final GridCacheTwoStepQuery twoStepQry;
+    private final GridCacheTwoStepQuery twoStepQry;
 
     /**
      * @param meta Fields metadata.
@@ -42,6 +42,20 @@ public class H2TwoStepCachedQuery {
         this.twoStepQry = twoStepQry;
     }
 
+    /**
+     * @return Fields metadata.
+     */
+    public List<GridQueryFieldMetadata> meta() {
+        return meta;
+    }
+
+    /**
+     * @return Query.
+     */
+    public GridCacheTwoStepQuery query() {
+        return twoStepQry;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(H2TwoStepCachedQuery.class, this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/858e5b72/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TwoStepCachedQueryKey.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TwoStepCachedQueryKey.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TwoStepCachedQueryKey.java
index 1452a83..cc14abd 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TwoStepCachedQueryKey.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TwoStepCachedQueryKey.java
@@ -22,7 +22,7 @@ package org.apache.ignite.internal.processors.query.h2;
  */
 public class H2TwoStepCachedQueryKey {
     /** */
-    private final String cacheName;
+    private final String schemaName;
 
     /** */
     private final String sql;
@@ -40,20 +40,20 @@ public class H2TwoStepCachedQueryKey {
     private final boolean isLocal;
 
     /**
-     * @param cacheName Cache name.
+     * @param schemaName Schema name.
      * @param sql Sql.
      * @param grpByCollocated Collocated GROUP BY.
      * @param distributedJoins Distributed joins enabled.
      * @param enforceJoinOrder Enforce join order of tables.
      * @param isLocal Query is local flag.
      */
-    H2TwoStepCachedQueryKey(String cacheName,
+    H2TwoStepCachedQueryKey(String schemaName,
         String sql,
         boolean grpByCollocated,
         boolean distributedJoins,
         boolean enforceJoinOrder,
         boolean isLocal) {
-        this.cacheName = cacheName;
+        this.schemaName = schemaName;
         this.sql = sql;
         this.grpByCollocated = grpByCollocated;
         this.distributedJoins = distributedJoins;
@@ -61,13 +61,6 @@ public class H2TwoStepCachedQueryKey {
         this.isLocal = isLocal;
     }
 
-    /**
-     * @return Cache name.
-     */
-    public String cacheName() {
-        return cacheName;
-    }
-
     /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)
@@ -87,7 +80,7 @@ public class H2TwoStepCachedQueryKey {
         if (enforceJoinOrder != that.enforceJoinOrder)
             return false;
 
-        if (cacheName != null ? !cacheName.equals(that.cacheName) : that.cacheName != null)
+        if (schemaName != null ? !schemaName.equals(that.schemaName) : that.schemaName != null)
             return false;
 
         return isLocal == that.isLocal && sql.equals(that.sql);
@@ -95,7 +88,7 @@ public class H2TwoStepCachedQueryKey {
 
     /** {@inheritDoc} */
     @Override public int hashCode() {
-        int res = cacheName != null ? cacheName.hashCode() : 0;
+        int res = schemaName != null ? schemaName.hashCode() : 0;
         res = 31 * res + sql.hashCode();
         res = 31 * res + (grpByCollocated ? 1 : 0);
         res = res + (distributedJoins ? 2 : 0);

http://git-wip-us.apache.org/repos/asf/ignite/blob/858e5b72/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 0291b0a..c94c215 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
@@ -1324,12 +1324,11 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     /** {@inheritDoc} */
     @Override public FieldsQueryCursor<List<?>> queryDistributedSqlFields(GridCacheContext<?, ?> cctx,
         SqlFieldsQuery qry, boolean keepBinary, GridQueryCancel cancel) {
-        final String cacheName = cctx.name();
         final String sqlQry = qry.getSql();
 
-        String schema = schema(cctx.name());
+        String schemaName = schema(cctx.name());
 
-        Connection c = connectionForSchema(schema);
+        Connection c = connectionForSchema(schemaName);
 
         final boolean enforceJoinOrder = qry.isEnforceJoinOrder();
         final boolean distributedJoins = qry.isDistributedJoins();
@@ -1340,13 +1339,13 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         GridCacheTwoStepQuery twoStepQry = null;
         List<GridQueryFieldMetadata> meta;
 
-        final H2TwoStepCachedQueryKey cachedQryKey = new H2TwoStepCachedQueryKey(cacheName, sqlQry, grpByCollocated,
+        final H2TwoStepCachedQueryKey cachedQryKey = new H2TwoStepCachedQueryKey(schemaName, sqlQry, grpByCollocated,
             distributedJoins, enforceJoinOrder, qry.isLocal());
         H2TwoStepCachedQuery cachedQry = twoStepCache.get(cachedQryKey);
 
         if (cachedQry != null) {
-            twoStepQry = cachedQry.twoStepQry.copy();
-            meta = cachedQry.meta;
+            twoStepQry = cachedQry.query().copy();
+            meta = cachedQry.meta();
         }
         else {
             final UUID locNodeId = ctx.localNodeId();
@@ -1415,7 +1414,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 if (twoStepQry == null) {
                     if (DmlStatementsProcessor.isDmlStatement(prepared)) {
                         try {
-                            return dmlProc.updateSqlFieldsDistributed(schema, stmt, qry, cancel);
+                            return dmlProc.updateSqlFieldsDistributed(schemaName, stmt, qry, cancel);
                         }
                         catch (IgniteCheckedException e) {
                             throw new IgniteSQLException("Failed to execute DML statement [stmt=" + sqlQry +
@@ -2249,11 +2248,15 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 for (Index idx : tblDesc.table().getIndexes())
                     idx.close(null);
 
+            int cacheId = CU.cacheId(cacheName);
+
             for (Iterator<Map.Entry<H2TwoStepCachedQueryKey, H2TwoStepCachedQuery>> it =
                 twoStepCache.entrySet().iterator(); it.hasNext();) {
                 Map.Entry<H2TwoStepCachedQueryKey, H2TwoStepCachedQuery> e = it.next();
 
-                if (F.eq(e.getKey().cacheName(), cacheName))
+                GridCacheTwoStepQuery qry = e.getValue().query();
+
+                if (!F.isEmpty(qry.cacheIds()) && qry.cacheIds().contains(cacheId))
                     it.remove();
             }
         }


[13/22] ignite git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/ignite

Posted by sb...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/ignite


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

Branch: refs/heads/ignite-5075
Commit: 172419b30b3e5523f426239c0d521c82639dfe3d
Parents: c68c146 88fd1a6
Author: Sergi Vladykin <se...@gmail.com>
Authored: Mon May 29 09:42:12 2017 +0300
Committer: Sergi Vladykin <se...@gmail.com>
Committed: Mon May 29 09:42:12 2017 +0300

----------------------------------------------------------------------
 modules/web-console/frontend/.babelrc           |   9 +-
 modules/web-console/frontend/.gitignore         |   1 -
 modules/web-console/frontend/app/app.js         |  18 +-
 .../components/web-console-header/component.js  |   6 +-
 .../app/modules/agent/AgentManager.service.js   |   2 -
 .../frontend/gulpfile.babel.js/index.js         |  26 ---
 .../frontend/gulpfile.babel.js/paths.js         |  64 ------
 .../frontend/gulpfile.babel.js/tasks/build.js   |  21 --
 .../frontend/gulpfile.babel.js/tasks/bundle.js  |  36 ----
 .../frontend/gulpfile.babel.js/tasks/clean.js   |  32 ---
 .../frontend/gulpfile.babel.js/tasks/copy.js    |  33 ---
 .../gulpfile.babel.js/tasks/ignite-modules.js   |  55 -----
 .../frontend/gulpfile.babel.js/tasks/watch.js   |  30 ---
 .../gulpfile.babel.js/webpack/common.js         | 205 -------------------
 .../webpack/environments/development.js         |  60 ------
 .../webpack/environments/production.js          |  41 ----
 .../webpack/environments/test.js                |  44 ----
 .../frontend/gulpfile.babel.js/webpack/index.js |  36 ----
 .../frontend/ignite_modules/index.js            |   7 +-
 modules/web-console/frontend/package.json       | 104 ++++------
 .../frontend/test/karma.conf.babel.js           |  13 +-
 modules/web-console/frontend/test/karma.conf.js |   2 +-
 .../frontend/webpack/webpack.common.js          | 188 +++++++++++++++++
 .../frontend/webpack/webpack.dev.babel.js       | 100 +++++++++
 .../frontend/webpack/webpack.prod.babel.js      |  64 ++++++
 .../frontend/webpack/webpack.test.js            |  33 +++
 26 files changed, 449 insertions(+), 781 deletions(-)
----------------------------------------------------------------------



[14/22] ignite git commit: Start internal caches first

Posted by sb...@apache.org.
Start internal caches first


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

Branch: refs/heads/ignite-5075
Commit: e0b2053e663c76a17b262940cef33399d30ec824
Parents: 172419b
Author: Константин Дудков <kd...@ya.ru>
Authored: Mon May 29 11:03:39 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Mon May 29 11:03:39 2017 +0300

----------------------------------------------------------------------
 .../ignite/internal/processors/cache/ClusterCachesInfo.java | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e0b2053e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
index ab5cf37..c372037 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
@@ -717,8 +717,13 @@ class ClusterCachesInfo {
                     desc = desc0;
                 }
 
-                if (locCfg != null || joinDiscoData.startCaches() || CU.affinityNode(ctx.discovery().localNode(), cfg.getNodeFilter()))
-                    locJoinStartCaches.add(new T2<>(desc, nearCfg));
+                if (locCfg != null || joinDiscoData.startCaches() || CU.affinityNode(ctx.discovery().localNode(), cfg.getNodeFilter())) {
+                    // Move system and internal caches first.
+                    if (desc.cacheType().userCache())
+                        locJoinStartCaches.add(new T2<>(desc, nearCfg));
+                    else
+                        locJoinStartCaches.add(0, new T2<>(desc, nearCfg));
+                }
             }
         }
     }


[12/22] ignite git commit: master - tests for SQL schema

Posted by sb...@apache.org.
master - tests for SQL schema


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

Branch: refs/heads/ignite-5075
Commit: c68c146d1671a26efd38335f7902965d0534c0b6
Parents: 52e14ac
Author: Sergi Vladykin <se...@gmail.com>
Authored: Mon May 29 09:41:56 2017 +0300
Committer: Sergi Vladykin <se...@gmail.com>
Committed: Mon May 29 09:41:56 2017 +0300

----------------------------------------------------------------------
 .../query/IgniteSqlSplitterSelfTest.java        | 51 ++++++++++++++++++++
 1 file changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c68c146d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
index 4bb6a3a..6b984bf 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
@@ -1123,6 +1123,57 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     */
+    public void testSchemaQuoted() {
+        assert false; // TODO test hangs
+        doTestSchemaName("\"ppAf\"");
+    }
+
+    /**
+     */
+    public void testSchemaQuotedUpper() {
+        assert false; // TODO test hangs
+        doTestSchemaName("\"PPAF\"");
+    }
+
+    /**
+     */
+    public void testSchemaUnquoted() {
+        doTestSchemaName("ppAf");
+    }
+
+    /**
+     */
+    public void testSchemaUnquotedUpper() {
+        doTestSchemaName("PPAF");
+    }
+
+    /**
+     * @param schema Schema name.
+     */
+    public void doTestSchemaName(String schema) {
+        CacheConfiguration ccfg = cacheConfig("persPartAff", true, Integer.class, Person2.class);
+
+        ccfg.setSqlSchema(schema);
+
+        IgniteCache<Integer, Person2> ppAf = ignite(0).createCache(ccfg);
+
+        try {
+            ppAf.put(1, new Person2(10, "Petya"));
+            ppAf.put(2, new Person2(10, "Kolya"));
+
+            List<List<?>> res = ppAf.query(new SqlFieldsQuery("select name from " +
+                schema + ".Person2 order by _key")).getAll();
+
+            assertEquals("Petya", res.get(0).get(0));
+            assertEquals("Kolya", res.get(1).get(0));
+        }
+        finally {
+            ppAf.destroy();
+        }
+    }
+
+    /**
      * @throws Exception If failed.
      */
     public void testIndexSegmentation() throws Exception {


[21/22] ignite git commit: Merge remote-tracking branch 'remotes/origin/master' into ignite-5075

Posted by sb...@apache.org.
Merge remote-tracking branch 'remotes/origin/master' into ignite-5075

# Conflicts:
#	modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
#	modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
#	modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java


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

Branch: refs/heads/ignite-5075
Commit: 681454cf58178bd3665f4788d4a85acae4f28fcc
Parents: 9284f80
Author: sboikov <sb...@gridgain.com>
Authored: Mon May 29 16:54:14 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon May 29 16:54:14 2017 +0300

----------------------------------------------------------------------
 .../dht/preloader/GridDhtPartitionsExchangeFuture.java    | 10 +++++-----
 .../cache/query/continuous/CounterSkipContext.java        |  5 ++++-
 .../ignite/internal/processors/query/QueryUtils.java      |  2 ++
 3 files changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/681454cf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
index bc6f8c7..65a20eb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
@@ -1623,13 +1623,13 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter<AffinityT
                     GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage)msg;
 
                     for (Map.Entry<Integer, GridDhtPartitionMap> entry : msg0.partitions().entrySet()) {
-                        Integer cacheId = entry.getKey();
-                        GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
+                        Integer grpId = entry.getKey();
+                        CacheGroupInfrastructure grp = cctx.cache().cacheGroup(grpId);
 
-                        GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() :
-                            cctx.exchange().clientTopology(cacheId, this);
+                        GridDhtPartitionTopology top = grp != null ? grp.topology() :
+                            cctx.exchange().clientTopology(grpId, this);
 
-                        Map<Integer, T2<Long, Long>> cntrs = msg0.partitionUpdateCounters(cacheId);
+                        Map<Integer, T2<Long, Long>> cntrs = msg0.partitionUpdateCounters(grpId);
 
                         if (cntrs != null)
                             top.applyUpdateCounters(cntrs);

http://git-wip-us.apache.org/repos/asf/ignite/blob/681454cf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java
index 342b9d7..89ac6f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java
@@ -41,7 +41,10 @@ public class CounterSkipContext {
                 false,
                 part,
                 cntr,
-                topVer);
+                topVer,
+                (byte)0);
+
+            entry.markFiltered();
         }
 
         return entry;

http://git-wip-us.apache.org/repos/asf/ignite/blob/681454cf/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
index 569200d..4457954 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
@@ -22,7 +22,9 @@ import java.math.BigDecimal;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;


[02/22] ignite git commit: IGNITE-5287: Simplified CacheConfiguration.sqlEscapeAll handling. This closes #2004.

Posted by sb...@apache.org.
IGNITE-5287: Simplified CacheConfiguration.sqlEscapeAll handling. This closes #2004.


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

Branch: refs/heads/ignite-5075
Commit: 427ca6900209421db7693df1dbf7e15fc872c0cd
Parents: e09b5a2
Author: devozerov <vo...@gridgain.com>
Authored: Sat May 27 12:48:08 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Sat May 27 12:48:08 2017 +0300

----------------------------------------------------------------------
 .../internal/jdbc2/JdbcNoDefaultCacheTest.java  |   2 -
 .../configuration/CacheConfiguration.java       |  11 +
 .../processors/cache/GridCacheProcessor.java    |  16 +-
 .../processors/query/GridQueryIndexing.java     |   9 +-
 .../processors/query/GridQueryProcessor.java    |  21 +-
 .../query/GridQueryTypeDescriptor.java          |  15 +
 .../internal/processors/query/QuerySchema.java  |   2 +-
 .../query/QueryTypeDescriptorImpl.java          |   9 +
 .../internal/processors/query/QueryUtils.java   | 272 ++++++++++++++-----
 .../query/property/QueryBinaryProperty.java     |   2 +-
 .../query/h2/H2IndexingAbstractGeoSelfTest.java |  26 +-
 .../query/h2/H2IndexingBinaryGeoSelfTest.java   |  30 --
 .../H2IndexingBinarySegmentedGeoSelfTest.java   |  30 --
 .../query/h2/H2IndexingGeoSelfTest.java         |   2 +-
 .../h2/H2IndexingSegmentedGeoSelfTest.java      |   2 +-
 .../testsuites/GeoSpatialIndexingTestSuite.java |   5 -
 .../processors/query/h2/H2RowDescriptor.java    |   8 +-
 .../internal/processors/query/h2/H2Schema.java  |  46 +++-
 .../processors/query/h2/H2TableDescriptor.java  |  30 +-
 .../internal/processors/query/h2/H2Utils.java   |  79 +-----
 .../processors/query/h2/IgniteH2Indexing.java   |  74 ++---
 .../processors/query/h2/opt/GridH2Table.java    |   6 +-
 .../IgniteCacheInsertSqlQuerySelfTest.java      |  27 +-
 .../cache/index/AbstractSchemaSelfTest.java     | 123 +++++++--
 .../DynamicIndexAbstractBasicSelfTest.java      |  77 ++----
 .../DynamicIndexAbstractConcurrentSelfTest.java |  28 +-
 .../index/DynamicIndexAbstractSelfTest.java     |  30 +-
 .../index/H2DynamicIndexAbstractSelfTest.java   |  48 ++--
 .../cache/index/SchemaExchangeSelfTest.java     |  13 +-
 .../query/IgniteSqlSchemaIndexingTest.java      |   4 +-
 .../query/IgniteSqlSplitterSelfTest.java        |  10 +-
 .../h2/GridIndexingSpiAbstractSelfTest.java     |  10 +
 .../query/h2/sql/BaseH2CompareQueryTest.java    |  12 +-
 .../query/h2/sql/H2CompareBigQueryTest.java     |   2 +-
 .../processors/query/h2/sql/bigQuery.sql        |   8 +-
 35 files changed, 602 insertions(+), 487 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcNoDefaultCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcNoDefaultCacheTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcNoDefaultCacheTest.java
index b28f9dd..545286c 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcNoDefaultCacheTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcNoDefaultCacheTest.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.jdbc2;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.concurrent.Callable;
@@ -33,7 +32,6 @@ 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 org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.IgniteJdbcDriver.CFG_URL_PREFIX;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index 1136c71..7269086 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -1819,6 +1819,17 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
     }
 
     /**
+     * Clear query entities.
+     *
+     * @return {@code this} for chaining.
+     */
+    public CacheConfiguration<K, V> clearQueryEntities() {
+        this.qryEntities = null;
+
+        return this;
+    }
+
+    /**
      * Defines a hint to query execution engine on desired degree of parallelism within a single node.
      * Query executor may or may not use this hint depending on estimated query costs. Query executor may define
      * certain restrictions on parallelism depending on query type and/or cache type.

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index d94c41f..9a25672 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -45,6 +45,7 @@ import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cache.CacheExistsException;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.affinity.AffinityFunction;
 import org.apache.ignite.cache.affinity.AffinityFunctionContext;
 import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
@@ -297,6 +298,17 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 throw new IgniteCheckedException("Cannot set both cache writer factory and cache store factory " +
                     "for cache: " + U.maskName(cfg.getName()));
         }
+
+        Collection<QueryEntity> entities = cfg.getQueryEntities();
+
+        if (!F.isEmpty(entities)) {
+            Collection<QueryEntity> normalEntities = new ArrayList<>(entities.size());
+
+            for (QueryEntity entity : entities)
+                normalEntities.add(QueryUtils.normalizeQueryEntity(entity, cfg.isSqlEscapeAll()));
+
+            cfg.clearQueryEntities().setQueryEntities(normalEntities);
+        }
     }
 
     /**
@@ -503,8 +515,6 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         if (cc.getEvictionPolicy() != null && !cc.isOnheapCacheEnabled())
             throw new IgniteCheckedException("Onheap cache must be enabled if eviction policy is configured [cacheName="
                 + U.maskName(cc.getName()) + "]");
-
-        QueryUtils.validateCacheConfiguration(cc);
     }
 
     /**
@@ -1361,8 +1371,6 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
         CacheStore cfgStore = cfg.getCacheStoreFactory() != null ? cfg.getCacheStoreFactory().create() : null;
 
-        QueryUtils.prepareCacheConfiguration(cfg);
-
         validate(ctx.config(), cfg, desc.cacheType(), cfgStore);
 
         if (pluginMgr == null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
index 4b9c0e2..77c581c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
@@ -168,12 +168,13 @@ public interface GridQueryIndexing {
      * Registers cache.
      *
      * @param cacheName Cache name.
+     * @param schemaName Schema name.
      * @param cctx Cache context.
      * @param ccfg Cache configuration.
      * @throws IgniteCheckedException If failed.
      */
-    public void registerCache(String cacheName, GridCacheContext<?,?> cctx, CacheConfiguration<?,?> ccfg)
-        throws IgniteCheckedException;
+    public void registerCache(String cacheName, String schemaName, GridCacheContext<?,?> cctx,
+        CacheConfiguration<?,?> ccfg) throws IgniteCheckedException;
 
     /**
      * Unregisters cache.
@@ -207,14 +208,14 @@ public interface GridQueryIndexing {
      * the key should be removed from indexes other than one being updated.
      *
      * @param cacheName Cache name.
-     * @param typeName Type name.
+     * @param type Type descriptor.
      * @param key Key.
      * @param val Value.
      * @param ver Version.
      * @param expirationTime Expiration time or 0 if never expires.
      * @throws IgniteCheckedException If failed.
      */
-    public void store(String cacheName, String typeName, KeyCacheObject key, int partId, CacheObject val,
+    public void store(String cacheName, GridQueryTypeDescriptor type, KeyCacheObject key, int partId, CacheObject val,
         GridCacheVersion ver, long expirationTime, long link) throws IgniteCheckedException;
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 09dbe42..3233fd2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -668,8 +668,12 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
         try {
             synchronized (stateMux) {
+                boolean escape = cctx.config().isSqlEscapeAll();
+
                 String cacheName = cctx.name();
 
+                String schemaName = QueryUtils.normalizeSchemaName(cacheName, cctx.config().getSqlSchema(), escape);
+
                 // Prepare candidates.
                 List<Class<?>> mustDeserializeClss = new ArrayList<>();
 
@@ -680,7 +684,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 if (!F.isEmpty(qryEntities)) {
                     for (QueryEntity qryEntity : qryEntities) {
                         QueryTypeCandidate cand = QueryUtils.typeForQueryEntity(cacheName, cctx, qryEntity,
-                            mustDeserializeClss);
+                            mustDeserializeClss, escape);
 
                         cands.add(cand);
                     }
@@ -755,7 +759,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 }
 
                 // Ready to register at this point.
-                registerCache0(cacheName, cctx, cands);
+                registerCache0(cacheName, schemaName, cctx, cands);
 
                 // Warn about possible implicit deserialization.
                 if (!mustDeserializeClss.isEmpty()) {
@@ -978,7 +982,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         Map<String, T2<QueryEntity, QueryIndex>> idxMap = new HashMap<>();
 
         for (QueryEntity entity : schema.entities()) {
-            String tblName = QueryUtils.tableName(entity);
+            String tblName = entity.getTableName();
 
             QueryEntity oldEntity = tblMap.put(tblName, entity);
 
@@ -989,7 +993,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             }
 
             for (QueryIndex entityIdx : entity.getIndexes()) {
-                String idxName = QueryUtils.indexName(entity, entityIdx);
+                String idxName = entityIdx.getName();
 
                 T2<QueryEntity, QueryIndex> oldIdxEntity = idxMap.put(idxName, new T2<>(entity, entityIdx));
 
@@ -1321,15 +1325,16 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * Register cache in indexing SPI.
      *
      * @param cacheName Cache name.
+     * @param schemaName Schema name.
      * @param cctx Cache context.
      * @param cands Candidates.
      * @throws IgniteCheckedException If failed.
      */
-    private void registerCache0(String cacheName, GridCacheContext<?, ?> cctx, Collection<QueryTypeCandidate> cands)
-        throws IgniteCheckedException {
+    private void registerCache0(String cacheName, String schemaName, GridCacheContext<?, ?> cctx,
+        Collection<QueryTypeCandidate> cands) throws IgniteCheckedException {
         synchronized (stateMux) {
             if (idx != null)
-                idx.registerCache(cacheName, cctx, cctx.config());
+                idx.registerCache(cacheName, schemaName, cctx, cctx.config());
 
             try {
                 for (QueryTypeCandidate cand : cands) {
@@ -1596,7 +1601,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             if (desc == null)
                 return;
 
-            idx.store(cacheName, desc.name(), key, partId, val, ver, expirationTime, link);
+            idx.store(cacheName, desc, key, partId, val, ver, expirationTime, link);
         }
         finally {
             busyLock.leaveBusy();

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryTypeDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryTypeDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryTypeDescriptor.java
index 3c75ac4..c1a9e1e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryTypeDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryTypeDescriptor.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.query;
 
 import java.util.Map;
 import org.apache.ignite.IgniteCheckedException;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Value descriptor which allows to extract fields from value object of given type.
@@ -145,4 +146,18 @@ public interface GridQueryTypeDescriptor {
      * @return value field name.
      */
     public String valueFieldName();
+
+    /**
+     * Gets key field alias.
+     *
+     * @return Key field alias.
+     */
+    @Nullable public String keyFieldAlias();
+
+    /**
+     * Gets value field alias.
+     *
+     * @return value field alias.
+     */
+    @Nullable public String valueFieldAlias();
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
index b380131..34a4502 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
@@ -93,7 +93,7 @@ public class QuerySchema implements Serializable {
                 SchemaIndexCreateOperation op0 = (SchemaIndexCreateOperation)op;
 
                 for (QueryEntity entity : entities) {
-                    String tblName = QueryUtils.tableName(entity);
+                    String tblName = entity.getTableName();
 
                     if (F.eq(tblName, op0.tableName())) {
                         boolean exists = false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
index 4848b0a..c0da83f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
@@ -447,4 +447,13 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
     @Override public String valueFieldName() {
         return valFieldName;
     }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public String keyFieldAlias() {
+        return keyFieldName != null ? aliases.get(keyFieldName) : null;
+    }
+
+    @Nullable @Override public String valueFieldAlias() {
+        return valFieldName != null ? aliases.get(valFieldName) : null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
index 245965c..c327820 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.query;
 
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
 import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.cache.QueryIndexType;
@@ -45,10 +46,10 @@ import java.lang.reflect.Method;
 import java.math.BigDecimal;
 import java.sql.Time;
 import java.sql.Timestamp;
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -64,13 +65,13 @@ import static org.apache.ignite.IgniteSystemProperties.getInteger;
 public class QueryUtils {
 
     /** Field name for key. */
-    public static final String KEY_FIELD_NAME = "_key";
+    public static final String KEY_FIELD_NAME = "_KEY";
 
     /** Field name for value. */
-    public static final String VAL_FIELD_NAME = "_val";
+    public static final String VAL_FIELD_NAME = "_VAL";
 
     /** Version field name. */
-    public static final String VER_FIELD_NAME = "_ver";
+    public static final String VER_FIELD_NAME = "_VER";
 
     /** Discovery history size. */
     private static final int DISCO_HIST_SIZE = getInteger(IGNITE_INDEXING_DISCOVERY_HISTORY_SIZE, 1000);
@@ -106,8 +107,14 @@ public class QueryUtils {
     public static String tableName(QueryEntity entity) {
         String res = entity.getTableName();
 
-        if (res == null)
+        if (res == null) {
+            String valTyp = entity.findValueType();
+
+            if (valTyp == null)
+                throw new IgniteException("Value type cannot be null or empty [queryEntity=" + entity + ']');
+
             res = typeName(entity.findValueType());
+        }
 
         return res;
     }
@@ -161,17 +168,172 @@ public class QueryUtils {
     }
 
     /**
+     * Normalize query entity. If "escape" flag is set, nothing changes. Otherwise we convert all object names to
+     * upper case and replace inner class separator characters ('$' for Java and '.' for .NET) with underscore.
+     *
+     * @param entity Query entity.
+     * @param escape Escape flag taken form configuration.
+     * @return Normalized query entity.
+     */
+    public static QueryEntity normalizeQueryEntity(QueryEntity entity, boolean escape) {
+        if (escape) {
+            String tblName = tableName(entity);
+
+            entity.setTableName(tblName);
+
+            Map<String, String> aliases = new HashMap<>(entity.getAliases());
+
+            for (String fieldName : entity.getFields().keySet()) {
+                String fieldAlias = entity.getAliases().get(fieldName);
+
+                if (fieldAlias == null) {
+                    fieldAlias = aliasForFieldName(fieldName);
+
+                    aliases.put(fieldName, fieldAlias);
+                }
+            }
+
+            entity.setAliases(aliases);
+
+            for (QueryIndex idx : entity.getIndexes())
+                idx.setName(indexName(tblName, idx));
+
+            validateQueryEntity(entity);
+
+            return entity;
+        }
+
+        QueryEntity normalEntity = new QueryEntity();
+
+        // Propagate plain properties.
+        normalEntity.setKeyType(entity.getKeyType());
+        normalEntity.setValueType(entity.getValueType());
+        normalEntity.setFields(entity.getFields());
+        normalEntity.setKeyFields(entity.getKeyFields());
+        normalEntity.setKeyFieldName(entity.getKeyFieldName());
+        normalEntity.setValueFieldName(entity.getValueFieldName());
+
+        // Normalize table name.
+        String normalTblName = entity.getTableName();
+
+        if (normalTblName == null)
+            // Replace special characters for auto-generated table name.
+            normalTblName = normalizeObjectName(tableName(entity), true);
+        else
+            // No replaces for manually defined table.
+            normalTblName = normalizeObjectName(normalTblName, false);
+
+        normalEntity.setTableName(normalTblName);
+
+        // Normalize field names through aliases.
+        Map<String, String> normalAliases = new HashMap<>(normalEntity.getAliases());
+
+        for (String fieldName : normalEntity.getFields().keySet()) {
+            String fieldAlias = entity.getAliases().get(fieldName);
+
+            if (fieldAlias == null)
+                fieldAlias = aliasForFieldName(fieldName);
+
+            assert fieldAlias != null;
+
+            normalAliases.put(fieldName, normalizeObjectName(fieldAlias, false));
+        }
+
+        normalEntity.setAliases(normalAliases);
+
+        // Normalize indexes.
+        Collection<QueryIndex> normalIdxs = new LinkedList<>();
+
+        for (QueryIndex idx : entity.getIndexes()) {
+            QueryIndex normalIdx = new QueryIndex();
+
+            normalIdx.setFields(idx.getFields());
+            normalIdx.setIndexType(idx.getIndexType());
+            normalIdx.setInlineSize(idx.getInlineSize());
+
+            normalIdx.setName(normalizeObjectName(indexName(normalTblName, idx), false));
+
+            normalIdxs.add(normalIdx);
+        }
+
+        normalEntity.setIndexes(normalIdxs);
+
+        validateQueryEntity(normalEntity);
+
+        return normalEntity;
+    }
+
+    /**
+     * Stores rule for constructing schemaName according to cache configuration.
+     *
+     * @param cacheName Cache name.
+     * @param schemaName Schema name.
+     * @param escape Whether to perform escape.
+     * @return Proper schema name according to ANSI-99 standard.
+     */
+    public static String normalizeSchemaName(String cacheName, @Nullable String schemaName, boolean escape) {
+        String res = schemaName;
+
+        if (res == null) {
+            res = cacheName;
+
+            // If schema name is not set explicitly, we will use escaped cache name. The reason is that cache name
+            // could contain weird characters, such as underscores, dots or non-Latin stuff, which are invalid from
+            // SQL synthax perspective. We do not want node to fail on startup due to this.
+            escape = true;
+        }
+
+        if (!escape)
+            res = normalizeObjectName(res, false);
+
+        return res;
+    }
+
+    /**
+     * Get alias for the field name (i.e. last part of the property).
+     *
+     * @param fieldName Field name.
+     * @return Alias.
+     */
+    private static String aliasForFieldName(String fieldName) {
+        int idx = fieldName.lastIndexOf('.');
+
+        if (idx >= 0)
+            fieldName = fieldName.substring(idx + 1);
+
+        return fieldName;
+    }
+
+    /**
+     * Normalize object name.
+     *
+     * @param str String.
+     * @param replace Whether to perform replace.
+     * @return Escaped string.
+     */
+    public static @Nullable String normalizeObjectName(@Nullable String str, boolean replace) {
+        if (str == null)
+            return null;
+
+        if (replace)
+            str = str.replace('.', '_').replace('$', '_');
+
+        return str.toUpperCase();
+    }
+
+    /**
      * Create type candidate for query entity.
      *
      * @param cacheName Cache name.
      * @param cctx Cache context.
      * @param qryEntity Query entity.
      * @param mustDeserializeClss Classes which must be deserialized.
+     * @param escape Escape flag.
      * @return Type candidate.
      * @throws IgniteCheckedException If failed.
      */
     public static QueryTypeCandidate typeForQueryEntity(String cacheName, GridCacheContext cctx, QueryEntity qryEntity,
-        List<Class<?>> mustDeserializeClss) throws IgniteCheckedException {
+        List<Class<?>> mustDeserializeClss, boolean escape) throws IgniteCheckedException {
         GridKernalContext ctx = cctx.kernalContext();
         CacheConfiguration<?,?> ccfg = cctx.config();
 
@@ -253,8 +415,12 @@ public class QueryUtils {
                 // Need to setup affinity key for distributed joins.
                 String affField = ctx.cacheObjects().affinityField(qryEntity.findKeyType());
 
-                if (affField != null)
+                if (affField != null) {
+                    if (!escape)
+                        affField = normalizeObjectName(affField, false);
+
                     desc.affinityKey(affField);
+                }
             }
         }
         else {
@@ -266,8 +432,12 @@ public class QueryUtils {
                 String affField =
                     ((GridCacheDefaultAffinityKeyMapper)keyMapper).affinityKeyPropertyName(desc.keyClass());
 
-                if (affField != null)
+                if (affField != null) {
+                    if (!escape)
+                        affField = normalizeObjectName(affField, false);
+
                     desc.affinityKey(affField);
+                }
             }
 
             typeId = new QueryTypeIdKey(cacheName, valCls);
@@ -836,76 +1006,48 @@ public class QueryUtils {
     }
 
     /**
-     * Prepare cache configuration.
+     * Validate query entity.
      *
-     * @param ccfg Cache configuration.
+     * @param entity Entity.
      */
-    @SuppressWarnings("unchecked")
-    public static void prepareCacheConfiguration(CacheConfiguration ccfg) {
-        assert ccfg != null;
-
-        Collection<QueryEntity> entities = ccfg.getQueryEntities();
-
-        if (!F.isEmpty(entities)) {
-            for (QueryEntity entity : entities) {
-                if (F.isEmpty(entity.findValueType()))
-                    continue;
-
-                Collection<QueryIndex> idxs = entity.getIndexes();
+    private static void validateQueryEntity(QueryEntity entity) {
+        if (F.isEmpty(entity.findValueType()))
+            throw new IgniteException("Value type cannot be null or empty [queryEntity=" + entity + ']');
 
-                if (!F.isEmpty(idxs)) {
-                    for (QueryIndex idx : idxs) {
-                        if (idx.getName() == null) {
-                            String idxName = indexName(entity, idx);
+        String keyFieldName = entity.getKeyFieldName();
 
-                            idx.setName(idxName);
-                        }
-                    }
-                }
-            }
+        if (keyFieldName != null && !entity.getFields().containsKey(keyFieldName)) {
+            throw new IgniteException("Key field is not in the field list [queryEntity=" + entity +
+                ", keyFieldName=" + keyFieldName + "]");
         }
-    }
 
-    /**
-     * Prepare cache configuration.
-     *
-     * @param ccfg Cache configuration.
-     * @throws IgniteCheckedException If failed.
-     */
-    @SuppressWarnings("unchecked")
-    public static void validateCacheConfiguration(CacheConfiguration ccfg) throws IgniteCheckedException {
-        assert ccfg != null;
-
-        Collection<QueryEntity> entities = ccfg.getQueryEntities();
+        String valFieldName = entity.getValueFieldName();
 
-        if (!F.isEmpty(entities)) {
-            for (QueryEntity entity : entities) {
-                if (F.isEmpty(entity.findValueType()))
-                    throw new IgniteCheckedException("Value type cannot be null or empty [cacheName=" +
-                        ccfg.getName() + ", queryEntity=" + entity + ']');
+        if (valFieldName != null && !entity.getFields().containsKey(valFieldName)) {
+            throw new IgniteException("Value field is not in the field list [queryEntity=" + entity +
+                ", valFieldName=" + valFieldName + "]");
+        }
 
-                Collection<QueryIndex> idxs = entity.getIndexes();
+        Collection<QueryIndex> idxs = entity.getIndexes();
 
-                if (!F.isEmpty(idxs)) {
-                    Set<String> idxNames = new HashSet<>();
+        if (!F.isEmpty(idxs)) {
+            Set<String> idxNames = new HashSet<>();
 
-                    for (QueryIndex idx : idxs) {
-                        String idxName = idx.getName();
+            for (QueryIndex idx : idxs) {
+                String idxName = idx.getName();
 
-                        if (idxName == null)
-                            idxName = indexName(entity, idx);
+                if (idxName == null)
+                    idxName = indexName(entity, idx);
 
-                        assert !F.isEmpty(idxName);
+                assert !F.isEmpty(idxName);
 
-                        if (!idxNames.add(idxName))
-                            throw new IgniteCheckedException("Duplicate index name [cacheName=" + ccfg.getName() +
-                                ", queryEntity=" + entity + ", queryIdx=" + idx + ']');
+                if (!idxNames.add(idxName))
+                    throw new IgniteException("Duplicate index name [queryEntity=" + entity +
+                        ", queryIdx=" + idx + ']');
 
-                        if (idx.getIndexType() == null)
-                            throw new IgniteCheckedException("Index type is not set [cacheName=" + ccfg.getName() +
-                                ", queryEntity=" + entity + ", queryIdx=" + idx + ']');
-                    }
-                }
+                if (idx.getIndexType() == null)
+                    throw new IgniteException("Index type is not set [queryEntity=" + entity +
+                        ", queryIdx=" + idx + ']');
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/core/src/main/java/org/apache/ignite/internal/processors/query/property/QueryBinaryProperty.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/property/QueryBinaryProperty.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/property/QueryBinaryProperty.java
index 3b42a78..d8b907e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/property/QueryBinaryProperty.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/property/QueryBinaryProperty.java
@@ -137,7 +137,7 @@ public class QueryBinaryProperty implements GridQueryProperty {
         else if (obj instanceof BinaryObjectBuilder) {
             BinaryObjectBuilder obj0 = (BinaryObjectBuilder)obj;
 
-            return obj0.getField(name());
+            return obj0.getField(propName);
         }
         else
             throw new IgniteCheckedException("Unexpected binary object class [type=" + obj.getClass() + ']');

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java
index ddba4cc..7f135fd 100644
--- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java
+++ b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingAbstractGeoSelfTest.java
@@ -30,9 +30,7 @@ import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.cache.query.SqlQuery;
 import org.apache.ignite.cache.query.annotations.QuerySqlField;
 import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
 import org.apache.ignite.internal.processors.query.QueryUtils;
 import org.apache.ignite.internal.util.GridStringBuilder;
@@ -74,20 +72,15 @@ public abstract class H2IndexingAbstractGeoSelfTest extends GridCacheAbstractSel
     /** */
     private static final int QRY_PARALLELISM_LVL = 7;
 
-    /** Binary marshaller flag. */
-    private final boolean binary;
-
     /** Segmented index flag. */
     private final boolean segmented;
 
     /**
      * Constructor.
      *
-     * @param binary Binary marshaller flag.
      * @param segmented Segmented index flag.
      */
-    protected H2IndexingAbstractGeoSelfTest(boolean binary, boolean segmented) {
-        this.binary = binary;
+    protected H2IndexingAbstractGeoSelfTest(boolean segmented) {
         this.segmented = segmented;
     }
 
@@ -101,16 +94,6 @@ public abstract class H2IndexingAbstractGeoSelfTest extends GridCacheAbstractSel
         return DUR * 3;
     }
 
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
-        if (binary)
-            cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
     /**
      * Create cache.
      *
@@ -157,8 +140,11 @@ public abstract class H2IndexingAbstractGeoSelfTest extends GridCacheAbstractSel
             IgniteCache<K, V> cache = grid(0).getOrCreateCache(ccfg);
 
             // Process indexes dynamically.
-            for (QueryIndex idx : idxs)
-                createDynamicIndex(cache, entity, idx);
+            for (QueryIndex idx : idxs) {
+                QueryEntity normalEntity = QueryUtils.normalizeQueryEntity(entity, ccfg.isSqlEscapeAll());
+
+                createDynamicIndex(cache, normalEntity, idx);
+            }
 
             return cache;
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingBinaryGeoSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingBinaryGeoSelfTest.java b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingBinaryGeoSelfTest.java
deleted file mode 100644
index eb3ec6e..0000000
--- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingBinaryGeoSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.query.h2;
-
-/**
- * Geo-indexing test for binary mode.
- */
-public class H2IndexingBinaryGeoSelfTest extends H2IndexingAbstractGeoSelfTest {
-    /**
-     * Constructor.
-     */
-    public H2IndexingBinaryGeoSelfTest() {
-        super(true, false);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingBinarySegmentedGeoSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingBinarySegmentedGeoSelfTest.java b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingBinarySegmentedGeoSelfTest.java
deleted file mode 100644
index fe94a3d..0000000
--- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingBinarySegmentedGeoSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.query.h2;
-
-/**
- * Geo-indexing test for binary mode and segmented cache.
- */
-public class H2IndexingBinarySegmentedGeoSelfTest extends H2IndexingAbstractGeoSelfTest {
-    /**
-     * Constructor.
-     */
-    public H2IndexingBinarySegmentedGeoSelfTest() {
-        super(true, true);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingGeoSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingGeoSelfTest.java b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingGeoSelfTest.java
index 280c946..be3f5cd 100644
--- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingGeoSelfTest.java
+++ b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingGeoSelfTest.java
@@ -25,6 +25,6 @@ public class H2IndexingGeoSelfTest extends H2IndexingAbstractGeoSelfTest {
      * Constructor.
      */
     public H2IndexingGeoSelfTest() {
-        super(false, false);
+        super(false);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingSegmentedGeoSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingSegmentedGeoSelfTest.java b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingSegmentedGeoSelfTest.java
index b2cf781..97bfb88 100644
--- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingSegmentedGeoSelfTest.java
+++ b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/H2IndexingSegmentedGeoSelfTest.java
@@ -25,6 +25,6 @@ public class H2IndexingSegmentedGeoSelfTest extends H2IndexingAbstractGeoSelfTes
      * Constructor.
      */
     public H2IndexingSegmentedGeoSelfTest() {
-        super(false, true);
+        super(true);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/geospatial/src/test/java/org/apache/ignite/testsuites/GeoSpatialIndexingTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/geospatial/src/test/java/org/apache/ignite/testsuites/GeoSpatialIndexingTestSuite.java b/modules/geospatial/src/test/java/org/apache/ignite/testsuites/GeoSpatialIndexingTestSuite.java
index 2395b93..22109de 100644
--- a/modules/geospatial/src/test/java/org/apache/ignite/testsuites/GeoSpatialIndexingTestSuite.java
+++ b/modules/geospatial/src/test/java/org/apache/ignite/testsuites/GeoSpatialIndexingTestSuite.java
@@ -18,8 +18,6 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.processors.query.h2.H2IndexingBinaryGeoSelfTest;
-import org.apache.ignite.internal.processors.query.h2.H2IndexingBinarySegmentedGeoSelfTest;
 import org.apache.ignite.internal.processors.query.h2.H2IndexingGeoSelfTest;
 import org.apache.ignite.internal.processors.query.h2.H2IndexingSegmentedGeoSelfTest;
 
@@ -37,9 +35,6 @@ public class GeoSpatialIndexingTestSuite extends TestSuite {
         suite.addTestSuite(H2IndexingGeoSelfTest.class);
         suite.addTestSuite(H2IndexingSegmentedGeoSelfTest.class);
 
-        suite.addTestSuite(H2IndexingBinaryGeoSelfTest.class);
-        suite.addTestSuite(H2IndexingBinarySegmentedGeoSelfTest.class);
-
         return suite;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
index 6f5ce3e..fbc9d6c 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
@@ -154,8 +154,12 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
         }
 
         final List<String> fieldsList = Arrays.asList(fields);
-        keyAliasColumnId = (type.keyFieldName() != null) ? DEFAULT_COLUMNS_COUNT + fieldsList.indexOf(type.keyFieldName()) : -1;
-        valueAliasColumnId = (type.valueFieldName() != null) ? DEFAULT_COLUMNS_COUNT + fieldsList.indexOf(type.valueFieldName()) : -1;
+
+        keyAliasColumnId =
+            (type.keyFieldName() != null) ? DEFAULT_COLUMNS_COUNT + fieldsList.indexOf(type.keyFieldAlias()) : -1;
+
+        valueAliasColumnId =
+            (type.valueFieldName() != null) ? DEFAULT_COLUMNS_COUNT + fieldsList.indexOf(type.valueFieldAlias()) : -1;
 
         // Index is not snapshotable in db-x.
         snapshotableIdx = false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Schema.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Schema.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Schema.java
index 603a0c1..8dd87c0 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Schema.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Schema.java
@@ -17,14 +17,13 @@
 
 package org.apache.ignite.internal.processors.query.h2;
 
-import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row;
 import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
 import org.h2.mvstore.cache.CacheLongKeyLIRS;
 import org.jsr166.ConcurrentHashMap8;
 
-import java.util.Map;
+import java.util.Collection;
 import java.util.concurrent.ConcurrentMap;
 
 /**
@@ -43,27 +42,24 @@ public class H2Schema {
     /** */
     private final ConcurrentMap<String, H2TableDescriptor> tbls = new ConcurrentHashMap8<>();
 
+    /** */
+    private final ConcurrentMap<String, H2TableDescriptor> typeToTbl = new ConcurrentHashMap8<>();
+
     /** Cache for deserialized offheap rows. */
     private final CacheLongKeyLIRS<GridH2Row> rowCache;
 
     /** */
     private final GridCacheContext<?, ?> cctx;
 
-    /** */
-    private final CacheConfiguration<?, ?> ccfg;
-
     /**
      * @param cacheName Cache name.
      * @param schemaName Schema name.
      * @param cctx Cache context.
-     * @param ccfg Cache configuration.
      */
-    H2Schema(String cacheName, String schemaName, GridCacheContext<?, ?> cctx,
-        CacheConfiguration<?, ?> ccfg) {
+    public H2Schema(String cacheName, String schemaName, GridCacheContext<?, ?> cctx) {
         this.cacheName = cacheName;
         this.cctx = cctx;
         this.schemaName = schemaName;
-        this.ccfg = ccfg;
 
         rowCache = null;
     }
@@ -106,23 +102,43 @@ public class H2Schema {
     /**
      * @return Tables.
      */
-    public Map<String, H2TableDescriptor> tables() {
-        return tbls;
+    public Collection<H2TableDescriptor> tables() {
+        return tbls.values();
+    }
+
+    /**
+     * @param tblName Table name.
+     * @return Table.
+     */
+    public H2TableDescriptor tableByName(String tblName) {
+        return tbls.get(tblName);
+    }
+
+    /**
+     * @param typeName Type name.
+     * @return Table.
+     */
+    public H2TableDescriptor tableByTypeName(String typeName) {
+        return typeToTbl.get(typeName);
     }
 
     /**
      * @param tbl Table descriptor.
      */
     public void add(H2TableDescriptor tbl) {
-        if (tbls.putIfAbsent(tbl.typeName(), tbl) != null)
+        if (tbls.putIfAbsent(tbl.tableName(), tbl) != null)
+            throw new IllegalStateException("Table already registered: " + tbl.fullTableName());
+
+        if (typeToTbl.putIfAbsent(tbl.typeName(), tbl) != null)
             throw new IllegalStateException("Table already registered: " + tbl.fullTableName());
     }
 
     /**
-     * @return Escape all.
+     * @param tbl Table descriptor.
      */
-    public boolean escapeAll() {
-        return ccfg.isSqlEscapeAll();
+    public void remove(H2TableDescriptor tbl) {
+        tbls.remove(tbl.tableName());
+        typeToTbl.remove(tbl.typeName());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
index a9548aa..2440788 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
@@ -80,9 +80,7 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
         this.type = type;
         this.schema = schema;
 
-        String tblName = H2Utils.escapeName(type.tableName(), schema.escapeAll());
-
-        fullTblName = schema.schemaName() + "." + tblName;
+        fullTblName = H2Utils.withQuotes(schema.schemaName()) + "." + H2Utils.withQuotes(type.tableName());
     }
 
     /**
@@ -121,6 +119,13 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
     }
 
     /**
+     * @return Table name.
+     */
+    String tableName() {
+        return type.tableName();
+    }
+
+    /**
      * @return Database full table name.
      */
     String fullTableName() {
@@ -232,10 +237,7 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
 
                 String firstField = idxDesc.fields().iterator().next();
 
-                String firstFieldName =
-                    schema.escapeAll() ? firstField : H2Utils.escapeName(firstField, false).toUpperCase();
-
-                Column col = tbl.getColumn(firstFieldName);
+                Column col = tbl.getColumn(firstField);
 
                 IndexColumn idxCol = tbl.indexColumn(col.getColumnId(),
                     idxDesc.descending(firstField) ? SortOrder.DESCENDING : SortOrder.ASCENDING);
@@ -279,31 +281,27 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
      * @return Index.
      */
     public GridH2IndexBase createUserIndex(GridQueryIndexDescriptor idxDesc) {
-        String name = schema.escapeAll() ? idxDesc.name() : H2Utils.escapeName(idxDesc.name(), false).toUpperCase();
-
         IndexColumn keyCol = tbl.indexColumn(KEY_COL, SortOrder.ASCENDING);
         IndexColumn affCol = tbl.getAffinityKeyColumn();
 
         List<IndexColumn> cols = new ArrayList<>(idxDesc.fields().size() + 2);
 
-        boolean escapeAll = schema.escapeAll();
-
         for (String field : idxDesc.fields()) {
-            String fieldName = escapeAll ? field : H2Utils.escapeName(field, false).toUpperCase();
-
-            Column col = tbl.getColumn(fieldName);
+            Column col = tbl.getColumn(field);
 
             cols.add(tbl.indexColumn(col.getColumnId(),
                 idxDesc.descending(field) ? SortOrder.DESCENDING : SortOrder.ASCENDING));
         }
 
         GridH2RowDescriptor desc = tbl.rowDescriptor();
+
         if (idxDesc.type() == QueryIndexType.SORTED) {
             cols = H2Utils.treeIndexColumns(desc, cols, keyCol, affCol);
-            return idx.createSortedIndex(schema, name, tbl, false, cols, idxDesc.inlineSize());
+
+            return idx.createSortedIndex(schema, idxDesc.name(), tbl, false, cols, idxDesc.inlineSize());
         }
         else if (idxDesc.type() == QueryIndexType.GEOSPATIAL) {
-            return H2Utils.createSpatialIndex(tbl, name, cols.toArray(new IndexColumn[cols.size()]));
+            return H2Utils.createSpatialIndex(tbl, idxDesc.name(), cols.toArray(new IndexColumn[cols.size()]));
         }
 
         throw new IllegalStateException("Index type: " + idxDesc.type());

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Utils.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Utils.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Utils.java
index 75d739d..a4fdb53 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Utils.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Utils.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.internal.processors.query.h2;
 
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor;
@@ -46,11 +45,8 @@ public class H2Utils {
     private static final String SPATIAL_IDX_CLS =
         "org.apache.ignite.internal.processors.query.h2.opt.GridH2SpatialIndex";
 
-    /** */
-    public static final char ESC_CH = '\"';
-
-    /** */
-    private static final String ESC_STR = ESC_CH + "" + ESC_CH;
+    /** Quotation character. */
+    private static final char ESC_CH = '\"';
 
     /**
      * @param c1 First column.
@@ -98,15 +94,14 @@ public class H2Utils {
      * @param ifNotExists Quietly skip index creation if it exists.
      * @return Statement string.
      */
-    public static String indexCreateSql(String fullTblName, GridH2IndexBase h2Idx, boolean ifNotExists,
-        boolean escapeAll) {
+    public static String indexCreateSql(String fullTblName, GridH2IndexBase h2Idx, boolean ifNotExists) {
         boolean spatial = F.eq(SPATIAL_IDX_CLS, h2Idx.getClass().getName());
 
         GridStringBuilder sb = new SB("CREATE ")
             .a(spatial ? "SPATIAL " : "")
             .a("INDEX ")
             .a(ifNotExists ? "IF NOT EXISTS " : "")
-            .a(escapeName(h2Idx.getName(), escapeAll))
+            .a(withQuotes(h2Idx.getName()))
             .a(" ON ")
             .a(fullTblName)
             .a(" (");
@@ -119,7 +114,7 @@ public class H2Utils {
             else
                 sb.a(", ");
 
-            sb.a("\"" + col.columnName + "\"").a(" ").a(col.sortType == SortOrder.ASCENDING ? "ASC" : "DESC");
+            sb.a(withQuotes(col.columnName)).a(" ").a(col.sortType == SortOrder.ASCENDING ? "ASC" : "DESC");
         }
 
         sb.a(')');
@@ -132,53 +127,10 @@ public class H2Utils {
      * @param schemaName <b>Quoted</b> schema name.
      * @param idxName Index name.
      * @param ifExists Quietly skip index drop if it exists.
-     * @param escapeAll Escape flag.
      * @return Statement string.
      */
-    public static String indexDropSql(String schemaName, String idxName, boolean ifExists, boolean escapeAll) {
-        return "DROP INDEX " + (ifExists ? "IF EXISTS " : "") + schemaName + '.' + escapeName(idxName, escapeAll);
-    }
-
-    /**
-     * Escapes name to be valid SQL identifier. Currently just replaces '.' and '$' sign with '_'.
-     *
-     * @param name Name.
-     * @param escapeAll Escape flag.
-     * @return Escaped name.
-     */
-    public static String escapeName(String name, boolean escapeAll) {
-        if (name == null) // It is possible only for a cache name.
-            return ESC_STR;
-
-        if (escapeAll)
-            return ESC_CH + name + ESC_CH;
-
-        SB sb = null;
-
-        for (int i = 0; i < name.length(); i++) {
-            char ch = name.charAt(i);
-
-            if (!Character.isLetter(ch) && !Character.isDigit(ch) && ch != '_' &&
-                !(ch == '"' && (i == 0 || i == name.length() - 1)) && ch != '-') {
-                // Class name can also contain '$' or '.' - these should be escaped.
-                assert ch == '$' || ch == '.';
-
-                if (sb == null)
-                    sb = new SB();
-
-                sb.a(name.substring(sb.length(), i));
-
-                // Replace illegal chars with '_'.
-                sb.a('_');
-            }
-        }
-
-        if (sb == null)
-            return name;
-
-        sb.a(name.substring(sb.length(), name.length()));
-
-        return sb.toString();
+    public static String indexDropSql(String schemaName, String idxName, boolean ifExists) {
+        return "DROP INDEX " + (ifExists ? "IF EXISTS " : "") + withQuotes(schemaName) + '.' + withQuotes(idxName);
     }
 
     /**
@@ -231,20 +183,13 @@ public class H2Utils {
     }
 
     /**
-     * Stores rule for constructing schemaName according to cache configuration.
+     * Add quotes around the name.
      *
-     * @param ccfg Cache configuration.
-     * @return Proper schema name according to ANSI-99 standard.
+     * @param str String.
+     * @return String with quotes.
      */
-    public static String schemaNameFromCacheConfiguration(CacheConfiguration<?, ?> ccfg) {
-        if (ccfg.getSqlSchema() == null)
-            return escapeName(ccfg.getName(), true);
-
-        if (ccfg.getSqlSchema().charAt(0) == ESC_CH)
-            return ccfg.getSqlSchema();
-
-        return ccfg.isSqlEscapeAll() ?
-            escapeName(ccfg.getSqlSchema(), true) : ccfg.getSqlSchema().toUpperCase();
+    public static String withQuotes(String str) {
+        return ESC_CH + str + ESC_CH;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/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 8e6eeba..71d3ad5 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
@@ -450,7 +450,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             try {
                 stmt = c.connection().createStatement();
 
-                stmt.executeUpdate("SET SCHEMA " + schema);
+                stmt.executeUpdate("SET SCHEMA " + H2Utils.withQuotes(schema));
 
                 if (log.isDebugEnabled())
                     log.debug("Set schema: " + schema);
@@ -476,7 +476,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * @throws IgniteCheckedException If failed to create db schema.
      */
     private void createSchema(String schema) throws IgniteCheckedException {
-        executeStatement("INFORMATION_SCHEMA", "CREATE SCHEMA IF NOT EXISTS " + schema);
+        executeStatement("INFORMATION_SCHEMA", "CREATE SCHEMA IF NOT EXISTS " + H2Utils.withQuotes(schema));
 
         if (log.isDebugEnabled())
             log.debug("Created H2 schema for index database: " + schema);
@@ -489,7 +489,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * @throws IgniteCheckedException If failed to create db schema.
      */
     private void dropSchema(String schema) throws IgniteCheckedException {
-        executeStatement("INFORMATION_SCHEMA", "DROP SCHEMA IF EXISTS " + schema);
+        executeStatement("INFORMATION_SCHEMA", "DROP SCHEMA IF EXISTS " + H2Utils.withQuotes(schema));
 
         if (log.isDebugEnabled())
             log.debug("Dropped H2 schema for index database: " + schema);
@@ -559,14 +559,14 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
     /** {@inheritDoc} */
     @Override public void store(String cacheName,
-        String typeName,
+        GridQueryTypeDescriptor type,
         KeyCacheObject k,
         int partId,
         CacheObject v,
         GridCacheVersion ver,
         long expirationTime,
         long link) throws IgniteCheckedException {
-        H2TableDescriptor tbl = tableDescriptor(typeName, cacheName);
+        H2TableDescriptor tbl = tableDescriptor(type.name(), cacheName);
 
         if (tbl == null)
             return; // Type was rejected.
@@ -664,7 +664,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
         tbl.onDrop();
 
-        tbl.schema().tables().remove(tbl.typeName());
+        tbl.schema().remove(tbl);
     }
 
     /**
@@ -682,7 +682,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         h2Tbl.proposeUserIndex(h2Idx);
 
         try {
-            String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, false, desc.schema().escapeAll());
+            String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, false);
 
             executeSql(cacheName, sql);
         }
@@ -703,7 +703,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
         H2Schema schema = schemas.get(schemaName);
 
-        H2TableDescriptor desc = (schema != null ? schema.tables().get(tblName) : null);
+        H2TableDescriptor desc = (schema != null ? schema.tableByName(tblName) : null);
 
         if (desc == null)
             throw new IgniteCheckedException("Table not found in internal H2 database [schemaName=" + schemaName +
@@ -738,7 +738,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
             // At this point index is in consistent state, promote it through H2 SQL statement, so that cached
             // prepared statements are re-built.
-            String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, ifNotExists, schema.escapeAll());
+            String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, ifNotExists);
 
             executeSql(cacheName, sql);
         }
@@ -756,9 +756,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         throws IgniteCheckedException{
         String schemaName = schema(cacheName);
 
-        H2Schema schema = schemas.get(schemaName);
-
-        String sql = H2Utils.indexDropSql(schemaName, idxName, ifExists, schema.escapeAll());
+        String sql = H2Utils.indexDropSql(schemaName, idxName, ifExists);
 
         executeSql(cacheName, sql);
     }
@@ -1450,7 +1448,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                     caches0.add(cctx.cacheId());
 
                     for (QueryTable table : twoStepQry.tables()) {
-                        String tblCacheName = cacheNameForSchemaAndTable(table.schema(), table.table());
+                        String tblCacheName = cacheName(table.schema());
 
                         int cacheId = CU.cacheId(tblCacheName);
 
@@ -1505,17 +1503,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /**
-     * Get cache for schema and table.
-     *
-     * @param schemaName Schema name.
-     * @param tblName Table name.
-     * @return Cache name.
-     */
-    private String cacheNameForSchemaAndTable(String schemaName, String tblName) {
-        return cacheName(schemaName);
-    }
-
-    /**
      * @throws IllegalStateException if segmented indices used with non-segmented indices.
      */
     private void checkCacheIndexSegmentation(List<Integer> cacheIds) {
@@ -1661,16 +1648,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 name.equalsIgnoreCase(VER_FIELD_NAME))
                 throw new IgniteCheckedException(MessageFormat.format(ptrn, name));
         }
-
-        if (type.keyFieldName() != null && !type.fields().containsKey(type.keyFieldName())) {
-            throw new IgniteCheckedException(MessageFormat.format("Name ''{0}'' must be amongst fields since it " +
-                "is configured as ''keyFieldName'' [type=" + type.name() + "]", type.keyFieldName()));
-        }
-
-        if (type.valueFieldName() != null && !type.fields().containsKey(type.valueFieldName())) {
-            throw new IgniteCheckedException(MessageFormat.format("Name ''{0}'' must be amongst fields since it " +
-                "is configured as ''valueFieldName'' [type=" + type.name() + "]", type.valueFieldName()));
-        }
     }
 
     /**
@@ -1688,8 +1665,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         assert schema != null;
         assert tbl != null;
 
-        boolean escapeAll = schema.escapeAll();
-
         String keyType = dbTypeFromClass(tbl.type().keyClass());
         String valTypeStr = dbTypeFromClass(tbl.type().valueClass());
 
@@ -1704,7 +1679,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         sql.a(',').a(VER_FIELD_NAME).a(" OTHER INVISIBLE");
 
         for (Map.Entry<String, Class<?>> e : tbl.type().fields().entrySet())
-            sql.a(',').a(H2Utils.escapeName(e.getKey(), escapeAll)).a(' ').a(dbTypeFromClass(e.getValue()));
+            sql.a(',').a(H2Utils.withQuotes(e.getKey())).a(' ').a(dbTypeFromClass(e.getValue()));
 
         sql.a(')');
 
@@ -1797,7 +1772,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         if (schema == null)
             return null;
 
-        return schema.tables().get(type);
+        return schema.tableByTypeName(type);
     }
 
     /**
@@ -1838,12 +1813,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
         H2Schema schema = schemas.get(schemaName);
 
-        // For the compatibility with conversion from """" to "" inside h2 lib
-        if (schema == null) {
-            assert schemaName.isEmpty() || schemaName.charAt(0) != H2Utils.ESC_CH;
-
-            schema = schemas.get(H2Utils.escapeName(schemaName, true));
-        }
+        assert schema != null;
 
         return schema.cacheName();
     }
@@ -2248,18 +2218,16 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /** {@inheritDoc} */
-    @Override public void registerCache(String cacheName, GridCacheContext<?, ?> cctx, CacheConfiguration<?, ?> ccfg)
-        throws IgniteCheckedException {
-        String schema = H2Utils.schemaNameFromCacheConfiguration(ccfg);
-
-        if (schemas.putIfAbsent(schema, new H2Schema(cacheName, schema, cctx, ccfg)) != null)
+    @Override public void registerCache(String cacheName, String schemaName, GridCacheContext<?, ?> cctx,
+        CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException {
+        if (schemas.putIfAbsent(schemaName, new H2Schema(cacheName, schemaName, cctx)) != null)
             throw new IgniteCheckedException("Cache already registered: " + U.maskName(cacheName));
 
-        cacheName2schema.put(cacheName, schema);
+        cacheName2schema.put(cacheName, schemaName);
 
-        createSchema(schema);
+        createSchema(schemaName);
 
-        createSqlFunctions(schema, ccfg.getSqlFunctionClasses());
+        createSqlFunctions(schemaName, ccfg.getSqlFunctionClasses());
     }
 
     /** {@inheritDoc} */
@@ -2281,7 +2249,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 U.error(log, "Failed to drop schema on cache stop (will ignore): " + cacheName, e);
             }
 
-            for (H2TableDescriptor tblDesc : rmv.tables().values())
+            for (H2TableDescriptor tblDesc : rmv.tables())
                 for (Index idx : tblDesc.table().getIndexes())
                     idx.close(null);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
----------------------------------------------------------------------
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 cb9042e..a85cd93 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
@@ -138,10 +138,8 @@ public class GridH2Table extends TableBase {
             int affKeyColId = -1;
 
             if (affKey != null) {
-                String colName = desc.context().config().isSqlEscapeAll() ? affKey : affKey.toUpperCase();
-
-                if (doesColumnExist(colName))
-                    affKeyColId = getColumn(colName).getColumnId();
+                if (doesColumnExist(affKey))
+                    affKeyColId = getColumn(affKey).getColumnId();
                 else
                     affinityColExists = false;
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInsertSqlQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInsertSqlQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInsertSqlQuerySelfTest.java
index 6bbd7e1..579432f 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInsertSqlQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInsertSqlQuerySelfTest.java
@@ -30,6 +30,8 @@ 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 static org.apache.ignite.internal.processors.cache.IgniteCacheUpdateSqlQuerySelfTest.*;
+
 /**
  *
  */
@@ -187,15 +189,20 @@ public class IgniteCacheInsertSqlQuerySelfTest extends IgniteCacheAbstractInsert
      *
      */
     public void testNestedFieldsHandling() {
-        IgniteCache<Integer, IgniteCacheUpdateSqlQuerySelfTest.AllTypes> p = ignite(0).cache("I2AT");
+        IgniteCache<Integer, AllTypes> p = ignite(0).cache("I2AT");
 
-        p.query(new SqlFieldsQuery("insert into AllTypes(_key, innerTypeCol, arrListCol, _val, innerStrCol) " +
-            "values (1, ?, ?, ?, 'sss')") .setArgs(new IgniteCacheUpdateSqlQuerySelfTest.AllTypes.InnerType(50L),
-            new ArrayList<>(Arrays.asList(3L, 2L, 1L)), new IgniteCacheUpdateSqlQuerySelfTest.AllTypes(1L)));
+        p.query(new SqlFieldsQuery(
+            "insert into AllTypes(_key, innerTypeCol, arrListCol, _val, innerStrCol) values (1, ?, ?, ?, 'sss')").
+            setArgs(
+                new AllTypes.InnerType(50L),
+                new ArrayList<>(Arrays.asList(3L, 2L, 1L)),
+                new AllTypes(1L)
+            )
+        );
 
-        IgniteCacheUpdateSqlQuerySelfTest.AllTypes res = p.get(1);
+        AllTypes res = p.get(1);
 
-        IgniteCacheUpdateSqlQuerySelfTest.AllTypes.InnerType resInner = new IgniteCacheUpdateSqlQuerySelfTest.AllTypes.InnerType(50L);
+        AllTypes.InnerType resInner = new AllTypes.InnerType(50L);
 
         resInner.innerStrCol = "sss";
         resInner.arrListCol = new ArrayList<>(Arrays.asList(3L, 2L, 1L));
@@ -208,17 +215,17 @@ public class IgniteCacheInsertSqlQuerySelfTest extends IgniteCacheAbstractInsert
         IgniteCache<Integer, IgniteCacheUpdateSqlQuerySelfTest.AllTypes> p = ignite(0).cache("I2AT");
 
         p.query(new SqlFieldsQuery("insert into AllTypes(_key, _val) values (1, ?)")
-            .setArgs(new IgniteCacheUpdateSqlQuerySelfTest.AllTypes(1L)));
+            .setArgs(new AllTypes(1L)));
 
         p.destroy();
 
         p = ignite(0).getOrCreateCache(cacheConfig("I2AT", true, false, Integer.class,
-            IgniteCacheUpdateSqlQuerySelfTest.AllTypes.class));
+            AllTypes.class));
 
         p.query(new SqlFieldsQuery("insert into AllTypes(_key, _val, dateCol) values (1, ?, null)")
-            .setArgs(new IgniteCacheUpdateSqlQuerySelfTest.AllTypes(1L)));
+            .setArgs(new AllTypes(1L)));
 
-        IgniteCacheUpdateSqlQuerySelfTest.AllTypes exp = new IgniteCacheUpdateSqlQuerySelfTest.AllTypes(1L);
+        AllTypes exp = new AllTypes(1L);
 
         exp.dateCol = null;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/427ca690/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java
index 1f50244..91ae2f7 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java
@@ -22,6 +22,7 @@ import org.apache.ignite.Ignition;
 import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.cache.QueryIndexType;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.cache.query.annotations.QuerySqlField;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.IgniteEx;
@@ -33,7 +34,9 @@ import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
 import org.apache.ignite.internal.processors.query.QueryIndexDescriptorImpl;
 import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
 import org.apache.ignite.internal.processors.query.QueryUtils;
+import org.apache.ignite.internal.util.GridStringBuilder;
 import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.SB;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgnitePredicate;
@@ -58,32 +61,38 @@ public class AbstractSchemaSelfTest extends GridCommonAbstractTest {
     /** Table name. */
     protected static final String TBL_NAME = tableName(ValueClass.class);
 
-    /** Table name 2. */
-    protected static final String TBL_NAME_2 = tableName(ValueClass2.class);
+    /** Escaped table name. */
+    protected static final String TBL_NAME_ESCAPED = typeName(ValueClass.class);
 
     /** Index name 1. */
-    protected static final String IDX_NAME_1 = "idx_1";
+    protected static final String IDX_NAME_1 = "IDX_1";
+
+    /** Index name 1 escaped. */
+    protected static final String IDX_NAME_1_ESCAPED = "idx_1";
 
     /** Index name 2. */
-    protected static final String IDX_NAME_2 = "idx_2";
+    protected static final String IDX_NAME_2 = "IDX_2";
 
-    /** Index name 3. */
-    protected static final String IDX_NAME_3 = "idx_3";
+    /** Index name 2 escaped. */
+    protected static final String IDX_NAME_2_ESCAPED = "idx_2";
 
     /** Key ID field. */
     protected static final String FIELD_KEY = "id";
 
-    /** Field 1. */
-    protected static final String FIELD_NAME_1 = "field1";
+    /** Key alias */
+    protected static final String FIELD_KEY_ALIAS = "key";
 
     /** Field 1. */
-    protected static final String FIELD_NAME_2 = "field2";
+    protected static final String FIELD_NAME_1 = "FIELD1";
 
-    /** Field 3. */
-    protected static final String FIELD_NAME_3 = "field3";
+    /** Field 1 escaped. */
+    protected static final String FIELD_NAME_1_ESCAPED = "field1";
 
-    /** Key alias */
-    protected static final String FIELD_KEY_ALIAS = "key";
+    /** Field 2. */
+    protected static final String FIELD_NAME_2 = "FIELD2";
+
+    /** Field 2 escaped. */
+    protected static final String FIELD_NAME_2_ESCAPED = "field2";
 
     /**
      * Get type on the given node for the given cache and table name. Type must exist.
@@ -205,7 +214,7 @@ public class AbstractSchemaSelfTest extends GridCommonAbstractTest {
         assert desc != null;
 
         for (QueryEntity entity : desc.schema().entities()) {
-            if (F.eq(tblName, QueryUtils.tableName(entity))) {
+            if (F.eq(tblName, entity.getTableName())) {
                 for (QueryIndex idx : entity.getIndexes()) {
                     if (F.eq(QueryUtils.indexName(entity, idx), idxName)) {
                         LinkedHashMap<String, Boolean> idxFields = idx.getFields();
@@ -215,7 +224,7 @@ public class AbstractSchemaSelfTest extends GridCommonAbstractTest {
                         int i = 0;
 
                         for (String idxField : idxFields.keySet()) {
-                            assertEquals(idxField, fields[i].get1());
+                            assertEquals(idxField.toLowerCase(), fields[i].get1().toLowerCase());
                             assertEquals(idxFields.get(idxField), fields[i].get2());
 
                             i++;
@@ -256,8 +265,8 @@ public class AbstractSchemaSelfTest extends GridCommonAbstractTest {
             String expFieldName = fields[i].get1();
             boolean expFieldAsc = fields[i].get2();
 
-            assertEquals("Index field mismatch [pos=" + i + ", expField=" + expFieldName +
-                ", actualField=" + fieldNames.get(i) + ']', expFieldName, fieldNames.get(i));
+            assertEquals("Index field mismatch [pos=" + i + ", expField=" + expFieldName + ", actualField=" +
+                fieldNames.get(i) + ']', expFieldName.toLowerCase(), fieldNames.get(i).toLowerCase());
 
             boolean fieldAsc = !idxDesc.descending(expFieldName);
 
@@ -275,7 +284,7 @@ public class AbstractSchemaSelfTest extends GridCommonAbstractTest {
      */
     protected static void assertNoIndex(String cacheName, String tblName, String idxName) {
         for (Ignite node : Ignition.allGrids())
-            assertNoIndex((IgniteEx)node, cacheName, tblName, idxName);
+            assertNoIndex(node, cacheName, tblName, idxName);
     }
 
     /**
@@ -367,11 +376,21 @@ public class AbstractSchemaSelfTest extends GridCommonAbstractTest {
      * @param cls Class.
      * @return Table name.
      */
-    protected static String tableName(Class cls) {
+    protected static String typeName(Class cls) {
         return cls.getSimpleName();
     }
 
     /**
+     * Get table name for class.
+     *
+     * @param cls Class.
+     * @return Table name.
+     */
+    protected static String tableName(Class cls) {
+        return QueryUtils.normalizeObjectName(typeName(cls), true);
+    }
+
+    /**
      * Convenient method for index creation.
      *
      * @param name Name.
@@ -433,6 +452,72 @@ public class AbstractSchemaSelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * Synchronously create index.
+     *
+     * @param node Ignite node.
+     * @param cacheName Cache name.
+     * @param tblName Table name.
+     * @param idx Index.
+     * @param ifNotExists When set to true operation will fail if index already exists.
+     * @throws Exception If failed.
+     */
+    protected void dynamicIndexCreate(Ignite node, String cacheName, String tblName, QueryIndex idx, boolean ifNotExists)
+        throws Exception {
+        GridStringBuilder sql = new SB("CREATE INDEX ")
+            .a(ifNotExists ? "IF NOT EXISTS " : "")
+            .a(idx.getName())
+            .a(" ON ")
+            .a(tblName)
+            .a(" (");
+
+        boolean first = true;
+
+        for (Map.Entry<String, Boolean> fieldEntry : idx.getFields().entrySet()) {
+            if (first)
+                first = false;
+            else
+                sql.a(", ");
+
+            String name = fieldEntry.getKey();
+            boolean asc = fieldEntry.getValue();
+
+            sql.a(name).a(" ").a(asc ? "ASC" : "DESC");
+        }
+
+        sql.a(')');
+
+        executeSql(node, cacheName, sql.toString());
+    }
+
+    /**
+     * Synchronously drop index.
+     *
+     * @param node Ignite node.
+     * @param cacheName Cache name.
+     * @param idxName Index name.
+     * @param ifExists When set to true operation fill fail if index doesn't exists.
+     * @throws Exception if failed.
+     */
+    protected void dynamicIndexDrop(Ignite node, String cacheName, String idxName, boolean ifExists) throws Exception {
+        String sql = "DROP INDEX " + (ifExists ? "IF EXISTS " : "") + idxName;
+
+        executeSql(node, cacheName, sql);
+    }
+
+    /**
+     * Execute SQL.
+     *
+     * @param node Ignite node.
+     * @param cacheName Cache name.
+     * @param sql SQL.
+     */
+    private void executeSql(Ignite node, String cacheName, String sql) {
+        log.info("Executing DDL: " + sql);
+
+        node.cache(cacheName).query(new SqlFieldsQuery(sql)).getAll();
+    }
+
+    /**
      * Key class.
      */
     public static class KeyClass {


[04/22] ignite git commit: IGNITE-5310: Fix to DML statement cache to decouple it from Ignite cache. This closes #2018.

Posted by sb...@apache.org.
IGNITE-5310: Fix to DML statement cache to decouple it from Ignite cache. This closes #2018.


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

Branch: refs/heads/ignite-5075
Commit: b673bdb58ccf9bf5a959cf43423ba4316535caa6
Parents: 40851c7
Author: devozerov <vo...@gridgain.com>
Authored: Sat May 27 16:40:43 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Sat May 27 16:40:43 2017 +0300

----------------------------------------------------------------------
 .../query/h2/DmlStatementsProcessor.java        | 27 ++++----
 .../processors/query/h2/H2DmlPlanKey.java       | 66 ++++++++++++++++++++
 2 files changed, 79 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b673bdb5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
index 47b5ef4..0474aeb 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
@@ -30,7 +30,6 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.TimeUnit;
 import javax.cache.processor.EntryProcessor;
@@ -105,7 +104,8 @@ public class DmlStatementsProcessor {
     private static final int PLAN_CACHE_SIZE = 1024;
 
     /** Update plans cache. */
-    private final ConcurrentMap<String, ConcurrentMap<String, UpdatePlan>> planCache = new ConcurrentHashMap<>();
+    private final ConcurrentMap<H2DmlPlanKey, UpdatePlan> planCache =
+        new GridBoundedConcurrentLinkedHashMap<>(PLAN_CACHE_SIZE);
 
     /**
      * Constructor.
@@ -125,7 +125,14 @@ public class DmlStatementsProcessor {
      * @param cacheName Cache name.
      */
     public void onCacheStop(String cacheName) {
-        planCache.remove(idx.schema(cacheName));
+        Iterator<Map.Entry<H2DmlPlanKey, UpdatePlan>> iter = planCache.entrySet().iterator();
+
+        while (iter.hasNext()) {
+            UpdatePlan plan = iter.next().getValue();
+
+            if (F.eq(cacheName, plan.tbl.cacheName()))
+                iter.remove();
+        }
     }
 
     /**
@@ -408,17 +415,9 @@ public class DmlStatementsProcessor {
         throws IgniteCheckedException {
         Prepared p = GridSqlQueryParser.prepared(prepStmt);
 
-        ConcurrentMap<String, UpdatePlan> cachePlans = planCache.get(schema);
-
-        if (cachePlans == null) {
-            cachePlans = new GridBoundedConcurrentLinkedHashMap<>(PLAN_CACHE_SIZE);
-
-            cachePlans = U.firstNotNull(planCache.putIfAbsent(schema, cachePlans), cachePlans);
-        }
+        H2DmlPlanKey planKey = new H2DmlPlanKey(schema, p.getSQL());
 
-        // getSQL returns field value, so it's fast
-        // Don't look for re-runs in cache, we don't cache them
-        UpdatePlan res = (errKeysPos == null ? cachePlans.get(p.getSQL()) : null);
+        UpdatePlan res = (errKeysPos == null ? planCache.get(planKey) : null);
 
         if (res != null)
             return res;
@@ -427,7 +426,7 @@ public class DmlStatementsProcessor {
 
         // Don't cache re-runs
         if (errKeysPos == null)
-            return U.firstNotNull(cachePlans.putIfAbsent(p.getSQL(), res), res);
+            return U.firstNotNull(planCache.putIfAbsent(planKey, res), res);
         else
             return res;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b673bdb5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DmlPlanKey.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DmlPlanKey.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DmlPlanKey.java
new file mode 100644
index 0000000..3a43ea1
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DmlPlanKey.java
@@ -0,0 +1,66 @@
+/*
+ * 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.query.h2;
+
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * H2 DML plan key.
+ */
+public class H2DmlPlanKey {
+    /** Schema name. */
+    private final String schemaName;
+
+    /** SQL. */
+    private final String sql;
+
+    /**
+     * Constructor.
+     *
+     * @param schemaName Schema name.
+     * @param sql SQL.
+     */
+    public H2DmlPlanKey(String schemaName, String sql) {
+        this.schemaName = schemaName;
+        this.sql = sql;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return 31 * (schemaName != null ? schemaName.hashCode() : 0) + (sql != null ? sql.hashCode() : 0);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        H2DmlPlanKey other = (H2DmlPlanKey)o;
+
+        return F.eq(sql, other.sql) && F.eq(schemaName, other.schemaName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(H2DmlPlanKey.class, this);
+    }
+}


[19/22] ignite git commit: Continuous queries fixes: - flush backup queue on exchange end (otherwise we don't really wait for all current operations) - on coordinator apply counters after all single messages received (otherwise extra counter increments a

Posted by sb...@apache.org.
Continuous queries fixes:
- flush backup queue on exchange end (otherwise we don't really wait for all current operations)
- on coordinator apply counters after all single messages received (otherwise extra counter increments are possible)
- do not send info about filtered entries if do not have non-filtered entry
- added system properties for hardcoded constants


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

Branch: refs/heads/ignite-5075
Commit: 42293fac88c29544b7c55c0340224afbf474a301
Parents: 827b7f6
Author: sboikov <sb...@gridgain.com>
Authored: Mon May 29 16:41:23 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon May 29 16:41:23 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheIoManager.java    |   6 +-
 .../processors/cache/GridCacheMapEntry.java     |   5 +-
 .../GridCachePartitionExchangeManager.java      |   2 +-
 .../dht/GridClientPartitionTopology.java        |  31 +-
 .../dht/GridDhtPartitionTopology.java           |   9 +-
 .../dht/GridDhtPartitionTopologyImpl.java       |  59 +-
 .../GridDhtPartitionsExchangeFuture.java        |  51 +-
 .../CacheContinuousQueryAcknowledgeBuffer.java  | 120 +++
 .../CacheContinuousQueryDeployableObject.java   | 110 +++
 .../continuous/CacheContinuousQueryEntry.java   | 117 ++-
 .../CacheContinuousQueryEventBuffer.java        | 483 ++++++++++++
 .../continuous/CacheContinuousQueryHandler.java | 733 +++----------------
 .../CacheContinuousQueryHandlerV2.java          |   6 +-
 .../continuous/CacheContinuousQueryManager.java |  16 +-
 .../CacheContinuousQueryPartitionRecovery.java  | 267 +++++++
 .../continuous/GridContinuousBatchAdapter.java  |   2 +-
 .../continuous/GridContinuousProcessor.java     |  19 +-
 .../continuous/GridContinuousQueryBatch.java    |  16 +-
 ...tinuousQueryAsyncFailoverAtomicSelfTest.java |   1 -
 ...nuousQueryConcurrentPartitionUpdateTest.java | 304 ++++++++
 .../CacheContinuousQueryEventBufferTest.java    | 217 ++++++
 ...ContinuousQueryFailoverAbstractSelfTest.java |  79 +-
 ...niteCacheContinuousQueryBackupQueueTest.java |  13 +-
 ...eCacheContinuousQueryImmutableEntryTest.java |   6 +-
 .../IgniteCacheQuerySelfTestSuite3.java         |   5 +
 25 files changed, 1885 insertions(+), 792 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
index fdd29e4..bb31645 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
@@ -874,7 +874,11 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter {
         finally {
             // Reset thread local context.
             cctx.tm().resetContext();
-            cctx.mvcc().contextReset();
+
+            GridCacheMvccManager mvcc = cctx.mvcc();
+
+            if (mvcc != null)
+                mvcc.contextReset();
 
             // Unwind eviction notifications.
             if (msg instanceof IgniteTxStateAware) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index 4f87658..7c7fc99 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.internal.processors.cache;
 
-import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -29,7 +28,6 @@ import javax.cache.Cache;
 import javax.cache.expiry.ExpiryPolicy;
 import javax.cache.processor.EntryProcessor;
 import javax.cache.processor.EntryProcessorResult;
-
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
@@ -62,8 +60,8 @@ import org.apache.ignite.internal.processors.cache.version.GridCacheVersionConfl
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersionedEntryEx;
 import org.apache.ignite.internal.processors.dr.GridDrType;
-import org.apache.ignite.internal.util.IgniteTree;
 import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorClosure;
+import org.apache.ignite.internal.util.IgniteTree;
 import org.apache.ignite.internal.util.lang.GridClosureException;
 import org.apache.ignite.internal.util.lang.GridMetadataAwareAdapter;
 import org.apache.ignite.internal.util.lang.GridTuple;
@@ -76,7 +74,6 @@ import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.lang.IgniteUuid;
 import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_EXPIRED;

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
index 5314088..2eec8f6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
@@ -1312,7 +1312,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
                         top = cacheCtx.topology();
 
                     if (top != null) {
-                        updated |= top.update(null, entry.getValue(), null) != null;
+                        updated |= top.update(null, entry.getValue()) != null;
 
                         cctx.affinity().checkRebalanceState(top, cacheId);
                     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
index 1de64c5..43bc609 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
@@ -650,11 +650,29 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
     }
 
     /** {@inheritDoc} */
+    @Override public void applyUpdateCounters(Map<Integer, T2<Long, Long>> cntrMap) {
+        assert cntrMap != null;
+
+        lock.writeLock().lock();
+
+        try {
+            for (Map.Entry<Integer, T2<Long, Long>> e : cntrMap.entrySet()) {
+                T2<Long, Long> cntr = this.cntrMap.get(e.getKey());
+
+                if (cntr == null || cntr.get2() < e.getValue().get2())
+                    this.cntrMap.put(e.getKey(), e.getValue());
+            }
+        }
+        finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    /** {@inheritDoc} */
     @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})
     @Nullable @Override public GridDhtPartitionMap update(
         @Nullable GridDhtPartitionExchangeId exchId,
-        GridDhtPartitionMap parts,
-        Map<Integer, T2<Long, Long>> cntrMap
+        GridDhtPartitionMap parts
     ) {
         if (log.isDebugEnabled())
             log.debug("Updating single partition map [exchId=" + exchId + ", parts=" + mapString(parts) + ']');
@@ -733,15 +751,6 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
                 }
             }
 
-            if (cntrMap != null) {
-                for (Map.Entry<Integer, T2<Long, Long>> e : cntrMap.entrySet()) {
-                    T2<Long, Long> cntr = this.cntrMap.get(e.getKey());
-
-                    if (cntr == null || cntr.get2() < e.getValue().get2())
-                        this.cntrMap.put(e.getKey(), e.getValue());
-                }
-            }
-
             consistencyCheck();
 
             if (log.isDebugEnabled())

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
index f9fd852..ffc1d63 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
@@ -234,12 +234,15 @@ public interface GridDhtPartitionTopology {
     /**
      * @param exchId Exchange ID.
      * @param parts Partitions.
-     * @param cntrMap Partition update counters.
      * @return Local partition map if there were evictions or {@code null} otherwise.
      */
     @Nullable public GridDhtPartitionMap update(@Nullable GridDhtPartitionExchangeId exchId,
-        GridDhtPartitionMap parts,
-        @Nullable Map<Integer, T2<Long, Long>> cntrMap);
+        GridDhtPartitionMap parts);
+
+    /**
+     * @param cntrMap Counters map.
+     */
+    public void applyUpdateCounters(Map<Integer, T2<Long, Long>> cntrMap);
 
     /**
      * Checks if there is at least one owner for each partition in the cache topology.

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index 8e79eda..7adce6e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -1256,11 +1256,45 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
     }
 
     /** {@inheritDoc} */
+    @Override public void applyUpdateCounters(Map<Integer, T2<Long, Long>> cntrMap) {
+        assert cntrMap != null;
+
+        lock.writeLock().lock();
+
+        try {
+            if (stopping)
+                return;
+
+            for (Map.Entry<Integer, T2<Long, Long>> e : cntrMap.entrySet()) {
+                T2<Long, Long> cntr = this.cntrMap.get(e.getKey());
+
+                if (cntr == null || cntr.get2() < e.getValue().get2())
+                    this.cntrMap.put(e.getKey(), e.getValue());
+            }
+
+            for (int i = 0; i < locParts.length(); i++) {
+                GridDhtLocalPartition part = locParts.get(i);
+
+                if (part == null)
+                    continue;
+
+                T2<Long, Long> cntr = cntrMap.get(part.id());
+
+                if (cntr != null && cntr.get2() > part.updateCounter())
+                    part.updateCounter(cntr.get2());
+            }
+        }
+        finally {
+            lock.writeLock().unlock();
+
+        }
+    }
+
+    /** {@inheritDoc} */
     @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})
     @Nullable @Override public GridDhtPartitionMap update(
         @Nullable GridDhtPartitionExchangeId exchId,
-        GridDhtPartitionMap parts,
-        @Nullable Map<Integer, T2<Long, Long>> cntrMap
+        GridDhtPartitionMap parts
     ) {
         if (log.isDebugEnabled())
             log.debug("Updating single partition map [exchId=" + exchId + ", parts=" + mapString(parts) + ']');
@@ -1279,27 +1313,6 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
             if (stopping)
                 return null;
 
-            if (cntrMap != null) {
-                for (Map.Entry<Integer, T2<Long, Long>> e : cntrMap.entrySet()) {
-                    T2<Long, Long> cntr = this.cntrMap.get(e.getKey());
-
-                    if (cntr == null || cntr.get2() < e.getValue().get2())
-                        this.cntrMap.put(e.getKey(), e.getValue());
-                }
-
-                for (int i = 0; i < locParts.length(); i++) {
-                    GridDhtLocalPartition part = locParts.get(i);
-
-                    if (part == null)
-                        continue;
-
-                    T2<Long, Long> cntr = cntrMap.get(part.id());
-
-                    if (cntr != null && cntr.get2() > part.updateCounter())
-                        part.updateCounter(cntr.get2());
-                }
-            }
-
             if (lastExchangeId != null && exchId != null && lastExchangeId.compareTo(exchId) > 0) {
                 if (log.isDebugEnabled())
                     log.debug("Stale exchange id for single partition map update (will ignore) [lastExchId=" +

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
index 544f847..72c5bbc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
@@ -34,7 +34,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.ReadWriteLock;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.IgniteNeedReconnectException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cache.PartitionLossPolicy;
@@ -47,18 +46,19 @@ import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException;
 import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.IgniteNeedReconnectException;
 import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
 import org.apache.ignite.internal.events.DiscoveryCustomEvent;
-import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
 import org.apache.ignite.internal.managers.discovery.DiscoCache;
+import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
 import org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache;
 import org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage;
 import org.apache.ignite.internal.processors.cache.CacheInvalidStateException;
+import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask;
 import org.apache.ignite.internal.processors.cache.ClusterState;
 import org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch;
-import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask;
 import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
 import org.apache.ignite.internal.processors.cache.ExchangeActions;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
@@ -789,14 +789,11 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter<AffinityT
 
         boolean topChanged = discoEvt.type() != EVT_DISCOVERY_CUSTOM_EVT || affChangeMsg != null;
 
-        //todo check
         for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
             if (cacheCtx.isLocal() || stopping(cacheCtx.cacheId()))
                 continue;
 
             if (topChanged) {
-                cacheCtx.continuousQueries().beforeExchange(exchId.topologyVersion());
-
                 // Partition release future is done so we can flush the write-behind store.
                 cacheCtx.store().forceFlush();
             }
@@ -1101,10 +1098,31 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter<AffinityT
         }
     }
 
+    /**
+     * @return {@code True} if exchange triggered by server node join or fail.
+     */
+    private boolean serverNodeDiscoveryEvent() {
+        assert discoEvt != null;
+
+        return discoEvt.type() != EVT_DISCOVERY_CUSTOM_EVT && !CU.clientNode(discoEvt.eventNode());
+    }
+
     /** {@inheritDoc} */
     @Override public boolean onDone(@Nullable AffinityTopologyVersion res, @Nullable Throwable err) {
         boolean realExchange = !dummy && !forcePreload;
 
+        if (err == null &&
+            realExchange &&
+            !cctx.kernalContext().clientNode() &&
+            (serverNodeDiscoveryEvent() || affChangeMsg != null)) {
+            for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
+                if (!cacheCtx.affinityNode() || cacheCtx.isLocal())
+                    continue;
+
+                cacheCtx.continuousQueries().flushBackupQueue(exchId.topologyVersion());
+            }
+       }
+
         if (err == null && realExchange) {
             for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
                 if (cacheCtx.isLocal())
@@ -1554,6 +1572,25 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter<AffinityT
                 }
             }
 
+            for (GridDhtPartitionsAbstractMessage msg : msgs.values()) {
+                if (msg instanceof GridDhtPartitionsSingleMessage) {
+                    GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage)msg;
+
+                    for (Map.Entry<Integer, GridDhtPartitionMap> entry : msg0.partitions().entrySet()) {
+                        Integer cacheId = entry.getKey();
+                        GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
+
+                        GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() :
+                            cctx.exchange().clientTopology(cacheId, this);
+
+                        Map<Integer, T2<Long, Long>> cntrs = msg0.partitionUpdateCounters(cacheId);
+
+                        if (cntrs != null)
+                            top.applyUpdateCounters(cntrs);
+                    }
+                }
+            }
+
             if (discoEvt.type() == EVT_NODE_JOINED) {
                 if (cctx.kernalContext().state().active())
                     assignPartitionsStates();
@@ -1785,7 +1822,7 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter<AffinityT
             GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() :
                 cctx.exchange().clientTopology(cacheId, this);
 
-            top.update(exchId, entry.getValue(), msg.partitionUpdateCounters(cacheId));
+            top.update(exchId, entry.getValue());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAcknowledgeBuffer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAcknowledgeBuffer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAcknowledgeBuffer.java
new file mode 100644
index 0000000..c95dc42
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAcknowledgeBuffer.java
@@ -0,0 +1,120 @@
+/*
+ * 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.continuous;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.continuous.GridContinuousBatch;
+import org.apache.ignite.internal.processors.continuous.GridContinuousQueryBatch;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.Nullable;
+
+/** */
+class CacheContinuousQueryAcknowledgeBuffer {
+    /** */
+    private int size;
+
+    /** */
+    @GridToStringInclude
+    private Map<Integer, Long> updateCntrs = new HashMap<>();
+
+    /** */
+    @GridToStringInclude
+    private Set<AffinityTopologyVersion> topVers = U.newHashSet(1);
+
+    /**
+     * @param batch Batch.
+     * @return Non-null tuple if acknowledge should be sent to backups.
+     */
+    @SuppressWarnings("unchecked")
+    @Nullable synchronized IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>>onAcknowledged(
+        GridContinuousBatch batch) {
+        assert batch instanceof GridContinuousQueryBatch;
+
+        size += ((GridContinuousQueryBatch)batch).entriesCount();
+
+        Collection<CacheContinuousQueryEntry> entries = (Collection)batch.collect();
+
+        for (CacheContinuousQueryEntry e : entries)
+            addEntry(e);
+
+        return size >= CacheContinuousQueryHandler.BACKUP_ACK_THRESHOLD ? acknowledgeData() : null;
+    }
+
+    /**
+     * @param e Entry.
+     * @return Non-null tuple if acknowledge should be sent to backups.
+     */
+    @Nullable synchronized IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>>
+    onAcknowledged(CacheContinuousQueryEntry e) {
+        size++;
+
+        addEntry(e);
+
+        return size >= CacheContinuousQueryHandler.BACKUP_ACK_THRESHOLD ? acknowledgeData() : null;
+    }
+
+    /**
+     * @param e Entry.
+     */
+    private void addEntry(CacheContinuousQueryEntry e) {
+        topVers.add(e.topologyVersion());
+
+        Long cntr0 = updateCntrs.get(e.partition());
+
+        if (cntr0 == null || e.updateCounter() > cntr0)
+            updateCntrs.put(e.partition(), e.updateCounter());
+    }
+
+    /**
+     * @return Non-null tuple if acknowledge should be sent to backups.
+     */
+    @Nullable synchronized IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>>
+        acknowledgeOnTimeout() {
+        return size > 0 ? acknowledgeData() : null;
+    }
+
+    /**
+     * @return Tuple with acknowledge information.
+     */
+    private IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>> acknowledgeData() {
+        assert size > 0;
+
+        Map<Integer, Long> cntrs = new HashMap<>(updateCntrs);
+
+        IgniteBiTuple<Map<Integer, Long>, Set<AffinityTopologyVersion>> res =
+            new IgniteBiTuple<>(cntrs, topVers);
+
+        topVers = U.newHashSet(1);
+
+        size = 0;
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(CacheContinuousQueryAcknowledgeBuffer.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryDeployableObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryDeployableObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryDeployableObject.java
new file mode 100644
index 0000000..f888467
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryDeployableObject.java
@@ -0,0 +1,110 @@
+/*
+ * 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.continuous;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.UUID;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteDeploymentCheckedException;
+import org.apache.ignite.internal.managers.deployment.GridDeployment;
+import org.apache.ignite.internal.managers.deployment.GridDeploymentInfo;
+import org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+/**
+ * Deployable object.
+ */
+class CacheContinuousQueryDeployableObject implements Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Serialized object. */
+    private byte[] bytes;
+
+    /** Deployment class name. */
+    private String clsName;
+
+    /** Deployment info. */
+    private GridDeploymentInfo depInfo;
+
+    /**
+     * Required by {@link Externalizable}.
+     */
+    public CacheContinuousQueryDeployableObject() {
+        // No-op.
+    }
+
+    /**
+     * @param obj Object.
+     * @param ctx Kernal context.
+     * @throws IgniteCheckedException In case of error.
+     */
+    protected CacheContinuousQueryDeployableObject(Object obj, GridKernalContext ctx) throws IgniteCheckedException {
+        assert obj != null;
+        assert ctx != null;
+
+        Class cls = U.detectClass(obj);
+
+        clsName = cls.getName();
+
+        GridDeployment dep = ctx.deploy().deploy(cls, U.detectClassLoader(cls));
+
+        if (dep == null)
+            throw new IgniteDeploymentCheckedException("Failed to deploy object: " + obj);
+
+        depInfo = new GridDeploymentInfoBean(dep);
+
+        bytes = U.marshal(ctx, obj);
+    }
+
+    /**
+     * @param nodeId Node ID.
+     * @param ctx Kernal context.
+     * @return Deserialized object.
+     * @throws IgniteCheckedException In case of error.
+     */
+    <T> T unmarshal(UUID nodeId, GridKernalContext ctx) throws IgniteCheckedException {
+        assert ctx != null;
+
+        GridDeployment dep = ctx.deploy().getGlobalDeployment(depInfo.deployMode(), clsName, clsName,
+            depInfo.userVersion(), nodeId, depInfo.classLoaderId(), depInfo.participants(), null);
+
+        if (dep == null)
+            throw new IgniteDeploymentCheckedException("Failed to obtain deployment for class: " + clsName);
+
+        return U.unmarshal(ctx, bytes, U.resolveClassLoader(dep.classLoader(), ctx.config()));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        U.writeByteArray(out, bytes);
+        U.writeString(out, clsName);
+        out.writeObject(depInfo);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        bytes = U.readByteArray(in);
+        clsName = U.readString(in);
+        depInfo = (GridDeploymentInfo)in.readObject();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java
index bf2a691..7e3f0b5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java
@@ -51,6 +51,9 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
     private static final byte FILTERED_ENTRY = 0b0010;
 
     /** */
+    private static final byte KEEP_BINARY = 0b0100;
+
+    /** */
     private static final EventType[] EVT_TYPE_VALS = EventType.values();
 
     /**
@@ -105,11 +108,8 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
     @GridToStringInclude
     private AffinityTopologyVersion topVer;
 
-    /** Filtered events. */
-    private GridLongList filteredEvts;
-
-    /** Keep binary. */
-    private boolean keepBinary;
+    /** */
+    private long filteredCnt;
 
     /**
      * Required by {@link Message}.
@@ -124,9 +124,11 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
      * @param key Key.
      * @param newVal New value.
      * @param oldVal Old value.
+     * @param keepBinary Keep binary flag.
      * @param part Partition.
      * @param updateCntr Update partition counter.
      * @param topVer Topology version if applicable.
+     * @param flags Flags.
      */
     CacheContinuousQueryEntry(
         int cacheId,
@@ -137,7 +139,8 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
         boolean keepBinary,
         int part,
         long updateCntr,
-        @Nullable AffinityTopologyVersion topVer) {
+        @Nullable AffinityTopologyVersion topVer,
+        byte flags) {
         this.cacheId = cacheId;
         this.evtType = evtType;
         this.key = key;
@@ -146,7 +149,17 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
         this.part = part;
         this.updateCntr = updateCntr;
         this.topVer = topVer;
-        this.keepBinary = keepBinary;
+        this.flags = flags;
+
+        if (keepBinary)
+            this.flags |= KEEP_BINARY;
+    }
+
+    /**
+     * @return Flags.
+     */
+    public byte flags() {
+        return flags;
     }
 
     /**
@@ -207,26 +220,40 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
     }
 
     /**
-     * @return Size include this event and filtered.
+     * @param filteredCnt Number of entries filtered before this entry.
+     */
+    void filteredCount(long filteredCnt) {
+        assert filteredCnt >= 0 : filteredCnt;
+
+        this.filteredCnt = filteredCnt;
+    }
+
+    /**
+     * @return Number of entries filtered before this entry.
      */
-    public int size() {
-        return filteredEvts != null ? filteredEvts.size() + 1 : 1;
+    long filteredCount() {
+        return filteredCnt;
     }
 
     /**
      * @return If entry filtered then will return light-weight <i><b>new entry</b></i> without values and key
      * (avoid to huge memory consumption), otherwise {@code this}.
      */
-    CacheContinuousQueryEntry forBackupQueue() {
+    CacheContinuousQueryEntry copyWithDataReset() {
         if (!isFiltered())
             return this;
 
-        CacheContinuousQueryEntry e = new CacheContinuousQueryEntry(
-                cacheId, null, null, null, null, keepBinary, part, updateCntr, topVer);
-
-        e.flags = flags;
-
-        return e;
+        return new CacheContinuousQueryEntry(
+            cacheId,
+            null,
+            null,
+            null,
+            null,
+            false,
+            part,
+            updateCntr,
+            topVer,
+            flags);
     }
 
     /**
@@ -247,21 +274,7 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
      * @return Keep binary flag.
      */
     boolean isKeepBinary() {
-        return keepBinary;
-    }
-
-    /**
-     * @param cntrs Filtered events.
-     */
-    void filteredEvents(GridLongList cntrs) {
-        filteredEvts = cntrs;
-    }
-
-    /**
-     * @return previous filtered events.
-     */
-    long[] filteredEvents() {
-        return filteredEvts == null ? null : filteredEvts.array();
+        return (flags & KEEP_BINARY) != 0;
     }
 
     /**
@@ -363,7 +376,7 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
                 writer.incrementState();
 
             case 2:
-                if (!writer.writeMessage("filteredEvts", filteredEvts))
+                if (!writer.writeLong("filteredCnt", filteredCnt))
                     return false;
 
                 writer.incrementState();
@@ -375,42 +388,36 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
                 writer.incrementState();
 
             case 4:
-                if (!writer.writeBoolean("keepBinary", keepBinary))
-                    return false;
-
-                writer.incrementState();
-
-            case 5:
                 if (!writer.writeMessage("key", isFiltered() ? null : key))
                     return false;
 
                 writer.incrementState();
 
-            case 6:
+            case 5:
                 if (!writer.writeMessage("newVal", isFiltered() ? null : newVal))
                     return false;
 
                 writer.incrementState();
 
-            case 7:
+            case 6:
                 if (!writer.writeMessage("oldVal", isFiltered() ? null : oldVal))
                     return false;
 
                 writer.incrementState();
 
-            case 8:
+            case 7:
                 if (!writer.writeInt("part", part))
                     return false;
 
                 writer.incrementState();
 
-            case 9:
+            case 8:
                 if (!writer.writeMessage("topVer", topVer))
                     return false;
 
                 writer.incrementState();
 
-            case 10:
+            case 9:
                 if (!writer.writeLong("updateCntr", updateCntr))
                     return false;
 
@@ -446,7 +453,7 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
                 reader.incrementState();
 
             case 2:
-                filteredEvts = reader.readMessage("filteredEvts");
+                filteredCnt = reader.readLong("filteredCnt");
 
                 if (!reader.isLastRead())
                     return false;
@@ -462,14 +469,6 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
                 reader.incrementState();
 
             case 4:
-                keepBinary = reader.readBoolean("keepBinary");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 5:
                 key = reader.readMessage("key");
 
                 if (!reader.isLastRead())
@@ -477,7 +476,7 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
 
                 reader.incrementState();
 
-            case 6:
+            case 5:
                 newVal = reader.readMessage("newVal");
 
                 if (!reader.isLastRead())
@@ -485,7 +484,7 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
 
                 reader.incrementState();
 
-            case 7:
+            case 6:
                 oldVal = reader.readMessage("oldVal");
 
                 if (!reader.isLastRead())
@@ -493,7 +492,7 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
 
                 reader.incrementState();
 
-            case 8:
+            case 7:
                 part = reader.readInt("part");
 
                 if (!reader.isLastRead())
@@ -501,7 +500,7 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
 
                 reader.incrementState();
 
-            case 9:
+            case 8:
                 topVer = reader.readMessage("topVer");
 
                 if (!reader.isLastRead())
@@ -509,7 +508,7 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
 
                 reader.incrementState();
 
-            case 10:
+            case 9:
                 updateCntr = reader.readLong("updateCntr");
 
                 if (!reader.isLastRead())
@@ -524,7 +523,7 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Message {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 11;
+        return 10;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBuffer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBuffer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBuffer.java
new file mode 100644
index 0000000..336f650
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBuffer.java
@@ -0,0 +1,483 @@
+/*
+ * 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.continuous;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentLinkedDeque8;
+
+/**
+ *
+ */
+public class CacheContinuousQueryEventBuffer {
+    /** */
+    private static final int BUF_SIZE =
+        IgniteSystemProperties.getInteger("IGNITE_CONTINUOUS_QUERY_SERVER_BUFFER_SIZE", 1000);
+
+    /** */
+    private static final Object RETRY = new Object();
+
+    /** */
+    protected final int part;
+
+    /** */
+    private AtomicReference<Batch> curBatch = new AtomicReference<>();
+
+    /** */
+    private ConcurrentLinkedDeque8<CacheContinuousQueryEntry> backupQ = new ConcurrentLinkedDeque8<>();
+
+    /** */
+    private ConcurrentSkipListMap<Long, CacheContinuousQueryEntry> pending = new ConcurrentSkipListMap<>();
+
+    /**
+     * @param part Partition number.
+     */
+    CacheContinuousQueryEventBuffer(int part) {
+        this.part = part;
+    }
+
+    /**
+     * @param updateCntr Acknowledged counter.
+     */
+    void cleanupBackupQueue(Long updateCntr) {
+        Iterator<CacheContinuousQueryEntry> it = backupQ.iterator();
+
+        while (it.hasNext()) {
+            CacheContinuousQueryEntry backupEntry = it.next();
+
+            if (backupEntry.updateCounter() <= updateCntr)
+                it.remove();
+        }
+    }
+
+    /**
+     * @return Backup entries.
+     */
+    @Nullable Collection<CacheContinuousQueryEntry> flushOnExchange() {
+        TreeMap<Long, CacheContinuousQueryEntry> ret = null;
+
+        int size = backupQ.sizex();
+
+        if (size > 0) {
+            ret = new TreeMap<>();
+
+            for (int i = 0; i < size; i++) {
+                CacheContinuousQueryEntry e = backupQ.pollFirst();
+
+                if (e != null)
+                    ret.put(e.updateCounter(), e);
+                else
+                    break;
+            }
+        }
+
+        Batch batch = curBatch.get();
+
+        if (batch != null)
+            ret = batch.flushCurrentEntries(ret);
+
+        if (!pending.isEmpty()) {
+            if (ret == null)
+                ret = new TreeMap<>();
+
+            for (CacheContinuousQueryEntry e : pending.values())
+                ret.put(e.updateCounter(), e);
+        }
+
+        return ret != null ? ret.values() : null;
+    }
+
+    /**
+     * @return Initial partition counter.
+     */
+    protected long currentPartitionCounter() {
+        return 0;
+    }
+
+    /**
+     * For test purpose only.
+     *
+     * @return Current number of filtered events.
+     */
+    long currentFiltered() {
+        Batch batch = curBatch.get();
+
+        return batch != null ? batch.filtered : 0;
+    }
+
+    /**
+     * @param e Entry to process.
+     * @param backup Backup entry flag.
+     * @return Collected entries to pass to listener (single entry or entries list).
+     */
+    @Nullable Object processEntry(CacheContinuousQueryEntry e, boolean backup) {
+        return process0(e.updateCounter(), e, backup);
+    }
+
+    /**
+     * @param backup Backup entry flag.
+     * @param cntr Entry counter.
+     * @param entry Entry.
+     * @return Collected entries.
+     */
+    private Object process0(long cntr, CacheContinuousQueryEntry entry, boolean backup) {
+        assert cntr >= 0 : cntr;
+
+        Batch batch;
+        Object res = null;
+
+        for (;;) {
+            batch = initBatch(entry.topologyVersion());
+
+            if (batch == null || cntr < batch.startCntr) {
+                if (backup)
+                    backupQ.add(entry);
+
+                return entry;
+            }
+
+            if (cntr <= batch.endCntr) {
+                res = batch.processEntry0(null, cntr, entry, backup);
+
+                if (res == RETRY)
+                    continue;
+            }
+            else
+                pending.put(cntr, entry);
+
+            break;
+        }
+
+        Batch batch0 = curBatch.get();
+
+        if (batch0 != batch) {
+            do {
+                batch = batch0;
+
+                res = processPending(res, batch, backup);
+
+                batch0 = initBatch(entry.topologyVersion());
+            }
+            while (batch != batch0);
+        }
+
+        return res;
+    }
+
+    /**
+     * @param topVer Current event topology version.
+     * @return Current batch.
+     */
+    @Nullable private Batch initBatch(AffinityTopologyVersion topVer) {
+        Batch batch = curBatch.get();
+
+        if (batch != null)
+            return batch;
+
+        for (;;) {
+            long curCntr = currentPartitionCounter();
+
+            if (curCntr == -1)
+                return null;
+
+            batch = new Batch(curCntr + 1, 0L, new CacheContinuousQueryEntry[BUF_SIZE], topVer);
+
+            if (curBatch.compareAndSet(null, batch))
+                return batch;
+
+            batch = curBatch.get();
+
+            if (batch != null)
+                return batch;
+        }
+    }
+
+    /**
+     * @param res Current result.
+     * @param batch Current batch.
+     * @param backup Backup entry flag.
+     * @return New result.
+     */
+    @Nullable private Object processPending(@Nullable Object res, Batch batch, boolean backup) {
+        if (pending.floorKey(batch.endCntr) != null) {
+            for (Map.Entry<Long, CacheContinuousQueryEntry> p : pending.headMap(batch.endCntr, true).entrySet()) {
+                long cntr = p.getKey();
+
+                assert cntr <= batch.endCntr;
+
+                if (pending.remove(p.getKey()) != null) {
+                    if (cntr < batch.startCntr)
+                        res = addResult(res, p.getValue(), backup);
+                    else
+                        res = batch.processEntry0(res, p.getKey(), p.getValue(), backup);
+                }
+            }
+        }
+
+        return res;
+    }
+
+    /**
+     * @param res Current result.
+     * @param entry Entry to add.
+     * @param backup Backup entry flag.
+     * @return Updated result.
+     */
+    @Nullable private Object addResult(@Nullable Object res, CacheContinuousQueryEntry entry, boolean backup) {
+        if (res == null) {
+            if (backup)
+                backupQ.add(entry);
+            else
+                res = entry;
+        }
+        else {
+            assert !backup;
+
+            List<CacheContinuousQueryEntry> resList;
+
+            if (res instanceof CacheContinuousQueryEntry) {
+                resList = new ArrayList<>();
+
+                resList.add((CacheContinuousQueryEntry)res);
+            }
+            else {
+                assert res instanceof List : res;
+
+                resList = (List<CacheContinuousQueryEntry>)res;
+            }
+
+            resList.add(entry);
+
+            res = resList;
+        }
+
+        return res;
+    }
+
+    /**
+     *
+     */
+    private class Batch {
+        /** */
+        private long filtered;
+
+        /** */
+        private final long startCntr;
+
+        /** */
+        private final long endCntr;
+
+        /** */
+        private int lastProc = -1;
+
+        /** */
+        private CacheContinuousQueryEntry[] entries;
+
+        /** */
+        private final AffinityTopologyVersion topVer;
+
+        /**
+         * @param filtered Number of filtered events before this batch.
+         * @param entries Entries array.
+         * @param topVer Current event topology version.
+         * @param startCntr Start counter.
+         */
+        Batch(long startCntr, long filtered, CacheContinuousQueryEntry[] entries, AffinityTopologyVersion topVer) {
+            assert startCntr >= 0;
+            assert filtered >= 0;
+
+            this.startCntr = startCntr;
+            this.filtered = filtered;
+            this.entries = entries;
+            this.topVer = topVer;
+
+            endCntr = startCntr + BUF_SIZE - 1;
+        }
+
+        /**
+         * @param res Current entries.
+         * @return Entries to send as part of backup queue.
+         */
+        @Nullable synchronized TreeMap<Long, CacheContinuousQueryEntry> flushCurrentEntries(
+            @Nullable TreeMap<Long, CacheContinuousQueryEntry> res) {
+            if (entries == null)
+                return res;
+
+            long filtered = this.filtered;
+            long cntr = startCntr;
+
+            for (int i = 0; i < entries.length; i++) {
+                CacheContinuousQueryEntry e = entries[i];
+
+                CacheContinuousQueryEntry flushEntry = null;
+
+                if (e == null) {
+                    if (filtered != 0) {
+                        flushEntry = filteredEntry(cntr - 1, filtered - 1);
+
+                        filtered = 0;
+                    }
+                }
+                else {
+                    if (e.isFiltered())
+                        filtered++;
+                    else {
+                        flushEntry = new CacheContinuousQueryEntry(e.cacheId(),
+                            e.eventType(),
+                            e.key(),
+                            e.value(),
+                            e.oldValue(),
+                            e.isKeepBinary(),
+                            e.partition(),
+                            e.updateCounter(),
+                            e.topologyVersion(),
+                            e.flags());
+
+                        flushEntry.filteredCount(filtered);
+
+                        filtered = 0;
+                    }
+                }
+
+                if (flushEntry != null) {
+                    if (res == null)
+                        res = new TreeMap<>();
+
+                    res.put(flushEntry.updateCounter(), flushEntry);
+                }
+
+                cntr++;
+            }
+
+            if (filtered != 0L) {
+                if (res == null)
+                    res = new TreeMap<>();
+
+                CacheContinuousQueryEntry flushEntry = filteredEntry(cntr - 1, filtered - 1);
+
+                res.put(flushEntry.updateCounter(), flushEntry);
+            }
+
+            return res;
+        }
+
+        /**
+         * @param cntr Entry counter.
+         * @param filtered Number of entries filtered before this entry.
+         * @return Entry.
+         */
+        private CacheContinuousQueryEntry filteredEntry(long cntr, long filtered) {
+            CacheContinuousQueryEntry e = new CacheContinuousQueryEntry(0,
+                null,
+                null,
+                null,
+                null,
+                false,
+                part,
+                cntr,
+                topVer,
+                (byte)0);
+
+            e.markFiltered();
+
+            e.filteredCount(filtered);
+
+            return e;
+        }
+
+        /**
+         * @param res Current result.
+         * @param cntr Entry counter.
+         * @param entry Entry.
+         * @param backup Backup entry flag.
+         * @return New result.
+         */
+        @SuppressWarnings("unchecked")
+        @Nullable private Object processEntry0(
+            @Nullable Object res,
+            long cntr,
+            CacheContinuousQueryEntry entry,
+            boolean backup) {
+            int pos = (int)(cntr - startCntr);
+
+            synchronized (this) {
+                if (entries == null)
+                    return RETRY;
+
+                entry = entry.copyWithDataReset();
+
+                entries[pos] = entry;
+
+                int next = lastProc + 1;
+
+                if (next == pos) {
+                    for (int i = next; i < entries.length; i++) {
+                        CacheContinuousQueryEntry entry0 = entries[i];
+
+                        if (entry0 != null) {
+                            if (!entry0.isFiltered()) {
+                                entry0.filteredCount(filtered);
+
+                                filtered = 0;
+
+                                res = addResult(res, entry0, backup);
+                            }
+                            else
+                                filtered++;
+
+                            pos = i;
+                        }
+                        else
+                            break;
+                    }
+
+                    lastProc = pos;
+
+                    if (pos == entries.length - 1) {
+                        Arrays.fill(entries, null);
+
+                        Batch nextBatch = new Batch(this.startCntr + BUF_SIZE,
+                            filtered,
+                            entries,
+                            entry.topologyVersion());
+
+                        entries = null;
+
+                        assert curBatch.get() == this;
+
+                        curBatch.set(nextBatch);
+                    }
+                }
+                else
+                    return res;
+            }
+
+            return res;
+        }
+    }
+}
\ No newline at end of file


[22/22] ignite git commit: ignite-5075

Posted by sb...@apache.org.
ignite-5075


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

Branch: refs/heads/ignite-5075
Commit: 9db0d4862070da6db7973e2b66067dd00da0ba8d
Parents: 681454c
Author: sboikov <sb...@gridgain.com>
Authored: Mon May 29 17:19:53 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon May 29 17:19:53 2017 +0300

----------------------------------------------------------------------
 .../continuous/CacheContinuousQueryHandler.java | 15 ++++++++
 .../CacheContinuousQueryListener.java           | 16 ++++++++
 .../continuous/CacheContinuousQueryManager.java |  9 +++--
 .../query/continuous/CounterSkipContext.java    | 40 ++++++++++++--------
 4 files changed, 61 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9db0d486/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
index 82b57b4..8d6aa2c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
@@ -487,6 +487,21 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
                 onEntryUpdated(evt, primary, false, null);
             }
 
+            @Override public CounterSkipContext skipUpdateCounter(GridCacheContext cctx,
+                @Nullable CounterSkipContext ctx,
+                int part,
+                long cntr,
+                AffinityTopologyVersion topVer) {
+                CacheContinuousQueryEventBuffer buf = partitionBuffer(cctx, part);
+
+                if (ctx == null)
+                    ctx = new CounterSkipContext(part, cntr, topVer);
+
+                buf.processEntry(ctx.entry(), true);
+
+                return ctx;
+            }
+
             @Override public void onPartitionEvicted(int part) {
                 entryBufs.remove(part);
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/9db0d486/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java
index 84b22f9..fe9c198 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.cache.query.continuous;
 import java.util.Map;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicAbstractUpdateFuture;
 import org.jetbrains.annotations.Nullable;
 
@@ -76,6 +77,21 @@ public interface CacheContinuousQueryListener<K, V> {
     public void skipUpdateEvent(CacheContinuousQueryEvent<K, V> evt, AffinityTopologyVersion topVer, boolean primary);
 
     /**
+     * @param cctx Cache context.
+     * @param skipCtx Context.
+     * @param part Partition.
+     * @param cntr Counter to skip.
+     * @param topVer Topology version.
+     * @return Context.
+     */
+    public CounterSkipContext skipUpdateCounter(
+        GridCacheContext cctx,
+        @Nullable CounterSkipContext skipCtx,
+        int part,
+        long cntr,
+        AffinityTopologyVersion topVer);
+
+    /**
      * @param part Partition.
      */
     public void onPartitionEvicted(int part);

http://git-wip-us.apache.org/repos/asf/ignite/blob/9db0d486/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
index 6a10ed5..9910955 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
@@ -204,17 +204,20 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
     }
 
     /**
-     * @param ctx Context.
+     * @param skipCtx Context.
      * @param part Partition number.
      * @param cntr Update counter.
      * @param topVer Topology version.
      * @return Context.
      */
-    @Nullable public CounterSkipContext skipUpdateCounter(@Nullable CounterSkipContext ctx,
+    @Nullable public CounterSkipContext skipUpdateCounter(@Nullable CounterSkipContext skipCtx,
         int part,
         long cntr,
         AffinityTopologyVersion topVer) {
-        return null;
+        for (CacheContinuousQueryListener lsnr : lsnrs.values())
+            skipCtx = lsnr.skipUpdateCounter(cctx, skipCtx, part, cntr, topVer);
+
+        return skipCtx;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/9db0d486/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java
index 89ac6f9..41183c8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CounterSkipContext.java
@@ -26,27 +26,35 @@ import org.jetbrains.annotations.Nullable;
  */
 public class CounterSkipContext {
     /** */
-    private CacheContinuousQueryEntry entry;
+    private final CacheContinuousQueryEntry entry;
 
     /** */
     private List<Runnable> readySendC;
 
-    CacheContinuousQueryEntry entry(int part, long cntr, AffinityTopologyVersion topVer) {
-        if (entry == null) {
-            entry = new CacheContinuousQueryEntry(0,
-                null,
-                null,
-                null,
-                null,
-                false,
-                part,
-                cntr,
-                topVer,
-                (byte)0);
-
-            entry.markFiltered();
-        }
+    /**
+     * @param part Partition.
+     * @param cntr Filtered counter.
+     * @param topVer Topology version.
+     */
+    CounterSkipContext(int part, long cntr, AffinityTopologyVersion topVer) {
+        entry = new CacheContinuousQueryEntry(0,
+            null,
+            null,
+            null,
+            null,
+            false,
+            part,
+            cntr,
+            topVer,
+            (byte)0);
+
+        entry.markFiltered();
+    }
 
+    /**
+     * @return Entry for filtered counter.
+     */
+    CacheContinuousQueryEntry entry() {
         return entry;
     }
 


[17/22] ignite git commit: Continuous queries fixes: - flush backup queue on exchange end (otherwise we don't really wait for all current operations) - on coordinator apply counters after all single messages received (otherwise extra counter increments a

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
index befd1d7..2fb7fcb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
@@ -30,6 +30,7 @@ import java.util.UUID;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ThreadLocalRandom;
@@ -400,7 +401,8 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
     /**
      * @param ignite Ignite.
-     * @param topVer Topology version.
+     * @param topVer Major topology version.
+     * @param minorVer Minor topology version.
      * @throws Exception If failed.
      */
     private void waitRebalanceFinished(Ignite ignite, long topVer, int minorVer) throws Exception {
@@ -511,9 +513,8 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
      * @param nodes Count nodes.
      * @param killedNodeIdx Killed node index.
      * @param updCntrs Update counters.
-     * @return {@code True} if counters matches.
      */
-    private boolean checkPartCounter(int nodes, int killedNodeIdx, Map<Integer, Long> updCntrs) {
+    private void checkPartCounter(int nodes, int killedNodeIdx, Map<Integer, Long> updCntrs) {
         for (int i = 0; i < nodes; i++) {
             if (i == killedNodeIdx)
                 continue;
@@ -527,8 +528,6 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
                     assertEquals(e.getValue(), act.get(e.getKey()).get2());
             }
         }
-
-        return true;
     }
 
     /**
@@ -753,8 +752,8 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
         assert GridTestUtils.waitForCondition(new PA() {
             @Override public boolean apply() {
                 // (SRV_NODES + 1 client node) - 1 primary - backup nodes.
-                return qryClient.cluster().nodes().size() == (SRV_NODES + 1 /** client node */)
-                    - 1 /** Primary node */ - backups;
+                return qryClient.cluster().nodes().size() == (SRV_NODES + 1 /* client node */)
+                    - 1 /* Primary node */ - backups;
             }
         }, 5000L);
 
@@ -1253,6 +1252,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
     /**
      * @param expEvts Expected events.
      * @param lsnr Listener.
+     * @throws Exception If failed.
      */
     private void checkEvents(final List<T3<Object, Object, Object>> expEvts, final CacheEventListener3 lsnr,
         boolean allowLoseEvt) throws Exception {
@@ -1347,9 +1347,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         QueryCursor<?> cur = qryClient.cache(DEFAULT_CACHE_NAME).query(qry);
 
-        final Collection<Object> backupQueue = backupQueue(ignite(1));
-
-        assertEquals(0, backupQueue.size());
+        assertEquals(0, backupQueue(ignite(1)).size());
 
         IgniteCache<Object, Object> cache0 = ignite(0).cache(DEFAULT_CACHE_NAME);
 
@@ -1367,11 +1365,12 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         GridTestUtils.waitForCondition(new GridAbsPredicate() {
             @Override public boolean apply() {
-                return backupQueue.isEmpty();
+                return backupQueue(ignite(1)).isEmpty();
             }
         }, 2000);
 
-        assertTrue("Backup queue is not cleared: " + backupQueue, backupQueue.size() < BACKUP_ACK_THRESHOLD);
+        assertTrue("Backup queue is not cleared: " + backupQueue(ignite(1)),
+            backupQueue(ignite(1)).size() < BACKUP_ACK_THRESHOLD);
 
         if (!latch.await(5, SECONDS))
             fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + lsnr.latch.getCount() + ']');
@@ -1389,11 +1388,11 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         GridTestUtils.waitForCondition(new GridAbsPredicate() {
             @Override public boolean apply() {
-                return backupQueue.isEmpty();
+                return backupQueue(ignite(1)).isEmpty();
             }
         }, ACK_FREQ + 2000);
 
-        assertTrue("Backup queue is not cleared: " + backupQueue, backupQueue.isEmpty());
+        assertTrue("Backup queue is not cleared: " + backupQueue(ignite(1)), backupQueue(ignite(1)).isEmpty());
 
         if (!latch.await(5, SECONDS))
             fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + lsnr.latch.getCount() + ']');
@@ -1421,9 +1420,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         QueryCursor<?> cur = qryClient.cache(DEFAULT_CACHE_NAME).query(qry);
 
-        final Collection<Object> backupQueue = backupQueue(ignite(0));
-
-        assertEquals(0, backupQueue.size());
+        assertEquals(0, backupQueue(ignite(0)).size());
 
         long ttl = 100;
 
@@ -1433,9 +1430,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         final List<Integer> keys = primaryKeys(ignite(1).cache(DEFAULT_CACHE_NAME), BACKUP_ACK_THRESHOLD);
 
-        CountDownLatch latch = new CountDownLatch(keys.size());
-
-        lsnr.latch = latch;
+        lsnr.latch = new CountDownLatch(keys.size());
 
         for (Integer key : keys) {
             log.info("Put: " + key);
@@ -1445,11 +1440,12 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         GridTestUtils.waitForCondition(new GridAbsPredicate() {
             @Override public boolean apply() {
-                return backupQueue.isEmpty();
+                return backupQueue(ignite(0)).isEmpty();
             }
         }, 2000);
 
-        assertTrue("Backup queue is not cleared: " + backupQueue, backupQueue.size() < BACKUP_ACK_THRESHOLD);
+        assertTrue("Backup queue is not cleared: " + backupQueue(ignite(0)),
+            backupQueue(ignite(0)).size() < BACKUP_ACK_THRESHOLD);
 
         boolean wait = waitForCondition(new GridAbsPredicate() {
             @Override public boolean apply() {
@@ -1461,14 +1457,14 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         GridTestUtils.waitForCondition(new GridAbsPredicate() {
             @Override public boolean apply() {
-                return backupQueue.isEmpty();
+                return backupQueue(ignite(0)).isEmpty();
             }
         }, 2000);
 
-        assertTrue("Backup queue is not cleared: " + backupQueue, backupQueue.size() < BACKUP_ACK_THRESHOLD);
+        assertTrue("Backup queue is not cleared: " + backupQueue(ignite(0)), backupQueue(ignite(0)).size() < BACKUP_ACK_THRESHOLD);
 
-        if (backupQueue.size() != 0) {
-            for (Object o : backupQueue) {
+        if (backupQueue(ignite(0)).size() != 0) {
+            for (Object o : backupQueue(ignite(0))) {
                 CacheContinuousQueryEntry e = (CacheContinuousQueryEntry)o;
 
                 assertNotSame("Evicted entry added to backup queue.", -1L, e.updateCounter());
@@ -1494,9 +1490,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         QueryCursor<?> cur = cache.query(qry);
 
-        final Collection<Object> backupQueue = backupQueue(ignite(1));
-
-        assertEquals(0, backupQueue.size());
+        assertEquals(0, backupQueue(ignite(1)).size());
 
         List<Integer> keys = primaryKeys(cache, BACKUP_ACK_THRESHOLD);
 
@@ -1512,11 +1506,12 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         GridTestUtils.waitForCondition(new GridAbsPredicate() {
             @Override public boolean apply() {
-                return backupQueue.isEmpty();
+                return backupQueue(ignite(1)).isEmpty();
             }
         }, 3000);
 
-        assertTrue("Backup queue is not cleared: " + backupQueue, backupQueue.size() < BACKUP_ACK_THRESHOLD);
+        assertTrue("Backup queue is not cleared: " + backupQueue(ignite(1)),
+            backupQueue(ignite(1)).size() < BACKUP_ACK_THRESHOLD);
 
         if (!latch.await(5, SECONDS))
             fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + lsnr.latch.getCount() + ']');
@@ -1533,20 +1528,25 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         ConcurrentMap<Object, Object> infos = GridTestUtils.getFieldValue(proc, "rmtInfos");
 
-        Collection<Object> backupQueue = null;
+        Collection<Object> backupQueue = new ArrayList<>();
 
         for (Object info : infos.values()) {
             GridContinuousHandler hnd = GridTestUtils.getFieldValue(info, "hnd");
 
-            if (hnd.isQuery() && DEFAULT_CACHE_NAME.equals(hnd.cacheName())) {
-                backupQueue = GridTestUtils.getFieldValue(hnd, CacheContinuousQueryHandler.class, "backupQueue");
+            if (hnd.isQuery() && hnd.cacheName().equals(DEFAULT_CACHE_NAME)) {
+                Map<Integer, CacheContinuousQueryEventBuffer> map = GridTestUtils.getFieldValue(hnd,
+                    CacheContinuousQueryHandler.class, "entryBufs");
+
+                for (CacheContinuousQueryEventBuffer buf : map.values()) {
+                    Collection<Object> q = GridTestUtils.getFieldValue(buf,
+                        CacheContinuousQueryEventBuffer.class, "backupQ");
 
-                break;
+                    if (q != null)
+                        backupQueue.addAll(q);
+                }
             }
         }
 
-        assertNotNull(backupQueue);
-
         return backupQueue;
     }
 
@@ -2422,7 +2422,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
         private ConcurrentHashMap<Object, CacheEntryEvent<?, ?>> evts = new ConcurrentHashMap<>();
 
         /** */
-        private List<CacheEntryEvent<?, ?>> allEvts;
+        private final CopyOnWriteArrayList<CacheEntryEvent<?, ?>> allEvts;
 
         /** */
         @LoggerResource
@@ -2432,8 +2432,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
          * @param saveAll Save all events flag.
          */
         CacheEventListener1(boolean saveAll) {
-            if (saveAll)
-                allEvts = new ArrayList<>();
+            allEvts = saveAll ? new CopyOnWriteArrayList<CacheEntryEvent<?, ?>>() : null;
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryBackupQueueTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryBackupQueueTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryBackupQueueTest.java
index 26c7d41..85d68d3 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryBackupQueueTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryBackupQueueTest.java
@@ -262,11 +262,16 @@ public class IgniteCacheContinuousQueryBackupQueueTest extends GridCommonAbstrac
             GridContinuousHandler hnd = GridTestUtils.getFieldValue(info, "hnd");
 
             if (hnd.isQuery() && hnd.cacheName().equals(CACHE_NAME)) {
-                Collection<Object> q = GridTestUtils.getFieldValue(hnd,
-                    CacheContinuousQueryHandler.class, "backupQueue");
+                Map<Integer, CacheContinuousQueryEventBuffer> map = GridTestUtils.getFieldValue(hnd,
+                    CacheContinuousQueryHandler.class, "entryBufs");
 
-                if (q != null)
-                    backupQueues.add(q);
+                for (CacheContinuousQueryEventBuffer buf : map.values()) {
+                    Collection<Object> q = GridTestUtils.getFieldValue(buf,
+                        CacheContinuousQueryEventBuffer.class, "backupQ");
+
+                    if (q != null)
+                        backupQueues.add(q);
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java
index b91217f..81a7515 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java
@@ -35,7 +35,6 @@ import org.apache.ignite.internal.managers.communication.GridIoMessageFactory;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
 import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
-import org.apache.ignite.internal.util.GridLongList;
 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;
@@ -138,9 +137,9 @@ public class IgniteCacheContinuousQueryImmutableEntryTest extends GridCommonAbst
             true,
             1,
             1L,
-            new AffinityTopologyVersion(1L));
+            new AffinityTopologyVersion(1L),
+            (byte)0);
 
-        e0.filteredEvents(new GridLongList(new long[]{1L, 2L}));
         e0.markFiltered();
 
         ByteBuffer buf = ByteBuffer.allocate(4096);
@@ -156,7 +155,6 @@ public class IgniteCacheContinuousQueryImmutableEntryTest extends GridCommonAbst
         assertEquals(e0.cacheId(), e1.cacheId());
         assertEquals(e0.eventType(), e1.eventType());
         assertEquals(e0.isFiltered(), e1.isFiltered());
-        assertEquals(GridLongList.asList(e0.filteredEvents()), GridLongList.asList(e1.filteredEvents()));
         assertEquals(e0.isBackup(), e1.isBackup());
         assertEquals(e0.isKeepBinary(), e1.isKeepBinary());
         assertEquals(e0.partition(), e1.partition());

http://git-wip-us.apache.org/repos/asf/ignite/blob/42293fac/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
index 8dd273a..0084cdc 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
@@ -21,6 +21,8 @@ import junit.framework.TestSuite;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousBatchAckTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousBatchForceServerModeAckTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryAsyncFilterListenerTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryConcurrentPartitionUpdateTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryEventBufferTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryExecuteInPrimaryTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryFactoryAsyncFilterRandomOperationTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryFactoryFilterRandomOperationTest;
@@ -118,6 +120,9 @@ public class IgniteCacheQuerySelfTestSuite3 extends TestSuite {
         suite.addTestSuite(ContinuousQueryPeerClassLoadingTest.class);
         suite.addTestSuite(ClientReconnectContinuousQueryTest.class);
 
+        suite.addTestSuite(CacheContinuousQueryConcurrentPartitionUpdateTest.class);
+        suite.addTestSuite(CacheContinuousQueryEventBufferTest.class);
+
         suite.addTest(IgniteDistributedJoinTestSuite.suite());
 
         return suite;


[10/22] ignite git commit: master - AffinityKeyMapper is deprecated.

Posted by sb...@apache.org.
master - AffinityKeyMapper is deprecated.


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

Branch: refs/heads/ignite-5075
Commit: 52e14ac079a27e42c4b356202148d0d5cddce52a
Parents: fb12f0f
Author: Sergi Vladykin <se...@gmail.com>
Authored: Sun May 28 22:40:20 2017 +0300
Committer: Sergi Vladykin <se...@gmail.com>
Committed: Sun May 28 22:40:20 2017 +0300

----------------------------------------------------------------------
 .../java/org/apache/ignite/cache/affinity/AffinityKeyMapper.java  | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/52e14ac0/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapper.java
index 4e2c624..7fd5e08 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapper.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapper.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.cache.affinity;
 
 import java.io.Serializable;
+import org.apache.ignite.cache.CacheKeyConfiguration;
 
 /**
  * Affinity mapper which maps cache key to an affinity key. Affinity key is a key which will be
@@ -41,7 +42,9 @@ import java.io.Serializable;
  * {@link AffinityKeyMapped @AffinityKeyMapped} documentation.
  * @see AffinityFunction
  * @see AffinityKeyMapped
+ * @deprecated Use {@link AffinityKeyMapped} or {@link CacheKeyConfiguration#setAffinityKeyFieldName(String)} instead.
  */
+@Deprecated
 public interface AffinityKeyMapper extends Serializable {
     /**
      * Maps passed in key to an alternate key which will be used for node affinity.


[08/22] ignite git commit: IGNITE-5311: Added ability to get CacheObject value without CacheObjectContext. This closes #2019.

Posted by sb...@apache.org.
IGNITE-5311: Added ability to get CacheObject value without CacheObjectContext. This closes #2019.


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

Branch: refs/heads/ignite-5075
Commit: aad3b0c536e3f7b0836d31daa63cd6d6137675d5
Parents: 858e5b7
Author: devozerov <vo...@gridgain.com>
Authored: Sat May 27 21:39:08 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Sat May 27 21:39:08 2017 +0300

----------------------------------------------------------------------
 .../internal/binary/BinaryEnumObjectImpl.java   |   5 +-
 .../internal/binary/BinaryObjectImpl.java       |  18 +-
 .../binary/BinaryObjectOffheapImpl.java         |   3 +-
 .../internal/processors/cache/CacheObject.java  |   2 +-
 .../processors/cache/CacheObjectAdapter.java    |   4 +-
 .../cache/CacheObjectByteArrayImpl.java         |   2 +-
 .../processors/cache/CacheObjectContext.java    | 197 ++-----------------
 .../processors/cache/CacheObjectImpl.java       |  25 ++-
 .../processors/cache/CacheObjectUtils.java      | 173 ++++++++++++++++
 .../cache/CacheObjectValueContext.java          |  50 +++++
 .../processors/cache/GridCacheContext.java      |   4 +-
 .../processors/cache/GridCacheEventManager.java |   2 +-
 .../processors/cache/GridCacheMapEntry.java     |   4 +-
 .../processors/cache/KeyCacheObjectImpl.java    |   4 +-
 .../cache/binary/CacheObjectBinaryContext.java  |   6 +-
 .../binary/CacheObjectBinaryProcessorImpl.java  |   5 +-
 .../cache/database/CacheDataRowAdapter.java     |   8 +-
 .../cache/distributed/near/GridNearTxLocal.java |   3 +-
 .../cache/transactions/TxDeadlock.java          |   7 +-
 .../cacheobject/IgniteCacheObjectProcessor.java |   6 +-
 .../IgniteCacheObjectProcessorImpl.java         |  39 ++--
 .../query/CacheQueryObjectValueContext.java     |  64 ++++++
 .../query/GridQueryCacheObjectsIterator.java    |  16 +-
 .../processors/query/GridQueryProcessor.java    |  14 +-
 .../processors/query/GridRunningQueryInfo.java  |  16 +-
 .../query/VisorRunningQueriesCollectorTask.java |   2 +-
 .../internal/GridAffinityNoCacheSelfTest.java   |   3 +-
 .../IgniteIncompleteCacheObjectSelfTest.java    |   2 +-
 .../database/FreeListImplSelfTest.java          |   3 +-
 .../query/h2/DmlStatementsProcessor.java        |   4 +-
 .../processors/query/h2/IgniteH2Indexing.java   |  44 +++--
 .../query/h2/opt/GridLuceneIndex.java           |   2 +-
 .../query/h2/twostep/GridMapQueryExecutor.java  |   4 +-
 .../h2/twostep/GridReduceQueryExecutor.java     | 159 ++++-----------
 .../query/h2/twostep/ReduceQueryRun.java        | 157 +++++++++++++++
 .../h2/GridIndexingSpiAbstractSelfTest.java     |   3 +-
 .../query/h2/sql/GridQueryParsingTest.java      |   4 +-
 37 files changed, 655 insertions(+), 409 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
index f889e45..6a1ad6e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
@@ -31,6 +31,7 @@ import org.apache.ignite.internal.GridDirectTransient;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectAdapter;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.SB;
@@ -280,7 +281,7 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+    @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
         return deserialize();
     }
 
@@ -335,7 +336,7 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
 
     /** {@inheritDoc} */
     @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
-        this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.processor()).binaryContext();
+        this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.kernalContext().cacheObjects()).binaryContext();
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index 16e5ccd..d0d0699 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -38,6 +38,7 @@ import org.apache.ignite.internal.binary.streams.BinaryHeapInputStream;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectAdapter;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -135,7 +136,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+    @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
         Object obj0 = obj;
 
         if (obj0 == null || (cpy && needCopy(ctx)))
@@ -188,7 +189,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
 
     /** {@inheritDoc} */
     @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
-        this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.processor()).binaryContext();
+        this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.kernalContext().cacheObjects()).binaryContext();
     }
 
     /** {@inheritDoc} */
@@ -787,9 +788,9 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
      * @param coCtx CacheObjectContext.
      * @return Object.
      */
-    private Object deserializeValue(@Nullable CacheObjectContext coCtx) {
-        BinaryReaderExImpl reader = reader(null,
-            coCtx != null ? coCtx.kernalContext().config().getClassLoader() : ctx.configuration().getClassLoader(), true);
+    private Object deserializeValue(@Nullable CacheObjectValueContext coCtx) {
+        BinaryReaderExImpl reader = reader(null, coCtx != null ?
+            coCtx.kernalContext().config().getClassLoader() : ctx.configuration().getClassLoader(), true);
 
         Object obj0 = reader.deserialize();
 
@@ -807,8 +808,8 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
      * @param ctx Context.
      * @return {@code True} need to copy value returned to user.
      */
-    private boolean needCopy(CacheObjectContext ctx) {
-        return ctx.copyOnGet() && obj != null && !ctx.processor().immutable(obj);
+    private boolean needCopy(CacheObjectValueContext ctx) {
+        return ctx.copyOnGet() && obj != null && !ctx.kernalContext().cacheObjects().immutable(obj);
     }
 
     /**
@@ -819,7 +820,8 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
      * @param forUnmarshal {@code True} if reader is need to unmarshal object.
      * @return Reader.
      */
-    private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx, @Nullable ClassLoader ldr, boolean forUnmarshal) {
+    private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx, @Nullable ClassLoader ldr,
+        boolean forUnmarshal) {
         if (ldr == null)
             ldr = ctx.configuration().getClassLoader();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
index bdf0ce1..0a0a7b1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@ -37,6 +37,7 @@ import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
 import org.apache.ignite.internal.binary.streams.BinaryOffheapInputStream;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.plugin.extensions.communication.MessageReader;
 import org.apache.ignite.plugin.extensions.communication.MessageWriter;
@@ -444,7 +445,7 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+    @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
         return (T)deserializeValue();
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
index c226ba2..8faaa03 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
@@ -43,7 +43,7 @@ public interface CacheObject extends Message {
      * @param cpy If {@code true} need to copy value.
      * @return Value.
      */
-    @Nullable public <T> T value(CacheObjectContext ctx, boolean cpy);
+    @Nullable public <T> T value(CacheObjectValueContext ctx, boolean cpy);
 
     /**
      * @param ctx Context.

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
index 6af38ac..e2a15ee 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
@@ -50,8 +50,8 @@ public abstract class CacheObjectAdapter implements CacheObject, Externalizable
      * @param ctx Context.
      * @return {@code True} need to copy value returned to user.
      */
-    protected boolean needCopy(CacheObjectContext ctx) {
-        return ctx.copyOnGet() && val != null && !ctx.processor().immutable(val);
+    protected boolean needCopy(CacheObjectValueContext ctx) {
+        return ctx.copyOnGet() && val != null && !ctx.kernalContext().cacheObjects().immutable(val);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
index fe284ae..6a13f8d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
@@ -62,7 +62,7 @@ public class CacheObjectByteArrayImpl implements CacheObject, Externalizable {
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+    @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
         if (cpy)
             return (T)Arrays.copyOf(val, val.length);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
index a777ab6..655a3e3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
@@ -27,21 +27,17 @@ import java.util.Map;
 import org.apache.ignite.cache.affinity.AffinityKeyMapper;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.binary.BinaryUtils;
-import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
 import org.apache.ignite.internal.util.typedef.F;
 
 /**
  *
  */
 @SuppressWarnings("TypeMayBeWeakened")
-public class CacheObjectContext {
+public class CacheObjectContext implements CacheObjectValueContext {
     /** */
     private GridKernalContext kernalCtx;
 
     /** */
-    private IgniteCacheObjectProcessor proc;
-
-    /** */
     private String cacheName;
 
     /** */
@@ -54,9 +50,6 @@ public class CacheObjectContext {
     private boolean storeVal;
 
     /** */
-    private boolean p2pEnabled;
-
-    /** */
     private boolean addDepInfo;
 
     /**
@@ -78,9 +71,6 @@ public class CacheObjectContext {
         this.cpyOnGet = cpyOnGet;
         this.storeVal = storeVal;
         this.addDepInfo = addDepInfo;
-
-        p2pEnabled = kernalCtx.config().isPeerClassLoadingEnabled();
-        proc = kernalCtx.cacheObjects();
     }
 
     /**
@@ -90,31 +80,18 @@ public class CacheObjectContext {
         return cacheName;
     }
 
-    /**
-     * @return {@code True} if peer class loading is enabled.
-     */
-    public boolean p2pEnabled() {
-        return p2pEnabled;
-    }
-
-    /**
-     * @return {@code True} if deployment info should be associated with the objects of this cache.
-     */
-    public boolean addDeploymentInfo() {
+    /** {@inheritDoc} */
+    @Override public boolean addDeploymentInfo() {
         return addDepInfo;
     }
 
-    /**
-     * @return Copy on get flag.
-     */
-    public boolean copyOnGet() {
+    /** {@inheritDoc} */
+    @Override public boolean copyOnGet() {
         return cpyOnGet;
     }
 
-    /**
-     * @return {@code True} if should store unmarshalled value in cache.
-     */
-    public boolean storeValue() {
+    /** {@inheritDoc} */
+    @Override public boolean storeValue() {
         return storeVal;
     }
 
@@ -125,27 +102,14 @@ public class CacheObjectContext {
         return dfltAffMapper;
     }
 
-    /**
-     * @return Kernal context.
-     */
-    public GridKernalContext kernalContext() {
+    /** {@inheritDoc} */
+    @Override public GridKernalContext kernalContext() {
         return kernalCtx;
     }
 
-    /**
-     * @return Processor.
-     */
-    public IgniteCacheObjectProcessor processor() {
-        return proc;
-    }
-
-    /**
-     * @param o Object to unwrap.
-     * @param keepBinary Keep binary flag.
-     * @return Unwrapped object.
-     */
-    public Object unwrapBinaryIfNeeded(Object o, boolean keepBinary) {
-        return unwrapBinaryIfNeeded(o, keepBinary, true);
+    /** {@inheritDoc} */
+    @Override public boolean binaryEnabled() {
+        return false;
     }
 
     /**
@@ -158,141 +122,6 @@ public class CacheObjectContext {
         if (o == null)
             return null;
 
-        return unwrapBinary(o, keepBinary, cpy);
-    }
-
-    /**
-     * @param col Collection of objects to unwrap.
-     * @param keepBinary Keep binary flag.
-     * @return Unwrapped collection.
-     */
-    public Collection<Object> unwrapBinariesIfNeeded(Collection<Object> col, boolean keepBinary) {
-        return unwrapBinariesIfNeeded(col, keepBinary, true);
-    }
-
-    /**
-     * @param col Collection to unwrap.
-     * @param keepBinary Keep binary flag.
-     * @param cpy Copy value flag.
-     * @return Unwrapped collection.
-     */
-    public Collection<Object> unwrapBinariesIfNeeded(Collection<Object> col, boolean keepBinary, boolean cpy) {
-        Collection<Object> col0 = BinaryUtils.newKnownCollection(col);
-
-        if (col0 == null)
-            col0 = new ArrayList<>(col.size());
-
-        for (Object obj : col)
-            col0.add(unwrapBinary(obj, keepBinary, cpy));
-
-        return col0;
-    }
-
-    /**
-     * @param col Collection to unwrap.
-     * @param keepBinary Keep binary flag.
-     * @param cpy Copy flag.
-     * @return Unwrapped collection.
-     */
-    private Collection<Object> unwrapKnownCollection(Collection<Object> col, boolean keepBinary, boolean cpy) {
-        Collection<Object> col0 = BinaryUtils.newKnownCollection(col);
-
-        for (Object obj : col)
-            col0.add(unwrapBinary(obj, keepBinary, cpy));
-
-        return col0;
-    }
-
-    /**
-     * Unwrap array of binaries if needed.
-     *
-     * @param arr Array.
-     * @param keepBinary Keep binary flag.
-     * @param cpy Copy.
-     * @return Result.
-     */
-    public Object[] unwrapBinariesInArrayIfNeeded(Object[] arr, boolean keepBinary, boolean cpy) {
-        if (BinaryUtils.knownArray(arr))
-            return arr;
-
-        Object[] res = new Object[arr.length];
-
-        for (int i = 0; i < arr.length; i++)
-            res[i] = unwrapBinary(arr[i], keepBinary, cpy);
-
-        return res;
-    }
-
-    /**
-     * Unwraps map.
-     *
-     * @param map Map to unwrap.
-     * @param keepBinary Keep binary flag.
-     * @return Unwrapped collection.
-     */
-    private Map<Object, Object> unwrapBinariesIfNeeded(Map<Object, Object> map, boolean keepBinary, boolean cpy) {
-        if (keepBinary)
-            return map;
-
-        Map<Object, Object> map0 = BinaryUtils.newMap(map);
-
-        for (Map.Entry<Object, Object> e : map.entrySet())
-            map0.put(unwrapBinary(e.getKey(), keepBinary, cpy), unwrapBinary(e.getValue(), keepBinary, cpy));
-
-        return map0;
-    }
-
-    /**
-     * @param o Object to unwrap.
-     * @return Unwrapped object.
-     */
-    private Object unwrapBinary(Object o, boolean keepBinary, boolean cpy) {
-        if (o instanceof Map.Entry) {
-            Map.Entry entry = (Map.Entry)o;
-
-            Object key = entry.getKey();
-
-            Object uKey = unwrapBinary(key, keepBinary, cpy);
-
-            Object val = entry.getValue();
-
-            Object uVal = unwrapBinary(val, keepBinary, cpy);
-
-            return (key != uKey || val != uVal) ? F.t(uKey, uVal) : o;
-        }
-        else if (BinaryUtils.knownCollection(o))
-            return unwrapKnownCollection((Collection<Object>)o, keepBinary, cpy);
-        else if (BinaryUtils.knownMap(o))
-            return unwrapBinariesIfNeeded((Map<Object, Object>)o, keepBinary, cpy);
-        else if (o instanceof Object[])
-            return unwrapBinariesInArrayIfNeeded((Object[])o, keepBinary, cpy);
-        else if (o instanceof CacheObject) {
-            CacheObject co = (CacheObject)o;
-
-            if (!keepBinary || co.isPlatformType())
-                return unwrapBinary(co.value(this, cpy), keepBinary, cpy);
-        }
-
-        return o;
-    }
-
-    /**
-     * @param o Object to test.
-     * @return True if collection should be recursively unwrapped.
-     */
-    private boolean knownCollection(Object o) {
-        Class<?> cls = o == null ? null : o.getClass();
-
-        return cls == ArrayList.class || cls == LinkedList.class || cls == HashSet.class;
-    }
-
-    /**
-     * @param o Object to test.
-     * @return True if map should be recursively unwrapped.
-     */
-    private boolean knownMap(Object o) {
-        Class<?> cls = o == null ? null : o.getClass();
-
-        return cls == HashMap.class || cls == LinkedHashMap.class;
+        return CacheObjectUtils.unwrapBinaryIfNeeded(this, o, keepBinary, cpy);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
index 7fe4297..76f354a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
@@ -19,6 +19,8 @@ package org.apache.ignite.internal.processors.cache;
 
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -53,27 +55,31 @@ public class CacheObjectImpl extends CacheObjectAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+    @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
         cpy = cpy && needCopy(ctx);
 
         try {
+            GridKernalContext kernalCtx = ctx.kernalContext();
+
+            IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
+
             if (cpy) {
                 if (valBytes == null) {
                     assert val != null;
 
-                    valBytes = ctx.processor().marshal(ctx, val);
+                    valBytes = proc.marshal(ctx, val);
                 }
 
                 ClassLoader clsLdr;
 
                 if (val != null)
                     clsLdr = val.getClass().getClassLoader();
-                else if (ctx.kernalContext().config().isPeerClassLoadingEnabled())
-                    clsLdr = ctx.kernalContext().cache().context().deploy().globalLoader();
+                else if (kernalCtx.config().isPeerClassLoadingEnabled())
+                    clsLdr = kernalCtx.cache().context().deploy().globalLoader();
                 else
                     clsLdr = null;
 
-                return (T)ctx.processor().unmarshal(ctx, valBytes, clsLdr);
+                return (T)proc.unmarshal(ctx, valBytes, clsLdr);
             }
 
             if (val != null)
@@ -81,9 +87,8 @@ public class CacheObjectImpl extends CacheObjectAdapter {
 
             assert valBytes != null;
 
-            Object val = ctx.processor().unmarshal(ctx, valBytes,
-                ctx.kernalContext().config().isPeerClassLoadingEnabled() ?
-                    ctx.kernalContext().cache().context().deploy().globalLoader() : null);
+            Object val = proc.unmarshal(ctx, valBytes, kernalCtx.config().isPeerClassLoadingEnabled() ?
+                kernalCtx.cache().context().deploy().globalLoader() : null);
 
             if (ctx.storeValue())
                 this.val = val;
@@ -98,7 +103,7 @@ public class CacheObjectImpl extends CacheObjectAdapter {
     /** {@inheritDoc} */
     @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
         if (valBytes == null)
-            valBytes = ctx.processor().marshal(ctx, val);
+            valBytes = ctx.kernalContext().cacheObjects().marshal(ctx, val);
 
         return valBytes;
     }
@@ -116,7 +121,7 @@ public class CacheObjectImpl extends CacheObjectAdapter {
         assert val != null || valBytes != null;
 
         if (val == null && ctx.storeValue())
-            val = ctx.processor().unmarshal(ctx, valBytes, ldr);
+            val = ctx.kernalContext().cacheObjects().unmarshal(ctx, valBytes, ldr);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectUtils.java
new file mode 100644
index 0000000..f9c76df
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectUtils.java
@@ -0,0 +1,173 @@
+/*
+ * 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.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.util.typedef.F;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Cache object utility methods.
+ */
+public class CacheObjectUtils {
+    /**
+     * @param o Object to unwrap.
+     * @param keepBinary Keep binary flag.
+     * @param cpy Copy value flag.
+     * @return Unwrapped object.
+     */
+    public static Object unwrapBinaryIfNeeded(CacheObjectValueContext ctx, Object o, boolean keepBinary, boolean cpy) {
+        if (o == null)
+            return null;
+
+        return unwrapBinary(ctx, o, keepBinary, cpy);
+    }
+
+    /**
+     * @param col Collection of objects to unwrap.
+     * @param keepBinary Keep binary flag.
+     * @return Unwrapped collection.
+     */
+    public static Collection<Object> unwrapBinariesIfNeeded(CacheObjectValueContext ctx, Collection<Object> col,
+        boolean keepBinary) {
+        return unwrapBinariesIfNeeded(ctx, col, keepBinary, true);
+    }
+
+    /**
+     * @param col Collection to unwrap.
+     * @param keepBinary Keep binary flag.
+     * @param cpy Copy flag.
+     * @return Unwrapped collection.
+     */
+    private static Collection<Object> unwrapKnownCollection(CacheObjectValueContext ctx, Collection<Object> col,
+        boolean keepBinary, boolean cpy) {
+        Collection<Object> col0 = BinaryUtils.newKnownCollection(col);
+
+        assert col0 != null;
+
+        for (Object obj : col)
+            col0.add(unwrapBinary(ctx, obj, keepBinary, cpy));
+
+        return col0;
+    }
+
+    /**
+     * Unwraps map.
+     *
+     * @param map Map to unwrap.
+     * @param keepBinary Keep binary flag.
+     * @return Unwrapped collection.
+     */
+    private static Map<Object, Object> unwrapBinariesIfNeeded(CacheObjectValueContext ctx, Map<Object, Object> map,
+        boolean keepBinary, boolean cpy) {
+        if (keepBinary)
+            return map;
+
+        Map<Object, Object> map0 = BinaryUtils.newMap(map);
+
+        for (Map.Entry<Object, Object> e : map.entrySet())
+            map0.put(unwrapBinary(ctx, e.getKey(), false, cpy), unwrapBinary(ctx, e.getValue(), false, cpy));
+
+        return map0;
+    }
+
+    /**
+     * @param col Collection to unwrap.
+     * @param keepBinary Keep binary flag.
+     * @param cpy Copy value flag.
+     * @return Unwrapped collection.
+     */
+    private static Collection<Object> unwrapBinariesIfNeeded(CacheObjectValueContext ctx, Collection<Object> col,
+        boolean keepBinary, boolean cpy) {
+        Collection<Object> col0 = BinaryUtils.newKnownCollection(col);
+
+        if (col0 == null)
+            col0 = new ArrayList<>(col.size());
+
+        for (Object obj : col)
+            col0.add(unwrapBinary(ctx, obj, keepBinary, cpy));
+
+        return col0;
+    }
+
+    /**
+     * Unwrap array of binaries if needed.
+     *
+     * @param arr Array.
+     * @param keepBinary Keep binary flag.
+     * @param cpy Copy.
+     * @return Result.
+     */
+    private static Object[] unwrapBinariesInArrayIfNeeded(CacheObjectValueContext ctx, Object[] arr, boolean keepBinary,
+        boolean cpy) {
+        if (BinaryUtils.knownArray(arr))
+            return arr;
+
+        Object[] res = new Object[arr.length];
+
+        for (int i = 0; i < arr.length; i++)
+            res[i] = unwrapBinary(ctx, arr[i], keepBinary, cpy);
+
+        return res;
+    }
+
+    /**
+     * @param o Object to unwrap.
+     * @return Unwrapped object.
+     */
+    @SuppressWarnings("unchecked")
+    private static Object unwrapBinary(CacheObjectValueContext ctx, Object o, boolean keepBinary, boolean cpy) {
+        if (o instanceof Map.Entry) {
+            Map.Entry entry = (Map.Entry)o;
+
+            Object key = entry.getKey();
+
+            Object uKey = unwrapBinary(ctx, key, keepBinary, cpy);
+
+            Object val = entry.getValue();
+
+            Object uVal = unwrapBinary(ctx, val, keepBinary, cpy);
+
+            return (key != uKey || val != uVal) ? F.t(uKey, uVal) : o;
+        }
+        else if (BinaryUtils.knownCollection(o))
+            return unwrapKnownCollection(ctx, (Collection<Object>)o, keepBinary, cpy);
+        else if (BinaryUtils.knownMap(o))
+            return unwrapBinariesIfNeeded(ctx, (Map<Object, Object>)o, keepBinary, cpy);
+        else if (o instanceof Object[])
+            return unwrapBinariesInArrayIfNeeded(ctx, (Object[])o, keepBinary, cpy);
+        else if (o instanceof CacheObject) {
+            CacheObject co = (CacheObject)o;
+
+            if (!keepBinary || co.isPlatformType())
+                return unwrapBinary(ctx, co.value(ctx, cpy), keepBinary, cpy);
+        }
+
+        return o;
+    }
+
+    /**
+     * Private constructor.
+     */
+    private CacheObjectUtils() {
+        // No-op.
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectValueContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectValueContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectValueContext.java
new file mode 100644
index 0000000..49b2873
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectValueContext.java
@@ -0,0 +1,50 @@
+/*
+ * 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.internal.GridKernalContext;
+
+/**
+ * Context to get value of cache object.
+ */
+public interface CacheObjectValueContext {
+    /**
+     * @return Kernal context.
+     */
+    public GridKernalContext kernalContext();
+
+    /**
+     * @return Copy on get flag.
+     */
+    public boolean copyOnGet();
+
+    /**
+     * @return {@code True} if should store unmarshalled value in cache.
+     */
+    public boolean storeValue();
+
+    /**
+     * @return {@code True} if deployment info should be associated with the objects of this cache.
+     */
+    public boolean addDeploymentInfo();
+
+    /**
+     * @return Binary enabled flag.
+     */
+    public boolean binaryEnabled();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index a3e70dd..e637122 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -1713,7 +1713,7 @@ public class GridCacheContext<K, V> implements Externalizable {
      * @return Unwrapped collection.
      */
     public Collection<Object> unwrapBinariesIfNeeded(Collection<Object> col, boolean keepBinary) {
-        return cacheObjCtx.unwrapBinariesIfNeeded(col, keepBinary);
+        return CacheObjectUtils.unwrapBinariesIfNeeded(cacheObjCtx, col, keepBinary);
     }
 
     /**
@@ -1724,7 +1724,7 @@ public class GridCacheContext<K, V> implements Externalizable {
      * @return Unwrapped object.
      */
     public Object unwrapBinaryIfNeeded(Object o, boolean keepBinary) {
-        return cacheObjCtx.unwrapBinaryIfNeeded(o, keepBinary);
+        return unwrapBinaryIfNeeded(o, keepBinary, true);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
index 687b132..93c5950 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
@@ -309,7 +309,7 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
                 oldVal0 = cctx.cacheObjectContext().unwrapBinaryIfNeeded(oldVal, keepBinary, false);
             }
             catch (Exception e) {
-                if (!cctx.cacheObjectContext().processor().isBinaryEnabled(cctx.config()))
+                if (!cctx.cacheObjectContext().kernalContext().cacheObjects().isBinaryEnabled(cctx.config()))
                     throw e;
 
                 if (log.isDebugEnabled())

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index 15e4469..4f87658 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -3840,13 +3840,13 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
 
         /** {@inheritDoc} */
         @Override public K getKey() {
-            return (K)cctx.cacheObjectContext().unwrapBinaryIfNeeded(key, keepBinary);
+            return (K)cctx.cacheObjectContext().unwrapBinaryIfNeeded(key, keepBinary, true);
         }
 
         /** {@inheritDoc} */
         @SuppressWarnings("unchecked")
         @Override public V getValue() {
-            return (V)cctx.cacheObjectContext().unwrapBinaryIfNeeded(peekVisibleValue(), keepBinary);
+            return (V)cctx.cacheObjectContext().unwrapBinaryIfNeeded(peekVisibleValue(), keepBinary, true);
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
index b9efab1..c50672b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
@@ -75,7 +75,7 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
     /** {@inheritDoc} */
     @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
         if (valBytes == null)
-            valBytes = ctx.processor().marshal(ctx, val);
+            valBytes = ctx.kernalContext().cacheObjects().marshal(ctx, val);
 
         return valBytes;
     }
@@ -94,7 +94,7 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+    @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
         assert val != null;
 
         return (T)val;

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
index 26c713c..3b3cf67 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
@@ -53,10 +53,8 @@ public class CacheObjectBinaryContext extends CacheObjectContext {
         this.binaryEnabled = binaryEnabled;
     }
 
-    /**
-     * @return Binary enabled flag.
-     */
-    public boolean binaryEnabled() {
+    /** {@inheritDoc} */
+    @Override public boolean binaryEnabled() {
         return binaryEnabled;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
index 14947e9..5567809 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
@@ -59,6 +59,7 @@ import org.apache.ignite.internal.binary.streams.BinaryOffheapInputStream;
 import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheUtils;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
@@ -735,7 +736,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] marshal(CacheObjectContext ctx, Object val) throws IgniteCheckedException {
+    @Override public byte[] marshal(CacheObjectValueContext ctx, Object val) throws IgniteCheckedException {
         if (!((CacheObjectBinaryContext)ctx).binaryEnabled() || binaryMarsh == null)
             return super.marshal(ctx, val);
 
@@ -747,7 +748,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     }
 
     /** {@inheritDoc} */
-    @Override public Object unmarshal(CacheObjectContext ctx, byte[] bytes, ClassLoader clsLdr)
+    @Override public Object unmarshal(CacheObjectValueContext ctx, byte[] bytes, ClassLoader clsLdr)
         throws IgniteCheckedException {
         if (!((CacheObjectBinaryContext)ctx).binaryEnabled() || binaryMarsh == null)
             return super.unmarshal(ctx, bytes, clsLdr);

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
index afeada5..955ca69 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
@@ -283,7 +283,7 @@ public class CacheDataRowAdapter implements CacheDataRow {
             byte[] bytes = PageUtils.getBytes(addr, off, len);
             off += len;
 
-            key = coctx.processor().toKeyCacheObject(coctx, type, bytes);
+            key = coctx.kernalContext().cacheObjects().toKeyCacheObject(coctx, type, bytes);
 
             if (rowData == RowData.KEY_ONLY)
                 return;
@@ -300,7 +300,7 @@ public class CacheDataRowAdapter implements CacheDataRow {
         byte[] bytes = PageUtils.getBytes(addr, off, len);
         off += len;
 
-        val = coctx.processor().toCacheObject(coctx, type, bytes);
+        val = coctx.kernalContext().cacheObjects().toCacheObject(coctx, type, bytes);
 
         ver = CacheVersionIO.read(addr + off, false);
 
@@ -359,7 +359,7 @@ public class CacheDataRowAdapter implements CacheDataRow {
         ByteBuffer buf,
         IncompleteCacheObject incomplete
     ) throws IgniteCheckedException {
-        incomplete = coctx.processor().toKeyCacheObject(coctx, buf, incomplete);
+        incomplete = coctx.kernalContext().cacheObjects().toKeyCacheObject(coctx, buf, incomplete);
 
         if (incomplete.isReady()) {
             key = (KeyCacheObject)incomplete.object();
@@ -384,7 +384,7 @@ public class CacheDataRowAdapter implements CacheDataRow {
         ByteBuffer buf,
         IncompleteCacheObject incomplete
     ) throws IgniteCheckedException {
-        incomplete = coctx.processor().toCacheObject(coctx, buf, incomplete);
+        incomplete = coctx.kernalContext().cacheObjects().toCacheObject(coctx, buf, incomplete);
 
         if (incomplete.isReady()) {
             val = incomplete.object();

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 9ad084e..8c10e53 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -1728,7 +1728,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
                         for (KeyCacheObject cacheKey : lockKeys) {
                             K keyVal = (K)
                                 (keepCacheObjects ? cacheKey :
-                                    cacheCtx.cacheObjectContext().unwrapBinaryIfNeeded(cacheKey, !deserializeBinary));
+                                    cacheCtx.cacheObjectContext().unwrapBinaryIfNeeded(cacheKey, !deserializeBinary,
+                                        true));
 
                             if (retMap.containsKey(keyVal))
                                 // We already have a return value.

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlock.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlock.java
index 97db698..a613184 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlock.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlock.java
@@ -22,6 +22,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.util.typedef.T2;
@@ -133,15 +134,15 @@ public class TxDeadlock {
             IgniteTxKey txKey = e.getKey();
 
             try {
-                CacheObjectContext objCtx = ctx.cacheObjectContext(txKey.cacheId());
+                GridCacheContext cctx = ctx.cacheContext(txKey.cacheId());
 
-                Object val = txKey.key().value(objCtx, true);
+                Object val = txKey.key().value(cctx.cacheObjectContext(), true);
 
                 sb.append(e.getValue())
                     .append(" [key=")
                     .append(val)
                     .append(", cache=")
-                    .append(objCtx.cacheName())
+                    .append(cctx.name())
                     .append("]\n");
             }
             catch (Exception ex) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
index 9beb296..ee2d1f2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
@@ -27,6 +27,7 @@ import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.GridProcessor;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.IncompleteCacheObject;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
@@ -116,7 +117,7 @@ public interface IgniteCacheObjectProcessor extends GridProcessor {
      * @return Value bytes.
      * @throws IgniteCheckedException If failed.
      */
-    public byte[] marshal(CacheObjectContext ctx, Object val) throws IgniteCheckedException;
+    public byte[] marshal(CacheObjectValueContext ctx, Object val) throws IgniteCheckedException;
 
     /**
      * @param ctx Context.
@@ -125,7 +126,8 @@ public interface IgniteCacheObjectProcessor extends GridProcessor {
      * @return Unmarshalled object.
      * @throws IgniteCheckedException If failed.
      */
-    public Object unmarshal(CacheObjectContext ctx, byte[] bytes, ClassLoader clsLdr) throws IgniteCheckedException;
+    public Object unmarshal(CacheObjectValueContext ctx, byte[] bytes, ClassLoader clsLdr)
+        throws IgniteCheckedException;
 
     /**
      * @param ccfg Cache configuration.

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
index a8595fb..de9256c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
@@ -33,6 +33,7 @@ import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectByteArrayImpl;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
 import org.apache.ignite.internal.processors.cache.IncompleteCacheObject;
@@ -55,8 +56,8 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
     /** */
     private IgniteBinary noOpBinary = new NoOpBinary();
 
-    /**
-     *
+    /*
+     * Static initializer
      */
     static {
         IMMUTABLE_CLS.add(String.class);
@@ -99,12 +100,12 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] marshal(CacheObjectContext ctx, Object val) throws IgniteCheckedException {
+    @Override public byte[] marshal(CacheObjectValueContext ctx, Object val) throws IgniteCheckedException {
         return CU.marshal(ctx.kernalContext().cache().context(), ctx.addDeploymentInfo(), val);
     }
 
     /** {@inheritDoc} */
-    @Override public Object unmarshal(CacheObjectContext ctx, byte[] bytes, ClassLoader clsLdr)
+    @Override public Object unmarshal(CacheObjectValueContext ctx, byte[] bytes, ClassLoader clsLdr)
         throws IgniteCheckedException {
         return U.unmarshal(ctx.kernalContext(), bytes, U.resolveClassLoader(clsLdr, ctx.kernalContext().config()));
     }
@@ -166,7 +167,7 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
                 throw new IllegalArgumentException("Byte arrays cannot be used as cache keys.");
 
             case CacheObject.TYPE_REGULAR:
-                return new KeyCacheObjectImpl(ctx.processor().unmarshal(ctx, bytes, null), bytes, -1);
+                return new KeyCacheObjectImpl(ctx.kernalContext().cacheObjects().unmarshal(ctx, bytes, null), bytes, -1);
         }
 
         throw new IllegalArgumentException("Invalid object type: " + type);
@@ -392,14 +393,18 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
         /** {@inheritDoc} */
         @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
             try {
-                if (!ctx.processor().immutable(val)) {
+                IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
+
+                if (!proc.immutable(val)) {
                     if (valBytes == null)
-                        valBytes = ctx.processor().marshal(ctx, val);
+                        valBytes = proc.marshal(ctx, val);
+
+                    boolean p2pEnabled = ctx.kernalContext().config().isPeerClassLoadingEnabled();
 
-                    ClassLoader ldr = ctx.p2pEnabled() ?
+                    ClassLoader ldr = p2pEnabled ?
                         IgniteUtils.detectClassLoader(IgniteUtils.detectClass(this.val)) : U.gridClassLoader();
 
-                    Object val = ctx.processor().unmarshal(ctx, valBytes, ldr);
+                    Object val = proc.unmarshal(ctx, valBytes, ldr);
 
                     KeyCacheObject key = new KeyCacheObjectImpl(val, valBytes, partition());
 
@@ -443,22 +448,26 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+        @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
             return super.value(ctx, false); // Do not need copy since user value is not in cache.
         }
 
         /** {@inheritDoc} */
         @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
             try {
+                IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
+
                 if (valBytes == null)
-                    valBytes = ctx.processor().marshal(ctx, val);
+                    valBytes = proc.marshal(ctx, val);
 
                 if (ctx.storeValue()) {
-                    ClassLoader ldr = ctx.p2pEnabled() ?
+                    boolean p2pEnabled = ctx.kernalContext().config().isPeerClassLoadingEnabled();
+
+                    ClassLoader ldr = p2pEnabled ?
                         IgniteUtils.detectClass(this.val).getClassLoader() : val.getClass().getClassLoader();
 
-                    Object val = this.val != null && ctx.processor().immutable(this.val) ? this.val :
-                        ctx.processor().unmarshal(ctx, valBytes, ldr);
+                    Object val = this.val != null && proc.immutable(this.val) ? this.val :
+                        proc.unmarshal(ctx, valBytes, ldr);
 
                     return new CacheObjectImpl(val, valBytes);
                 }
@@ -493,7 +502,7 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+        @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
             return super.value(ctx, false); // Do not need copy since user value is not in cache.
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/query/CacheQueryObjectValueContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/CacheQueryObjectValueContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/CacheQueryObjectValueContext.java
new file mode 100644
index 0000000..08f71c8
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/CacheQueryObjectValueContext.java
@@ -0,0 +1,64 @@
+/*
+ * 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.query;
+
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
+
+/**
+ * Cache object value context for queries.
+ */
+public class CacheQueryObjectValueContext implements CacheObjectValueContext {
+    /** Kernal context. */
+    private final GridKernalContext ctx;
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Kernal context.
+     */
+    public CacheQueryObjectValueContext(GridKernalContext ctx) {
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridKernalContext kernalContext() {
+        return ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean copyOnGet() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean storeValue() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean addDeploymentInfo() {
+        return ctx.config().isPeerClassLoadingEnabled() && !binaryEnabled();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean binaryEnabled() {
+        return ctx.config().getMarshaller() instanceof BinaryMarshaller;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryCacheObjectsIterator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryCacheObjectsIterator.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryCacheObjectsIterator.java
index b006c75..b0e1562 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryCacheObjectsIterator.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryCacheObjectsIterator.java
@@ -20,7 +20,9 @@ package org.apache.ignite.internal.processors.query;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
-import org.apache.ignite.internal.processors.cache.GridCacheContext;
+
+import org.apache.ignite.internal.processors.cache.CacheObjectUtils;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.util.typedef.internal.U;
 
 /**
@@ -31,19 +33,20 @@ public class GridQueryCacheObjectsIterator implements Iterator<List<?>>, AutoClo
     private final Iterator<List<?>> iter;
 
     /** */
-    private final GridCacheContext<?,?> cctx;
+    private final CacheObjectValueContext cacheObjValCtx;
 
     /** */
     private final boolean keepBinary;
 
     /**
      * @param iter Iterator.
-     * @param cctx Cache context.
+     * @param cacheObjValCtx Cache object context.
      * @param keepBinary Keep binary.
      */
-    public GridQueryCacheObjectsIterator(Iterator<List<?>> iter, GridCacheContext<?,?> cctx, boolean keepBinary) {
+    public GridQueryCacheObjectsIterator(Iterator<List<?>> iter, CacheObjectValueContext cacheObjValCtx,
+        boolean keepBinary) {
         this.iter = iter;
-        this.cctx = cctx;
+        this.cacheObjValCtx = cacheObjValCtx;
         this.keepBinary = keepBinary;
     }
 
@@ -61,7 +64,8 @@ public class GridQueryCacheObjectsIterator implements Iterator<List<?>>, AutoClo
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override public List<?> next() {
-        return (List<?>)cctx.unwrapBinariesIfNeeded((Collection<Object>)iter.next(), keepBinary);
+        return ((List<?>)CacheObjectUtils.unwrapBinariesIfNeeded(
+            cacheObjValCtx, (Collection<Object>)iter.next(), keepBinary));
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 76cde17..65151c7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -1587,10 +1587,10 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         try {
             CacheObjectContext coctx = cacheObjectContext(cacheName);
 
-            QueryTypeDescriptorImpl desc = typeByValue(coctx, key, val, true);
+            QueryTypeDescriptorImpl desc = typeByValue(cacheName, coctx, key, val, true);
 
             if (prevVal != null) {
-                QueryTypeDescriptorImpl prevValDesc = typeByValue(coctx, key, prevVal, false);
+                QueryTypeDescriptorImpl prevValDesc = typeByValue(cacheName, coctx, key, prevVal, false);
 
                 if (prevValDesc != null && prevValDesc != desc)
                     idx.remove(cacheName, prevValDesc, key, partId, prevVal, prevVer);
@@ -1607,6 +1607,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @param cacheName Cache name.
      * @param coctx Cache context.
      * @param key Key.
      * @param val Value.
@@ -1615,7 +1616,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @throws IgniteCheckedException If type check failed.
      */
     @SuppressWarnings("ConstantConditions")
-    @Nullable private QueryTypeDescriptorImpl typeByValue(CacheObjectContext coctx,
+    @Nullable private QueryTypeDescriptorImpl typeByValue(String cacheName,
+        CacheObjectContext coctx,
         KeyCacheObject key,
         CacheObject val,
         boolean checkType)
@@ -1629,12 +1631,12 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         if (binaryVal) {
             int typeId = ctx.cacheObjects().typeId(val);
 
-            id = new QueryTypeIdKey(coctx.cacheName(), typeId);
+            id = new QueryTypeIdKey(cacheName, typeId);
         }
         else {
             valCls = val.value(coctx, false).getClass();
 
-            id = new QueryTypeIdKey(coctx.cacheName(), valCls);
+            id = new QueryTypeIdKey(cacheName, valCls);
         }
 
         QueryTypeDescriptorImpl desc = types.get(id);
@@ -2078,7 +2080,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         try {
             CacheObjectContext coctx = cacheObjectContext(cacheName);
 
-            QueryTypeDescriptorImpl desc = typeByValue(coctx, key, val, false);
+            QueryTypeDescriptorImpl desc = typeByValue(cacheName, coctx, key, val, false);
 
             if (desc == null)
                 return;

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridRunningQueryInfo.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridRunningQueryInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridRunningQueryInfo.java
index d77c8c0..9e11cdf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridRunningQueryInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridRunningQueryInfo.java
@@ -32,8 +32,8 @@ public class GridRunningQueryInfo {
     /** Query type. */
     private final GridCacheQueryType qryType;
 
-    /** */
-    private final String cache;
+    /** Schema name. */
+    private final String schemaName;
 
     /** */
     private final long startTime;
@@ -48,17 +48,17 @@ public class GridRunningQueryInfo {
      * @param id Query ID.
      * @param qry Query text.
      * @param qryType Query type.
-     * @param cache Cache where query was executed.
+     * @param schemaName Schema name.
      * @param startTime Query start time.
      * @param cancel Query cancel.
      * @param loc Local query flag.
      */
-    public GridRunningQueryInfo(Long id, String qry, GridCacheQueryType qryType, String cache, long startTime,
+    public GridRunningQueryInfo(Long id, String qry, GridCacheQueryType qryType, String schemaName, long startTime,
         GridQueryCancel cancel, boolean loc) {
         this.id = id;
         this.qry = qry;
         this.qryType = qryType;
-        this.cache = cache;
+        this.schemaName = schemaName;
         this.startTime = startTime;
         this.cancel = cancel;
         this.loc = loc;
@@ -86,10 +86,10 @@ public class GridRunningQueryInfo {
     }
 
     /**
-     * @return Cache where query was executed.
+     * @return Schema name.
      */
-    public String cache() {
-        return cache;
+    public String schemaName() {
+        return schemaName;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorRunningQueriesCollectorTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorRunningQueriesCollectorTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorRunningQueriesCollectorTask.java
index 8d00dd6..9d1da00 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorRunningQueriesCollectorTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorRunningQueriesCollectorTask.java
@@ -90,7 +90,7 @@ public class VisorRunningQueriesCollectorTask extends VisorMultiNodeTask<VisorRu
             long curTime = U.currentTimeMillis();
 
             for (GridRunningQueryInfo qry : queries)
-                res.add(new VisorRunningQuery(qry.id(), qry.query(), qry.queryType(), qry.cache(),
+                res.add(new VisorRunningQuery(qry.id(), qry.query(), qry.queryType(), qry.schemaName(),
                     qry.startTime(), curTime - qry.startTime(),
                     qry.cancelable(), qry.local()));
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
index a49e095..e144325 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridAffinityNoCacheSelfTest.java
@@ -26,6 +26,7 @@ import org.apache.ignite.cache.affinity.Affinity;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityImpl;
 import org.apache.ignite.internal.util.typedef.internal.A;
 import org.apache.ignite.plugin.extensions.communication.MessageReader;
@@ -235,7 +236,7 @@ public class GridAffinityNoCacheSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+        @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
             A.notNull(ctx, "ctx");
 
             return (T)val;

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteIncompleteCacheObjectSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteIncompleteCacheObjectSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteIncompleteCacheObjectSelfTest.java
index 5be277a..77b6836 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteIncompleteCacheObjectSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteIncompleteCacheObjectSelfTest.java
@@ -102,7 +102,7 @@ public class IgniteIncompleteCacheObjectSelfTest extends GridCommonAbstractTest
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override public <T> T value(final CacheObjectContext ctx, final boolean cpy) {
+        @Nullable @Override public <T> T value(final CacheObjectValueContext ctx, final boolean cpy) {
             return null;
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
index 5f61bd6..a487218 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
@@ -37,6 +37,7 @@ import org.apache.ignite.internal.pagemem.PageUtils;
 import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.database.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl;
@@ -463,7 +464,7 @@ public class FreeListImplSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+        @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
             return (T)data;
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
index 0474aeb..352fe85 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
@@ -282,7 +282,7 @@ public class DmlStatementsProcessor {
             QueryCursorImpl<List<?>> stepCur = new QueryCursorImpl<>(new Iterable<List<?>>() {
                 @Override public Iterator<List<?>> iterator() {
                     try {
-                        return new GridQueryCacheObjectsIterator(res.iterator(), cctx, cctx.keepBinary());
+                        return new GridQueryCacheObjectsIterator(res.iterator(), idx.valueContext(), cctx.keepBinary());
                     }
                     catch (IgniteCheckedException e) {
                         throw new IgniteException(e);
@@ -372,7 +372,7 @@ public class DmlStatementsProcessor {
             cur = new QueryCursorImpl<>(new Iterable<List<?>>() {
                 @Override public Iterator<List<?>> iterator() {
                     try {
-                        return new GridQueryCacheObjectsIterator(res.iterator(), cctx, cctx.keepBinary());
+                        return new GridQueryCacheObjectsIterator(res.iterator(), idx.valueContext(), cctx.keepBinary());
                     }
                     catch (IgniteCheckedException e) {
                         throw new IgniteException(e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/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 c94c215..508c8be 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
@@ -63,6 +63,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheEntryImpl;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheAffinityManager;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
@@ -78,6 +79,7 @@ import org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery;
 import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
 import org.apache.ignite.internal.processors.cache.query.QueryTable;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.processors.query.CacheQueryObjectValueContext;
 import org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator;
 import org.apache.ignite.internal.processors.query.GridQueryCancel;
 import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata;
@@ -303,6 +305,9 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     /** */
     protected volatile GridKernalContext ctx;
 
+    /** Cache object value context. */
+    protected CacheQueryObjectValueContext valCtx;
+
     /** */
     private DmlStatementsProcessor dmlProc;
 
@@ -339,14 +344,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /**
-     * @param cacheName Cache name.
-     * @return Connection.
-     */
-    public Connection connectionForCache(String cacheName) {
-        return connectionForSchema(schema(cacheName));
-    }
-
-    /**
      * @param schema Schema.
      * @return Connection.
      */
@@ -403,7 +400,9 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
     /** {@inheritDoc} */
     @Override public PreparedStatement prepareNativeStatement(String cacheName, String sql) throws SQLException {
-        return prepareStatement(connectionForCache(cacheName), sql, true);
+        String schemaName = schema(cacheName);
+
+        return prepareStatement(connectionForSchema(schemaName), sql, true);
     }
 
     /** {@inheritDoc} */
@@ -918,7 +917,9 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     /** {@inheritDoc} */
     @Override public long streamUpdateQuery(String cacheName, String qry,
         @Nullable Object[] params, IgniteDataStreamer<?, ?> streamer) throws IgniteCheckedException {
-        final Connection conn = connectionForCache(cacheName);
+        String schemaName = schema(cacheName);
+
+        final Connection conn = connectionForSchema(schemaName);
 
         final PreparedStatement stmt;
 
@@ -1117,7 +1118,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             QueryCursorImpl<List<?>> cursor = new QueryCursorImpl<>(new Iterable<List<?>>() {
                 @Override public Iterator<List<?>> iterator() {
                     try {
-                        return new GridQueryCacheObjectsIterator(res.iterator(), cctx, keepBinary);
+                        return new GridQueryCacheObjectsIterator(res.iterator(), valueContext(), keepBinary);
                     }
                     catch (IgniteCheckedException e) {
                         throw new IgniteException(e);
@@ -1231,7 +1232,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /**
-     * @param cctx Cache context.
+     * @param schemaName Schema name.
      * @param qry Query.
      * @param keepCacheObj Flag to keep cache object.
      * @param enforceJoinOrder Enforce join order of tables.
@@ -1239,7 +1240,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * @return Iterable result.
      */
     private Iterable<List<?>> runQueryTwoStep(
-        final GridCacheContext<?,?> cctx,
+        final String schemaName,
         final GridCacheTwoStepQuery qry,
         final boolean keepCacheObj,
         final boolean enforceJoinOrder,
@@ -1250,7 +1251,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     ) {
         return new Iterable<List<?>>() {
             @Override public Iterator<List<?>> iterator() {
-                return rdcQryExec.query(cctx, qry, keepCacheObj, enforceJoinOrder, timeoutMillis, cancel, params,
+                return rdcQryExec.query(schemaName, qry, keepCacheObj, enforceJoinOrder, timeoutMillis, cancel, params,
                     parts);
             }
         };
@@ -1484,7 +1485,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             cancel = new GridQueryCancel();
 
         QueryCursorImpl<List<?>> cursor = new QueryCursorImpl<>(
-            runQueryTwoStep(cctx, twoStepQry, keepBinary, enforceJoinOrder, qry.getTimeout(), cancel,
+            runQueryTwoStep(schemaName, twoStepQry, keepBinary, enforceJoinOrder, qry.getTimeout(), cancel,
                 qry.getArgs(), qry.getPartitions()), cancel);
 
         cursor.fieldsMeta(meta);
@@ -1900,12 +1901,14 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * @throws IgniteCheckedException If failed or {@code -1} if the type is unknown.
      */
     long size(String cacheName, String typeName) throws IgniteCheckedException {
+        String schemaName = schema(cacheName);
+
         H2TableDescriptor tbl = tableDescriptor(typeName, cacheName);
 
         if (tbl == null)
             return -1;
 
-        Connection conn = connectionForCache(cacheName);
+        Connection conn = connectionForSchema(schemaName);
 
         H2Utils.setupConnection(conn, false, false);
 
@@ -1999,6 +2002,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         else {
             this.ctx = ctx;
 
+            valCtx = new CacheQueryObjectValueContext(ctx);
+
             nodeId = ctx.localNodeId();
             marshaller = ctx.config().getMarshaller();
 
@@ -2031,6 +2036,13 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /**
+     * @return Value context.
+     */
+    public CacheObjectValueContext valueContext() {
+        return valCtx;
+    }
+
+    /**
      * @param topic Topic.
      * @param topicOrd Topic ordinal for {@link GridTopic}.
      * @param nodes Nodes.

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
index 48c0cb9..93ebc71 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
@@ -356,7 +356,7 @@ public class GridLuceneIndex implements AutoCloseable {
             if (coctx == null) // For tests.
                 return (Z)JdbcUtils.deserialize(bytes, null);
 
-            return (Z)coctx.processor().unmarshal(coctx, bytes, ldr);
+            return (Z)coctx.kernalContext().cacheObjects().unmarshal(coctx, bytes, ldr);
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/aad3b0c5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
index 6fff8de..b7bdde5 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
@@ -579,7 +579,9 @@ public class GridMapQueryExecutor {
                 }
             }
 
-            Connection conn = h2.connectionForCache(mainCctx.name());
+            String schemaName = h2.schema(mainCctx.name());
+
+            Connection conn = h2.connectionForSchema(schemaName);
 
             H2Utils.setupConnection(conn, distributedJoinMode != OFF, enforceJoinOrder);