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 2015/06/09 08:32:50 UTC

[01/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-545 aa1fbf60d -> 96f0956d6


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2a45704..6f8524f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,9 +20,8 @@
 <!--
     POM file.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-<modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
 
     <parent>
         <groupId>org.apache.ignite</groupId>
@@ -32,29 +31,22 @@
     </parent>
 
     <groupId>org.apache.ignite</groupId>
-    <artifactId>ignite</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <artifactId>apache-ignite</artifactId>
+    <version>1.2.0-SNAPSHOT</version>
     <packaging>pom</packaging>
 
     <properties>
-        <ignite.site>scp://localhost:/home</ignite.site>
-        <ignite.zip.pattern>ignite-${ignite.edition}-${project.version}-incubating</ignite.zip.pattern>
+        <!--fix <attachartifact>...< /> at apache-release profile if changed-->
+        <ignite.zip.pattern>${project.artifactId}-${ignite.edition}-${project.version}-bin</ignite.zip.pattern>
     </properties>
 
     <scm>
         <url>https://git-wip-us.apache.org/repos/asf/incubator-ignite</url>
-        <connection>scm:git:git://git-wip-us.apache.org/repos/asf/incubator-ignite</connection>
+        <connection>scm:git:https://git-wip-us.apache.org/repos/asf/incubator-ignite</connection>
         <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/incubator-ignite</developerConnection>
         <tag>HEAD</tag>
     </scm>
 
-    <distributionManagement>
-        <site>
-            <id>ignite-site</id>
-            <url>${ignite.site}/${project.artifactId}-${project.version}</url>
-        </site>
-    </distributionManagement>
-
     <modules>
         <module>modules/tools</module>
         <module>modules/core</module>
@@ -74,10 +66,10 @@
         <module>modules/log4j</module>
         <module>modules/slf4j</module>
         <module>modules/jcl</module>
-        <module>modules/schema-import</module>
         <module>modules/codegen</module>
         <module>modules/gce</module>
         <module>modules/cloud</module>
+        <module>modules/mesos</module>
     </modules>
 
     <profiles>
@@ -122,30 +114,6 @@
                 <plugins>
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-clean-plugin</artifactId>
-                        <executions>
-                            <execution>
-                                <phase>clean</phase>
-                                <goals>
-                                    <goal>clean</goal>
-                                </goals>
-                                <configuration>
-                                    <filesets>
-                                        <fileset>
-                                            <directory>libs</directory>
-                                        </fileset>
-
-                                        <fileset>
-                                            <directory>bin/include/schema-import</directory>
-                                        </fileset>
-                                    </filesets>
-                                </configuration>
-                            </execution>
-                        </executions>
-                    </plugin>
-
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-antrun-plugin</artifactId>
                         <version>1.7</version>
                         <inherited>false</inherited>
@@ -174,6 +142,7 @@
             <id>release</id>
             <activation>
                 <activeByDefault>true</activeByDefault>
+                <jdk>[1.7,)</jdk>
             </activation>
             <build>
                 <plugins>
@@ -278,7 +247,7 @@
                                         </replaceregexp>
 
                                         <replaceregexp byline="true">
-                                            <regexp pattern="\. &quot;\$\{SCRIPTS_HOME\}&quot;/include/target-classpath.sh(\s*#.*)?" />
+                                            <regexp pattern="\. &quot;\$\{SCRIPTS_HOME\}&quot;/include/build-classpath.sh(\s*#.*)?" />
                                             <substitution expression="" />
                                             <fileset dir="${basedir}/target/release-package/bin">
                                                 <include name="**/*.sh" />
@@ -286,7 +255,7 @@
                                         </replaceregexp>
 
                                         <replaceregexp byline="true">
-                                            <regexp pattern="call &quot;%SCRIPTS_HOME%\\include\\target-classpath.bat&quot;(\s*&amp;::.*)?" />
+                                            <regexp pattern="call &quot;%SCRIPTS_HOME%\\include\\build-classpath.bat&quot;(\s*&amp;::.*)?" />
                                             <substitution expression="" />
                                             <fileset dir="${basedir}/target/release-package/bin">
                                                 <include name="**/*.bat" />
@@ -323,6 +292,8 @@
                                             <substitution expression="${project.version}" />
                                         </replaceregexp>
 
+                                        <chmod dir="${basedir}/target/release-package" perm="755" includes="**/*.sh" />
+
                                         <zip destfile="${basedir}/target/bin/${ignite.zip.pattern}.zip" encoding="UTF-8">
                                             <zipfileset dir="${basedir}/target/release-package" prefix="${ignite.zip.pattern}" filemode="755">
                                                 <include name="**/*.sh" />
@@ -383,22 +354,6 @@
                             </execution>
 
                             <execution>
-                                <id>dependencies-schema-import</id>
-                                <phase>prepare-package</phase>
-                                <goals>
-                                    <goal>single</goal>
-                                </goals>
-                                <configuration>
-                                    <descriptors>
-                                        <descriptor>assembly/dependencies-schema-import.xml</descriptor>
-                                    </descriptors>
-                                    <outputDirectory>target/release-package/bin</outputDirectory>
-                                    <finalName>include</finalName>
-                                    <appendAssemblyId>false</appendAssemblyId>
-                                </configuration>
-                            </execution>
-
-                            <execution>
                                 <id>dependencies-visor-console</id>
                                 <phase>prepare-package</phase>
                                 <goals>
@@ -455,6 +410,7 @@
 
             <activation>
                 <activeByDefault>true</activeByDefault>
+                <jdk>[1.7,)</jdk>
             </activation>
 
             <modules>
@@ -481,6 +437,95 @@
         </profile>
 
         <profile>
+            <id>apache-release</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-assembly-plugin</artifactId>
+                        <dependencies>
+                            <dependency>
+                                <groupId>org.apache.apache.resources</groupId>
+                                <artifactId>apache-source-release-assembly-descriptor</artifactId>
+                                <version>1.0.4</version>
+                            </dependency>
+                        </dependencies>
+                        <executions>
+                            <execution>
+                                <id>source-release-assembly</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>single</goal>
+                                </goals>
+                                <configuration>
+                                    <runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>
+                                    <descriptorRefs>
+                                        <descriptorRef>${sourceReleaseAssemblyDescriptor}</descriptorRef>
+                                    </descriptorRefs>
+                                    <tarLongFileMode>gnu</tarLongFileMode>
+                                    <finalName>${project.artifactId}-${project.version}-src</finalName>
+                                    <appendAssemblyId>false</appendAssemblyId>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-antrun-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>attach-artifact</id><!-- allows to sign *bin.zip files -->
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>run</goal>
+                                </goals>
+                                <configuration>
+                                    <failOnError>false</failOnError>
+                                    <target>
+                                        <attachartifact file="${basedir}/target/bin/${project.artifactId}-fabric-${project.version}-bin.zip" classifier="fabric" type="zip" />
+                                        <attachartifact file="${basedir}/target/bin/${project.artifactId}-hadoop-${project.version}-bin.zip" classifier="hadoop" type="zip" />
+                                    </target>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-gpg-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>sign</goal>
+                                </goals>
+                                <configuration>
+                                    <ascDirectory>${basedir}</ascDirectory>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-remote-resources-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>process</goal>
+                                </goals>
+                                <configuration>
+                                    <!-- no <resourceBundle>, fix unexpected generation of
+                                       DEPENDENCIES, LICENSE, NOTICE files-->
+                                    <skip>true</skip>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+        <profile>
             <id>deploy-ignite-site</id>
             <build>
                 <plugins>
@@ -502,7 +547,8 @@
                                 <fileSet>
                                     <directory>${basedir}/target</directory>
                                     <includes>
-                                        <include>${project.artifactId}-${project.version}-source-release.zip</include>
+                                        <include>${project.artifactId}-${project.version}-src.zip</include>
+                                        <include>bin/*.zip</include>
                                     </includes>
                                 </fileSet>
                             </fileSets>
@@ -529,41 +575,141 @@
                                     <failOnError>false</failOnError>
                                     <target>
                                         <mkdir dir="${basedir}/target/site" />
-                                        <copy file="${basedir}/target/${project.artifactId}-${project.version}-source-release.zip" tofile="${basedir}/target/site/incubator-ignite-${project.version}-src.zip" failonerror="false" />
-                                        <copy file="${basedir}/target/${project.artifactId}-${project.version}-source-release.zip.asc" tofile="${basedir}/target/site/incubator-ignite-${project.version}-src.zip.asc" failonerror="false" />
-                                        <copy file="${basedir}/target/${project.artifactId}-${project.version}-source-release.zip.md5" tofile="${basedir}/target/site/incubator-ignite-${project.version}-src.zip.md5" failonerror="false" />
-                                        <copy file="${basedir}/target/${project.artifactId}-${project.version}-source-release.zip.sha1" tofile="${basedir}/target/site/incubator-ignite-${project.version}-src.zip.sha1" failonerror="false" />
+
+                                        <copy file="${basedir}/target/${project.artifactId}-${project.version}-src.zip" tofile="${basedir}/target/site/${project.artifactId}-${project.version}-src.zip" failonerror="false" />
+                                        <copy file="${basedir}/target/${project.artifactId}-${project.version}-src.zip.asc" tofile="${basedir}/target/site/${project.artifactId}-${project.version}-src.zip.asc" failonerror="false" />
+                                        <copy file="${basedir}/target/${project.artifactId}-${project.version}-src.zip.md5" tofile="${basedir}/target/site/${project.artifactId}-${project.version}-src.zip.md5" failonerror="false" />
+                                        <copy file="${basedir}/target/${project.artifactId}-${project.version}-src.zip.sha1" tofile="${basedir}/target/site/${project.artifactId}-${project.version}-src.zip.sha1" failonerror="false" />
+
                                         <copy todir="${basedir}/target/site">
                                             <fileset dir="${basedir}/target/bin">
                                                 <include name="**/*" />
                                             </fileset>
                                         </copy>
-                                        <copy file="${basedir}/KEYS" todir="${basedir}/target/site" />
+
+                                        <!-- appending filename to md5 and sha1 files. to be improved. -->
+                                        <concat destfile="${basedir}/target/site/${project.artifactId}-fabric-${project.version}-bin.zip.md5" append="true"> ${project.artifactId}-fabric-${project.version}-bin.zip</concat>
+                                        <concat destfile="${basedir}/target/site/${project.artifactId}-fabric-${project.version}-bin.zip.sha1" append="true"> ${project.artifactId}-fabric-${project.version}-bin.zip</concat>
+                                        <concat destfile="${basedir}/target/site/${project.artifactId}-hadoop-${project.version}-bin.zip.md5" append="true"> ${project.artifactId}-hadoop-${project.version}-bin.zip</concat>
+                                        <concat destfile="${basedir}/target/site/${project.artifactId}-hadoop-${project.version}-bin.zip.sha1" append="true"> ${project.artifactId}-hadoop-${project.version}-bin.zip</concat>
+                                        <concat destfile="${basedir}/target/site/${project.artifactId}-${project.version}-src.zip.md5" append="true"> ${project.artifactId}-${project.version}-src.zip</concat>
+                                        <concat destfile="${basedir}/target/site/${project.artifactId}-${project.version}-src.zip.sha1" append="true"> ${project.artifactId}-${project.version}-src.zip</concat>
+
+                                        <copy file="${basedir}/KEYS" todir="${basedir}/target/site" failonerror="false" />
                                     </target>
                                 </configuration>
                             </execution>
                         </executions>
                     </plugin>
+                </plugins>
+            </build>
+        </profile>
 
+        <profile>
+            <id>java8-schema-import</id>
+            <activation>
+                <file>
+                    <exists>${java.home}/lib/ext/jfxrt.jar</exists>
+                </file>
+            </activation>
+            <modules>
+                <module>modules/schema-import</module>
+            </modules>
+            <build>
+                <plugins>
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-site-plugin</artifactId>
-                        <version>3.4</version>
-                        <dependencies>
-                            <dependency>
-                                <groupId>org.apache.maven.wagon</groupId>
-                                <artifactId>wagon-ssh</artifactId>
-                                <version>2.8</version>
-                            </dependency>
-                        </dependencies>
+                        <artifactId>maven-assembly-plugin</artifactId>
+                        <version>2.4</version>
+                        <inherited>false</inherited>
+
+                        <executions>
+                            <execution>
+                                <id>dependencies-schema-import</id>
+                                <phase>prepare-package</phase>
+                                <goals>
+                                    <goal>single</goal>
+                                </goals>
+                                <configuration>
+                                    <descriptors>
+                                        <descriptor>assembly/dependencies-schema-import.xml</descriptor>
+                                    </descriptors>
+                                    <outputDirectory>target/release-package/bin</outputDirectory>
+                                    <finalName>include</finalName>
+                                    <appendAssemblyId>false</appendAssemblyId>
+                                </configuration>
+                            </execution>
+
+                            <execution>
+                                <id>schema-import-scripts</id>
+                                <phase>prepare-package</phase>
+                                <goals>
+                                    <goal>single</goal>
+                                </goals>
+                                <configuration>
+                                    <descriptors>
+                                        <descriptor>assembly/release-schema-import.xml</descriptor>
+                                    </descriptors>
+                                    <outputDirectory>target/release-package</outputDirectory>
+                                    <finalName>bin</finalName>
+                                    <appendAssemblyId>false</appendAssemblyId>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+
+        <profile>
+            <id>schema-import</id>
+            <activation>
+                <file>
+                    <exists>${java.home}/lib/jfxrt.jar</exists>
+                </file>
+            </activation>
+            <modules>
+                <module>modules/schema-import</module>
+            </modules>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-assembly-plugin</artifactId>
+                        <version>2.4</version>
+                        <inherited>false</inherited>
+
                         <executions>
                             <execution>
+                                <id>dependencies-schema-import</id>
+                                <phase>prepare-package</phase>
                                 <goals>
-                                    <goal>deploy</goal>
+                                    <goal>single</goal>
+                                </goals>
+                                <configuration>
+                                    <descriptors>
+                                        <descriptor>assembly/dependencies-schema-import.xml</descriptor>
+                                    </descriptors>
+                                    <outputDirectory>target/release-package/bin</outputDirectory>
+                                    <finalName>include</finalName>
+                                    <appendAssemblyId>false</appendAssemblyId>
+                                </configuration>
+                            </execution>
+
+                            <execution>
+                                <id>schema-import-scripts</id>
+                                <phase>prepare-package</phase>
+                                <goals>
+                                    <goal>single</goal>
                                 </goals>
-                                <phase>deploy</phase>
                                 <configuration>
-                                    <inputDirectory>${basedir}/target/site</inputDirectory>
+                                    <descriptors>
+                                        <descriptor>assembly/release-schema-import.xml</descriptor>
+                                    </descriptors>
+                                    <outputDirectory>target/release-package</outputDirectory>
+                                    <finalName>bin</finalName>
+                                    <appendAssemblyId>false</appendAssemblyId>
                                 </configuration>
                             </execution>
                         </executions>
@@ -572,4 +718,28 @@
             </build>
         </profile>
     </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-clean-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>clean</phase>
+                        <goals>
+                            <goal>clean</goal>
+                        </goals>
+                        <configuration>
+                            <filesets>
+                                <fileset>
+                                    <directory>libs</directory>
+                                </fileset>
+                            </filesets>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/scripts/git-patch-prop.sh
----------------------------------------------------------------------
diff --git a/scripts/git-patch-prop.sh b/scripts/git-patch-prop.sh
index 9c52583..c856fb4 100644
--- a/scripts/git-patch-prop.sh
+++ b/scripts/git-patch-prop.sh
@@ -19,6 +19,6 @@
 #
 # Git patch-file maker/applier properties.
 #
-IGNITE_DEFAULT_BRANCH='ignite-sprint-3'
+IGNITE_DEFAULT_BRANCH='ignite-sprint-5'
 
 PATCHES_HOME=${IGNITE_HOME}


[13/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 2ed6c62..cd4d543 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
@@ -24,6 +24,7 @@ import org.apache.ignite.cache.query.annotations.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.managers.communication.*;
 import org.apache.ignite.internal.processors.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.cache.query.*;
@@ -35,6 +36,7 @@ import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.internal.util.worker.*;
 import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.apache.ignite.spi.indexing.*;
 import org.jetbrains.annotations.*;
 import org.jsr166.*;
@@ -391,27 +393,39 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @param space Space name.
+     * @return Cache object context.
+     */
+    private CacheObjectContext cacheObjectContext(String space) {
+        return ctx.cache().internalCache(space).context().cacheObjectContext();
+    }
+
+    /**
      * Writes key-value pair to index.
      *
      * @param space Space.
      * @param key Key.
-     * @param keyBytes Byte array with key data.
      * @param val Value.
-     * @param valBytes Byte array with value data.
      * @param ver Cache entry version.
      * @param expirationTime Expiration time or 0 if never expires.
      * @throws IgniteCheckedException In case of error.
      */
     @SuppressWarnings("unchecked")
-    public <K, V> void store(final String space, final K key, @Nullable byte[] keyBytes, final V val,
-        @Nullable byte[] valBytes, byte[] ver, long expirationTime) throws IgniteCheckedException {
+    public void store(final String space, final CacheObject key, final CacheObject val,
+        byte[] ver, long expirationTime) throws IgniteCheckedException {
         assert key != null;
         assert val != null;
 
         if (log.isDebugEnabled())
             log.debug("Store [space=" + space + ", key=" + key + ", val=" + val + "]");
 
-        ctx.indexing().store(space, key, val, expirationTime);
+        CacheObjectContext coctx = null;
+
+        if (ctx.indexing().enabled()) {
+            coctx = cacheObjectContext(space);
+
+            ctx.indexing().store(space, key.value(coctx, false), val.value(coctx, false), expirationTime);
+        }
 
         if (idx == null)
             return;
@@ -420,7 +434,10 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             throw new IllegalStateException("Failed to write to index (grid is stopping).");
 
         try {
-            final Class<?> valCls = val.getClass();
+            if (coctx == null)
+                coctx = cacheObjectContext(space);
+
+            Class<?> valCls = null;
 
             TypeId id;
 
@@ -431,8 +448,11 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                 id = new TypeId(space, typeId);
             }
-            else
+            else {
+                valCls = val.value(coctx, false).getClass();
+
                 id = new TypeId(space, valCls);
+            }
 
             TypeDescriptor desc = types.get(id);
 
@@ -444,9 +464,13 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                     "(multiple classes with same simple name are stored in the same cache) " +
                     "[expCls=" + desc.valueClass().getName() + ", actualCls=" + valCls.getName() + ']');
 
-            if (!ctx.cacheObjects().isPortableObject(key) && !desc.keyClass().isAssignableFrom(key.getClass()))
-                throw new IgniteCheckedException("Failed to update index, incorrect key class [expCls=" +
-                    desc.keyClass().getName() + ", actualCls=" + key.getClass().getName() + "]");
+            if (!ctx.cacheObjects().isPortableObject(key)) {
+                Class<?> keyCls = key.value(coctx, false).getClass();
+
+                if (!desc.keyClass().isAssignableFrom(keyCls))
+                    throw new IgniteCheckedException("Failed to update index, incorrect key class [expCls=" +
+                        desc.keyClass().getName() + ", actualCls=" + keyCls.getName() + "]");
+            }
 
             idx.store(space, desc, key, val, ver, expirationTime);
         }
@@ -628,6 +652,13 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @return Message factory for {@link GridIoManager}.
+     */
+    public MessageFactory messageFactory() {
+        return idx == null ? null : idx.messageFactory();
+    }
+
+    /**
      * Closeable iterator.
      */
     private static interface ClIter<X> extends AutoCloseable, Iterator<X> {
@@ -687,13 +718,17 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @throws IgniteCheckedException Thrown in case of any errors.
      */
     @SuppressWarnings("unchecked")
-    public void remove(String space, Object key, Object val) throws IgniteCheckedException {
+    public void remove(String space, CacheObject key, CacheObject val) throws IgniteCheckedException {
         assert key != null;
 
         if (log.isDebugEnabled())
             log.debug("Remove [space=" + space + ", key=" + key + ", val=" + val + "]");
 
-        ctx.indexing().remove(space, key);
+        if (ctx.indexing().enabled()) {
+            CacheObjectContext coctx = cacheObjectContext(space);
+
+            ctx.indexing().remove(space, key.value(coctx, false));
+        }
 
         if (idx == null)
             return;
@@ -795,11 +830,15 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param key key.
      * @throws IgniteCheckedException If failed.
      */
-    public void onSwap(String spaceName, Object key) throws IgniteCheckedException {
+    public void onSwap(String spaceName, CacheObject key) throws IgniteCheckedException {
         if (log.isDebugEnabled())
             log.debug("Swap [space=" + spaceName + ", key=" + key + "]");
 
-        ctx.indexing().onSwap(spaceName, key);
+        if (ctx.indexing().enabled()) {
+            CacheObjectContext coctx = cacheObjectContext(spaceName);
+
+            ctx.indexing().onSwap(spaceName, key.value(coctx, false));
+        }
 
         if (idx == null)
             return;
@@ -821,15 +860,18 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param spaceName Space name.
      * @param key Key.
      * @param val Value.
-     * @param valBytes Value bytes.
      * @throws IgniteCheckedException If failed.
      */
-    public void onUnswap(String spaceName, Object key, Object val, byte[] valBytes)
+    public void onUnswap(String spaceName, CacheObject key, CacheObject val)
         throws IgniteCheckedException {
         if (log.isDebugEnabled())
             log.debug("Unswap [space=" + spaceName + ", key=" + key + ", val=" + val + "]");
 
-        ctx.indexing().onUnswap(spaceName, key, val);
+        if (ctx.indexing().enabled()) {
+            CacheObjectContext coctx = cacheObjectContext(spaceName);
+
+            ctx.indexing().onUnswap(spaceName, key.value(coctx, false), val.value(coctx, false));
+        }
 
         if (idx == null)
             return;
@@ -838,7 +880,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             throw new IllegalStateException("Failed to process swap event (grid is stopping).");
 
         try {
-            idx.onUnswap(spaceName, key, val, valBytes);
+            idx.onUnswap(spaceName, key, val);
         }
         finally {
             busyLock.leaveBusy();
@@ -894,10 +936,19 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param parent Parent in case of embeddable.
      * @throws IgniteCheckedException In case of error.
      */
-    static void processAnnotationsInClass(boolean key, Class<?> cls, TypeDescriptor type,
+    private void processAnnotationsInClass(boolean key, Class<?> cls, TypeDescriptor type,
         @Nullable ClassProperty parent) throws IgniteCheckedException {
-        if (U.isJdk(cls))
+        if (U.isJdk(cls) || idx.isGeometryClass(cls)) {
+            if (parent == null && !key && idx.isSqlType(cls) ) { // We have to index primitive _val.
+                String idxName = "_val_idx";
+
+                type.addIndex(idxName, idx.isGeometryClass(cls) ? GEO_SPATIAL : SORTED);
+
+                type.addFieldToIndex(idxName, "_VAL", 0, false);
+            }
+
             return;
+        }
 
         if (parent != null && parent.knowsClass(cls))
             throw new IgniteCheckedException("Recursive reference found in type: " + cls.getName());
@@ -969,7 +1020,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param desc Class description.
      * @throws IgniteCheckedException In case of error.
      */
-    static void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTextField txtAnn,
+    private void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTextField txtAnn,
         Class<?> cls, ClassProperty prop, TypeDescriptor desc) throws IgniteCheckedException {
         if (sqlAnn != null) {
             processAnnotationsInClass(key, cls, desc, prop);
@@ -980,7 +1031,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             if (sqlAnn.index()) {
                 String idxName = prop.name() + "_idx";
 
-                desc.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+                desc.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
                 desc.addFieldToIndex(idxName, prop.name(), 0, sqlAnn.descending());
             }
@@ -1007,7 +1058,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param d Type descriptor.
      * @throws IgniteCheckedException If failed.
      */
-    static void processClassMeta(CacheTypeMetadata meta, TypeDescriptor d)
+    private void processClassMeta(CacheTypeMetadata meta, TypeDescriptor d)
         throws IgniteCheckedException {
         Class<?> keyCls = d.keyClass();
         Class<?> valCls = d.valueClass();
@@ -1022,7 +1073,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, false);
         }
@@ -1034,7 +1085,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, true);
         }
@@ -1094,7 +1145,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, false);
         }
@@ -1106,7 +1157,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, true);
         }
@@ -1279,31 +1330,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
-     * @param cls Field type.
-     * @return {@code True} if given type is a spatial geometry type based on {@code com.vividsolutions.jts} library.
-     * @throws IgniteCheckedException If failed.
-     */
-    private static boolean isGeometryClass(Class<?> cls) throws IgniteCheckedException { // TODO optimize
-        Class<?> dataTypeCls;
-
-        try {
-            dataTypeCls = Class.forName("org.h2.value.DataType");
-        }
-        catch (ClassNotFoundException ignored) {
-            return false; // H2 is not in classpath.
-        }
-
-        try {
-            Method method = dataTypeCls.getMethod("isGeometryClass", Class.class);
-
-            return (Boolean)method.invoke(null, cls);
-        }
-        catch (Exception e) {
-            throw new IgniteCheckedException("Failed to invoke 'org.h2.value.DataType.isGeometryClass' method.", e);
-        }
-    }
-
-    /**
      *
      */
     private abstract static class Property {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryNextPageResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryNextPageResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryNextPageResponse.java
index b7b6f4c..4fdc027 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryNextPageResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryNextPageResponse.java
@@ -23,6 +23,7 @@ import org.apache.ignite.plugin.extensions.communication.*;
 
 import java.io.*;
 import java.nio.*;
+import java.util.*;
 
 /**
  * Next page response.
@@ -44,11 +45,15 @@ public class GridQueryNextPageResponse implements Message {
     private int allRows;
 
     /** */
-    private byte[] rows;
+    private int cols;
+
+    /** */
+    @GridDirectCollection(Message.class)
+    private Collection<Message> vals;
 
     /** */
     @GridDirectTransient
-    private transient Object plainRows;
+    private transient Collection<?> plainRows;
 
     /**
      * For {@link Externalizable}.
@@ -62,18 +67,21 @@ public class GridQueryNextPageResponse implements Message {
      * @param qry Query.
      * @param page Page.
      * @param allRows All rows count.
-     * @param rows Rows.
+     * @param cols Number of columns in row.
+     * @param vals Values for rows in this page added sequentially.
      * @param plainRows Not marshalled rows for local node.
      */
-    public GridQueryNextPageResponse(long qryReqId, int qry, int page, int allRows,
-        byte[] rows, Object plainRows) {
-        assert rows != null ^ plainRows != null;
+    public GridQueryNextPageResponse(long qryReqId, int qry, int page, int allRows, int cols,
+        Collection<Message> vals, Collection<?> plainRows) {
+        assert vals != null ^ plainRows != null;
+        assert cols > 0 : cols;
 
         this.qryReqId = qryReqId;
         this.qry = qry;
         this.page = page;
         this.allRows = allRows;
-        this.rows = rows;
+        this.cols = cols;
+        this.vals = vals;
         this.plainRows = plainRows;
     }
 
@@ -106,16 +114,23 @@ public class GridQueryNextPageResponse implements Message {
     }
 
     /**
-     * @return Rows.
+     * @return Columns in row.
      */
-    public byte[] rows() {
-        return rows;
+    public int columns() {
+        return cols;
+    }
+
+    /**
+     * @return Values.
+     */
+    public Collection<Message> values() {
+        return vals;
     }
 
     /**
      * @return Plain rows.
      */
-    public Object plainRows() {
+    public Collection<?> plainRows() {
         return plainRows;
     }
 
@@ -143,29 +158,34 @@ public class GridQueryNextPageResponse implements Message {
                 writer.incrementState();
 
             case 1:
-                if (!writer.writeInt("page", page))
+                if (!writer.writeInt("cols", cols))
                     return false;
 
                 writer.incrementState();
 
             case 2:
-                if (!writer.writeInt("qry", qry))
+                if (!writer.writeInt("page", page))
                     return false;
 
                 writer.incrementState();
 
             case 3:
-                if (!writer.writeLong("qryReqId", qryReqId))
+                if (!writer.writeInt("qry", qry))
                     return false;
 
                 writer.incrementState();
 
             case 4:
-                if (!writer.writeByteArray("rows", rows))
+                if (!writer.writeLong("qryReqId", qryReqId))
                     return false;
 
                 writer.incrementState();
 
+            case 5:
+                if (!writer.writeCollection("vals", vals, MessageCollectionItemType.MSG))
+                    return false;
+
+                writer.incrementState();
         }
 
         return true;
@@ -188,7 +208,7 @@ public class GridQueryNextPageResponse implements Message {
                 reader.incrementState();
 
             case 1:
-                page = reader.readInt("page");
+                cols = reader.readInt("cols");
 
                 if (!reader.isLastRead())
                     return false;
@@ -196,7 +216,7 @@ public class GridQueryNextPageResponse implements Message {
                 reader.incrementState();
 
             case 2:
-                qry = reader.readInt("qry");
+                page = reader.readInt("page");
 
                 if (!reader.isLastRead())
                     return false;
@@ -204,7 +224,7 @@ public class GridQueryNextPageResponse implements Message {
                 reader.incrementState();
 
             case 3:
-                qryReqId = reader.readLong("qryReqId");
+                qry = reader.readInt("qry");
 
                 if (!reader.isLastRead())
                     return false;
@@ -212,7 +232,15 @@ public class GridQueryNextPageResponse implements Message {
                 reader.incrementState();
 
             case 4:
-                rows = reader.readByteArray("rows");
+                qryReqId = reader.readLong("qryReqId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 5:
+                vals = reader.readCollection("vals", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
                     return false;
@@ -231,6 +259,6 @@ public class GridQueryNextPageResponse implements Message {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 5;
+        return 6;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryRequest.java
index b4c6668..3d3bcf9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/messages/GridQueryRequest.java
@@ -22,7 +22,6 @@ import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.query.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.marshaller.*;
 import org.apache.ignite.plugin.extensions.communication.*;
 
 import java.nio.*;
@@ -46,12 +45,9 @@ public class GridQueryRequest implements Message {
 
     /** */
     @GridToStringInclude
-    @GridDirectTransient
+    @GridDirectCollection(GridCacheSqlQuery.class)
     private Collection<GridCacheSqlQuery> qrys;
 
-    /** */
-    private byte[] qrysBytes;
-
     /**
      * Default constructor.
      */
@@ -64,17 +60,13 @@ public class GridQueryRequest implements Message {
      * @param pageSize Page size.
      * @param space Space.
      * @param qrys Queries.
-     * @param qrysBytes Marshalled queries.
      */
-    public GridQueryRequest(long reqId, int pageSize, String space, Collection<GridCacheSqlQuery> qrys, byte[] qrysBytes) {
+    public GridQueryRequest(long reqId, int pageSize, String space, Collection<GridCacheSqlQuery> qrys) {
         this.reqId = reqId;
         this.pageSize = pageSize;
         this.space = space;
 
-        assert qrysBytes != null;
-
         this.qrys = qrys;
-        this.qrysBytes = qrysBytes;
     }
 
     /**
@@ -101,10 +93,7 @@ public class GridQueryRequest implements Message {
     /**
      * @return Queries.
      */
-    public Collection<GridCacheSqlQuery> queries(Marshaller m) throws IgniteCheckedException {
-        if (qrys == null && qrysBytes != null)
-            qrys = m.unmarshal(qrysBytes, null);
-
+    public Collection<GridCacheSqlQuery> queries() throws IgniteCheckedException {
         return qrys;
     }
 
@@ -132,7 +121,7 @@ public class GridQueryRequest implements Message {
                 writer.incrementState();
 
             case 1:
-                if (!writer.writeByteArray("qrysBytes", qrysBytes))
+                if (!writer.writeCollection("qrys", qrys, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
@@ -171,7 +160,7 @@ public class GridQueryRequest implements Message {
                 reader.incrementState();
 
             case 1:
-                qrysBytes = reader.readByteArray("qrysBytes");
+                qrys = reader.readCollection("qrys", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
                     return false;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceField.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceField.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceField.java
index 6b921f4..fed7ebd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceField.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceField.java
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.*;
 
 import java.lang.annotation.*;
 import java.lang.reflect.*;
+import java.util.*;
 
 /**
  * Wrapper for data where resource should be injected.
@@ -43,10 +44,7 @@ class GridResourceField {
      * @param field Field where resource should be injected.
      * @param ann Resource annotation.
      */
-    GridResourceField(Field field, @Nullable Annotation ann) {
-        assert field != null;
-        assert ann != null || GridResourceUtils.mayRequireResources(field);
-
+    GridResourceField(@NotNull Field field, @NotNull Annotation ann) {
         this.field = field;
         this.ann = ann;
 
@@ -78,6 +76,16 @@ class GridResourceField {
         return ann == null;
     }
 
+    /**
+     * @param c Closure.
+     */
+    public static GridResourceField[] toArray(Collection<GridResourceField> c) {
+        if (c.isEmpty())
+            return EMPTY_ARRAY;
+
+        return c.toArray(new GridResourceField[c.size()]);
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(GridResourceField.class, this);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceIoc.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceIoc.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceIoc.java
index 8410e71..1e85ecd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceIoc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceIoc.java
@@ -21,6 +21,7 @@ import org.apache.ignite.*;
 import org.apache.ignite.internal.managers.deployment.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
 import org.jetbrains.annotations.*;
 import org.jsr166.*;
 
@@ -38,20 +39,8 @@ class GridResourceIoc {
     private final ConcurrentMap<ClassLoader, Set<Class<?>>> taskMap =
         new ConcurrentHashMap8<>();
 
-    /** Field cache. */
-    private final ConcurrentMap<Class<?>, ConcurrentMap<Class<? extends Annotation>, GridResourceField[]>> fieldCache =
-        new ConcurrentHashMap8<>();
-
-    /** Method cache. */
-    private final ConcurrentMap<Class<?>, ConcurrentMap<Class<? extends Annotation>, GridResourceMethod[]>> mtdCache =
-        new ConcurrentHashMap8<>();
-
-    /**
-     * Cache for classes that do not require injection with some annotation.
-     * Maps annotation classes to set a set of target classes to skip.
-     */
-    private final ConcurrentMap<Class<? extends Annotation>, Set<Class<?>>> skipCache =
-        new ConcurrentHashMap8<>();
+    /** Class descriptors cache. */
+    private final ConcurrentMap<Class<?>, ClassDescriptor> clsDescs = new ConcurrentHashMap8<>();
 
     /** */
     private final ConcurrentMap<Class<?>, Class<? extends Annotation>[]> annCache =
@@ -64,18 +53,8 @@ class GridResourceIoc {
         Set<Class<?>> clss = taskMap.remove(ldr);
 
         if (clss != null) {
-            fieldCache.keySet().removeAll(clss);
-            mtdCache.keySet().removeAll(clss);
-
-            for (Map.Entry<Class<? extends Annotation>, Set<Class<?>>> e : skipCache.entrySet()) {
-                Set<Class<?>> skipClss = e.getValue();
-
-                if (skipClss != null)
-                    e.getValue().removeAll(clss);
-            }
-
-            for (Class<?> cls : clss)
-                annCache.remove(cls);
+            clsDescs.keySet().removeAll(clss);
+            annCache.keySet().removeAll(clss);
         }
     }
 
@@ -84,8 +63,8 @@ class GridResourceIoc {
      */
     void undeployAll() {
         taskMap.clear();
-        mtdCache.clear();
-        fieldCache.clear();
+        clsDescs.clear();
+        annCache.clear();
     }
 
     /**
@@ -107,15 +86,26 @@ class GridResourceIoc {
         @Nullable Class<?> depCls)
         throws IgniteCheckedException
     {
-        assert target != null;
-        assert annCls != null;
-        assert injector != null;
+        return injectInternal(target, annCls, injector, dep, depCls, null);
+    }
 
-        if (isAnnotationPresent(target, annCls, dep))
-            // Use identity hash set to compare via referential equality.
-            return injectInternal(target, annCls, injector, dep, depCls, new GridLeanIdentitySet<>());
+    /**
+     * @param cls Class.
+     */
+    private ClassDescriptor descriptor(@Nullable GridDeployment dep, Class<?> cls) {
+        ClassDescriptor res = clsDescs.get(cls);
 
-        return false;
+        if (res == null) {
+            if (dep != null) {
+                Set<Class<?>> classes = F.addIfAbsent(taskMap, dep.classLoader(), F.<Class<?>>newCSet());
+
+                classes.add(cls);
+            }
+
+            res = F.addIfAbsent(clsDescs, cls, new ClassDescriptor(cls));
+        }
+
+        return res;
     }
 
     /**
@@ -133,73 +123,54 @@ class GridResourceIoc {
         GridResourceInjector injector,
         @Nullable GridDeployment dep,
         @Nullable Class<?> depCls,
-        Set<Object> checkedObjs)
+        @Nullable Set<Object> checkedObjs)
         throws IgniteCheckedException
     {
-        assert target != null;
-        assert annCls != null;
-        assert injector != null;
-        assert checkedObjs != null;
-
         Class<?> targetCls = target.getClass();
 
-        Set<Class<?>> skipClss = skipCache.get(annCls);
+        ClassDescriptor descr = descriptor(dep, targetCls);
 
-        // Skip this class if it does not need to be injected.
-        if (skipClss != null && skipClss.contains(targetCls))
-            return false;
+        T2<GridResourceField[], GridResourceMethod[]> annotatedMembers = descr.annotatedMembers(annCls);
 
-        // Check if already inspected to avoid indefinite recursion.
-        if (!checkedObjs.add(target))
+        if (descr.recursiveFields().length == 0 && annotatedMembers == null)
             return false;
 
-        int annCnt = 0;
+        if (checkedObjs == null && descr.recursiveFields().length > 0)
+            checkedObjs = new GridLeanIdentitySet<>();
 
-        boolean injected = false;
+        if (checkedObjs != null && !checkedObjs.add(target))
+            return false;
 
-        for (GridResourceField field : getFieldsWithAnnotation(dep, targetCls, annCls)) {
-            if (field.processFieldValue()) {
-                Field f = field.getField();
+        boolean injected = false;
 
-                try {
-                    Object obj = f.get(target);
+        for (Field field : descr.recursiveFields()) {
+            try {
+                Object obj = field.get(target);
 
-                    if (obj != null) {
-                        // Recursion.
-                        boolean injected0 = injectInternal(obj, annCls, injector, dep, depCls, checkedObjs);
+                if (obj != null) {
+                    assert checkedObjs != null;
 
-                        injected |= injected0;
-                    }
-                }
-                catch (IllegalAccessException e) {
-                    throw new IgniteCheckedException("Failed to inject resource [field=" + f.getName() +
-                        ", target=" + target + ']', e);
+                    injected |= injectInternal(obj, annCls, injector, dep, depCls, checkedObjs);
                 }
             }
-            else {
-                injector.inject(field, target, depCls, dep);
-
-                injected = true;
+            catch (IllegalAccessException e) {
+                throw new IgniteCheckedException("Failed to inject resource [field=" + field.getName() +
+                    ", target=" + target + ']', e);
             }
-
-            annCnt++;
         }
 
-        for (GridResourceMethod mtd : getMethodsWithAnnotation(dep, targetCls, annCls)) {
-            injector.inject(mtd, target, depCls, dep);
-
-            injected = true;
-
-            annCnt++;
-        }
+        if (annotatedMembers != null) {
+            for (GridResourceField field : annotatedMembers.get1()) {
+                injector.inject(field, target, depCls, dep);
 
-        if (annCnt == 0) {
-            if (skipClss == null)
-                skipClss = F.addIfAbsent(skipCache, annCls, F.<Class<?>>newCSet());
+                injected = true;
+            }
 
-            assert skipClss != null;
+            for (GridResourceMethod mtd : annotatedMembers.get2()) {
+                injector.inject(mtd, target, depCls, dep);
 
-            skipClss.add(targetCls);
+                injected = true;
+            }
         }
 
         return injected;
@@ -217,29 +188,9 @@ class GridResourceIoc {
         assert target != null;
         assert annCls != null;
 
-        Class<?> targetCls = target.getClass();
-
-        Set<Class<?>> skipClss = skipCache.get(annCls);
-
-        if (skipClss != null && skipClss.contains(targetCls))
-            return false;
-
-        GridResourceField[] fields = getFieldsWithAnnotation(dep, targetCls, annCls);
-
-        if (fields.length > 0)
-            return true;
+        ClassDescriptor desc = descriptor(dep, target.getClass());
 
-        GridResourceMethod[] mtds = getMethodsWithAnnotation(dep, targetCls, annCls);
-
-        if (mtds.length > 0)
-            return true;
-
-        if (skipClss == null)
-            skipClss = F.addIfAbsent(skipCache, annCls, F.<Class<?>>newCSet());
-
-        skipClss.add(targetCls);
-
-        return false;
+        return desc.recursiveFields().length > 0 || desc.annotatedMembers(annCls) != null;
     }
 
     /**
@@ -260,17 +211,14 @@ class GridResourceIoc {
         Class<? extends Annotation>[] res = annCache.get(cls);
 
         if (res == null) {
-            Collection<Class<? extends Annotation>> res0 =
-                new HashSet<>(annClss.size(), 1.0f);
+            Collection<Class<? extends Annotation>> res0 = new ArrayList<>();
 
             for (Class<? extends Annotation> annCls : annClss) {
                 if (isAnnotationPresent(target, annCls, dep))
                     res0.add(annCls);
             }
 
-            res = new Class[res0.size()];
-
-            res0.toArray(res);
+            res = res0.toArray(new Class[res0.size()]);
 
             annCache.putIfAbsent(cls, res);
         }
@@ -279,36 +227,6 @@ class GridResourceIoc {
     }
 
     /**
-     * For tests only.
-     *
-     * @param cls Class for test.
-     * @return {@code true} if cached, {@code false} otherwise.
-     */
-    boolean isCached(Class<?> cls) {
-        return isCached(cls.getName());
-    }
-
-    /**
-     * For tests only.
-     *
-     * @param clsName Class for test.
-     * @return {@code true} if cached, {@code false} otherwise.
-     */
-    boolean isCached(String clsName) {
-        for (Class<?> aClass : fieldCache.keySet()) {
-            if (aClass.getName().equals(clsName))
-                return true;
-        }
-
-        for (Class<?> aClass : mtdCache.keySet()) {
-            if (aClass.getName().equals(clsName))
-                return true;
-        }
-
-        return false;
-    }
-
-    /**
      * Gets set of methods with given annotation.
      *
      * @param dep Deployment.
@@ -318,156 +236,111 @@ class GridResourceIoc {
      */
     GridResourceMethod[] getMethodsWithAnnotation(@Nullable GridDeployment dep, Class<?> cls,
         Class<? extends Annotation> annCls) {
-        GridResourceMethod[] mtds = getMethodsFromCache(cls, annCls);
+        ClassDescriptor desc = descriptor(dep, cls);
 
-        if (mtds == null) {
-            List<GridResourceMethod> mtdsList = new ArrayList<>();
-
-            for (Class cls0 = cls; !cls0.equals(Object.class); cls0 = cls0.getSuperclass()) {
-                for (Method mtd : cls0.getDeclaredMethods()) {
-                    Annotation ann = mtd.getAnnotation(annCls);
-
-                    if (ann != null)
-                        mtdsList.add(new GridResourceMethod(mtd, ann));
-                }
-            }
+        T2<GridResourceField[], GridResourceMethod[]> t2 = desc.annotatedMembers(annCls);
 
-            if (mtdsList.isEmpty())
-                mtds = GridResourceMethod.EMPTY_ARRAY;
-            else
-                mtds = mtdsList.toArray(new GridResourceMethod[mtdsList.size()]);
-
-            cacheMethods(dep, cls, annCls, mtds);
-        }
+        return t2 == null ? GridResourceMethod.EMPTY_ARRAY : t2.get2();
+    }
 
-        return mtds;
+    /** {@inheritDoc} */
+    public void printMemoryStats() {
+        X.println(">>>   taskMapSize: " + taskMap.size());
+        X.println(">>>   classDescriptorsCacheSize: " + clsDescs.size());
     }
 
     /**
-     * Gets all entries from the specified class or its super-classes that have
-     * been annotated with annotation provided.
      *
-     * @param cls Class in which search for methods.
-     * @param dep Deployment.
-     * @param annCls Annotation.
-     * @return Set of entries with given annotations.
      */
-    private GridResourceField[] getFieldsWithAnnotation(@Nullable GridDeployment dep, Class<?> cls,
-        Class<? extends Annotation> annCls) {
-        GridResourceField[] fields = getFieldsFromCache(cls, annCls);
+    private static class ClassDescriptor {
+        /** */
+        private final Field[] recursiveFields;
+
+        /** */
+        private final Map<Class<? extends Annotation>, T2<GridResourceField[], GridResourceMethod[]>> annMap;
+
+        /**
+         * @param cls Class.
+         */
+        ClassDescriptor(Class<?> cls) {
+            Map<Class<? extends Annotation>, T2<List<GridResourceField>, List<GridResourceMethod>>> annMap
+                = new HashMap<>();
 
-        if (fields == null) {
-            List<GridResourceField> fieldsList = new ArrayList<>();
+            List<Field> recursiveFieldsList = new ArrayList<>();
 
             boolean allowImplicitInjection = !GridNoImplicitInjection.class.isAssignableFrom(cls);
 
             for (Class cls0 = cls; !cls0.equals(Object.class); cls0 = cls0.getSuperclass()) {
                 for (Field field : cls0.getDeclaredFields()) {
-                    Annotation ann = field.getAnnotation(annCls);
-
-                    if (ann != null)
-                        fieldsList.add(new GridResourceField(field, ann));
-                    else if (allowImplicitInjection && GridResourceUtils.mayRequireResources(field)) {
-                        // Account for anonymous inner classes.
-                        fieldsList.add(new GridResourceField(field, null));
-                    }
-                }
-            }
-
-            if (fieldsList.isEmpty())
-                fields = GridResourceField.EMPTY_ARRAY;
-            else
-                fields = fieldsList.toArray(new GridResourceField[fieldsList.size()]);
+                    Annotation[] fieldAnns = field.getAnnotations();
 
-            cacheFields(dep, cls, annCls, fields);
-        }
+                    for (Annotation ann : fieldAnns) {
+                        T2<List<GridResourceField>, List<GridResourceMethod>> t2 = annMap.get(ann.annotationType());
 
-        return fields;
-    }
+                        if (t2 == null) {
+                            t2 = new T2<List<GridResourceField>, List<GridResourceMethod>>(
+                                new ArrayList<GridResourceField>(),
+                                new ArrayList<GridResourceMethod>());
 
-    /**
-     * Gets all fields for a given class with given annotation from cache.
-     *
-     * @param cls Class to get fields from.
-     * @param annCls Annotation class for fields.
-     * @return List of fields with given annotation, possibly {@code null}.
-     */
-    @Nullable private GridResourceField[] getFieldsFromCache(Class<?> cls, Class<? extends Annotation> annCls) {
-        Map<Class<? extends Annotation>, GridResourceField[]> annCache = fieldCache.get(cls);
+                            annMap.put(ann.annotationType(), t2);
+                        }
 
-        return annCache != null ? annCache.get(annCls) : null;
-    }
-
-    /**
-     * Caches list of fields with given annotation from given class.
-     *
-     * @param cls Class the fields belong to.
-     * @param dep Deployment.
-     * @param annCls Annotation class for the fields.
-     * @param fields Fields to cache.
-     */
-    private void cacheFields(@Nullable GridDeployment dep, Class<?> cls, Class<? extends Annotation> annCls,
-        GridResourceField[] fields) {
-        if (dep != null) {
-            Set<Class<?>> classes = F.addIfAbsent(taskMap, dep.classLoader(), F.<Class<?>>newCSet());
+                        t2.get1().add(new GridResourceField(field, ann));
+                    }
 
-            assert classes != null;
+                    if (allowImplicitInjection
+                        && fieldAnns.length == 0
+                        && GridResourceUtils.mayRequireResources(field)) {
+                        field.setAccessible(true);
 
-            classes.add(cls);
-        }
+                        // Account for anonymous inner classes.
+                        recursiveFieldsList.add(field);
+                    }
+                }
 
-        Map<Class<? extends Annotation>, GridResourceField[]> rsrcFields =
-            F.addIfAbsent(fieldCache, cls, F.<Class<? extends Annotation>, GridResourceField[]>newCMap());
+                for (Method mtd : cls0.getDeclaredMethods()) {
+                    for (Annotation ann : mtd.getAnnotations()) {
+                        T2<List<GridResourceField>, List<GridResourceMethod>> t2 = annMap.get(ann.annotationType());
 
-        assert rsrcFields != null;
+                        if (t2 == null) {
+                            t2 = new T2<List<GridResourceField>, List<GridResourceMethod>>(
+                                new ArrayList<GridResourceField>(),
+                                new ArrayList<GridResourceMethod>());
 
-        rsrcFields.put(annCls, fields);
-    }
+                            annMap.put(ann.annotationType(), t2);
+                        }
 
-    /**
-     * Gets all methods for a given class with given annotation from cache.
-     *
-     * @param cls Class to get methods from.
-     * @param annCls Annotation class for fields.
-     * @return List of methods with given annotation, possibly {@code null}.
-     */
-    @Nullable private GridResourceMethod[] getMethodsFromCache(Class<?> cls, Class<? extends Annotation> annCls) {
-        Map<Class<? extends Annotation>, GridResourceMethod[]> annCache = mtdCache.get(cls);
+                        t2.get2().add(new GridResourceMethod(mtd, ann));
+                    }
+                }
+            }
 
-        return annCache != null ? annCache.get(annCls) : null;
-    }
+            recursiveFields = recursiveFieldsList.isEmpty() ? U.EMPTY_FIELDS
+                : recursiveFieldsList.toArray(new Field[recursiveFieldsList.size()]);
 
-    /**
-     * Caches list of methods with given annotation from given class.
-     *
-     * @param rsrcCls Class the fields belong to.
-     * @param dep Deployment.
-     * @param annCls Annotation class for the fields.
-     * @param mtds Methods to cache.
-     */
-    private void cacheMethods(@Nullable GridDeployment dep, Class<?> rsrcCls, Class<? extends Annotation> annCls,
-        GridResourceMethod[] mtds) {
-        if (dep != null) {
-            Set<Class<?>> classes = F.addIfAbsent(taskMap, dep.classLoader(), F.<Class<?>>newCSet());
+            this.annMap = IgniteUtils.limitedMap(annMap.size());
 
-            assert classes != null;
+            for (Map.Entry<Class<? extends Annotation>, T2<List<GridResourceField>, List<GridResourceMethod>>> entry
+                : annMap.entrySet()) {
+                GridResourceField[] fields = GridResourceField.toArray(entry.getValue().get1());
+                GridResourceMethod[] mtds = GridResourceMethod.toArray(entry.getValue().get2());
 
-            classes.add(rsrcCls);
+                this.annMap.put(entry.getKey(), new T2<>(fields, mtds));
+            }
         }
 
-        Map<Class<? extends Annotation>, GridResourceMethod[]> rsrcMtds = F.addIfAbsent(mtdCache,
-            rsrcCls, F.<Class<? extends Annotation>, GridResourceMethod[]>newCMap());
-
-        assert rsrcMtds != null;
-
-        rsrcMtds.put(annCls, mtds);
-    }
+        /**
+         * @return Recursive fields.
+         */
+        public Field[] recursiveFields() {
+            return recursiveFields;
+        }
 
-    /** {@inheritDoc} */
-    public void printMemoryStats() {
-        X.println(">>>   taskMapSize: " + taskMap.size());
-        X.println(">>>   fieldCacheSize: " + fieldCache.size());
-        X.println(">>>   mtdCacheSize: " + mtdCache.size());
-        X.println(">>>   skipCacheSize: " + skipCache.size());
+        /**
+         * @return Fields.
+         */
+        @Nullable public T2<GridResourceField[], GridResourceMethod[]> annotatedMembers(Class<? extends Annotation> annCls) {
+            return annMap.get(annCls);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceMethod.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceMethod.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceMethod.java
index aba9405..ad08a40 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceMethod.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceMethod.java
@@ -21,6 +21,7 @@ import org.apache.ignite.internal.util.typedef.internal.*;
 
 import java.lang.annotation.*;
 import java.lang.reflect.*;
+import java.util.*;
 
 /**
  * Wrapper for data where resource should be injected.
@@ -48,6 +49,8 @@ class GridResourceMethod {
 
         this.mtd = mtd;
         this.ann = ann;
+
+        mtd.setAccessible(true);
     }
 
     /**
@@ -68,6 +71,16 @@ class GridResourceMethod {
         return ann;
     }
 
+    /**
+     * @param c Closure.
+     */
+    public static GridResourceMethod[] toArray(Collection<GridResourceMethod> c) {
+        if (c.isEmpty())
+            return EMPTY_ARRAY;
+
+        return c.toArray(new GridResourceMethod[c.size()]);
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(GridResourceMethod.class, this);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java
index f08a287..f5ba492 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java
@@ -23,7 +23,6 @@ import org.apache.ignite.compute.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.managers.deployment.*;
 import org.apache.ignite.internal.processors.*;
-import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.lifecycle.*;
 import org.apache.ignite.resources.*;
@@ -147,8 +146,8 @@ public class GridResourceProcessor extends GridProcessorAdapter {
                 Method mtd = rsrcMtd.getMethod();
 
                 try {
-                    mtd.setAccessible(true);
-
+                    // No need to call mtd.setAccessible(true);
+                    // It has been called in GridResourceMethod constructor.
                     mtd.invoke(target);
                 }
                 catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
@@ -278,7 +277,7 @@ public class GridResourceProcessor extends GridProcessorAdapter {
             log.debug("Injecting resources: " + job);
 
         // Unwrap Proxy object.
-        Object obj = unwrapTarget(unwrapJob(job));
+        Object obj = unwrapTarget(job);
 
         injectToJob(dep, taskCls, obj, ses, jobCtx);
 
@@ -329,19 +328,6 @@ public class GridResourceProcessor extends GridProcessorAdapter {
     }
 
     /**
-     * Gets rid of job wrapper, if any.
-     *
-     * @param job Job to unwrap.
-     * @return Unwrapped job.
-     */
-    private ComputeJob unwrapJob(ComputeJob job) {
-        if (job instanceof GridComputeJobWrapper)
-            return ((GridComputeJobWrapper)job).wrappedJob();
-
-        return job;
-    }
-
-    /**
      * Injects held resources into given grid task.
      *
      * @param dep Deployed class.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index cb56650..0932212 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -108,10 +108,13 @@ public abstract class IgniteUtils {
     private static final int[] GRID_EVTS;
 
     /** Empty integers array. */
-    private static final int[] EMPTY_INTS = new int[0];
+    public static final int[] EMPTY_INTS = new int[0];
 
     /** Empty  longs. */
-    private static final long[] EMPTY_LONGS = new long[0];
+    public static final long[] EMPTY_LONGS = new long[0];
+
+    /** Empty  longs. */
+    public static final Field[] EMPTY_FIELDS = new Field[0];
 
     /** System line separator. */
     private static final String NL = System.getProperty("line.separator");
@@ -1529,8 +1532,10 @@ public abstract class IgniteUtils {
             return Collections.emptyList();
 
         if (addrs.size() == 1) {
-            if (reachable(addrs.get(1), reachTimeout))
-                return Collections.singletonList(addrs.get(1));
+            InetAddress addr = addrs.get(0);
+
+            if (reachable(addr, reachTimeout))
+                return Collections.singletonList(addr);
 
             return Collections.emptyList();
         }
@@ -8807,6 +8812,21 @@ public abstract class IgniteUtils {
     }
 
     /**
+     * Creates new map that limited by size.
+     *
+     * @param limit Limit for size.
+     */
+    public static <K, V> Map<K, V> limitedMap(int limit) {
+        if (limit == 0)
+            return Collections.emptyMap();
+
+        if (limit < 5)
+            return new GridLeanMap<>(limit);
+
+        return new HashMap<>(capacity(limit), 0.75f);
+    }
+
+    /**
      * Returns comparator that sorts remote node addresses. If remote node resides on the same host, then put
      * loopback addresses first, last otherwise.
      *

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryServerEndpoint.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryServerEndpoint.java b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryServerEndpoint.java
index 86a0886..5185856 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryServerEndpoint.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryServerEndpoint.java
@@ -592,7 +592,7 @@ public class IpcSharedMemoryServerEndpoint implements IpcServerEndpoint {
                 if (log.isDebugEnabled())
                     log.debug("Token directory is being processed concurrently: " + workTokDir.getAbsolutePath());
             }
-            catch (InterruptedIOException ignored) {
+            catch (FileLockInterruptionException ignored) {
                 Thread.currentThread().interrupt();
             }
             catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridComputeJobWrapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridComputeJobWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridComputeJobWrapper.java
deleted file mode 100644
index 82c0078..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridComputeJobWrapper.java
+++ /dev/null
@@ -1,96 +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.util.lang;
-
-import org.apache.ignite.compute.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.jetbrains.annotations.*;
-
-import java.util.concurrent.*;
-
-/**
- * Convenient wrapper for grid job. It allows to create a job clone in cases when the same
- * job needs to be cloned to multiple grid nodes during mapping phase of task execution.
- */
-public class GridComputeJobWrapper implements ComputeJob, Callable<Object>,
-    GridPeerDeployAware {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** */
-    private final ComputeJob job;
-
-    /** Peer deploy aware class. */
-    private transient volatile GridPeerDeployAware p;
-
-    /**
-     * Creates a wrapper with given grid {@code job}.
-     *
-     * @param job Job to wrap.
-     */
-    public GridComputeJobWrapper(ComputeJob job) {
-        A.notNull(job, "job");
-
-        this.job = job;
-    }
-
-    /**
-     * Gets wrapped job.
-     *
-     * @return Wrapped job.
-     */
-    public ComputeJob wrappedJob() {
-        return job;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public final Object call() throws Exception {
-        return execute();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Class<?> deployClass() {
-        if (p == null)
-            p = U.detectPeerDeployAware(this);
-
-        return p.deployClass();
-    }
-
-    /** {@inheritDoc} */
-    @Override public ClassLoader classLoader() {
-        if (p == null)
-            p = U.detectPeerDeployAware(this);
-
-        return p.classLoader();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void cancel() {
-        job.cancel();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object execute() {
-        return job.execute();
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(GridComputeJobWrapper.class, this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFilteredIterator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFilteredIterator.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFilteredIterator.java
index b1df224..f3240d7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFilteredIterator.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFilteredIterator.java
@@ -35,7 +35,7 @@ public abstract class GridFilteredIterator<T> implements Iterator<T> {
     /**
      * @param it Iterator.
      */
-    public GridFilteredIterator(Iterator<? extends T> it) {
+    protected GridFilteredIterator(Iterator<? extends T> it) {
         assert it != null;
 
         this.it = it;


[02/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/licenses/jcraft-revised-bsd.txt
----------------------------------------------------------------------
diff --git a/modules/visor-console/licenses/jcraft-revised-bsd.txt b/modules/visor-console/licenses/jcraft-revised-bsd.txt
deleted file mode 100644
index 3748f98..0000000
--- a/modules/visor-console/licenses/jcraft-revised-bsd.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-3-clause BSD license
-------------------------------------------------------------------------------
-Copyright (c) 2002-2014 Atsuhiko Yamanaka, JCraft,Inc.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-  1. Redistributions of source code must retain the above copyright notice,
-     this list of conditions and the following disclaimer.
-
-  2. Redistributions in binary form must reproduce the above copyright
-     notice, this list of conditions and the following disclaimer in
-     the documentation and/or other materials provided with the distribution.
-
-  3. The names of the authors may not be used to endorse or promote products
-     derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
-INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/pom.xml
----------------------------------------------------------------------
diff --git a/modules/visor-console/pom.xml b/modules/visor-console/pom.xml
index 07e27a0..8e71970 100644
--- a/modules/visor-console/pom.xml
+++ b/modules/visor-console/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-visor-console</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>
@@ -100,7 +100,7 @@
         <dependency>
             <groupId>org.scalatest</groupId>
             <artifactId>scalatest_2.11</artifactId>
-            <version>2.2.2</version>
+            <version>2.2.4</version>
             <scope>test</scope>
             <exclusions>
                 <exclusion>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
index ccfc5ef..144779c 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
@@ -859,9 +859,9 @@ object VisorCacheCommand {
         cacheT += ("Synchronous Eviction Timeout", evictCfg.synchronizedTimeout())
         cacheT += ("Synchronous Eviction Concurrency Level", evictCfg.synchronizedConcurrencyLevel())
 
+        cacheT += ("Near Cache Enabled", bool2Str(nearCfg.nearEnabled()))
         cacheT += ("Near Start Size", nearCfg.nearStartSize())
         cacheT += ("Near Eviction Policy", safe(nearCfg.nearEvictPolicy()))
-        cacheT += ("Near Eviction Enabled", bool2Str(nearCfg.nearEnabled()))
         cacheT += ("Near Eviction Policy Max Size", safe(nearCfg.nearEvictMaxSize()))
 
         cacheT += ("Default Lock Timeout", defaultCfg.txLockTimeout())

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala
index d40ec8d..4b66720 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala
@@ -139,7 +139,7 @@ class VisorCacheScanCommand {
         val firstPage =
             try
                 executeRandom(groupForDataNode(node, cacheName),
-                    classOf[VisorQueryTask], new VisorQueryArg(cacheName, "SCAN", pageSize)) match {
+                    classOf[VisorQueryTask], new VisorQueryArg(cacheName, "SCAN", false, pageSize)) match {
                     case x if x.get1() != null =>
                         error(x.get1())
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
index 064d33e..f4a1f87 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
@@ -159,7 +159,7 @@ class VisorNodeCommand extends VisorConsoleCommand {
                         t += ("ID8", nid8(node))
                         t += ("Order", node.order)
 
-                        (0 /: node.addresses())((b, a) => { t += ("Address (" + b + ")", a); b + 1 })
+                        (0 /: sortAddresses(node.addresses))((b, a) => { t += ("Address (" + b + ")", a); b + 1 })
 
                         val m = node.metrics
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala
index 16bce29..e158506 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala
@@ -1216,7 +1216,7 @@ class VisorTasksCommand extends VisorConsoleCommand {
 
                 eLst.foreach(e => {
                     e.nodeIds.foreach(id => {
-                        val host = ignite.cluster.node(id).addresses.headOption
+                        val host = sortAddresses(ignite.cluster.node(id).addresses).headOption
 
                         if (host.isDefined) {
                             var eSet = hMap.getOrElse(host.get, Set.empty[VisorExecution])

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
index 356c80a..c943fc5 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
@@ -1699,7 +1699,7 @@ object visor extends VisorTag {
         ignite.cluster.nodes().foreach(n => {
             setVarIfAbsent(nid8(n), "n")
 
-            val ip = n.addresses().headOption
+            val ip = sortAddresses(n.addresses()).headOption
 
             if (ip.isDefined)
                 setVarIfAbsent(ip.get, "h")
@@ -1714,7 +1714,7 @@ object visor extends VisorTag {
                         val node = ignite.cluster.node(de.eventNode().id())
 
                         if (node != null) {
-                            val ip = node.addresses().headOption
+                            val ip = sortAddresses(node.addresses).headOption
 
                             if (ip.isDefined)
                                 setVarIfAbsent(ip.get, "h")
@@ -1743,11 +1743,11 @@ object visor extends VisorTag {
                         if (nv.isDefined)
                             mem.remove(nv.get._1)
 
-                        val ip = de.eventNode().addresses.headOption
+                        val ip = sortAddresses(de.eventNode().addresses).headOption
 
                         if (ip.isDefined) {
                             val last = !ignite.cluster.nodes().exists(n =>
-                                n.addresses.size > 0 && n.addresses.head == ip.get
+                                n.addresses.size > 0 && sortAddresses(n.addresses).head == ip.get
                             )
 
                             if (last) {
@@ -1858,7 +1858,7 @@ object visor extends VisorTag {
             id8 +
                 (if (v.isDefined) "(@" + v.get._1 + ")" else "") +
                 ", " +
-                (if (n == null) NA else n.addresses().headOption.getOrElse(NA))
+                (if (n == null) NA else sortAddresses(n.addresses).headOption.getOrElse(NA))
         }
     }
 
@@ -2012,6 +2012,8 @@ object visor extends VisorTag {
 
             None
         }
+        else if (nodes.size == 1)
+            Some(nodes.head.id)
         else {
             (0 until nodes.size) foreach (i => {
                 val n = nodes(i)
@@ -2099,7 +2101,7 @@ object visor extends VisorTag {
                 neighbors.foreach(n => {
                     id8s = id8s :+ nodeId8(n.id)
 
-                    ips = ips ++ n.addresses()
+                    ips = ips ++ n.addresses
 
                     cpuLoadSum += n.metrics().getCurrentCpuLoad
 
@@ -2834,4 +2836,53 @@ object visor extends VisorTag {
         else
             Long.MaxValue
     }
+
+    /**
+     * Sort addresses to properly display in Visor.
+     *
+     * @param addrs Addresses to sort.
+     * @return Sorted list.
+     */
+    def sortAddresses(addrs: Iterable[String]) = {
+        def ipToLong(ip: String) = {
+            try {
+                val octets = if (ip.contains(".")) ip.split('.') else ip.split(':')
+
+                var dec = BigDecimal.valueOf(0L)
+
+                for (i <- 0 until octets.length) dec += octets(i).toLong * math.pow(256, octets.length - 1 - i).toLong
+
+                dec
+            }
+            catch {
+                case _: Exception => BigDecimal.valueOf(0L)
+            }
+        }
+
+        /**
+         * Sort addresses to properly display in Visor.
+         *
+         * @param addr Address to detect type for.
+         * @return IP class type for sorting in order: public addresses IPv4 + private IPv4 + localhost + IPv6.
+         */
+        def addrType(addr: String) = {
+            if (addr.contains(':'))
+                4 // IPv6
+            else {
+                try {
+                    InetAddress.getByName(addr) match {
+                        case ip if ip.isLoopbackAddress => 3 // localhost
+                        case ip if ip.isSiteLocalAddress => 2 // private IPv4
+                        case _ => 1 // other IPv4
+                    }
+                }
+                catch {
+                    case ignore: UnknownHostException => 5
+                }
+            }
+        }
+
+        addrs.map(addr => (addrType(addr), ipToLong(addr), addr)).toSeq.
+            sortWith((l, r) => if (l._1 == r._1) l._2.compare(r._2) < 0 else l._1 < r._1).map(_._3)
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorRuntimeBaseSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorRuntimeBaseSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorRuntimeBaseSpec.scala
index aa6ab84..f27bae3 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorRuntimeBaseSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorRuntimeBaseSpec.scala
@@ -24,7 +24,7 @@ import org.scalatest._
 /**
  * Base abstract class for unit tests requiring Visor runtime.
  */
-abstract class VisorRuntimeBaseSpec(private[this] val num: Int) extends FlatSpec with Matchers
+abstract class VisorRuntimeBaseSpec(private[this] val num: Int) extends FunSpec with Matchers
     with BeforeAndAfterAll with BeforeAndAfterEach {
     assert(num >= 1)
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/VisorArgListSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/VisorArgListSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/VisorArgListSpec.scala
index 8b71918..a581899 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/VisorArgListSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/VisorArgListSpec.scala
@@ -25,48 +25,48 @@ import visor._
 /**
  * Test for visor's argument list parsing.
  */
-class VisorArgListSpec extends FlatSpec with ShouldMatchers {
-    behavior of "A visor argument list"
+class VisorArgListSpec extends FunSpec with ShouldMatchers {
+    describe("A visor argument list") {
+        it("should properly parse 'null' arguments") {
+            val v = parseArgs(null)
 
-    it should "properly parse 'null' arguments" in {
-        val v = parseArgs(null)
+            assert(v.isEmpty)
+        }
 
-        assert(v.isEmpty)
-    }
-
-    it should "properly parse non-empty arguments" in {
-        val v = parseArgs("-a=b c d -minus -d=")
+        it("should properly parse non-empty arguments") {
+            val v = parseArgs("-a=b c d -minus -d=")
 
-        assert(v.size == 5)
+            assert(v.size == 5)
 
-        assert(v(0)._1 == "a")
-        assert(v(0)._2 == "b")
+            assert(v(0)._1 == "a")
+            assert(v(0)._2 == "b")
 
-        assert(v(1)._1 == null)
-        assert(v(1)._2 == "c")
+            assert(v(1)._1 == null)
+            assert(v(1)._2 == "c")
 
-        assert(v(2)._1 == null)
-        assert(v(2)._2 == "d")
+            assert(v(2)._1 == null)
+            assert(v(2)._2 == "d")
 
-        assert(v(3)._1 == "minus")
-        assert(v(3)._2 == null)
+            assert(v(3)._1 == "minus")
+            assert(v(3)._2 == null)
 
-        assert(v(4)._1 == "d")
-        assert(v(4)._2 == "")
-    }
+            assert(v(4)._1 == "d")
+            assert(v(4)._2 == "")
+        }
 
-    it should "properly parse quoted arguments" in {
-        val v = parseArgs("-a='b 'c' d' -minus -d=")
+        it("should properly parse quoted arguments") {
+            val v = parseArgs("-a='b 'c' d' -minus -d=")
 
-        assert(v.size == 3)
+            assert(v.size == 3)
 
-        assert(v(0)._1 == "a")
-        assert(v(0)._2 == "b 'c' d")
+            assert(v(0)._1 == "a")
+            assert(v(0)._2 == "b 'c' d")
 
-        assert(v(1)._1 == "minus")
-        assert(v(1)._2 == null)
+            assert(v(1)._1 == "minus")
+            assert(v(1)._2 == null)
 
-        assert(v(2)._1 == "d")
-        assert(v(2)._2 == "")
+            assert(v(2)._1 == "d")
+            assert(v(2)._2 == "")
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/VisorFileNameCompleterSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/VisorFileNameCompleterSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/VisorFileNameCompleterSpec.scala
index 9767fc4..e7333c6 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/VisorFileNameCompleterSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/VisorFileNameCompleterSpec.scala
@@ -25,34 +25,34 @@ import java.util
 /**
  * Test for visor's file name completer.
  */
-class VisorFileNameCompleterSpec extends FlatSpec with ShouldMatchers {
-    behavior of "A visor file name completer"
+class VisorFileNameCompleterSpec extends FunSpec with ShouldMatchers {
+    describe("A visor file name completer") {
+        it("should properly parse empty path") {
+            val c = new VisorFileNameCompleter()
 
-    it should "properly parse empty path" in {
-        val c = new VisorFileNameCompleter()
+            val res = new util.ArrayList[CharSequence]()
 
-        val res = new util.ArrayList[CharSequence]()
+            c.complete("", 0, res)
 
-        c.complete("", 0, res)
+            assertResult(new File("").getAbsoluteFile.listFiles().length)(res.size)
 
-        assertResult(new File("").getAbsoluteFile.listFiles().length)(res.size)
+            res.clear()
 
-        res.clear()
+            c.complete(null, 0, res)
 
-        c.complete(null, 0, res)
+            assertResult(new File("").getAbsoluteFile.listFiles().length)(res.size)
 
-        assertResult(new File("").getAbsoluteFile.listFiles().length)(res.size)
+            res.clear()
 
-        res.clear()
+            c.complete("    ", 2, res)
 
-        c.complete("    ", 2, res)
+            assertResult(new File("").getAbsoluteFile.listFiles().length)(res.size)
 
-        assertResult(new File("").getAbsoluteFile.listFiles().length)(res.size)
+            res.clear()
 
-        res.clear()
+            c.complete("help ", 5, res)
 
-        c.complete("help ", 5, res)
-
-        assertResult(new File("").getAbsoluteFile.listFiles().length)(res.size)
+            assertResult(new File("").getAbsoluteFile.listFiles().length)(res.size)
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/ack/VisorAckCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/ack/VisorAckCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/ack/VisorAckCommandSpec.scala
index 6c6c829..b6a9608 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/ack/VisorAckCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/ack/VisorAckCommandSpec.scala
@@ -24,17 +24,17 @@ import org.apache.ignite.visor.commands.ack.VisorAckCommand._
  * Unit test for 'ack' command.
  */
 class VisorAckCommandSpec extends VisorRuntimeBaseSpec(2) {
-    behavior of "A 'ack' visor command"
+    describe("A 'ack' visor command") {
+        it("should properly execute w/o arguments"){
+            visor ack()
+        }
 
-    it should "properly execute w/o arguments" in {
-        visor ack()
-    }
-
-    it should "properly execute with arguments" in {
-        visor ack "Broadcasting!"
-    }
+        it("should properly execute with arguments") {
+            visor ack "Broadcasting!"
+        }
 
-    it should "print error message when not connected" in {
-        visor ack()
+        it("should print error message when not connected") {
+            visor ack()
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommandSpec.scala
index 0a3a011..ec7d1b5 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommandSpec.scala
@@ -100,54 +100,54 @@ class VisorAlertCommandSpec extends VisorRuntimeBaseSpec(1) {
         }
     }
 
-    behavior of "An 'alert' visor command"
+    describe("An 'alert' visor command") {
+        it("should print not connected error message") {
+            visor.close()
 
-    it should "print not connected error message" in {
-        visor.close()
+            checkOut(visor.alert("-r -t=5 -cc=gte4"), "Visor is disconnected.")
 
-        checkOut(visor.alert("-r -t=5 -cc=gte4"), "Visor is disconnected.")
-
-        checkOut(visor.alert(), "No alerts are registered.")
-    }
-
-    it should "register new alert" in {
-        try {
             checkOut(visor.alert(), "No alerts are registered.")
+        }
 
-            matchOut(visor.alert("-r -t=5 -cc=gte4"), "Alert.+registered.")
+        it("should register new alert") {
+            try {
+                checkOut(visor.alert(), "No alerts are registered.")
 
-            checkOut(visor.alert(), "No alerts are registered.", false)
-        }
-        finally {
-            visor.alert("-u -a")
+                matchOut(visor.alert("-r -t=5 -cc=gte4"), "Alert.+registered.")
+
+                checkOut(visor.alert(), "No alerts are registered.", false)
+            }
+            finally {
+                visor.alert("-u -a")
+            }
         }
-    }
 
-    it should "print error messages on incorrect alerts" in {
-        try {
-            matchOut(visor.alert("-r -t=5"), "Alert.+registered.")
+        it("should print error messages on incorrect alerts") {
+            try {
+                matchOut(visor.alert("-r -t=5"), "Alert.+registered.")
 
-            checkOut(visor.alert("-r -UNKNOWN_KEY=lt20"), "Invalid argument")
+                checkOut(visor.alert("-r -UNKNOWN_KEY=lt20"), "Invalid argument")
 
-            checkOut(visor.alert("-r -cc=UNKNOWN_OPERATION20"), "Invalid expression")
-        }
-        finally {
-            visor.alert("-u -a")
+                checkOut(visor.alert("-r -cc=UNKNOWN_OPERATION20"), "Invalid expression")
+            }
+            finally {
+                visor.alert("-u -a")
+            }
         }
-    }
 
-    it should "write alert to log" in {
-        try {
-            matchOut(visor.alert("-r -nc=gte1"), "Alert.+registered.")
+        it("should write alert to log") {
+            try {
+                matchOut(visor.alert("-r -nc=gte1"), "Alert.+registered.")
 
-            Ignition.start(config("node-2"))
+                Ignition.start(config("node-2"))
 
-            Ignition.stop("node-2", false)
+                Ignition.stop("node-2", false)
 
-            checkOut(visor.alert(), "No alerts are registered.", false)
-        }
-        finally {
-            visor.alert("-u -a")
+                checkOut(visor.alert(), "No alerts are registered.", false)
+            }
+            finally {
+                visor.alert("-u -a")
+            }
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheClearCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheClearCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheClearCommandSpec.scala
index 2e51698..6bb4993 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheClearCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheClearCommandSpec.scala
@@ -75,43 +75,43 @@ class VisorCacheClearCommandSpec extends VisorRuntimeBaseSpec(2) {
         cfg
     }
 
-    behavior of "An 'cclear' visor command"
+    describe("An 'cclear' visor command") {
+        it("should show correct result for default cache") {
+            Ignition.ignite("node-1").cache[Int, Int](null).putAll(Map(1 -> 1, 2 -> 2, 3 -> 3))
 
-    it should "show correct result for default cache" in {
-        Ignition.ignite("node-1").cache[Int, Int](null).putAll(Map(1 -> 1, 2 -> 2, 3 -> 3))
+            val lock = Ignition.ignite("node-1").cache[Int, Int](null).lock(1)
 
-        val lock = Ignition.ignite("node-1").cache[Int, Int](null).lock(1)
+            lock.lock()
 
-        lock.lock()
+            VisorCacheClearCommand().clear(Nil, None)
 
-        VisorCacheClearCommand().clear(Nil, None)
+            lock.unlock()
 
-        lock.unlock()
+            VisorCacheClearCommand().clear(Nil, None)
+        }
 
-        VisorCacheClearCommand().clear(Nil, None)
-    }
-
-    it should "show correct result for named cache" in {
-        Ignition.ignite("node-1").cache[Int, Int]("cache").putAll(Map(1 -> 1, 2 -> 2, 3 -> 3))
+        it("should show correct result for named cache") {
+            Ignition.ignite("node-1").cache[Int, Int]("cache").putAll(Map(1 -> 1, 2 -> 2, 3 -> 3))
 
-        val lock = Ignition.ignite("node-1").cache[Int, Int]("cache").lock(1)
+            val lock = Ignition.ignite("node-1").cache[Int, Int]("cache").lock(1)
 
-        lock.lock()
+            lock.lock()
 
-        visor.cache("-clear -c=cache")
+            visor.cache("-clear -c=cache")
 
-        lock.unlock()
+            lock.unlock()
 
-        visor.cache("-clear -c=cache")
-    }
+            visor.cache("-clear -c=cache")
+        }
 
-    it should "show correct help" in {
-        VisorCacheCommand
+        it("should show correct help") {
+            VisorCacheCommand
 
-        visor.help("cache")
-    }
+            visor.help("cache")
+        }
 
-    it should "show empty projection error message" in {
-        visor.cache("-clear -c=wrong")
+        it("should show empty projection error message") {
+            visor.cache("-clear -c=wrong")
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommandSpec.scala
index 4724006..4859a8f 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommandSpec.scala
@@ -36,7 +36,6 @@ import org.apache.ignite.visor.commands.cache.VisorCacheCommand._
  * Unit test for 'events' command.
  */
 class VisorCacheCommandSpec extends VisorRuntimeBaseSpec(1) {
-    behavior of "A 'cache' visor command"
 
     /** IP finder. */
     val ipFinder = new TcpDiscoveryVmIpFinder(true)
@@ -54,7 +53,7 @@ class VisorCacheCommandSpec extends VisorRuntimeBaseSpec(1) {
 
         val arr = Seq(classOf[JavaInt], classOf[Foo]).toArray
 
-        cfg.setIndexedTypes(arr:_*)
+        cfg.setIndexedTypes(arr: _*)
 
         cfg
     }
@@ -65,7 +64,8 @@ class VisorCacheCommandSpec extends VisorRuntimeBaseSpec(1) {
      * @param name Grid name.
      * @return Grid configuration.
      */
-    override def config(name: String): IgniteConfiguration = {
+    override def config(name: String): IgniteConfiguration =
+    {
         val cfg = new IgniteConfiguration
 
         cfg.setGridName(name)
@@ -81,49 +81,51 @@ class VisorCacheCommandSpec extends VisorRuntimeBaseSpec(1) {
         cfg
     }
 
-    it should "put/get some values to/from cache and display information about caches" in {
-        val c = Ignition.ignite("node-1").cache[String, String]("replicated")
+    describe("A 'cache' visor command") {
+        it("should put/get some values to/from cache and display information about caches") {
+            val c = Ignition.ignite("node-1").cache[String, String]("replicated")
 
-        for (i <- 0 to 3) {
-            val kv = "" + i
+            for (i <- 0 to 3) {
+                val kv = "" + i
 
-            c.put(kv, kv)
+                c.put(kv, kv)
 
-            c.get(kv)
-        }
+                c.get(kv)
+            }
 
-        visor.cache()
-    }
+            visor.cache()
+        }
 
-    it should "run query and display information about caches" in {
-        val g = Ignition.ignite("node-1")
+        it("should run query and display information about caches") {
+            val g = Ignition.ignite("node-1")
 
-        val c = g.cache[JavaInt, Foo]("replicated")
+            val c = g.cache[JavaInt, Foo]("replicated")
 
-        c.put(0, Foo(20))
-        c.put(1, Foo(100))
-        c.put(2, Foo(101))
-        c.put(3, Foo(150))
+            c.put(0, Foo(20))
+            c.put(1, Foo(100))
+            c.put(2, Foo(101))
+            c.put(3, Foo(150))
 
-        // Create and execute query that mast return 2 rows.
-        val q1 = c.query(new SqlQuery(classOf[Foo], "_key > ?").setArgs(JavaInt.valueOf(1))).getAll()
+            // Create and execute query that mast return 2 rows.
+            val q1 = c.query(new SqlQuery(classOf[Foo], "_key > ?").setArgs(JavaInt.valueOf(1))).getAll
 
-        assert(q1.size() == 2)
+            assert(q1.size() == 2)
 
-        // Create and execute query that mast return 0 rows.
-        val q2 = c.query(new SqlQuery(classOf[Foo], "_key > ?").setArgs(JavaInt.valueOf(100))).getAll()
+            // Create and execute query that mast return 0 rows.
+            val q2 = c.query(new SqlQuery(classOf[Foo], "_key > ?").setArgs(JavaInt.valueOf(100))).getAll
 
-        assert(q2.size() == 0)
+            assert(q2.size() == 0)
 
-        visor cache "-a"
-    }
+            visor cache "-a"
+        }
 
-    it should "display correct information for 'replicated' cache only" in {
-        visor cache "-n=replicated -a"
-    }
+        it("should display correct information for 'replicated' cache only") {
+            visor cache "-n=replicated -a"
+        }
 
-    it should "display correct information for all caches" in {
-        visor cache "-a"
+        it("should display correct information for all caches") {
+            visor cache "-a"
+        }
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommandSpec.scala
index 6b1b62d..72642f7 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommandSpec.scala
@@ -42,9 +42,9 @@ class VisorConfigurationCommandSpec extends VisorRuntimeBaseSpec(1) {
         cfg
     }
 
-    behavior of "A 'config' visor command"
-
-    it should "print configuration for first node" in {
-        visor.config("-id8=@n0")
+    describe("A 'config' visor command") {
+        it("should print configuration for first node") {
+            visor.config("-id8=@n0")
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cswap/VisorCacheSwapCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cswap/VisorCacheSwapCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cswap/VisorCacheSwapCommandSpec.scala
index f5af1d3..8a0b0c8 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cswap/VisorCacheSwapCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cswap/VisorCacheSwapCommandSpec.scala
@@ -69,21 +69,21 @@ class VisorCacheSwapCommandSpec extends VisorRuntimeBaseSpec(2) {
         cfg
     }
 
-    behavior of "An 'cswap' visor command"
+    describe("An 'cswap' visor command") {
+        it("should show correct result for default cache") {
+            Ignition.ignite("node-1").cache[Int, Int](null).putAll(Map(1 -> 1, 2 -> 2, 3 -> 3))
 
-    it should "show correct result for default cache" in {
-        Ignition.ignite("node-1").cache[Int, Int](null).putAll(Map(1 -> 1, 2 -> 2, 3 -> 3))
+            visor.cache("-swap -c=<default>")
+        }
 
-        visor.cache("-swap -c=<default>")
-    }
-
-    it should "show correct result for named cache" in {
-        Ignition.ignite("node-1").cache[Int, Int]("cache").putAll(Map(1 -> 1, 2 -> 2, 3 -> 3))
+        it("should show correct result for named cache") {
+            Ignition.ignite("node-1").cache[Int, Int]("cache").putAll(Map(1 -> 1, 2 -> 2, 3 -> 3))
 
-        visor.cache("-swap -c=cache")
-    }
+            visor.cache("-swap -c=cache")
+        }
 
-    it should "show empty projection error message" in {
-        visor.cache("-swap -c=wrong")
+        it("should show empty projection error message") {
+            visor.cache("-swap -c=wrong")
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/deploy/VisorDeployCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/deploy/VisorDeployCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/deploy/VisorDeployCommandSpec.scala
index 6003119..b80ff1d 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/deploy/VisorDeployCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/deploy/VisorDeployCommandSpec.scala
@@ -25,10 +25,10 @@ import org.apache.ignite.visor.commands.deploy.VisorDeployCommand._
 /**
  * Unit test for 'deploy' command.
  */
-class VisorDeployCommandSpec extends FlatSpec with Matchers {
-    behavior of "A 'deploy' visor command"
-
-    it should "copy folder" in {
-        visor.deploy("-h=uname:passwd@localhost -s=/home/uname/test -d=dir")
+class VisorDeployCommandSpec extends FunSpec with Matchers {
+    describe("A 'deploy' visor command") {
+        it("should copy folder") {
+            visor.deploy("-h=uname:passwd@localhost -s=/home/uname/test -d=dir")
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommandSpec.scala
index 64f0e0f..335a048 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommandSpec.scala
@@ -51,35 +51,35 @@ class VisorDiscoveryCommandSpec extends VisorRuntimeBaseSpec(4) {
         cfg
     }
 
-    behavior of  "A 'disco' visor command"
+    describe("A 'disco' visor command") {
+        it("should advise to connect") {
+            closeVisorQuiet()
 
-    it should "advise to connect" in  {
-        closeVisorQuiet()
+            visor.disco()
+        }
 
-        visor.disco()
-    }
+        it("should show all discovery events") {
+            visor.disco()
+        }
 
-    it should "show all discovery events" in  {
-        visor.disco()
-    }
+        it("should show all discovery events in reversed order") {
+            visor.disco("-r")
+        }
 
-    it should "show all discovery events in reversed order" in  {
-        visor.disco("-r")
-    }
+        it("should show discovery events from last two minutes") {
+            visor.disco("-t=2m")
+        }
 
-    it should "show discovery events from last two minutes" in {
-        visor.disco("-t=2m")
-    }
+        it("should show discovery events from last two minutes in reversed order ") {
+            visor.disco("-t=2m -r")
+        }
 
-    it should "show discovery events from last two minutes in reversed order " in {
-        visor.disco("-t=2m -r")
-    }
-
-    it should "show top 3 discovery events" in  {
-        visor.disco("-c=3")
-    }
+        it("should show top 3 discovery events") {
+            visor.disco("-c=3")
+        }
 
-    it should "print error message with invalid count" in {
-        visor.disco("-c=x")
+        it("should print error message with invalid count") {
+            visor.disco("-c=x")
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/events/VisorEventsCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/events/VisorEventsCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/events/VisorEventsCommandSpec.scala
index 365032e..5b18590 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/events/VisorEventsCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/events/VisorEventsCommandSpec.scala
@@ -40,23 +40,23 @@ class VisorEventsCommandSpec extends VisorRuntimeBaseSpec(1) {
         cfg
     }
 
-    behavior of "A 'events' visor command"
+    describe("A 'events' visor command") {
+        it("should print error message when not connected") {
+            closeVisorQuiet()
 
-    it should "print error message when not connected" in {
-        closeVisorQuiet()
+            visor.events()
+        }
 
-        visor.events()
-    }
-
-    it should "display all events from remote node" in {
-        visor.events("-id8=@n0")
-    }
+        it("should display all events from remote node") {
+            visor.events("-id8=@n0")
+        }
 
-    it should "display top 3 events from remote node" in {
-        visor.events("-id8=@n0 -c=3")
-    }
+        it("should display top 3 events from remote node") {
+            visor.events("-id8=@n0 -c=3")
+        }
 
-    it should "print error message with invalid count" in {
-        visor.events("-id8=@n0 -c=x")
+        it("should print error message with invalid count") {
+            visor.events("-id8=@n0 -c=x")
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/gc/VisorGcCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/gc/VisorGcCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/gc/VisorGcCommandSpec.scala
index 678aaf4..b467687 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/gc/VisorGcCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/gc/VisorGcCommandSpec.scala
@@ -25,15 +25,14 @@ import org.apache.ignite.visor.{VisorRuntimeBaseSpec, visor}
  * Unit test for 'gc' command.
  */
 class VisorGcCommandSpec extends VisorRuntimeBaseSpec(1) {
-    behavior of "A 'gc' visor command"
-
     /**
      * Creates grid configuration for provided grid host.
      *
      * @param name Grid name.
      * @return Grid configuration.
      */
-    override def config(name: String): IgniteConfiguration = {
+    override def config(name: String): IgniteConfiguration =
+    {
         val cfg = new IgniteConfiguration
 
         cfg.setGridName(name)
@@ -41,19 +40,22 @@ class VisorGcCommandSpec extends VisorRuntimeBaseSpec(1) {
         cfg
     }
 
-    it should "run GC on all nodes" in {
-        visor.gc()
-    }
+    describe("'gc' visor command") {
+        it("should run GC on all nodes") {
+            visor.gc()
+        }
 
-    it should "run GC on first node" in {
-        visor.gc("-id8=@n0")
-    }
+        it("should run GC on first node") {
+            visor.gc("-id8=@n0")
+        }
 
-    it should "run GC and DGC on all nodes" in {
-        visor.gc("-c")
-    }
+        it("should run GC and DGC on all nodes") {
+            visor.gc("-c")
+        }
+
+        it("should run GC and DGC on first node") {
+            visor.gc("-id8=@n0 -c")
+        }
 
-    it should "run GC and DGC on first node" in {
-        visor.gc("-id8=@n0 -c")
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/help/VisorHelpCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/help/VisorHelpCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/help/VisorHelpCommandSpec.scala
index b97cb85..43c6f52 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/help/VisorHelpCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/help/VisorHelpCommandSpec.scala
@@ -23,7 +23,7 @@ import org.scalatest._
 /**
  * Unit test for 'help' command.
  */
-class VisorHelpCommandSpec extends FlatSpec with Matchers {
+class VisorHelpCommandSpec extends FunSpec with Matchers {
     // Pre-initialize command so that help can be registered.
     commands.ack.VisorAckCommand
     commands.ping.VisorPingCommand
@@ -40,29 +40,34 @@ class VisorHelpCommandSpec extends FlatSpec with Matchers {
     commands.deploy.VisorDeployCommand
     commands.start.VisorStartCommand
 
-    "General help" should "properly execute via alias" in { visor.help() }
-    "General help" should "properly execute w/o alias" in { visor.help() }
-    "Help for 'start' command" should "properly execute" in { visor.help("start") }
-    "Help for 'deploy' command" should "properly execute" in { visor.help("deploy") }
-    "Help for 'events' command" should "properly execute" in { visor.help("events") }
-    "Help for 'mclear' command" should "properly execute" in { visor.help("mclear") }
-    "Help for 'cache' command" should "properly execute" in { visor.help("cache") }
-    "Help for 'disco' command" should "properly execute" in { visor.help("disco") }
-    "Help for 'alert' command" should "properly execute" in { visor.help("alert") }
-    "Help for 'node' command" should "properly execute" in { visor.help("node") }
-    "Help for 'vvm' command" should "properly execute" in { visor.help("vvm") }
-    "Help for 'kill' command" should "properly execute" in { visor.help("kill") }
-    "Help for 'top' command" should "properly execute" in { visor.help("top") }
-    "Help for 'config' command" should "properly execute" in { visor.help("config") }
-    "Help for 'ack' command" should "properly execute" in { visor.help("ack") }
-    "Help for 'ping' command" should "properly execute" in { visor.help("ping") }
-    "Help for 'close' command" should "properly execute" in { visor.help("close") }
-    "Help for 'open' command" should "properly execute" in { visor.help("open") }
-    "Help for 'status' command" should "properly execute" in { visor.help("status") }
-    "Help for 'mset' command" should "properly execute" in { visor.help("mset") }
-    "Help for 'mget' command" should "properly execute" in { visor.help("mget") }
-    "Help for 'mlist' command" should "properly execute" in { visor.help("mlist") }
-    "Help for 'help' command" should "properly execute" in { visor.help("help") }
-    "Help for 'log' command" should "properly execute" in { visor.help("log") }
-    "Help for 'dash' command" should "properly execute" in { visor.help("dash") }
+
+    describe("General help") {
+        it ("should properly execute via alias") { visor.searchCmd("?").get.emptyArgs }
+        it ("should properly execute w/o alias") { visor.searchCmd("help").get.emptyArgs }
+    }
+
+    describe("Help for command") {
+        it ("should properly execute for 'start' command") { visor.help("start") }
+        it ("should properly execute for 'deploy' command") { visor.help("deploy") }
+        it ("should properly execute for 'events' command") { visor.help("events") }
+        it ("should properly execute for 'mclear' command") { visor.help("mclear") }
+        it ("should properly execute for 'cache' command") { visor.help("cache") }
+        it ("should properly execute for 'disco' command") { visor.help("disco") }
+        it ("should properly execute for 'alert' command") { visor.help("alert") }
+        it ("should properly execute for 'node' command") { visor.help("node") }
+        it ("should properly execute for 'vvm' command") { visor.help("vvm") }
+        it ("should properly execute for 'kill' command") { visor.help("kill") }
+        it ("should properly execute for 'top' command") { visor.help("top") }
+        it ("should properly execute for 'config' command") { visor.help("config") }
+        it ("should properly execute for 'ack' command") { visor.help("ack") }
+        it ("should properly execute for 'ping' command") { visor.help("ping") }
+        it ("should properly execute for 'close' command") { visor.help("close") }
+        it ("should properly execute for 'open' command") { visor.help("open") }
+        it ("should properly execute for 'start' status") { visor.help("status") }
+        it ("should properly execute for 'start' mset") { visor.help("mset") }
+        it ("should properly execute for 'start' mget") { visor.help("mget") }
+        it ("should properly execute for 'start' mlist") { visor.help("mlist") }
+        it ("should properly execute for 'start' log") { visor.help("log") }
+        it ("should properly execute for 'start' dash") { visor.help("dash") }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/kill/VisorKillCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/kill/VisorKillCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/kill/VisorKillCommandSpec.scala
index 43ef313..2c659b5 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/kill/VisorKillCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/kill/VisorKillCommandSpec.scala
@@ -25,34 +25,34 @@ import org.apache.ignite.visor.commands.kill.VisorKillCommand._
 /**
  * Unit test for 'kill' command.
  */
-class VisorKillCommandSpec extends FlatSpec with Matchers {
-    behavior of "A 'kill' visor command"
-
-    it should "print error message with null argument" in {
-        visor.open("-d")
-        visor.kill(null)
-        visor.close()
-    }
-
-    it should "print error message if both kill and restart specified" in {
-        visor.open("-d")
-        visor.kill("-k -r")
-        visor.close()
-    }
-
-    it should "print error message if not connected" in {
-        visor.kill("-k")
-    }
-
-    it should "restart node" in {
-        visor.open("-d")
-        visor.kill("-r -id8=@n1")
-        visor.close()
-    }
-
-    it should "print error message" in {
-        visor.open("-d")
-        visor.kill("-r -id=xxx")
-        visor.close()
+class VisorKillCommandSpec extends FunSpec with Matchers {
+    describe("A 'kill' visor command") {
+        it("should print error message with null argument") {
+            visor.open("-d")
+            visor.kill(null)
+            visor.close()
+        }
+
+        it("should print error message if both kill and restart specified") {
+            visor.open("-d")
+            visor.kill("-k -r")
+            visor.close()
+        }
+
+        it("should print error message if not connected") {
+            visor.kill("-k")
+        }
+
+        it("should restart node") {
+            visor.open("-d")
+            visor.kill("-r -id8=@n1")
+            visor.close()
+        }
+
+        it("should print error message") {
+            visor.open("-d")
+            visor.kill("-r -id=xxx")
+            visor.close()
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/log/VisorLogCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/log/VisorLogCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/log/VisorLogCommandSpec.scala
index dcf7aae..ddb84ea 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/log/VisorLogCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/log/VisorLogCommandSpec.scala
@@ -23,10 +23,10 @@ import org.scalatest._
 /**
 * Unit test for 'log' command.
 */
-class VisorLogCommandSpec extends FlatSpec with Matchers {
-    behavior of "A 'log' visor command"
-
-    it should "print log status" in {
-        visor.log()
+class VisorLogCommandSpec extends FunSpec with Matchers {
+    describe("A 'log' visor command") {
+        it("should print log status") {
+            visor.log()
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/mem/VisorMemoryCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/mem/VisorMemoryCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/mem/VisorMemoryCommandSpec.scala
index 744d93b..27eaa94 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/mem/VisorMemoryCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/mem/VisorMemoryCommandSpec.scala
@@ -23,53 +23,60 @@ import org.scalatest._
 /**
  * Unit test for memory commands.
  */
-class VisorMemoryCommandSpec extends FlatSpec with Matchers {
-    "A 'mget' visor command" should "get correct value" in {
-        visor.mset("key", "value")
+class VisorMemoryCommandSpec extends FunSpec with Matchers {
+    describe("A 'mget' visor command") {
+        it("should get correct value") {
+            visor.mset("key", "value")
 
-        assertResult(Option("value"))(visor.mgetOpt("key"))
+            assertResult(Option("value"))(visor.mgetOpt("key"))
 
-        visor.mclear()
+            visor.mclear()
+        }
     }
 
-    "A 'mlist' visor command" should "list all variables" in {
-        visor.mset("key1", "value1")
-        visor.mset("key2", "value2")
-        visor.mset("key3", "value3")
+    describe("A 'mlist' visor command") {
+        it("should list all variables") {
+            visor.mset("key1", "value1")
+            visor.mset("key2", "value2")
+            visor.mset("key3", "value3")
 
-        visor.mlist()
-        visor.mclear()
-    }
+            visor.mlist()
+            visor.mclear()
+        }
 
-    "A 'mlist' visor command" should "list ax and cx variables" in {
-        visor.mset("a1", "1")
-        visor.mset("a2", "2")
-        visor.mset("b1", "3")
-        visor.mset("b2", "4")
-        visor.mset("c1", "5")
-        visor.mset("c2", "6")
+        it("should list ax and cx variables") {
+            visor.mset("a1", "1")
+            visor.mset("a2", "2")
+            visor.mset("b1", "3")
+            visor.mset("b2", "4")
+            visor.mset("c1", "5")
+            visor.mset("c2", "6")
 
-        visor.mlist("ac")
-        visor.mclear()
+            visor.mlist("ac")
+            visor.mclear()
+        }
     }
 
-    "A 'mclear' visor command" should "remove first two variables" in {
-        visor.mset("key1", "value1")
-        visor.mset("key2", "value2")
-        visor.mset("key3", "value3")
+    describe("A 'mclear' visor command") {
+        it("should remove first two variables") {
+            visor.mset("key1", "value1")
+            visor.mset("key2", "value2")
+            visor.mset("key3", "value3")
 
-        visor mclear "key1 key2"
+            visor mclear "key1 key2"
 
-        visor.mlist()
-        visor.mclear()
-    }
+            visor.mlist()
+            visor.mclear()
+
+        }
 
-    "A 'mclear' visor command" should "remove all variables" in {
-        visor.mset("key1", "value1")
-        visor.mset("key2", "value2")
-        visor.mset("key3", "value3")
+        it("should remove all variables") {
+            visor.mset("key1", "value1")
+            visor.mset("key2", "value2")
+            visor.mset("key3", "value3")
 
-        visor.mclear()
-        visor.mlist()
+            visor.mclear()
+            visor.mlist()
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/node/VisorNodeCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/node/VisorNodeCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/node/VisorNodeCommandSpec.scala
index 992ff7f..c0983c0 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/node/VisorNodeCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/node/VisorNodeCommandSpec.scala
@@ -24,19 +24,19 @@ import org.apache.ignite.visor.commands.node.VisorNodeCommand._
  * Unit test for 'node' command.
  */
 class VisorNodeCommandSpec extends VisorRuntimeBaseSpec(1) {
-    behavior of "A 'node' visor command"
+    describe("A 'node' visor command") {
+        it("should properly execute with valid node ID") {
+            visor.node("-id8=@n1")
+        }
 
-    it should "properly execute with valid node ID" in {
-        visor.node("-id8=@n1")
-    }
-
-    it should "print the error message for invalid node ID" in {
-        visor.node("-id8=zeee")
-    }
+        it("should print the error message for invalid node ID") {
+            visor.node("-id8=zeee")
+        }
 
-    it should "print error message when not connected" in {
-        closeVisorQuiet()
+        it("should print error message when not connected") {
+            closeVisorQuiet()
 
-        visor.node("") // Arguments are ignored.
+            visor.node("") // Arguments are ignored.
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/open/VisorOpenCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/open/VisorOpenCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/open/VisorOpenCommandSpec.scala
index 786d04e..4cf2204 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/open/VisorOpenCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/open/VisorOpenCommandSpec.scala
@@ -24,15 +24,15 @@ import org.apache.ignite.visor.{VisorRuntimeBaseSpec, visor}
  * Unit test for 'open' command.
  */
 class VisorOpenCommandSpec extends VisorRuntimeBaseSpec(3) {
-    behavior of "A 'open' visor command"
-
-    it should "properly connect using default configuration" in {
-        visor.mlist()
-    }
+    describe("A 'open' visor command") {
+        it("should properly connect using default configuration") {
+            visor.mlist()
+        }
 
-    it should "print error message when already connected" in {
-        intercept[IgniteException] {
-            openVisor()
+        it("should print error message when already connected") {
+            intercept[IgniteException] {
+                openVisor()
+            }
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/ping/VisorPingCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/ping/VisorPingCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/ping/VisorPingCommandSpec.scala
index dde5f18..06e3a22 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/ping/VisorPingCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/ping/VisorPingCommandSpec.scala
@@ -24,15 +24,15 @@ import org.apache.ignite.visor.commands.ping.VisorPingCommand._
  * Unit test for 'ping' command.
  */
 class VisorPingCommandSpec extends VisorRuntimeBaseSpec(2) {
-    behavior of "A 'ping' visor command"
+    describe("A 'ping' visor command") {
+        it("should properly execute") {
+            visor.ping()
+        }
 
-    it should "properly execute" in {
-        visor.ping()
-    }
-
-    it should "print error message when not connected" in {
-        closeVisorQuiet()
+        it("should print error message when not connected") {
+            closeVisorQuiet()
 
-        visor.ping()
+            visor.ping()
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/start/VisorStartCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/start/VisorStartCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/start/VisorStartCommandSpec.scala
index 1a451c4..c6404b5 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/start/VisorStartCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/start/VisorStartCommandSpec.scala
@@ -26,7 +26,7 @@ import org.apache.ignite.visor.commands.top.VisorTopologyCommand._
 /**
  * Unit test for 'start' command.
  */
-class VisorStartCommandSpec extends FlatSpec with Matchers with BeforeAndAfterAll {
+class VisorStartCommandSpec extends FunSpec with Matchers with BeforeAndAfterAll {
     override def beforeAll() {
         visor.open("-d")
     }
@@ -35,89 +35,89 @@ class VisorStartCommandSpec extends FlatSpec with Matchers with BeforeAndAfterAl
         visor.close()
     }
 
-    behavior of "A 'start' visor command"
+    describe("A 'start' visor command") {
+        it("should should start one new node") {
+            visor.start("-h=192.168.1.103 -r -p=password")
+        }
 
-    it should "should start one new node" in {
-        visor.start("-h=192.168.1.103 -r -p=password")
-    }
+        it("should should start two nodes") {
+            visor.start("-h=uname:passwd@localhost -n=2")
+        }
 
-    it should "should start two nodes" in {
-        visor.start("-h=uname:passwd@localhost -n=2")
-    }
+        it("should print error message with invalid port number") {
+            visor.start("-h=localhost:x -p=passwd")
+        }
 
-    it should "print error message with invalid port number" in {
-        visor.start("-h=localhost:x -p=passwd")
-    }
+        it("should print error message with zero port number") {
+            visor.start("-h=localhost:0 -p=passwd")
+        }
 
-    it should "print error message with zero port number" in {
-        visor.start("-h=localhost:0 -p=passwd")
-    }
+        it("should print error message with negative port number") {
+            visor.start("-h=localhost:-1 -p=passwd")
+        }
 
-    it should "print error message with negative port number" in {
-        visor.start("-h=localhost:-1 -p=passwd")
-    }
+        it("should print error message with invalid nodes count") {
+            visor.start("-h=localhost#x -p=passwd")
+        }
 
-    it should "print error message with invalid nodes count" in {
-        visor.start("-h=localhost#x -p=passwd")
-    }
+        it("should print error message with zero nodes count") {
+            visor.start("-h=localhost#0 -p=passwd")
+        }
 
-    it should "print error message with zero nodes count" in {
-        visor.start("-h=localhost#0 -p=passwd")
-    }
+        it("should print error message with negative nodes count") {
+            visor.start("-h=localhost#-1 -p=passwd")
+        }
 
-    it should "print error message with negative nodes count" in {
-        visor.start("-h=localhost#-1 -p=passwd")
-    }
+        it("should print error message with incorrect host") {
+            visor.start("-h=incorrect -p=passwd")
+        }
 
-    it should "print error message with incorrect host" in {
-        visor.start("-h=incorrect -p=passwd")
-    }
+        it("should print error message with incorrect username") {
+            visor.start("-h=incorrect@localhost -p=passwd")
+        }
 
-    it should "print error message with incorrect username" in {
-        visor.start("-h=incorrect@localhost -p=passwd")
-    }
+        it("should print error message with incorrect password") {
+            visor.start("-h=uname:incorrect@localhost")
+        }
 
-    it should "print error message with incorrect password" in {
-        visor.start("-h=uname:incorrect@localhost")
-    }
+        it("should print error message with nonexistent script path") {
+            visor.start("-h=uname:passwd@localhost -s=incorrect")
+        }
 
-    it should "print error message with nonexistent script path" in {
-        visor.start("-h=uname:passwd@localhost -s=incorrect")
-    }
+        it("should print error message with incorrect script path") {
+            visor.start("-h=uname:passwd@localhost -s=bin/readme.txt")
+        }
 
-    it should "print error message with incorrect script path" in {
-        visor.start("-h=uname:passwd@localhost -s=bin/readme.txt")
-    }
+        it("should print error message with nonexistent config path") {
+            visor.start("-h=uname:passwd@localhost -c=incorrect")
+        }
 
-    it should "print error message with nonexistent config path" in {
-        visor.start("-h=uname:passwd@localhost -c=incorrect")
-    }
+        it("should print error message with incorrect config path") {
+            visor.start("-h=uname:passwd@localhost -c=bin/readme.txt")
+        }
 
-    it should "print error message with incorrect config path" in {
-        visor.start("-h=uname:passwd@localhost -c=bin/readme.txt")
-    }
+        it("should start one node") {
+            visor.start("-h=uname:passwd@localhost")
 
-    it should "start one node" in {
-        visor.start("-h=uname:passwd@localhost")
+            visor.top()
+        }
 
-        visor.top()
-    }
-
-    it should "start one node on host identified by IP" in {
-        visor.start("-h=uname:passwd@127.0.0.1")
+        it("should start one node on host identified by IP") {
+            visor.start("-h=uname:passwd@127.0.0.1")
 
-        visor.top()
-    }
+            visor.top()
+        }
 
-    it should "start two nodes" in {
-        visor.start("-h=uname:passwd@localhost#2")
+        it("should start two nodes") {
+            visor.start("-h=uname:passwd@localhost#2")
 
-        visor.top()
-    }
+            visor.top()
+        }
 
-    it should "restart 4 nodes" in {
-        visor.start("-h=uname:passwd@localhost#4 -r")
+        it("should restart 4 nodes") {
+            visor.start("-h=uname:passwd@localhost#4 -r")
 
-        visor.top()
+            visor.top()
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommandSpec.scala
index 320a6bb..db07543 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommandSpec.scala
@@ -34,7 +34,7 @@ import scala.collection._
 /**
  * Unit test for 'tasks' command.
  */
-class VisorTasksCommandSpec extends FlatSpec with Matchers with BeforeAndAfterAll {
+class VisorTasksCommandSpec extends FunSpec with Matchers with BeforeAndAfterAll {
     /**
      * Open visor and execute several tasks before all tests.
      */
@@ -103,78 +103,78 @@ class VisorTasksCommandSpec extends FlatSpec with Matchers with BeforeAndAfterAl
         Ignition.stopAll(false)
     }
 
-    behavior of "A 'tasks' visor command"
-
-    it should "print tasks when called w/o arguments" in {
-        visor.tasks()
-    }
+    describe("A 'tasks' visor command") {
+        it("should print tasks when called w/o arguments") {
+            visor.tasks()
+        }
 
-    it should "print error message with incorrect argument" in {
-        visor.tasks("-xx")
-    }
+        it("should print error message with incorrect argument") {
+            visor.tasks("-xx")
+        }
 
-    it should "print task summary when called for specific task" in {
-        visor.tasks("-n=@t1")
-    }
+        it("should print task summary when called for specific task") {
+            visor.tasks("-n=@t1")
+        }
 
-    it should "print execution when called for specific execution" in {
-        visor.tasks("-e=@e1")
-    }
+        it("should print execution when called for specific execution") {
+            visor.tasks("-e=@e1")
+        }
 
-    it should "print all tasks" in {
-        visor.tasks("-l")
-    }
+        it("should print all tasks") {
+            visor.tasks("-l")
+        }
 
-    it should "print all tasks and executions" in {
-        visor.tasks("-l -a")
-    }
+        it("should print all tasks and executions") {
+            visor.tasks("-l -a")
+        }
 
-    it should "print tasks that started during last 5 seconds" in {
-        visor.tasks("-l -t=5s")
-    }
+        it("should print tasks that started during last 5 seconds") {
+            visor.tasks("-l -t=5s")
+        }
 
-    it should "print error message about invalid time period" in {
-        visor.tasks("-l -t=x2s")
-    }
+        it("should print error message about invalid time period") {
+            visor.tasks("-l -t=x2s")
+        }
 
-    it should "print error message about negative time period" in {
-        visor.tasks("-l -t=-10s")
-    }
+        it("should print error message about negative time period") {
+            visor.tasks("-l -t=-10s")
+        }
 
-    it should "print error message about invalid time period specification" in {
-        visor.tasks("-l -t=10x")
-    }
+        it("should print error message about invalid time period specification") {
+            visor.tasks("-l -t=10x")
+        }
 
-    it should "print task summary for the first task" in {
-        visor.tasks("-n=TestTask1")
-    }
+        it("should print task summary for the first task") {
+            visor.tasks("-n=TestTask1")
+        }
 
-    it should "print task summary and executions for the first task" in {
-        visor.tasks("-n=TestTask1 -a")
-    }
+        it("should print task summary and executions for the first task") {
+            visor.tasks("-n=TestTask1 -a")
+        }
 
-    it should "print list of tasks grouped by nodes" in {
-        visor.tasks("-g")
-    }
+        it("should print list of tasks grouped by nodes") {
+            visor.tasks("-g")
+        }
 
-    it should "print list of tasks that started during last 5 minutes grouped by nodes" in {
-        visor.tasks("-g -t=5m")
-    }
+        it("should print list of tasks that started during last 5 minutes grouped by nodes") {
+            visor.tasks("-g -t=5m")
+        }
 
-    it should "print list of tasks grouped by hosts" in {
-        visor.tasks("-h")
-    }
+        it("should print list of tasks grouped by hosts") {
+            visor.tasks("-h")
+        }
 
-    it should "print list of tasks that started during last 5 minutes grouped by hosts" in {
-        visor.tasks("-h -t=5m")
-    }
+        it("should print list of tasks that started during last 5 minutes grouped by hosts") {
+            visor.tasks("-h -t=5m")
+        }
 
-    it should "print list of tasks filtered by substring" in {
-        visor.tasks("-s=TestTask")
-    }
+        it("should print list of tasks filtered by substring") {
+            visor.tasks("-s=TestTask")
+        }
 
-    it should "print list of tasks and executions filtered by substring" in {
-        visor.tasks("-s=TestTask -a")
+        it("should print list of tasks and executions filtered by substring") {
+            visor.tasks("-s=TestTask -a")
+        }
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommandSpec.scala
index 3a3b6e5..515cf67 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommandSpec.scala
@@ -24,39 +24,39 @@ import org.apache.ignite.visor.commands.top.VisorTopologyCommand._
  * Unit test for topology commands.
  */
 class VisorTopologyCommandSpec extends VisorRuntimeBaseSpec(2) {
-    behavior of "A 'top' visor command"
+    describe("A 'top' visor command") {
+        it("should advise to connect") {
+            closeVisorQuiet()
 
-    it should "advise to connect" in {
-        closeVisorQuiet()
+            visor.top()
+        }
 
-        visor.top()
-    }
-
-    it should "print error message" in {
-        visor.top("-cc=eq1x")
-    }
+        it("should print error message") {
+            visor.top("-cc=eq1x")
+        }
 
-    it should "print full topology" in {
-        visor.top()
-    }
+        it("should print full topology") {
+            visor.top()
+        }
 
-    it should "print nodes with idle time greater than 12000ms" in {
-        visor.top("-it=gt12000")
-    }
+        it("should print nodes with idle time greater than 12000ms") {
+            visor.top("-it=gt12000")
+        }
 
-    it should "print nodes with idle time greater than 12sec" in {
-        visor.top("-it=gt12s")
-    }
+        it("should print nodes with idle time greater than 12sec") {
+            visor.top("-it=gt12s")
+        }
 
-    it should "print full information about all nodes" in {
-        visor.top("-a")
-    }
+        it("should print full information about all nodes") {
+            visor.top("-a")
+        }
 
-    it should "print information about nodes on localhost" in {
-        visor.top("-h=192.168.1.100")
-    }
+        it("should print information about nodes on localhost") {
+            visor.top("-h=192.168.1.100")
+        }
 
-    it should "print full information about nodes on localhost" in {
-        visor.top("-h=localhost")
+        it("should print full information about nodes on localhost") {
+            visor.top("-h=localhost")
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommandSpec.scala
index 969fb94..1a4bc3e 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommandSpec.scala
@@ -25,22 +25,22 @@ import org.apache.ignite.visor.commands.vvm.VisorVvmCommand._
 /**
  * Unit test for 'vvm' command.
  */
-class VisorVvmCommandSpec extends FlatSpec with Matchers {
-    behavior of "A 'vvm' visor command"
+class VisorVvmCommandSpec extends FunSpec with Matchers {
+    describe("A 'vvm' visor command") {
+        it("should print error message when not connected") {
+            visor.vvm()
+        }
 
-    it should "print error message when not connected" in {
-        visor.vvm()
-    }
-
-    it should "open VisualVM connected to all nodes skipping ones with disabled JMX" in {
-        visor.open("-d")
-        visor.vvm()
-        visor.close()
-    }
+        it("should open VisualVM connected to all nodes skipping ones with disabled JMX") {
+            visor.open("-d")
+            visor.vvm()
+            visor.close()
+        }
 
-    it should "open VisualVM connected to first node if it has JMX enabled" in {
-        visor.open("-d")
-        visor.vvm("-id8=@n1")
-        visor.close()
+        it("should open VisualVM connected to first node if it has JMX enabled") {
+            visor.open("-d")
+            visor.vvm("-id8=@n1")
+            visor.close()
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/visor-plugins/pom.xml
----------------------------------------------------------------------
diff --git a/modules/visor-plugins/pom.xml b/modules/visor-plugins/pom.xml
index 4e58ab8..46b136e 100644
--- a/modules/visor-plugins/pom.xml
+++ b/modules/visor-plugins/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-visor-plugins</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <!-- Ignite dependencies -->

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/web/pom.xml
----------------------------------------------------------------------
diff --git a/modules/web/pom.xml b/modules/web/pom.xml
index de50712..df6e923 100644
--- a/modules/web/pom.xml
+++ b/modules/web/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-web</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/yardstick/config/benchmark-client-mode.properties
----------------------------------------------------------------------
diff --git a/modules/yardstick/config/benchmark-client-mode.properties b/modules/yardstick/config/benchmark-client-mode.properties
new file mode 100644
index 0000000..8941417
--- /dev/null
+++ b/modules/yardstick/config/benchmark-client-mode.properties
@@ -0,0 +1,89 @@
+# 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.
+
+#
+# Contains all multicast benchmarks
+#
+
+# JVM options.
+JVM_OPTS=${JVM_OPTS}" -DIGNITE_QUIET=false"
+
+# Uncomment to enable concurrent garbage collection (GC) if you encounter long GC pauses.
+JVM_OPTS=${JVM_OPTS}" \
+-Xloggc:./gc.log \
+-XX:+PrintGCDetails \
+-verbose:gc \
+-XX:+UseParNewGC \
+-XX:+UseConcMarkSweepGC \
+-XX:+UseTLAB \
+-XX:NewSize=128m \
+-XX:MaxNewSize=128m \
+-XX:MaxTenuringThreshold=0 \
+-XX:SurvivorRatio=1024 \
+-XX:+UseCMSInitiatingOccupancyOnly \
+-XX:CMSInitiatingOccupancyFraction=60 \
+"
+#Ignite version
+ver="RELEASE-"
+
+# List of default probes.
+# Add DStatProbe or VmStatProbe if your OS supports it (e.g. if running on Linux).
+BENCHMARK_DEFAULT_PROBES=ThroughputLatencyProbe,PercentileProbe,DStatProbe
+
+# Packages where the specified benchmark is searched by reflection mechanism.
+BENCHMARK_PACKAGES=org.yardstickframework,org.apache.ignite.yardstick
+
+RESTART_SERVERS=true
+
+# Probe point writer class name.
+# BENCHMARK_WRITER=
+
+# Comma-separated list of the hosts to run BenchmarkServers on.
+SERVER_HOSTS=localhost,localhost,localhost
+
+# Comma-separated list of the hosts to run BenchmarkDrivers on.
+DRIVER_HOSTS=localhost
+
+# Remote username.
+# REMOTE_USER=
+
+# Number of nodes, used to wait for the specified number of nodes to start.
+nodesNum=$((`echo ${SERVER_HOSTS} | tr ',' '\n' | wc -l` + `echo ${DRIVER_HOSTS} | tr ',' '\n' | wc -l`))
+
+# Run configuration which contains all benchmarks.
+# Note that each benchmark is set to run for 300 seconds (5 mins) with warm-up set to 60 seconds (1 minute).
+CONFIGS="\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgnitePutBenchmark -sn IgniteNode -ds ${ver}atomic-put-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgnitePutGetBenchmark -sn IgniteNode -ds ${ver}atomic-put-get-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgnitePutTxBenchmark -sn IgniteNode -ds ${ver}tx-put-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgnitePutGetTxBenchmark -sn IgniteNode -ds ${ver}tx-put-get-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgniteSqlQueryBenchmark -sn IgniteNode -ds ${ver}sql-query-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgniteSqlQueryJoinBenchmark -sn IgniteNode -ds ${ver}sql-query-join-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgniteSqlQueryPutBenchmark -sn IgniteNode -ds ${ver}sql-query-put-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -j 10 -dn IgniteAffinityCallBenchmark -sn IgniteNode -ds ${ver}affcall-compute-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -j 10 -dn IgniteApplyBenchmark -sn IgniteNode -ds ${ver}apply-compute-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -j 10 -dn IgniteBroadcastBenchmark -sn IgniteNode -ds ${ver}broad-compute-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -j 10 -dn IgniteExecuteBenchmark -sn IgniteNode -ds ${ver}exec-compute-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -j 10 -dn IgniteRunBenchmark -sn IgniteNode -ds ${ver}run-compute-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgnitePutGetOffHeapBenchmark -sn IgniteNode -ds ${ver}atomic-put-get-offheap-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgnitePutGetOffHeapValuesBenchmark -sn IgniteNode -ds ${ver}atomic-put-get-offheap-val-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgnitePutOffHeapBenchmark -sn IgniteNode -ds ${ver}atomic-put-offheap-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgnitePutOffHeapValuesBenchmark -sn IgniteNode -ds ${ver}atomic-put-offheap-val-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgnitePutTxOffHeapBenchmark -sn IgniteNode -ds ${ver}tx-put-offheap-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgnitePutTxOffHeapValuesBenchmark -sn IgniteNode -ds ${ver}tx-put-offheap-val-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgniteSqlQueryOffHeapBenchmark -sn IgniteNode -ds ${ver}sql-query-offheap-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgniteSqlQueryJoinOffHeapBenchmark -sn IgniteNode -ds ${ver}sql-query-join-offheap-1-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-multicast-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 --client -sm PRIMARY_SYNC -dn IgniteSqlQueryPutOffHeapBenchmark -sn IgniteNode -ds ${ver}sql-query-put-offheap-1-backup\
+"

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/yardstick/pom.xml
----------------------------------------------------------------------
diff --git a/modules/yardstick/pom.xml b/modules/yardstick/pom.xml
index 6bd65cc..3d4ce66 100644
--- a/modules/yardstick/pom.xml
+++ b/modules/yardstick/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-yardstick</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <properties>
         <yardstick.version>0.7.0</yardstick.version>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 661b310..a514e35 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -317,6 +317,10 @@
                                 <title>Spring Caching</title>
                                 <packages>org.apache.ignite.cache.spring</packages>
                             </group>
+                            <group>
+                                <title>Mesos Framework</title>
+                                <packages>org.apache.ignite.mesos*</packages>
+                            </group>
                         </groups>
                         <header>
                             <![CDATA[
@@ -628,10 +632,15 @@
                                         <exclude>src/test/java/org/apache/ignite/spi/deployment/uri/META-INF/ignite.empty</exclude><!--should be empty-->
                                         <exclude>src/test/java/org/apache/ignite/spi/deployment/uri/META-INF/ignite.brokenxml</exclude><!--test resource-->
                                         <exclude>src/test/java/org/apache/ignite/internal/processors/hadoop/books/*.txt</exclude><!--books examples-->
+                                        <exclude>src/main/java/org/apache/ignite/examples/streaming/wordcount/*.txt</exclude><!--books examples-->
                                         <exclude>examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/*.txt</exclude><!--books examples-->
                                         <exclude>src/main/java/META-INF/services/javax.cache.spi.CachingProvider</exclude><!--cannot be changed-->
                                         <exclude>src/main/java/org/jetbrains/annotations/*.java</exclude><!--copyright-->
                                         <exclude>src/main/resources/META-INF/services/org.apache.hadoop.mapreduce.protocol.ClientProtocolProvider</exclude><!--cannot be changed-->
+                                        <exclude>dev-tools/IGNITE-*.patch</exclude>
+                                        <exclude>dev-tools/.gradle/**/*</exclude>
+                                        <exclude>dev-tools/gradle/wrapper/**/*</exclude>
+                                        <exclude>dev-tools/gradlew</exclude>
                                         <!--shmem-->
                                         <exclude>ipc/shmem/**/Makefile.in</exclude><!--auto generated files-->
                                         <exclude>ipc/shmem/**/Makefile</exclude><!--auto generated files-->


[20/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 b8668e6..02f16c0 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
@@ -24,6 +24,10 @@ import org.apache.ignite.internal.cluster.*;
 import org.apache.ignite.internal.managers.communication.*;
 import org.apache.ignite.internal.managers.deployment.*;
 import org.apache.ignite.internal.processors.affinity.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.typedef.*;
@@ -32,7 +36,6 @@ import org.apache.ignite.lang.*;
 import org.jetbrains.annotations.*;
 import org.jsr166.*;
 
-import java.io.*;
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
@@ -146,9 +149,8 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter {
             c = clsHandlers.get(new ListenerKey(cacheMsg.cacheId(), cacheMsg.getClass()));
 
         if (c == null) {
-            if (log.isDebugEnabled())
-                log.debug("Received message without registered handler (will ignore) [msg=" + cacheMsg +
-                    ", nodeId=" + nodeId + ']');
+            U.warn(log, "Received message without registered handler (will ignore) [msg=" + cacheMsg +
+                ", nodeId=" + nodeId + ']');
 
             return;
         }
@@ -226,69 +228,67 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter {
 
             unmarshall(nodeId, cacheMsg);
 
-            if (cacheMsg.allowForStartup())
-                processMessage(nodeId, cacheMsg, c);
+            if (cacheMsg.classError() != null)
+                processFailedMessage(nodeId, cacheMsg);
             else {
-                IgniteInternalFuture<?> startFut = startFuture(cacheMsg);
-
-                if (startFut.isDone())
+                if (cacheMsg.allowForStartup())
                     processMessage(nodeId, cacheMsg, c);
                 else {
-                    if (log.isDebugEnabled())
-                        log.debug("Waiting for start future to complete for message [nodeId=" + nodeId +
-                            ", locId=" + cctx.localNodeId() + ", msg=" + cacheMsg + ']');
-
-                    // Don't hold this thread waiting for preloading to complete.
-                    startFut.listen(new CI1<IgniteInternalFuture<?>>() {
-                        @Override public void apply(final IgniteInternalFuture<?> f) {
-                            cctx.kernalContext().closure().runLocalSafe(
-                                new GridPlainRunnable() {
-                                    @Override public void run() {
-                                        rw.readLock();
-
-                                        try {
-                                            if (stopping) {
-                                                if (log.isDebugEnabled())
-                                                    log.debug("Received cache communication message while stopping " +
-                                                        "(will ignore) [nodeId=" + nodeId + ", msg=" + cacheMsg + ']');
+                    IgniteInternalFuture<?> startFut = startFuture(cacheMsg);
 
-                                                return;
-                                            }
+                    if (startFut.isDone())
+                        processMessage(nodeId, cacheMsg, c);
+                    else {
+                        if (log.isDebugEnabled())
+                            log.debug("Waiting for start future to complete for message [nodeId=" + nodeId +
+                                ", locId=" + cctx.localNodeId() + ", msg=" + cacheMsg + ']');
 
-                                            f.get();
+                        // Don't hold this thread waiting for preloading to complete.
+                        startFut.listen(new CI1<IgniteInternalFuture<?>>() {
+                            @Override public void apply(final IgniteInternalFuture<?> f) {
+                                cctx.kernalContext().closure().runLocalSafe(
+                                    new GridPlainRunnable() {
+                                        @Override public void run() {
+                                            rw.readLock();
 
-                                            if (log.isDebugEnabled())
-                                                log.debug("Start future completed for message [nodeId=" + nodeId +
-                                                    ", locId=" + cctx.localNodeId() + ", msg=" + cacheMsg + ']');
+                                            try {
+                                                if (stopping) {
+                                                    if (log.isDebugEnabled())
+                                                        log.debug("Received cache communication message while stopping " +
+                                                            "(will ignore) [nodeId=" + nodeId + ", msg=" + cacheMsg + ']');
 
-                                            processMessage(nodeId, cacheMsg, c);
-                                        }
-                                        catch (IgniteCheckedException e) {
-                                            // Log once.
-                                            if (startErr.compareAndSet(false, true))
-                                                U.error(log, "Failed to complete preload start future " +
-                                                    "(will ignore message) " +
-                                                    "[fut=" + f + ", nodeId=" + nodeId + ", msg=" + cacheMsg + ']', e);
-                                        }
-                                        finally {
-                                            rw.readUnlock();
+                                                    return;
+                                                }
+
+                                                f.get();
+
+                                                if (log.isDebugEnabled())
+                                                    log.debug("Start future completed for message [nodeId=" + nodeId +
+                                                        ", locId=" + cctx.localNodeId() + ", msg=" + cacheMsg + ']');
+
+                                                processMessage(nodeId, cacheMsg, c);
+                                            }
+                                            catch (IgniteCheckedException e) {
+                                                // Log once.
+                                                if (startErr.compareAndSet(false, true))
+                                                    U.error(log, "Failed to complete preload start future " +
+                                                        "(will ignore message) " +
+                                                        "[fut=" + f + ", nodeId=" + nodeId + ", msg=" + cacheMsg + ']', e);
+                                            }
+                                            finally {
+                                                rw.readUnlock();
+                                            }
                                         }
                                     }
-                                }
-                            );
-                        }
-                    });
+                                );
+                            }
+                        });
+                    }
                 }
             }
         }
         catch (Throwable e) {
-            if (X.hasCause(e, ClassNotFoundException.class))
-                U.error(log, "Failed to process message (note that distributed services " +
-                    "do not support peer class loading, if you deploy distributed service " +
-                    "you should have all required classes in CLASSPATH on all nodes in topology) " +
-                    "[senderId=" + nodeId + ", err=" + X.cause(e, ClassNotFoundException.class).getMessage() + ']');
-            else
-                U.error(log, "Failed to process message [senderId=" + nodeId + ']', e);
+            U.error(log, "Failed to process message [senderId=" + nodeId + ", messageType=" + cacheMsg.getClass() + ']', e);
 
             if (e instanceof Error)
                 throw (Error)e;
@@ -302,6 +302,208 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
+     * Sends response on failed message.
+     * @param nodeId node id.
+     * @param res response.
+     * @param cctx shared context.
+     * @param plc grid io policy.
+     */
+    private void sendResponseOnFailedMessage(UUID nodeId, GridCacheMessage res, GridCacheSharedContext cctx,
+        GridIoPolicy plc) {
+        try {
+            cctx.io().send(nodeId, res, plc);
+        }
+        catch (IgniteCheckedException e) {
+            U.error(log, "Failed to send response to node (is node still alive?) [nodeId=" + nodeId +
+                ",res=" + res + ']', e);
+        }
+    }
+
+    /**
+     * Processes failed messages.
+     * @param nodeId niode id.
+     * @param msg message.
+     * @throws IgniteCheckedException
+     */
+    private void processFailedMessage(UUID nodeId, GridCacheMessage msg) throws IgniteCheckedException {
+        GridCacheContext ctx = cctx.cacheContext(msg.cacheId());
+
+        switch (msg.directType()) {
+            case 14: {
+                GridCacheEvictionRequest req = (GridCacheEvictionRequest)msg;
+
+                GridCacheEvictionResponse res = new GridCacheEvictionResponse(
+                    ctx.cacheId(),
+                    req.futureId(),
+                    req.classError() != null
+                );
+
+                sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy());
+            }
+
+            break;
+
+            case 30: {
+                GridDhtLockRequest req = (GridDhtLockRequest)msg;
+
+                GridDhtLockResponse res = new GridDhtLockResponse(
+                    ctx.cacheId(),
+                    req.version(),
+                    req.futureId(),
+                    req.miniId(),
+                    0);
+
+                sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy());
+            }
+
+            break;
+
+            case 34: {
+                GridDhtTxPrepareRequest req = (GridDhtTxPrepareRequest)msg;
+
+                GridDhtTxPrepareResponse res = new GridDhtTxPrepareResponse(
+                    req.version(),
+                    req.futureId(),
+                    req.miniId());
+
+                res.error(req.classError());
+
+                sendResponseOnFailedMessage(nodeId, res, cctx, req.policy());
+            }
+
+            break;
+
+            case 38: {
+                GridDhtAtomicUpdateRequest req = (GridDhtAtomicUpdateRequest)msg;
+
+                GridDhtAtomicUpdateResponse res = new GridDhtAtomicUpdateResponse(
+                    ctx.cacheId(),
+                    req.futureVersion());
+
+                res.onError(req.classError());
+
+                sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy());
+            }
+
+            break;
+
+            case 40: {
+                GridNearAtomicUpdateRequest req = (GridNearAtomicUpdateRequest)msg;
+
+                GridNearAtomicUpdateResponse res = new GridNearAtomicUpdateResponse(
+                    ctx.cacheId(),
+                    nodeId,
+                    req.futureVersion());
+
+                res.error(req.classError());
+
+                sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy());
+            }
+
+            break;
+
+            case 42: {
+                GridDhtForceKeysRequest req = (GridDhtForceKeysRequest)msg;
+
+                GridDhtForceKeysResponse res = new GridDhtForceKeysResponse(
+                    ctx.cacheId(),
+                    req.futureId(),
+                    req.miniId()
+                );
+
+                res.error(req.classError());
+
+                sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy());
+            }
+
+            break;
+
+            case 45: {
+                GridDhtPartitionSupplyMessage req = (GridDhtPartitionSupplyMessage)msg;
+
+                U.error(log, "Supply message cannot be unmarshalled.", req.classError());
+            }
+
+            break;
+
+            case 49: {
+                GridNearGetRequest req = (GridNearGetRequest)msg;
+
+                GridNearGetResponse res = new GridNearGetResponse(
+                    ctx.cacheId(),
+                    req.futureId(),
+                    req.miniId(),
+                    req.version());
+
+                res.error(req.classError());
+
+                sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy());
+            }
+
+            break;
+
+            case 50: {
+                GridNearGetResponse res = (GridNearGetResponse)msg;
+
+                GridPartitionedGetFuture fut = (GridPartitionedGetFuture)ctx.mvcc().future(
+                    res.version(), res.futureId());
+
+                if (fut == null) {
+                    if (log.isDebugEnabled())
+                        log.debug("Failed to find future for get response [sender=" + nodeId + ", res=" + res + ']');
+
+                    return;
+                }
+
+                res.error(res.classError());
+
+                fut.onResult(nodeId, res);
+            }
+
+            break;
+
+            case 51: {
+                GridNearLockRequest req = (GridNearLockRequest)msg;
+
+                GridNearLockResponse res = new GridNearLockResponse(
+                    ctx.cacheId(),
+                    req.version(),
+                    req.futureId(),
+                    req.miniId(),
+                    false,
+                    0,
+                    req.classError());
+
+                sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy());
+            }
+
+            break;
+
+            case 55: {
+                GridNearTxPrepareRequest req = (GridNearTxPrepareRequest)msg;
+
+                GridNearTxPrepareResponse res = new GridNearTxPrepareResponse(
+                    req.version(),
+                    req.futureId(),
+                    req.miniId(),
+                    req.version(),
+                    req.version(),
+                    null, null, null);
+
+                res.error(req.classError());
+
+                sendResponseOnFailedMessage(nodeId, res, cctx, req.policy());
+            }
+
+            break;
+
+            default:
+                throw new IgniteCheckedException("Failed to send response to node. Unsupported direct type [message="
+                    + msg + "]");
+        }
+    }
+
+    /**
      * @param cacheMsg Cache message to get start future.
      * @return Preloader start future.
      */
@@ -744,16 +946,12 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter {
             cacheMsg.finishUnmarshal(cctx, cctx.deploy().globalLoader());
         }
         catch (IgniteCheckedException e) {
-            if (cacheMsg.ignoreClassErrors() && X.hasCause(e, InvalidClassException.class,
-                    ClassNotFoundException.class, NoClassDefFoundError.class, UnsupportedClassVersionError.class))
-                cacheMsg.onClassError(e);
-            else
-                throw e;
+            cacheMsg.onClassError(e);
         }
         catch (Error e) {
             if (cacheMsg.ignoreClassErrors() && X.hasCause(e, NoClassDefFoundError.class,
                 UnsupportedClassVersionError.class))
-                    cacheMsg.onClassError(new IgniteCheckedException("Failed to load class during unmarshalling: " + e, e));
+                cacheMsg.onClassError(new IgniteCheckedException("Failed to load class during unmarshalling: " + e, e));
             else
                 throw e;
         }
@@ -782,7 +980,7 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter {
         }
 
         /** {@inheritDoc} */
-        @SuppressWarnings( {"CatchGenericClass", "unchecked"})
+        @SuppressWarnings({"CatchGenericClass", "unchecked"})
         @Override public void onMessage(final UUID nodeId, Object msg) {
             if (log.isDebugEnabled())
                 log.debug("Received cache ordered message [nodeId=" + nodeId + ", msg=" + msg + ']');

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 3dcd0ec..92035af 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
@@ -115,9 +115,6 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
     @GridToStringInclude
     private final int hash;
 
-    /** Off-heap value pointer. */
-    protected long valPtr;
-
     /** Extras */
     @GridToStringInclude
     private GridCacheEntryExtras extras;
@@ -188,7 +185,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         if (cctx.cache().isIgfsDataCache() &&
             cctx.kernalContext().igfsHelper().isIgfsBlockKey(key.value(cctx.cacheObjectContext(), false))) {
             int newSize = valueLength0(val, null);
-            int oldSize = valueLength0(this.val, (this.val == null && valPtr != 0) ? valueBytes0() : null);
+            int oldSize = valueLength0(this.val, (this.val == null && hasOffHeapPointer()) ? valueBytes0() : null);
 
             int delta = newSize - oldSize;
 
@@ -199,7 +196,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         if (!isOffHeapValuesOnly()) {
             this.val = val;
 
-            valPtr = 0;
+            offHeapPointer(0);
         }
         else {
             try {
@@ -227,12 +224,12 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                 if (val != null) {
                     byte type = val.type();
 
-                    valPtr = mem.putOffHeap(valPtr, val.valueBytes(cctx.cacheObjectContext()), type);
+                    offHeapPointer(mem.putOffHeap(offHeapPointer(), val.valueBytes(cctx.cacheObjectContext()), type));
                 }
                 else {
-                    mem.removeOffHeap(valPtr);
+                    mem.removeOffHeap(offHeapPointer());
 
-                    valPtr = 0;
+                    offHeapPointer(0);
                 }
             }
             catch (IgniteCheckedException e) {
@@ -270,7 +267,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
         CacheObject val0 = val;
 
-        if (val0 == null && valPtr != 0) {
+        if (val0 == null && hasOffHeapPointer()) {
             IgniteBiTuple<byte[], Byte> t = valueBytes0();
 
             return cctx.cacheObjects().toCacheObject(cctx.cacheObjectContext(), t.get2(), t.get1());
@@ -434,16 +431,16 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
                     if (e != null) {
                         if (e.offheapPointer() > 0) {
-                            valPtr = e.offheapPointer();
+                            offHeapPointer(e.offheapPointer());
 
                             if (needVal) {
-                                CacheObject val = cctx.fromOffheap(valPtr, false);
+                                CacheObject val = cctx.fromOffheap(offHeapPointer(), false);
 
                                 e.value(val);
                             }
                         }
                         else // Read from swap.
-                            valPtr = 0;
+                            offHeapPointer(0);
                     }
                 }
                 else
@@ -468,7 +465,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
                         // Must update valPtr again since update() will reset it.
                         if (cctx.offheapTiered() && e.offheapPointer() > 0)
-                            valPtr = e.offheapPointer();
+                            offHeapPointer(e.offheapPointer());
 
                         return val;
                     }
@@ -495,13 +492,13 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                 if (cctx.offheapTiered()) {
                     cctx.swap().removeOffheap(key);
 
-                    valPtr = 0;
+                    offHeapPointer(0);
                 }
 
                 return;
             }
 
-            if (val == null && cctx.offheapTiered() && valPtr != 0) {
+            if (val == null && cctx.offheapTiered() && hasOffHeapPointer()) {
                 if (log.isDebugEnabled())
                     log.debug("Value did not change, skip write swap entry: " + this);
 
@@ -540,10 +537,10 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
     protected IgniteBiTuple<byte[], Byte> valueBytes0() {
         assert Thread.holdsLock(this);
 
-        if (valPtr != 0) {
+        if (hasOffHeapPointer()) {
             assert isOffHeapValuesOnly() || cctx.offheapTiered();
 
-            return cctx.unsafeMemory().get(valPtr);
+            return cctx.unsafeMemory().get(offHeapPointer());
         }
         else {
             assert val != null;
@@ -672,7 +669,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
             CacheObject val = this.val;
 
-            hasOldBytes = valPtr != 0;
+            hasOldBytes = hasOffHeapPointer();
 
             if ((unmarshal || isOffHeapValuesOnly()) && !expired && val == null && hasOldBytes)
                 val = rawGetOrUnmarshalUnlocked(tmp);
@@ -816,7 +813,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                         // Update indexes before actual write to entry.
                         updateIndex(ret, expTime, nextVer, prevVal);
 
-                    boolean hadValPtr = valPtr != 0;
+                    boolean hadValPtr = hasOffHeapPointer();
 
                     // Don't change version for read-through.
                     update(ret, expTime, ttl, nextVer);
@@ -964,13 +961,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         synchronized (this) {
             checkObsolete();
 
-            if (cctx.kernalContext().config().isCacheSanityCheckEnabled()) {
-                if (tx != null && tx.groupLock())
-                    groupLockSanityCheck(tx);
-                else
-                    assert tx == null || (!tx.local() && tx.onePhaseCommit()) || tx.ownsLock(this) :
-                        "Transaction does not own lock for update [entry=" + this + ", tx=" + tx + ']';
-            }
+            assert tx == null || (!tx.local() && tx.onePhaseCommit()) || tx.ownsLock(this) :
+                "Transaction does not own lock for update [entry=" + this + ", tx=" + tx + ']';
 
             // Load and remove from swap if it is new.
             boolean startVer = isStartVersion();
@@ -1128,10 +1120,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         synchronized (this) {
             checkObsolete();
 
-            if (tx != null && tx.groupLock() && cctx.kernalContext().config().isCacheSanityCheckEnabled())
-                groupLockSanityCheck(tx);
-            else
-                assert tx == null || (!tx.local() && tx.onePhaseCommit()) || tx.ownsLock(this) :
+            assert tx == null || (!tx.local() && tx.onePhaseCommit()) || tx.ownsLock(this) :
                     "Transaction does not own lock for remove[entry=" + this + ", tx=" + tx + ']';
 
             boolean startVer = isStartVersion();
@@ -1164,7 +1153,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
             // can be updated without actually holding entry lock.
             clearIndex(old);
 
-            boolean hadValPtr = valPtr != 0;
+            boolean hadValPtr = hasOffHeapPointer();
 
             update(null, 0, 0, newVer);
 
@@ -1198,7 +1187,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                 obsoleteVer = newVer;
             else {
                 // Only delete entry if the lock is not explicit.
-                if (tx.groupLock() || lockedBy(tx.xidVersion()))
+                if (lockedBy(tx.xidVersion()))
                     obsoleteVer = tx.xidVersion();
                 else if (log.isDebugEnabled())
                     log.debug("Obsolete version was not set because lock was explicit: " + this);
@@ -1521,7 +1510,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                     // Must persist inside synchronization in non-tx mode.
                     cctx.store().remove(null, keyValue(false));
 
-                boolean hasValPtr = valPtr != 0;
+                boolean hasValPtr = hasOffHeapPointer();
 
                 // Update index inside synchronization since it can be updated
                 // in load methods without actually holding entry lock.
@@ -2122,7 +2111,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
                 enqueueVer = newVer;
 
-                boolean hasValPtr = valPtr != 0;
+                boolean hasValPtr = hasOffHeapPointer();
 
                 // Clear value on backup. Entry will be removed from cache when it got evicted from queue.
                 update(null, CU.TTL_ETERNAL, CU.EXPIRE_TIME_ETERNAL, newVer);
@@ -2799,25 +2788,6 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
     }
 
     /**
-     * Checks that entries in group locks transactions are not locked during commit.
-     *
-     * @param tx Transaction to check.
-     * @throws GridCacheEntryRemovedException If entry is obsolete.
-     * @throws IgniteCheckedException If entry was externally locked.
-     */
-    private void groupLockSanityCheck(IgniteInternalTx tx) throws GridCacheEntryRemovedException, IgniteCheckedException {
-        assert tx.groupLock();
-
-        IgniteTxEntry txEntry = tx.entry(txKey());
-
-        if (txEntry.groupLockEntry()) {
-            if (lockedByAny())
-                throw new IgniteCheckedException("Failed to update cache entry (entry was externally locked while " +
-                    "accessing entry within group lock transaction) [entry=" + this + ", tx=" + tx + ']');
-        }
-    }
-
-    /**
      * @param failFast Fail fast flag.
      * @param topVer Topology version.
      * @param filter Filter.
@@ -2929,8 +2899,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         if (val != null)
             return val;
 
-        if (valPtr != 0) {
-            CacheObject val0 = cctx.fromOffheap(valPtr, tmp);
+        if (hasOffHeapPointer()) {
+            CacheObject val0 = cctx.fromOffheap(offHeapPointer(), tmp);
 
             if (!tmp && cctx.kernalContext().config().isPeerClassLoadingEnabled())
                 val0.finishUnmarshal(cctx.cacheObjectContext(), cctx.deploy().globalLoader());
@@ -2952,7 +2922,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
     protected boolean hasValueUnlocked() {
         assert Thread.holdsLock(this);
 
-        return val != null || valPtr != 0;
+        return val != null || hasOffHeapPointer();
     }
 
     /** {@inheritDoc} */
@@ -3292,12 +3262,13 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
     @Override public boolean onTtlExpired(GridCacheVersion obsoleteVer) {
         boolean obsolete = false;
         boolean deferred = false;
+        GridCacheVersion ver0 = null;
 
         try {
             synchronized (this) {
                 CacheObject expiredVal = saveValueForIndexUnlocked();
 
-                boolean hasOldBytes = valPtr != 0;
+                boolean hasOldBytes = hasOffHeapPointer();
 
                 boolean expired = checkExpired();
 
@@ -3305,7 +3276,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                     if (!obsolete()) {
                         if (cctx.deferredDelete() && !detached() && !isInternal()) {
                             if (!deletedUnlocked()) {
-                                update(null, 0L, 0L, ver);
+                                update(null, 0L, 0L, ver0 = ver);
 
                                 deletedUnlocked(true);
 
@@ -3345,11 +3316,20 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
             U.error(log, "Failed to clean up expired cache entry: " + this, e);
         }
         finally {
-            if (obsolete)
+            if (obsolete) {
                 onMarkedObsolete();
 
-            if (deferred)
-                cctx.onDeferredDelete(this, obsoleteVer);
+                cctx.cache().removeEntry(this);
+            }
+
+            if (deferred) {
+                assert ver0 != null;
+
+                cctx.onDeferredDelete(this, ver0);
+            }
+
+            if ((obsolete || deferred) && cctx.cache().configuration().isStatisticsEnabled())
+                cctx.cache().metrics0().onEvict();
         }
 
         return obsolete;
@@ -3468,10 +3448,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
             GridCacheQueryManager qryMgr = cctx.queries();
 
             if (qryMgr != null && qryMgr.enabled()) {
-                qryMgr.store(key.value(cctx.cacheObjectContext(), false),
-                    null,
-                    CU.value(val, cctx, false),
-                    null,
+                qryMgr.store(key,
+                    val,
                     ver,
                     expireTime);
             }
@@ -3494,8 +3472,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
             GridCacheQueryManager<?, ?> qryMgr = cctx.queries();
 
             if (qryMgr != null)
-                qryMgr.remove(key().value(cctx.cacheObjectContext(), false),
-                    prevVal == null ? null : prevVal.value(cctx.cacheObjectContext(), false));
+                qryMgr.remove(key(), prevVal == null ? null : prevVal);
         }
         catch (IgniteCheckedException e) {
             throw new GridCacheIndexUpdateException(e);
@@ -4095,6 +4072,27 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
     }
 
     /**
+     * @return True if entry has off-heap value pointer.
+     */
+    protected boolean hasOffHeapPointer() {
+        return false;
+    }
+
+    /**
+     * @return Off-heap value pointer.
+     */
+    protected long offHeapPointer() {
+        return 0;
+    }
+
+    /**
+     * @param valPtr Off-heap value pointer.
+     */
+    protected void offHeapPointer(long valPtr) {
+        // No-op.
+    }
+
+    /**
      * @return Size of extras object.
      */
     private int extrasSize() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
index fefd582..5432c90 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
@@ -60,7 +60,7 @@ public abstract class GridCacheMessage implements Message {
 
     /** */
     @GridDirectTransient
-    private Exception err;
+    private IgniteCheckedException err;
 
     /** */
     @GridDirectTransient
@@ -115,14 +115,14 @@ public abstract class GridCacheMessage implements Message {
      *
      * @param err Error.
      */
-    public void onClassError(Exception err) {
+    public void onClassError(IgniteCheckedException err) {
         this.err = err;
     }
 
     /**
-     * @return Error set via {@link #onClassError(Exception)} method.
+     * @return Error set via {@link #onClassError(IgniteCheckedException)} method.
      */
-    public Exception classError() {
+    public IgniteCheckedException classError() {
         return err;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
index 0bb97a9..c05e4b4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
@@ -510,7 +510,7 @@ public class GridCacheMvccManager extends GridCacheSharedManagerAdapter {
      * @return Future.
      */
     @SuppressWarnings({"unchecked"})
-    @Nullable public <T> GridCacheFuture<T> future(GridCacheVersion ver, IgniteUuid futId) {
+    @Nullable public GridCacheFuture future(GridCacheVersion ver, IgniteUuid futId) {
         Collection<? extends GridCacheFuture> futs = this.futs.get(ver);
 
         if (futs != null)
@@ -519,7 +519,7 @@ public class GridCacheMvccManager extends GridCacheSharedManagerAdapter {
                     if (log.isDebugEnabled())
                         log.debug("Found future in futures map: " + fut);
 
-                    return (GridCacheFuture<T>)fut;
+                    return fut;
                 }
 
         if (log.isDebugEnabled())

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 5f82ae2..0ecaf97 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
@@ -409,10 +409,10 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
      * @param ver Topology version.
      * @return Future or {@code null} is future is already completed.
      */
-    public @Nullable IgniteInternalFuture<?> affinityReadyFuture(AffinityTopologyVersion ver) {
+    @Nullable public IgniteInternalFuture<?> affinityReadyFuture(AffinityTopologyVersion ver) {
         GridDhtPartitionsExchangeFuture lastInitializedFut0 = lastInitializedFut;
 
-        if (lastInitializedFut0 != null && lastInitializedFut0.topologyVersion().compareTo(ver) >= 0) {
+        if (lastInitializedFut0 != null && lastInitializedFut0.topologyVersion().compareTo(ver) == 0) {
             if (log.isDebugEnabled())
                 log.debug("Return lastInitializedFut for topology ready future " +
                     "[ver=" + ver + ", fut=" + lastInitializedFut0 + ']');
@@ -745,6 +745,9 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
             int skipped = 0;
 
             for (GridDhtPartitionsExchangeFuture fut : exchFuts0.values()) {
+                if (exchFut.exchangeId().topologyVersion().compareTo(fut.exchangeId().topologyVersion()) < 0)
+                    continue;
+
                 skipped++;
 
                 if (skipped == EXCH_FUT_CLEANUP_HISTORY_SIZE) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 83f1fed..0e1a9c2 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
@@ -124,6 +124,9 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     /** Must use JDK marshaller since it is used by discovery to fire custom events. */
     private Marshaller marshaller = new JdkMarshaller();
 
+    /** Count down latch for caches. */
+    private final CountDownLatch cacheStartedLatch = new CountDownLatch(1);
+
     /**
      * @param ctx Kernal context.
      */
@@ -607,7 +610,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
             boolean template = cfg.getName() != null && cfg.getName().endsWith("*");
 
-            DynamicCacheDescriptor desc = new DynamicCacheDescriptor(cfg, cacheType, template, IgniteUuid.randomUuid());
+            DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx, cfg, cacheType, template,
+                IgniteUuid.randomUuid());
 
             desc.locallyConfigured(true);
             desc.staticallyConfigured(true);
@@ -635,7 +639,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
             if (cfg.getName() == null) { // Use cache configuration with null name as template.
                 DynamicCacheDescriptor desc0 =
-                    new DynamicCacheDescriptor(cfg, cacheType, true, IgniteUuid.randomUuid());
+                    new DynamicCacheDescriptor(ctx, cfg, cacheType, true, IgniteUuid.randomUuid());
 
                 desc0.locallyConfigured(true);
                 desc0.staticallyConfigured(true);
@@ -657,87 +661,77 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override public void onKernalStart() throws IgniteCheckedException {
-        if (ctx.config().isDaemon())
-            return;
-
-        ClusterNode locNode = ctx.discovery().localNode();
-
-        // Init cache plugin managers.
-        final Map<String, CachePluginManager> cache2PluginMgr = new HashMap<>();
-
-        for (DynamicCacheDescriptor desc : registeredCaches.values()) {
-            CacheConfiguration locCcfg = desc.cacheConfiguration();
-
-            CachePluginManager pluginMgr = new CachePluginManager(ctx, locCcfg);
-
-            cache2PluginMgr.put(locCcfg.getName(), pluginMgr);
-        }
+        try {
+            if (ctx.config().isDaemon())
+                return;
 
-        if (!getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
-            for (ClusterNode n : ctx.discovery().remoteNodes()) {
-                checkTransactionConfiguration(n);
+            ClusterNode locNode = ctx.discovery().localNode();
 
-                DeploymentMode locDepMode = ctx.config().getDeploymentMode();
-                DeploymentMode rmtDepMode = n.attribute(IgniteNodeAttributes.ATTR_DEPLOYMENT_MODE);
+            if (!getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
+                for (ClusterNode n : ctx.discovery().remoteNodes()) {
+                    checkTransactionConfiguration(n);
 
-                CU.checkAttributeMismatch(log, null, n.id(), "deploymentMode", "Deployment mode",
-                    locDepMode, rmtDepMode, true);
+                    DeploymentMode locDepMode = ctx.config().getDeploymentMode();
+                    DeploymentMode rmtDepMode = n.attribute(IgniteNodeAttributes.ATTR_DEPLOYMENT_MODE);
 
-                for (DynamicCacheDescriptor desc : registeredCaches.values()) {
-                    CacheConfiguration rmtCfg = desc.remoteConfiguration(n.id());
+                    CU.checkAttributeMismatch(log, null, n.id(), "deploymentMode", "Deployment mode",
+                        locDepMode, rmtDepMode, true);
 
-                    if (rmtCfg != null) {
-                        CacheConfiguration locCfg = desc.cacheConfiguration();
+                    for (DynamicCacheDescriptor desc : registeredCaches.values()) {
+                        CacheConfiguration rmtCfg = desc.remoteConfiguration(n.id());
 
-                        checkCache(locCfg, rmtCfg, n);
+                        if (rmtCfg != null) {
+                            CacheConfiguration locCfg = desc.cacheConfiguration();
 
-                        // Check plugin cache configurations.
-                        CachePluginManager pluginMgr = cache2PluginMgr.get(locCfg.getName());
+                            checkCache(locCfg, rmtCfg, n);
 
-                        assert pluginMgr != null : " Map=" + cache2PluginMgr;
+                            // Check plugin cache configurations.
+                            CachePluginManager pluginMgr = desc.pluginManager();
 
-                        pluginMgr.validateRemotes(rmtCfg, n);
+                            pluginMgr.validateRemotes(rmtCfg, n);
+                        }
                     }
                 }
             }
-        }
-
-        // Start dynamic caches received from collect discovery data.
-        for (DynamicCacheDescriptor desc : registeredCaches.values()) {
-            boolean started = desc.onStart();
 
-            assert started : "Failed to change started flag for locally configured cache: " + desc;
+            // Start dynamic caches received from collect discovery data.
+            for (DynamicCacheDescriptor desc : registeredCaches.values()) {
+                boolean started = desc.onStart();
 
-            desc.clearRemoteConfigurations();
+                assert started : "Failed to change started flag for locally configured cache: " + desc;
 
-            CacheConfiguration ccfg = desc.cacheConfiguration();
+                desc.clearRemoteConfigurations();
 
-            IgnitePredicate filter = ccfg.getNodeFilter();
+                CacheConfiguration ccfg = desc.cacheConfiguration();
 
-            if (filter.apply(locNode)) {
-                CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(ccfg);
+                IgnitePredicate filter = ccfg.getNodeFilter();
 
-                CachePluginManager pluginMgr = cache2PluginMgr.get(ccfg.getName());
+                if (filter.apply(locNode)) {
+                    CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(ccfg);
 
-                assert pluginMgr != null : " Map=" + cache2PluginMgr;
+                    CachePluginManager pluginMgr = desc.pluginManager();
 
-                GridCacheContext ctx = createCache(ccfg, pluginMgr, desc.cacheType(), cacheObjCtx);
+                    GridCacheContext ctx = createCache(ccfg, pluginMgr, desc.cacheType(), cacheObjCtx);
 
-                ctx.dynamicDeploymentId(desc.deploymentId());
+                    ctx.dynamicDeploymentId(desc.deploymentId());
 
-                sharedCtx.addCacheContext(ctx);
+                    sharedCtx.addCacheContext(ctx);
 
-                GridCacheAdapter cache = ctx.cache();
+                    GridCacheAdapter cache = ctx.cache();
 
-                String name = ccfg.getName();
+                    String name = ccfg.getName();
 
-                caches.put(maskNull(name), cache);
+                    caches.put(maskNull(name), cache);
 
-                startCache(cache);
+                    startCache(cache);
 
-                jCacheProxies.put(maskNull(name), new IgniteCacheProxy(ctx, cache, null, false));
+                    jCacheProxies.put(maskNull(name), new IgniteCacheProxy(ctx, cache, null, false));
+                }
             }
         }
+        finally {
+            cacheStartedLatch.countDown();
+        }
 
         ctx.marshallerContext().onMarshallerCacheStarted(ctx);
 
@@ -835,6 +829,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override public void onKernalStop(boolean cancel) {
+        cacheStartedLatch.countDown();
+
         if (ctx.config().isDaemon())
             return;
 
@@ -959,6 +955,13 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @throws IgniteCheckedException If failed to wait.
+     */
+    public void awaitStarted() throws IgniteCheckedException {
+        U.await(cacheStartedLatch);
+    }
+
+    /**
      * @param cache Cache.
      * @throws IgniteCheckedException If failed.
      */
@@ -1640,6 +1643,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
                     if (existing == null) {
                         DynamicCacheDescriptor desc = new DynamicCacheDescriptor(
+                            ctx,
                             ccfg,
                             req.cacheType(),
                             true,
@@ -1673,6 +1677,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                         assert req.cacheType() != null : req;
 
                         DynamicCacheDescriptor desc = new DynamicCacheDescriptor(
+                            ctx,
                             ccfg,
                             req.cacheType(),
                             false,
@@ -2022,7 +2027,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
                 if (desc == null) {
                     DynamicCacheDescriptor templateDesc =
-                        new DynamicCacheDescriptor(ccfg, req.cacheType(), true, req.deploymentId());
+                        new DynamicCacheDescriptor(ctx, ccfg, req.cacheType(), true, req.deploymentId());
 
                     DynamicCacheDescriptor old = registeredTemplates.put(maskNull(ccfg.getName()), templateDesc);
 
@@ -2076,7 +2081,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                     assert req.cacheType() != null : req;
 
                     DynamicCacheDescriptor startDesc =
-                        new DynamicCacheDescriptor(ccfg, req.cacheType(), false, req.deploymentId());
+                        new DynamicCacheDescriptor(ctx, ccfg, req.cacheType(), false, req.deploymentId());
 
                     DynamicCacheDescriptor old = registeredCaches.put(maskNull(ccfg.getName()), startDesc);
 
@@ -2381,8 +2386,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
                     assert val != null;
 
-                    qryMgr.remove(key.value(cctx.cacheObjectContext(), false),
-                        val.value(cctx.cacheObjectContext(), false));
+                    qryMgr.remove(key, val);
                 }
                 catch (IgniteCheckedException e) {
                     U.error(log, "Failed to unmarshal key evicted from swap [swapSpaceName=" + spaceName + ']', e);
@@ -2448,6 +2452,24 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @param name Cache name.
+     * @return Cache instance for given name.
+     * @throws IgniteCheckedException If failed.
+     */
+    @SuppressWarnings("unchecked")
+    public <K, V> IgniteInternalCache<K, V> getOrStartCache(@Nullable String name) throws IgniteCheckedException {
+        if (log.isDebugEnabled())
+            log.debug("Getting cache for name: " + name);
+
+        IgniteCache<K, V> jcache = (IgniteCache<K, V>)jCacheProxies.get(maskNull(name));
+
+        if (jcache == null)
+            jcache = startJCache(name, true);
+
+        return jcache == null ? null : ((IgniteCacheProxy<K, V>)jcache).internalProxy();
+    }
+
+    /**
      * @return All configured cache instances.
      */
     public Collection<IgniteInternalCache<?, ?>> caches() {
@@ -2554,37 +2576,53 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         if (desc != null && !desc.cacheType().userCache())
             throw new IllegalStateException("Failed to get cache because it is a system cache: " + cacheName);
 
-        if (cache == null) {
-            if (desc == null || desc.cancelled()) {
-                if (failIfNotStarted)
-                    throw new IllegalArgumentException("Cache is not started: " + cacheName);
+        if (cache == null)
+           cache = startJCache(cacheName, failIfNotStarted);
 
-                return null;
-            }
+        return cache;
+    }
 
-            DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(cacheName, ctx.localNodeId());
+    /**
+     * @param cacheName Cache name.
+     * @param failIfNotStarted If {@code true} throws {@link IllegalArgumentException} if cache is not started,
+     *        otherwise returns {@code null} in this case.
+     * @return Cache instance for given name.
+     * @throws IgniteCheckedException If failed.
+     */
+    private IgniteCache startJCache(String cacheName, boolean failIfNotStarted) throws IgniteCheckedException {
+        String masked = maskNull(cacheName);
 
-            req.cacheName(cacheName);
+        DynamicCacheDescriptor desc = registeredCaches.get(masked);
 
-            req.deploymentId(desc.deploymentId());
+        if (desc == null || desc.cancelled()) {
+            if (failIfNotStarted)
+                throw new IllegalArgumentException("Cache is not started: " + cacheName);
 
-            CacheConfiguration cfg = new CacheConfiguration(desc.cacheConfiguration());
+            return null;
+        }
 
-            cfg.setNearConfiguration(null);
+        DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(cacheName, ctx.localNodeId());
 
-            req.startCacheConfiguration(cfg);
+        req.cacheName(cacheName);
 
-            req.cacheType(desc.cacheType());
+        req.deploymentId(desc.deploymentId());
 
-            req.clientStartOnly(true);
+        CacheConfiguration cfg = new CacheConfiguration(desc.cacheConfiguration());
 
-            F.first(initiateCacheChanges(F.asList(req))).get();
+        cfg.setNearConfiguration(null);
 
-            cache = (IgniteCache<K, V>)jCacheProxies.get(masked);
+        req.startCacheConfiguration(cfg);
 
-            if (cache == null && failIfNotStarted)
-                throw new IllegalArgumentException("Cache is not started: " + cacheName);
-        }
+        req.cacheType(desc.cacheType());
+
+        req.clientStartOnly(true);
+
+        F.first(initiateCacheChanges(F.asList(req))).get();
+
+        IgniteCache cache = jCacheProxies.get(masked);
+
+        if (cache == null && failIfNotStarted)
+            throw new IllegalArgumentException("Cache is not started: " + cacheName);
 
         return cache;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
index 5487944..55d2f84 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
@@ -1390,30 +1390,6 @@ public class GridCacheProxyImpl<K, V> implements IgniteInternalCache<K, V>, Exte
     }
 
     /** {@inheritDoc} */
-    @Override public Iterator<Map.Entry<K, V>> swapIterator() throws IgniteCheckedException {
-        CacheOperationContext prev = gate.enter(opCtx);
-
-        try {
-            return delegate.swapIterator();
-        }
-        finally {
-            gate.leave(prev);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator<Map.Entry<K, V>> offHeapIterator() throws IgniteCheckedException {
-        CacheOperationContext prev = gate.enter(opCtx);
-
-        try {
-            return delegate.offHeapIterator();
-        }
-        finally {
-            gate.leave(prev);
-        }
-    }
-
-    /** {@inheritDoc} */
     @Override public long offHeapEntriesCount() {
         CacheOperationContext prev = gate.enter(opCtx);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index fb6b103..eb82218 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -551,11 +551,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
                 GridCacheQueryManager qryMgr = cctx.queries();
 
-                if (qryMgr != null) {
-                    qryMgr.onUnswap(key.value(cctx.cacheObjectContext(), false),
-                            entry.value().value(cctx.cacheObjectContext(), false),
-                            entry.valueBytes());
-                }
+                if (qryMgr != null)
+                    qryMgr.onUnswap(key, entry.value());
 
                 return entry;
             }
@@ -619,11 +616,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
                         GridCacheQueryManager qryMgr = cctx.queries();
 
-                        if (qryMgr != null) {
-                            qryMgr.onUnswap(key.value(cctx.cacheObjectContext(), false),
-                                v.value(cctx.cacheObjectContext(), false),
-                                valBytes);
-                        }
+                        if (qryMgr != null)
+                            qryMgr.onUnswap(key, v);
                     }
                     catch (IgniteCheckedException e) {
                         err.set(e);
@@ -758,9 +752,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
                                 EVT_CACHE_OBJECT_FROM_OFFHEAP, null, false, null, true, null, null, null);
 
                         if (qryMgr != null)
-                            qryMgr.onUnswap(key.value(cctx.cacheObjectContext(), false),
-                                    entry.value().value(cctx.cacheObjectContext(), false),
-                                    entry.valueBytes());
+                            qryMgr.onUnswap(key, entry.value());
 
                         GridCacheBatchSwapEntry unswapped = new GridCacheBatchSwapEntry(key,
                             part,
@@ -859,11 +851,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
                             // Always fire this event, since preloading depends on it.
                             onUnswapped(swapKey.partition(), key, entry);
 
-                            if (qryMgr != null) {
-                                qryMgr.onUnswap(key.value(cctx.cacheObjectContext(), false),
-                                        entry.value().value(cctx.cacheObjectContext(), false),
-                                        entry.valueBytes());
-                            }
+                            if (qryMgr != null)
+                                qryMgr.onUnswap(key, entry.value());
                         }
                         catch (IgniteCheckedException e) {
                             err.set(e);
@@ -941,9 +930,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
                     if (entry == null)
                         return;
 
-                    qryMgr.onUnswap(key.value(cctx.cacheObjectContext(), false),
-                            entry.value().value(cctx.cacheObjectContext(), false),
-                            entry.valueBytes());
+                    qryMgr.onUnswap(key, entry.value());
                 }
                 catch (IgniteCheckedException e) {
                     throw new IgniteException(e);
@@ -1030,7 +1017,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         GridCacheQueryManager qryMgr = cctx.queries();
 
         if (qryMgr != null)
-            qryMgr.onSwap(spaceName, key.value(cctx.cacheObjectContext(), false));
+            qryMgr.onSwap(key);
     }
 
     /**
@@ -1059,7 +1046,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
                         (IgniteUuid)null, null, EVT_CACHE_OBJECT_TO_OFFHEAP, null, false, null, true, null, null, null);
 
                 if (qryMgr != null)
-                    qryMgr.onSwap(spaceName, swapEntry.key().value(cctx.cacheObjectContext(), false));
+                    qryMgr.onSwap(swapEntry.key());
             }
         }
         else {
@@ -1081,7 +1068,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
                         (IgniteUuid)null, null, EVT_CACHE_OBJECT_SWAPPED, null, false, null, true, null, null, null);
 
                     if (qryMgr != null)
-                        qryMgr.onSwap(spaceName, batchSwapEntry.key().value(cctx.cacheObjectContext(), false));
+                        qryMgr.onSwap(batchSwapEntry.key());
                 }
             }
         }
@@ -1224,10 +1211,10 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         checkIteratorQueue();
 
         if (offHeapEnabled() && !swapEnabled())
-            return rawOffHeapIterator();
+            return rawOffHeapIterator(true, true);
 
         if (swapEnabled() && !offHeapEnabled())
-            return rawSwapIterator();
+            return rawSwapIterator(true, true);
 
         // Both, swap and off-heap are enabled.
         return new GridCloseableIteratorAdapter<Map.Entry<byte[], byte[]>>() {
@@ -1240,7 +1227,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             private Map.Entry<byte[], byte[]> cur;
 
             {
-                it = rawOffHeapIterator();
+                it = rawOffHeapIterator(true, true);
 
                 advance();
             }
@@ -1254,7 +1241,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
                 if (offheapFlag) {
                     offheapFlag = false;
 
-                    it = rawSwapIterator();
+                    it = rawSwapIterator(true, true);
 
                     if (!it.hasNext()) {
                         it.close();
@@ -1326,7 +1313,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         Set<Integer> parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) :
             cctx.affinity().backupPartitions(cctx.localNodeId(), topVer);
 
-        return new PartitionsKeyIterator(parts) {
+        return new PartitionsAbstractIterator<KeyCacheObject>(parts) {
             @Override protected Iterator<KeyCacheObject> partitionIterator(int part)
                 throws IgniteCheckedException
             {
@@ -1351,7 +1338,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         Set<Integer> parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) :
             cctx.affinity().backupPartitions(cctx.localNodeId(), topVer);
 
-        return new PartitionsKeyIterator(parts) {
+        return new PartitionsAbstractIterator<KeyCacheObject>(parts) {
             @Override protected Iterator<KeyCacheObject> partitionIterator(int part)
                 throws IgniteCheckedException
             {
@@ -1567,37 +1554,91 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
     /**
      * @param c Key/value closure.
+     * @param primary Include primaries.
+     * @param backup Include backups.
      * @return Off-heap iterator.
      */
-    public <T> GridCloseableIterator<T> rawOffHeapIterator(CX2<T2<Long, Integer>, T2<Long, Integer>, T> c) {
+    public <T> GridCloseableIterator<T> rawOffHeapIterator(final CX2<T2<Long, Integer>, T2<Long, Integer>, T> c,
+        boolean primary,
+        boolean backup)
+    {
         assert c != null;
 
-        if (!offheapEnabled)
+        if (!offheapEnabled || (!primary && !backup))
             return new GridEmptyCloseableIterator<>();
 
         checkIteratorQueue();
 
-        return offheap.iterator(spaceName, c);
+        if (primary && backup)
+            return offheap.iterator(spaceName, c);
+
+        AffinityTopologyVersion ver = cctx.affinity().affinityTopologyVersion();
+
+        Set<Integer> parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), ver) :
+            cctx.affinity().backupPartitions(cctx.localNodeId(), ver);
+
+        return new CloseablePartitionsIterator<T, T>(parts) {
+            @Override protected GridCloseableIterator<T> partitionIterator(int part)
+                throws IgniteCheckedException
+            {
+                return offheap.iterator(spaceName, c, part);
+            }
+        };
     }
 
     /**
+     * @param primary Include primaries.
+     * @param backup Include backups.
      * @return Raw off-heap iterator.
      */
-    public GridCloseableIterator<Map.Entry<byte[], byte[]>> rawOffHeapIterator() {
-        if (!offheapEnabled)
+    public GridCloseableIterator<Map.Entry<byte[], byte[]>> rawOffHeapIterator(final boolean primary,
+        final boolean backup)
+    {
+        if (!offheapEnabled || (!primary && !backup))
             return new GridEmptyCloseableIterator<>();
 
-        return new GridCloseableIteratorAdapter<Map.Entry<byte[], byte[]>>() {
-            private GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> it = offheap.iterator(spaceName);
+        if (primary && backup)
+            return new GridCloseableIteratorAdapter<Map.Entry<byte[], byte[]>>() {
+                private GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> it = offheap.iterator(spaceName);
+
+                private Map.Entry<byte[], byte[]> cur;
+
+                @Override protected Map.Entry<byte[], byte[]> onNext() {
+                    return cur = it.next();
+                }
+
+                @Override protected boolean onHasNext() {
+                    return it.hasNext();
+                }
+
+                @Override protected void onRemove() throws IgniteCheckedException {
+                    KeyCacheObject key = cctx.toCacheKeyObject(cur.getKey());
 
+                    int part = cctx.affinity().partition(key);
+
+                    offheap.removex(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()));
+                }
+
+                @Override protected void onClose() throws IgniteCheckedException {
+                    it.close();
+                }
+            };
+
+        AffinityTopologyVersion ver = cctx.affinity().affinityTopologyVersion();
+
+        Set<Integer> parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), ver) :
+            cctx.affinity().backupPartitions(cctx.localNodeId(), ver);
+
+        return new CloseablePartitionsIterator<Map.Entry<byte[], byte[]>, IgniteBiTuple<byte[], byte[]>>(parts) {
             private Map.Entry<byte[], byte[]> cur;
 
             @Override protected Map.Entry<byte[], byte[]> onNext() {
-                return cur = it.next();
+                return cur = super.onNext();
             }
 
-            @Override protected boolean onHasNext() {
-                return it.hasNext();
+            @Override protected GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> partitionIterator(int part)
+                throws IgniteCheckedException {
+                return offheap.iterator(spaceName, part);
             }
 
             @Override protected void onRemove() throws IgniteCheckedException {
@@ -1607,10 +1648,6 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
                 offheap.removex(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()));
             }
-
-            @Override protected void onClose() throws IgniteCheckedException {
-                it.close();
-            }
         };
     }
 
@@ -1634,15 +1671,33 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
     /**
      * @return Raw off-heap iterator.
+     * @param primary Include primaries.
+     * @param backup Include backups.
      * @throws IgniteCheckedException If failed.
      */
-    public GridCloseableIterator<Map.Entry<byte[], byte[]>> rawSwapIterator() throws IgniteCheckedException {
-        if (!swapEnabled)
+    public GridCloseableIterator<Map.Entry<byte[], byte[]>> rawSwapIterator(boolean primary, boolean backup)
+        throws IgniteCheckedException
+    {
+        if (!swapEnabled || (!primary && !backup))
             return new GridEmptyCloseableIterator<>();
 
         checkIteratorQueue();
 
-        return swapMgr.rawIterator(spaceName);
+        if (primary && backup)
+            return swapMgr.rawIterator(spaceName);
+
+        AffinityTopologyVersion ver = cctx.affinity().affinityTopologyVersion();
+
+        Set<Integer> parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), ver) :
+            cctx.affinity().backupPartitions(cctx.localNodeId(), ver);
+
+        return new CloseablePartitionsIterator<Map.Entry<byte[], byte[]>, Map.Entry<byte[], byte[]>>(parts) {
+            @Override protected GridCloseableIterator<Map.Entry<byte[], byte[]>> partitionIterator(int part)
+                throws IgniteCheckedException
+            {
+                return swapMgr.rawIterator(spaceName, part);
+            }
+        };
     }
 
     /**
@@ -1667,7 +1722,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             cctx.affinity().backupPartitions(cctx.localNodeId(), topVer);
 
         return new PartitionsIterator<K, V>(parts) {
-            @Override protected GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> partitionIterator(int part)
+            @Override protected GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> nextPartition(int part)
                 throws IgniteCheckedException
             {
                 return swapMgr.rawIterator(spaceName, part);
@@ -1682,7 +1737,9 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
      * @return Offheap entries iterator.
      * @throws IgniteCheckedException If failed.
      */
-    public <K, V> Iterator<Cache.Entry<K, V>> offheapIterator(boolean primary, boolean backup, AffinityTopologyVersion topVer)
+    public <K, V> Iterator<Cache.Entry<K, V>> offheapIterator(boolean primary,
+        boolean backup,
+        AffinityTopologyVersion topVer)
         throws IgniteCheckedException
     {
         assert primary || backup;
@@ -1697,7 +1754,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             cctx.affinity().backupPartitions(cctx.localNodeId(), topVer);
 
         return new PartitionsIterator<K, V>(parts) {
-            @Override protected GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> partitionIterator(int part) {
+            @Override protected GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> nextPartition(int part) {
                 return offheap.iterator(spaceName, part);
             }
         };
@@ -1897,20 +1954,46 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
     /**
      *
      */
-    private abstract class PartitionsIterator<K, V> implements Iterator<Cache.Entry<K, V>> {
+    private abstract class PartitionsIterator<K, V> extends PartitionsAbstractIterator<Cache.Entry<K, V>> {
+        /**
+         * @param parts Partitions
+         */
+        public PartitionsIterator(Collection<Integer> parts) {
+            super(parts);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected Iterator<Cache.Entry<K, V>> partitionIterator(int part)
+            throws IgniteCheckedException {
+            return cacheEntryIterator(GridCacheSwapManager.this.<K, V>lazyIterator(nextPartition(part)));
+        }
+
+        /**
+         * @param part Partition.
+         * @return Iterator for given partition.
+         * @throws IgniteCheckedException If failed.
+         */
+        abstract protected GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> nextPartition(int part)
+            throws IgniteCheckedException;
+    }
+
+    /**
+     *
+     */
+    private abstract class PartitionsAbstractIterator<T> implements Iterator<T> {
         /** */
         private Iterator<Integer> partIt;
 
         /** */
-        private Iterator<Cache.Entry<K, V>> curIt;
+        private Iterator<T> curIt;
 
         /** */
-        private Cache.Entry<K, V> next;
+        private T next;
 
         /**
          * @param parts Partitions
          */
-        public PartitionsIterator(Collection<Integer> parts) {
+        public PartitionsAbstractIterator(Collection<Integer> parts) {
             this.partIt = parts.iterator();
 
             advance();
@@ -1922,11 +2005,11 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         }
 
         /** {@inheritDoc} */
-        @Override public Cache.Entry<K, V> next() {
+        @Override public T next() {
             if (next == null)
                 throw new NoSuchElementException();
 
-            Cache.Entry<K, V> e = next;
+            T e = next;
 
             advance();
 
@@ -1950,8 +2033,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
                         int part = partIt.next();
 
                         try {
-                            curIt = cacheEntryIterator(
-                                GridCacheSwapManager.this.<K, V>lazyIterator(partitionIterator(part)));
+                            curIt = partitionIterator(part);
                         }
                         catch (IgniteCheckedException e) {
                             throw new IgniteException(e);
@@ -1977,58 +2059,70 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
          * @return Iterator for given partition.
          * @throws IgniteCheckedException If failed.
          */
-        abstract protected GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> partitionIterator(int part)
+        abstract protected Iterator<T> partitionIterator(int part)
             throws IgniteCheckedException;
     }
 
     /**
      *
      */
-    private abstract class PartitionsKeyIterator implements Iterator<KeyCacheObject> {
+    private abstract class CloseablePartitionsIterator<T, T1 extends T> extends GridCloseableIteratorAdapter<T> {
         /** */
         private Iterator<Integer> partIt;
 
         /** */
-        private Iterator<KeyCacheObject> curIt;
+        protected GridCloseableIterator<T1> curIt;
 
         /** */
-        private KeyCacheObject next;
+        protected T next;
 
         /**
          * @param parts Partitions
          */
-        public PartitionsKeyIterator(Collection<Integer> parts) {
+        public CloseablePartitionsIterator(Collection<Integer> parts) {
             this.partIt = parts.iterator();
 
-            advance();
+            try {
+                advance();
+            }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
         }
 
         /** {@inheritDoc} */
-        @Override public boolean hasNext() {
+        @Override protected boolean onHasNext() {
             return next != null;
         }
 
         /** {@inheritDoc} */
-        @Override public KeyCacheObject next() {
-            if (next == null)
-                throw new NoSuchElementException();
+        @Override protected T onNext() {
+            try {
+                if (next == null)
+                    throw new NoSuchElementException();
 
-            KeyCacheObject e = next;
+                T e = next;
 
-            advance();
+                advance();
 
-            return e;
+                return e;
+            }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
         }
 
         /** {@inheritDoc} */
-        @Override public void remove() {
-            throw new UnsupportedOperationException();
+        @Override protected void onClose() throws IgniteCheckedException {
+            if (curIt != null)
+                curIt.close();
         }
 
         /**
          * Switches to next element.
+         * @throws IgniteCheckedException If failed.
          */
-        private void advance() {
+        private void advance() throws IgniteCheckedException {
             next = null;
 
             do {
@@ -2051,8 +2145,11 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
                         break;
                     }
-                    else
+                    else {
+                        curIt.close();
+
                         curIt = null;
+                    }
                 }
             }
             while (partIt.hasNext());
@@ -2063,7 +2160,6 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
          * @return Iterator for given partition.
          * @throws IgniteCheckedException If failed.
          */
-        abstract protected Iterator<KeyCacheObject> partitionIterator(int part)
-            throws IgniteCheckedException;
+        abstract protected GridCloseableIterator<T1> partitionIterator(int part) throws IgniteCheckedException;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
index 5198b53..5f9049a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
@@ -26,22 +26,21 @@ import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.internal.util.worker.*;
 import org.apache.ignite.thread.*;
 
-import java.util.*;
+import org.jetbrains.annotations.*;
+import org.jsr166.*;
 
 /**
- * Eagerly removes expired entries from cache when {@link org.apache.ignite.configuration.CacheConfiguration#isEagerTtl()} flag is set.
+ * Eagerly removes expired entries from cache when
+ * {@link org.apache.ignite.configuration.CacheConfiguration#isEagerTtl()} flag is set.
  */
 @SuppressWarnings("NakedNotify")
 public class GridCacheTtlManager extends GridCacheManagerAdapter {
     /** Entries pending removal. */
-    private final GridConcurrentSkipListSet<EntryWrapper> pendingEntries = new GridConcurrentSkipListSet<>();
+    private final GridConcurrentSkipListSetEx pendingEntries = new GridConcurrentSkipListSetEx();
 
     /** Cleanup worker thread. */
     private CleanupWorker cleanupWorker;
 
-    /** Sync mutex. */
-    private final Object mux = new Object();
-
     /** {@inheritDoc} */
     @Override protected void start0() throws IgniteCheckedException {
         if (cctx.kernalContext().isDaemon() || !cctx.config().isEagerTtl())
@@ -68,24 +67,15 @@ public class GridCacheTtlManager extends GridCacheManagerAdapter {
      * @param entry Entry to add.
      */
     public void addTrackedEntry(GridCacheMapEntry entry) {
-        EntryWrapper wrapper = new EntryWrapper(entry);
-
-        pendingEntries.add(wrapper);
-
-        // If entry is on the first position, notify waiting thread.
-        if (wrapper == pendingEntries.firstx()) {
-            synchronized (mux) {
-                mux.notifyAll();
-            }
-        }
+        pendingEntries.add(new EntryWrapper(entry));
     }
 
     /**
      * @param entry Entry to remove.
      */
     public void removeTrackedEntry(GridCacheMapEntry entry) {
-        // Remove must be called while holding lock on entry before updating expire time.
-        // No need to wake up waiting thread in this case.
+        assert Thread.holdsLock(entry);
+
         pendingEntries.remove(new EntryWrapper(entry));
     }
 
@@ -97,6 +87,32 @@ public class GridCacheTtlManager extends GridCacheManagerAdapter {
     }
 
     /**
+     * Expires entries by TTL.
+     */
+    public void expire() {
+        long now = U.currentTimeMillis();
+
+        GridCacheVersion obsoleteVer = null;
+
+        for (int size = pendingEntries.sizex(); size > 0; size--) {
+            EntryWrapper e = pendingEntries.firstx();
+
+            if (e == null || e.expireTime > now)
+                return;
+
+            if (pendingEntries.remove(e)) {
+                if (obsoleteVer == null)
+                    obsoleteVer = cctx.versions().next();
+
+                if (log.isTraceEnabled())
+                    log.trace("Trying to remove expired entry from cache: " + e);
+
+                e.entry.onTtlExpired(obsoleteVer);
+            }
+        }
+    }
+
+    /**
      * Entry cleanup worker.
      */
     private class CleanupWorker extends GridWorker {
@@ -110,52 +126,18 @@ public class GridCacheTtlManager extends GridCacheManagerAdapter {
         /** {@inheritDoc} */
         @Override protected void body() throws InterruptedException, IgniteInterruptedCheckedException {
             while (!isCancelled()) {
-                long now = U.currentTimeMillis();
-
-                GridCacheVersion obsoleteVer = null;
-
-                for (Iterator<EntryWrapper> it = pendingEntries.iterator(); it.hasNext(); ) {
-                    EntryWrapper wrapper = it.next();
+                expire();
 
-                    if (wrapper.expireTime <= now) {
-                        if (log.isDebugEnabled())
-                            log.debug("Trying to remove expired entry from cache: " + wrapper);
+                EntryWrapper first = pendingEntries.firstx();
 
-                        if (obsoleteVer == null)
-                            obsoleteVer = cctx.versions().next();
+                if (first != null) {
+                    long waitTime = first.expireTime - U.currentTimeMillis();
 
-                        if (wrapper.entry.onTtlExpired(obsoleteVer))
-                            wrapper.entry.context().cache().removeEntry(wrapper.entry);
-
-                        if (wrapper.entry.context().cache().configuration().isStatisticsEnabled())
-                            wrapper.entry.context().cache().metrics0().onEvict();
-
-                        it.remove();
-                    }
-                    else
-                        break;
-                }
-
-                synchronized (mux) {
-                    while (true) {
-                        // Access of the first element must be inside of
-                        // synchronization block, so we don't miss out
-                        // on thread notification events sent from
-                        // 'addTrackedEntry(..)' method.
-                        EntryWrapper first = pendingEntries.firstx();
-
-                        if (first != null) {
-                            long waitTime = first.expireTime - U.currentTimeMillis();
-
-                            if (waitTime > 0)
-                                mux.wait(waitTime);
-                            else
-                                break;
-                        }
-                        else
-                            mux.wait(5000);
-                    }
+                    if (waitTime > 0)
+                        U.sleep(waitTime);
                 }
+                else
+                    U.sleep(500);
             }
         }
     }
@@ -214,4 +196,58 @@ public class GridCacheTtlManager extends GridCacheManagerAdapter {
             return res;
         }
     }
+
+    /**
+     * Provides additional method {@code #sizex()}. NOTE: Only the following methods supports this addition:
+     * <ul>
+     *     <li>{@code #add()}</li>
+     *     <li>{@code #remove()}</li>
+     *     <li>{@code #pollFirst()}</li>
+     * <ul/>
+     */
+    private static class GridConcurrentSkipListSetEx extends GridConcurrentSkipListSet<EntryWrapper> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Size. */
+        private final LongAdder8 size = new LongAdder8();
+
+        /**
+         * @return Size based on performed operations.
+         */
+        public int sizex() {
+            return size.intValue();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean add(EntryWrapper e) {
+            boolean res = super.add(e);
+
+            assert res;
+
+            size.increment();
+
+            return res;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean remove(Object o) {
+            boolean res = super.remove(o);
+
+            if (res)
+                size.decrement();
+
+            return res;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public EntryWrapper pollFirst() {
+            EntryWrapper e = super.pollFirst();
+
+            if (e != null)
+                size.decrement();
+
+            return e;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index e7c7f9d..549f42f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -29,7 +29,6 @@ import org.apache.ignite.internal.processors.cache.distributed.*;
 import org.apache.ignite.internal.processors.cache.distributed.dht.*;
 import org.apache.ignite.internal.processors.cache.transactions.*;
 import org.apache.ignite.internal.processors.cache.version.*;
-import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.T2;
@@ -1157,6 +1156,8 @@ public class GridCacheUtils {
 
         if (ctx.isNear())
             ctx.near().dht().context().evicts().unwind();
+
+        ctx.ttl().expire();
     }
 
     /**
@@ -1166,11 +1167,12 @@ public class GridCacheUtils {
         assert ctx != null;
 
         for (GridCacheContext<K, V> cacheCtx : ctx.cacheContexts()) {
-
             cacheCtx.evicts().unwind();
 
             if (cacheCtx.isNear())
                 cacheCtx.near().dht().context().evicts().unwind();
+
+            cacheCtx.ttl().expire();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 2de5bf0..f840015 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -542,7 +542,8 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V
     private void validate(Query qry) {
         if (!GridQueryProcessor.isEnabled(ctx.config()) && !(qry instanceof ScanQuery) &&
             !(qry instanceof ContinuousQuery))
-            throw new CacheException("Indexing is disabled for cache: " + ctx.cache().name());
+            throw new CacheException("Indexing is disabled for cache: " + ctx.cache().name() +
+                ". Use setIndexedTypes or setTypeMetadata methods on CacheConfiguration to enable.");
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
index fe371ce..5184115 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
@@ -1451,33 +1451,6 @@ public interface IgniteInternalCache<K, V> extends Iterable<Cache.Entry<K, V>> {
     public long swapKeys() throws IgniteCheckedException;
 
     /**
-     * Gets iterator over keys and values belonging to this cache swap space on local node. This
-     * iterator is thread-safe, which means that cache (and therefore its swap space)
-     * may be modified concurrently with iteration over swap.
-     * <p>
-     * Returned iterator supports {@code remove} operation which delegates to
-     * <code>removex(Object, org.apache.ignite.lang.IgnitePredicate[])</code> method.
-     *
-     * @return Iterator over keys.
-     * @throws IgniteCheckedException If failed.
-     */
-    public Iterator<Map.Entry<K, V>> swapIterator() throws IgniteCheckedException;
-
-    /**
-     * Gets iterator over keys and values belonging to this cache off-heap memory on local node. This
-     * iterator is thread-safe, which means that cache (and therefore its off-heap memory)
-     * may be modified concurrently with iteration over off-heap. To achieve better performance
-     * the keys and values deserialized on demand, whenever accessed.
-     * <p>
-     * Returned iterator supports {@code remove} operation which delegates to
-     * <code>removex(Object, org.apache.ignite.lang.IgnitePredicate[])}</code> method.
-     *
-     * @return Iterator over keys.
-     * @throws IgniteCheckedException If failed.
-     */
-    public Iterator<Map.Entry<K, V>> offHeapIterator() throws IgniteCheckedException;
-
-    /**
      * Forces this cache node to re-balance its partitions. This method is usually used when
      * {@link CacheConfiguration#getRebalanceDelay()} configuration parameter has non-zero value.
      * When many nodes are started or stopped almost concurrently, it is more efficient to delay



[03/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteTask.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteTask.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteTask.java
new file mode 100644
index 0000000..ecd2272
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteTask.java
@@ -0,0 +1,86 @@
+/*
+ * 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.mesos;
+
+/**
+ * Information about launched task.
+ */
+public class IgniteTask {
+    /** */
+    public final String host;
+
+    /** */
+    public final double cpuCores;
+
+    /** */
+    public final double mem;
+
+    /** */
+    public final double disk;
+
+    /**
+     * Ignite launched task.
+     *
+     * @param host Host.
+     * @param cpuCores Cpu cores count.
+     * @param mem Memory.
+     * @param disk Disk.
+     */
+    public IgniteTask(String host, double cpuCores, double mem, double disk) {
+        this.host = host;
+        this.cpuCores = cpuCores;
+        this.mem = mem;
+        this.disk = disk;
+    }
+
+    /**
+     * @return Host.
+     */
+    public String host() {
+        return host;
+    }
+
+    /**
+     * @return Cores count.
+     */
+    public double cpuCores() {
+        return cpuCores;
+    }
+
+    /**
+     * @return Memory.
+     */
+    public double mem() {
+        return mem;
+    }
+
+    /**
+     * @return Disk.
+     */
+    public double disk() {
+        return disk;
+    }
+
+    @Override
+    public String toString() {
+        return "IgniteTask " +
+            "host: [" + host + ']' +
+            ", cpuCores: [" + cpuCores + "]" +
+            ", mem: [" + mem + "]";
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/java/org/apache/ignite/mesos/package-info.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/package-info.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/package-info.java
new file mode 100644
index 0000000..0404c02
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains classes to support integration with Apache Mesos.
+ */
+package org.apache.ignite.mesos;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/IgniteProvider.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/IgniteProvider.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/IgniteProvider.java
new file mode 100644
index 0000000..f459e5d
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/IgniteProvider.java
@@ -0,0 +1,234 @@
+/*
+ * 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.mesos.resource;
+
+import java.io.*;
+import java.net.*;
+import java.nio.channels.*;
+import java.util.*;
+
+/**
+ * Class downloads and stores Ignite.
+ */
+public class IgniteProvider {
+    /** */
+    public static final String DOWNLOAD_LINK = "http://tiny.cc/updater/download_community.php";
+
+    /** */
+    public static final String DIRECT_DOWNLOAD_LINK = "http://www.gridgain.com/media/gridgain-community-fabric-";
+
+    /** */
+    private String downloadFolder;
+
+    /** */
+    private String latestVersion = null;
+
+    /**
+     * @param downloadFolder Folder with ignite.
+     */
+    public IgniteProvider(String downloadFolder) {
+        this.downloadFolder = downloadFolder;
+    }
+
+    /**
+     * @return Latest ignite version.
+     */
+    public String getIgnite() {
+        File folder = checkDownloadFolder();
+
+        if (latestVersion == null) {
+            List<String> files = findIgnites(folder);
+
+            if (!files.isEmpty()) {
+                if (files.size() == 1)
+                    latestVersion = parseVersion(files.get(0));
+                else
+                    latestVersion = parseVersion(Collections.max(files, new Comparator<String>() {
+                        @Override public int compare(String f1, String f2) {
+                            if (f1.equals(f2))
+                                return 0;
+
+                            String[] ver1 = parseVersion(f1).split("\\.");
+                            String[] ver2 = parseVersion(f2).split("\\.");
+
+                            if (Integer.valueOf(ver1[0]) >= Integer.valueOf(ver2[0])
+                                && Integer.valueOf(ver1[1]) >= Integer.valueOf(ver2[1])
+                                && Integer.valueOf(ver1[2]) >= Integer.valueOf(ver2[2]))
+
+                                return 1;
+                            else
+                                return -1;
+                        }
+                    }));
+            }
+        }
+
+        latestVersion = updateIgnite(latestVersion);
+
+        return "gridgain-community-fabric-" + latestVersion + ".zip";
+    }
+
+    /**
+     * @param folder Folder.
+     * @return Ignite archives.
+     */
+    private List<String> findIgnites(File folder) {
+        String[] files = folder.list();
+
+        List<String> ignites = new ArrayList<>();
+
+        if (files != null) {
+            for (String fileName : files) {
+                if (fileName.contains("gridgain-community-fabric-") && fileName.endsWith(".zip"))
+                    ignites.add(fileName);
+            }
+        }
+
+        return ignites;
+    }
+
+    /**
+     * @param version Ignite version.
+     * @return Ignite.
+     */
+    public String getIgnite(String version) {
+        File folder = checkDownloadFolder();
+
+        String[] ignites = folder.list();
+
+        String ignite = null;
+
+        if (ignites != null) {
+            for (String fileName : ignites) {
+                if (fileName.equals("gridgain-community-fabric-" + version + ".zip"))
+                    ignite = fileName;
+            }
+        }
+
+        if (ignite != null)
+            return ignite;
+
+        return downloadIgnite(version);
+    }
+
+    /**
+     * @param currentVersion The current latest version.
+     * @return Current version if the current version is latest; new ignite version otherwise.
+     */
+    private String updateIgnite(String currentVersion) {
+        try {
+            URL url;
+
+            if (currentVersion == null)
+                url = new URL(DOWNLOAD_LINK);
+            else
+                url = new URL(DOWNLOAD_LINK + "?version=" + currentVersion);
+
+            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+
+            int code = conn.getResponseCode();
+
+            if (code == 200) {
+                String redirectUrl = conn.getURL().toString();
+
+                checkDownloadFolder();
+
+                FileOutputStream outFile = new FileOutputStream(downloadFolder + "/" + fileName(redirectUrl));
+
+                outFile.getChannel().transferFrom(Channels.newChannel(conn.getInputStream()), 0, Long.MAX_VALUE);
+
+                outFile.close();
+
+                return parseVersion(redirectUrl);
+            }
+            else if (code == 304)
+                // This version is latest.
+                return currentVersion;
+            else
+                throw new RuntimeException("Got unexpected response code. Response code: " + code);
+        }
+        catch (IOException e) {
+            throw new RuntimeException("Failed update ignite.", e);
+        }
+    }
+
+    /**
+     * @param version The current latest version.
+     * @return Ignite archive.
+     */
+    public String downloadIgnite(String version) {
+        try {
+            URL url = new URL(DIRECT_DOWNLOAD_LINK + version + ".zip");
+
+            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+
+            int code = conn.getResponseCode();
+
+            if (code == 200) {
+                checkDownloadFolder();
+
+                String fileName = fileName(url.toString());
+
+                FileOutputStream outFile = new FileOutputStream(downloadFolder + fileName);
+
+                outFile.getChannel().transferFrom(Channels.newChannel(conn.getInputStream()), 0, Long.MAX_VALUE);
+
+                outFile.close();
+
+                return fileName;
+            }
+            else
+                throw new RuntimeException("Got unexpected response code. Response code: " + code);
+        }
+        catch (IOException e) {
+            throw new RuntimeException("Failed update ignite.", e);
+        }
+    }
+
+    /**
+     * @return Download folder.
+     */
+    private File checkDownloadFolder() {
+        File file = new File(downloadFolder);
+
+        if (!file.exists())
+            file.mkdirs();
+
+        return file;
+    }
+
+    /**
+     * @param url URL.
+     * @return Ignite version.
+     */
+    public static String parseVersion(String url) {
+        String[] split = url.split("-");
+
+        return split[split.length - 1].replaceAll(".zip", "");
+    }
+
+    /**
+     * @param url URL.
+     * @return File name.
+     */
+    private static String fileName(String url) {
+        String[] split = url.split("/");
+
+        return split[split.length - 1];
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/JettyServer.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/JettyServer.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/JettyServer.java
new file mode 100644
index 0000000..446ac77
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/JettyServer.java
@@ -0,0 +1,61 @@
+/*
+ * 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.mesos.resource;
+
+import org.eclipse.jetty.server.*;
+
+import java.net.*;
+
+/**
+ * Embedded jetty server.
+ */
+public class JettyServer {
+    /** */
+    private Server server;
+
+    /**
+     * Starts jetty server.
+     *
+     * @param address Inter socket address.
+     * @param handler Handler.
+     * @throws Exception If failed.
+     */
+    public void start(InetSocketAddress address, Handler handler) throws Exception {
+        if (server == null) {
+            server = new Server(address);
+
+            server.setHandler(handler);
+
+            server.start();
+        }
+        else
+            throw new IllegalStateException("Jetty server has already been started.");
+    }
+
+    /**
+     * Stops server.
+     *
+     * @throws Exception If failed.
+     */
+    public void stop() throws Exception {
+        if (server != null)
+            server.stop();
+        else
+            throw new IllegalStateException("Jetty server has not yet been started.");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceHandler.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceHandler.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceHandler.java
new file mode 100644
index 0000000..cb8c773
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceHandler.java
@@ -0,0 +1,142 @@
+/*
+ * 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.mesos.resource;
+
+import org.eclipse.jetty.server.*;
+import org.eclipse.jetty.server.handler.*;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+import java.io.*;
+import java.nio.channels.*;
+import java.nio.file.*;
+
+/**
+ * HTTP controller which provides on slave resources.
+ */
+public class ResourceHandler extends AbstractHandler {
+    /** */
+    public static final String IGNITE_PREFIX = "/ignite/";
+
+    /** */
+    public static final String LIBS_PREFIX = "/libs/";
+
+    /** */
+    public static final String CONFIG_PREFIX = "/config/";
+
+    /** */
+    public static final String DEFAULT_CONFIG = CONFIG_PREFIX + "default/";
+
+    /** */
+    private String libsDir;
+
+    /** */
+    private String cfgPath;
+
+    /** */
+    private String igniteDir;
+
+    /**
+     * @param libsDir Directory with user's libs.
+     * @param cfgPath Path to config file.
+     * @param igniteDir Directory with ignites.
+     */
+    public ResourceHandler(String libsDir, String cfgPath, String igniteDir) {
+        this.libsDir = libsDir;
+        this.cfgPath = cfgPath;
+        this.igniteDir = igniteDir;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override public void handle(
+        String url,
+        Request request,
+        HttpServletRequest httpServletRequest,
+        HttpServletResponse response) throws IOException, ServletException {
+
+        String[] path = url.split("/");
+
+        String fileName = path[path.length - 1];
+
+        String servicePath = url.substring(0, url.length() - fileName.length());
+
+        switch (servicePath) {
+            case IGNITE_PREFIX:
+                handleRequest(response, "application/zip-archive", igniteDir + "/" + fileName);
+
+                request.setHandled(true);
+                break;
+
+            case LIBS_PREFIX:
+                handleRequest(response, "application/java-archive", libsDir + "/" + fileName);
+
+                request.setHandled(true);
+                break;
+
+            case CONFIG_PREFIX:
+                handleRequest(response, "application/xml", cfgPath);
+
+                request.setHandled(true);
+                break;
+
+            case DEFAULT_CONFIG:
+                handleRequest(response, "application/xml",
+                    Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName),
+                    fileName);
+
+                request.setHandled(true);
+                break;
+        }
+    }
+
+    /**
+     * @param response Http response.
+     * @param type Type.
+     * @param path Path to file.
+     * @throws IOException If failed.
+     */
+    private static void handleRequest(HttpServletResponse response, String type, String path) throws IOException {
+        Path path0 = Paths.get(path);
+
+        response.setContentType(type);
+        response.setHeader("Content-Disposition", "attachment; filename=\"" + path0.getFileName() + "\"");
+
+        try (HttpOutput out = (HttpOutput)response.getOutputStream()) {
+            out.sendContent(FileChannel.open(path0, StandardOpenOption.READ));
+        }
+    }
+
+    /**
+     * @param response Http response.
+     * @param type Type.
+     * @param stream Stream.
+     * @param attachmentName Attachment name.
+     * @throws IOException If failed.
+     */
+    private static void handleRequest(HttpServletResponse response, String type, InputStream stream,
+        String attachmentName) throws IOException {
+        response.setContentType(type);
+        response.setHeader("Content-Disposition", "attachment; filename=\"" + attachmentName + "\"");
+
+        try (HttpOutput out = (HttpOutput)response.getOutputStream()) {
+            out.sendContent(stream);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceProvider.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceProvider.java
new file mode 100644
index 0000000..f02d1bf
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceProvider.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.mesos.resource;
+
+import org.apache.ignite.mesos.*;
+
+import java.io.*;
+import java.util.*;
+
+import static org.apache.ignite.mesos.resource.ResourceHandler.*;
+
+/**
+ * Provides path to user's libs and config file.
+ */
+public class ResourceProvider {
+    /** Ignite url. */
+    private String igniteUrl;
+
+    /** Resources. */
+    private Collection<String> libsUris;
+
+    /** Url config. */
+    private String configUrl;
+
+    /** Config name. */
+    private String configName;
+
+    /**
+     * @param properties Cluster properties.
+     * @param provider Ignite provider.
+     * @param baseUrl Base url.
+     */
+    public void init(ClusterProperties properties, IgniteProvider provider, String baseUrl) {
+        // Downloading ignite.
+        if (properties.igniteVer().equals(ClusterProperties.DEFAULT_IGNITE_VERSION))
+            igniteUrl = baseUrl + IGNITE_PREFIX + provider.getIgnite();
+        else
+            igniteUrl = baseUrl + IGNITE_PREFIX + provider.getIgnite(properties.igniteVer());
+
+        // Find all jar files into user folder.
+        if (properties.userLibs() != null && !properties.userLibs().isEmpty()) {
+            File libsDir = new File(properties.userLibs());
+
+            List<String> libs = new ArrayList<>();
+
+            if (libsDir.isDirectory()) {
+                File[] files = libsDir.listFiles();
+
+                if (files != null) {
+                    for (File lib : files) {
+                        if (lib.isFile() && lib.canRead() &&
+                            (lib.getName().endsWith(".jar") || lib.getName().endsWith(".JAR")))
+                            libs.add(baseUrl + LIBS_PREFIX + lib.getName());
+                    }
+                }
+            }
+
+            libsUris = libs.isEmpty() ? null : libs;
+        }
+
+        // Set configuration url.
+        if (properties.igniteCfg() != null) {
+            File cfg = new File(properties.igniteCfg());
+
+            if (cfg.isFile() && cfg.canRead()) {
+                configUrl = baseUrl + CONFIG_PREFIX + cfg.getName();
+
+                configName = cfg.getName();
+            }
+        }
+        else {
+            configName = "ignite-default-config.xml";
+
+            configUrl = baseUrl + DEFAULT_CONFIG + configName;
+        }
+    }
+
+    /**
+     * @return Config name.
+     */
+    public String configName() {
+        return configName;
+    }
+
+    /**
+     * @return Ignite url.
+     */
+    public String igniteUrl() {
+        return igniteUrl;
+    }
+
+    /**
+     * @return Urls to user's libs.
+     */
+    public Collection<String> resourceUrl() {
+        return libsUris;
+    }
+
+    /**
+     * @return Url to config file.
+     */
+    public String igniteConfigUrl() {
+        return configUrl;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/package-info.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/package-info.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/package-info.java
new file mode 100644
index 0000000..7e3614e
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains classes provide access to resources.
+ */
+package org.apache.ignite.mesos.resource;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/resources/ignite-default-config.xml
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/resources/ignite-default-config.xml b/modules/mesos/src/main/resources/ignite-default-config.xml
new file mode 100644
index 0000000..2f26398
--- /dev/null
+++ b/modules/mesos/src/main/resources/ignite-default-config.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                            http://www.springframework.org/schema/beans/spring-beans.xsd">
+    <bean class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"/>
+                </property>
+
+                <property name="joinTimeout" value="60000"/>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/test/java/org/apache/ignite/IgniteMesosTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/test/java/org/apache/ignite/IgniteMesosTestSuite.java b/modules/mesos/src/test/java/org/apache/ignite/IgniteMesosTestSuite.java
new file mode 100644
index 0000000..f1bcb90
--- /dev/null
+++ b/modules/mesos/src/test/java/org/apache/ignite/IgniteMesosTestSuite.java
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+import junit.framework.*;
+import org.apache.ignite.mesos.*;
+
+/**
+ * Apache Mesos integration tests.
+ */
+public class IgniteMesosTestSuite extends TestSuite {
+    /**
+     * @return Test suite.
+     * @throws Exception Thrown in case of the failure.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Apache Mesos Integration Test Suite");
+
+        suite.addTest(new TestSuite(IgniteSchedulerSelfTest.class));
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/test/java/org/apache/ignite/mesos/IgniteSchedulerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/test/java/org/apache/ignite/mesos/IgniteSchedulerSelfTest.java b/modules/mesos/src/test/java/org/apache/ignite/mesos/IgniteSchedulerSelfTest.java
new file mode 100644
index 0000000..d627553
--- /dev/null
+++ b/modules/mesos/src/test/java/org/apache/ignite/mesos/IgniteSchedulerSelfTest.java
@@ -0,0 +1,464 @@
+/*
+ * 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.mesos;
+
+import junit.framework.*;
+import org.apache.ignite.mesos.resource.*;
+import org.apache.mesos.*;
+
+import java.util.*;
+import java.util.regex.*;
+
+/**
+ * Scheduler tests.
+ */
+public class IgniteSchedulerSelfTest extends TestCase {
+    /** */
+    private IgniteScheduler scheduler;
+
+    /** {@inheritDoc} */
+    @Override public void setUp() throws Exception {
+        super.setUp();
+
+        ClusterProperties clustProp = new ClusterProperties();
+
+        scheduler = new IgniteScheduler(clustProp, new ResourceProvider() {
+            @Override public String configName() {
+                return "config.xml";
+            }
+
+            @Override public String igniteUrl() {
+                return "ignite.jar";
+            }
+
+            @Override public String igniteConfigUrl() {
+                return "config.xml";
+            }
+
+            @Override public Collection<String> resourceUrl() {
+                return null;
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testHostRegister() throws Exception {
+        Protos.Offer offer = createOffer("hostname", 4, 1024);
+
+        DriverMock mock = new DriverMock();
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNotNull(mock.launchedTask);
+        assertEquals(1, mock.launchedTask.size());
+
+        Protos.TaskInfo taskInfo = mock.launchedTask.iterator().next();
+
+        assertEquals(4.0, resources(taskInfo.getResourcesList(), IgniteScheduler.CPU));
+        assertEquals(1024.0, resources(taskInfo.getResourcesList(), IgniteScheduler.MEM));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDeclineByCpu() throws Exception {
+        Protos.Offer offer = createOffer("hostname", 4, 1024);
+
+        DriverMock mock = new DriverMock();
+
+        ClusterProperties clustProp = new ClusterProperties();
+        clustProp.cpus(2);
+
+        scheduler.setClusterProps(clustProp);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNotNull(mock.launchedTask);
+        assertEquals(1, mock.launchedTask.size());
+
+        Protos.TaskInfo taskInfo = mock.launchedTask.iterator().next();
+
+        assertEquals(2.0, resources(taskInfo.getResourcesList(), IgniteScheduler.CPU));
+        assertEquals(1024.0, resources(taskInfo.getResourcesList(), IgniteScheduler.MEM));
+
+        mock.clear();
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNull(mock.launchedTask);
+
+        Protos.OfferID declinedOffer = mock.declinedOffer;
+
+        assertEquals(offer.getId(), declinedOffer);
+    }
+
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDeclineByMem() throws Exception {
+        Protos.Offer offer = createOffer("hostname", 4, 1024);
+
+        DriverMock mock = new DriverMock();
+
+        ClusterProperties clustProp = new ClusterProperties();
+        clustProp.memory(512);
+
+        scheduler.setClusterProps(clustProp);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNotNull(mock.launchedTask);
+        assertEquals(1, mock.launchedTask.size());
+
+        Protos.TaskInfo taskInfo = mock.launchedTask.iterator().next();
+
+        assertEquals(4.0, resources(taskInfo.getResourcesList(), IgniteScheduler.CPU));
+        assertEquals(512.0, resources(taskInfo.getResourcesList(), IgniteScheduler.MEM));
+
+        mock.clear();
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNull(mock.launchedTask);
+
+        Protos.OfferID declinedOffer = mock.declinedOffer;
+
+        assertEquals(offer.getId(), declinedOffer);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDeclineByMemCpu() throws Exception {
+        Protos.Offer offer = createOffer("hostname", 1, 1024);
+
+        DriverMock mock = new DriverMock();
+
+        ClusterProperties clustProp = new ClusterProperties();
+        clustProp.cpus(4);
+        clustProp.memory(2000);
+
+        scheduler.setClusterProps(clustProp);
+
+        double totalMem = 0, totalCpu = 0;
+
+        for (int i = 0; i < 2; i++) {
+            scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+            assertNotNull(mock.launchedTask);
+            assertEquals(1, mock.launchedTask.size());
+
+            Protos.TaskInfo taskInfo = mock.launchedTask.iterator().next();
+
+            totalCpu += resources(taskInfo.getResourcesList(), IgniteScheduler.CPU);
+            totalMem += resources(taskInfo.getResourcesList(), IgniteScheduler.MEM);
+
+            mock.clear();
+        }
+
+        assertEquals(2.0, totalCpu);
+        assertEquals(2000.0, totalMem);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNull(mock.launchedTask);
+
+        Protos.OfferID declinedOffer = mock.declinedOffer;
+
+        assertEquals(offer.getId(), declinedOffer);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDeclineByCpuMinRequirements() throws Exception {
+        Protos.Offer offer = createOffer("hostname", 8, 10240);
+
+        DriverMock mock = new DriverMock();
+
+        ClusterProperties clustProp = new ClusterProperties();
+        clustProp.minCpuPerNode(12);
+
+        scheduler.setClusterProps(clustProp);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNotNull(mock.declinedOffer);
+
+        assertEquals(offer.getId(), mock.declinedOffer);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDeclineByMemMinRequirements() throws Exception {
+        Protos.Offer offer = createOffer("hostname", 8, 10240);
+
+        DriverMock mock = new DriverMock();
+
+        ClusterProperties clustProp = new ClusterProperties();
+        clustProp.minMemoryPerNode(15000);
+
+        scheduler.setClusterProps(clustProp);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNotNull(mock.declinedOffer);
+
+        assertEquals(offer.getId(), mock.declinedOffer);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testHosthameConstraint() throws Exception {
+        Protos.Offer offer = createOffer("hostname", 8, 10240);
+
+        DriverMock mock = new DriverMock();
+
+        ClusterProperties clustProp = new ClusterProperties();
+        clustProp.hostnameConstraint(Pattern.compile("hostname"));
+
+        scheduler.setClusterProps(clustProp);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNotNull(mock.declinedOffer);
+
+        assertEquals(offer.getId(), mock.declinedOffer);
+
+        offer = createOffer("hostnameAccept", 8, 10240);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNotNull(mock.launchedTask);
+        assertEquals(1, mock.launchedTask.size());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPerNode() throws Exception {
+        Protos.Offer offer = createOffer("hostname", 8, 1024);
+
+        DriverMock mock = new DriverMock();
+
+        ClusterProperties clustProp = new ClusterProperties();
+        clustProp.memoryPerNode(1024);
+        clustProp.cpusPerNode(2);
+
+        scheduler.setClusterProps(clustProp);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNotNull(mock.launchedTask);
+
+        Protos.TaskInfo taskInfo = mock.launchedTask.iterator().next();
+
+        assertEquals(2.0, resources(taskInfo.getResourcesList(), IgniteScheduler.CPU));
+        assertEquals(1024.0, resources(taskInfo.getResourcesList(), IgniteScheduler.MEM));
+
+        mock.clear();
+
+        offer = createOffer("hostname", 1, 2048);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNull(mock.launchedTask);
+
+        assertNotNull(mock.declinedOffer);
+        assertEquals(offer.getId(), mock.declinedOffer);
+
+        mock.clear();
+
+        offer = createOffer("hostname", 4, 512);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNull(mock.launchedTask);
+
+        assertNotNull(mock.declinedOffer);
+        assertEquals(offer.getId(), mock.declinedOffer);
+    }
+
+    /**
+     * @param resourceType Resource type.
+     * @return Value.
+     */
+    private Double resources(List<Protos.Resource> resources, String resourceType) {
+        for (Protos.Resource resource : resources) {
+            if (resource.getName().equals(resourceType))
+                return resource.getScalar().getValue();
+        }
+
+        return null;
+    }
+
+    /**
+     * @param hostname Hostname
+     * @param cpu Cpu count.
+     * @param mem Mem size.
+     * @return Offer.
+     */
+    private Protos.Offer createOffer(String hostname, double cpu, double mem) {
+        return Protos.Offer.newBuilder()
+            .setId(Protos.OfferID.newBuilder().setValue("1"))
+            .setSlaveId(Protos.SlaveID.newBuilder().setValue("1"))
+            .setFrameworkId(Protos.FrameworkID.newBuilder().setValue("1"))
+            .setHostname(hostname)
+            .addResources(Protos.Resource.newBuilder()
+                .setType(Protos.Value.Type.SCALAR)
+                .setName(IgniteScheduler.CPU)
+                .setScalar(Protos.Value.Scalar.newBuilder().setValue(cpu).build())
+                .build())
+            .addResources(Protos.Resource.newBuilder()
+                .setType(Protos.Value.Type.SCALAR)
+                .setName(IgniteScheduler.MEM)
+                .setScalar(Protos.Value.Scalar.newBuilder().setValue(mem).build())
+                .build())
+            .build();
+    }
+
+    /**
+     * No-op implementation.
+     */
+    public static class DriverMock implements SchedulerDriver {
+        /** */
+        Collection<Protos.TaskInfo> launchedTask;
+
+        /** */
+        Protos.OfferID declinedOffer;
+
+        /**
+         * Clears launched task.
+         */
+        public void clear() {
+            launchedTask = null;
+            declinedOffer = null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status start() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status stop(boolean failover) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status stop() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status abort() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status join() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status run() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status requestResources(Collection<Protos.Request> requests) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status launchTasks(Collection<Protos.OfferID> offerIds,
+            Collection<Protos.TaskInfo> tasks, Protos.Filters filters) {
+            launchedTask = tasks;
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status launchTasks(Collection<Protos.OfferID> offerIds,
+            Collection<Protos.TaskInfo> tasks) {
+            launchedTask = tasks;
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status launchTasks(Protos.OfferID offerId, Collection<Protos.TaskInfo> tasks,
+            Protos.Filters filters) {
+            launchedTask = tasks;
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status launchTasks(Protos.OfferID offerId, Collection<Protos.TaskInfo> tasks) {
+            launchedTask = tasks;
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status killTask(Protos.TaskID taskId) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status declineOffer(Protos.OfferID offerId, Protos.Filters filters) {
+            declinedOffer = offerId;
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status declineOffer(Protos.OfferID offerId) {
+            declinedOffer = offerId;
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status reviveOffers() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status acknowledgeStatusUpdate(Protos.TaskStatus status) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status sendFrameworkMessage(Protos.ExecutorID executorId, Protos.SlaveID slaveId,
+            byte[] data) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Protos.Status reconcileTasks(Collection<Protos.TaskStatus> statuses) {
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/rest-http/pom.xml
----------------------------------------------------------------------
diff --git a/modules/rest-http/pom.xml b/modules/rest-http/pom.xml
index 9097614..64db144 100644
--- a/modules/rest-http/pom.xml
+++ b/modules/rest-http/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-rest-http</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/scalar/pom.xml
----------------------------------------------------------------------
diff --git a/modules/scalar/pom.xml b/modules/scalar/pom.xml
index 590d3f7..d3fcf2e 100644
--- a/modules/scalar/pom.xml
+++ b/modules/scalar/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-scalar</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/scalar/src/main/scala/org/apache/ignite/scalar/ScalarConversions.scala
----------------------------------------------------------------------
diff --git a/modules/scalar/src/main/scala/org/apache/ignite/scalar/ScalarConversions.scala b/modules/scalar/src/main/scala/org/apache/ignite/scalar/ScalarConversions.scala
index d9565af..32e6758 100644
--- a/modules/scalar/src/main/scala/org/apache/ignite/scalar/ScalarConversions.scala
+++ b/modules/scalar/src/main/scala/org/apache/ignite/scalar/ScalarConversions.scala
@@ -867,14 +867,6 @@ trait ScalarConversions {
         GridFunc.as(r)
 
     /**
-     * Implicit converter from `java.util.concurrent.Callable` to `GridOutClosure`.
-     *
-     * @param c Java callable to convert.
-     */
-    implicit def toOutClosure2[R](c: java.util.concurrent.Callable[R]): IgniteOutClosure[R] =
-        GridFunc.as0(c)
-
-    /**
      * Implicit converter from Scala predicate to Scala wrapping predicate.
      *
      * @param f Scala predicate to convert.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarCacheQueriesSpec.scala
----------------------------------------------------------------------
diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarCacheQueriesSpec.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarCacheQueriesSpec.scala
index 8d91fdc..2a11e5e 100644
--- a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarCacheQueriesSpec.scala
+++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarCacheQueriesSpec.scala
@@ -31,7 +31,7 @@ import scala.collection.JavaConversions._
  * Tests for Scalar cache queries API.
  */
 @RunWith(classOf[JUnitRunner])
-class ScalarCacheQueriesSpec extends FlatSpec with ShouldMatchers with BeforeAndAfterAll {
+class ScalarCacheQueriesSpec extends FunSpec with ShouldMatchers with BeforeAndAfterAll {
     /** Entries count. */
     private val ENTRY_CNT = 10
 
@@ -67,142 +67,142 @@ class ScalarCacheQueriesSpec extends FlatSpec with ShouldMatchers with BeforeAnd
         stop()
     }
 
-    behavior of "Scalar cache queries API"
+    describe("Scalar cache queries API") {
+        it("should correctly execute SCAN queries") {
+            var res = c.scan(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8).getAll
 
-    it should "correctly execute SCAN queries" in {
-        var res = c.scan(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8).getAll
+            assert(res.size == 2)
 
-        assert(res.size == 2)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey < 8 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey < 8 && t.getKey == t.getValue.intVal))
+            res = c.scan((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8).getAll
 
-        res = c.scan((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8).getAll
+            assert(res.size == 2)
 
-        assert(res.size == 2)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey < 8 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey < 8 && t.getKey == t.getValue.intVal))
+            res = c.scan(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8).getAll
 
-        res = c.scan(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8).getAll
+            assert(res.size == 2)
 
-        assert(res.size == 2)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey < 8 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey < 8 && t.getKey == t.getValue.intVal))
+            res = c.scan((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8).getAll
 
-        res = c.scan((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8).getAll
+            assert(res.size == 2)
 
-        assert(res.size == 2)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey < 8 && t.getKey == t.getValue.intVal))
+        }
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey < 8 && t.getKey == t.getValue.intVal))
-    }
+        it("should correctly execute SQL queries") {
+            var res = c.sql(classOf[ObjectValue], "intVal > 5").getAll
 
-    it should "correctly execute SQL queries" in {
-        var res = c.sql(classOf[ObjectValue], "intVal > 5").getAll
+            assert(res.size == ENTRY_CNT - 5)
 
-        assert(res.size == ENTRY_CNT - 5)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
+            res = c.sql(classOf[ObjectValue], "intVal > ?", 5).getAll
 
-        res = c.sql(classOf[ObjectValue], "intVal > ?", 5).getAll
+            assert(res.size == ENTRY_CNT - 5)
 
-        assert(res.size == ENTRY_CNT - 5)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
+            res = c.sql("intVal > 5").getAll
 
-        res = c.sql("intVal > 5").getAll
+            assert(res.size == ENTRY_CNT - 5)
 
-        assert(res.size == ENTRY_CNT - 5)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
+            res = c.sql("intVal > ?", 5).getAll
 
-        res = c.sql("intVal > ?", 5).getAll
+            assert(res.size == ENTRY_CNT - 5)
 
-        assert(res.size == ENTRY_CNT - 5)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
+            res = c.sql(classOf[ObjectValue], "intVal > 5").getAll
 
-        res = c.sql(classOf[ObjectValue], "intVal > 5").getAll
+            assert(res.size == ENTRY_CNT - 5)
 
-        assert(res.size == ENTRY_CNT - 5)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
+            res = c.sql(classOf[ObjectValue], "intVal > ?", 5).getAll
 
-        res = c.sql(classOf[ObjectValue], "intVal > ?", 5).getAll
+            assert(res.size == ENTRY_CNT - 5)
 
-        assert(res.size == ENTRY_CNT - 5)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
+            res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
+            res = c.sql("intVal > 5").getAll
 
-        res = c.sql("intVal > 5").getAll
+            assert(res.size == ENTRY_CNT - 5)
 
-        assert(res.size == ENTRY_CNT - 5)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
+            res = c.sql("intVal > ?", 5).getAll
 
-        res = c.sql("intVal > ?", 5).getAll
+            assert(res.size == ENTRY_CNT - 5)
 
-        assert(res.size == ENTRY_CNT - 5)
+            res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
+        }
 
-        res.foreach(t => assert(t.getKey > 5 && t.getKey == t.getValue.intVal))
-    }
+        it("should correctly execute TEXT queries") {
+            var res = c.text(classOf[ObjectValue], "str").getAll
 
-    it should "correctly execute TEXT queries" in {
-        var res = c.text(classOf[ObjectValue], "str").getAll
+            assert(res.size == ENTRY_CNT)
 
-        assert(res.size == ENTRY_CNT)
+            res = c.text(classOf[ObjectValue], "five").getAll
 
-        res = c.text(classOf[ObjectValue], "five").getAll
+            assert(res.size == 1)
+            assert(res.head.getKey == 5)
 
-        assert(res.size == 1)
-        assert(res.head.getKey == 5)
+            res = c.text("str").getAll
 
-        res = c.text("str").getAll
+            assert(res.size == ENTRY_CNT)
 
-        assert(res.size == ENTRY_CNT)
+            res = c.text("five").getAll
 
-        res = c.text("five").getAll
+            assert(res.size == 1)
+            assert(res.head.getKey == 5)
 
-        assert(res.size == 1)
-        assert(res.head.getKey == 5)
+            res = c.text(classOf[ObjectValue], "str").getAll
 
-        res = c.text(classOf[ObjectValue], "str").getAll
+            assert(res.size == ENTRY_CNT)
 
-        assert(res.size == ENTRY_CNT)
+            res = c.text(classOf[ObjectValue], "five").getAll
 
-        res = c.text(classOf[ObjectValue], "five").getAll
+            assert(res.size == 1)
+            assert(res.head.getKey == 5)
 
-        assert(res.size == 1)
-        assert(res.head.getKey == 5)
+            res = c.text("str").getAll
 
-        res = c.text("str").getAll
+            assert(res.size == ENTRY_CNT)
 
-        assert(res.size == ENTRY_CNT)
+            res = c.text("five").getAll
 
-        res = c.text("five").getAll
+            assert(res.size == 1)
+            assert(res.head.getKey == 5)
+        }
 
-        assert(res.size == 1)
-        assert(res.head.getKey == 5)
-    }
+        it("should correctly execute fields queries") {
+            var res = c.sqlFields("select intVal from ObjectValue where intVal > 5").getAll
 
-    it should "correctly execute fields queries" in {
-        var res = c.sqlFields("select intVal from ObjectValue where intVal > 5").getAll
+            assert(res.size == ENTRY_CNT - 5)
 
-        assert(res.size == ENTRY_CNT - 5)
+            res.foreach(t => assert(t.size == 1 && t.head.asInstanceOf[Int] > 5))
 
-        res.foreach(t => assert(t.size == 1 && t.head.asInstanceOf[Int] > 5))
+            res = c.sqlFields("select intVal from ObjectValue where intVal > ?", 5).getAll
 
-        res = c.sqlFields("select intVal from ObjectValue where intVal > ?", 5).getAll
+            assert(res.size == ENTRY_CNT - 5)
 
-        assert(res.size == ENTRY_CNT - 5)
-
-        res.foreach(t => assert(t.size == 1 && t.head.asInstanceOf[Int] > 5))
-    }
+            res.foreach(t => assert(t.size == 1 && t.head.asInstanceOf[Int] > 5))
+        }
 
-    it should "correctly execute queries with multiple arguments" in {
-        val res = c.sql("from ObjectValue where intVal in (?, ?, ?)", 1, 2, 3).getAll
+        it("should correctly execute queries with multiple arguments") {
+            val res = c.sql("from ObjectValue where intVal in (?, ?, ?)", 1, 2, 3).getAll
 
-        assert(res.size == 3)
+            assert(res.size == 3)
+        }
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarCacheSpec.scala
----------------------------------------------------------------------
diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarCacheSpec.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarCacheSpec.scala
index 0fde48f..853cc16 100644
--- a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarCacheSpec.scala
+++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarCacheSpec.scala
@@ -22,32 +22,35 @@ import org.apache.ignite.events.EventType._
 import org.apache.ignite.lang.IgnitePredicate
 import org.apache.ignite.scalar.scalar
 import org.apache.ignite.scalar.scalar._
+
 import org.junit.runner.RunWith
 import org.scalatest._
 import org.scalatest.junit.JUnitRunner
+
 import scala.collection.JavaConversions._
 
 /**
  * Scalar cache test.
  */
 @RunWith(classOf[JUnitRunner])
-class ScalarCacheSpec extends FlatSpec with ShouldMatchers {
+class ScalarCacheSpec extends FunSpec with ShouldMatchers {
     private val CFG = "modules/scalar/src/test/resources/spring-cache.xml"
 
-    behavior of "Scalar cache"
+    describe("Scalar cache") {
 
-    it should "work properly via Java APIs" in {
-        scalar(CFG) {
-            registerListener()
+        it("should work properly via Java APIs") {
+            scalar(CFG) {
+                registerListener()
 
-            val c = cache$[Int, Int]("partitioned").get
+                val c = cache$[Int, Int]("partitioned").get
 
-            c.put(1, 1)
-            c.put(2, 2)
+                c.put(1, 1)
+                c.put(2, 2)
 
-            c.iterator() foreach println
+                c.iterator() foreach println
 
-            println("Size is: " + c.size())
+                println("Size is: " + c.size())
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarConversionsSpec.scala
----------------------------------------------------------------------
diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarConversionsSpec.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarConversionsSpec.scala
index b20c755..c766422 100644
--- a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarConversionsSpec.scala
+++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarConversionsSpec.scala
@@ -21,7 +21,7 @@ import org.apache.ignite.internal.util.lang._
 import org.apache.ignite.lang._
 import org.apache.ignite.scalar.scalar._
 import org.junit.runner.RunWith
-import org.scalatest.FlatSpec
+import org.scalatest._
 import org.scalatest.junit.JUnitRunner
 import org.scalatest.matchers.ShouldMatchers
 
@@ -31,10 +31,10 @@ import java.util.concurrent.atomic._
  *
  */
 @RunWith(classOf[JUnitRunner])
-class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
-    behavior of "Scalar mixin"
+class ScalarConversionsSpec extends FunSpec with ShouldMatchers {
+    describe("Scalar mixin") {
 
-    it should "convert reducer" in {
+    it("should convert reducer") {
         val r = new IgniteReducer[Int, Int] {
             var sum = 0
 
@@ -52,7 +52,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(r.scala.apply(Seq(1, 2, 3)) == 6)
     }
 
-    it should "convert reducer 2" in {
+    it("should convert reducer 2") {
         val r = new IgniteReducer2[Int, Int, Int] {
             var sum = 0
 
@@ -70,7 +70,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(r.scala.apply(Seq(1, 2), Seq(3, 4)) == 21)
     }
 
-    it should "convert reducer 3" in {
+    it("should convert reducer 3") {
         val r = new IgniteReducer3[Int, Int, Int, Int] {
             var sum = 0
 
@@ -88,14 +88,14 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(r.scala.apply(Seq(1, 2), Seq(1, 2), Seq(1, 2)) == 27)
     }
 
-    it should "convert tuple 2" in {
+    it("should convert tuple 2") {
         val t = new IgniteBiTuple[Int, Int](1, 2)
 
         assert(t.scala._1 == 1)
         assert(t.scala._2 == 2)
     }
 
-    it should "convert tuple 3" in {
+    it("should convert tuple 3") {
         val t = new GridTuple3[Int, Int, Int](1, 2, 3)
 
         assert(t.scala._1 == 1)
@@ -103,7 +103,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(t.scala._3 == 3)
     }
 
-    it should "convert tuple 4" in {
+    it("should convert tuple 4") {
         val t = new GridTuple4[Int, Int, Int, Int](1, 2, 3, 4)
 
         assert(t.scala._1 == 1)
@@ -112,7 +112,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(t.scala._4 == 4)
     }
 
-    it should "convert tuple 5" in {
+    it("should convert tuple 5") {
         val t = new GridTuple5[Int, Int, Int, Int, Int](1, 2, 3, 4, 5)
 
         assert(t.scala._1 == 1)
@@ -122,7 +122,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(t.scala._5 == 5)
     }
 
-    it should "convert in closure" in {
+    it("should convert in closure") {
         val i = new AtomicInteger()
 
         val f = new IgniteInClosure[Int] {
@@ -136,7 +136,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(i.get == 9)
     }
 
-    it should "convert in closure 2" in {
+    it("should convert in closure 2") {
         val i = new AtomicInteger()
 
         val f = new IgniteBiInClosure[Int, Int] {
@@ -150,7 +150,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(i.get == 6)
     }
 
-    it should "convert in closure 3" in {
+    it("should convert in closure 3") {
         val i = new AtomicInteger()
 
         val f = new GridInClosure3[Int, Int, Int] {
@@ -164,7 +164,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(i.get == 9)
     }
 
-    it should "convert absolute closure" in {
+    it("should convert absolute closure") {
         val i = new AtomicInteger()
 
         val f = new GridAbsClosure {
@@ -178,7 +178,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(i.get == 3)
     }
 
-    it should "convert absolute predicate" in {
+    it("should convert absolute predicate") {
         val i = new AtomicInteger()
 
         val p = new GridAbsPredicate {
@@ -195,7 +195,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(p.scala.apply())
     }
 
-    it should "convert predicate" in {
+    it("should convert predicate") {
         val p = new IgnitePredicate[Int] {
             override def apply(e: Int): Boolean =
                 e > 5
@@ -205,7 +205,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(p.scala.apply(6))
     }
 
-    it should "convert predicate 2" in {
+    it("should convert predicate 2") {
         val p = new IgniteBiPredicate[Int, Int] {
             override def apply(e1: Int, e2: Int): Boolean =
                 e1 + e2 > 5
@@ -215,7 +215,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(p.scala.apply(3, 3))
     }
 
-    it should "convert predicate 3" in {
+    it("should convert predicate 3") {
         val p = new GridPredicate3[Int, Int, Int] {
             override def apply(e1: Int, e2: Int, e3: Int): Boolean =
                 e1 + e2 + e3 > 5
@@ -225,7 +225,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(p.scala.apply(2, 2, 2))
     }
 
-    it should "convert closure" in {
+    it("should convert closure") {
         val f = new IgniteClosure[Int, Int] {
             override def apply(e: Int): Int =
                 e * 3
@@ -234,7 +234,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(f.scala.apply(3) == 9)
     }
 
-    it should "convert closure 2" in {
+    it("should convert closure 2") {
         val f = new IgniteBiClosure[Int, Int, Int] {
             override def apply(e1: Int, e2: Int): Int =
                 e1 + e2
@@ -243,7 +243,7 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
         assert(f.scala.apply(3, 3) == 6)
     }
 
-    it should "convert closure 3" in {
+    it("should convert closure 3") {
         val f = new GridClosure3[Int, Int, Int, Int] {
             override def apply(e1: Int, e2: Int, e3: Int): Int =
                 e1 + e2 + e3
@@ -251,4 +251,5 @@ class ScalarConversionsSpec extends FlatSpec with ShouldMatchers {
 
         assert(f.scala.apply(3, 3, 3) == 9)
     }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarProjectionSpec.scala
----------------------------------------------------------------------
diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarProjectionSpec.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarProjectionSpec.scala
index a035550..ecb1e5a 100644
--- a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarProjectionSpec.scala
+++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarProjectionSpec.scala
@@ -23,6 +23,7 @@ import org.apache.ignite.configuration.IgniteConfiguration
 import org.apache.ignite.messaging.MessagingListenActor
 import org.apache.ignite.scalar.scalar
 import org.apache.ignite.scalar.scalar._
+
 import org.junit.runner.RunWith
 import org.scalatest._
 import org.scalatest.junit.JUnitRunner
@@ -35,7 +36,7 @@ import scala.collection.JavaConversions._
  * Scalar cache test.
  */
 @RunWith(classOf[JUnitRunner])
-class ScalarProjectionSpec extends FlatSpec with ShouldMatchers with BeforeAndAfterAll {
+class ScalarProjectionSpec extends FunSpec with ShouldMatchers with BeforeAndAfterAll {
     /**
      *
      */
@@ -68,82 +69,95 @@ class ScalarProjectionSpec extends FlatSpec with ShouldMatchers with BeforeAndAf
         cfg
     }
 
-    behavior of "ScalarProjectionPimp class"
-
-    it should "return all nodes" in scalar(gridConfig("node-scalar", true)) {
-        assertResult(3) {
-            ignite$("node-scalar").get.cluster().nodes().size
+    describe("ScalarProjectionPimp class") {
+        it("should return all nodes") {
+            scalar(gridConfig("node-scalar", true)) {
+                assertResult(3)(ignite$("node-scalar").get.cluster().nodes().size)
+            }
         }
-    }
-
-    it should "return shown nodes" in  scalar(gridConfig("node-scalar", true)) {
-        assert(ignite$("node-scalar").get.nodes$((node: ClusterNode) => node.attribute[Boolean]("shown")).size == 2)
-    }
 
-    it should "return all remote nodes" in scalar(gridConfig("node-scalar", true)) {
-        assertResult(2) {
-            ignite$("node-scalar").get.remoteNodes$().size
+        it("should return shown nodes") {
+            scalar(gridConfig("node-scalar", true)) {
+                assert(ignite$("node-scalar").get.nodes$(
+                    (node: ClusterNode) => node.attribute[Boolean]("shown")).size == 2)
+            }
         }
-    }
-
-    it should "return shown remote nodes" in  scalar(gridConfig("node-scalar", true)) {
-        assert(ignite$("node-scalar").get.remoteNodes$((node: ClusterNode) =>
-            node.attribute[Boolean]("shown")).size == 1)
-    }
-
-    it should "correctly send messages" in scalar(gridConfig("node-scalar", true)) {
 
-        ignite$("node-1").get.message().remoteListen(null, new MessagingListenActor[Any]() {
-            def receive(nodeId: UUID, msg: Any) {
-                println("node-1 received " + msg)
+        it("should return all remote nodes") {
+            scalar(gridConfig("node-scalar", true)) {
+                assertResult(2)(ignite$("node-scalar").get.remoteNodes$().size)
             }
-        })
+        }
 
-        ignite$("node-2").get.message().remoteListen(null, new MessagingListenActor[Any]() {
-            def receive(nodeId: UUID, msg: Any) {
-                println("node-2 received " + msg)
+        it("should return shown remote nodes") {
+            scalar(gridConfig("node-scalar", true)) {
+                assert(ignite$("node-scalar").get.remoteNodes$((node: ClusterNode) =>
+                    node.attribute[Boolean]("shown")).size == 1)
             }
-        })
+        }
 
-        ignite$("node-scalar").get !< ("Message", null)
-        ignite$("node-scalar").get !< (Seq("Message1", "Message2"), null)
-    }
+        it("should correctly send messages") {
+            scalar(gridConfig("node-scalar", true)) {
+                ignite$("node-1").get.message().remoteListen(null, new MessagingListenActor[Any]() {
+                    def receive(nodeId: UUID, msg: Any) {
+                        println("node-1 received " + msg)
+                    }
+                })
+
+                ignite$("node-2").get.message().remoteListen(null, new MessagingListenActor[Any]() {
+                    def receive(nodeId: UUID, msg: Any) {
+                        println("node-2 received " + msg)
+                    }
+                })
+
+                ignite$("node-scalar").get !<("Message", null)
+                ignite$("node-scalar").get !<(Seq("Message1", "Message2"), null)
+            }
+        }
 
-    it should "correctly make calls" in scalar(gridConfig("node-scalar", true)) {
-        println("CALL RESULT: " + ignite$("node-scalar").get #< (() => "Message", null))
+        it("should correctly make calls") {
+            scalar(gridConfig("node-scalar", true)) {
+                println("CALL RESULT: " + ignite$("node-scalar").get #<(() => "Message", null))
 
-        println("ASYNC CALL RESULT: " + ignite$("node-scalar").get.callAsync$[String](() => "Message", null).get)
+                println("ASYNC CALL RESULT: " + ignite$("node-scalar").get.callAsync$[String](() => "Message", null).get)
 
-        val call1: () => String = () => "Message1"
-        val call2: () => String = () => "Message2"
+                val call1: () => String = () => "Message1"
+                val call2: () => String = () => "Message2"
 
-        println("MULTIPLE CALL RESULT: " + ignite$("node-scalar").get #< (Seq(call1, call2), null))
+                println("MULTIPLE CALL RESULT: " + ignite$("node-scalar").get #<(Seq(call1, call2), null))
 
-        println("MULTIPLE ASYNC CALL RESULT: " +
-            (ignite$("node-scalar").get #? (Seq(call1, call2), null)).get)
-    }
+                println("MULTIPLE ASYNC CALL RESULT: " +
+                    (ignite$("node-scalar").get #?(Seq(call1, call2), null)).get)
+            }
+        }
 
-    it should "correctly make runs" in scalar(gridConfig("node-scalar", true)) {
-        ignite$("node-scalar").get *< (() => println("RUN RESULT: Message"), null)
+        it("should correctly make runs") {
+            scalar(gridConfig("node-scalar", true)) {
+                ignite$("node-scalar").get *<(() => println("RUN RESULT: Message"), null)
 
-        (ignite$("node-scalar").get *? (() => println("ASYNC RUN RESULT: Message"), null)).get
+                (ignite$("node-scalar").get *?(() => println("ASYNC RUN RESULT: Message"), null)).get
 
-        val run1: () => Unit = () => println("RUN 1 RESULT: Message1")
-        val run2: () => Unit = () => println("RUN 2 RESULT: Message2")
+                val run1: () => Unit = () => println("RUN 1 RESULT: Message1")
+                val run2: () => Unit = () => println("RUN 2 RESULT: Message2")
 
-        ignite$("node-scalar").get *< (Seq(run1, run2), null)
+                ignite$("node-scalar").get *<(Seq(run1, run2), null)
 
-        val runAsync1: () => Unit = () => println("ASYNC RUN 1 RESULT: Message1")
-        val runAsync2: () => Unit = () => println("ASYNC RUN 2 RESULT: Message2")
+                val runAsync1: () => Unit = () => println("ASYNC RUN 1 RESULT: Message1")
+                val runAsync2: () => Unit = () => println("ASYNC RUN 2 RESULT: Message2")
 
-        (ignite$("node-scalar").get *? (Seq(runAsync1, runAsync2), null)).get
-    }
+                (ignite$("node-scalar").get *?(Seq(runAsync1, runAsync2), null)).get
+            }
+        }
 
-    it should "correctly reduce" in scalar(gridConfig("node-scalar", true)) {
-        val call1: () => Int = () => 15
-        val call2: () => Int = () => 82
+        it("should correctly reduce") {
+            scalar(gridConfig("node-scalar", true)) {
+                val call1: () => Int = () => 15
+                val call2: () => Int = () => 82
 
-        assert(ignite$("node-scalar").get @< (Seq(call1, call2), (n: Seq[Int]) => n.sum, null) == 97)
-        assert(ignite$("node-scalar").get.reduceAsync$(Seq(call1, call2), (n: Seq[Int]) => n.sum, null).get == 97)
+                assert(ignite$("node-scalar").get @<(Seq(call1, call2), (n: Seq[Int]) => n.sum, null) == 97)
+                assert(ignite$("node-scalar").get.reduceAsync$(Seq(call1, call2), (
+                    n: Seq[Int]) => n.sum, null).get == 97)
+            }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarReturnableSpec.scala
----------------------------------------------------------------------
diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarReturnableSpec.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarReturnableSpec.scala
index 21e8cef..2927dd7 100644
--- a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarReturnableSpec.scala
+++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarReturnableSpec.scala
@@ -18,6 +18,7 @@
 package org.apache.ignite.scalar.tests
 
 import org.apache.ignite.scalar.scalar._
+
 import org.junit.runner.RunWith
 import org.scalatest._
 import org.scalatest.junit.JUnitRunner
@@ -28,30 +29,32 @@ import scala.util.control.Breaks._
  *
  */
 @RunWith(classOf[JUnitRunner])
-class ScalarReturnableSpec extends FlatSpec with ShouldMatchers {
-    "Scalar '^^'" should "work" in {
-        var i = 0
+class ScalarReturnableSpec extends FunSpec with ShouldMatchers {
+    describe("Scalar '^^'") {
+        it("should work") {
+            var i = 0
+
+            breakable {
+                while (true) {
+                    if (i == 0)
+                        println("Only once!") ^^
+
+                    i += 1
+                }
+            }
 
-        breakable {
-            while (true) {
-                if (i == 0)
-                    println("Only once!") ^^
+            assert(i == 0)
+        }
 
-                i += 1
+        // Ignore exception below.
+        def test() = breakable {
+            while (true) {
+                println("Only once!") ^^
             }
         }
 
-        assert(i == 0)
-    }
-
-    "Scalar '^^'" should "also work" in {
-        test()
-    }
-
-    // Ignore exception below.
-    def test() = breakable {
-        while (true) {
-            println("Only once!") ^^
+        it("should also work") {
+            test()
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/schedule/pom.xml
----------------------------------------------------------------------
diff --git a/modules/schedule/pom.xml b/modules/schedule/pom.xml
index 2c09ed9..cac133f 100644
--- a/modules/schedule/pom.xml
+++ b/modules/schedule/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-schedule</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/schema-import/pom.xml
----------------------------------------------------------------------
diff --git a/modules/schema-import/pom.xml b/modules/schema-import/pom.xml
index 7c49cab..64f85d9 100644
--- a/modules/schema-import/pom.xml
+++ b/modules/schema-import/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-schema-import</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>
@@ -84,9 +84,11 @@
 
     <profiles>
         <profile>
-            <id>jfxrt.jar</id>
+            <id>schema-import</id>
             <activation>
-                <jdk>[1.7,1.8)</jdk>
+                <file>
+                    <exists>${java.home}/lib/jfxrt.jar</exists>
+                </file>
             </activation>
             <dependencies>
                 <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
index f8901d2..b92d84b 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
@@ -69,7 +69,7 @@ public class CodeGenerator {
      * @throws IllegalStateException If passed string is not valid java identifier.
      */
     private static void checkValidJavaIdentifier(String identifier, boolean split, String msg, String type)
-        throws IllegalStateException{
+        throws IllegalStateException {
         if (identifier.isEmpty())
             throw new IllegalStateException(msg + " could not be empty!");
 
@@ -550,21 +550,25 @@ public class CodeGenerator {
      * @param mtdName Method name to generate.
      * @param comment Commentary text.
      * @param first {@code true} if variable should be declared.
+     * @return {@code false} if variable was declared.
      */
-    private static void addQueryFields(Collection<String> src, Collection<PojoField> fields, String varName,
+    private static boolean addQueryFields(Collection<String> src, Collection<PojoField> fields, String varName,
         String mtdName, String comment, boolean first) {
-        if (!fields.isEmpty()) {
-            add2(src, comment);
-            add2(src, (first ? "Map<String, Class<?>> " : "") + varName + " = new LinkedHashMap<>();");
-            add0(src, "");
+        if (fields.isEmpty())
+            return true;
 
-            for (PojoField field : fields)
-                add2(src, varName + ".put(\"" + field.javaName() + "\", " + javaTypeName(field) + ".class);");
+        add2(src, comment);
+        add2(src, (first ? "Map<String, Class<?>> " : "") + varName + " = new LinkedHashMap<>();");
+        add0(src, "");
 
-            add0(src, "");
-            add2(src, "type." + mtdName + "(" + varName + ");");
-            add0(src, "");
-        }
+        for (PojoField field : fields)
+            add2(src, varName + ".put(\"" + field.javaName() + "\", " + javaTypeName(field) + ".class);");
+
+        add0(src, "");
+        add2(src, "type." + mtdName + "(" + varName + ");");
+        add0(src, "");
+
+        return false;
     }
 
     /**
@@ -623,6 +627,9 @@ public class CodeGenerator {
         add0(src, "");
 
         boolean first = true;
+        boolean firstAsc = true;
+        boolean firstDesc = true;
+        boolean firstGrps = true;
         boolean firstGrp = true;
 
         for (PojoDescriptor pojo : pojos) {
@@ -661,25 +668,27 @@ public class CodeGenerator {
             addQueryFields(src, pojo.fields(), "qryFlds", "setQueryFields", "// Query fields for " + tbl + ".", first);
 
             // Ascending fields.
-            addQueryFields(src, pojo.ascendingFields(), "ascFlds", "setAscendingFields",
-                "// Ascending fields for " + tbl + ".", first);
+            firstAsc = addQueryFields(src, pojo.ascendingFields(), "ascFlds", "setAscendingFields",
+                "// Ascending fields for " + tbl + ".", firstAsc);
 
             // Descending fields.
-            addQueryFields(src, pojo.descendingFields(), "descFlds", "setDescendingFields",
-                "// Descending fields for " + tbl + ".", first);
+            firstDesc = addQueryFields(src, pojo.descendingFields(), "descFlds", "setDescendingFields",
+                "// Descending fields for " + tbl + ".", firstDesc);
 
             // Groups.
             Map<String, Map<String, IndexItem>> groups = pojo.groups();
 
             if (!groups.isEmpty()) {
                 add2(src, "// Groups for " + tbl + ".");
-                add2(src, (first ? "Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> " : "") +
-                    " grps = new LinkedHashMap<>();");
+                add2(src, (firstGrps ? "Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> " : "") +
+                    "grps = new LinkedHashMap<>();");
                 add0(src, "");
 
+                firstGrps = false;
+
                 for (Map.Entry<String, Map<String, IndexItem>> group : groups.entrySet()) {
                     add2(src, (firstGrp ? "LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>> " : "") +
-                            "grpItems = new LinkedHashMap<>();");
+                        "grpItems = new LinkedHashMap<>();");
                     add0(src, "");
 
                     for (Map.Entry<String, IndexItem> grpItem : group.getValue().entrySet()) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/slf4j/pom.xml
----------------------------------------------------------------------
diff --git a/modules/slf4j/pom.xml b/modules/slf4j/pom.xml
index 1f78f42..7c1e660 100644
--- a/modules/slf4j/pom.xml
+++ b/modules/slf4j/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-slf4j</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/spring/pom.xml
----------------------------------------------------------------------
diff --git a/modules/spring/pom.xml b/modules/spring/pom.xml
index 1390a39..e922215 100644
--- a/modules/spring/pom.xml
+++ b/modules/spring/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-spring</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java b/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
index f05e991..2c7c7e1 100644
--- a/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
+++ b/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
@@ -399,7 +399,7 @@ public class IgniteSpringHelperImpl implements IgniteSpringHelper {
      * Prepares Spring context.
      *
      * @param excludedProps Properties to be excluded.
-     * @return
+     * @return application context.
      */
     private static GenericApplicationContext prepareSpringContext(final String... excludedProps){
         GenericApplicationContext springCtx = new GenericApplicationContext();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/ssh/pom.xml
----------------------------------------------------------------------
diff --git a/modules/ssh/pom.xml b/modules/ssh/pom.xml
index 867e9be..0dcbd80 100644
--- a/modules/ssh/pom.xml
+++ b/modules/ssh/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-ssh</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/ssh/src/test/java/org/apache/ignite/internal/IgniteProjectionStartStopRestartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/ssh/src/test/java/org/apache/ignite/internal/IgniteProjectionStartStopRestartSelfTest.java b/modules/ssh/src/test/java/org/apache/ignite/internal/IgniteProjectionStartStopRestartSelfTest.java
index 7fa5b4b..3618c2c 100644
--- a/modules/ssh/src/test/java/org/apache/ignite/internal/IgniteProjectionStartStopRestartSelfTest.java
+++ b/modules/ssh/src/test/java/org/apache/ignite/internal/IgniteProjectionStartStopRestartSelfTest.java
@@ -131,7 +131,8 @@ public class IgniteProjectionStartStopRestartSelfTest extends GridCommonAbstract
 
                     if (joinedLatch != null)
                         joinedLatch.countDown();
-                } else if (evt.type() == EVT_NODE_LEFT) {
+                }
+                else if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) {
                     leftCnt.incrementAndGet();
 
                     if (leftLatch != null)
@@ -140,20 +141,26 @@ public class IgniteProjectionStartStopRestartSelfTest extends GridCommonAbstract
 
                 return true;
             }
-        }, EVT_NODE_JOINED, EVT_NODE_LEFT);
+        }, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED);
     }
 
     /** {@inheritDoc} */
     @Override protected void afterTest() throws Exception {
-        if (!ignite.cluster().nodes().isEmpty()) {
-            leftLatch = new CountDownLatch(ignite.cluster().nodes().size());
+        boolean wasEmpty = true;
 
-            ignite.cluster().stopNodes();
+        if (ignite != null) {
+            if (!ignite.cluster().nodes().isEmpty()) {
+                leftLatch = new CountDownLatch(ignite.cluster().nodes().size());
 
-            assert leftLatch.await(WAIT_TIMEOUT, MILLISECONDS);
-        }
+                ignite.cluster().stopNodes();
 
-        boolean wasEmpty = ignite.cluster().nodes().isEmpty();
+                assert leftLatch.await(
+                    WAIT_TIMEOUT,
+                    MILLISECONDS);
+            }
+
+            wasEmpty = ignite.cluster().nodes().isEmpty();
+        }
 
         G.stop(true);
 
@@ -163,7 +170,8 @@ public class IgniteProjectionStartStopRestartSelfTest extends GridCommonAbstract
         joinedLatch = null;
         leftLatch = null;
 
-        assert wasEmpty : "grid.isEmpty() returned false after all nodes were stopped [nodes=" + ignite.cluster().nodes() + ']';
+        assert wasEmpty : "grid.isEmpty() returned false after all nodes were stopped " +
+            "[nodes=" + ignite.cluster().nodes() + ']';
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/tools/pom.xml
----------------------------------------------------------------------
diff --git a/modules/tools/pom.xml b/modules/tools/pom.xml
index 625eeaa..2351d95 100644
--- a/modules/tools/pom.xml
+++ b/modules/tools/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-tools</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/urideploy/pom.xml
----------------------------------------------------------------------
diff --git a/modules/urideploy/pom.xml b/modules/urideploy/pom.xml
index 231a576..c6abfe5 100644
--- a/modules/urideploy/pom.xml
+++ b/modules/urideploy/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-urideploy</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>



[09/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractNodeRestartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractNodeRestartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractNodeRestartSelfTest.java
index 17d6e42..7e65f23 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractNodeRestartSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractNodeRestartSelfTest.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.processors.cache.distributed;
 
 import org.apache.ignite.*;
 import org.apache.ignite.cache.*;
-import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.spi.discovery.tcp.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
@@ -77,10 +76,10 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
     private static volatile int idx = -1;
 
     /** Preload mode. */
-    protected CacheRebalanceMode preloadMode = ASYNC;
+    protected CacheRebalanceMode rebalancMode = ASYNC;
 
     /** */
-    protected int preloadBatchSize = DFLT_BATCH_SIZE;
+    protected int rebalancBatchSize = DFLT_BATCH_SIZE;
 
     /** Number of partitions. */
     protected int partitions = DFLT_PARTITIONS;
@@ -106,6 +105,10 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
 
         disco.setIpFinder(ipFinder);
 
+        disco.setSocketTimeout(30_000);
+        disco.setAckTimeout(30_000);
+        disco.setNetworkTimeout(30_000);
+
         c.setDiscoverySpi(disco);
 
         return c;
@@ -124,8 +127,8 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
     @Override protected void beforeTest() throws Exception {
         backups = DFLT_BACKUPS;
         partitions = DFLT_PARTITIONS;
-        preloadMode = ASYNC;
-        preloadBatchSize = DFLT_BATCH_SIZE;
+        rebalancMode = ASYNC;
+        rebalancBatchSize = DFLT_BATCH_SIZE;
         nodeCnt = DFLT_NODE_CNT;
         keyCnt = DFLT_KEY_CNT;
         retries = DFLT_RETRIES;
@@ -160,7 +163,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
      * @throws Exception If failed.
      */
     public void testRestart() throws Exception {
-        preloadMode = SYNC;
+        rebalancMode = SYNC;
         partitions = 3;
         nodeCnt = 2;
         keyCnt = 10;
@@ -240,7 +243,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 2;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 30000;
 
@@ -255,7 +258,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 2;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 30000;
 
@@ -270,7 +273,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 2;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 30000;
 
@@ -285,7 +288,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 2;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 30000;
 
@@ -300,7 +303,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 4;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 60000;
 
@@ -315,7 +318,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 4;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 60000;
 
@@ -330,7 +333,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 4;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 60000;
 
@@ -345,7 +348,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 4;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 60000;
 
@@ -360,7 +363,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 6;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 90000;
 
@@ -375,7 +378,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 6;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 90000;
 
@@ -390,7 +393,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 8;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 90000;
 
@@ -405,7 +408,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 8;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 90000;
 
@@ -420,7 +423,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 10;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 90000;
 
@@ -435,7 +438,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 10;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 90000;
 
@@ -450,7 +453,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 10;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 90000;
 
@@ -465,7 +468,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
         nodeCnt = 4;
         keyCnt = 10;
         partitions = 29;
-        preloadMode = ASYNC;
+        rebalancMode = ASYNC;
 
         long duration = 90000;
 
@@ -512,7 +515,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
                                 try {
                                     cache.put(key, Integer.toString(key));
                                 }
-                                catch (TransactionRollbackException | ClusterTopologyException | CacheException ignored) {
+                                catch (IgniteException | CacheException ignored) {
                                     // It is ok if primary node leaves grid.
                                 }
 
@@ -525,7 +528,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
                         catch (Exception e) {
                             err.compareAndSet(null, e);
 
-                            error("Failed to put value in cache.", e);
+                            error("Unexpected exception in put-worker.", e);
                         }
                     }
                 }, "put-worker-" + i);
@@ -565,7 +568,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
                         catch (Exception e) {
                             err.compareAndSet(null, e);
 
-                            error("Failed to restart grid node.", e);
+                            error("Unexpected exception in restart-worker.", e);
                         }
                     }
                 }, "restart-worker-" + i);
@@ -643,12 +646,16 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
                                 int c = 0;
 
                                 try {
-                                    try (Transaction tx = ignite.transactions().txStart(txConcurrency(), REPEATABLE_READ)) {
+                                    IgniteTransactions txs = ignite.transactions();
+
+                                    try (Transaction tx = txs.txStart(txConcurrency(), REPEATABLE_READ)) {
                                         c = txCntr.incrementAndGet();
 
-                                        if (c % logFreq == 0)
-                                            info(">>> Tx iteration started [cnt=" + c + ", keys=" + keys + ", " +
-                                                "locNodeId=" + locNodeId + ']');
+                                        if (c % logFreq == 0) {
+                                            info(">>> Tx iteration started [cnt=" + c +
+                                                ", keys=" + keys +
+                                                ", locNodeId=" + locNodeId + ']');
+                                        }
 
                                         for (int key : keys) {
                                             int op = cacheOp();
@@ -664,17 +671,15 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
                                         tx.commit();
                                     }
                                 }
-                                catch (ClusterTopologyException | CacheException e) {
-                                    if (e instanceof CacheException
-                                        && !(e.getCause() instanceof ClusterTopologyException))
-                                        throw e;
-
+                                catch (IgniteException | CacheException ignored) {
                                     // It is ok if primary node leaves grid.
                                 }
 
-                                if (c % logFreq == 0)
-                                    info(">>> Tx iteration finished [cnt=" + c + ", keys=" + keys + ", " +
-                                        "locNodeId=" + locNodeId + ']');
+                                if (c % logFreq == 0) {
+                                    info(">>> Tx iteration finished [cnt=" + c +
+                                        ", keys=" + keys +
+                                        ", locNodeId=" + locNodeId + ']');
+                                }
                             }
 
                             info(">>> " + Thread.currentThread().getName() + " finished.");
@@ -682,7 +687,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
                         catch (Exception e) {
                             err.compareAndSet(null, e);
 
-                            error("Failed to put value in cache.", e);
+                            error("Unexpected exception in put-worker.", e);
                         }
                     }
                 }, "put-worker-" + i);
@@ -719,7 +724,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
                         catch (Exception e) {
                             err.compareAndSet(null, e);
 
-                            error("Failed to restart grid node.", e);
+                            error("Unexpected exception in restart-worker.", e);
                         }
                     }
                 }, "restart-worker-" + i);
@@ -812,19 +817,21 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
 
                                     tx.commit();
                                 }
-                                catch (ClusterTopologyException ignored) {
+                                catch (IgniteException | CacheException ignored) {
                                     // It is ok if primary node leaves grid.
                                 }
 
-                                if (c % logFreq == 0)
-                                    info(">>> Tx iteration finished [cnt=" + c + ", keys=" + keys + ", " +
+                                if (c % logFreq == 0) {
+                                    info(">>> Tx iteration finished [cnt=" + c +
+                                        ", keys=" + keys + ", " +
                                         "locNodeId=" + locNodeId + ']');
+                                }
                             }
                         }
                         catch (Exception e) {
                             err.compareAndSet(null, e);
 
-                            error("Failed to put value in cache.", e);
+                            error("Unexpected exception in put-worker.", e);
                         }
                     }
                 }, "put-worker-" + i);
@@ -859,7 +866,7 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
                         catch (Exception e) {
                             err.compareAndSet(null, e);
 
-                            error("Failed to restart grid node.", e);
+                            error("Unexpected exception in restart-worker.", e);
                         }
                     }
                 }, "restart-worker-" + i);
@@ -893,10 +900,12 @@ public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbs
      * @param attempt Attempt.
      */
     private void printFailureDetails(IgniteCache<Integer, String> c, int key, int attempt) {
+        Ignite ignite = c.unwrap(Ignite.class);
+
         error("*** Failure details ***");
         error("Key: " + key);
-        error("Partition: " + c.getConfiguration(CacheConfiguration.class).getAffinity().partition(key));
+        error("Partition: " + ignite.affinity(c.getName()).partition(key));
         error("Attempt: " + attempt);
-        error("Node: " + c.unwrap(Ignite.class).cluster().localNode().id());
+        error("Node: " + ignite.cluster().localNode().id());
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLoadingConcurrentGridStartTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLoadingConcurrentGridStartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLoadingConcurrentGridStartTest.java
deleted file mode 100644
index 2f9bb96..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLoadingConcurrentGridStartTest.java
+++ /dev/null
@@ -1,154 +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.distributed;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cache.*;
-import org.apache.ignite.cache.store.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.internal.*;
-import org.apache.ignite.lang.*;
-import org.apache.ignite.testframework.*;
-import org.apache.ignite.testframework.junits.common.*;
-import org.jetbrains.annotations.*;
-
-import javax.cache.*;
-import javax.cache.configuration.*;
-import javax.cache.integration.*;
-import java.util.concurrent.*;
-
-import static org.apache.ignite.cache.CacheMode.*;
-
-/**
- * Tests for cache data loading during simultaneous grids start.
- */
-public class GridCacheLoadingConcurrentGridStartTest extends GridCommonAbstractTest {
-    /** Grids count */
-    private static int GRIDS_CNT = 5;
-
-    /** Keys count */
-    private static int KEYS_CNT = 1_000_000;
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        CacheConfiguration ccfg = new CacheConfiguration();
-
-        ccfg.setCacheMode(PARTITIONED);
-
-        ccfg.setBackups(1);
-
-        CacheStore<Integer, String> store = new CacheStoreAdapter<Integer, String>() {
-            @Override public void loadCache(IgniteBiInClosure<Integer, String> f, Object... args) {
-                for (int i = 0; i < KEYS_CNT; i++)
-                    f.apply(i, Integer.toString(i));
-            }
-
-            @Nullable @Override public String load(Integer i) throws CacheLoaderException {
-                return null;
-            }
-
-            @Override public void write(Cache.Entry<? extends Integer, ? extends String> entry) throws CacheWriterException {
-                // No-op.
-            }
-
-            @Override public void delete(Object o) throws CacheWriterException {
-                // No-op.
-            }
-        };
-
-        ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory(store));
-
-        cfg.setCacheConfiguration(ccfg);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * @throws Exception if failed
-     */
-    public void testLoadCacheWithDataStreamer() throws Exception {
-        IgniteInClosure<Ignite> f = new IgniteInClosure<Ignite>() {
-            @Override public void apply(Ignite grid) {
-                try (IgniteDataStreamer<Integer, String> dataStreamer = grid.dataStreamer(null)) {
-                    for (int i = 0; i < KEYS_CNT; i++)
-                        dataStreamer.addData(i, Integer.toString(i));
-                }
-            }
-        };
-
-        loadCache(f);
-    }
-
-    /**
-     * @throws Exception if failed
-     */
-    public void testLoadCacheFromStore() throws Exception {
-        loadCache(new IgniteInClosure<Ignite>() {
-            @Override public void apply(Ignite grid) {
-                grid.cache(null).loadCache(null);
-            }
-        });
-    }
-
-    /**
-     * Loads cache using closure and asserts cache size.
-     *
-     * @param f cache loading closure
-     * @throws Exception if failed
-     */
-    private void loadCache(IgniteInClosure<Ignite> f) throws Exception {
-        Ignite g0 = startGrid(0);
-
-        IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Ignite>() {
-            @Override public Ignite call() throws Exception {
-                return startGridsMultiThreaded(1, GRIDS_CNT - 1);
-            }
-        });
-
-        try {
-            f.apply(g0);
-        }
-        finally {
-            fut.get();
-        }
-
-        assertCacheSize();
-    }
-
-    /** Asserts cache size. */
-    private void assertCacheSize() {
-        IgniteCache<Integer, String> cache = grid(0).cache(null);
-
-        assertEquals(KEYS_CNT, cache.size(CachePeekMode.PRIMARY));
-
-        int total = 0;
-
-        for (int i = 0; i < GRIDS_CNT; i++)
-            total += grid(i).cache(null).localSize(CachePeekMode.PRIMARY);
-
-        assertEquals(KEYS_CNT, total);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
index ab0f7d0..2fe76e7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
@@ -501,8 +501,6 @@ public abstract class GridCacheLockAbstractTest extends GridCommonAbstractTest {
      * @throws Throwable If failed.
      */
     public void testLockReentrancy() throws Throwable {
-        fail("https://issues.apache.org/jira/browse/IGNITE-835");
-
         Affinity<Integer> aff = ignite1.affinity(null);
 
         for (int i = 10; i < 100; i++) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxGetAfterStopTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxGetAfterStopTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxGetAfterStopTest.java
new file mode 100644
index 0000000..469f513
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxGetAfterStopTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.distributed;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.transactions.*;
+import org.jetbrains.annotations.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ *
+ */
+public class IgniteTxGetAfterStopTest extends IgniteCacheAbstractTest {
+    /** */
+    private CacheMode cacheMode;
+
+    /** */
+    private NearCacheConfiguration nearCfg;
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return cacheMode;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return nearCfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReplicated() throws Exception {
+        getAfterStop(REPLICATED, null);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPartitioned() throws Exception {
+        getAfterStop(PARTITIONED, new NearCacheConfiguration());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPartitionedNearDisabled() throws Exception {
+        getAfterStop(PARTITIONED, null);
+    }
+
+    /**
+     * @param cacheMode Cache mode.
+     * @param nearCfg Near cache configuration.
+     * @throws Exception If failed.
+     */
+    private void getAfterStop(CacheMode cacheMode, @Nullable NearCacheConfiguration nearCfg) throws Exception {
+        this.cacheMode = cacheMode;
+        this.nearCfg = nearCfg;
+
+        startGrids();
+
+        IgniteCache<Integer, Integer> cache0 = jcache(0);
+        IgniteCache<Integer, Integer> cache1 = jcache(1);
+
+        Integer key0 = primaryKey(cache0);
+        Integer key1 = primaryKey(cache1);
+
+        try (Transaction tx = ignite(0).transactions().txStart()) {
+            log.info("Put: " + key0);
+
+            cache0.put(key0, key0);
+
+            log.info("Stop node.");
+
+            stopGrid(3);
+
+            log.info("Get: " + key1);
+
+            cache0.get(key1);
+
+            log.info("Commit.");
+
+            tx.commit();
+        }
+
+        assertEquals(key0, cache0.get(key0));
+        assertNull(cache1.get(key1));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxOriginatingNodeFailureAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxOriginatingNodeFailureAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxOriginatingNodeFailureAbstractSelfTest.java
index 00bd43f..d664aa8 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxOriginatingNodeFailureAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteTxOriginatingNodeFailureAbstractSelfTest.java
@@ -156,7 +156,7 @@ public abstract class IgniteTxOriginatingNodeFailureAbstractSelfTest extends Gri
 
                 TransactionProxyImpl tx = (TransactionProxyImpl)txIgniteNode.transactions().txStart();
 
-                IgniteInternalTx txEx = GridTestUtils.getFieldValue(tx, "tx");
+                IgniteInternalTx txEx = tx.tx();
 
                 assertTrue(txEx.optimistic());
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadSelfTest.java
index f04b87f..5b63c6a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtPreloadSelfTest.java
@@ -266,7 +266,7 @@ public class GridCacheDhtPreloadSelfTest extends GridCommonAbstractTest {
                         ClusterNode node = evt.discoveryNode();
 
                         return evt.type() == EVT_CACHE_REBALANCE_STOPPED && node.id().equals(nodeId) &&
-                            evt.discoveryEventType() == EVT_NODE_LEFT;
+                            (evt.discoveryEventType() == EVT_NODE_LEFT || evt.discoveryEventType() == EVT_NODE_FAILED);
                     }
                 }, EVT_CACHE_REBALANCE_STOPPED));
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledAtomicOffHeapTieredMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledAtomicOffHeapTieredMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledAtomicOffHeapTieredMultiNodeFullApiSelfTest.java
new file mode 100644
index 0000000..686cc31
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledAtomicOffHeapTieredMultiNodeFullApiSelfTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+
+/**
+ * Tests colocated cache with off-heap tiered mode.
+ */
+public class GridCachePartitionedNearDisabledAtomicOffHeapTieredMultiNodeFullApiSelfTest extends
+    GridCachePartitionedNearDisabledOffHeapTieredMultiNodeFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean txEnabled() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean lockingEnabled() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledLockSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledLockSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledLockSelfTest.java
new file mode 100644
index 0000000..69c7909
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledLockSelfTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
+
+/**
+ *
+ */
+public class GridCachePartitionedNearDisabledLockSelfTest extends GridCachePartitionedLockSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration cacheConfiguration() {
+        CacheConfiguration ccfg = super.cacheConfiguration();
+
+        assertNotNull(ccfg.getNearConfiguration());
+
+        ccfg.setNearConfiguration(null);
+
+        return ccfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean isPartitioned() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testLockReentrancy() throws Throwable {
+        fail("https://issues.apache.org/jira/browse/IGNITE-835");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapFullApiSelfTest.java
index c3a69e2..2dd07ff 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapFullApiSelfTest.java
@@ -17,13 +17,17 @@
 
 package org.apache.ignite.internal.processors.cache.distributed.dht;
 
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
 /**
  * Tests colocated cache with values being stored off-heap.
  */
 public class GridCachePartitionedNearDisabledOffHeapFullApiSelfTest extends
     GridCachePartitionedNearDisabledFullApiSelfTest {
     /** {@inheritDoc} */
-    @Override protected boolean offHeapValues() {
-        return true;
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_VALUES;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapMultiNodeFullApiSelfTest.java
index 62e4452..216832c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapMultiNodeFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapMultiNodeFullApiSelfTest.java
@@ -17,13 +17,17 @@
 
 package org.apache.ignite.internal.processors.cache.distributed.dht;
 
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
 /**
  * Tests colocated cache with values being stored off-heap.
  */
 public class GridCachePartitionedNearDisabledOffHeapMultiNodeFullApiSelfTest
     extends GridCachePartitionedNearDisabledMultiNodeFullApiSelfTest {
     /** {@inheritDoc} */
-    @Override protected boolean offHeapValues() {
-        return true;
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_VALUES;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredAtomicFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredAtomicFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredAtomicFullApiSelfTest.java
new file mode 100644
index 0000000..875a913
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredAtomicFullApiSelfTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests colocated cache with off-heap tiered mode.
+ */
+public class GridCachePartitionedNearDisabledOffHeapTieredAtomicFullApiSelfTest extends
+    GridCachePartitionedFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean txEnabled() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean lockingEnabled() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredFullApiSelfTest.java
new file mode 100644
index 0000000..bab26f7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredFullApiSelfTest.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.dht;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests colocated cache with off-heap tiered mode.
+ */
+public class GridCachePartitionedNearDisabledOffHeapTieredFullApiSelfTest extends
+    GridCachePartitionedNearDisabledOffHeapFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredMultiNodeFullApiSelfTest.java
new file mode 100644
index 0000000..022f26b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledOffHeapTieredMultiNodeFullApiSelfTest.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.dht;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests colocated cache with off-heap tiered mode.
+ */
+public class GridCachePartitionedNearDisabledOffHeapTieredMultiNodeFullApiSelfTest extends
+    GridCachePartitionedNearDisabledOffHeapMultiNodeFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedNearDisabledPrimaryNodeFailureRecoveryTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedNearDisabledPrimaryNodeFailureRecoveryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedNearDisabledPrimaryNodeFailureRecoveryTest.java
new file mode 100644
index 0000000..62d9b79
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedNearDisabledPrimaryNodeFailureRecoveryTest.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.dht;
+
+import org.apache.ignite.configuration.*;
+
+/**
+ *
+ */
+public class IgniteCachePartitionedNearDisabledPrimaryNodeFailureRecoveryTest
+    extends IgniteCachePrimaryNodeFailureRecoveryAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedPrimaryNodeFailureRecoveryTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedPrimaryNodeFailureRecoveryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedPrimaryNodeFailureRecoveryTest.java
new file mode 100644
index 0000000..a40c989
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedPrimaryNodeFailureRecoveryTest.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.dht;
+
+import org.apache.ignite.configuration.*;
+
+/**
+ *
+ */
+public class IgniteCachePartitionedPrimaryNodeFailureRecoveryTest
+    extends IgniteCachePrimaryNodeFailureRecoveryAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return new NearCacheConfiguration();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedTwoBackupsPrimaryNodeFailureRecoveryTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedTwoBackupsPrimaryNodeFailureRecoveryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedTwoBackupsPrimaryNodeFailureRecoveryTest.java
new file mode 100644
index 0000000..70eef1d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedTwoBackupsPrimaryNodeFailureRecoveryTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.configuration.*;
+
+/**
+ *
+ */
+public class IgniteCachePartitionedTwoBackupsPrimaryNodeFailureRecoveryTest
+    extends IgniteCachePartitionedPrimaryNodeFailureRecoveryTest {
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
+        CacheConfiguration ccfg = super.cacheConfiguration(gridName);
+
+        assertEquals(1, ccfg.getBackups());
+
+        ccfg.setBackups(2);
+
+        return ccfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePrimaryNodeFailureRecoveryAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePrimaryNodeFailureRecoveryAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePrimaryNodeFailureRecoveryAbstractTest.java
new file mode 100644
index 0000000..f996877
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePrimaryNodeFailureRecoveryAbstractTest.java
@@ -0,0 +1,533 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.affinity.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.managers.communication.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
+import org.apache.ignite.internal.processors.cache.transactions.*;
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.spi.*;
+import org.apache.ignite.spi.communication.tcp.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.transactions.*;
+
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.transactions.TransactionConcurrency.*;
+import static org.apache.ignite.transactions.TransactionIsolation.*;
+import static org.apache.ignite.transactions.TransactionState.*;
+
+/**
+ *
+ */
+public abstract class IgniteCachePrimaryNodeFailureRecoveryAbstractTest extends IgniteCacheAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCommunicationSpi(new TestCommunicationSpi());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        startGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        // No-op
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimisticPrimaryNodeFailureRecovery1() throws Exception {
+        primaryNodeFailure(false, false, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimisticPrimaryNodeFailureRecovery2() throws Exception {
+        primaryNodeFailure(true, false, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimisticPrimaryNodeFailureRollback1() throws Exception {
+        primaryNodeFailure(false, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimisticPrimaryNodeFailureRollback2() throws Exception {
+        primaryNodeFailure(true, true, true);
+    }
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPessimisticPrimaryNodeFailureRecovery1() throws Exception {
+        primaryNodeFailure(false, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPessimisticPrimaryNodeFailureRecovery2() throws Exception {
+        primaryNodeFailure(true, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPessimisticPrimaryNodeFailureRollback1() throws Exception {
+        primaryNodeFailure(false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPessimisticPrimaryNodeFailureRollback2() throws Exception {
+        primaryNodeFailure(true, true, false);
+    }
+
+    /**
+     * @param locBackupKey If {@code true} uses one key which is backup for originating node.
+     * @param rollback If {@code true} tests rollback after primary node failure.
+     * @param optimistic If {@code true} tests optimistic transaction.
+     * @throws Exception If failed.
+     */
+    private void primaryNodeFailure(boolean locBackupKey, final boolean rollback, boolean optimistic) throws Exception {
+        IgniteCache<Integer, Integer> cache0 = jcache(0);
+        IgniteCache<Integer, Integer> cache2 = jcache(2);
+
+        Affinity<Integer> aff = ignite(0).affinity(null);
+
+        Integer key0 = null;
+
+        for (int key = 0; key < 10_000; key++) {
+            if (aff.isPrimary(ignite(1).cluster().localNode(), key)) {
+                if (locBackupKey == aff.isBackup(ignite(0).cluster().localNode(), key)) {
+                    key0 = key;
+
+                    break;
+                }
+            }
+        }
+
+        assertNotNull(key0);
+
+        final Integer key1 = key0;
+        final Integer key2 = primaryKey(cache2);
+
+        final Collection<ClusterNode> key1Nodes = aff.mapKeyToPrimaryAndBackups(key1);
+        final Collection<ClusterNode> key2Nodes = aff.mapKeyToPrimaryAndBackups(key2);
+
+        TestCommunicationSpi commSpi = (TestCommunicationSpi)ignite(0).configuration().getCommunicationSpi();
+
+        IgniteTransactions txs = ignite(0).transactions();
+
+        try (Transaction tx = txs.txStart(optimistic ? OPTIMISTIC : PESSIMISTIC, REPEATABLE_READ)) {
+            log.info("Put key1: " + key1);
+
+            cache0.put(key1, key1);
+
+            log.info("Put key2: " + key2);
+
+            cache0.put(key2, key2);
+
+            log.info("Start prepare.");
+
+            IgniteInternalTx txEx = ((TransactionProxyImpl)tx).tx();
+
+            commSpi.blockMessages(ignite(2).cluster().localNode().id()); // Do not allow to finish prepare for key2.
+
+            IgniteInternalFuture<?> prepFut = txEx.prepareAsync();
+
+            waitPrepared(ignite(1));
+
+            log.info("Stop one primary node.");
+
+            stopGrid(1);
+
+            U.sleep(1000); // Wait some time to catch possible issues in tx recovery.
+
+            commSpi.stopBlock();
+
+            prepFut.get(10_000);
+
+            if (rollback) {
+                log.info("Rollback.");
+
+                tx.rollback();
+            }
+            else {
+                log.info("Commit.");
+
+                tx.commit();
+            }
+        }
+
+        GridTestUtils.waitForCondition(new GridAbsPredicate() {
+            @Override public boolean apply() {
+                try {
+                    checkKey(key1, rollback ? null : key1Nodes);
+                    checkKey(key2, rollback ? null : key2Nodes);
+
+                    return true;
+                }
+                catch (AssertionError e) {
+                    log.info("Check failed: " + e);
+
+                    return false;
+                }
+            }
+        }, 5000);
+
+        checkKey(key1, rollback ? null : key1Nodes);
+        checkKey(key2, rollback ? null : key2Nodes);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimisticPrimaryAndOriginatingNodeFailureRecovery1() throws Exception {
+        primaryAndOriginatingNodeFailure(false, false, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimisticPrimaryAndOriginatingNodeFailureRecovery2() throws Exception {
+        primaryAndOriginatingNodeFailure(true, false, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimisticPrimaryAndOriginatingNodeFailureRollback1() throws Exception {
+        primaryAndOriginatingNodeFailure(false, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimisticPrimaryAndOriginatingNodeFailureRollback2() throws Exception {
+        primaryAndOriginatingNodeFailure(true, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPessimisticPrimaryAndOriginatingNodeFailureRecovery1() throws Exception {
+        primaryAndOriginatingNodeFailure(false, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPessimisticPrimaryAndOriginatingNodeFailureRecovery2() throws Exception {
+        primaryAndOriginatingNodeFailure(true, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPessimisticPrimaryAndOriginatingNodeFailureRollback1() throws Exception {
+        primaryAndOriginatingNodeFailure(false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPessimisticPrimaryAndOriginatingNodeFailureRollback2() throws Exception {
+        primaryAndOriginatingNodeFailure(true, true, false);
+    }
+
+    /**
+     * @param locBackupKey If {@code true} uses one key which is backup for originating node.
+     * @param rollback If {@code true} tests rollback after primary node failure.
+     * @param optimistic If {@code true} tests optimistic transaction.
+     * @throws Exception If failed.
+     */
+    private void primaryAndOriginatingNodeFailure(final boolean locBackupKey,
+        final boolean rollback,
+        boolean optimistic)
+        throws Exception
+    {
+        IgniteCache<Integer, Integer> cache0 = jcache(0);
+        IgniteCache<Integer, Integer> cache2 = jcache(2);
+
+        Affinity<Integer> aff = ignite(0).affinity(null);
+
+        Integer key0 = null;
+
+        for (int key = 0; key < 10_000; key++) {
+            if (aff.isPrimary(ignite(1).cluster().localNode(), key)) {
+                if (locBackupKey == aff.isBackup(ignite(0).cluster().localNode(), key)) {
+                    key0 = key;
+
+                    break;
+                }
+            }
+        }
+
+        assertNotNull(key0);
+
+        final Integer key1 = key0;
+        final Integer key2 = primaryKey(cache2);
+
+        int backups = cache0.getConfiguration(CacheConfiguration.class).getBackups();
+
+        final Collection<ClusterNode> key1Nodes =
+            (locBackupKey && backups < 2) ? null : aff.mapKeyToPrimaryAndBackups(key1);
+        final Collection<ClusterNode> key2Nodes = aff.mapKeyToPrimaryAndBackups(key2);
+
+        TestCommunicationSpi commSpi = (TestCommunicationSpi)ignite(0).configuration().getCommunicationSpi();
+
+        IgniteTransactions txs = ignite(0).transactions();
+
+        Transaction tx = txs.txStart(optimistic ? OPTIMISTIC : PESSIMISTIC, REPEATABLE_READ);
+
+        log.info("Put key1: " + key1);
+
+        cache0.put(key1, key1);
+
+        log.info("Put key2: " + key2);
+
+        cache0.put(key2, key2);
+
+        log.info("Start prepare.");
+
+        IgniteInternalTx txEx = ((TransactionProxyImpl)tx).tx();
+
+        commSpi.blockMessages(ignite(2).cluster().localNode().id()); // Do not allow to finish prepare for key2.
+
+        IgniteInternalFuture<?> prepFut = txEx.prepareAsync();
+
+        waitPrepared(ignite(1));
+
+        log.info("Stop one primary node.");
+
+        stopGrid(1);
+
+        U.sleep(1000); // Wait some time to catch possible issues in tx recovery.
+
+        if (!rollback) {
+            commSpi.stopBlock();
+
+            prepFut.get(10_000);
+        }
+
+        log.info("Stop originating node.");
+
+        stopGrid(0);
+
+        GridTestUtils.waitForCondition(new GridAbsPredicate() {
+            @Override public boolean apply() {
+                try {
+                    checkKey(key1, rollback ? null : key1Nodes);
+                    checkKey(key2, rollback ? null : key2Nodes);
+
+                    return true;
+                } catch (AssertionError e) {
+                    log.info("Check failed: " + e);
+
+                    return false;
+                }
+            }
+        }, 5000);
+
+        checkKey(key1, rollback ? null : key1Nodes);
+        checkKey(key2, rollback ? null : key2Nodes);
+    }
+
+    /**
+     * @param key Key.
+     * @param keyNodes Key nodes.
+     */
+    private void checkKey(Integer key, Collection<ClusterNode> keyNodes) {
+        if (keyNodes == null) {
+            for (Ignite ignite : G.allGrids()) {
+                IgniteCache<Integer, Integer> cache = ignite.cache(null);
+
+                assertNull("Unexpected value for: " + ignite.name(), cache.localPeek(key));
+            }
+
+            for (Ignite ignite : G.allGrids()) {
+                IgniteCache<Integer, Integer> cache = ignite.cache(null);
+
+                assertNull("Unexpected value for: " + ignite.name(), cache.get(key));
+            }
+        }
+        else {
+            boolean found = false;
+
+            for (ClusterNode node : keyNodes) {
+                try {
+                    Ignite ignite = grid(node);
+
+                    found = true;
+
+                    IgniteCache<Integer, Integer> cache = ignite.cache(null);
+
+                    assertEquals("Unexpected value for: " + ignite.name(), key, key);
+                }
+                catch (IgniteIllegalStateException ignore) {
+                    // No-op.
+                }
+            }
+
+            assertTrue("Failed to find key node.", found);
+
+            for (Ignite ignite : G.allGrids()) {
+                IgniteCache<Integer, Integer> cache = ignite.cache(null);
+
+                assertEquals("Unexpected value for: " + ignite.name(), key, cache.get(key));
+            }
+        }
+    }
+
+    /**
+     * @param ignite Node.
+     * @throws Exception If failed.
+     */
+    private void waitPrepared(Ignite ignite) throws Exception {
+        final IgniteTxManager tm = ((IgniteKernal)ignite).context().cache().context().tm();
+
+        boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
+            @Override public boolean apply() {
+                GridDhtTxLocal locTx = null;
+
+                for (IgniteInternalTx tx : tm.txs()) {
+                    if (tx instanceof GridDhtTxLocal) {
+                        assertNull("Only one tx is expected.", locTx);
+
+                        locTx = (GridDhtTxLocal)tx;
+                    }
+                }
+
+                log.info("Wait for tx, state: " + (locTx != null ? locTx.state() : null));
+
+                return locTx != null && locTx.state() == PREPARED;
+            }
+        }, 5000);
+
+        assertTrue("Failed to wait for tx.", wait);
+    }
+
+    /**
+     *
+     */
+    private static class TestCommunicationSpi extends TcpCommunicationSpi {
+        /** Logger. */
+        @LoggerResource
+        private IgniteLogger log;
+
+        /** */
+        private UUID blockNodeId;
+
+        /** */
+        private List<T2<ClusterNode, GridIoMessage>> blockedMsgs = new ArrayList<>();
+
+        /** {@inheritDoc} */
+        @Override public void sendMessage(ClusterNode node, Message msg) throws IgniteSpiException {
+            if (msg instanceof GridIoMessage) {
+                Object msg0 = ((GridIoMessage)msg).message();
+
+                if (msg0 instanceof GridNearTxPrepareRequest) {
+                    synchronized (this) {
+                        if (blockNodeId != null && blockNodeId.equals(node.id())) {
+                            log.info("Block message: " + msg0);
+
+                            blockedMsgs.add(new T2<>(node, (GridIoMessage)msg));
+
+                            return;
+                        }
+                    }
+                }
+            }
+
+            super.sendMessage(node, msg);
+        }
+
+        /**
+         * @param nodeId Node ID.
+         */
+        void blockMessages(UUID nodeId) {
+            blockNodeId = nodeId;
+        }
+
+        /**
+         *
+         */
+        void stopBlock() {
+            synchronized (this) {
+                blockNodeId = null;
+
+                for (T2<ClusterNode, GridIoMessage> msg : blockedMsgs) {
+                    log.info("Send blocked message: " + msg.get2().message());
+
+                    super.sendMessage(msg.get1(), msg.get2());
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridCacheAtomicReplicatedFailoverSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridCacheAtomicReplicatedFailoverSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridCacheAtomicReplicatedFailoverSelfTest.java
index 0a2781b..1e57c09 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridCacheAtomicReplicatedFailoverSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridCacheAtomicReplicatedFailoverSelfTest.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.cache.distributed.dht.atomic;
 
 import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
 
 import static org.apache.ignite.cache.CacheMode.*;
 
@@ -29,4 +30,9 @@ public class GridCacheAtomicReplicatedFailoverSelfTest extends GridCacheAtomicFa
     @Override protected CacheMode cacheMode() {
         return REPLICATED;
     }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicOffHeapTieredFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicOffHeapTieredFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicOffHeapTieredFullApiSelfTest.java
new file mode 100644
index 0000000..b0d13e0
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicOffHeapTieredFullApiSelfTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.distributed.near;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests partitioned cache with off-heap tiered mode.
+ */
+public class GridCacheAtomicOffHeapTieredFullApiSelfTest extends GridCacheAtomicOffHeapFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicOffHeapTieredMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicOffHeapTieredMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicOffHeapTieredMultiNodeFullApiSelfTest.java
new file mode 100644
index 0000000..b3adf14
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicOffHeapTieredMultiNodeFullApiSelfTest.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.near;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests partitioned cache with off-heap tiered mode.
+ */
+public class GridCacheAtomicOffHeapTieredMultiNodeFullApiSelfTest extends
+    GridCacheAtomicOffHeapMultiNodeFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPrimaryWriteOrderOffHeapTieredFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPrimaryWriteOrderOffHeapTieredFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPrimaryWriteOrderOffHeapTieredFullApiSelfTest.java
new file mode 100644
index 0000000..41e98b2
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPrimaryWriteOrderOffHeapTieredFullApiSelfTest.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.near;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests partitioned cache with off-heap tiered mode.
+ */
+public class GridCacheAtomicPrimaryWriteOrderOffHeapTieredFullApiSelfTest extends
+    GridCacheAtomicPrimaryWriteOrderOffHeapFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPrimaryWrityOrderOffHeapTieredMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPrimaryWrityOrderOffHeapTieredMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPrimaryWrityOrderOffHeapTieredMultiNodeFullApiSelfTest.java
new file mode 100644
index 0000000..f29cdd0
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPrimaryWrityOrderOffHeapTieredMultiNodeFullApiSelfTest.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.near;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests partitioned cache with off-heap tiered mode.
+ */
+public class GridCacheAtomicPrimaryWrityOrderOffHeapTieredMultiNodeFullApiSelfTest extends
+    GridCacheAtomicPrimaryWrityOrderOffHeapMultiNodeFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
index caacc2b..84594a2 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
@@ -27,7 +27,6 @@ import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.lang.*;
 
-import javax.cache.*;
 import java.util.*;
 import java.util.concurrent.atomic.*;
 
@@ -138,12 +137,12 @@ public class GridCachePartitionedMultiNodeFullApiSelfTest extends GridCacheParti
 
         int size = 10;
 
-        IgniteCache<Object, Object> prj0 = grid(0).cache(null);
+        IgniteCache<Object, Object> chache0 = grid(0).cache(null);
 
         for (int i = 0; i < size; i++) {
             info("Putting value [i=" + i + ']');
 
-            prj0.put(i, i);
+            chache0.put(i, i);
 
             info("Finished putting value [i=" + i + ']');
         }
@@ -156,26 +155,30 @@ public class GridCachePartitionedMultiNodeFullApiSelfTest extends GridCacheParti
 
             for (int k = 0; k < size; k++) {
                 if (affinity(cache).isPrimaryOrBackup(node, k))
-                    assertEquals("Check failed for node: " + node.id(), k, cache.localPeek(k, ONHEAP));
+                    assertEquals("Check failed for node: " + node.id(), k,
+                        cache.localPeek(k, CachePeekMode.ONHEAP, CachePeekMode.OFFHEAP));
             }
         }
 
         for (int i = 0; i < size; i++) {
             info("Putting value 2 [i=" + i + ']');
 
-            assertEquals(i, prj0.getAndPutIfAbsent(i, i * i));
+            assertEquals(i, chache0.getAndPutIfAbsent(i, i * i));
 
             info("Finished putting value 2 [i=" + i + ']');
         }
 
         for (int i = 0; i < size; i++)
-            assertEquals(i, prj0.get(i));
+            assertEquals(i, chache0.get(i));
     }
 
     /**
      * @throws Exception If failed.
      */
     public void testUnswapShort() throws Exception {
+        if (memoryMode() == CacheMemoryMode.OFFHEAP_TIERED)
+            return;
+
         final AtomicInteger swapEvts = new AtomicInteger(0);
         final AtomicInteger unswapEvts = new AtomicInteger(0);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedNodeRestartTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedNodeRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedNodeRestartTest.java
index 8a2b19a..2096836 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedNodeRestartTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedNodeRestartTest.java
@@ -43,8 +43,8 @@ public class GridCachePartitionedNodeRestartTest extends GridCacheAbstractNodeRe
         cc.setWriteSynchronizationMode(FULL_ASYNC);
         cc.setNearConfiguration(null);
         cc.setStartSize(20);
-        cc.setRebalanceMode(preloadMode);
-        cc.setRebalanceBatchSize(preloadBatchSize);
+        cc.setRebalanceMode(rebalancMode);
+        cc.setRebalanceBatchSize(rebalancBatchSize);
         cc.setAffinity(new RendezvousAffinityFunction(false, partitions));
         cc.setBackups(backups);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapFullApiSelfTest.java
index d77efcf..78c8ab7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapFullApiSelfTest.java
@@ -17,12 +17,16 @@
 
 package org.apache.ignite.internal.processors.cache.distributed.near;
 
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
 /**
  * Tests partitioned cache with values being stored off-heap.
  */
 public class GridCachePartitionedOffHeapFullApiSelfTest extends GridCachePartitionedFullApiSelfTest {
     /** {@inheritDoc} */
-    @Override protected boolean offHeapValues() {
-        return true;
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_VALUES;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapMultiNodeFullApiSelfTest.java
index c7a04fc..4724d9d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapMultiNodeFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapMultiNodeFullApiSelfTest.java
@@ -17,12 +17,16 @@
 
 package org.apache.ignite.internal.processors.cache.distributed.near;
 
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
 /**
  * Tests partitioned cache with values being stored off-heap.
  */
 public class GridCachePartitionedOffHeapMultiNodeFullApiSelfTest extends GridCachePartitionedMultiNodeFullApiSelfTest {
     /** {@inheritDoc} */
-    @Override protected boolean offHeapValues() {
-        return true;
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_VALUES;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredFullApiSelfTest.java
new file mode 100644
index 0000000..365e9aa
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredFullApiSelfTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.distributed.near;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests partitioned cache with off-heap tiered mode.
+ */
+public class GridCachePartitionedOffHeapTieredFullApiSelfTest extends GridCachePartitionedOffHeapFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}
\ No newline at end of file


[24/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
ignite-545: merge from ignite-sprint-6


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

Branch: refs/heads/ignite-545
Commit: 96f0956d64965ae042795eb94310bcffc5da129c
Parents: aa1fbf6
Author: Denis Magda <dm...@gridgain.com>
Authored: Tue Jun 9 09:32:27 2015 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue Jun 9 09:32:27 2015 +0300

----------------------------------------------------------------------
 .gitignore                                      |    3 +-
 DEVNOTES.txt                                    |   41 +-
 LICENSE                                         |  238 +
 LICENSE.txt                                     |  238 -
 NOTICE                                          |   12 +
 NOTICE.txt                                      |   12 -
 assembly/release-base.xml                       |   10 +-
 assembly/release-schema-import.xml              |   50 +
 bin/ignite-schema-import.bat                    |    2 +-
 bin/ignite-schema-import.sh                     |    2 +-
 bin/ignite.bat                                  |    2 +-
 bin/ignite.sh                                   |    2 +-
 bin/ignitevisorcmd.bat                          |    2 +-
 bin/ignitevisorcmd.sh                           |    2 +-
 bin/include/build-classpath.bat                 |   46 +
 bin/include/build-classpath.sh                  |   71 +
 bin/include/functions.sh                        |    2 +-
 bin/include/target-classpath.bat                |   46 -
 bin/include/target-classpath.sh                 |   71 -
 dev-tools/.gitignore                            |    2 +
 dev-tools/build.gradle                          |   54 +
 .../gradle/wrapper/gradle-wrapper.properties    |   20 +
 dev-tools/gradlew                               |  233 +
 dev-tools/slurp.sh                              |   76 +
 dev-tools/src/main/groovy/jiraslurp.groovy      |  544 ++
 examples/pom.xml                                |    2 +-
 .../streaming/StreamTransformerExample.java     |    4 +-
 .../streaming/StreamVisitorExample.java         |    4 +-
 .../ignite/examples/streaming/package-info.java |    1 -
 .../streaming/wordcount/CacheConfig.java        |    7 +-
 .../streaming/wordcount/QueryWords.java         |   12 +-
 .../streaming/wordcount/StreamWords.java        |   12 +-
 .../streaming/wordcount/package-info.java       |    1 -
 .../socket/WordsSocketStreamerClient.java       |   82 +
 .../socket/WordsSocketStreamerServer.java       |  124 +
 .../wordcount/socket/package-info.java          |   21 +
 modules/aop/pom.xml                             |    2 +-
 modules/aws/pom.xml                             |    2 +-
 .../config/grid-client-config.properties        |   50 +-
 modules/clients/pom.xml                         |    2 +-
 .../ClientPropertiesConfigurationSelfTest.java  |   12 +-
 .../ClientAbstractConnectivitySelfTest.java     |   14 +
 modules/cloud/pom.xml                           |    8 +-
 .../cloud/TcpDiscoveryCloudIpFinder.java        |   25 +-
 .../TcpDiscoveryCloudIpFinderSelfTest.java      |    5 +-
 modules/codegen/pom.xml                         |    2 +-
 .../ignite/codegen/MessageCodeGenerator.java    |   30 +-
 modules/core/pom.xml                            |    2 +-
 modules/core/src/main/java/META-INF/LICENSE     |  238 +
 modules/core/src/main/java/META-INF/NOTICE      |   12 +
 .../src/main/java/org/apache/ignite/Ignite.java |    8 +-
 .../java/org/apache/ignite/IgniteCache.java     |    5 +
 .../org/apache/ignite/IgniteJdbcDriver.java     |   81 +-
 .../java/org/apache/ignite/IgniteServices.java  |    5 +-
 .../configuration/CacheConfiguration.java       |  259 +-
 .../configuration/IgniteConfiguration.java      |  344 +-
 .../ignite/internal/GridDirectCollection.java   |    3 +
 .../internal/GridEventConsumeHandler.java       |   26 +
 .../ignite/internal/GridUpdateNotifier.java     |   66 +-
 .../ignite/internal/IgniteComponentType.java    |   36 +-
 .../apache/ignite/internal/IgniteKernal.java    |  113 +-
 .../org/apache/ignite/internal/IgnitionEx.java  |  151 +-
 .../client/GridClientConfiguration.java         |    2 +-
 .../internal/direct/DirectByteBufferStream.java |    4 +-
 .../interop/InteropAwareEventFilter.java        |   37 +
 .../internal/interop/InteropBootstrap.java      |   34 +
 .../interop/InteropBootstrapFactory.java        |   39 +
 .../internal/interop/InteropException.java      |   71 +
 .../internal/interop/InteropIgnition.java       |  166 +
 .../interop/InteropLocalEventListener.java      |   28 +
 .../interop/InteropNoCallbackException.java     |   50 +
 .../internal/interop/InteropProcessor.java      |   36 +
 .../managers/communication/GridIoManager.java   |   36 +-
 .../communication/GridIoMessageFactory.java     |   12 +-
 .../GridLifecycleAwareMessageFilter.java        |    5 +-
 .../eventstorage/GridEventStorageManager.java   |   29 +-
 .../managers/indexing/GridIndexingManager.java  |   14 +-
 .../processors/cache/CacheObjectImpl.java       |    2 +-
 .../cache/DynamicCacheDescriptor.java           |   16 +-
 .../processors/cache/GridCacheAdapter.java      |  589 +-
 .../processors/cache/GridCacheContext.java      |    7 +
 .../cache/GridCacheEvictionManager.java         |    2 +-
 .../processors/cache/GridCacheIoManager.java    |  320 +-
 .../processors/cache/GridCacheMapEntry.java     |  132 +-
 .../processors/cache/GridCacheMessage.java      |    8 +-
 .../processors/cache/GridCacheMvccManager.java  |    4 +-
 .../GridCachePartitionExchangeManager.java      |    7 +-
 .../processors/cache/GridCacheProcessor.java    |  192 +-
 .../processors/cache/GridCacheProxyImpl.java    |   24 -
 .../processors/cache/GridCacheSwapManager.java  |  250 +-
 .../processors/cache/GridCacheTtlManager.java   |  156 +-
 .../processors/cache/GridCacheUtils.java        |    6 +-
 .../processors/cache/IgniteCacheProxy.java      |    3 +-
 .../processors/cache/IgniteInternalCache.java   |   27 -
 ...ridCacheOptimisticCheckPreparedTxFuture.java |  434 --
 ...idCacheOptimisticCheckPreparedTxRequest.java |  232 -
 ...dCacheOptimisticCheckPreparedTxResponse.java |  179 -
 .../distributed/GridCacheTxRecoveryFuture.java  |  506 ++
 .../distributed/GridCacheTxRecoveryRequest.java |  261 +
 .../GridCacheTxRecoveryResponse.java            |  182 +
 .../GridDistributedCacheAdapter.java            |  210 +-
 .../distributed/GridDistributedLockRequest.java |  111 +-
 .../GridDistributedTxFinishRequest.java         |   70 +-
 .../distributed/GridDistributedTxMapping.java   |    5 +-
 .../GridDistributedTxPrepareRequest.java        |  112 +-
 .../GridDistributedTxRemoteAdapter.java         |   32 +-
 .../distributed/dht/GridDhtCacheAdapter.java    |   22 +-
 .../distributed/dht/GridDhtLocalPartition.java  |    2 +-
 .../distributed/dht/GridDhtLockFuture.java      |    2 -
 .../distributed/dht/GridDhtLockRequest.java     |   45 +-
 .../dht/GridDhtOffHeapCacheEntry.java           |   63 +
 .../dht/GridDhtTransactionalCacheAdapter.java   |   15 +-
 .../distributed/dht/GridDhtTxFinishFuture.java  |    3 -
 .../distributed/dht/GridDhtTxFinishRequest.java |   43 +-
 .../cache/distributed/dht/GridDhtTxLocal.java   |   38 +-
 .../distributed/dht/GridDhtTxLocalAdapter.java  |   95 +-
 .../cache/distributed/dht/GridDhtTxMapping.java |    2 +-
 .../distributed/dht/GridDhtTxPrepareFuture.java |  100 +-
 .../dht/GridDhtTxPrepareRequest.java            |   60 +-
 .../cache/distributed/dht/GridDhtTxRemote.java  |    8 +-
 .../distributed/dht/GridNoStorageCacheMap.java  |    4 +-
 .../dht/GridPartitionedGetFuture.java           |    2 +-
 .../dht/atomic/GridDhtAtomicCache.java          |    7 +-
 .../atomic/GridDhtAtomicOffHeapCacheEntry.java  |   63 +
 .../dht/atomic/GridDhtAtomicUpdateResponse.java |    8 +
 .../dht/atomic/GridNearAtomicUpdateFuture.java  |   44 +-
 .../dht/atomic/GridNearAtomicUpdateRequest.java |   36 +-
 .../atomic/GridNearAtomicUpdateResponse.java    |   18 +-
 .../dht/colocated/GridDhtColocatedCache.java    |    5 +-
 .../colocated/GridDhtColocatedLockFuture.java   |   37 +-
 .../GridDhtColocatedOffHeapCacheEntry.java      |   63 +
 .../colocated/GridDhtDetachedCacheEntry.java    |    4 +-
 .../dht/preloader/GridDhtForceKeysFuture.java   |    6 +
 .../dht/preloader/GridDhtForceKeysResponse.java |   54 +-
 .../GridDhtPartitionsExchangeFuture.java        |    2 +-
 .../distributed/near/GridNearCacheAdapter.java  |   13 +-
 .../distributed/near/GridNearCacheEntry.java    |    6 +-
 .../distributed/near/GridNearGetResponse.java   |    8 +-
 .../distributed/near/GridNearLockFuture.java    |   11 -
 .../distributed/near/GridNearLockRequest.java   |   61 +-
 .../near/GridNearOffHeapCacheEntry.java         |   60 +
 .../near/GridNearOptimisticTxPrepareFuture.java |  768 ++
 .../GridNearPessimisticTxPrepareFuture.java     |  347 +
 .../near/GridNearTransactionalCache.java        |    4 -
 .../near/GridNearTxFinishRequest.java           |   28 +-
 .../cache/distributed/near/GridNearTxLocal.java |  109 +-
 .../near/GridNearTxPrepareFuture.java           | 1050 ---
 .../near/GridNearTxPrepareFutureAdapter.java    |  231 +
 .../near/GridNearTxPrepareRequest.java          |   52 +-
 .../near/GridNearTxPrepareResponse.java         |   28 +-
 .../distributed/near/GridNearTxRemote.java      |   24 +-
 .../processors/cache/local/GridLocalCache.java  |    8 +-
 .../cache/local/GridLocalCacheEntry.java        |   18 +
 .../local/atomic/GridLocalAtomicCache.java      |   27 +-
 .../cache/query/GridCacheQueryManager.java      |   43 +-
 .../cache/query/GridCacheSqlQuery.java          |  137 +-
 .../cache/query/GridCacheTwoStepQuery.java      |   25 +-
 .../cache/transactions/IgniteInternalTx.java    |   19 +-
 .../transactions/IgniteTransactionsImpl.java    |    4 +-
 .../cache/transactions/IgniteTxAdapter.java     |   76 +-
 .../cache/transactions/IgniteTxEntry.java       |   48 +-
 .../cache/transactions/IgniteTxHandler.java     |  106 +-
 .../transactions/IgniteTxLocalAdapter.java      |  185 +-
 .../cache/transactions/IgniteTxLocalEx.java     |   21 +-
 .../cache/transactions/IgniteTxManager.java     |  271 +-
 .../datastreamer/DataStreamerImpl.java          |    2 +
 .../processors/igfs/IgfsDataManager.java        |    3 +
 .../processors/igfs/IgfsDeleteWorker.java       |    4 +
 .../processors/igfs/IgfsMetaManager.java        |    2 +-
 .../internal/processors/igfs/IgfsUtils.java     |   11 +-
 .../offheap/GridOffHeapProcessor.java           |   17 +
 .../processors/query/GridQueryIndexing.java     |   35 +-
 .../processors/query/GridQueryProcessor.java    |  130 +-
 .../messages/GridQueryNextPageResponse.java     |   68 +-
 .../h2/twostep/messages/GridQueryRequest.java   |   21 +-
 .../processors/resource/GridResourceField.java  |   16 +-
 .../processors/resource/GridResourceIoc.java    |  389 +-
 .../processors/resource/GridResourceMethod.java |   13 +
 .../resource/GridResourceProcessor.java         |   20 +-
 .../ignite/internal/util/IgniteUtils.java       |   28 +-
 .../shmem/IpcSharedMemoryServerEndpoint.java    |    2 +-
 .../util/lang/GridComputeJobWrapper.java        |   96 -
 .../util/lang/GridFilteredIterator.java         |    2 +-
 .../ignite/internal/util/lang/GridFunc.java     | 7218 +++++-------------
 .../internal/util/nio/GridBufferedParser.java   |    4 -
 .../internal/util/nio/GridDelimitedParser.java  |   91 +
 .../util/nio/GridNioDelimitedBuffer.java        |  106 +
 .../util/offheap/GridOffHeapPartitionedMap.java |    9 +
 .../unsafe/GridUnsafePartitionedMap.java        |  155 +-
 .../util/spring/IgniteSpringHelper.java         |    4 +-
 .../internal/visor/cache/VisorCacheMetrics.java |   53 +-
 .../cache/VisorCacheNearConfiguration.java      |    4 +-
 .../visor/cache/VisorCacheStartTask.java        |  155 +
 .../internal/visor/query/VisorQueryArg.java     |   14 +-
 .../internal/visor/query/VisorQueryJob.java     |    2 +
 .../internal/visor/util/VisorTaskUtils.java     |   10 +
 .../apache/ignite/lang/IgniteAsyncSupport.java  |    4 +-
 .../org/apache/ignite/services/Service.java     |    5 +-
 .../org/apache/ignite/spi/IgniteSpiAdapter.java |   19 +-
 .../communication/tcp/TcpCommunicationSpi.java  |    2 +-
 .../discovery/tcp/TcpClientDiscoverySpi.java    |    4 -
 .../spi/discovery/tcp/TcpDiscoverySpi.java      |   74 +-
 .../discovery/tcp/TcpDiscoverySpiAdapter.java   |   14 +-
 .../org/apache/ignite/stream/StreamAdapter.java |  111 +
 .../ignite/stream/StreamTupleExtractor.java     |   33 +
 .../stream/socket/SocketMessageConverter.java   |   31 +
 .../ignite/stream/socket/SocketStreamer.java    |  218 +
 .../ignite/stream/socket/package-info.java      |   21 +
 .../resources/META-INF/classnames.properties    |   24 +-
 .../core/src/main/resources/ignite.properties   |    2 +-
 .../internal/GridUpdateNotifierSelfTest.java    |   30 +-
 .../processors/cache/CacheGetFromJobTest.java   |  110 +
 .../cache/CacheOffheapMapEntrySelfTest.java     |  168 +
 .../cache/CacheRemoveAllSelfTest.java           |   81 +
 .../GridCacheAbstractFailoverSelfTest.java      |   12 +-
 .../cache/GridCacheAbstractFullApiSelfTest.java |  227 +-
 .../cache/GridCacheAbstractSelfTest.java        |    4 +-
 .../cache/GridCacheSwapReloadSelfTest.java      |   20 +-
 .../IgniteCacheEntryListenerAbstractTest.java   |    4 +-
 .../cache/IgniteCacheNearLockValueSelfTest.java |  145 +
 .../IgniteCacheP2pUnmarshallingErrorTest.java   |  189 +
 ...gniteCacheP2pUnmarshallingNearErrorTest.java |   56 +
 ...CacheP2pUnmarshallingRebalanceErrorTest.java |   80 +
 .../IgniteCacheP2pUnmarshallingTxErrorTest.java |  109 +
 .../cache/IgniteCachePeekModesAbstractTest.java |   15 +-
 .../cache/IgniteDynamicCacheStartSelfTest.java  |   20 +-
 .../cache/OffHeapTieredTransactionSelfTest.java |  127 +
 ...CacheLoadingConcurrentGridStartSelfTest.java |  163 +
 .../GridCacheAbstractNodeRestartSelfTest.java   |  101 +-
 ...GridCacheLoadingConcurrentGridStartTest.java |  154 -
 .../distributed/GridCacheLockAbstractTest.java  |    2 -
 .../distributed/IgniteTxGetAfterStopTest.java   |  131 +
 ...xOriginatingNodeFailureAbstractSelfTest.java |    2 +-
 .../dht/GridCacheDhtPreloadSelfTest.java        |    2 +-
 ...icOffHeapTieredMultiNodeFullApiSelfTest.java |   43 +
 ...achePartitionedNearDisabledLockSelfTest.java |   47 +
 ...ionedNearDisabledOffHeapFullApiSelfTest.java |    8 +-
 ...DisabledOffHeapMultiNodeFullApiSelfTest.java |    8 +-
 ...abledOffHeapTieredAtomicFullApiSelfTest.java |   56 +
 ...earDisabledOffHeapTieredFullApiSelfTest.java |   33 +
 ...edOffHeapTieredMultiNodeFullApiSelfTest.java |   33 +
 ...rDisabledPrimaryNodeFailureRecoveryTest.java |   31 +
 ...rtitionedPrimaryNodeFailureRecoveryTest.java |   31 +
 ...woBackupsPrimaryNodeFailureRecoveryTest.java |   37 +
 ...ePrimaryNodeFailureRecoveryAbstractTest.java |  533 ++
 ...idCacheAtomicReplicatedFailoverSelfTest.java |    6 +
 ...CacheAtomicOffHeapTieredFullApiSelfTest.java |   32 +
 ...icOffHeapTieredMultiNodeFullApiSelfTest.java |   33 +
 ...yWriteOrderOffHeapTieredFullApiSelfTest.java |   33 +
 ...erOffHeapTieredMultiNodeFullApiSelfTest.java |   33 +
 ...achePartitionedMultiNodeFullApiSelfTest.java |   15 +-
 .../GridCachePartitionedNodeRestartTest.java    |    4 +-
 ...dCachePartitionedOffHeapFullApiSelfTest.java |    8 +-
 ...titionedOffHeapMultiNodeFullApiSelfTest.java |    8 +-
 ...PartitionedOffHeapTieredFullApiSelfTest.java |   32 +
 ...edOffHeapTieredMultiNodeFullApiSelfTest.java |   72 +
 ...ePartitionedOptimisticTxNodeRestartTest.java |    4 +-
 .../GridCachePartitionedTxSalvageSelfTest.java  |   25 +-
 .../near/IgniteCacheNearOnlyTxTest.java         |  190 +
 .../near/NoneRebalanceModeSelfTest.java         |   67 +
 .../GridCacheReplicatedFailoverSelfTest.java    |    6 +
 .../GridCacheReplicatedLockSelfTest.java        |    5 +
 .../GridCacheReplicatedNodeRestartSelfTest.java |   82 +
 ...idCacheReplicatedOffHeapFullApiSelfTest.java |    8 +-
 ...plicatedOffHeapMultiNodeFullApiSelfTest.java |    8 +-
 ...eReplicatedOffHeapTieredFullApiSelfTest.java |   33 +
 ...edOffHeapTieredMultiNodeFullApiSelfTest.java |   33 +
 .../RandomEvictionPolicyCacheSizeSelfTest.java  |   72 +
 .../IgniteCacheExpiryPolicyAbstractTest.java    |    2 +-
 .../IgniteCacheExpiryPolicyTestSuite.java       |    2 +
 .../expiry/IgniteCacheTtlCleanupSelfTest.java   |   85 +
 ...LocalAtomicOffHeapTieredFullApiSelfTest.java |   32 +
 .../GridCacheLocalIsolatedNodesSelfTest.java    |   18 +-
 .../GridCacheLocalOffHeapFullApiSelfTest.java   |    6 +-
 ...dCacheLocalOffHeapTieredFullApiSelfTest.java |   32 +
 .../igfs/IgfsClientCacheSelfTest.java           |  132 +
 .../processors/igfs/IgfsOneClientNodeTest.java  |  133 +
 .../processors/igfs/IgfsStreamsSelfTest.java    |    2 +-
 .../service/ClosureServiceClientsNodesTest.java |  245 +
 .../util/nio/GridNioDelimitedBufferTest.java    |  112 +
 ...idFileSwapSpaceSpiMultithreadedLoadTest.java |    4 +-
 .../tcp/TcpClientDiscoverySelfTest.java         |    8 +
 .../discovery/tcp/TcpDiscoveryRestartTest.java  |  199 +
 .../spi/discovery/tcp/TcpDiscoverySelfTest.java |   65 +-
 .../stream/socket/SocketStreamerSelfTest.java   |  315 +
 .../ignite/stream/socket/package-info.java      |   21 +
 .../ignite/testsuites/IgniteBasicTestSuite.java |    4 +
 .../IgniteCacheEvictionSelfTestSuite.java       |    1 +
 .../IgniteCacheFailoverTestSuite.java           |   10 +-
 .../IgniteCacheFullApiSelfTestSuite.java        |   18 +
 ...gniteCacheP2pUnmarshallingErrorTestSuit.java |   41 +
 .../testsuites/IgniteCacheRestartTestSuite.java |   11 +-
 .../ignite/testsuites/IgniteCacheTestSuite.java |  296 +-
 .../testsuites/IgniteCacheTestSuite2.java       |  144 +
 .../testsuites/IgniteCacheTestSuite3.java       |  142 +
 .../testsuites/IgniteCacheTestSuite4.java       |  135 +
 .../IgniteCacheTxRecoverySelfTestSuite.java     |    4 +
 .../ignite/testsuites/IgniteIgfsTestSuite.java  |    3 +
 .../testsuites/IgniteStreamTestSuite.java       |   39 +
 .../testsuites/IgniteUtilSelfTestSuite.java     |    1 +
 modules/extdata/p2p/pom.xml                     |    2 +-
 modules/extdata/uri/pom.xml                     |    2 +-
 modules/gce/pom.xml                             |    8 +-
 modules/geospatial/pom.xml                      |    2 +-
 .../query/h2/GridH2IndexingGeoSelfTest.java     |   20 +-
 modules/hadoop/pom.xml                          |    2 +-
 .../processors/hadoop/v2/HadoopV2Context.java   |   10 +-
 .../testsuites/IgniteHadoopTestSuite.java       |    2 +-
 modules/hibernate/pom.xml                       |    2 +-
 modules/indexing/pom.xml                        |    2 +-
 .../processors/query/h2/IgniteH2Indexing.java   |  190 +-
 .../query/h2/opt/GridH2AbstractKeyValueRow.java |  110 +-
 .../query/h2/opt/GridH2KeyValueRowOffheap.java  |   11 +-
 .../query/h2/opt/GridH2KeyValueRowOnheap.java   |    6 +-
 .../query/h2/opt/GridH2RowDescriptor.java       |   14 +-
 .../processors/query/h2/opt/GridH2Table.java    |   10 +-
 .../query/h2/opt/GridH2ValueCacheObject.java    |  191 +
 .../query/h2/opt/GridLuceneIndex.java           |   84 +-
 .../query/h2/sql/GridSqlOperationType.java      |    2 +-
 .../processors/query/h2/sql/GridSqlQuery.java   |   20 +
 .../query/h2/sql/GridSqlQueryParser.java        |   10 +-
 .../query/h2/sql/GridSqlQuerySplitter.java      |   15 +-
 .../processors/query/h2/sql/GridSqlSelect.java  |    2 +-
 .../processors/query/h2/sql/GridSqlUnion.java   |    2 +-
 .../query/h2/twostep/GridMapQueryExecutor.java  |   24 +-
 .../query/h2/twostep/GridMergeIndex.java        |    6 +-
 .../h2/twostep/GridMergeIndexUnsorted.java      |    4 +-
 .../h2/twostep/GridReduceQueryExecutor.java     |  130 +-
 .../query/h2/twostep/GridResultPage.java        |   80 +-
 .../query/h2/twostep/msg/GridH2Array.java       |  124 +
 .../query/h2/twostep/msg/GridH2Boolean.java     |  112 +
 .../query/h2/twostep/msg/GridH2Byte.java        |  113 +
 .../query/h2/twostep/msg/GridH2Bytes.java       |  113 +
 .../query/h2/twostep/msg/GridH2CacheObject.java |  148 +
 .../query/h2/twostep/msg/GridH2Date.java        |  115 +
 .../query/h2/twostep/msg/GridH2Decimal.java     |  134 +
 .../query/h2/twostep/msg/GridH2Double.java      |  113 +
 .../query/h2/twostep/msg/GridH2Float.java       |  113 +
 .../query/h2/twostep/msg/GridH2Geometry.java    |  134 +
 .../query/h2/twostep/msg/GridH2Integer.java     |  113 +
 .../query/h2/twostep/msg/GridH2JavaObject.java  |  113 +
 .../query/h2/twostep/msg/GridH2Long.java        |  113 +
 .../query/h2/twostep/msg/GridH2Null.java        |   78 +
 .../query/h2/twostep/msg/GridH2Short.java       |  113 +
 .../query/h2/twostep/msg/GridH2String.java      |  115 +
 .../query/h2/twostep/msg/GridH2Time.java        |  116 +
 .../query/h2/twostep/msg/GridH2Timestamp.java   |  133 +
 .../query/h2/twostep/msg/GridH2Uuid.java        |  133 +
 .../h2/twostep/msg/GridH2ValueMessage.java      |   49 +
 .../twostep/msg/GridH2ValueMessageFactory.java  |  201 +
 .../cache/GridCacheOffHeapAndSwapSelfTest.java  |   11 +-
 .../cache/GridCacheOffHeapSelfTest.java         |   11 +-
 .../cache/GridCacheOffheapIndexGetSelfTest.java |  111 +
 .../IgniteCacheAbstractFieldsQuerySelfTest.java |   21 +
 ...niteCacheP2pUnmarshallingQueryErrorTest.java |   56 +
 ...eQueryMultiThreadedOffHeapTiredSelfTest.java |   37 +
 .../IgniteCacheQueryMultiThreadedSelfTest.java  |   37 +-
 .../local/IgniteCacheLocalQuerySelfTest.java    |    6 +
 .../h2/GridIndexingSpiAbstractSelfTest.java     |  130 +-
 .../query/h2/sql/BaseH2CompareQueryTest.java    |   16 +
 .../IgniteCacheQuerySelfTestSuite.java          |    4 +
 .../IgniteCacheWithIndexingTestSuite.java       |    2 +
 modules/jcl/pom.xml                             |    2 +-
 modules/jta/pom.xml                             |    2 +-
 .../processors/cache/jta/CacheJtaManager.java   |    4 +-
 modules/log4j/pom.xml                           |    2 +-
 modules/mesos/README.txt                        |   28 +
 modules/mesos/licenses/apache-2.0.txt           |  202 +
 modules/mesos/licenses/jetty-epl-license.txt    |   69 +
 modules/mesos/pom.xml                           |   95 +
 .../apache/ignite/mesos/ClusterProperties.java  |  519 ++
 .../apache/ignite/mesos/IgniteFramework.java    |  119 +
 .../apache/ignite/mesos/IgniteScheduler.java    |  361 +
 .../org/apache/ignite/mesos/IgniteTask.java     |   86 +
 .../org/apache/ignite/mesos/package-info.java   |   22 +
 .../ignite/mesos/resource/IgniteProvider.java   |  234 +
 .../ignite/mesos/resource/JettyServer.java      |   61 +
 .../ignite/mesos/resource/ResourceHandler.java  |  142 +
 .../ignite/mesos/resource/ResourceProvider.java |  120 +
 .../ignite/mesos/resource/package-info.java     |   22 +
 .../main/resources/ignite-default-config.xml    |   35 +
 .../org/apache/ignite/IgniteMesosTestSuite.java |   38 +
 .../ignite/mesos/IgniteSchedulerSelfTest.java   |  464 ++
 modules/rest-http/pom.xml                       |    2 +-
 modules/scalar/pom.xml                          |    2 +-
 .../ignite/scalar/ScalarConversions.scala       |    8 -
 .../scalar/tests/ScalarCacheQueriesSpec.scala   |  154 +-
 .../ignite/scalar/tests/ScalarCacheSpec.scala   |   23 +-
 .../scalar/tests/ScalarConversionsSpec.scala    |   43 +-
 .../scalar/tests/ScalarProjectionSpec.scala     |  128 +-
 .../scalar/tests/ScalarReturnableSpec.scala     |   41 +-
 modules/schedule/pom.xml                        |    2 +-
 modules/schema-import/pom.xml                   |    8 +-
 .../ignite/schema/generator/CodeGenerator.java  |   47 +-
 modules/slf4j/pom.xml                           |    2 +-
 modules/spring/pom.xml                          |    2 +-
 .../util/spring/IgniteSpringHelperImpl.java     |    2 +-
 modules/ssh/pom.xml                             |    2 +-
 ...gniteProjectionStartStopRestartSelfTest.java |   26 +-
 modules/tools/pom.xml                           |    2 +-
 modules/urideploy/pom.xml                       |    2 +-
 .../licenses/jcraft-revised-bsd.txt             |   28 -
 modules/visor-console/pom.xml                   |    4 +-
 .../commands/cache/VisorCacheCommand.scala      |    2 +-
 .../commands/cache/VisorCacheScanCommand.scala  |    2 +-
 .../visor/commands/node/VisorNodeCommand.scala  |    2 +-
 .../commands/tasks/VisorTasksCommand.scala      |    2 +-
 .../scala/org/apache/ignite/visor/visor.scala   |   63 +-
 .../ignite/visor/VisorRuntimeBaseSpec.scala     |    2 +-
 .../visor/commands/VisorArgListSpec.scala       |   60 +-
 .../commands/VisorFileNameCompleterSpec.scala   |   34 +-
 .../commands/ack/VisorAckCommandSpec.scala      |   20 +-
 .../commands/alert/VisorAlertCommandSpec.scala  |   68 +-
 .../cache/VisorCacheClearCommandSpec.scala      |   48 +-
 .../commands/cache/VisorCacheCommandSpec.scala  |   66 +-
 .../config/VisorConfigurationCommandSpec.scala  |    8 +-
 .../cswap/VisorCacheSwapCommandSpec.scala       |   24 +-
 .../deploy/VisorDeployCommandSpec.scala         |   10 +-
 .../disco/VisorDiscoveryCommandSpec.scala       |   46 +-
 .../events/VisorEventsCommandSpec.scala         |   28 +-
 .../visor/commands/gc/VisorGcCommandSpec.scala  |   30 +-
 .../commands/help/VisorHelpCommandSpec.scala    |   57 +-
 .../commands/kill/VisorKillCommandSpec.scala    |   58 +-
 .../commands/log/VisorLogCommandSpec.scala      |   10 +-
 .../commands/mem/VisorMemoryCommandSpec.scala   |   77 +-
 .../commands/node/VisorNodeCommandSpec.scala    |   22 +-
 .../commands/open/VisorOpenCommandSpec.scala    |   16 +-
 .../commands/ping/VisorPingCommandSpec.scala    |   16 +-
 .../commands/start/VisorStartCommandSpec.scala  |  126 +-
 .../commands/tasks/VisorTasksCommandSpec.scala  |  112 +-
 .../commands/top/VisorTopologyCommandSpec.scala |   52 +-
 .../commands/vvm/VisorVvmCommandSpec.scala      |   30 +-
 modules/visor-plugins/pom.xml                   |    2 +-
 modules/web/pom.xml                             |    2 +-
 .../config/benchmark-client-mode.properties     |   89 +
 modules/yardstick/pom.xml                       |    2 +-
 parent/pom.xml                                  |    9 +
 pom.xml                                         |  322 +-
 scripts/git-patch-prop.sh                       |    2 +-
 439 files changed, 23725 insertions(+), 12812 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 296e130..3da8e4d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,4 +19,5 @@ atlassian-ide-plugin.xml
 target
 /libs/
 pom-installed.xml
-git-patch-prop-local.sh
\ No newline at end of file
+git-patch-prop-local.sh
+/slurp.sh

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/DEVNOTES.txt
----------------------------------------------------------------------
diff --git a/DEVNOTES.txt b/DEVNOTES.txt
index 2e37cd1..8f1730c 100644
--- a/DEVNOTES.txt
+++ b/DEVNOTES.txt
@@ -9,7 +9,7 @@ With LGPL dependencies:
 Look for incubator-ignite-<version>-bin.zip in ./target/bin directory.
 
 NOTE: JDK version should be 1.7.0-* or >= 1.8.0-u40.
-
+      Schema Import module use JavaFX, under OpenJDK may be compiled and run only on OpenJDK 8 with installed OpenJFX.
 
 Ignite Hadoop Accelerator Maven Build Instructions
 ============================================
@@ -40,35 +40,27 @@ Specify gpg profile at settings.xml. It will be used to sign sources and artifac
    </properties>
 </profile>
 
-Configure access to people.apache.org/~<username>. It necessary to upload sources to site.
-See https://blogs.apache.org/infra/entry/committer_shell_access_to_people for details.
-Specify ignite-site server at settings.xml.
-
-<server>
-   <id>ignite-site</id>
-   <username>username</username>
-   <privateKey>/home/username.ppk</privateKey>
-   <passphrase>passphrase</passphrase>
-</server>
-
 Ensure you have RELEASE (not SNAPSHOT) version at Ignite poms.
 Maven release plugin release:prepare goal can be used to make release tag.
 
-Deploy Ignite release to maven repository and site:
+Deploy Ignite release candidate to maven repository and dev-svn:
 
-mvn deploy -P apache-release,gpg,release,scala,lgpl,deploy-ignite-site -Dignite.edition=fabric -DskipTests -Dignite.site=scp://people.apache.org:/home/<username>/public_html -B
+   mvn deploy -P apache-release,gpg,release,scala,lgpl,deploy-ignite-site -Dignite.edition=fabric -DskipTests -B
 
-You might need to allow connection to people.apache.org. Just do following at console:
+   Binary artifact name can be changed by setting additional property -Dignite.zip.pattern.
+   Sources package name is fixed. Sources package zip will be created automatically when apache-release profile used.
 
-ssh people.apache.org
+   In case you want to release both fabric and hadoop editions you have to build hadoop first, save /target/bin/*.zip,
+   make "mvn clean" and restore them before deploy step.
 
-and type "yes" + enter.
+   Nexus staging (repository.apache.org) should be closed when mvn deploy finished.
+   Checkout https://dist.apache.org/repos/dist/dev/incubator/ignite svn. Create new folder with name equals to released
+   version at svn root. Copy target/site folder content to svn/ignite/<version> folder and commit.
 
-In case you want to release both fabric and hadoop editions you have to build hadoop first, save /target/bin/*.zip, make "mvn clean" and
-restore them before deploy step.
+Start vote based on https://dist.apache.org/repos/dist/dev/incubator/ignite/<version>.
 
-Start vote based on people.apache.org/~<username>/ignite-version.
-Close nexus staging when version accepted.
+Release nexus staging and copy binaries and sources from https://dist.apache.org/repos/dist/dev/incubator/ignite/<version>
+to https://dist.apache.org/repos/dist/release/incubator/ignite/<version> when version accepted.
 
 
 JCache TCK compliance
@@ -77,6 +69,13 @@ To test compliance with JCache TCK use:
 
 mvn test -P-release,jcache-tck -pl :ignite-core -am
 
+Run tests
+==========
+To run tests locally use:
+
+mvn clean test -U -Plgpl,examples,-clean-libs,-release -Dmaven.test.failure.ignore=true -DfailIfNoTests=false -Dtest=%TEST_PATTERN%
+
+For example, %TEST_PATTERN% can be 'org.apache.ignite.testsuites.IgniteBasicTestSuite' or 'GridCacheLocalAtomicFullApiSelfTest#testGet'
 
 Apache RAT Instructions
 =======================

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..7649b39
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,238 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+
+
+
+==============================================================================
+Apache Ignite (incubating) Subcomponents:
+
+The Apache Ignite project contains subcomponents with separate copyright
+notices and license terms. Your use of the source code for the these
+subcomponents is subject to the terms and conditions of the following
+licenses.
+
+
+==============================================================================
+For SnapTree:
+==============================================================================
+This product bundles SnapTree, which is available under a
+"3-clause BSD" license.  For details, see
+https://github.com/nbronson/snaptree/blob/master/LICENSE.
+
+==============================================================================
+For JSR 166 classes in "org.jsr166" package
+==============================================================================
+This product bundles JSR-166 classes which are donated to public domain.
+For details, see CC0 1.0 Universal (1.0), Public Domain Dedication,
+http://creativecommons.org/publicdomain/zero/1.0/
+
+==============================================================================
+For books used for tests in "org.apache.ignite.internal.processors.hadoop.books"
+==============================================================================
+This code bundles book text files used for testing purposes which contain
+the following header:
+
+This eBook is for the use of anyone anywhere at no cost and with
+almost no restrictions whatsoever.  You may copy it, give it away or
+re-use it under the terms of the Project Gutenberg License included
+with this eBook or online at www.gutenberg.org

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/LICENSE.txt
----------------------------------------------------------------------
diff --git a/LICENSE.txt b/LICENSE.txt
deleted file mode 100644
index 7649b39..0000000
--- a/LICENSE.txt
+++ /dev/null
@@ -1,238 +0,0 @@
-
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
-   APPENDIX: How to apply the Apache License to your work.
-
-      To apply the Apache License to your work, attach the following
-      boilerplate notice, with the fields enclosed by brackets "[]"
-      replaced with your own identifying information. (Don't include
-      the brackets!)  The text should be enclosed in the appropriate
-      comment syntax for the file format. We also recommend that a
-      file or class name and description of purpose be included on the
-      same "printed page" as the copyright notice for easier
-      identification within third-party archives.
-
-   Copyright [yyyy] [name of copyright owner]
-
-   Licensed 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.
-
-
-
-==============================================================================
-Apache Ignite (incubating) Subcomponents:
-
-The Apache Ignite project contains subcomponents with separate copyright
-notices and license terms. Your use of the source code for the these
-subcomponents is subject to the terms and conditions of the following
-licenses.
-
-
-==============================================================================
-For SnapTree:
-==============================================================================
-This product bundles SnapTree, which is available under a
-"3-clause BSD" license.  For details, see
-https://github.com/nbronson/snaptree/blob/master/LICENSE.
-
-==============================================================================
-For JSR 166 classes in "org.jsr166" package
-==============================================================================
-This product bundles JSR-166 classes which are donated to public domain.
-For details, see CC0 1.0 Universal (1.0), Public Domain Dedication,
-http://creativecommons.org/publicdomain/zero/1.0/
-
-==============================================================================
-For books used for tests in "org.apache.ignite.internal.processors.hadoop.books"
-==============================================================================
-This code bundles book text files used for testing purposes which contain
-the following header:
-
-This eBook is for the use of anyone anywhere at no cost and with
-almost no restrictions whatsoever.  You may copy it, give it away or
-re-use it under the terms of the Project Gutenberg License included
-with this eBook or online at www.gutenberg.org

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/NOTICE
----------------------------------------------------------------------
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..298d05b
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,12 @@
+Apache Ignite (incubating)
+Copyright 2015 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+
+This software includes code from IntelliJ IDEA Community Edition
+Copyright (C) JetBrains s.r.o.
+https://www.jetbrains.com/idea/
+Licensed under Apache License, Version 2.0.
+http://search.maven.org/#artifactdetails%7Corg.jetbrains%7Cannotations%7C13.0%7Cjar

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/NOTICE.txt
----------------------------------------------------------------------
diff --git a/NOTICE.txt b/NOTICE.txt
deleted file mode 100644
index 298d05b..0000000
--- a/NOTICE.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-Apache Ignite (incubating)
-Copyright 2015 The Apache Software Foundation
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
-
-
-This software includes code from IntelliJ IDEA Community Edition
-Copyright (C) JetBrains s.r.o.
-https://www.jetbrains.com/idea/
-Licensed under Apache License, Version 2.0.
-http://search.maven.org/#artifactdetails%7Corg.jetbrains%7Cannotations%7C13.0%7Cjar

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/assembly/release-base.xml
----------------------------------------------------------------------
diff --git a/assembly/release-base.xml b/assembly/release-base.xml
index 3297df8..21c4518 100644
--- a/assembly/release-base.xml
+++ b/assembly/release-base.xml
@@ -23,12 +23,12 @@
            http://maven.apache.org/xsd/component-1.1.2.xsd">
     <files>
         <file>
-            <source>LICENSE.txt</source>
+            <source>LICENSE</source>
             <outputDirectory>/</outputDirectory>
         </file>
 
         <file>
-            <source>NOTICE.txt</source>
+            <source>NOTICE</source>
             <outputDirectory>/</outputDirectory>
         </file>
 
@@ -71,8 +71,9 @@
             <excludes>
                 <exclude>**/*hadoop*.bat</exclude>
                 <exclude>igniterouter.bat</exclude>
-                <exclude>**/target-classpath.bat</exclude>
+                <exclude>**/build-classpath.bat</exclude>
                 <exclude>ignitevisorcmd.bat</exclude>
+                <exclude>ignite-schema-import.bat</exclude>
             </excludes>
         </fileSet>
 
@@ -86,9 +87,10 @@
             <excludes>
                 <exclude>**/*hadoop*.sh</exclude>
                 <exclude>igniterouter.sh</exclude>
-                <exclude>**/target-classpath.sh</exclude>
+                <exclude>**/build-classpath.sh</exclude>
                 <exclude>**/service.sh</exclude>
                 <exclude>ignitevisorcmd.sh</exclude>
+                <exclude>ignite-schema-import.sh</exclude>
             </excludes>
         </fileSet>
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/assembly/release-schema-import.xml
----------------------------------------------------------------------
diff --git a/assembly/release-schema-import.xml b/assembly/release-schema-import.xml
new file mode 100644
index 0000000..b746c83
--- /dev/null
+++ b/assembly/release-schema-import.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
+          http://maven.apache.org/xsd/assembly-1.1.2.xsd">
+    <id>scala</id>
+
+    <includeBaseDirectory>false</includeBaseDirectory>
+
+    <formats>
+        <format>dir</format>
+    </formats>
+
+    <fileSets>
+        <fileSet>
+            <directory>bin</directory>
+            <outputDirectory>/</outputDirectory>
+            <includes>
+                <include>**/ignite-schema-import.bat</include>
+            </includes>
+        </fileSet>
+
+        <fileSet>
+            <directory>bin</directory>
+            <outputDirectory>/</outputDirectory>
+            <fileMode>0755</fileMode>
+            <includes>
+                <include>**/ignite-schema-import.sh</include>
+            </includes>
+        </fileSet>
+    </fileSets>
+</assembly>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/ignite-schema-import.bat
----------------------------------------------------------------------
diff --git a/bin/ignite-schema-import.bat b/bin/ignite-schema-import.bat
index 4731105..a4ec86b 100644
--- a/bin/ignite-schema-import.bat
+++ b/bin/ignite-schema-import.bat
@@ -91,7 +91,7 @@ if /i "%SCRIPTS_HOME%\" == "%~dp0" goto run
 :: Set IGNITE_LIBS
 ::
 call "%SCRIPTS_HOME%\include\setenv.bat"
-call "%SCRIPTS_HOME%\include\target-classpath.bat" &:: Will be removed in release.
+call "%SCRIPTS_HOME%\include\build-classpath.bat" &:: Will be removed in the binary release.
 set CP=%JAVA_HOME%\jre\lib\jfxrt.jar;%IGNITE_HOME%\bin\include\schema-import\*;%IGNITE_LIBS%
 
 ::

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/ignite-schema-import.sh
----------------------------------------------------------------------
diff --git a/bin/ignite-schema-import.sh b/bin/ignite-schema-import.sh
index 0a70d54..1029882 100755
--- a/bin/ignite-schema-import.sh
+++ b/bin/ignite-schema-import.sh
@@ -57,7 +57,7 @@ setIgniteHome
 # Set IGNITE_LIBS.
 #
 . "${SCRIPTS_HOME}"/include/setenv.sh
-. "${SCRIPTS_HOME}"/include/target-classpath.sh # Will be removed in release.
+. "${SCRIPTS_HOME}"/include/build-classpath.sh # Will be removed in the binary release.
 CP="${JAVA_HOME}/jre/lib/jfxrt.jar${SEP}${IGNITE_HOME}/bin/include/schema-import/*${SEP}${IGNITE_LIBS}"
 
 #

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/ignite.bat
----------------------------------------------------------------------
diff --git a/bin/ignite.bat b/bin/ignite.bat
index 687db60..1a4a58c 100644
--- a/bin/ignite.bat
+++ b/bin/ignite.bat
@@ -102,7 +102,7 @@ if "%OS%" == "Windows_NT" set PROG_NAME=%~nx0%
 :: Set IGNITE_LIBS
 ::
 call "%SCRIPTS_HOME%\include\setenv.bat"
-call "%SCRIPTS_HOME%\include\target-classpath.bat" &:: Will be removed in release.
+call "%SCRIPTS_HOME%\include\build-classpath.bat" &:: Will be removed in the binary release.
 set CP=%IGNITE_LIBS%
 
 ::

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/ignite.sh
----------------------------------------------------------------------
diff --git a/bin/ignite.sh b/bin/ignite.sh
index a246613..660a80f 100755
--- a/bin/ignite.sh
+++ b/bin/ignite.sh
@@ -58,7 +58,7 @@ fi
 # Set IGNITE_LIBS.
 #
 . "${SCRIPTS_HOME}"/include/setenv.sh
-. "${SCRIPTS_HOME}"/include/target-classpath.sh # Will be removed in release.
+. "${SCRIPTS_HOME}"/include/build-classpath.sh # Will be removed in the binary release.
 CP="${IGNITE_LIBS}"
 
 RANDOM_NUMBER=$("$JAVA" -cp "${CP}" org.apache.ignite.startup.cmdline.CommandLineRandomNumberGenerator)

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/ignitevisorcmd.bat
----------------------------------------------------------------------
diff --git a/bin/ignitevisorcmd.bat b/bin/ignitevisorcmd.bat
index 1cf2b26..4a1aafd 100644
--- a/bin/ignitevisorcmd.bat
+++ b/bin/ignitevisorcmd.bat
@@ -100,7 +100,7 @@ if "%OS%" == "Windows_NT" set PROG_NAME=%~nx0%
 :: Set IGNITE_LIBS
 ::
 call "%SCRIPTS_HOME%\include\setenv.bat"
-call "%SCRIPTS_HOME%\include\target-classpath.bat" &:: Will be removed in release.
+call "%SCRIPTS_HOME%\include\build-classpath.bat" &:: Will be removed in the binary release.
 set CP=%IGNITE_HOME%\bin\include\visor-common\*;%IGNITE_HOME%\bin\include\visorcmd\*;%IGNITE_LIBS%
 
 ::

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/ignitevisorcmd.sh
----------------------------------------------------------------------
diff --git a/bin/ignitevisorcmd.sh b/bin/ignitevisorcmd.sh
index 6118560..fe74f6a 100755
--- a/bin/ignitevisorcmd.sh
+++ b/bin/ignitevisorcmd.sh
@@ -53,7 +53,7 @@ setIgniteHome
 # Set IGNITE_LIBS.
 #
 . "${SCRIPTS_HOME}"/include/setenv.sh
-. "${SCRIPTS_HOME}"/include/target-classpath.sh # Will be removed in release.
+. "${SCRIPTS_HOME}"/include/build-classpath.sh # Will be removed in the binary release.
 CP="${IGNITE_HOME}/bin/include/visor-common/*${SEP}${IGNITE_HOME}/bin/include/visorcmd/*${SEP}${IGNITE_LIBS}"
 
 #

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/include/build-classpath.bat
----------------------------------------------------------------------
diff --git a/bin/include/build-classpath.bat b/bin/include/build-classpath.bat
new file mode 100644
index 0000000..5f932d3
--- /dev/null
+++ b/bin/include/build-classpath.bat
@@ -0,0 +1,46 @@
+::
+:: 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.
+::
+
+:: Target class path resolver.
+::
+:: Can be used like:
+::       call "%IGNITE_HOME%\bin\include\build-classpath.bat"
+:: in other scripts to set classpath using libs from target folder.
+::
+:: Will be excluded in release.
+
+@echo off
+
+for /D %%F in (modules\*) do if not %%F == "modules" call :includeToClassPath %%F
+
+for /D %%F in (%IGNITE_HOME%\modules\*) do if not %%F == "%IGNITE_HOME%\modules" call :includeToClassPath %%F
+
+goto :eof
+
+:includeToClassPath
+if exist "%1\target\" (
+    if exist "%1\target\classes\" call :concat %1\target\classes
+
+    if exist "%1\target\test-classes\" call :concat %1\target\test-classes
+
+    if exist "%1\target\libs\" call :concat %1\target\libs\*
+)
+goto :eof
+
+:concat
+set IGNITE_LIBS=%IGNITE_LIBS%;%1
+goto :eof

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/include/build-classpath.sh
----------------------------------------------------------------------
diff --git a/bin/include/build-classpath.sh b/bin/include/build-classpath.sh
new file mode 100644
index 0000000..9f0c878
--- /dev/null
+++ b/bin/include/build-classpath.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+#
+# 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.
+#
+
+# Target class path resolver.
+#
+# Can be used like:
+#       . "${IGNITE_HOME}"/bin/include/build-classpath.sh
+# in other scripts to set classpath using libs from target folder.
+#
+# Will be excluded in release.
+
+
+#
+# OS specific support.
+#
+SEP=":";
+
+case "`uname`" in
+    MINGW*)
+        SEP=";";
+        export IGNITE_HOME=`echo $IGNITE_HOME | sed -e 's/^\/\([a-zA-Z]\)/\1:/'`
+        ;;
+    CYGWIN*)
+        SEP=";";
+        export IGNITE_HOME=`echo $IGNITE_HOME | sed -e 's/^\/\([a-zA-Z]\)/\1:/'`
+        ;;
+esac
+
+includeToClassPath() {
+    for file in $1/*
+    do
+        if [ -d ${file} ] && [ -d "${file}/target" ]; then
+            if [ -d "${file}/target/classes" ]; then
+                IGNITE_LIBS=${IGNITE_LIBS}${SEP}${file}/target/classes
+            fi
+
+            if [ -d "${file}/target/test-classes" ]; then
+                IGNITE_LIBS=${IGNITE_LIBS}${SEP}${file}/target/test-classes
+            fi
+
+            if [ -d "${file}/target/libs" ]; then
+                IGNITE_LIBS=${IGNITE_LIBS}${SEP}${file}/target/libs/*
+            fi
+        fi
+    done
+}
+
+#
+# Include target libraries for enterprise modules to classpath.
+#
+includeToClassPath modules
+
+#
+# Include target libraries for opensourse modules to classpath.
+#
+includeToClassPath ${IGNITE_HOME}/modules

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/include/functions.sh
----------------------------------------------------------------------
diff --git a/bin/include/functions.sh b/bin/include/functions.sh
index f0430c1..b18b150 100755
--- a/bin/include/functions.sh
+++ b/bin/include/functions.sh
@@ -34,7 +34,7 @@
 checkJava() {
     # Check JAVA_HOME.
     if [ "$JAVA_HOME" = "" ]; then
-        JAVA=`which java`
+        JAVA=`type -p java`
         RETCODE=$?
 
         if [ $RETCODE -ne 0 ]; then

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/include/target-classpath.bat
----------------------------------------------------------------------
diff --git a/bin/include/target-classpath.bat b/bin/include/target-classpath.bat
deleted file mode 100644
index 4416557..0000000
--- a/bin/include/target-classpath.bat
+++ /dev/null
@@ -1,46 +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.
-::
-
-:: Target class path resolver.
-::
-:: Can be used like:
-::       call "%IGNITE_HOME%\bin\include\target-classpath.bat"
-:: in other scripts to set classpath using libs from target folder.
-::
-:: Will be excluded in release.
-
-@echo off
-
-for /D %%F in (modules\*) do if not %%F == "modules" call :includeToClassPath %%F
-
-for /D %%F in (%IGNITE_HOME%\modules\*) do if not %%F == "%IGNITE_HOME%\modules" call :includeToClassPath %%F
-
-goto :eof
-
-:includeToClassPath
-if exist "%1\target\" (
-    if exist "%1\target\classes\" call :concat %1\target\classes
-
-    if exist "%1\target\test-classes\" call :concat %1\target\test-classes
-
-    if exist "%1\target\libs\" call :concat %1\target\libs\*
-)
-goto :eof
-
-:concat
-set IGNITE_LIBS=%IGNITE_LIBS%;%1
-goto :eof

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/bin/include/target-classpath.sh
----------------------------------------------------------------------
diff --git a/bin/include/target-classpath.sh b/bin/include/target-classpath.sh
deleted file mode 100644
index 871d517..0000000
--- a/bin/include/target-classpath.sh
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/bin/sh
-#
-# 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.
-#
-
-# Target class path resolver.
-#
-# Can be used like:
-#       . "${IGNITE_HOME}"/bin/include/target-classpath.sh
-# in other scripts to set classpath using libs from target folder.
-#
-# Will be excluded in release.
-
-
-#
-# OS specific support.
-#
-SEP=":";
-
-case "`uname`" in
-    MINGW*)
-        SEP=";";
-        export IGNITE_HOME=`echo $IGNITE_HOME | sed -e 's/^\/\([a-zA-Z]\)/\1:/'`
-        ;;
-    CYGWIN*)
-        SEP=";";
-        export IGNITE_HOME=`echo $IGNITE_HOME | sed -e 's/^\/\([a-zA-Z]\)/\1:/'`
-        ;;
-esac
-
-includeToClassPath() {
-    for file in $1/*
-    do
-        if [ -d ${file} ] && [ -d "${file}/target" ]; then
-            if [ -d "${file}/target/classes" ]; then
-                IGNITE_LIBS=${IGNITE_LIBS}${SEP}${file}/target/classes
-            fi
-
-            if [ -d "${file}/target/test-classes" ]; then
-                IGNITE_LIBS=${IGNITE_LIBS}${SEP}${file}/target/test-classes
-            fi
-
-            if [ -d "${file}/target/libs" ]; then
-                IGNITE_LIBS=${IGNITE_LIBS}${SEP}${file}/target/libs/*
-            fi
-        fi
-    done
-}
-
-#
-# Include target libraries for enterprise modules to classpath.
-#
-includeToClassPath modules
-
-#
-# Include target libraries for opensourse modules to classpath.
-#
-includeToClassPath ${IGNITE_HOME}/modules

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/dev-tools/.gitignore
----------------------------------------------------------------------
diff --git a/dev-tools/.gitignore b/dev-tools/.gitignore
new file mode 100644
index 0000000..3036616
--- /dev/null
+++ b/dev-tools/.gitignore
@@ -0,0 +1,2 @@
+validated-jira.txt
+.gradle

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/dev-tools/build.gradle
----------------------------------------------------------------------
diff --git a/dev-tools/build.gradle b/dev-tools/build.gradle
new file mode 100644
index 0000000..5b089e8
--- /dev/null
+++ b/dev-tools/build.gradle
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+apply plugin: 'groovy'
+
+repositories {
+    mavenCentral()
+}
+
+dependencies {
+    compile 'org.codehaus.groovy:groovy-all:2.2.1'
+}
+
+task help {
+    println '''There are 3 interfaces to work with JIRA attachment validation tool
+    - to do the batch validation of all latest patch attachments
+      gradle slurp
+    - to grab a single JIRA's latest attachment and run test validation on it
+      JIRA_NUM=INGITE-### gradle patchapply
+    - to run all test builds for a single JIRA's latest attachment and run test validation on it
+      JIRA_NUM=INGITE-### gradle runAllBuilds'''
+}
+
+task slurp(dependsOn: 'classes', type: JavaExec) {
+    args(project.buildDir, "slurp")
+    main = 'jiraslurp'
+    classpath = sourceSets.main.runtimeClasspath
+}
+
+task patchapply(dependsOn: 'classes', type: JavaExec) {
+    args("patchApply,${System.getenv('JIRA_NUM')}")
+    main = 'jiraslurp'
+    classpath = sourceSets.main.runtimeClasspath
+}
+
+task runAllBuilds(dependsOn: 'classes', type: JavaExec) {
+    args("runAllBuilds,${System.getenv('JIRA_NUM')}")
+    main = 'jiraslurp'
+    classpath = sourceSets.main.runtimeClasspath
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/dev-tools/gradle/wrapper/gradle-wrapper.properties
----------------------------------------------------------------------
diff --git a/dev-tools/gradle/wrapper/gradle-wrapper.properties b/dev-tools/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..b85fc63
--- /dev/null
+++ b/dev-tools/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,20 @@
+# 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.
+  
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/dev-tools/gradlew
----------------------------------------------------------------------
diff --git a/dev-tools/gradlew b/dev-tools/gradlew
new file mode 100755
index 0000000..aa08fcb
--- /dev/null
+++ b/dev-tools/gradlew
@@ -0,0 +1,233 @@
+#!/usr/bin/env bash
+
+# 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.
+
+##
+## Tries to recreate Gradle's gradlew command in pure bash.
+## This way you don't have to worry about binaries in your build.
+##
+## Depdencies
+## unzip
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+bin=`dirname "$0"`
+bin=`cd "$bin">/dev/null; pwd`
+
+if [ -e "$bin/gradle/wrapper/gradle-wrapper.properties" ]; then
+  . "$bin/gradle/wrapper/gradle-wrapper.properties"
+else
+  # the location that the wrapper is at doesn't have a properties
+  # check PWD, gradlew may be shared
+  if [ -e "$PWD/gradle/wrapper/gradle-wrapper.properties" ]; then
+    . "$PWD/gradle/wrapper/gradle-wrapper.properties"
+  else
+    echo "Unable to locate gradle-wrapper.properties.  Not at $PWD/gradle/wrapper/gradle-wrapper.properties or $bin/gradle/wrapper/gradle-wrapper.properties" 1>&2
+    exit 1
+  fi
+fi
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# does not match gradle's hash
+# waiting for http://stackoverflow.com/questions/26642077/java-biginteger-in-bash-rewrite-gradlew
+hash() {
+  local input="$1"
+  if $darwin; then
+    md5 -q -s "$1"
+  else
+    echo -n "$1" | md5sum  | cut -d" " -f1
+  fi
+}
+
+dist_path() {
+  local dir=$(basename $distributionUrl | sed 's;.zip;;g')
+  local id=$(hash "$distributionUrl")
+
+  echo "$HOME/.gradle/${distributionPath:-wrapper/dists}/$dir/$id"
+}
+
+zip_path() {
+  local dir=$(basename $distributionUrl | sed 's;.zip;;g')
+  local id=$(hash "$distributionUrl")
+
+  echo "$HOME/.gradle/${zipStorePath:-wrapper/dists}/$dir/$id"
+}
+
+download() {
+  local base_path=$(dist_path)
+  local file_name=$(basename $distributionUrl)
+  local dir_name=$(echo "$file_name" | sed 's;-bin.zip;;g' | sed 's;-src.zip;;g' |sed 's;-all.zip;;g')
+
+  if [ ! -d "$base_path" ]; then
+    mkdir -p "$base_path"
+  else
+    # if data already exists, it means we failed to do this before
+    # so cleanup last run and try again
+    rm -rf $base_path/*
+  fi
+
+  # download dist. curl on mac doesn't like the cert provided...
+  local zip_path=$(zip_path)
+  curl --insecure -L -o "$zip_path/$file_name" "$distributionUrl"
+
+  pushd "$base_path"
+    touch "$file_name.lck"
+    unzip "$zip_path/$file_name" 1> /dev/null
+    touch "$file_name.ok"
+  popd
+}
+
+is_cached() {
+  local file_name=$(basename $distributionUrl)
+
+  [ -e "$(dist_path)/$file_name.ok" ]
+}
+
+lib_path() {
+  local base_path=$(dist_path)
+  local file_name=$(basename $distributionUrl | sed 's;-bin.zip;;g' | sed 's;-src.zip;;g' |sed 's;-all.zip;;g')
+
+  echo "$base_path/$file_name/lib"
+}
+
+classpath() {
+  local dir=$(lib_path)
+  local cp=$(ls -1 $dir/*.jar | tr '\n' ':')
+  echo "$dir:$cp"
+}
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+  JVM_OPTS=("$@")
+}
+
+main() {
+  if ! is_cached; then
+    download
+  fi
+
+  eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+
+  exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath $(classpath) org.gradle.launcher.GradleMain "$@"
+  #$JAVACMD "${JVM_OPTS[@]}" -cp $(classpath) org.gradle.launcher.GradleMain "$@"
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+main "$@"


[08/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest.java
new file mode 100644
index 0000000..4392365
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.distributed.near;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests partitioned cache with off-heap tiered mode.
+ */
+public class GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest extends GridCachePartitionedOffHeapMultiNodeFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+
+    /**
+    * @throws Exception If failed.
+    */
+    public void testPut() throws Exception {
+        IgniteCache<String, Integer> cache = grid(0).cache(null);
+
+        assert gridCount() > 3;
+        String key = null;
+
+        for (int i = 0; i < 250; ++i) {
+            String testKey = "key_" + i;
+
+            if (!grid(0).affinity(null).isPrimaryOrBackup(grid(0).localNode(), testKey)) {
+                key = testKey;
+
+                break;
+            }
+        }
+
+        assert key != null;
+
+        IgniteCache<String, Integer> primaryCache = primaryCache(key);
+
+        assertFalse(grid(0).affinity(null).isPrimary(grid(0).localNode(), key));
+        assertFalse(grid(0).affinity(null).isBackup(grid(0).localNode(), key));
+
+        primaryCache.put(key, 4); // Put from primary.
+
+        assertNull(primaryCache.localPeek(key, CachePeekMode.ONHEAP));
+        assertEquals(4, primaryCache.localPeek(key, CachePeekMode.OFFHEAP).intValue());
+
+        cache.put(key, 5); // Put from near to add reader on primary.
+
+        assertEquals(5, primaryCache.localPeek(key, CachePeekMode.ONHEAP).intValue());
+        assertEquals(5, primaryCache.localPeek(key, CachePeekMode.OFFHEAP).intValue());
+        assertEquals(5, cache.get(key).intValue());
+        assertEquals(5, map.get(key));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOptimisticTxNodeRestartTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOptimisticTxNodeRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOptimisticTxNodeRestartTest.java
index 62dfaa9..82da2ac 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOptimisticTxNodeRestartTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedOptimisticTxNodeRestartTest.java
@@ -42,8 +42,8 @@ public class GridCachePartitionedOptimisticTxNodeRestartTest extends GridCacheAb
         cc.setCacheMode(PARTITIONED);
         cc.setWriteSynchronizationMode(FULL_ASYNC);
         cc.setStartSize(20);
-        cc.setRebalanceMode(preloadMode);
-        cc.setRebalanceBatchSize(preloadBatchSize);
+        cc.setRebalanceMode(rebalancMode);
+        cc.setRebalanceBatchSize(rebalancBatchSize);
         cc.setAffinity(new RendezvousAffinityFunction(false, partitions));
         cc.setBackups(backups);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxSalvageSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxSalvageSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxSalvageSelfTest.java
index 5072642..6192f39 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxSalvageSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxSalvageSelfTest.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.internal.processors.cache.distributed.near;
 
 import org.apache.ignite.*;
-import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.affinity.rendezvous.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
@@ -35,6 +34,8 @@ import org.apache.ignite.transactions.*;
 import java.util.*;
 
 import static org.apache.ignite.IgniteSystemProperties.*;
+import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.cache.CacheRebalanceMode.*;
 import static org.apache.ignite.transactions.TransactionConcurrency.*;
 import static org.apache.ignite.transactions.TransactionIsolation.*;
 
@@ -76,10 +77,10 @@ public class GridCachePartitionedTxSalvageSelfTest extends GridCommonAbstractTes
 
         CacheConfiguration cc = defaultCacheConfiguration();
 
-        cc.setCacheMode(CacheMode.PARTITIONED);
+        cc.setCacheMode(PARTITIONED);
         cc.setAffinity(new RendezvousAffinityFunction(false, 18));
         cc.setBackups(1);
-        cc.setRebalanceMode(CacheRebalanceMode.SYNC);
+        cc.setRebalanceMode(SYNC);
 
         c.setCacheConfiguration(cc);
 
@@ -109,8 +110,9 @@ public class GridCachePartitionedTxSalvageSelfTest extends GridCommonAbstractTes
 
     /** {@inheritDoc} */
     @Override protected void afterTest() throws Exception {
-        // Shutwodn the gird.
         stopAllGrids();
+
+        System.gc();
     }
 
     /**
@@ -145,8 +147,8 @@ public class GridCachePartitionedTxSalvageSelfTest extends GridCommonAbstractTes
      * Check whether caches has no transactions after salvage timeout.
      *
      * @param mode Transaction mode (PESSIMISTIC, OPTIMISTIC).
-     * @param prepare Whether to preapre transaction state
-     *                (i.e. call {@link org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx#prepare()}).
+     * @param prepare Whether to prepare transaction state
+     *                (i.e. call {@link IgniteInternalTx#prepare()}).
      * @throws Exception If failed.
      */
     private void checkSalvageAfterTimeout(TransactionConcurrency mode, boolean prepare) throws Exception {
@@ -164,8 +166,8 @@ public class GridCachePartitionedTxSalvageSelfTest extends GridCommonAbstractTes
      * Check whether caches still has all transactions before salvage timeout.
      *
      * @param mode Transaction mode (PESSIMISTIC, OPTIMISTIC).
-     * @param prepare Whether to preapre transaction state
-     *                (i.e. call {@link org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx#prepare()}).
+     * @param prepare Whether to prepare transaction state
+     *                (i.e. call {@link IgniteInternalTx#prepare()}).
      * @throws Exception If failed.
      */
     private void checkSalvageBeforeTimeout(TransactionConcurrency mode, boolean prepare) throws Exception {
@@ -191,8 +193,8 @@ public class GridCachePartitionedTxSalvageSelfTest extends GridCommonAbstractTes
      * Start new transaction on the grid(0) and put some keys to it.
      *
      * @param mode Transaction mode (PESSIMISTIC, OPTIMISTIC).
-     * @param prepare Whether to preapre transaction state
-     *                (i.e. call {@link org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx#prepare()}).
+     * @param prepare Whether to prepare transaction state
+     *                (i.e. call {@link IgniteInternalTx#prepare()}).
      * @throws Exception If failed.
      */
     private void startTxAndPutKeys(final TransactionConcurrency mode, final boolean prepare) throws Exception {
@@ -210,9 +212,8 @@ public class GridCachePartitionedTxSalvageSelfTest extends GridCommonAbstractTes
                     for (Integer key : keys)
                         c.put(key, "val" + key);
 
-                    // Unproxy.
                     if (prepare)
-                        U.<IgniteInternalTx>field(tx, "tx").prepare();
+                        ((TransactionProxyImpl)tx).tx().prepare();
                 }
                 catch (IgniteCheckedException e) {
                     info("Failed to put keys to cache: " + e.getMessage());

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java
new file mode 100644
index 0000000..88e7f03
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java
@@ -0,0 +1,190 @@
+/*
+ * 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.distributed.near;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.transactions.*;
+
+import java.util.concurrent.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.transactions.TransactionConcurrency.*;
+import static org.apache.ignite.transactions.TransactionIsolation.*;
+
+/**
+ *
+ */
+public class IgniteCacheNearOnlyTxTest extends IgniteCacheAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 2;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        if (getTestGridName(1).equals(gridName)) {
+            cfg.setClientMode(true);
+
+            cfg.setCacheConfiguration();
+        }
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNearOnlyPutMultithreaded() throws Exception {
+        final Ignite ignite1 = ignite(1);
+
+        assertTrue(ignite1.configuration().isClientMode());
+
+        ignite1.createNearCache(null, new NearCacheConfiguration<>());
+
+        GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                IgniteCache cache = ignite1.cache(null);
+
+                int key = 1;
+
+                for (int i = 0; i < 100; i++)
+                    cache.put(key, 1);
+
+                return null;
+            }
+        }, 5, "put-thread");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimisticTx() throws Exception {
+        txMultithreaded(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPessimisticTx() throws Exception {
+        txMultithreaded(false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void txMultithreaded(final boolean optimistic) throws Exception {
+        final Ignite ignite1 = ignite(1);
+
+        assertTrue(ignite1.configuration().isClientMode());
+
+        ignite1.createNearCache(null, new NearCacheConfiguration<>());
+
+        GridTestUtils.runMultiThreaded(new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                IgniteCache cache = ignite1.cache(null);
+
+                int key = 1;
+
+                IgniteTransactions txs = ignite1.transactions();
+
+                for (int i = 0; i < 100; i++) {
+                    try (Transaction tx = txs.txStart(optimistic ? OPTIMISTIC : PESSIMISTIC, REPEATABLE_READ)) {
+                        cache.get(key);
+
+                        cache.put(key, 1);
+
+                        tx.commit();
+                    }
+                }
+
+                return null;
+            }
+        }, 5, "put-thread");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConcurrentTx() throws Exception {
+        final Ignite ignite1 = ignite(1);
+
+        assertTrue(ignite1.configuration().isClientMode());
+
+        ignite1.createNearCache(null, new NearCacheConfiguration<>());
+
+        IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                IgniteCache cache = ignite1.cache(null);
+
+                int key = 1;
+
+                for (int i = 0; i < 100; i++)
+                    cache.put(key, 1);
+
+                return null;
+            }
+        }, 5, "put1-thread");
+
+        IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                IgniteCache cache = ignite1.cache(null);
+
+                int key = 1;
+
+                IgniteTransactions txs = ignite1.transactions();
+
+                for (int i = 0; i < 100; i++) {
+                    try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                        cache.get(key);
+
+                        cache.put(key, 1);
+
+                        tx.commit();
+                    }
+                }
+
+                return null;
+            }
+        }, 5, "put2-thread");
+
+        fut1.get();
+        fut2.get();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/NoneRebalanceModeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/NoneRebalanceModeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/NoneRebalanceModeSelfTest.java
new file mode 100644
index 0000000..d61ddcc
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/NoneRebalanceModeSelfTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.distributed.near;
+
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import static org.apache.ignite.cache.CacheRebalanceMode.*;
+import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.*;
+
+/**
+ * Test none rebalance mode.
+ */
+public class NoneRebalanceModeSelfTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @SuppressWarnings({"ConstantConditions"})
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration c = super.getConfiguration(gridName);
+
+        CacheConfiguration cc = defaultCacheConfiguration();
+
+        cc.setRebalanceMode(NONE);
+
+        c.setCacheConfiguration(cc);
+
+        return c;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRemoveAll() throws Exception {
+        GridNearTransactionalCache cache = (GridNearTransactionalCache)((IgniteKernal)grid(0)).internalCache(null);
+
+        for (GridDhtLocalPartition part : cache.dht().topology().localPartitions())
+            assertEquals(MOVING, part.state());
+
+        grid(0).cache(null).removeAll();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedFailoverSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedFailoverSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedFailoverSelfTest.java
index 326f57d..3461dd4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedFailoverSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedFailoverSelfTest.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.cache.distributed.replicated;
 
 import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.processors.cache.*;
 
 import static org.apache.ignite.cache.CacheMode.*;
@@ -30,4 +31,9 @@ public class GridCacheReplicatedFailoverSelfTest extends GridCacheAbstractFailov
     @Override protected CacheMode cacheMode() {
         return REPLICATED;
     }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedLockSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedLockSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedLockSelfTest.java
index 97df1f0..510fa0c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedLockSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedLockSelfTest.java
@@ -30,4 +30,9 @@ public class GridCacheReplicatedLockSelfTest extends GridCacheLockAbstractTest {
     @Override protected CacheMode cacheMode() {
         return REPLICATED;
     }
+
+    /** {@inheritDoc} */
+    @Override public void testLockReentrancy() throws Throwable {
+        fail("https://issues.apache.org/jira/browse/IGNITE-835");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedNodeRestartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedNodeRestartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedNodeRestartSelfTest.java
index aa32559..8ce96cd 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedNodeRestartSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedNodeRestartSelfTest.java
@@ -34,6 +34,8 @@ public class GridCacheReplicatedNodeRestartSelfTest extends GridCacheAbstractNod
 
         CacheConfiguration cc = defaultCacheConfiguration();
 
+        cc.setNearConfiguration(null);
+
         cc.setAtomicityMode(atomicityMode());
 
         cc.setName(CACHE_NAME);
@@ -52,4 +54,84 @@ public class GridCacheReplicatedNodeRestartSelfTest extends GridCacheAbstractNod
 
         return c;
     }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithPutTwoNodesNoBackups() throws Throwable {
+        super.testRestartWithPutTwoNodesNoBackups();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithPutTwoNodesOneBackup() throws Throwable {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithPutFourNodesOneBackups() throws Throwable {
+        super.testRestartWithPutFourNodesOneBackups();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithPutFourNodesNoBackups() throws Throwable {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithPutSixNodesTwoBackups() throws Throwable {
+        super.testRestartWithPutSixNodesTwoBackups();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithPutEightNodesTwoBackups() throws Throwable {
+        super.testRestartWithPutEightNodesTwoBackups();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithPutTenNodesTwoBackups() throws Throwable {
+        super.testRestartWithPutTenNodesTwoBackups();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithTxTwoNodesNoBackups() throws Throwable {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithTxTwoNodesOneBackup() throws Throwable {
+        super.testRestartWithTxTwoNodesOneBackup();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithTxFourNodesOneBackups() throws Throwable {
+        super.testRestartWithTxFourNodesOneBackups();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithTxFourNodesNoBackups() throws Throwable {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithTxSixNodesTwoBackups() throws Throwable {
+        super.testRestartWithTxSixNodesTwoBackups();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithTxEightNodesTwoBackups() throws Throwable {
+        super.testRestartWithTxEightNodesTwoBackups();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithTxTenNodesTwoBackups() throws Throwable {
+        super.testRestartWithTxTenNodesTwoBackups();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithTxPutAllTenNodesTwoBackups() throws Throwable {
+        super.testRestartWithTxPutAllTenNodesTwoBackups();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testRestartWithTxPutAllFourNodesTwoBackups() throws Throwable {
+        super.testRestartWithTxPutAllFourNodesTwoBackups();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapFullApiSelfTest.java
index c9b9072..1cb5df5 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapFullApiSelfTest.java
@@ -17,12 +17,16 @@
 
 package org.apache.ignite.internal.processors.cache.distributed.replicated;
 
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
 /**
  * Tests replicated cache with values being stored off-heap.
  */
 public class GridCacheReplicatedOffHeapFullApiSelfTest extends GridCacheReplicatedFullApiSelfTest {
     /** {@inheritDoc} */
-    @Override protected boolean offHeapValues() {
-        return true;
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_VALUES;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapMultiNodeFullApiSelfTest.java
index 382b0f9..f79f898 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapMultiNodeFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapMultiNodeFullApiSelfTest.java
@@ -17,12 +17,16 @@
 
 package org.apache.ignite.internal.processors.cache.distributed.replicated;
 
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
 /**
  * Tests replicated cache with values being stored off-heap.
  */
 public class GridCacheReplicatedOffHeapMultiNodeFullApiSelfTest extends GridCacheReplicatedMultiNodeFullApiSelfTest {
     /** {@inheritDoc} */
-    @Override protected boolean offHeapValues() {
-        return true;
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_VALUES;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapTieredFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapTieredFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapTieredFullApiSelfTest.java
new file mode 100644
index 0000000..8162c8e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapTieredFullApiSelfTest.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.replicated;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests replicated cache with off-heap tiered mode.
+ */
+public class GridCacheReplicatedOffHeapTieredFullApiSelfTest extends
+    GridCacheReplicatedOffHeapFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapTieredMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapTieredMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapTieredMultiNodeFullApiSelfTest.java
new file mode 100644
index 0000000..0e2bf90
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedOffHeapTieredMultiNodeFullApiSelfTest.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.replicated;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests replicated cache with off-heap tiered mode.
+ */
+public class GridCacheReplicatedOffHeapTieredMultiNodeFullApiSelfTest extends
+    GridCacheReplicatedOffHeapMultiNodeFullApiSelfTest{
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicyCacheSizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicyCacheSizeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicyCacheSizeSelfTest.java
new file mode 100644
index 0000000..e9e7228
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicyCacheSizeSelfTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.eviction.random;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.eviction.random.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+/**
+ * Random eviction policy cache size test.
+ */
+public class RandomEvictionPolicyCacheSizeSelfTest extends GridCommonAbstractTest {
+    /** Grid count. */
+    private static final int GRID_CNT = 3;
+
+    /** Keys count. */
+    private static final int KEYS_CNT = 50;
+
+    /** Policy max size. */
+    private static final int PLC_MAX_SIZE = 10;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(GRID_CNT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration ccfg = defaultCacheConfiguration();
+        ccfg.setNearConfiguration(null);
+        ccfg.setEvictionPolicy(new RandomEvictionPolicy(PLC_MAX_SIZE));
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSize() throws Exception {
+        IgniteCache<Integer, Integer> cache = grid(0).cache(null);
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.put(i, i);
+
+        assertEquals(PLC_MAX_SIZE * GRID_CNT, cache.size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java
index 1e937ea..b74a373 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java
@@ -1047,7 +1047,7 @@ public abstract class IgniteCacheExpiryPolicyAbstractTest extends IgniteCacheAbs
             if (e != null && e.deleted()) {
                 assertEquals(0, e.ttl());
 
-                assertTrue(!cache.affinity().isPrimaryOrBackup(grid.localNode(), key));
+                assertFalse(cache.affinity().isPrimaryOrBackup(grid.localNode(), key));
 
                 continue;
             }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java
index 3a87d6d..c006f69 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java
@@ -48,6 +48,8 @@ public class IgniteCacheExpiryPolicyTestSuite extends TestSuite {
 
         suite.addTestSuite(IgniteCacheExpiryStoreLoadSelfTest.class);
 
+        suite.addTestSuite(IgniteCacheTtlCleanupSelfTest.class);
+
         return suite;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java
new file mode 100644
index 0000000..c0e4189
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.expiry;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.affinity.rendezvous.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.internal.processors.cacheobject.*;
+
+import javax.cache.expiry.*;
+import java.util.concurrent.*;
+
+/**
+ *
+ */
+public class IgniteCacheTtlCleanupSelfTest extends GridCacheAbstractSelfTest {
+    /** Number of partitions. */
+    private static final int PART_NUM = 10;
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
+        CacheConfiguration ccfg = super.cacheConfiguration(gridName);
+
+        ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+
+        ccfg.setAffinity(new RendezvousAffinityFunction(false, 10));
+
+        ccfg.setNearConfiguration(null);
+
+        return ccfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDeferredDeleteTtl() throws Exception {
+        IgniteCache<Object, Object> cache = grid(0).cache(null)
+            .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5)));
+
+        int cnt = GridDhtLocalPartition.MAX_DELETE_QUEUE_SIZE / PART_NUM + 100;
+
+        for (long i = 0; i < cnt; i++)
+            grid(0).cache(null).put(i * PART_NUM, i);
+
+        for (int i = 0; i < cnt; i++)
+            cache.put(i * PART_NUM, i);
+
+        // Wait 5 seconds.
+        Thread.sleep(6_000);
+
+        assertEquals(cnt, grid(0).cache(null).size());
+
+        GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal)grid(0)).internalCache(null);
+
+        IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects();
+
+        CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext();
+
+        for (int i = 0; i < 100; i++)
+            assertNull(cacheAdapter.map().getEntry(cacheObjects.toCacheKeyObject(cacheObjCtx, i, true)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalAtomicOffHeapTieredFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalAtomicOffHeapTieredFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalAtomicOffHeapTieredFullApiSelfTest.java
new file mode 100644
index 0000000..b4e8cf1
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalAtomicOffHeapTieredFullApiSelfTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.local;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests local cache in atomic mode with off-heap tiered mode.
+ */
+public class GridCacheLocalAtomicOffHeapTieredFullApiSelfTest extends GridCacheLocalAtomicOffHeapFullApiSelfTest{
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalIsolatedNodesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalIsolatedNodesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalIsolatedNodesSelfTest.java
index dbfdc86..ee42ddb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalIsolatedNodesSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalIsolatedNodesSelfTest.java
@@ -40,7 +40,7 @@ public class GridCacheLocalIsolatedNodesSelfTest extends GridCommonAbstractTest
 
     /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
-        startGrids(2);
+        startGrids(3);
     }
 
     /** {@inheritDoc} */
@@ -59,7 +59,11 @@ public class GridCacheLocalIsolatedNodesSelfTest extends GridCommonAbstractTest
         Ignite g2 = grid(1);
         UUID nid2 = g2.cluster().localNode().id();
 
+        Ignite g3 = grid(2);
+        UUID nid3 = g3.cluster().localNode().id();
+
         assert !nid1.equals(nid2);
+        assert !nid1.equals(nid3);
 
         // Local cache on first node only.
         CacheConfiguration<String, String> ccfg1 = new CacheConfiguration<>("A");
@@ -77,8 +81,20 @@ public class GridCacheLocalIsolatedNodesSelfTest extends GridCommonAbstractTest
         IgniteCache<String, String> c2 = g2.createCache(ccfg2);
         c2.put("g2", "c2");
 
+        // Local cache on third node only.
+        CacheConfiguration<String, String> ccfg3 = new CacheConfiguration<>("A");
+        ccfg3.setCacheMode(LOCAL);
+        ccfg3.setNodeFilter(new NodeIdFilter(nid3));
+
+        IgniteCache<String, String> c3 = g3.createCache(ccfg3);
+        c3.put("g3", "c3");
+
         assertNull(c1.get("g2"));
+        assertNull(c1.get("g3"));
         assertNull(c2.get("g1"));
+        assertNull(c2.get("g3"));
+        assertNull(c3.get("g1"));
+        assertNull(c3.get("g2"));
     }
 
     /** Filter by node ID. */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalOffHeapFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalOffHeapFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalOffHeapFullApiSelfTest.java
index 31b8bee..e2621ce 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalOffHeapFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalOffHeapFullApiSelfTest.java
@@ -17,12 +17,14 @@
 
 package org.apache.ignite.internal.processors.cache.local;
 
+import org.apache.ignite.cache.*;
+
 /**
  * Tests local cache with values being stored offheap.
  */
 public class GridCacheLocalOffHeapFullApiSelfTest extends GridCacheLocalFullApiSelfTest {
     /** {@inheritDoc} */
-    @Override protected boolean offHeapValues() {
-        return true;
+    @Override protected CacheMemoryMode memoryMode() {
+        return CacheMemoryMode.OFFHEAP_VALUES;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalOffHeapTieredFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalOffHeapTieredFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalOffHeapTieredFullApiSelfTest.java
new file mode 100644
index 0000000..c6ce9da
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalOffHeapTieredFullApiSelfTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.local;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+
+/**
+ * Tests local cache with off-heap tired memory mode.
+ */
+public class GridCacheLocalOffHeapTieredFullApiSelfTest extends GridCacheLocalOffHeapFullApiSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMemoryMode memoryMode() {
+        return OFFHEAP_TIERED;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsClientCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsClientCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsClientCacheSelfTest.java
new file mode 100644
index 0000000..d983302
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsClientCacheSelfTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.igfs;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.igfs.*;
+import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ * Test for igfs with nodes in client mode (see {@link IgniteConfiguration#setClientMode(boolean)}.
+ */
+public class IgfsClientCacheSelfTest extends IgfsAbstractSelfTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** Meta-information cache name. */
+    private static final String META_CACHE_NAME = "meta";
+
+    /** Data cache name. */
+    private static final String DATA_CACHE_NAME = null;
+
+    /** Regular cache name. */
+    private static final String CACHE_NAME = "cache";
+
+    /**
+     * Constructor.
+     */
+    public IgfsClientCacheSelfTest() {
+        super(IgfsMode.PRIMARY);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        igfsSecondaryFileSystem = createSecondaryFileSystemStack();
+
+        Ignite ignite1 = G.start(getConfiguration(getTestGridName(1)));
+
+        igfs = (IgfsImpl) ignite1.fileSystem("igfs");
+    }
+
+    /**{@inheritDoc} */
+    protected IgfsSecondaryFileSystem createSecondaryFileSystemStack() throws Exception {
+        Ignite igniteSecondary = G.start(getConfiguration(getTestGridName(0)));
+
+        IgfsEx secondaryIgfsImpl = (IgfsEx)igniteSecondary.fileSystem("igfs");
+
+        igfsSecondary = new IgfsExUniversalFileSystemAdapter(secondaryIgfsImpl);
+
+        return secondaryIgfsImpl.asSecondary();
+    }
+
+    /**
+     *
+     * @param gridName Grid name.
+     * @return Ignite configuration.
+     * @throws Exception If failed.
+     */
+    protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(cacheConfiguration(META_CACHE_NAME), cacheConfiguration(DATA_CACHE_NAME),
+            cacheConfiguration(CACHE_NAME));
+
+        if (!gridName.equals(getTestGridName(0)))
+            cfg.setClientMode(true);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(disco);
+
+        FileSystemConfiguration igfsCfg = new FileSystemConfiguration();
+
+        igfsCfg.setMetaCacheName(META_CACHE_NAME);
+        igfsCfg.setDataCacheName(DATA_CACHE_NAME);
+        igfsCfg.setName("igfs");
+
+        cfg.setFileSystemConfiguration(igfsCfg);
+
+        return cfg;
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @return Cache configuration.
+     */
+    protected CacheConfiguration cacheConfiguration(String cacheName) {
+        CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+        cacheCfg.setName(cacheName);
+
+        if (META_CACHE_NAME.equals(cacheName))
+            cacheCfg.setCacheMode(REPLICATED);
+        else {
+            cacheCfg.setCacheMode(PARTITIONED);
+            cacheCfg.setNearConfiguration(null);
+
+            cacheCfg.setBackups(0);
+            cacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(128));
+        }
+
+        cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+        cacheCfg.setAtomicityMode(TRANSACTIONAL);
+
+        return cacheCfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsOneClientNodeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsOneClientNodeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsOneClientNodeTest.java
new file mode 100644
index 0000000..49ddb03
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsOneClientNodeTest.java
@@ -0,0 +1,133 @@
+/*
+ * 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.igfs;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.igfs.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.concurrent.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ * Test for igfs with one node in client mode.
+ */
+public class IgfsOneClientNodeTest extends GridCommonAbstractTest {
+    /** Meta-information cache name. */
+    private static final String META_CACHE_NAME = "meta";
+
+    /** Data cache name. */
+    private static final String DATA_CACHE_NAME = null;
+
+    /** Regular cache name. */
+    private static final String CACHE_NAME = "cache";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(cacheConfiguration(META_CACHE_NAME), cacheConfiguration(DATA_CACHE_NAME),
+            cacheConfiguration(CACHE_NAME));
+
+        cfg.setClientMode(true);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        FileSystemConfiguration igfsCfg = new FileSystemConfiguration();
+
+        igfsCfg.setMetaCacheName(META_CACHE_NAME);
+        igfsCfg.setDataCacheName(DATA_CACHE_NAME);
+        igfsCfg.setName("igfs");
+
+        cfg.setFileSystemConfiguration(igfsCfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    protected CacheConfiguration cacheConfiguration(String cacheName) {
+        CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+        cacheCfg.setName(cacheName);
+
+        cacheCfg.setCacheMode(PARTITIONED);
+
+        cacheCfg.setBackups(0);
+        cacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(128));
+
+        cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+        cacheCfg.setAtomicityMode(TRANSACTIONAL);
+
+        return cacheCfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        startGrids(1);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStartIgfs() throws Exception {
+
+        final IgfsImpl igfs = (IgfsImpl) grid(0).fileSystem("igfs");
+
+        GridTestUtils.assertThrows(log, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                IgfsAbstractSelfTest.create(igfs, new IgfsPath[]{new IgfsPath("/dir")}, null);
+                return null;
+            }
+        }, IgfsException.class, "Cache server nodes not found.");
+
+        GridTestUtils.assertThrows(log, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                IgfsPath FILE = new IgfsPath(new IgfsPath("/dir"), "file");
+
+                igfs.delete(FILE, false);
+
+                return null;
+            }
+        }, IgfsException.class, "Cache server nodes not found.");
+
+        GridTestUtils.assertThrows(log, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                IgfsPath FILE = new IgfsPath(new IgfsPath("/dir"), "file");
+
+                igfs.append(FILE, true);
+
+                return null;
+            }
+        }, IgfsException.class, "Cache server nodes not found.");
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsStreamsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsStreamsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsStreamsSelfTest.java
index 57b1010..d377560 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsStreamsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsStreamsSelfTest.java
@@ -154,7 +154,7 @@ public class IgfsStreamsSelfTest extends IgfsCommonAbstractTest {
      */
     public void testConfiguration() throws IgniteCheckedException {
         IgniteInternalCache metaCache = getFieldValue(fs, "meta", "metaCache");
-        GridCacheAdapter dataCache = getFieldValue(fs, "data", "dataCache");
+        IgniteInternalCache dataCache = getFieldValue(fs, "data", "dataCache");
 
         assertNotNull(metaCache);
         assertEquals(META_CACHE_NAME, metaCache.name());

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
new file mode 100644
index 0000000..761f00f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
@@ -0,0 +1,245 @@
+/*
+ * 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.service;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.marshaller.optimized.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.services.Service;
+import org.apache.ignite.services.ServiceContext;
+import org.apache.ignite.services.ServiceDescriptor;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+
+/**
+ * Test that compute and service run only on server nodes by default.
+ */
+public class ClosureServiceClientsNodesTest extends GridCommonAbstractTest {
+    /** Number of grids started for tests. */
+    private static final int NODES_CNT = 4;
+
+    /** Test singleton service name. */
+    private static final String SINGLETON_NAME = "testSingleton";
+
+    /** IP finder. */
+    private final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setMarshaller(new OptimizedMarshaller(false));
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(ipFinder);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setCacheConfiguration();
+
+        if (gridName.equals(getTestGridName(0)))
+            cfg.setClientMode(true);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"ConstantConditions"})
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(NODES_CNT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDefaultClosure() throws Exception {
+        Set<String> srvNames = new HashSet<>(NODES_CNT - 1);
+
+        for (int i = 1; i < NODES_CNT; ++i)
+            srvNames.add(getTestGridName(i));
+
+        for (int i = 0 ; i < NODES_CNT; i++) {
+            Ignite ignite = grid(i);
+
+            Collection<String> res = ignite.compute().broadcast(new IgniteCallable<String>() {
+                @IgniteInstanceResource
+                Ignite ignite;
+
+                @Override public String call() throws Exception {
+                    assertFalse(ignite.configuration().isClientMode());
+
+                    return ignite.name();
+                }
+            });
+
+            assertEquals(res.size(), NODES_CNT - 1);
+
+            for (String name : res)
+                assertTrue(srvNames.contains(name));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClientClosure() throws Exception {
+        for (int i = 0 ; i < NODES_CNT; i++) {
+            Ignite ignite = grid(i);
+
+            Collection<String> res = ignite.compute(ignite.cluster().forClients()).
+                broadcast(new IgniteCallable<String>() {
+                    @IgniteInstanceResource
+                    Ignite ignite;
+
+                    @Override public String call() throws Exception {
+                        assertTrue(ignite.configuration().isClientMode());
+
+                        return ignite.name();
+                    }
+                });
+
+            assertEquals(1, res.size());
+
+            assertEquals(getTestGridName(0), F.first(res));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCustomClosure() throws Exception {
+        for (int i = 0 ; i < NODES_CNT; i++) {
+            Ignite ignite = grid(i);
+
+            Collection<String> res = ignite.compute(ignite.cluster().forPredicate(F.<ClusterNode>alwaysTrue())).
+                broadcast(new IgniteCallable<String>() {
+                    @IgniteInstanceResource
+                    Ignite ignite;
+
+                    @Override public String call() throws Exception {
+                        return ignite.name();
+                    }
+                });
+
+            assertEquals(NODES_CNT, res.size());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDefaultService() throws Exception {
+        UUID clientNodeId = grid(0).cluster().localNode().id();
+
+        for (int i = 0 ; i < NODES_CNT; i++) {
+            Ignite ignite = grid(i);
+
+            ignite.services().deployNodeSingleton(SINGLETON_NAME, new TestService());
+
+            ClusterGroup grp = ignite.cluster();
+
+            assertEquals(NODES_CNT, grp.nodes().size());
+
+            Collection<ServiceDescriptor> srvDscs = ignite.services(grp).serviceDescriptors();
+
+            assertEquals(1, srvDscs.size());
+
+            Map<UUID, Integer> nodesMap = F.first(srvDscs).topologySnapshot();
+
+            assertEquals(NODES_CNT - 1, nodesMap.size());
+
+            for (Map.Entry<UUID, Integer> nodeInfo : nodesMap.entrySet()) {
+                assertFalse(clientNodeId.equals(nodeInfo.getKey()));
+
+                assertEquals(1, nodeInfo.getValue().intValue());
+            }
+
+            ignite.services().cancelAll();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClientService() throws Exception {
+        UUID clientNodeId = grid(0).cluster().localNode().id();
+
+        for (int i = 0 ; i < NODES_CNT; i++) {
+            Ignite ignite = grid(i);
+
+            ignite.services(ignite.cluster().forClients()).deployNodeSingleton(SINGLETON_NAME, new TestService());
+
+            ClusterGroup grp = ignite.cluster();
+
+            assertEquals(NODES_CNT, grp.nodes().size());
+
+            Collection<ServiceDescriptor> srvDscs = ignite.services(grp).serviceDescriptors();
+
+            assertEquals(1, srvDscs.size());
+
+            Map<UUID, Integer> nodesMap = F.first(srvDscs).topologySnapshot();
+
+            assertEquals(1, nodesMap.size());
+
+            for (Map.Entry<UUID, Integer> nodeInfo : nodesMap.entrySet()) {
+                assertEquals(clientNodeId, nodeInfo.getKey());
+
+                assertEquals(1, nodeInfo.getValue().intValue());
+            }
+
+            ignite.services().cancelAll();
+        }
+    }
+
+    /**
+     * Test service.
+     */
+    private static class TestService implements Service {
+        @LoggerResource
+        private IgniteLogger log;
+
+        /** {@inheritDoc} */
+        @Override public void cancel(ServiceContext ctx) {
+          //No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void init(ServiceContext ctx) throws Exception {
+            //No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void execute(ServiceContext ctx) throws Exception {
+            log.info("Executing test service.");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridNioDelimitedBufferTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridNioDelimitedBufferTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridNioDelimitedBufferTest.java
new file mode 100644
index 0000000..a0dd2e5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridNioDelimitedBufferTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.util.nio;
+
+import junit.framework.TestCase;
+
+import java.nio.*;
+import java.util.*;
+
+/**
+ * Tests for {@link GridNioDelimitedBuffer}.
+ */
+public class GridNioDelimitedBufferTest extends TestCase {
+    /** */
+    private static final String ASCII = "ASCII";
+
+    /**
+     * Tests simple delimiter (excluded from alphabet)
+     */
+    public void testReadZString() throws Exception {
+        Random rnd = new Random();
+
+        int buffSize = 0;
+
+        byte[] delim = new byte[] {0};
+
+        List<String> strs = new ArrayList<>(50);
+
+        for (int i = 0; i < 50; i++) {
+            int len = rnd.nextInt(128) + 1;
+
+            buffSize += len + delim.length;
+
+            StringBuilder sb = new StringBuilder(len);
+
+            for (int j = 0; j < len; j++)
+                sb.append((char)(rnd.nextInt(26) + 'a'));
+
+
+            strs.add(sb.toString());
+        }
+
+        ByteBuffer buff = ByteBuffer.allocate(buffSize);
+
+        for (String str : strs) {
+            buff.put(str.getBytes(ASCII));
+            buff.put(delim);
+        }
+
+        buff.flip();
+
+        byte[] msg;
+
+        GridNioDelimitedBuffer delimBuff = new GridNioDelimitedBuffer(delim);
+
+        List<String> res = new ArrayList<>(strs.size());
+
+        while ((msg = delimBuff.read(buff)) != null)
+            res.add(new String(msg, ASCII));
+
+        assertEquals(strs, res);
+    }
+
+    /**
+     * Tests compound delimiter (included to alphabet)
+     */
+    public void testDelim() throws Exception {
+        byte[] delim = "aabb".getBytes(ASCII);
+
+        List<String> strs = Arrays.asList("za", "zaa", "zaab", "zab", "zaabaababbbbabaab");
+
+        int buffSize = 0;
+
+        for (String str : strs)
+            buffSize += str.length() + delim.length;
+
+        ByteBuffer buff = ByteBuffer.allocate(buffSize);
+
+        for (String str : strs) {
+            buff.put(str.getBytes(ASCII));
+            buff.put(delim);
+        }
+
+        buff.flip();
+
+        byte[] msg;
+
+        GridNioDelimitedBuffer delimBuff = new GridNioDelimitedBuffer(delim);
+
+        List<String> res = new ArrayList<>(strs.size());
+
+        while ((msg = delimBuff.read(buff)) != null)
+            res.add(new String(msg, ASCII));
+
+        assertEquals(strs, res);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/loadtest/swapspace/GridFileSwapSpaceSpiMultithreadedLoadTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/loadtest/swapspace/GridFileSwapSpaceSpiMultithreadedLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtest/swapspace/GridFileSwapSpaceSpiMultithreadedLoadTest.java
index abd80e1..d21fb13 100644
--- a/modules/core/src/test/java/org/apache/ignite/loadtest/swapspace/GridFileSwapSpaceSpiMultithreadedLoadTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/loadtest/swapspace/GridFileSwapSpaceSpiMultithreadedLoadTest.java
@@ -49,7 +49,7 @@ public class GridFileSwapSpaceSpiMultithreadedLoadTest extends GridCommonAbstrac
     private static final long MAX_ENTRIES = 9000000;
 
     /** Test duration. */
-    private static final long DURATION = 10 * 60 * 1000;
+    private static final long DURATION = 2 * 60 * 1000;
 
     /** Swap context. */
     private final SwapContext swapCtx = new SwapContext();
@@ -73,7 +73,7 @@ public class GridFileSwapSpaceSpiMultithreadedLoadTest extends GridCommonAbstrac
     /**
      * @return An SPI instance to test.
      */
-    private SwapSpaceSpi spi() {
+    protected SwapSpaceSpi spi() {
         FileSwapSpaceSpi spi = new FileSwapSpaceSpi();
 
 //        spi.setConcurrencyLevel(N_THREADS);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySelfTest.java
index 09cbd97..0c9f2f2 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySelfTest.java
@@ -275,9 +275,12 @@ public class TcpClientDiscoverySelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * TODO: IGNITE-587.
      * @throws Exception If failed.
      */
     public void testClientReconnect() throws Exception {
+        fail("ignite-587");
+
         clientsPerSrv = 1;
 
         startServerNodes(3);
@@ -318,9 +321,12 @@ public class TcpClientDiscoverySelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * TODO: IGNITE-587.
      * @throws Exception If failed.
      */
     public void testClientNodeLeaveOneServer() throws Exception {
+        fail("ignite-587");
+
         startServerNodes(1);
         startClientNodes(1);
 
@@ -430,6 +436,8 @@ public class TcpClientDiscoverySelfTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     public void testDataExchangeFromClient() throws Exception {
+        fail("ignite-587");
+
         testDataExchange("client-0");
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryRestartTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryRestartTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryRestartTest.java
new file mode 100644
index 0000000..e6bee4a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryRestartTest.java
@@ -0,0 +1,199 @@
+/*
+ * 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.spi.discovery.tcp;
+
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.events.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.eclipse.jetty.util.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+import static org.apache.ignite.events.EventType.*;
+
+/**
+ *
+ */
+public class TcpDiscoveryRestartTest extends GridCommonAbstractTest {
+    /** */
+    private TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static AtomicReference<String> err;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi spi = new TcpDiscoverySpi();
+
+        spi.setIpFinder(ipFinder);
+
+        cfg.setDiscoverySpi(spi);
+
+        int[] evts = {EVT_NODE_JOINED, EVT_NODE_FAILED, EVT_NODE_LEFT};
+
+        cfg.setIncludeEventTypes(evts);
+
+        Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();
+
+        lsnrs.put(new TestEventListener(), evts);
+
+        cfg.setLocalEventListeners(lsnrs);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRestart() throws Exception {
+        err = new AtomicReference<>();
+
+        final int NODE_CNT = 3;
+
+        startGrids(NODE_CNT);
+
+        final ConcurrentHashSet<UUID> nodeIds = new ConcurrentHashSet<>();
+
+        final AtomicInteger id = new AtomicInteger(NODE_CNT);
+
+        final IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                int nodeIdx = id.getAndIncrement();
+
+                for (int i = 0; i < 10 && err.get() == null; i++) {
+                    Ignite ignite = startGrid(nodeIdx);
+
+                    UUID nodeId = ignite.cluster().localNode().id();
+
+                    if (!nodeIds.add(nodeId))
+                        failed("Duplicated node ID: " + nodeId);
+
+                    stopGrid(nodeIdx);
+                }
+
+                return null;
+            }
+        }, 5, "restart-thread");
+
+        IgniteInternalFuture<?> loadFut = GridTestUtils.runMultiThreadedAsync(new Callable<Long>() {
+            @Override public Long call() throws Exception {
+                long dummyRes = 0;
+
+                List<String> list = new ArrayList<>();
+
+                while (!fut.isDone()) {
+                    for (int i = 0; i < 100; i++) {
+                        String str = new String(new byte[i]);
+
+                        list.add(str);
+
+                        dummyRes += str.hashCode();
+                    }
+
+                    if (list.size() > 1000_000) {
+                        list = new ArrayList<>();
+
+                        System.gc();
+                    }
+                }
+
+                return dummyRes;
+            }
+        }, 2, "test-load");
+
+        fut.get();
+
+        loadFut.get();
+
+        assertNull(err.get());
+
+        for (int i = 0; i < NODE_CNT; i++) {
+            Ignite ignite = ignite(i);
+
+            TestEventListener lsnr = (TestEventListener)F.firstKey(ignite.configuration().getLocalEventListeners());
+
+            assertNotNull(lsnr);
+
+            for (UUID nodeId : nodeIds)
+                lsnr.checkEvents(nodeId);
+        }
+    }
+
+
+    /**
+     * @param msg Message.
+     */
+    private void failed(String msg) {
+        info(msg);
+
+        err.compareAndSet(null, msg);
+    }
+
+    /**
+     *
+     */
+    private class TestEventListener implements IgnitePredicate<Event> {
+        /** */
+        private final ConcurrentHashSet<UUID> joinIds = new ConcurrentHashSet<>();
+
+        /** */
+        private final ConcurrentHashSet<UUID> leftIds = new ConcurrentHashSet<>();
+
+        /** {@inheritDoc} */
+        @Override public boolean apply(Event evt) {
+            DiscoveryEvent evt0 = (DiscoveryEvent)evt;
+
+            if (evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT) {
+                if (!leftIds.add(evt0.eventNode().id()))
+                    failed("Duplicated failed node ID: " + evt0.eventNode().id());
+            }
+            else {
+                assertEquals(EVT_NODE_JOINED, evt.type());
+
+                if (!joinIds.add(evt0.eventNode().id()))
+                    failed("Duplicated joined node ID: " + evt0.eventNode().id());
+            }
+
+            return true;
+        }
+
+        /**
+         * @param nodeId Node ID.
+         */
+        void checkEvents(UUID nodeId) {
+            assertTrue("No join event: " + nodeId, joinIds.contains(nodeId));
+
+            assertTrue("No left event: " + nodeId, leftIds.contains(nodeId));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
index 7bea1eb..5648c31 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
@@ -70,14 +70,7 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        TcpDiscoverySpi spi;
-
-        if (gridName.contains("FailBeforeNodeAddedSentSpi"))
-            spi = new FailBeforeNodeAddedSentSpi();
-        else if (gridName.contains("FailBeforeNodeLeftSentSpi"))
-            spi = new FailBeforeNodeLeftSentSpi();
-        else
-            spi = new TcpDiscoverySpi();
+        TcpDiscoverySpi spi = new TcpDiscoverySpi();
 
         discoMap.put(gridName, spi);
 
@@ -600,7 +593,17 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
                 }
             }, EVT_NODE_JOINED, EVT_NODE_FAILED);
 
-            startGrid("FailBeforeNodeAddedSentSpi");
+            final Ignite g = startGrid("FailBeforeNodeAddedSentSpi");
+
+            discoMap.get(g.name()).addSendMessageListener(new IgniteInClosure<TcpDiscoveryAbstractMessage>() {
+                @Override public void apply(TcpDiscoveryAbstractMessage msg) {
+                    if (msg instanceof TcpDiscoveryNodeAddedMessage) {
+                        discoMap.get(g.name()).simulateNodeFailure();
+
+                        throw new RuntimeException("Avoid message sending: " + msg.getClass());
+                    }
+                }
+            });
 
             startGrid(3);
 
@@ -620,7 +623,17 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
             startGrid(1);
             startGrid(2);
 
-            startGrid("FailBeforeNodeLeftSentSpi");
+            final Ignite g = startGrid("FailBeforeNodeLeftSentSpi");
+
+            discoMap.get(g.name()).addSendMessageListener(new IgniteInClosure<TcpDiscoveryAbstractMessage>() {
+                @Override public void apply(TcpDiscoveryAbstractMessage msg) {
+                    if (msg instanceof TcpDiscoveryNodeLeftMessage) {
+                        discoMap.get(g.name()).simulateNodeFailure();
+
+                        throw new RuntimeException("Avoid message sending: " + msg.getClass());
+                    }
+                }
+            });
 
             Ignite g3 = startGrid(3);
 
@@ -954,36 +967,4 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
     private Ignite startGridNoOptimize(String gridName) throws Exception {
         return G.start(getConfiguration(gridName));
     }
-
-    /**
-     *
-     */
-    private static class FailBeforeNodeAddedSentSpi extends TcpDiscoverySpi {
-        /** */
-        private int i;
-
-        /** {@inheritDoc} */
-        @Override void onBeforeMessageSentAcrossRing(Serializable msg) {
-            if (msg instanceof TcpDiscoveryNodeAddedMessage)
-                if (++i == 2) {
-                    simulateNodeFailure();
-
-                    throw new RuntimeException("Avoid message sending: " + msg.getClass());
-                }
-        }
-    }
-
-    /**
-     *
-     */
-    private static class FailBeforeNodeLeftSentSpi extends TcpDiscoverySpi {
-        /** {@inheritDoc} */
-        @Override void onBeforeMessageSentAcrossRing(Serializable msg) {
-            if (msg instanceof TcpDiscoveryNodeLeftMessage) {
-                simulateNodeFailure();
-
-                throw new RuntimeException("Avoid message sending: " + msg.getClass());
-            }
-        }
-    }
 }



[15/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFuture.java
deleted file mode 100644
index f573187..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFuture.java
+++ /dev/null
@@ -1,1050 +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.distributed.near;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cluster.*;
-import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.cluster.*;
-import org.apache.ignite.internal.processors.affinity.*;
-import org.apache.ignite.internal.processors.cache.*;
-import org.apache.ignite.internal.processors.cache.distributed.*;
-import org.apache.ignite.internal.processors.cache.distributed.dht.*;
-import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.*;
-import org.apache.ignite.internal.processors.cache.transactions.*;
-import org.apache.ignite.internal.processors.cache.version.*;
-import org.apache.ignite.internal.transactions.*;
-import org.apache.ignite.internal.util.*;
-import org.apache.ignite.internal.util.future.*;
-import org.apache.ignite.internal.util.lang.*;
-import org.apache.ignite.internal.util.tostring.*;
-import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.lang.*;
-import org.apache.ignite.transactions.*;
-import org.jetbrains.annotations.*;
-import org.jsr166.*;
-
-import javax.cache.expiry.*;
-import java.util.*;
-import java.util.concurrent.atomic.*;
-
-import static org.apache.ignite.internal.processors.cache.GridCacheOperation.*;
-import static org.apache.ignite.transactions.TransactionState.*;
-
-/**
- *
- */
-public final class GridNearTxPrepareFuture<K, V> extends GridCompoundIdentityFuture<IgniteInternalTx>
-    implements GridCacheMvccFuture<IgniteInternalTx> {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Logger reference. */
-    private static final AtomicReference<IgniteLogger> logRef = new AtomicReference<>();
-
-    /** Logger. */
-    private static IgniteLogger log;
-
-    /** Context. */
-    private GridCacheSharedContext<K, V> cctx;
-
-    /** Future ID. */
-    private IgniteUuid futId;
-
-    /** Transaction. */
-    @GridToStringInclude
-    private GridNearTxLocal tx;
-
-    /** Error. */
-    @GridToStringExclude
-    private AtomicReference<Throwable> err = new AtomicReference<>(null);
-
-    /** Trackable flag. */
-    private boolean trackable = true;
-
-    /** Full information about transaction nodes mapping. */
-    private GridDhtTxMapping<K, V> txMapping;
-
-    /** */
-    private Collection<IgniteTxKey> lockKeys = new GridConcurrentHashSet<>();
-
-    /**
-     * @param cctx Context.
-     * @param tx Transaction.
-     */
-    public GridNearTxPrepareFuture(GridCacheSharedContext<K, V> cctx, final GridNearTxLocal tx) {
-        super(cctx.kernalContext(), new IgniteReducer<IgniteInternalTx, IgniteInternalTx>() {
-            @Override public boolean collect(IgniteInternalTx e) {
-                return true;
-            }
-
-            @Override public IgniteInternalTx reduce() {
-                // Nothing to aggregate.
-                return tx;
-            }
-        });
-
-        assert cctx != null;
-        assert tx != null;
-
-        this.cctx = cctx;
-        this.tx = tx;
-
-        futId = IgniteUuid.randomUuid();
-
-        if (log == null)
-            log = U.logger(cctx.kernalContext(), logRef, GridNearTxPrepareFuture.class);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteUuid futureId() {
-        return futId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridCacheVersion version() {
-        return tx.xidVersion();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean onOwnerChanged(GridCacheEntryEx entry, GridCacheMvccCandidate owner) {
-        if (log.isDebugEnabled())
-            log.debug("Transaction future received owner changed callback: " + entry);
-
-        if (tx.optimistic()) {
-            if ((entry.context().isNear() || entry.context().isLocal()) && owner != null && tx.hasWriteKey(entry.txKey())) {
-                lockKeys.remove(entry.txKey());
-
-                // This will check for locks.
-                onDone();
-
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @return Involved nodes.
-     */
-    @Override public Collection<? extends ClusterNode> nodes() {
-        return
-            F.viewReadOnly(futures(), new IgniteClosure<IgniteInternalFuture<?>, ClusterNode>() {
-                @Nullable @Override public ClusterNode apply(IgniteInternalFuture<?> f) {
-                    if (isMini(f))
-                        return ((MiniFuture)f).node();
-
-                    return cctx.discovery().localNode();
-                }
-            });
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean trackable() {
-        return trackable;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void markNotTrackable() {
-        trackable = false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean onNodeLeft(UUID nodeId) {
-        boolean found = false;
-
-        for (IgniteInternalFuture<?> fut : futures())
-            if (isMini(fut)) {
-                MiniFuture f = (MiniFuture)fut;
-
-                if (f.node().id().equals(nodeId)) {
-                    f.onResult(new ClusterTopologyCheckedException("Remote node left grid: " + nodeId));
-
-                    found = true;
-                }
-            }
-
-        return found;
-    }
-
-    /**
-     * @param nodeId Failed node ID.
-     * @param mappings Remaining mappings.
-     * @param e Error.
-     */
-    void onError(@Nullable UUID nodeId, @Nullable Iterable<GridDistributedTxMapping> mappings, Throwable e) {
-        if (err.compareAndSet(null, e)) {
-            boolean marked = tx.setRollbackOnly();
-
-            if (e instanceof IgniteTxOptimisticCheckedException) {
-                assert nodeId != null : "Missing node ID for optimistic failure exception: " + e;
-
-                tx.removeKeysMapping(nodeId, mappings);
-            }
-
-            if (e instanceof IgniteTxRollbackCheckedException) {
-                if (marked) {
-                    try {
-                        tx.rollback();
-                    }
-                    catch (IgniteCheckedException ex) {
-                        U.error(log, "Failed to automatically rollback transaction: " + tx, ex);
-                    }
-                }
-            }
-
-            onComplete();
-        }
-    }
-
-    /**
-     * @return {@code True} if all locks are owned.
-     */
-    private boolean checkLocks() {
-        boolean locked = lockKeys.isEmpty();
-
-        if (locked) {
-            if (log.isDebugEnabled())
-                log.debug("All locks are acquired for near prepare future: " + this);
-        }
-        else {
-            if (log.isDebugEnabled())
-                log.debug("Still waiting for locks [fut=" + this + ", keys=" + lockKeys + ']');
-        }
-
-        return locked;
-    }
-
-    /**
-     * @param e Error.
-     */
-    void onError(Throwable e) {
-        onError(null, null, e);
-    }
-
-    /**
-     * @param nodeId Sender.
-     * @param res Result.
-     */
-    public void onResult(UUID nodeId, GridNearTxPrepareResponse res) {
-        if (!isDone()) {
-            for (IgniteInternalFuture<IgniteInternalTx> fut : pending()) {
-                if (isMini(fut)) {
-                    MiniFuture f = (MiniFuture)fut;
-
-                    if (f.futureId().equals(res.miniId())) {
-                        assert f.node().id().equals(nodeId);
-
-                        f.onResult(nodeId, res);
-                    }
-                }
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean onDone(IgniteInternalTx t, Throwable err) {
-        // If locks were not acquired yet, delay completion.
-        if (isDone() || (err == null && !checkLocks()))
-            return false;
-
-        this.err.compareAndSet(null, err);
-
-        if (err == null)
-            tx.state(PREPARED);
-
-        if (super.onDone(tx, err)) {
-            // Don't forget to clean up.
-            cctx.mvcc().removeFuture(this);
-
-            return true;
-        }
-
-        return false;
-    }
-
-    /**
-     * @param f Future.
-     * @return {@code True} if mini-future.
-     */
-    private boolean isMini(IgniteInternalFuture<?> f) {
-        return f.getClass().equals(MiniFuture.class);
-    }
-
-    /**
-     * Completeness callback.
-     */
-    private void onComplete() {
-        if (super.onDone(tx, err.get()))
-            // Don't forget to clean up.
-            cctx.mvcc().removeFuture(this);
-    }
-
-    /**
-     * Completes this future.
-     */
-    void complete() {
-        onComplete();
-    }
-
-    /**
-     * Waits for topology exchange future to be ready and then prepares user transaction.
-     */
-    public void prepare() {
-        if (tx.optimistic()) {
-            // Obtain the topology version to use.
-            AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(Thread.currentThread().getId());
-
-            if (topVer != null) {
-                tx.topologyVersion(topVer);
-
-                prepare0();
-
-                return;
-            }
-
-            prepareOnTopology();
-
-        }
-        else
-            preparePessimistic();
-    }
-
-    /**
-     *
-     */
-    private void prepareOnTopology() {
-        GridDhtTopologyFuture topFut = topologyReadLock();
-
-        try {
-            if (topFut == null) {
-                assert isDone();
-
-                return;
-            }
-
-            if (topFut.isDone()) {
-                StringBuilder invalidCaches = new StringBuilder();
-                Boolean cacheInvalid = false;
-                for (GridCacheContext ctx : cctx.cacheContexts()) {
-                    if (tx.activeCacheIds().contains(ctx.cacheId()) && !topFut.isCacheTopologyValid(ctx)) {
-                        if (cacheInvalid)
-                            invalidCaches.append(", ");
-
-                        invalidCaches.append(U.maskName(ctx.name()));
-
-                        cacheInvalid = true;
-                    }
-                }
-
-                if (cacheInvalid) {
-                    onDone(new IgniteCheckedException("Failed to perform cache operation (cache topology is not valid): " +
-                        invalidCaches.toString()));
-
-                    return;
-                }
-
-                tx.topologyVersion(topFut.topologyVersion());
-
-                prepare0();
-            }
-            else {
-                topFut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
-                    @Override
-                    public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
-                        cctx.kernalContext().closure().runLocalSafe(new GridPlainRunnable() {
-                            @Override
-                            public void run() {
-                                prepareOnTopology();
-                            }
-                        });
-                    }
-                });
-            }
-        }
-        finally {
-            topologyReadUnlock();
-        }
-    }
-
-    /**
-     * Acquires topology read lock.
-     *
-     * @return Topology ready future.
-     */
-    private GridDhtTopologyFuture topologyReadLock() {
-        if (tx.activeCacheIds().isEmpty())
-            return cctx.exchange().lastTopologyFuture();
-
-        GridCacheContext<K, V> nonLocCtx = null;
-
-        for (int cacheId : tx.activeCacheIds()) {
-            GridCacheContext<K, V> cacheCtx = cctx.cacheContext(cacheId);
-
-            if (!cacheCtx.isLocal()) {
-                nonLocCtx = cacheCtx;
-
-                break;
-            }
-        }
-
-        if (nonLocCtx == null)
-            return cctx.exchange().lastTopologyFuture();
-
-        nonLocCtx.topology().readLock();
-
-        if (nonLocCtx.topology().stopping()) {
-            onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " +
-                nonLocCtx.name()));
-
-            return null;
-        }
-
-        return nonLocCtx.topology().topologyVersionFuture();
-    }
-
-    /**
-     * Releases topology read lock.
-     */
-    private void topologyReadUnlock() {
-        if (!tx.activeCacheIds().isEmpty()) {
-            GridCacheContext<K, V> nonLocalCtx = null;
-
-            for (int cacheId : tx.activeCacheIds()) {
-                GridCacheContext<K, V> cacheCtx = cctx.cacheContext(cacheId);
-
-                if (!cacheCtx.isLocal()) {
-                    nonLocalCtx = cacheCtx;
-
-                    break;
-                }
-            }
-
-            if (nonLocalCtx != null)
-                nonLocalCtx.topology().readUnlock();
-        }
-    }
-
-    /**
-     * Initializes future.
-     */
-    private void prepare0() {
-        assert tx.optimistic();
-
-        try {
-            if (!tx.state(PREPARING)) {
-                if (tx.setRollbackOnly()) {
-                    if (tx.timedOut())
-                        onError(null, null, new IgniteTxTimeoutCheckedException("Transaction timed out and " +
-                            "was rolled back: " + this));
-                    else
-                        onError(null, null, new IgniteCheckedException("Invalid transaction state for prepare " +
-                            "[state=" + tx.state() + ", tx=" + this + ']'));
-                }
-                else
-                    onError(null, null, new IgniteTxRollbackCheckedException("Invalid transaction state for " +
-                        "prepare [state=" + tx.state() + ", tx=" + this + ']'));
-
-                return;
-            }
-
-            // Make sure to add future before calling prepare.
-            cctx.mvcc().addFuture(this);
-
-            prepare(
-                tx.optimistic() && tx.serializable() ? tx.readEntries() : Collections.<IgniteTxEntry>emptyList(),
-                tx.writeEntries());
-
-            markInitialized();
-        }
-        catch (TransactionTimeoutException | TransactionOptimisticException e) {
-            onError(cctx.localNodeId(), null, e);
-        }
-        catch (IgniteCheckedException e) {
-            onDone(e);
-        }
-    }
-
-    /**
-     * @param reads Read entries.
-     * @param writes Write entries.
-     * @throws IgniteCheckedException If transaction is group-lock and some key was mapped to to the local node.
-     */
-    private void prepare(
-        Iterable<IgniteTxEntry> reads,
-        Iterable<IgniteTxEntry> writes
-    ) throws IgniteCheckedException {
-        assert tx.optimistic();
-
-        AffinityTopologyVersion topVer = tx.topologyVersion();
-
-        assert topVer.topologyVersion() > 0;
-
-        txMapping = new GridDhtTxMapping<>();
-
-        ConcurrentLinkedDeque8<GridDistributedTxMapping> mappings =
-            new ConcurrentLinkedDeque8<>();
-
-        if (!F.isEmpty(reads) || !F.isEmpty(writes)) {
-            for (int cacheId : tx.activeCacheIds()) {
-                GridCacheContext<K, V> cacheCtx = cctx.cacheContext(cacheId);
-
-                if (CU.affinityNodes(cacheCtx, topVer).isEmpty()) {
-                    onDone(new ClusterTopologyCheckedException("Failed to map keys for cache (all " +
-                        "partition nodes left the grid): " + cacheCtx.name()));
-
-                    return;
-                }
-            }
-        }
-
-        // Assign keys to primary nodes.
-        GridDistributedTxMapping cur = null;
-
-        for (IgniteTxEntry read : reads) {
-            GridDistributedTxMapping updated = map(read, topVer, cur, false);
-
-            if (cur != updated) {
-                mappings.offer(updated);
-
-                if (updated.node().isLocal()) {
-                    if (read.context().isNear())
-                        tx.nearLocallyMapped(true);
-                    else if (read.context().isColocated())
-                        tx.colocatedLocallyMapped(true);
-                }
-
-                cur = updated;
-            }
-        }
-
-        for (IgniteTxEntry write : writes) {
-            GridDistributedTxMapping updated = map(write, topVer, cur, true);
-
-            if (cur != updated) {
-                mappings.offer(updated);
-
-                if (updated.node().isLocal()) {
-                    if (write.context().isNear())
-                        tx.nearLocallyMapped(true);
-                    else if (write.context().isColocated())
-                        tx.colocatedLocallyMapped(true);
-                }
-
-                cur = updated;
-            }
-        }
-
-        if (isDone()) {
-            if (log.isDebugEnabled())
-                log.debug("Abandoning (re)map because future is done: " + this);
-
-            return;
-        }
-
-        tx.addEntryMapping(mappings);
-
-        cctx.mvcc().recheckPendingLocks();
-
-        txMapping.initLast(mappings);
-
-        tx.transactionNodes(txMapping.transactionNodes());
-
-        checkOnePhase();
-
-        proceedPrepare(mappings);
-    }
-
-    /**
-     *
-     */
-    private void preparePessimistic() {
-        Map<IgniteBiTuple<ClusterNode, Boolean>, GridDistributedTxMapping> mappings = new HashMap<>();
-
-        AffinityTopologyVersion topVer = tx.topologyVersion();
-
-        txMapping = new GridDhtTxMapping<>();
-
-        for (IgniteTxEntry txEntry : tx.allEntries()) {
-            GridCacheContext cacheCtx = txEntry.context();
-
-            List<ClusterNode> nodes = cacheCtx.affinity().nodes(txEntry.key(), topVer);
-
-            ClusterNode primary = F.first(nodes);
-
-            boolean near = cacheCtx.isNear();
-
-            IgniteBiTuple<ClusterNode, Boolean> key = F.t(primary, near);
-
-            GridDistributedTxMapping nodeMapping = mappings.get(key);
-
-            if (nodeMapping == null) {
-                nodeMapping = new GridDistributedTxMapping(primary);
-
-                nodeMapping.near(cacheCtx.isNear());
-
-                mappings.put(key, nodeMapping);
-            }
-
-            txEntry.nodeId(primary.id());
-
-            nodeMapping.add(txEntry);
-
-            txMapping.addMapping(nodes);
-        }
-
-        tx.transactionNodes(txMapping.transactionNodes());
-
-        checkOnePhase();
-
-        for (final GridDistributedTxMapping m : mappings.values()) {
-            final ClusterNode node = m.node();
-
-            GridNearTxPrepareRequest req = new GridNearTxPrepareRequest(
-                futId,
-                tx.topologyVersion(),
-                tx,
-                m.reads(),
-                m.writes(),
-                /*grp lock key*/null,
-                /*part lock*/false,
-                m.near(),
-                txMapping.transactionNodes(),
-                true,
-                txMapping.transactionNodes().get(node.id()),
-                tx.onePhaseCommit(),
-                tx.needReturnValue() && tx.implicit(),
-                tx.implicitSingle(),
-                m.explicitLock(),
-                tx.subjectId(),
-                tx.taskNameHash());
-
-            for (IgniteTxEntry txEntry : m.writes()) {
-                if (txEntry.op() == TRANSFORM)
-                    req.addDhtVersion(txEntry.txKey(), null);
-            }
-
-            final MiniFuture fut = new MiniFuture(m, null);
-
-            req.miniId(fut.futureId());
-
-            add(fut);
-
-            if (node.isLocal()) {
-                cctx.tm().txHandler().prepareTx(node.id(), tx, req, new CI1<GridNearTxPrepareResponse>() {
-                    @Override public void apply(GridNearTxPrepareResponse res) {
-                        fut.onResult(node.id(), res);
-                    }
-                });
-            }
-            else {
-                try {
-                    cctx.io().send(node, req, tx.ioPolicy());
-                }
-                catch (IgniteCheckedException e) {
-                    // Fail the whole thing.
-                    fut.onResult(e);
-                }
-            }
-        }
-
-        markInitialized();
-    }
-
-    /**
-     * Checks if mapped transaction can be committed on one phase.
-     * One-phase commit can be done if transaction maps to one primary node and not more than one backup.
-     */
-    private void checkOnePhase() {
-        if (tx.storeUsed())
-            return;
-
-        Map<UUID, Collection<UUID>> map = txMapping.transactionNodes();
-
-        if (map.size() == 1) {
-            Map.Entry<UUID, Collection<UUID>> entry = F.firstEntry(map);
-
-            assert entry != null;
-
-            Collection<UUID> backups = entry.getValue();
-
-            if (backups.size() <= 1)
-                tx.onePhaseCommit(true);
-        }
-    }
-
-    /**
-     * Continues prepare after previous mapping successfully finished.
-     *
-     * @param mappings Queue of mappings.
-     */
-    private void proceedPrepare(final ConcurrentLinkedDeque8<GridDistributedTxMapping> mappings) {
-        if (isDone())
-            return;
-
-        final GridDistributedTxMapping m = mappings.poll();
-
-        if (m == null)
-            return;
-
-        assert !m.empty();
-
-        final ClusterNode n = m.node();
-
-        GridNearTxPrepareRequest req = new GridNearTxPrepareRequest(
-            futId,
-            tx.topologyVersion(),
-            tx,
-            tx.optimistic() && tx.serializable() ? m.reads() : null,
-            m.writes(),
-            tx.groupLockKey(),
-            tx.partitionLock(),
-            m.near(),
-            txMapping.transactionNodes(),
-            m.last(),
-            m.lastBackups(),
-            tx.onePhaseCommit(),
-            tx.needReturnValue() && tx.implicit(),
-            tx.implicitSingle(),
-            m.explicitLock(),
-            tx.subjectId(),
-            tx.taskNameHash());
-
-        for (IgniteTxEntry txEntry : m.writes()) {
-            if (txEntry.op() == TRANSFORM)
-                req.addDhtVersion(txEntry.txKey(), null);
-        }
-
-        // Must lock near entries separately.
-        if (m.near()) {
-            try {
-                tx.optimisticLockEntries(req.writes());
-
-                tx.userPrepare();
-            }
-            catch (IgniteCheckedException e) {
-                onError(null, null, e);
-            }
-        }
-
-        final MiniFuture fut = new MiniFuture(m, mappings);
-
-        req.miniId(fut.futureId());
-
-        add(fut); // Append new future.
-
-        // If this is the primary node for the keys.
-        if (n.isLocal()) {
-            // At this point, if any new node joined, then it is
-            // waiting for this transaction to complete, so
-            // partition reassignments are not possible here.
-            cctx.tm().txHandler().prepareTx(n.id(), tx, req, new CI1<GridNearTxPrepareResponse>() {
-                @Override public void apply(GridNearTxPrepareResponse res) {
-                    fut.onResult(n.id(), res);
-                }
-            });
-        }
-        else {
-            assert !tx.groupLock() : "Got group lock transaction that is mapped on remote node [tx=" + tx +
-                ", nodeId=" + n.id() + ']';
-
-            try {
-                cctx.io().send(n, req, tx.ioPolicy());
-            }
-            catch (IgniteCheckedException e) {
-                // Fail the whole thing.
-                fut.onResult(e);
-            }
-        }
-    }
-
-    /**
-     * @param entry Transaction entry.
-     * @param topVer Topology version.
-     * @param cur Current mapping.
-     * @throws IgniteCheckedException If transaction is group-lock and local node is not primary for key.
-     * @return Mapping.
-     */
-    private GridDistributedTxMapping map(
-        IgniteTxEntry entry,
-        AffinityTopologyVersion topVer,
-        GridDistributedTxMapping cur,
-        boolean waitLock
-    ) throws IgniteCheckedException {
-        GridCacheContext cacheCtx = entry.context();
-
-        List<ClusterNode> nodes = cacheCtx.affinity().nodes(entry.key(), topVer);
-
-        txMapping.addMapping(nodes);
-
-        ClusterNode primary = F.first(nodes);
-
-        assert primary != null;
-
-        if (log.isDebugEnabled()) {
-            log.debug("Mapped key to primary node [key=" + entry.key() +
-                ", part=" + cacheCtx.affinity().partition(entry.key()) +
-                ", primary=" + U.toShortString(primary) + ", topVer=" + topVer + ']');
-        }
-
-        if (tx.groupLock() && !primary.isLocal())
-            throw new IgniteCheckedException("Failed to prepare group lock transaction (local node is not primary for " +
-                " key)[key=" + entry.key() + ", primaryNodeId=" + primary.id() + ']');
-
-        // Must re-initialize cached entry while holding topology lock.
-        if (cacheCtx.isNear())
-            entry.cached(cacheCtx.nearTx().entryExx(entry.key(), topVer));
-        else if (!cacheCtx.isLocal())
-            entry.cached(cacheCtx.colocated().entryExx(entry.key(), topVer, true));
-        else
-            entry.cached(cacheCtx.local().entryEx(entry.key(), topVer));
-
-        if (cacheCtx.isNear() || cacheCtx.isLocal()) {
-            if (waitLock && entry.explicitVersion() == null) {
-                if (!tx.groupLock() || tx.groupLockKey().equals(entry.txKey()))
-                    lockKeys.add(entry.txKey());
-            }
-        }
-
-        if (cur == null || !cur.node().id().equals(primary.id()) || cur.near() != cacheCtx.isNear()) {
-            cur = new GridDistributedTxMapping(primary);
-
-            // Initialize near flag right away.
-            cur.near(cacheCtx.isNear());
-        }
-
-        cur.add(entry);
-
-        if (entry.explicitVersion() != null) {
-            tx.markExplicit(primary.id());
-
-            cur.markExplicitLock();
-        }
-
-        entry.nodeId(primary.id());
-
-        if (cacheCtx.isNear()) {
-            while (true) {
-                try {
-                    GridNearCacheEntry cached = (GridNearCacheEntry)entry.cached();
-
-                    cached.dhtNodeId(tx.xidVersion(), primary.id());
-
-                    break;
-                }
-                catch (GridCacheEntryRemovedException ignore) {
-                    entry.cached(cacheCtx.near().entryEx(entry.key()));
-                }
-            }
-        }
-
-        return cur;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(GridNearTxPrepareFuture.class, this, super.toString());
-    }
-
-    /**
-     * Mini-future for get operations. Mini-futures are only waiting on a single
-     * node as opposed to multiple nodes.
-     */
-    private class MiniFuture extends GridFutureAdapter<IgniteInternalTx> {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** */
-        private final IgniteUuid futId = IgniteUuid.randomUuid();
-
-        /** Keys. */
-        @GridToStringInclude
-        private GridDistributedTxMapping m;
-
-        /** Flag to signal some result being processed. */
-        private AtomicBoolean rcvRes = new AtomicBoolean(false);
-
-        /** Mappings to proceed prepare. */
-        private ConcurrentLinkedDeque8<GridDistributedTxMapping> mappings;
-
-        /**
-         * @param m Mapping.
-         * @param mappings Queue of mappings to proceed with.
-         */
-        MiniFuture(
-            GridDistributedTxMapping m,
-            ConcurrentLinkedDeque8<GridDistributedTxMapping> mappings
-        ) {
-            this.m = m;
-            this.mappings = mappings;
-        }
-
-        /**
-         * @return Future ID.
-         */
-        IgniteUuid futureId() {
-            return futId;
-        }
-
-        /**
-         * @return Node ID.
-         */
-        public ClusterNode node() {
-            return m.node();
-        }
-
-        /**
-         * @return Keys.
-         */
-        public GridDistributedTxMapping mapping() {
-            return m;
-        }
-
-        /**
-         * @param e Error.
-         */
-        void onResult(Throwable e) {
-            if (rcvRes.compareAndSet(false, true)) {
-                if (log.isDebugEnabled())
-                    log.debug("Failed to get future result [fut=" + this + ", err=" + e + ']');
-
-                // Fail.
-                onDone(e);
-            }
-            else
-                U.warn(log, "Received error after another result has been processed [fut=" +
-                    GridNearTxPrepareFuture.this + ", mini=" + this + ']', e);
-        }
-
-        /**
-         * @param e Node failure.
-         */
-        void onResult(ClusterTopologyCheckedException e) {
-            if (isDone())
-                return;
-
-            if (rcvRes.compareAndSet(false, true)) {
-                if (log.isDebugEnabled())
-                    log.debug("Remote node left grid while sending or waiting for reply (will not retry): " + this);
-
-                // Fail the whole future (make sure not to remap on different primary node
-                // to prevent multiple lock coordinators).
-                onError(null, null, e);
-            }
-        }
-
-        /**
-         * @param nodeId Failed node ID.
-         * @param res Result callback.
-         */
-        void onResult(UUID nodeId, GridNearTxPrepareResponse res) {
-            if (isDone())
-                return;
-
-            if (rcvRes.compareAndSet(false, true)) {
-                if (res.error() != null) {
-                    // Fail the whole compound future.
-                    onError(nodeId, mappings, res.error());
-                }
-                else {
-                    assert F.isEmpty(res.invalidPartitions());
-
-                    for (Map.Entry<IgniteTxKey, CacheVersionedValue> entry : res.ownedValues().entrySet()) {
-                        IgniteTxEntry txEntry = tx.entry(entry.getKey());
-
-                        assert txEntry != null;
-
-                        GridCacheContext cacheCtx = txEntry.context();
-
-                        while (true) {
-                            try {
-                                if (cacheCtx.isNear()) {
-                                    GridNearCacheEntry nearEntry = (GridNearCacheEntry)txEntry.cached();
-
-                                    CacheVersionedValue tup = entry.getValue();
-
-                                    nearEntry.resetFromPrimary(tup.value(), tx.xidVersion(),
-                                        tup.version(), m.node().id(), tx.topologyVersion());
-                                }
-                                else if (txEntry.cached().detached()) {
-                                    GridDhtDetachedCacheEntry detachedEntry = (GridDhtDetachedCacheEntry)txEntry.cached();
-
-                                    CacheVersionedValue tup = entry.getValue();
-
-                                    detachedEntry.resetFromPrimary(tup.value(), tx.xidVersion());
-                                }
-
-                                break;
-                            }
-                            catch (GridCacheEntryRemovedException ignored) {
-                                // Retry.
-                            }
-                            catch (IgniteCheckedException e) {
-                                // Fail the whole compound future.
-                                onError(nodeId, mappings, e);
-
-                                return;
-                            }
-                        }
-                    }
-
-                    tx.implicitSingleResult(res.returnValue());
-
-                    for (IgniteTxKey key : res.filterFailedKeys()) {
-                        IgniteTxEntry txEntry = tx.entry(key);
-
-                        assert txEntry != null : "Missing tx entry for write key: " + key;
-
-                        txEntry.op(NOOP);
-
-                        assert txEntry.context() != null;
-
-                        ExpiryPolicy expiry = txEntry.context().expiryForTxEntry(txEntry);
-
-                        if (expiry != null)
-                            txEntry.ttl(CU.toTtl(expiry.getExpiryForAccess()));
-                    }
-
-                    if (!m.empty()) {
-                        // Register DHT version.
-                        tx.addDhtVersion(m.node().id(), res.dhtVersion());
-
-                        m.dhtVersion(res.dhtVersion());
-
-                        if (m.near())
-                            tx.readyNearLocks(m, res.pending(), res.committedVersions(), res.rolledbackVersions());
-                    }
-
-                    // Proceed prepare before finishing mini future.
-                    if (mappings != null)
-                        proceedPrepare(mappings);
-
-                    // Finish this mini future.
-                    onDone(tx);
-                }
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(MiniFuture.class, this, "done", isDone(), "cancelled", isCancelled(), "err", error());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFutureAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFutureAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFutureAdapter.java
new file mode 100644
index 0000000..b7a2fee
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFutureAdapter.java
@@ -0,0 +1,231 @@
+/*
+ * 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.distributed.near;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.distributed.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.*;
+import org.apache.ignite.internal.processors.cache.transactions.*;
+import org.apache.ignite.internal.processors.cache.version.*;
+import org.apache.ignite.internal.util.future.*;
+import org.apache.ignite.internal.util.tostring.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+
+import javax.cache.expiry.*;
+import java.util.*;
+import java.util.concurrent.atomic.*;
+
+import static org.apache.ignite.internal.processors.cache.GridCacheOperation.*;
+
+/**
+ * Common code for tx prepare in optimistic and pessimistic modes.
+ */
+public abstract class GridNearTxPrepareFutureAdapter extends GridCompoundIdentityFuture<IgniteInternalTx>
+    implements GridCacheFuture<IgniteInternalTx> {
+    /** Logger reference. */
+    protected static final AtomicReference<IgniteLogger> logRef = new AtomicReference<>();
+
+    /** */
+    private static final IgniteReducer<IgniteInternalTx, IgniteInternalTx> REDUCER =
+        new IgniteReducer<IgniteInternalTx, IgniteInternalTx>() {
+            @Override public boolean collect(IgniteInternalTx e) {
+                return true;
+            }
+
+            @Override public IgniteInternalTx reduce() {
+                // Nothing to aggregate.
+                return null;
+            }
+        };
+
+    /** Logger. */
+    protected static IgniteLogger log;
+
+    /** Context. */
+    protected GridCacheSharedContext<?, ?> cctx;
+
+    /** Future ID. */
+    protected IgniteUuid futId;
+
+    /** Transaction. */
+    @GridToStringInclude
+    protected GridNearTxLocal tx;
+
+    /** Error. */
+    @GridToStringExclude
+    protected AtomicReference<Throwable> err = new AtomicReference<>(null);
+
+    /** Trackable flag. */
+    protected boolean trackable = true;
+
+    /** Full information about transaction nodes mapping. */
+    protected GridDhtTxMapping txMapping;
+
+    /**
+     * @param cctx Context.
+     * @param tx Transaction.
+     */
+    public GridNearTxPrepareFutureAdapter(GridCacheSharedContext cctx, final GridNearTxLocal tx) {
+        super(cctx.kernalContext(), REDUCER);
+
+        assert cctx != null;
+        assert tx != null;
+
+        this.cctx = cctx;
+        this.tx = tx;
+
+        futId = IgniteUuid.randomUuid();
+
+        if (log == null)
+            log = U.logger(cctx.kernalContext(), logRef, GridNearTxPrepareFutureAdapter.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteUuid futureId() {
+        return futId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheVersion version() {
+        return tx.xidVersion();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void markNotTrackable() {
+        trackable = false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean trackable() {
+        return trackable;
+    }
+
+    /**
+     * Prepares transaction.
+     */
+    public abstract void prepare();
+
+    /**
+     * @param nodeId Sender.
+     * @param res Result.
+     */
+    public abstract void onResult(UUID nodeId, GridNearTxPrepareResponse res);
+
+    /**
+     * Checks if mapped transaction can be committed on one phase.
+     * One-phase commit can be done if transaction maps to one primary node and not more than one backup.
+     */
+    protected final void checkOnePhase() {
+        if (tx.storeUsed())
+            return;
+
+        Map<UUID, Collection<UUID>> map = txMapping.transactionNodes();
+
+        if (map.size() == 1) {
+            Map.Entry<UUID, Collection<UUID>> entry = F.firstEntry(map);
+
+            assert entry != null;
+
+            Collection<UUID> backups = entry.getValue();
+
+            if (backups.size() <= 1)
+                tx.onePhaseCommit(true);
+        }
+    }
+
+    /**
+     * @param m Mapping.
+     * @param res Response.
+     */
+    protected final void onPrepareResponse(GridDistributedTxMapping m, GridNearTxPrepareResponse res) {
+        if (res == null)
+            return;
+
+        assert res.error() == null : res;
+        assert F.isEmpty(res.invalidPartitions()) : res;
+
+        for (Map.Entry<IgniteTxKey, CacheVersionedValue> entry : res.ownedValues().entrySet()) {
+            IgniteTxEntry txEntry = tx.entry(entry.getKey());
+
+            assert txEntry != null;
+
+            GridCacheContext cacheCtx = txEntry.context();
+
+            while (true) {
+                try {
+                    if (cacheCtx.isNear()) {
+                        GridNearCacheEntry nearEntry = (GridNearCacheEntry)txEntry.cached();
+
+                        CacheVersionedValue tup = entry.getValue();
+
+                        nearEntry.resetFromPrimary(tup.value(), tx.xidVersion(),
+                            tup.version(), m.node().id(), tx.topologyVersion());
+                    }
+                    else if (txEntry.cached().detached()) {
+                        GridDhtDetachedCacheEntry detachedEntry = (GridDhtDetachedCacheEntry)txEntry.cached();
+
+                        CacheVersionedValue tup = entry.getValue();
+
+                        detachedEntry.resetFromPrimary(tup.value(), tx.xidVersion());
+                    }
+
+                    break;
+                }
+                catch (GridCacheEntryRemovedException ignored) {
+                    // Retry.
+                }
+            }
+        }
+
+        tx.implicitSingleResult(res.returnValue());
+
+        for (IgniteTxKey key : res.filterFailedKeys()) {
+            IgniteTxEntry txEntry = tx.entry(key);
+
+            assert txEntry != null : "Missing tx entry for write key: " + key;
+
+            txEntry.op(NOOP);
+
+            assert txEntry.context() != null;
+
+            ExpiryPolicy expiry = txEntry.context().expiryForTxEntry(txEntry);
+
+            if (expiry != null)
+                txEntry.ttl(CU.toTtl(expiry.getExpiryForAccess()));
+        }
+
+        if (!m.empty()) {
+            GridCacheVersion writeVer = res.writeVersion();
+
+            if (writeVer == null)
+                writeVer = res.dhtVersion();
+
+            // Register DHT version.
+            tx.addDhtVersion(m.node().id(), res.dhtVersion(), writeVer);
+
+            m.dhtVersion(res.dhtVersion(), writeVer);
+
+            if (m.near())
+                tx.readyNearLocks(m, res.pending(), res.committedVersions(), res.rolledbackVersions());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java
index f0587ac..a08637d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java
@@ -88,8 +88,6 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
      * @param tx Transaction.
      * @param reads Read entries.
      * @param writes Write entries.
-     * @param grpLockKey Group lock key if preparing group-lock transaction.
-     * @param partLock {@code True} if preparing group-lock transaction with partition lock.
      * @param near {@code True} if mapping is for near caches.
      * @param txNodes Transaction nodes mapping.
      * @param last {@code True} if this last prepare request for node.
@@ -103,8 +101,6 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
         IgniteInternalTx tx,
         Collection<IgniteTxEntry> reads,
         Collection<IgniteTxEntry> writes,
-        IgniteTxKey grpLockKey,
-        boolean partLock,
         boolean near,
         Map<UUID, Collection<UUID>> txNodes,
         boolean last,
@@ -116,7 +112,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
         @Nullable UUID subjId,
         int taskNameHash
     ) {
-        super(tx, reads, writes, grpLockKey, partLock, txNodes, onePhaseCommit);
+        super(tx, reads, writes, txNodes, onePhaseCommit);
 
         assert futId != null;
 
@@ -270,67 +266,67 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
         }
 
         switch (writer.state()) {
-            case 25:
+            case 23:
                 if (!writer.writeBoolean("explicitLock", explicitLock))
                     return false;
 
                 writer.incrementState();
 
-            case 26:
+            case 24:
                 if (!writer.writeIgniteUuid("futId", futId))
                     return false;
 
                 writer.incrementState();
 
-            case 27:
+            case 25:
                 if (!writer.writeBoolean("implicitSingle", implicitSingle))
                     return false;
 
                 writer.incrementState();
 
-            case 28:
+            case 26:
                 if (!writer.writeBoolean("last", last))
                     return false;
 
                 writer.incrementState();
 
-            case 29:
+            case 27:
                 if (!writer.writeCollection("lastBackups", lastBackups, MessageCollectionItemType.UUID))
                     return false;
 
                 writer.incrementState();
 
-            case 30:
+            case 28:
                 if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
                 writer.incrementState();
 
-            case 31:
+            case 29:
                 if (!writer.writeBoolean("near", near))
                     return false;
 
                 writer.incrementState();
 
-            case 32:
+            case 30:
                 if (!writer.writeBoolean("retVal", retVal))
                     return false;
 
                 writer.incrementState();
 
-            case 33:
+            case 31:
                 if (!writer.writeUuid("subjId", subjId))
                     return false;
 
                 writer.incrementState();
 
-            case 34:
+            case 32:
                 if (!writer.writeInt("taskNameHash", taskNameHash))
                     return false;
 
                 writer.incrementState();
 
-            case 35:
+            case 33:
                 if (!writer.writeMessage("topVer", topVer))
                     return false;
 
@@ -352,7 +348,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
             return false;
 
         switch (reader.state()) {
-            case 25:
+            case 23:
                 explicitLock = reader.readBoolean("explicitLock");
 
                 if (!reader.isLastRead())
@@ -360,7 +356,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 26:
+            case 24:
                 futId = reader.readIgniteUuid("futId");
 
                 if (!reader.isLastRead())
@@ -368,7 +364,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 27:
+            case 25:
                 implicitSingle = reader.readBoolean("implicitSingle");
 
                 if (!reader.isLastRead())
@@ -376,7 +372,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 28:
+            case 26:
                 last = reader.readBoolean("last");
 
                 if (!reader.isLastRead())
@@ -384,7 +380,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 29:
+            case 27:
                 lastBackups = reader.readCollection("lastBackups", MessageCollectionItemType.UUID);
 
                 if (!reader.isLastRead())
@@ -392,7 +388,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 30:
+            case 28:
                 miniId = reader.readIgniteUuid("miniId");
 
                 if (!reader.isLastRead())
@@ -400,7 +396,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 31:
+            case 29:
                 near = reader.readBoolean("near");
 
                 if (!reader.isLastRead())
@@ -408,7 +404,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 32:
+            case 30:
                 retVal = reader.readBoolean("retVal");
 
                 if (!reader.isLastRead())
@@ -416,7 +412,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 33:
+            case 31:
                 subjId = reader.readUuid("subjId");
 
                 if (!reader.isLastRead())
@@ -424,7 +420,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 34:
+            case 32:
                 taskNameHash = reader.readInt("taskNameHash");
 
                 if (!reader.isLastRead())
@@ -432,7 +428,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 35:
+            case 33:
                 topVer = reader.readMessage("topVer");
 
                 if (!reader.isLastRead())
@@ -452,7 +448,7 @@ public class GridNearTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 36;
+        return 34;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java
index 2456674..f8c07f7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java
@@ -53,6 +53,9 @@ public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse
     /** DHT version. */
     private GridCacheVersion dhtVer;
 
+    /** Write version. */
+    private GridCacheVersion writeVer;
+
     /** */
     @GridToStringInclude
     @GridDirectCollection(int.class)
@@ -101,6 +104,7 @@ public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse
         IgniteUuid futId,
         IgniteUuid miniId,
         GridCacheVersion dhtVer,
+        GridCacheVersion writeVer,
         Collection<Integer> invalidParts,
         GridCacheReturn retVal,
         Throwable err
@@ -114,6 +118,7 @@ public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse
         this.futId = futId;
         this.miniId = miniId;
         this.dhtVer = dhtVer;
+        this.writeVer = writeVer;
         this.invalidParts = invalidParts;
         this.retVal = retVal;
     }
@@ -158,6 +163,13 @@ public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse
     }
 
     /**
+     * @return Write version.
+     */
+    public GridCacheVersion writeVersion() {
+        return writeVer;
+    }
+
+    /**
      * Adds owned value.
      *
      * @param key Key.
@@ -371,6 +383,12 @@ public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse
 
                 writer.incrementState();
 
+            case 19:
+                if (!writer.writeMessage("writeVer", writeVer))
+                    return false;
+
+                writer.incrementState();
+
         }
 
         return true;
@@ -459,6 +477,14 @@ public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse
 
                 reader.incrementState();
 
+            case 19:
+                writeVer = reader.readMessage("writeVer");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
         }
 
         return true;
@@ -471,7 +497,7 @@ public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 19;
+        return 20;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
index b6b6017..49283cb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
@@ -51,9 +51,6 @@ public class GridNearTxRemote extends GridDistributedTxRemoteAdapter {
     /** Owned versions. */
     private Map<IgniteTxKey, GridCacheVersion> owned;
 
-    /** Group lock flag. */
-    private boolean grpLock;
-
     /**
      * Empty constructor required for {@link Externalizable}.
      */
@@ -78,7 +75,6 @@ public class GridNearTxRemote extends GridDistributedTxRemoteAdapter {
      * @param writeEntries Write entries.
      * @param ctx Cache registry.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key if this is a group-lock transaction.
      * @throws IgniteCheckedException If unmarshalling failed.
      */
     public GridNearTxRemote(
@@ -97,12 +93,11 @@ public class GridNearTxRemote extends GridDistributedTxRemoteAdapter {
         long timeout,
         Collection<IgniteTxEntry> writeEntries,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
         @Nullable UUID subjId,
         int taskNameHash
     ) throws IgniteCheckedException {
         super(ctx, nodeId, rmtThreadId, xidVer, commitVer, sys, plc, concurrency, isolation, invalidate, timeout,
-            txSize, grpLockKey, subjId, taskNameHash);
+            txSize, subjId, taskNameHash);
 
         assert nearNodeId != null;
 
@@ -138,7 +133,6 @@ public class GridNearTxRemote extends GridDistributedTxRemoteAdapter {
      * @param timeout Timeout.
      * @param ctx Cache registry.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Collection of group lock keys if this is a group-lock transaction.
      */
     public GridNearTxRemote(
         GridCacheSharedContext ctx,
@@ -155,12 +149,11 @@ public class GridNearTxRemote extends GridDistributedTxRemoteAdapter {
         boolean invalidate,
         long timeout,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
         super(ctx, nodeId, rmtThreadId, xidVer, commitVer, sys, plc, concurrency, isolation, invalidate, timeout,
-            txSize, grpLockKey, subjId, taskNameHash);
+            txSize, subjId, taskNameHash);
 
         assert nearNodeId != null;
 
@@ -192,19 +185,6 @@ public class GridNearTxRemote extends GridDistributedTxRemoteAdapter {
     }
 
     /**
-     * Marks near local transaction as group lock. Note that near remote transaction may be
-     * marked as group lock even if it does not contain any locked key.
-     */
-    public void markGroupLock() {
-        grpLock = true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean groupLock() {
-        return grpLock || super.groupLock();
-    }
-
-    /**
      * @return Near transaction ID.
      */
     @Override public GridCacheVersion nearXidVersion() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java
index fae2372..6120e25 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java
@@ -146,6 +146,8 @@ public class GridLocalCache<K, V> extends GridCacheAdapter<K, V> {
                     try {
                         entry = entryExx(key);
 
+                        entry.unswap(false);
+
                         if (!ctx.isAll(entry, filter)) {
                             fut.onFailed();
 
@@ -200,12 +202,6 @@ public class GridLocalCache<K, V> extends GridCacheAdapter<K, V> {
     }
 
     /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public void removeAll() throws IgniteCheckedException {
-        removeAll(keySet());
-    }
-
-    /** {@inheritDoc} */
     @Override public IgniteInternalFuture<?> removeAllAsync() {
         return ctx.closures().callLocalSafe(new Callable<Void>() {
             @Override public Void call() throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCacheEntry.java
index 84d4c90..ea59f1f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCacheEntry.java
@@ -29,6 +29,9 @@ import static org.apache.ignite.events.EventType.*;
  */
 @SuppressWarnings({"NonPrivateFieldAccessedInSynchronizedContext", "TooBroadScope"})
 public class GridLocalCacheEntry extends GridCacheMapEntry {
+    /** Off-heap value pointer. */
+    private long valPtr;
+
     /**
      * @param ctx  Cache registry.
      * @param key  Cache key.
@@ -384,4 +387,19 @@ public class GridLocalCacheEntry extends GridCacheMapEntry {
 
         return doomed != null;
     }
+
+    /** {@inheritDoc} */
+    @Override protected boolean hasOffHeapPointer() {
+        return valPtr != 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long offHeapPointer() {
+        return valPtr;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void offHeapPointer(long valPtr) {
+        this.valPtr = valPtr;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
index 936ed9d..819b0f0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
@@ -387,12 +387,6 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
     }
 
     /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public void removeAll() throws IgniteCheckedException {
-        removeAll(keySet());
-    }
-
-    /** {@inheritDoc} */
     @Override public IgniteInternalFuture<?> removeAllAsync() {
         return ctx.closures().callLocalSafe(new Callable<Void>() {
             @Override public Void call() throws Exception {
@@ -1374,16 +1368,24 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
     private List<GridCacheEntryEx> lockEntries(Collection<? extends K> keys) {
         List<GridCacheEntryEx> locked = new ArrayList<>(keys.size());
 
+        boolean nullKeys = false;
+
         while (true) {
             for (K key : keys) {
-                if (key == null)
-                    throw new NullPointerException("Null key.");
+                if (key == null) {
+                    nullKeys = true;
+
+                    break;
+                }
 
                 GridCacheEntryEx entry = entryEx(ctx.toCacheKeyObject(key));
 
                 locked.add(entry);
             }
 
+            if (nullKeys)
+                break;
+
             for (int i = 0; i < locked.size(); i++) {
                 GridCacheEntryEx entry = locked.get(i);
 
@@ -1405,6 +1407,15 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
             if (!locked.isEmpty())
                 return locked;
         }
+
+        assert nullKeys;
+
+        AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
+
+        for (GridCacheEntryEx entry : locked)
+            ctx.evicts().touch(entry, topVer);
+
+        throw new NullPointerException("Null key.");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
index 50a22d5..16a8028 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
@@ -286,11 +286,10 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
     /**
      * Entry for given key unswapped.
      *
-     * @param swapSpaceName Swap space name.
      * @param key Key.
      * @throws IgniteCheckedException If failed.
      */
-    public void onSwap(String swapSpaceName, K key) throws IgniteCheckedException {
+    public void onSwap(CacheObject key) throws IgniteCheckedException {
         if (!enterBusy())
             return; // Ignore index update when node is stopping.
 
@@ -307,15 +306,14 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
      *
      * @param key Key.
      * @param val Value
-     * @param valBytes Value bytes.
      * @throws IgniteCheckedException If failed.
      */
-    public void onUnswap(K key, V val, byte[] valBytes) throws IgniteCheckedException {
+    public void onUnswap(CacheObject key, CacheObject val) throws IgniteCheckedException {
         if (!enterBusy())
             return; // Ignore index update when node is stopping.
 
         try {
-            qryProc.onUnswap(space, key, val, valBytes);
+            qryProc.onUnswap(space, key, val);
         }
         finally {
             leaveBusy();
@@ -334,18 +332,15 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
      * Writes key-value pair to index.
      *
      * @param key Key.
-     * @param keyBytes Byte array with key data.
      * @param val Value.
-     * @param valBytes Value bytes.
      * @param ver Cache entry version.
      * @param expirationTime Expiration time or 0 if never expires.
      * @throws IgniteCheckedException In case of error.
      */
-    public void store(K key, @Nullable byte[] keyBytes, @Nullable V val, @Nullable byte[] valBytes,
-        GridCacheVersion ver, long expirationTime)
+    public void store(CacheObject key, CacheObject val, GridCacheVersion ver, long expirationTime)
         throws IgniteCheckedException {
         assert key != null;
-        assert val != null || valBytes != null;
+        assert val != null;
         assert enabled();
 
         if (key instanceof GridCacheInternal)
@@ -355,10 +350,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
             return; // Ignore index update when node is stopping.
 
         try {
-            if (val == null)
-                val = cctx.marshaller().unmarshal(valBytes, cctx.deploy().globalLoader());
-
-            qryProc.store(space, key, keyBytes, val, valBytes, CU.versionToBytes(ver), expirationTime);
+            qryProc.store(space, key, val, CU.versionToBytes(ver), expirationTime);
         }
         finally {
             invalidateResultCache();
@@ -373,7 +365,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
      * @throws IgniteCheckedException Thrown in case of any errors.
      */
     @SuppressWarnings("SimplifiableIfStatement")
-    public void remove(Object key, Object val) throws IgniteCheckedException {
+    public void remove(CacheObject key, CacheObject val) throws IgniteCheckedException {
         assert key != null;
 
         if (!GridQueryProcessor.isEnabled(cctx.config()) && !(key instanceof GridCacheInternal))
@@ -774,13 +766,14 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
 
         final ExpiryPolicy plc = cctx.expiry();
 
+        final boolean backups = qry.includeBackups() || cctx.isReplicated();
+
         final GridCloseableIteratorAdapter<IgniteBiTuple<K, V>> heapIt = new GridCloseableIteratorAdapter<IgniteBiTuple<K, V>>() {
             private IgniteBiTuple<K, V> next;
 
             private IgniteCacheExpiryPolicy expiryPlc = cctx.cache().expiryPolicy(plc);
 
-            private Iterator<K> iter = qry.includeBackups() || cctx.isReplicated() ?
-                prj.keySet().iterator() : prj.primaryKeySet().iterator();
+            private Iterator<K> iter = backups ? prj.keySet().iterator() : prj.primaryKeySet().iterator();
 
             {
                 advance();
@@ -876,10 +869,10 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
             iters.add(heapIt);
 
             if (cctx.isOffHeapEnabled())
-                iters.add(offheapIterator(qry));
+                iters.add(offheapIterator(qry, backups));
 
             if (cctx.swap().swapEnabled())
-                iters.add(swapIterator(qry));
+                iters.add(swapIterator(qry, backups));
 
             it = new CompoundIterator<>(iters);
         }
@@ -913,32 +906,34 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
 
     /**
      * @param qry Query.
+     * @param backups Include backups.
      * @return Swap iterator.
      * @throws IgniteCheckedException If failed.
      */
-    private GridIterator<IgniteBiTuple<K, V>> swapIterator(GridCacheQueryAdapter<?> qry)
+    private GridIterator<IgniteBiTuple<K, V>> swapIterator(GridCacheQueryAdapter<?> qry, boolean backups)
         throws IgniteCheckedException {
         IgniteBiPredicate<K, V> filter = qry.scanFilter();
 
-        Iterator<Map.Entry<byte[], byte[]>> it = cctx.swap().rawSwapIterator();
+        Iterator<Map.Entry<byte[], byte[]>> it = cctx.swap().rawSwapIterator(true, backups);
 
         return scanIterator(it, filter, qry.keepPortable());
     }
 
     /**
      * @param qry Query.
+     * @param backups Include backups.
      * @return Offheap iterator.
      */
-    private GridIterator<IgniteBiTuple<K, V>> offheapIterator(GridCacheQueryAdapter<?> qry) {
+    private GridIterator<IgniteBiTuple<K, V>> offheapIterator(GridCacheQueryAdapter<?> qry, boolean backups) {
         IgniteBiPredicate<K, V> filter = qry.scanFilter();
 
         if (cctx.offheapTiered() && filter != null) {
             OffheapIteratorClosure c = new OffheapIteratorClosure(filter, qry.keepPortable());
 
-            return cctx.swap().rawOffHeapIterator(c);
+            return cctx.swap().rawOffHeapIterator(c, true, backups);
         }
         else {
-            Iterator<Map.Entry<byte[], byte[]>> it = cctx.swap().rawOffHeapIterator();
+            Iterator<Map.Entry<byte[], byte[]>> it = cctx.swap().rawOffHeapIterator(true, backups);
 
             return scanIterator(it, filter, qry.keepPortable());
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
index 2ee690a..7a0e140 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
@@ -17,16 +17,20 @@
 
 package org.apache.ignite.internal.processors.cache.query;
 
+import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.marshaller.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 
-import java.io.*;
+import java.nio.*;
 
 /**
  * Query.
  */
-public class GridCacheSqlQuery implements Externalizable {
+public class GridCacheSqlQuery implements Message {
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -34,18 +38,22 @@ public class GridCacheSqlQuery implements Externalizable {
     public static final Object[] EMPTY_PARAMS = {};
 
     /** */
-    String alias;
+    private String alias;
 
     /** */
     @GridToStringInclude
-    String qry;
+    private String qry;
 
     /** */
     @GridToStringInclude
-    Object[] params;
+    @GridDirectTransient
+    private Object[] params;
+
+    /** */
+    private byte[] paramsBytes;
 
     /**
-     * For {@link Externalizable}.
+     * For {@link Message}.
      */
     public GridCacheSqlQuery() {
         // No-op.
@@ -56,7 +64,7 @@ public class GridCacheSqlQuery implements Externalizable {
      * @param qry Query.
      * @param params Query parameters.
      */
-    GridCacheSqlQuery(String alias, String qry, Object[] params) {
+    public GridCacheSqlQuery(String alias, String qry, Object[] params) {
         A.ensure(!F.isEmpty(qry), "qry must not be empty");
 
         this.alias = alias;
@@ -86,25 +94,116 @@ public class GridCacheSqlQuery implements Externalizable {
         return params;
     }
 
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        U.writeString(out, alias);
-        U.writeString(out, qry);
-        U.writeArray(out, params);
+    /**
+     * @param m Marshaller.
+     * @throws IgniteCheckedException If failed.
+     */
+    public void marshallParams(Marshaller m) throws IgniteCheckedException {
+        if (paramsBytes != null)
+            return;
+
+        assert params != null;
+
+        paramsBytes = m.marshal(params);
     }
 
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        alias = U.readString(in);
-        qry = U.readString(in);
-        params = U.readArray(in);
+    /**
+     * @param m Marshaller.
+     * @throws IgniteCheckedException If failed.
+     */
+    public void unmarshallParams(Marshaller m) throws IgniteCheckedException {
+        if (params != null)
+            return;
+
+        assert paramsBytes != null;
 
-        if (F.isEmpty(params))
-            params = EMPTY_PARAMS;
+        params = m.unmarshal(paramsBytes, null);
     }
 
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(GridCacheSqlQuery.class, this);
     }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeString("alias", alias))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeByteArray("paramsBytes", paramsBytes))
+                    return false;
+
+                writer.incrementState();
+
+            case 2:
+                if (!writer.writeString("qry", qry))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                alias = reader.readString("alias");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                paramsBytes = reader.readByteArray("paramsBytes");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 2:
+                qry = reader.readString("qry");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return 112;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 3;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
index 11b2057..53fc7a3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
@@ -23,16 +23,12 @@ import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 
-import java.io.*;
 import java.util.*;
 
 /**
  * Two step map-reduce style query.
  */
-public class GridCacheTwoStepQuery implements Serializable {
-    /** */
-    private static final long serialVersionUID = 0L;
-
+public class GridCacheTwoStepQuery {
     /** */
     public static final int DFLT_PAGE_SIZE = 1000;
 
@@ -47,6 +43,9 @@ public class GridCacheTwoStepQuery implements Serializable {
     /** */
     private int pageSize = DFLT_PAGE_SIZE;
 
+    /** */
+    private boolean explain;
+
     /**
      * @param qry Reduce query.
      * @param params Reduce query parameters.
@@ -56,6 +55,20 @@ public class GridCacheTwoStepQuery implements Serializable {
     }
 
     /**
+     * @return If this is explain query.
+     */
+    public boolean explain() {
+        return explain;
+    }
+
+    /**
+     * @param explain If this is explain query.
+     */
+    public void explain(boolean explain) {
+        this.explain = explain;
+    }
+
+    /**
      * @param pageSize Page size.
      */
     public void pageSize(int pageSize) {
@@ -95,7 +108,7 @@ public class GridCacheTwoStepQuery implements Serializable {
      * @return Map queries.
      */
     public Collection<GridCacheSqlQuery> mapQueries() {
-        return new ArrayList<>(mapQrys.values()); // Copy to make it Serializable.
+        return mapQrys.values();
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
index 30367c5..5f877ec 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
@@ -284,16 +284,6 @@ public interface IgniteInternalTx extends AutoCloseable, GridTimeoutObject {
     public boolean empty();
 
     /**
-     * @return {@code True} if transaction group-locked.
-     */
-    public boolean groupLock();
-
-    /**
-     * @return Group lock key if {@link #groupLock()} is {@code true}.
-     */
-    @Nullable public IgniteTxKey groupLockKey();
-
-    /**
      * @return {@code True} if preparing flag was set with this call.
      */
     public boolean markPreparing();
@@ -338,8 +328,7 @@ public interface IgniteInternalTx extends AutoCloseable, GridTimeoutObject {
 
     /**
      * Gets node ID which directly started this transaction. In case of DHT local transaction it will be
-     * near node ID, in case of DHT remote transaction it will be primary node ID, in case of replicated remote
-     * transaction it will be starter node ID.
+     * near node ID, in case of DHT remote transaction it will be primary node ID.
      *
      * @return Originating node ID.
      */
@@ -507,7 +496,7 @@ public interface IgniteInternalTx extends AutoCloseable, GridTimeoutObject {
      * @return Current value for the key within transaction.
      * @throws GridCacheFilterFailedException If filter failed and failFast is {@code true}.
      */
-     @Nullable public <K, V> GridTuple<CacheObject> peek(
+     @Nullable public GridTuple<CacheObject> peek(
          GridCacheContext ctx,
          boolean failFast,
          KeyCacheObject key,
@@ -552,7 +541,7 @@ public interface IgniteInternalTx extends AutoCloseable, GridTimeoutObject {
      *
      * @return Future for prepare step.
      */
-    public IgniteInternalFuture<IgniteInternalTx> prepareAsync();
+    public IgniteInternalFuture<?> prepareAsync();
 
     /**
      * @param endVer End version (a.k.a. <tt>'tnc'</tt> or <tt>'transaction number counter'</tt>)
@@ -581,7 +570,7 @@ public interface IgniteInternalTx extends AutoCloseable, GridTimeoutObject {
     /**
      * @return Future for transaction prepare if prepare is in progress.
      */
-    @Nullable public IgniteInternalFuture<IgniteInternalTx> currentPrepareFuture();
+    @Nullable public IgniteInternalFuture<?> currentPrepareFuture();
 
     /**
      * @param state Transaction state.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
index 044c3d7..99907e4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
@@ -160,9 +160,7 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
             isolation,
             timeout,
             true,
-            txSize,
-            /** group lock keys */null,
-            /** partition lock */false
+            txSize
         );
 
         assert tx != null;


[19/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxFuture.java
deleted file mode 100644
index 8a14b48..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxFuture.java
+++ /dev/null
@@ -1,434 +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.distributed;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cluster.*;
-import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.cluster.*;
-import org.apache.ignite.internal.processors.cache.*;
-import org.apache.ignite.internal.processors.cache.transactions.*;
-import org.apache.ignite.internal.processors.cache.version.*;
-import org.apache.ignite.internal.util.*;
-import org.apache.ignite.internal.util.future.*;
-import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.lang.*;
-import org.jetbrains.annotations.*;
-
-import java.util.*;
-import java.util.concurrent.atomic.*;
-
-/**
- * Future verifying that all remote transactions related to some
- * optimistic transaction were prepared.
- */
-public class GridCacheOptimisticCheckPreparedTxFuture<K, V> extends GridCompoundIdentityFuture<Boolean>
-    implements GridCacheFuture<Boolean> {
-    /** */         
-    private static final long serialVersionUID = 0L;
-    
-    /** Logger reference. */
-    private static final AtomicReference<IgniteLogger> logRef = new AtomicReference<>();
-
-    /** Logger. */
-    private static IgniteLogger log;
-
-    /** Trackable flag. */
-    private boolean trackable = true;
-
-    /** Context. */
-    private final GridCacheSharedContext<K, V> cctx;
-
-    /** Future ID. */
-    private final IgniteUuid futId = IgniteUuid.randomUuid();
-
-    /** Transaction. */
-    private final IgniteInternalTx tx;
-
-    /** All involved nodes. */
-    private final Map<UUID, ClusterNode> nodes;
-
-    /** ID of failed node started transaction. */
-    private final UUID failedNodeId;
-
-    /** Transaction nodes mapping. */
-    private final Map<UUID, Collection<UUID>> txNodes;
-
-    /**
-     * @param cctx Context.
-     * @param tx Transaction.
-     * @param failedNodeId ID of failed node started transaction.
-     * @param txNodes Transaction mapping.
-     */
-    @SuppressWarnings("ConstantConditions")
-    public GridCacheOptimisticCheckPreparedTxFuture(GridCacheSharedContext<K, V> cctx, IgniteInternalTx tx,
-        UUID failedNodeId, Map<UUID, Collection<UUID>> txNodes) {
-        super(cctx.kernalContext(), CU.boolReducer());
-
-        this.cctx = cctx;
-        this.tx = tx;
-        this.txNodes = txNodes;
-        this.failedNodeId = failedNodeId;
-
-        if (log == null)
-            log = U.logger(cctx.kernalContext(), logRef, GridCacheOptimisticCheckPreparedTxFuture.class);
-
-        nodes = new GridLeanMap<>();
-
-        UUID locNodeId = cctx.localNodeId();
-
-        for (Map.Entry<UUID, Collection<UUID>> e : tx.transactionNodes().entrySet()) {
-            if (!locNodeId.equals(e.getKey()) && !failedNodeId.equals(e.getKey()) && !nodes.containsKey(e.getKey())) {
-                ClusterNode node = cctx.discovery().node(e.getKey());
-
-                if (node != null)
-                    nodes.put(node.id(), node);
-                else if (log.isDebugEnabled())
-                    log.debug("Transaction node left (will ignore) " + e.getKey());
-            }
-
-            for (UUID nodeId : e.getValue()) {
-                if (!locNodeId.equals(nodeId) && !failedNodeId.equals(nodeId) && !nodes.containsKey(nodeId)) {
-                    ClusterNode node = cctx.discovery().node(nodeId);
-
-                    if (node != null)
-                        nodes.put(node.id(), node);
-                    else if (log.isDebugEnabled())
-                        log.debug("Transaction node left (will ignore) " + e.getKey());
-                }
-            }
-        }
-    }
-
-    /**
-     * Initializes future.
-     */
-    @SuppressWarnings("ConstantConditions")
-    public void prepare() {
-        // First check transactions on local node.
-        int locTxNum = nodeTransactions(cctx.localNodeId());
-
-        if (locTxNum > 1) {
-            IgniteInternalFuture<Boolean> fut = cctx.tm().txsPreparedOrCommitted(tx.nearXidVersion(), locTxNum);
-
-            if (fut == null || fut.isDone()) {
-                boolean prepared;
-
-                try {
-                    prepared = fut == null ? true : fut.get();
-                }
-                catch (IgniteCheckedException e) {
-                    U.error(log, "Check prepared transaction future failed: " + e, e);
-
-                    prepared = false;
-                }
-
-                if (!prepared) {
-                    onDone(false);
-
-                    markInitialized();
-
-                    return;
-                }
-            }
-            else {
-                fut.listen(new CI1<IgniteInternalFuture<Boolean>>() {
-                    @Override public void apply(IgniteInternalFuture<Boolean> fut) {
-                        boolean prepared;
-
-                        try {
-                            prepared = fut.get();
-                        }
-                        catch (IgniteCheckedException e) {
-                            U.error(log, "Check prepared transaction future failed: " + e, e);
-
-                            prepared = false;
-                        }
-
-                        if (!prepared) {
-                            onDone(false);
-
-                            markInitialized();
-                        }
-                        else
-                            proceedPrepare();
-                    }
-                });
-
-                return;
-            }
-        }
-
-        proceedPrepare();
-    }
-
-    /**
-     * Process prepare after local check.
-     */
-    private void proceedPrepare() {
-        for (Map.Entry<UUID, Collection<UUID>> entry : txNodes.entrySet()) {
-            UUID nodeId = entry.getKey();
-
-            // Skip left nodes and local node.
-            if (!nodes.containsKey(nodeId) && nodeId.equals(cctx.localNodeId()))
-                continue;
-
-            /*
-             * If primary node failed then send message to all backups, otherwise
-             * send message only to primary node.
-             */
-
-            if (nodeId.equals(failedNodeId)) {
-                for (UUID id : entry.getValue()) {
-                    // Skip backup node if it is local node or if it is also was mapped as primary.
-                    if (txNodes.containsKey(id) || id.equals(cctx.localNodeId()))
-                        continue;
-
-                    MiniFuture fut = new MiniFuture(id);
-
-                    add(fut);
-
-                    GridCacheOptimisticCheckPreparedTxRequest req = new GridCacheOptimisticCheckPreparedTxRequest(tx,
-                        nodeTransactions(id),
-                        futureId(),
-                        fut.futureId());
-
-                    try {
-                        cctx.io().send(id, req, tx.ioPolicy());
-                    }
-                    catch (ClusterTopologyCheckedException ignored) {
-                        fut.onNodeLeft();
-                    }
-                    catch (IgniteCheckedException e) {
-                        fut.onError(e);
-
-                        break;
-                    }
-                }
-            }
-            else {
-                MiniFuture fut = new MiniFuture(nodeId);
-
-                add(fut);
-
-                GridCacheOptimisticCheckPreparedTxRequest req = new GridCacheOptimisticCheckPreparedTxRequest(
-                    tx, nodeTransactions(nodeId), futureId(), fut.futureId());
-
-                try {
-                    cctx.io().send(nodeId, req, tx.ioPolicy());
-                }
-                catch (ClusterTopologyCheckedException ignored) {
-                    fut.onNodeLeft();
-                }
-                catch (IgniteCheckedException e) {
-                    fut.onError(e);
-
-                    break;
-                }
-            }
-        }
-
-        markInitialized();
-    }
-
-    /**
-     * @param nodeId Node ID.
-     * @return Number of transactions on node.
-     */
-    private int nodeTransactions(UUID nodeId) {
-        int cnt = txNodes.containsKey(nodeId) ? 1 : 0; // +1 if node is primary.
-
-        for (Collection<UUID> backups : txNodes.values()) {
-            for (UUID backup : backups) {
-                if (backup.equals(nodeId)) {
-                    cnt++; // +1 if node is backup.
-
-                    break;
-                }
-            }
-        }
-
-        return cnt;
-    }
-
-    /**
-     * @param nodeId Node ID.
-     * @param res Response.
-     */
-    public void onResult(UUID nodeId, GridCacheOptimisticCheckPreparedTxResponse res) {
-        if (!isDone()) {
-            for (IgniteInternalFuture<Boolean> fut : pending()) {
-                if (isMini(fut)) {
-                    MiniFuture f = (MiniFuture)fut;
-
-                    if (f.futureId().equals(res.miniId())) {
-                        assert f.nodeId().equals(nodeId);
-
-                        f.onResult(res);
-
-                        break;
-                    }
-                }
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteUuid futureId() {
-        return futId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridCacheVersion version() {
-        return tx.xidVersion();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<? extends ClusterNode> nodes() {
-        return nodes.values();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean onNodeLeft(UUID nodeId) {
-        for (IgniteInternalFuture<?> fut : futures())
-            if (isMini(fut)) {
-                MiniFuture f = (MiniFuture)fut;
-
-                if (f.nodeId().equals(nodeId)) {
-                    f.onNodeLeft();
-
-                    return true;
-                }
-            }
-
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean trackable() {
-        return trackable;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void markNotTrackable() {
-        trackable = false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean onDone(@Nullable Boolean res, @Nullable Throwable err) {
-        if (super.onDone(res, err)) {
-            cctx.mvcc().removeFuture(this);
-
-            if (err == null) {
-                assert res != null;
-
-                cctx.tm().finishOptimisticTxOnRecovery(tx, res);
-            }
-            else {
-                if (log.isDebugEnabled())
-                    log.debug("Failed to check prepared transactions, " +
-                        "invalidating transaction [err=" + err + ", tx=" + tx + ']');
-
-                cctx.tm().salvageTx(tx);
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @param f Future.
-     * @return {@code True} if mini-future.
-     */
-    private boolean isMini(IgniteInternalFuture<?> f) {
-        return f.getClass().equals(MiniFuture.class);
-    }
-
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(GridCacheOptimisticCheckPreparedTxFuture.class, this, "super", super.toString());
-    }
-
-    /**
-     *
-     */
-    private class MiniFuture extends GridFutureAdapter<Boolean> {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Mini future ID. */
-        private final IgniteUuid futId = IgniteUuid.randomUuid();
-
-        /** Node ID. */
-        private UUID nodeId;
-
-        /**
-         * @param nodeId Node ID.
-         */
-        private MiniFuture(UUID nodeId) {
-            this.nodeId = nodeId;
-        }
-
-        /**
-         * @return Node ID.
-         */
-        private UUID nodeId() {
-            return nodeId;
-        }
-
-        /**
-         * @return Future ID.
-         */
-        private IgniteUuid futureId() {
-            return futId;
-        }
-
-        /**
-         * @param e Error.
-         */
-        private void onError(Throwable e) {
-            if (log.isDebugEnabled())
-                log.debug("Failed to get future result [fut=" + this + ", err=" + e + ']');
-
-            onDone(e);
-        }
-
-        /**
-         */
-        private void onNodeLeft() {
-            if (log.isDebugEnabled())
-                log.debug("Transaction node left grid (will ignore) [fut=" + this + ']');
-
-            onDone(true);
-        }
-
-        /**
-         * @param res Result callback.
-         */
-        private void onResult(GridCacheOptimisticCheckPreparedTxResponse res) {
-            onDone(res.success());
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(MiniFuture.class, this, "done", isDone(), "err", error());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java
deleted file mode 100644
index e83db66..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java
+++ /dev/null
@@ -1,232 +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.distributed;
-
-import org.apache.ignite.internal.processors.cache.transactions.*;
-import org.apache.ignite.internal.processors.cache.version.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.lang.*;
-import org.apache.ignite.plugin.extensions.communication.*;
-
-import java.io.*;
-import java.nio.*;
-
-/**
- * Message sent to check that transactions related to some optimistic transaction
- * were prepared on remote node.
- */
-public class GridCacheOptimisticCheckPreparedTxRequest extends GridDistributedBaseMessage {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Future ID. */
-    private IgniteUuid futId;
-
-    /** Mini future ID. */
-    private IgniteUuid miniId;
-
-    /** Near transaction ID. */
-    private GridCacheVersion nearXidVer;
-
-    /** Expected number of transactions on node. */
-    private int txNum;
-
-    /** System transaction flag. */
-    private boolean sys;
-
-    /**
-     * Empty constructor required by {@link Externalizable}
-     */
-    public GridCacheOptimisticCheckPreparedTxRequest() {
-        // No-op.
-    }
-
-    /**
-     * @param tx Transaction.
-     * @param txNum Expected number of transactions on remote node.
-     * @param futId Future ID.
-     * @param miniId Mini future ID.
-     */
-    public GridCacheOptimisticCheckPreparedTxRequest(IgniteInternalTx tx, int txNum, IgniteUuid futId,
-        IgniteUuid miniId) {
-        super(tx.xidVersion(), 0);
-
-        nearXidVer = tx.nearXidVersion();
-        sys = tx.system();
-
-        this.futId = futId;
-        this.miniId = miniId;
-        this.txNum = txNum;
-    }
-
-    /**
-     * @return Near version.
-     */
-    public GridCacheVersion nearXidVersion() {
-        return nearXidVer;
-    }
-
-    /**
-     * @return Future ID.
-     */
-    public IgniteUuid futureId() {
-        return futId;
-    }
-
-    /**
-     * @return Mini future ID.
-     */
-    public IgniteUuid miniId() {
-        return miniId;
-    }
-
-    /**
-     * @return Expected number of transactions on node.
-     */
-    public int transactions() {
-        return txNum;
-    }
-
-    /**
-     * @return System transaction flag.
-     */
-    public boolean system() {
-        return sys;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
-        writer.setBuffer(buf);
-
-        if (!super.writeTo(buf, writer))
-            return false;
-
-        if (!writer.isHeaderWritten()) {
-            if (!writer.writeHeader(directType(), fieldsCount()))
-                return false;
-
-            writer.onHeaderWritten();
-        }
-
-        switch (writer.state()) {
-            case 8:
-                if (!writer.writeIgniteUuid("futId", futId))
-                    return false;
-
-                writer.incrementState();
-
-            case 9:
-                if (!writer.writeIgniteUuid("miniId", miniId))
-                    return false;
-
-                writer.incrementState();
-
-            case 10:
-                if (!writer.writeMessage("nearXidVer", nearXidVer))
-                    return false;
-
-                writer.incrementState();
-
-            case 11:
-                if (!writer.writeBoolean("sys", sys))
-                    return false;
-
-                writer.incrementState();
-
-            case 12:
-                if (!writer.writeInt("txNum", txNum))
-                    return false;
-
-                writer.incrementState();
-
-        }
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
-        reader.setBuffer(buf);
-
-        if (!reader.beforeMessageRead())
-            return false;
-
-        if (!super.readFrom(buf, reader))
-            return false;
-
-        switch (reader.state()) {
-            case 8:
-                futId = reader.readIgniteUuid("futId");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 9:
-                miniId = reader.readIgniteUuid("miniId");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 10:
-                nearXidVer = reader.readMessage("nearXidVer");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 11:
-                sys = reader.readBoolean("sys");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 12:
-                txNum = reader.readInt("txNum");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-        }
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte directType() {
-        return 16;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte fieldsCount() {
-        return 13;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(GridCacheOptimisticCheckPreparedTxRequest.class, this, "super", super.toString());
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java
deleted file mode 100644
index bc8c2e0..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java
+++ /dev/null
@@ -1,179 +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.distributed;
-
-import org.apache.ignite.internal.processors.cache.version.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.lang.*;
-import org.apache.ignite.plugin.extensions.communication.*;
-
-import java.io.*;
-import java.nio.*;
-
-/**
- * Check prepared transactions response.
- */
-public class GridCacheOptimisticCheckPreparedTxResponse extends GridDistributedBaseMessage {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Future ID. */
-    private IgniteUuid futId;
-
-    /** Mini future ID. */
-    private IgniteUuid miniId;
-
-    /** Flag indicating if all remote transactions were prepared. */
-    private boolean success;
-
-    /**
-     * Empty constructor required by {@link Externalizable}
-     */
-    public GridCacheOptimisticCheckPreparedTxResponse() {
-        // No-op.
-    }
-
-    /**
-     * @param txId Transaction ID.
-     * @param futId Future ID.
-     * @param miniId Mini future ID.
-     * @param success {@code True} if all remote transactions were prepared, {@code false} otherwise.
-     */
-    public GridCacheOptimisticCheckPreparedTxResponse(GridCacheVersion txId, IgniteUuid futId, IgniteUuid miniId,
-        boolean success) {
-        super(txId, 0);
-
-        this.futId = futId;
-        this.miniId = miniId;
-        this.success = success;
-    }
-
-    /**
-     * @return Future ID.
-     */
-    public IgniteUuid futureId() {
-        return futId;
-    }
-
-    /**
-     * @return Mini future ID.
-     */
-    public IgniteUuid miniId() {
-        return miniId;
-    }
-
-    /**
-     * @return {@code True} if all remote transactions were prepared.
-     */
-    public boolean success() {
-        return success;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
-        writer.setBuffer(buf);
-
-        if (!super.writeTo(buf, writer))
-            return false;
-
-        if (!writer.isHeaderWritten()) {
-            if (!writer.writeHeader(directType(), fieldsCount()))
-                return false;
-
-            writer.onHeaderWritten();
-        }
-
-        switch (writer.state()) {
-            case 8:
-                if (!writer.writeIgniteUuid("futId", futId))
-                    return false;
-
-                writer.incrementState();
-
-            case 9:
-                if (!writer.writeIgniteUuid("miniId", miniId))
-                    return false;
-
-                writer.incrementState();
-
-            case 10:
-                if (!writer.writeBoolean("success", success))
-                    return false;
-
-                writer.incrementState();
-
-        }
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
-        reader.setBuffer(buf);
-
-        if (!reader.beforeMessageRead())
-            return false;
-
-        if (!super.readFrom(buf, reader))
-            return false;
-
-        switch (reader.state()) {
-            case 8:
-                futId = reader.readIgniteUuid("futId");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 9:
-                miniId = reader.readIgniteUuid("miniId");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 10:
-                success = reader.readBoolean("success");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-        }
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte directType() {
-        return 17;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte fieldsCount() {
-        return 11;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(GridCacheOptimisticCheckPreparedTxResponse.class, this, "super", super.toString());
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryFuture.java
new file mode 100644
index 0000000..663ed90
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryFuture.java
@@ -0,0 +1,506 @@
+/*
+ * 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.distributed;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.cluster.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.transactions.*;
+import org.apache.ignite.internal.processors.cache.version.*;
+import org.apache.ignite.internal.util.*;
+import org.apache.ignite.internal.util.future.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+import java.util.concurrent.atomic.*;
+
+/**
+ * Future verifying that all remote transactions related to transaction were prepared or committed.
+ */
+public class GridCacheTxRecoveryFuture extends GridCompoundIdentityFuture<Boolean> implements GridCacheFuture<Boolean> {
+    /** */         
+    private static final long serialVersionUID = 0L;
+    
+    /** Logger reference. */
+    private static final AtomicReference<IgniteLogger> logRef = new AtomicReference<>();
+
+    /** Logger. */
+    private static IgniteLogger log;
+
+    /** Trackable flag. */
+    private boolean trackable = true;
+
+    /** Context. */
+    private final GridCacheSharedContext<?, ?> cctx;
+
+    /** Future ID. */
+    private final IgniteUuid futId = IgniteUuid.randomUuid();
+
+    /** Transaction. */
+    private final IgniteInternalTx tx;
+
+    /** All involved nodes. */
+    private final Map<UUID, ClusterNode> nodes;
+
+    /** ID of failed node started transaction. */
+    private final UUID failedNodeId;
+
+    /** Transaction nodes mapping. */
+    private final Map<UUID, Collection<UUID>> txNodes;
+
+    /** */
+    private final boolean nearTxCheck;
+
+    /**
+     * @param cctx Context.
+     * @param tx Transaction.
+     * @param failedNodeId ID of failed node started transaction.
+     * @param txNodes Transaction mapping.
+     */
+    @SuppressWarnings("ConstantConditions")
+    public GridCacheTxRecoveryFuture(GridCacheSharedContext<?, ?> cctx,
+        IgniteInternalTx tx,
+         UUID failedNodeId,
+        Map<UUID, Collection<UUID>> txNodes)
+    {
+        super(cctx.kernalContext(), CU.boolReducer());
+
+        this.cctx = cctx;
+        this.tx = tx;
+        this.txNodes = txNodes;
+        this.failedNodeId = failedNodeId;
+
+        if (log == null)
+            log = U.logger(cctx.kernalContext(), logRef, GridCacheTxRecoveryFuture.class);
+
+        nodes = new GridLeanMap<>();
+
+        UUID locNodeId = cctx.localNodeId();
+
+        for (Map.Entry<UUID, Collection<UUID>> e : tx.transactionNodes().entrySet()) {
+            if (!locNodeId.equals(e.getKey()) && !failedNodeId.equals(e.getKey()) && !nodes.containsKey(e.getKey())) {
+                ClusterNode node = cctx.discovery().node(e.getKey());
+
+                if (node != null)
+                    nodes.put(node.id(), node);
+                else if (log.isDebugEnabled())
+                    log.debug("Transaction node left (will ignore) " + e.getKey());
+            }
+
+            for (UUID nodeId : e.getValue()) {
+                if (!locNodeId.equals(nodeId) && !failedNodeId.equals(nodeId) && !nodes.containsKey(nodeId)) {
+                    ClusterNode node = cctx.discovery().node(nodeId);
+
+                    if (node != null)
+                        nodes.put(node.id(), node);
+                    else if (log.isDebugEnabled())
+                        log.debug("Transaction node left (will ignore) " + e.getKey());
+                }
+            }
+        }
+
+        UUID nearNodeId = tx.eventNodeId();
+
+        nearTxCheck = !failedNodeId.equals(nearNodeId) && cctx.discovery().alive(nearNodeId);
+    }
+
+    /**
+     * Initializes future.
+     */
+    @SuppressWarnings("ConstantConditions")
+    public void prepare() {
+        if (nearTxCheck) {
+            UUID nearNodeId = tx.eventNodeId();
+
+            if (cctx.localNodeId().equals(nearNodeId)) {
+                IgniteInternalFuture<Boolean> fut = cctx.tm().txCommitted(tx.nearXidVersion());
+
+                fut.listen(new CI1<IgniteInternalFuture<Boolean>>() {
+                    @Override public void apply(IgniteInternalFuture<Boolean> fut) {
+                        try {
+                            onDone(fut.get());
+                        }
+                        catch (IgniteCheckedException e) {
+                            onDone(e);
+                        }
+                    }
+                });
+            }
+            else {
+                MiniFuture fut = new MiniFuture(tx.eventNodeId());
+
+                add(fut);
+
+                GridCacheTxRecoveryRequest req = new GridCacheTxRecoveryRequest(
+                    tx,
+                    0,
+                    true,
+                    futureId(),
+                    fut.futureId());
+
+                try {
+                    cctx.io().send(nearNodeId, req, tx.ioPolicy());
+                }
+                catch (ClusterTopologyCheckedException e) {
+                    fut.onNodeLeft();
+                }
+                catch (IgniteCheckedException e) {
+                    fut.onError(e);
+                }
+
+                markInitialized();
+            }
+
+            return;
+        }
+
+        // First check transactions on local node.
+        int locTxNum = nodeTransactions(cctx.localNodeId());
+
+        if (locTxNum > 1) {
+            IgniteInternalFuture<Boolean> fut = cctx.tm().txsPreparedOrCommitted(tx.nearXidVersion(), locTxNum);
+
+            if (fut == null || fut.isDone()) {
+                boolean prepared;
+
+                try {
+                    prepared = fut == null ? true : fut.get();
+                }
+                catch (IgniteCheckedException e) {
+                    U.error(log, "Check prepared transaction future failed: " + e, e);
+
+                    prepared = false;
+                }
+
+                if (!prepared) {
+                    onDone(false);
+
+                    markInitialized();
+
+                    return;
+                }
+            }
+            else {
+                fut.listen(new CI1<IgniteInternalFuture<Boolean>>() {
+                    @Override public void apply(IgniteInternalFuture<Boolean> fut) {
+                        boolean prepared;
+
+                        try {
+                            prepared = fut.get();
+                        }
+                        catch (IgniteCheckedException e) {
+                            U.error(log, "Check prepared transaction future failed: " + e, e);
+
+                            prepared = false;
+                        }
+
+                        if (!prepared) {
+                            onDone(false);
+
+                            markInitialized();
+                        }
+                        else
+                            proceedPrepare();
+                    }
+                });
+
+                return;
+            }
+        }
+
+        proceedPrepare();
+    }
+
+    /**
+     * Process prepare after local check.
+     */
+    private void proceedPrepare() {
+        for (Map.Entry<UUID, Collection<UUID>> entry : txNodes.entrySet()) {
+            UUID nodeId = entry.getKey();
+
+            // Skip left nodes and local node.
+            if (!nodes.containsKey(nodeId) && nodeId.equals(cctx.localNodeId()))
+                continue;
+
+            /*
+             * If primary node failed then send message to all backups, otherwise
+             * send message only to primary node.
+             */
+
+            if (nodeId.equals(failedNodeId)) {
+                for (UUID id : entry.getValue()) {
+                    // Skip backup node if it is local node or if it is also was mapped as primary.
+                    if (txNodes.containsKey(id) || id.equals(cctx.localNodeId()))
+                        continue;
+
+                    MiniFuture fut = new MiniFuture(id);
+
+                    add(fut);
+
+                    GridCacheTxRecoveryRequest req = new GridCacheTxRecoveryRequest(tx,
+                        nodeTransactions(id),
+                        false,
+                        futureId(),
+                        fut.futureId());
+
+                    try {
+                        cctx.io().send(id, req, tx.ioPolicy());
+                    }
+                    catch (ClusterTopologyCheckedException ignored) {
+                        fut.onNodeLeft();
+                    }
+                    catch (IgniteCheckedException e) {
+                        fut.onError(e);
+
+                        break;
+                    }
+                }
+            }
+            else {
+                MiniFuture fut = new MiniFuture(nodeId);
+
+                add(fut);
+
+                GridCacheTxRecoveryRequest req = new GridCacheTxRecoveryRequest(
+                    tx,
+                    nodeTransactions(nodeId),
+                    false,
+                    futureId(),
+                    fut.futureId());
+
+                try {
+                    cctx.io().send(nodeId, req, tx.ioPolicy());
+                }
+                catch (ClusterTopologyCheckedException ignored) {
+                    fut.onNodeLeft();
+                }
+                catch (IgniteCheckedException e) {
+                    fut.onError(e);
+
+                    break;
+                }
+            }
+        }
+
+        markInitialized();
+    }
+
+    /**
+     * @param nodeId Node ID.
+     * @return Number of transactions on node.
+     */
+    private int nodeTransactions(UUID nodeId) {
+        int cnt = txNodes.containsKey(nodeId) ? 1 : 0; // +1 if node is primary.
+
+        for (Collection<UUID> backups : txNodes.values()) {
+            for (UUID backup : backups) {
+                if (backup.equals(nodeId)) {
+                    cnt++; // +1 if node is backup.
+
+                    break;
+                }
+            }
+        }
+
+        return cnt;
+    }
+
+    /**
+     * @param nodeId Node ID.
+     * @param res Response.
+     */
+    public void onResult(UUID nodeId, GridCacheTxRecoveryResponse res) {
+        if (!isDone()) {
+            for (IgniteInternalFuture<Boolean> fut : pending()) {
+                if (isMini(fut)) {
+                    MiniFuture f = (MiniFuture)fut;
+
+                    if (f.futureId().equals(res.miniId())) {
+                        assert f.nodeId().equals(nodeId);
+
+                        f.onResult(res);
+
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteUuid futureId() {
+        return futId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheVersion version() {
+        return tx.xidVersion();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<? extends ClusterNode> nodes() {
+        return nodes.values();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onNodeLeft(UUID nodeId) {
+        for (IgniteInternalFuture<?> fut : futures())
+            if (isMini(fut)) {
+                MiniFuture f = (MiniFuture)fut;
+
+                if (f.nodeId().equals(nodeId)) {
+                    f.onNodeLeft();
+
+                    return true;
+                }
+            }
+
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean trackable() {
+        return trackable;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void markNotTrackable() {
+        trackable = false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onDone(@Nullable Boolean res, @Nullable Throwable err) {
+        if (super.onDone(res, err)) {
+            cctx.mvcc().removeFuture(this);
+
+            if (err == null) {
+                assert res != null;
+
+                cctx.tm().finishTxOnRecovery(tx, res);
+            }
+            else {
+                if (err instanceof ClusterTopologyCheckedException && nearTxCheck) {
+                    if (log.isDebugEnabled())
+                        log.debug("Failed to check transaction on near node, " +
+                            "ignoring [err=" + err + ", tx=" + tx + ']');
+                }
+                else {
+                    if (log.isDebugEnabled())
+                        log.debug("Failed to check prepared transactions, " +
+                            "invalidating transaction [err=" + err + ", tx=" + tx + ']');
+
+                    cctx.tm().salvageTx(tx);
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * @param f Future.
+     * @return {@code True} if mini-future.
+     */
+    private boolean isMini(IgniteInternalFuture<?> f) {
+        return f.getClass().equals(MiniFuture.class);
+    }
+
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheTxRecoveryFuture.class, this, "super", super.toString());
+    }
+
+    /**
+     *
+     */
+    private class MiniFuture extends GridFutureAdapter<Boolean> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Mini future ID. */
+        private final IgniteUuid futId = IgniteUuid.randomUuid();
+
+        /** Node ID. */
+        private UUID nodeId;
+
+        /**
+         * @param nodeId Node ID.
+         */
+        private MiniFuture(UUID nodeId) {
+            this.nodeId = nodeId;
+        }
+
+        /**
+         * @return Node ID.
+         */
+        private UUID nodeId() {
+            return nodeId;
+        }
+
+        /**
+         * @return Future ID.
+         */
+        private IgniteUuid futureId() {
+            return futId;
+        }
+
+        /**
+         * @param e Error.
+         */
+        private void onError(Throwable e) {
+            if (log.isDebugEnabled())
+                log.debug("Failed to get future result [fut=" + this + ", err=" + e + ']');
+
+            onDone(e);
+        }
+
+        /**
+         */
+        private void onNodeLeft() {
+            if (log.isDebugEnabled())
+                log.debug("Transaction node left grid (will ignore) [fut=" + this + ']');
+
+            if (nearTxCheck) {
+                // Near and originating nodes left, need initiate tx check.
+                cctx.tm().commitIfPrepared(tx);
+
+                onDone(new ClusterTopologyCheckedException("Transaction node left grid (will ignore)."));
+            }
+            else
+                onDone(true);
+        }
+
+        /**
+         * @param res Result callback.
+         */
+        private void onResult(GridCacheTxRecoveryResponse res) {
+            onDone(res.success());
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(MiniFuture.class, this, "done", isDone(), "err", error());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryRequest.java
new file mode 100644
index 0000000..259c288
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryRequest.java
@@ -0,0 +1,261 @@
+/*
+ * 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.distributed;
+
+import org.apache.ignite.internal.processors.cache.transactions.*;
+import org.apache.ignite.internal.processors.cache.version.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+
+import java.io.*;
+import java.nio.*;
+
+/**
+ * Message sent to check that transactions related to transaction were prepared on remote node.
+ */
+public class GridCacheTxRecoveryRequest extends GridDistributedBaseMessage {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Future ID. */
+    private IgniteUuid futId;
+
+    /** Mini future ID. */
+    private IgniteUuid miniId;
+
+    /** Near transaction ID. */
+    private GridCacheVersion nearXidVer;
+
+    /** Expected number of transactions on node. */
+    private int txNum;
+
+    /** System transaction flag. */
+    private boolean sys;
+
+    /** {@code True} if should check only tx on near node. */
+    private boolean nearTxCheck;
+
+    /**
+     * Empty constructor required by {@link Externalizable}
+     */
+    public GridCacheTxRecoveryRequest() {
+        // No-op.
+    }
+
+    /**
+     * @param tx Transaction.
+     * @param txNum Expected number of transactions on remote node.
+     * @param nearTxCheck {@code True} if should check only tx on near node.
+     * @param futId Future ID.
+     * @param miniId Mini future ID.
+     */
+    public GridCacheTxRecoveryRequest(IgniteInternalTx tx,
+        int txNum,
+        boolean nearTxCheck,
+        IgniteUuid futId,
+        IgniteUuid miniId)
+    {
+        super(tx.xidVersion(), 0);
+
+        nearXidVer = tx.nearXidVersion();
+        sys = tx.system();
+
+        this.futId = futId;
+        this.miniId = miniId;
+        this.txNum = txNum;
+        this.nearTxCheck = nearTxCheck;
+    }
+
+    /**
+     * @return {@code True} if should check only tx on near node.
+     */
+    public boolean nearTxCheck() {
+        return nearTxCheck;
+    }
+
+    /**
+     * @return Near version.
+     */
+    public GridCacheVersion nearXidVersion() {
+        return nearXidVer;
+    }
+
+    /**
+     * @return Future ID.
+     */
+    public IgniteUuid futureId() {
+        return futId;
+    }
+
+    /**
+     * @return Mini future ID.
+     */
+    public IgniteUuid miniId() {
+        return miniId;
+    }
+
+    /**
+     * @return Expected number of transactions on node.
+     */
+    public int transactions() {
+        return txNum;
+    }
+
+    /**
+     * @return System transaction flag.
+     */
+    public boolean system() {
+        return sys;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 8:
+                if (!writer.writeIgniteUuid("futId", futId))
+                    return false;
+
+                writer.incrementState();
+
+            case 9:
+                if (!writer.writeIgniteUuid("miniId", miniId))
+                    return false;
+
+                writer.incrementState();
+
+            case 10:
+                if (!writer.writeBoolean("nearTxCheck", nearTxCheck))
+                    return false;
+
+                writer.incrementState();
+
+            case 11:
+                if (!writer.writeMessage("nearXidVer", nearXidVer))
+                    return false;
+
+                writer.incrementState();
+
+            case 12:
+                if (!writer.writeBoolean("sys", sys))
+                    return false;
+
+                writer.incrementState();
+
+            case 13:
+                if (!writer.writeInt("txNum", txNum))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 8:
+                futId = reader.readIgniteUuid("futId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 9:
+                miniId = reader.readIgniteUuid("miniId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 10:
+                nearTxCheck = reader.readBoolean("nearTxCheck");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 11:
+                nearXidVer = reader.readMessage("nearXidVer");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 12:
+                sys = reader.readBoolean("sys");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 13:
+                txNum = reader.readInt("txNum");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return 16;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 14;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheTxRecoveryRequest.class, this, "super", super.toString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryResponse.java
new file mode 100644
index 0000000..e5c026a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxRecoveryResponse.java
@@ -0,0 +1,182 @@
+/*
+ * 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.distributed;
+
+import org.apache.ignite.internal.processors.cache.version.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+
+import java.io.*;
+import java.nio.*;
+
+/**
+ * Transactions recovery check response.
+ */
+public class GridCacheTxRecoveryResponse extends GridDistributedBaseMessage {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Future ID. */
+    private IgniteUuid futId;
+
+    /** Mini future ID. */
+    private IgniteUuid miniId;
+
+    /** Flag indicating if all remote transactions were prepared. */
+    private boolean success;
+
+    /**
+     * Empty constructor required by {@link Externalizable}
+     */
+    public GridCacheTxRecoveryResponse() {
+        // No-op.
+    }
+
+    /**
+     * @param txId Transaction ID.
+     * @param futId Future ID.
+     * @param miniId Mini future ID.
+     * @param success {@code True} if all remote transactions were prepared, {@code false} otherwise.
+     */
+    public GridCacheTxRecoveryResponse(GridCacheVersion txId,
+        IgniteUuid futId,
+        IgniteUuid miniId,
+        boolean success)
+    {
+        super(txId, 0);
+
+        this.futId = futId;
+        this.miniId = miniId;
+        this.success = success;
+    }
+
+    /**
+     * @return Future ID.
+     */
+    public IgniteUuid futureId() {
+        return futId;
+    }
+
+    /**
+     * @return Mini future ID.
+     */
+    public IgniteUuid miniId() {
+        return miniId;
+    }
+
+    /**
+     * @return {@code True} if all remote transactions were prepared.
+     */
+    public boolean success() {
+        return success;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 8:
+                if (!writer.writeIgniteUuid("futId", futId))
+                    return false;
+
+                writer.incrementState();
+
+            case 9:
+                if (!writer.writeIgniteUuid("miniId", miniId))
+                    return false;
+
+                writer.incrementState();
+
+            case 10:
+                if (!writer.writeBoolean("success", success))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 8:
+                futId = reader.readIgniteUuid("futId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 9:
+                miniId = reader.readIgniteUuid("miniId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 10:
+                success = reader.readBoolean("success");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return 17;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 11;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheTxRecoveryResponse.class, this, "super", super.toString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
index 3a685cc..c5ef22f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.cache.distributed;
 
 import org.apache.ignite.*;
 import org.apache.ignite.cluster.*;
+import org.apache.ignite.compute.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.cluster.*;
 import org.apache.ignite.internal.processors.affinity.*;
@@ -30,17 +31,17 @@ import org.apache.ignite.internal.processors.cache.version.*;
 import org.apache.ignite.internal.processors.datastreamer.*;
 import org.apache.ignite.internal.processors.task.*;
 import org.apache.ignite.internal.util.future.*;
+import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
-import org.apache.ignite.resources.*;
 import org.apache.ignite.transactions.*;
 import org.jetbrains.annotations.*;
 
 import java.io.*;
 import java.util.*;
-import java.util.concurrent.*;
 
-import static org.apache.ignite.internal.GridClosureCallMode.*;
+import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.*;
+import static org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.*;
 
 /**
  * Distributed cache implementation.
@@ -142,21 +143,28 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
         try {
             AffinityTopologyVersion topVer;
 
+            boolean retry;
+
+            CacheOperationContext opCtx = ctx.operationContextPerCall();
+
+            boolean skipStore = opCtx != null && opCtx.skipStore();
+
             do {
+                retry = false;
+
                 topVer = ctx.affinity().affinityTopologyVersion();
 
                 // Send job to all data nodes.
                 Collection<ClusterNode> nodes = ctx.grid().cluster().forDataNodes(name()).nodes();
 
                 if (!nodes.isEmpty()) {
-                    CacheOperationContext opCtx = ctx.operationContextPerCall();
+                    ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
 
-                    ctx.closures().callAsyncNoFailover(BROADCAST,
-                        new GlobalRemoveAllCallable<>(name(), topVer, opCtx != null && opCtx.skipStore()), nodes,
-                        true).get();
+                    retry = !ctx.kernalContext().task().execute(
+                        new RemoveAllTask(ctx.name(), topVer, skipStore), null).get();
                 }
             }
-            while (ctx.affinity().affinityTopologyVersion().compareTo(topVer) > 0);
+            while (ctx.affinity().affinityTopologyVersion().compareTo(topVer) != 0 || retry);
         }
         catch (ClusterGroupEmptyCheckedException ignore) {
             if (log.isDebugEnabled())
@@ -170,7 +178,11 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
 
         AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
 
-        removeAllAsync(opFut, topVer);
+        CacheOperationContext opCtx = ctx.operationContextPerCall();
+
+        boolean skipStore = opCtx != null && opCtx.skipStore();
+
+        removeAllAsync(opFut, topVer, skipStore);
 
         return opFut;
     }
@@ -178,27 +190,29 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
     /**
      * @param opFut Future.
      * @param topVer Topology version.
+     * @param skipStore Skip store flag.
      */
-    private void removeAllAsync(final GridFutureAdapter<Void> opFut, final AffinityTopologyVersion topVer) {
+    private void removeAllAsync(final GridFutureAdapter<Void> opFut, final AffinityTopologyVersion topVer,
+        final boolean skipStore) {
         Collection<ClusterNode> nodes = ctx.grid().cluster().forDataNodes(name()).nodes();
 
         if (!nodes.isEmpty()) {
-            CacheOperationContext opCtx = ctx.operationContextPerCall();
+            ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
 
-            IgniteInternalFuture<?> rmvFut = ctx.closures().callAsyncNoFailover(BROADCAST,
-                    new GlobalRemoveAllCallable<>(name(), topVer, opCtx != null && opCtx.skipStore()), nodes, true);
+            IgniteInternalFuture<Boolean> rmvAll = ctx.kernalContext().task().execute(
+                new RemoveAllTask(ctx.name(), topVer, skipStore), null);
 
-            rmvFut.listen(new IgniteInClosure<IgniteInternalFuture<?>>() {
-                @Override public void apply(IgniteInternalFuture<?> fut) {
+            rmvAll.listen(new IgniteInClosure<IgniteInternalFuture<Boolean>>() {
+                @Override public void apply(IgniteInternalFuture<Boolean> fut) {
                     try {
-                        fut.get();
+                        boolean retry = !fut.get();
 
                         AffinityTopologyVersion topVer0 = ctx.affinity().affinityTopologyVersion();
 
-                        if (topVer0.equals(topVer))
+                        if (topVer0.equals(topVer) && !retry)
                             opFut.onDone();
                         else
-                            removeAllAsync(opFut, topVer0);
+                            removeAllAsync(opFut, topVer0, skipStore);
                     }
                     catch (ClusterGroupEmptyCheckedException ignore) {
                         if (log.isDebugEnabled())
@@ -227,97 +241,150 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
     }
 
     /**
-     * Internal callable which performs remove all primary key mappings
-     * operation on a cache with the given name.
+     * Remove task.
      */
     @GridInternal
-    private static class GlobalRemoveAllCallable<K,V> implements Callable<Object>, Externalizable {
+    private static class RemoveAllTask extends ComputeTaskAdapter<Object, Boolean> {
         /** */
         private static final long serialVersionUID = 0L;
 
         /** Cache name. */
-        private String cacheName;
+        private final String cacheName;
 
-        /** Topology version. */
-        private AffinityTopologyVersion topVer;
+        /** Affinity topology version. */
+        private final AffinityTopologyVersion topVer;
 
         /** Skip store flag. */
-        private boolean skipStore;
-
-        /** Injected grid instance. */
-        @IgniteInstanceResource
-        private Ignite ignite;
+        private final boolean skipStore;
 
         /**
-         * Empty constructor for serialization.
+         * @param cacheName Cache name.
+         * @param topVer Affinity topology version.
+         * @param skipStore Skip store flag.
          */
-        public GlobalRemoveAllCallable() {
-            // No-op.
+        public RemoveAllTask(String cacheName, AffinityTopologyVersion topVer, boolean skipStore) {
+            this.cacheName = cacheName;
+            this.topVer = topVer;
+            this.skipStore = skipStore;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+            @Nullable Object arg) throws IgniteException {
+            Map<ComputeJob, ClusterNode> jobs = new HashMap();
+
+            for (ClusterNode node : subgrid)
+                jobs.put(new GlobalRemoveAllJob(cacheName, topVer, skipStore), node);
+
+            return jobs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
+            IgniteException e = res.getException();
+
+            if (e != null) {
+                if (e instanceof ClusterTopologyException)
+                    return ComputeJobResultPolicy.WAIT;
+
+                throw new IgniteException("Remote job threw exception.", e);
+            }
+
+            return ComputeJobResultPolicy.WAIT;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Boolean reduce(List<ComputeJobResult> results) throws IgniteException {
+            for (ComputeJobResult locRes : results) {
+                if (locRes != null && (locRes.getException() != null || !locRes.<Boolean>getData()))
+                    return false;
+            }
+
+            return true;
         }
+    }
+    /**
+     * Internal job which performs remove all primary key mappings
+     * operation on a cache with the given name.
+     */
+    @GridInternal
+    private static class GlobalRemoveAllJob<K,V>  extends TopologyVersionAwareJob {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Skip store flag. */
+        private final boolean skipStore;
 
         /**
          * @param cacheName Cache name.
          * @param topVer Topology version.
          * @param skipStore Skip store flag.
          */
-        private GlobalRemoveAllCallable(String cacheName, @NotNull AffinityTopologyVersion topVer, boolean skipStore) {
-            this.cacheName = cacheName;
-            this.topVer = topVer;
+        private GlobalRemoveAllJob(String cacheName, @NotNull AffinityTopologyVersion topVer, boolean skipStore) {
+            super(cacheName, topVer);
+
             this.skipStore = skipStore;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        @Override public Object call() throws Exception {
-            GridCacheAdapter<K, V> cacheAdapter = ((IgniteKernal)ignite).context().cache().internalCache(cacheName);
+        /** {@inheritDoc} */
+        @Nullable @Override public Object localExecute(@Nullable IgniteInternalCache cache0) {
+            GridCacheAdapter cache = ((IgniteKernal) ignite).context().cache().internalCache(cacheName);
 
-            final GridCacheContext<K, V> ctx = cacheAdapter.context();
+            if (cache == null)
+                return true;
 
-            ctx.affinity().affinityReadyFuture(topVer).get();
+            final GridCacheContext<K, V> ctx = cache.context();
 
             ctx.gate().enter();
 
             try {
                 if (!ctx.affinity().affinityTopologyVersion().equals(topVer))
-                    return null; // Ignore this remove request because remove request will be sent again.
+                    return false; // Ignore this remove request because remove request will be sent again.
 
                 GridDhtCacheAdapter<K, V> dht;
                 GridNearCacheAdapter<K, V> near = null;
 
-                if (cacheAdapter instanceof GridNearCacheAdapter) {
-                    near = ((GridNearCacheAdapter<K, V>)cacheAdapter);
+                if (cache instanceof GridNearCacheAdapter) {
+                    near = ((GridNearCacheAdapter<K, V>) cache);
                     dht = near.dht();
                 }
                 else
-                    dht = (GridDhtCacheAdapter<K, V>)cacheAdapter;
+                    dht = (GridDhtCacheAdapter<K, V>) cache;
 
                 try (DataStreamerImpl<KeyCacheObject, Object> dataLdr =
-                         (DataStreamerImpl)ignite.dataStreamer(cacheName)) {
-                    ((DataStreamerImpl)dataLdr).maxRemapCount(0);
+                         (DataStreamerImpl) ignite.dataStreamer(cacheName)) {
+                    ((DataStreamerImpl) dataLdr).maxRemapCount(0);
 
                     dataLdr.skipStore(skipStore);
 
                     dataLdr.receiver(DataStreamerCacheUpdaters.<KeyCacheObject, Object>batched());
 
-                    for (GridDhtLocalPartition locPart : dht.topology().currentLocalPartitions()) {
-                        if (!locPart.isEmpty() && locPart.primary(topVer)) {
-                            for (GridDhtCacheEntry o : locPart.entries()) {
-                                if (!o.obsoleteOrDeleted())
-                                    dataLdr.removeDataInternal(o.key());
-                            }
-                        }
-                    }
+                    for (int part : ctx.affinity().primaryPartitions(ctx.localNodeId(), topVer)) {
+                        GridDhtLocalPartition locPart = dht.topology().localPartition(part, topVer, false);
 
-                    Iterator<KeyCacheObject> it = dht.context().swap().offHeapKeyIterator(true, false, topVer);
+                        if (locPart == null || (ctx.rebalanceEnabled() && locPart.state() != OWNING) || !locPart.reserve())
+                            return false;
 
-                    while (it.hasNext())
-                        dataLdr.removeDataInternal(it.next());
+                        try {
+                            if (!locPart.isEmpty()) {
+                                for (GridDhtCacheEntry o : locPart.entries()) {
+                                    if (!o.obsoleteOrDeleted())
+                                        dataLdr.removeDataInternal(o.key());
+                                }
+                            }
 
-                    it = dht.context().swap().swapKeyIterator(true, false, topVer);
+                            GridCloseableIterator<Map.Entry<byte[], GridCacheSwapEntry>> iter =
+                                dht.context().swap().iterator(part);
 
-                    while (it.hasNext())
-                        dataLdr.removeDataInternal(it.next());
+                            if (iter != null) {
+                                for (Map.Entry<byte[], GridCacheSwapEntry> e : iter)
+                                    dataLdr.removeDataInternal(ctx.toCacheKeyObject(e.getKey()));
+                            }
+                        }
+                        finally {
+                            locPart.release();
+                        }
+                    }
                 }
 
                 if (near != null) {
@@ -329,25 +396,14 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
                     }
                 }
             }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
             finally {
                 ctx.gate().leave();
             }
 
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            U.writeString(out, cacheName);
-            out.writeObject(topVer);
-            out.writeBoolean(skipStore);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            cacheName = U.readString(in);
-            topVer = (AffinityTopologyVersion)in.readObject();
-            skipStore = in.readBoolean();
+            return true;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
index fd1040f..c5ac847 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
@@ -20,7 +20,6 @@ package org.apache.ignite.internal.processors.cache.distributed;
 import org.apache.ignite.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.*;
-import org.apache.ignite.internal.processors.cache.transactions.*;
 import org.apache.ignite.internal.processors.cache.version.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
@@ -83,12 +82,6 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
     /** Key count. */
     private int txSize;
 
-    /** Group lock key if this is a group-lock transaction. */
-    private IgniteTxKey grpLockKey;
-
-    /** Partition lock flag. Only if group-lock transaction. */
-    private boolean partLock;
-
     /**
      * Additional flags.
      * GridCacheUtils.SKIP_STORE_FLAG_MASK - for skipStore flag value.
@@ -116,9 +109,6 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
      * @param timeout Lock timeout.
      * @param keyCnt Number of keys.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key if this is a group-lock transaction.
-     * @param partLock {@code True} if this is a group-lock transaction request and whole partition is
-     *      locked.
      * @param skipStore Skip store flag.
      */
     public GridDistributedLockRequest(
@@ -135,8 +125,6 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
         long timeout,
         int keyCnt,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
-        boolean partLock,
         boolean skipStore
     ) {
         super(lockVer, keyCnt);
@@ -156,8 +144,6 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
         this.isInvalidate = isInvalidate;
         this.timeout = timeout;
         this.txSize = txSize;
-        this.grpLockKey = grpLockKey;
-        this.partLock = partLock;
 
         retVals = new boolean[keyCnt];
 
@@ -295,27 +281,6 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
     }
 
     /**
-     * @return {@code True} if lock request for group-lock transaction.
-     */
-    public boolean groupLock() {
-        return grpLockKey != null;
-    }
-
-    /**
-     * @return Group lock key.
-     */
-    @Nullable public IgniteTxKey groupLockKey() {
-        return grpLockKey;
-    }
-
-    /**
-     * @return {@code True} if partition is locked in group-lock transaction.
-     */
-    public boolean partitionLock() {
-        return partLock;
-    }
-
-    /**
      * @return Max lock wait time.
      */
     public long timeout() {
@@ -330,9 +295,6 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
         GridCacheContext cctx = ctx.cacheContext(cacheId);
 
         prepareMarshalCacheObjects(keys, cctx);
-
-        if (grpLockKey != null)
-            grpLockKey.prepareMarshal(cctx);
     }
 
     /** {@inheritDoc} */
@@ -342,9 +304,6 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
         GridCacheContext cctx = ctx.cacheContext(cacheId);
 
         finishUnmarshalCacheObjects(keys, cctx, ldr);
-
-        if (grpLockKey != null)
-            grpLockKey.finishUnmarshal(cctx, ldr);
     }
 
     /** {@inheritDoc} */
@@ -375,78 +334,66 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
                 writer.incrementState();
 
             case 10:
-                if (!writer.writeMessage("grpLockKey", grpLockKey))
-                    return false;
-
-                writer.incrementState();
-
-            case 11:
                 if (!writer.writeBoolean("isInTx", isInTx))
                     return false;
 
                 writer.incrementState();
 
-            case 12:
+            case 11:
                 if (!writer.writeBoolean("isInvalidate", isInvalidate))
                     return false;
 
                 writer.incrementState();
 
-            case 13:
+            case 12:
                 if (!writer.writeBoolean("isRead", isRead))
                     return false;
 
                 writer.incrementState();
 
-            case 14:
+            case 13:
                 if (!writer.writeByte("isolation", isolation != null ? (byte)isolation.ordinal() : -1))
                     return false;
 
                 writer.incrementState();
 
-            case 15:
+            case 14:
                 if (!writer.writeCollection("keys", keys, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
 
-            case 16:
+            case 15:
                 if (!writer.writeMessage("nearXidVer", nearXidVer))
                     return false;
 
                 writer.incrementState();
 
-            case 17:
+            case 16:
                 if (!writer.writeUuid("nodeId", nodeId))
                     return false;
 
                 writer.incrementState();
 
-            case 18:
-                if (!writer.writeBoolean("partLock", partLock))
-                    return false;
-
-                writer.incrementState();
-
-            case 19:
+            case 17:
                 if (!writer.writeBooleanArray("retVals", retVals))
                     return false;
 
                 writer.incrementState();
 
-            case 20:
+            case 18:
                 if (!writer.writeLong("threadId", threadId))
                     return false;
 
                 writer.incrementState();
 
-            case 21:
+            case 19:
                 if (!writer.writeLong("timeout", timeout))
                     return false;
 
                 writer.incrementState();
 
-            case 22:
+            case 20:
                 if (!writer.writeInt("txSize", txSize))
                     return false;
 
@@ -485,14 +432,6 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
                 reader.incrementState();
 
             case 10:
-                grpLockKey = reader.readMessage("grpLockKey");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 11:
                 isInTx = reader.readBoolean("isInTx");
 
                 if (!reader.isLastRead())
@@ -500,7 +439,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 12:
+            case 11:
                 isInvalidate = reader.readBoolean("isInvalidate");
 
                 if (!reader.isLastRead())
@@ -508,7 +447,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 13:
+            case 12:
                 isRead = reader.readBoolean("isRead");
 
                 if (!reader.isLastRead())
@@ -516,7 +455,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 14:
+            case 13:
                 byte isolationOrd;
 
                 isolationOrd = reader.readByte("isolation");
@@ -528,7 +467,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 15:
+            case 14:
                 keys = reader.readCollection("keys", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
@@ -536,7 +475,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 16:
+            case 15:
                 nearXidVer = reader.readMessage("nearXidVer");
 
                 if (!reader.isLastRead())
@@ -544,7 +483,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 17:
+            case 16:
                 nodeId = reader.readUuid("nodeId");
 
                 if (!reader.isLastRead())
@@ -552,15 +491,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 18:
-                partLock = reader.readBoolean("partLock");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 19:
+            case 17:
                 retVals = reader.readBooleanArray("retVals");
 
                 if (!reader.isLastRead())
@@ -568,7 +499,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 20:
+            case 18:
                 threadId = reader.readLong("threadId");
 
                 if (!reader.isLastRead())
@@ -576,7 +507,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 21:
+            case 19:
                 timeout = reader.readLong("timeout");
 
                 if (!reader.isLastRead())
@@ -584,7 +515,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 22:
+            case 20:
                 txSize = reader.readInt("txSize");
 
                 if (!reader.isLastRead())
@@ -604,7 +535,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 23;
+        return 21;
     }
 
     /** {@inheritDoc} */


[11/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridBufferedParser.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridBufferedParser.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridBufferedParser.java
index 3f81dc4..a03d2c8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridBufferedParser.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridBufferedParser.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.internal.util.nio;
 
 import org.apache.ignite.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
 
 import java.io.*;
 import java.nio.*;
@@ -33,9 +32,6 @@ import java.nio.*;
  *     | MSG_SIZE  |   MESSAGE  | MSG_SIZE  |   MESSAGE  |
  *     +--+--+--+--+--+--+...+--+--+--+--+--+--+--+...+--+
  * </pre>
- * <p>
- * It expects that first 4 bytes in stream are {@link U#IGNITE_HEADER}. If beginning of a stream,
- * isn't equal to these bytes than exception will be thrown.
  */
 public class GridBufferedParser implements GridNioParser {
     /** Buffer metadata key. */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridDelimitedParser.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridDelimitedParser.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridDelimitedParser.java
new file mode 100644
index 0000000..256597c
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridDelimitedParser.java
@@ -0,0 +1,91 @@
+/*
+ * 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.util.nio;
+
+import org.apache.ignite.*;
+
+import java.io.*;
+import java.nio.*;
+
+/**
+ * This class implements stream parser based on {@link GridNioDelimitedBuffer}.
+ * <p>
+ * The rule for this parser is that every message sent over the stream is appended with
+ * delimiter (bytes array). So, the stream structure is as follows:
+ * <pre>
+ *     +--+--+...+--+--+--+--+--+--+--+...+--+--+--+--+--+-
+ *     |   MESSAGE  | DELIMITER  |  MESSAGE  | DELIMITER  |
+ *     +--+--+...+--+--+--+--+--+--+--+...+--+--+--+--+--+-
+ * </pre>
+ */
+public class GridDelimitedParser implements GridNioParser {
+    /** Buffer metadata key. */
+    private static final int BUF_META_KEY = GridNioSessionMetaKey.nextUniqueKey();
+
+    /** Delimiter. */
+    private final byte[] delim;
+
+    /** Direct buffer. */
+    private final boolean directBuf;
+
+    /**
+     * @param delim Delimiter.
+     * @param directBuf Direct buffer.
+     */
+    public GridDelimitedParser(byte[] delim, boolean directBuf) {
+        this.delim = delim;
+        this.directBuf = directBuf;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] decode(GridNioSession ses, ByteBuffer buf) throws IOException, IgniteCheckedException {
+        GridNioDelimitedBuffer nioBuf = ses.meta(BUF_META_KEY);
+
+        // Decode for a given session is called per one thread, so there should not be any concurrency issues.
+        // However, we make some additional checks.
+        if (nioBuf == null) {
+            nioBuf = new GridNioDelimitedBuffer(delim);
+
+            GridNioDelimitedBuffer old = ses.addMeta(BUF_META_KEY, nioBuf);
+
+            assert old == null;
+        }
+
+        return nioBuf.read(buf);
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer encode(GridNioSession ses, Object msg) throws IOException, IgniteCheckedException {
+        byte[] msg0 = (byte[])msg;
+
+        int cap = msg0.length + delim.length;
+        ByteBuffer res = directBuf ? ByteBuffer.allocateDirect(cap) : ByteBuffer.allocate(cap);
+
+        res.put(msg0);
+        res.put(delim);
+
+        res.flip();
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return this.getClass().getSimpleName();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioDelimitedBuffer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioDelimitedBuffer.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioDelimitedBuffer.java
new file mode 100644
index 0000000..2b764ec
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioDelimitedBuffer.java
@@ -0,0 +1,106 @@
+/*
+ * 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.util.nio;
+
+import org.jetbrains.annotations.*;
+
+import java.nio.*;
+import java.util.*;
+
+/**
+ * Buffer with message delimiter support.
+ */
+public class GridNioDelimitedBuffer {
+    /** Delimiter. */
+    private final byte[] delim;
+
+    /** Data. */
+    private byte[] data = new byte[16384];
+
+    /** Count. */
+    private int cnt;
+
+    /** Index. */
+    private int idx;
+
+    /**
+     * @param delim Delimiter.
+     */
+    public GridNioDelimitedBuffer(byte[] delim) {
+        assert delim != null;
+        assert delim.length > 0;
+
+        this.delim = delim;
+
+        reset();
+    }
+
+    /**
+     * Resets buffer state.
+     */
+    private void reset() {
+        cnt = 0;
+        idx = 0;
+    }
+
+    /**
+     * @param buf Buffer.
+     * @return Message bytes or {@code null} if message is not fully read yet.
+     */
+    @Nullable public byte[] read(ByteBuffer buf) {
+        while(buf.hasRemaining()) {
+            if (cnt == data.length)
+                data = Arrays.copyOf(data, data.length * 2);
+
+            byte b = buf.get();
+
+            data[cnt++] = b;
+
+            if (b == delim[idx])
+                idx++;
+            else if (idx > 0) {
+                int pos = cnt - idx;
+
+                idx = 0;
+
+                for (int i = pos; i < cnt; i++) {
+                    if (data[pos] == delim[idx]) {
+                        pos++;
+
+                        idx++;
+                    }
+                    else {
+                        pos = cnt - idx;
+
+                        idx = 0;
+                    }
+                }
+            }
+
+            if (idx == delim.length) {
+                byte[] bytes = Arrays.copyOfRange(data, 0, cnt - delim.length);
+
+                reset();
+
+                return bytes;
+            }
+        }
+
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java
index 49850ab..a945262 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java
@@ -201,6 +201,15 @@ public interface GridOffHeapPartitionedMap {
     public <T> GridCloseableIterator<T> iterator(CX2<T2<Long, Integer>, T2<Long, Integer>, T> c);
 
     /**
+     * Gets iterator over the partition.
+     *
+     * @param c Key/value closure.
+     * @param part Partition.
+     * @return Iterator over the partition.
+     */
+    public <T> GridCloseableIterator<T> iterator(CX2<T2<Long, Integer>, T2<Long, Integer>, T> c, int part);
+
+    /**
      * Gets iterator over certain partition.
      *
      * @param p Partition.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java
index ba67b30..4ffc33f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java
@@ -277,21 +277,8 @@ public class GridUnsafePartitionedMap implements GridOffHeapPartitionedMap {
 
     /** {@inheritDoc} */
     @Override public GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> iterator() {
-        return new GridCloseableIteratorAdapter<IgniteBiTuple<byte[], byte[]>>() {
-            private int p;
-
-            private GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> curIt;
-
-            {
-                try {
-                    advance();
-                }
-                catch (IgniteCheckedException e) {
-                    e.printStackTrace(); // Should never happen.
-                }
-            }
-
-            private void advance() throws IgniteCheckedException {
+        return new PartitionedMapCloseableIterator<IgniteBiTuple<byte[], byte[]>>() {
+            protected void advance() throws IgniteCheckedException {
                 curIt = null;
 
                 while (p < parts) {
@@ -305,34 +292,6 @@ public class GridUnsafePartitionedMap implements GridOffHeapPartitionedMap {
 
                 curIt = null;
             }
-
-            @Override protected IgniteBiTuple<byte[], byte[]> onNext() throws IgniteCheckedException {
-                if (curIt == null)
-                    throw new NoSuchElementException();
-
-                IgniteBiTuple<byte[], byte[]> t = curIt.next();
-
-                if (!curIt.hasNext()) {
-                    curIt.close();
-
-                    advance();
-                }
-
-                return t;
-            }
-
-            @Override protected boolean onHasNext() {
-                return curIt != null;
-            }
-
-            @Override protected void onRemove() {
-                throw new UnsupportedOperationException();
-            }
-
-            @Override protected void onClose() throws IgniteCheckedException {
-                if (curIt != null)
-                    curIt.close();
-            }
         };
     }
 
@@ -340,21 +299,8 @@ public class GridUnsafePartitionedMap implements GridOffHeapPartitionedMap {
     @Override public <T> GridCloseableIterator<T> iterator(final CX2<T2<Long, Integer>, T2<Long, Integer>, T> c) {
         assert c != null;
 
-        return new GridCloseableIteratorAdapter<T>() {
-            private int p;
-
-            private GridCloseableIterator<T> curIt;
-
-            {
-                try {
-                    advance();
-                }
-                catch (IgniteCheckedException e) {
-                    e.printStackTrace(); // Should never happen.
-                }
-            }
-
-            private void advance() throws IgniteCheckedException {
+        return new PartitionedMapCloseableIterator<T>() {
+            protected void advance() throws IgniteCheckedException {
                 curIt = null;
 
                 while (p < parts) {
@@ -368,38 +314,16 @@ public class GridUnsafePartitionedMap implements GridOffHeapPartitionedMap {
 
                 curIt = null;
             }
-
-            @Override protected T onNext() throws IgniteCheckedException {
-                if (curIt == null)
-                    throw new NoSuchElementException();
-
-                T t = curIt.next();
-
-                if (!curIt.hasNext()) {
-                    curIt.close();
-
-                    advance();
-                }
-
-                return t;
-            }
-
-            @Override protected boolean onHasNext() {
-                return curIt != null;
-            }
-
-            @Override protected void onRemove() {
-                throw new UnsupportedOperationException();
-            }
-
-            @Override protected void onClose() throws IgniteCheckedException {
-                if (curIt != null)
-                    curIt.close();
-            }
         };
     }
 
     /** {@inheritDoc} */
+    @Override public <T> GridCloseableIterator<T> iterator(final CX2<T2<Long, Integer>, T2<Long, Integer>, T> c,
+       int part) {
+       return mapFor(part).iterator(c);
+    }
+
+    /** {@inheritDoc} */
     @Override public GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> iterator(int p) {
         return mapFor(p).iterator();
     }
@@ -430,4 +354,63 @@ public class GridUnsafePartitionedMap implements GridOffHeapPartitionedMap {
     public long lruSize() {
         return lru.size();
     }
+
+    /**
+     *  Partitioned closable iterator.
+     */
+    private abstract class PartitionedMapCloseableIterator<T> extends GridCloseableIteratorAdapter<T> {
+        /** Current partition. */
+        protected int p;
+
+        /** Current iterator. */
+        protected GridCloseableIterator<T> curIt;
+
+        {
+            try {
+                advance();
+            }
+            catch (IgniteCheckedException e) {
+                e.printStackTrace(); // Should never happen.
+            }
+        }
+
+        /**
+         * Switch to next partition.
+         *
+         * @throws IgniteCheckedException If failed.
+         */
+        abstract void advance() throws IgniteCheckedException;
+
+        /** {@inheritDoc} */
+        @Override protected T onNext() throws IgniteCheckedException {
+            if (curIt == null)
+                throw new NoSuchElementException();
+
+            T t = curIt.next();
+
+            if (!curIt.hasNext()) {
+                curIt.close();
+
+                advance();
+            }
+
+            return t;
+        }
+
+        /** {@inheritDoc} */
+        @Override protected boolean onHasNext() {
+            return curIt != null;
+        }
+
+        /** {@inheritDoc} */
+        @Override protected void onRemove() {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override protected void onClose() throws IgniteCheckedException {
+            if (curIt != null)
+                curIt.close();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelper.java
index 82ef421..a9e9e93 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelper.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelper.java
@@ -69,7 +69,7 @@ public interface IgniteSpringHelper {
      * Loads all configurations with given type specified within given configuration file.
      *
      * @param cfgUrl Configuration file path or URL. This cannot be {@code null}.
-     * @param cl Required type of configuration.
+     * @param cls Required type of configuration.
      * @param excludedProps Properties to exclude.
      * @return Tuple containing all loaded configurations and Spring context used to load them.
      * @throws IgniteCheckedException If configuration could not be read.
@@ -81,7 +81,7 @@ public interface IgniteSpringHelper {
      * Loads all configurations with given type specified within given configuration input stream.
      *
      * @param cfgStream Configuration input stream. This cannot be {@code null}.
-     * @param cl Required type of configuration.
+     * @param cls Required type of configuration.
      * @param excludedProps Properties to exclude.
      * @return Tuple containing all loaded configurations and Spring context used to load them.
      * @throws IgniteCheckedException If configuration could not be read.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java
index c05b9e0..30be424 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheMetrics.java
@@ -29,7 +29,7 @@ import java.io.*;
  */
 public class VisorCacheMetrics implements Serializable {
     /** */
-    private static final int MICROSECONDS_IN_SECOND = 1_000_000;
+    private static final float MICROSECONDS_IN_SECOND = 1_000_000;
 
     /** */
     private static final long serialVersionUID = 0L;
@@ -94,14 +94,11 @@ public class VisorCacheMetrics implements Serializable {
     /** Reads per second. */
     private int readsPerSec;
 
-    /** Writes per second. */
-    private int writesPerSec;
+    /** Puts per second. */
+    private int putsPerSec;
 
-    /** Hits per second. */
-    private int hitsPerSec;
-
-    /** Misses per second. */
-    private int missesPerSec;
+    /** Removes per second. */
+    private int removalsPerSec;
 
     /** Commits per second. */
     private int commitsPerSec;
@@ -160,15 +157,11 @@ public class VisorCacheMetrics implements Serializable {
     /**
      * Calculate rate of metric per second.
      *
-     * @param metric Metric value.
-     * @param time Metric finish time.
-     * @param createTime Metric start time.
+     * @param meanTime Metric mean time.
      * @return Metric per second.
      */
-    private static int perSecond(int metric, long time, long createTime) {
-        long seconds = (time - createTime) / 1000;
-
-        return (seconds > 0) ? (int)(metric / seconds) : 0;
+    private static int perSecond(float meanTime) {
+        return (meanTime > 0) ? (int)(MICROSECONDS_IN_SECOND / meanTime) : 0;
     }
 
     /**
@@ -209,12 +202,11 @@ public class VisorCacheMetrics implements Serializable {
         cm.avgPutTime = m.getAveragePutTime();
         cm.avgRemovalTime = m.getAverageRemoveTime();
 
-        cm.readsPerSec = (int)(MICROSECONDS_IN_SECOND * 1.f / m.getAverageGetTime());
-        cm.writesPerSec = (int)(MICROSECONDS_IN_SECOND * 1.f / m.getAveragePutTime());
-        cm.hitsPerSec = -1;
-        cm.missesPerSec = (int)(MICROSECONDS_IN_SECOND * 1.f / m.getAverageRemoveTime());
-        cm.commitsPerSec = (int)(MICROSECONDS_IN_SECOND * 1.f / m.getAverageTxCommitTime());
-        cm.rollbacksPerSec = (int)(MICROSECONDS_IN_SECOND * 1.f / m.getAverageTxRollbackTime());
+        cm.readsPerSec = perSecond(m.getAverageGetTime());
+        cm.putsPerSec = perSecond(m.getAveragePutTime());
+        cm.removalsPerSec = perSecond(m.getAverageRemoveTime());
+        cm.commitsPerSec = perSecond(m.getAverageTxCommitTime());
+        cm.rollbacksPerSec = perSecond(m.getAverageTxRollbackTime());
 
         cm.qryMetrics = VisorCacheQueryMetrics.from(c.context().queries().metrics());
 
@@ -364,24 +356,17 @@ public class VisorCacheMetrics implements Serializable {
     }
 
     /**
-     * @return Writes per second.
-     */
-    public int writesPerSecond() {
-        return writesPerSec;
-    }
-
-    /**
-     * @return Hits per second.
+     * @return Puts per second.
      */
-    public int hitsPerSecond() {
-        return hitsPerSec;
+    public int putsPerSecond() {
+        return putsPerSec;
     }
 
     /**
-     * @return Misses per second.
+     * @return Removes per second.
      */
-    public int missesPerSecond() {
-        return missesPerSec;
+    public int removalsPerSecond() {
+        return removalsPerSec;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheNearConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheNearConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheNearConfiguration.java
index a968f4f..3706650 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheNearConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheNearConfiguration.java
@@ -33,7 +33,7 @@ public class VisorCacheNearConfiguration implements Serializable {
     /** */
     private static final long serialVersionUID = 0L;
 
-    /** Flag to enable/disable near cache eviction policy. */
+    /** Flag indicating if near cache enabled. */
     private boolean nearEnabled;
 
     /** Near cache start size. */
@@ -66,7 +66,7 @@ public class VisorCacheNearConfiguration implements Serializable {
     }
 
     /**
-     * @return Flag to enable/disable near cache eviction policy.
+     * @return {@code true} if near cache enabled.
      */
     public boolean nearEnabled() {
         return nearEnabled;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartTask.java
new file mode 100644
index 0000000..2aa03a2
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartTask.java
@@ -0,0 +1,155 @@
+/*
+ * 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.visor.cache;
+
+import org.apache.ignite.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.processors.task.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.internal.visor.*;
+import org.apache.ignite.internal.visor.util.*;
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Task that start cache or near cache with specified configuration.
+ */
+@GridInternal
+public class VisorCacheStartTask extends
+    VisorMultiNodeTask<VisorCacheStartTask.VisorCacheStartArg, Map<UUID, IgniteException>, Void> {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** {@inheritDoc} */
+    @Override protected VisorCacheStartJob job(VisorCacheStartArg arg) {
+        return new VisorCacheStartJob(arg, debug);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override protected Map<UUID, IgniteException> reduce0(List<ComputeJobResult> results) throws IgniteException {
+        Map<UUID, IgniteException> map = new HashMap<>();
+
+        for (ComputeJobResult res : results)
+            if (res.getException() != null)
+                map.put(res.getNode().id(), res.getException());
+
+        return map;
+    }
+
+    /**
+     * Cache start arguments.
+     */
+    @SuppressWarnings("PublicInnerClass")
+    public static class VisorCacheStartArg implements Serializable {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** */
+        private final boolean near;
+
+        /** */
+        private final String name;
+
+        /** */
+        private final String cfg;
+
+        /**
+         * @param near {@code true} if near cache should be started.
+         * @param name Name for near cache.
+         * @param cfg Cache XML configuration.
+         */
+        public VisorCacheStartArg(boolean near, String name, String cfg) {
+            this.near = near;
+            this.name = name;
+            this.cfg = cfg;
+        }
+
+        /**
+         * @return {@code true} if near cache should be started.
+         */
+        public boolean near() {
+            return near;
+        }
+
+        /**
+         * @return Name for near cache.
+         */
+        public String name() {
+            return name;
+        }
+
+        /**
+         * @return Cache XML configuration.
+         */
+        public String configuration() {
+            return cfg;
+        }
+    }
+
+    /**
+     * Job that start cache or near cache with specified configuration.
+     */
+    private static class VisorCacheStartJob extends VisorJob<VisorCacheStartArg, Void> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /**
+         * Create job.
+         *
+         * @param arg Contains cache name and XML configurations of cache.
+         * @param debug Debug flag.
+         */
+        private VisorCacheStartJob(VisorCacheStartArg arg, boolean debug) {
+            super(arg, debug);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected Void run(VisorCacheStartArg arg) throws IgniteException {
+            String cfg = arg.configuration();
+
+            assert !F.isEmpty(cfg);
+
+            try (ByteArrayInputStream bais = new ByteArrayInputStream(cfg.getBytes())) {
+                if (arg.near) {
+                    NearCacheConfiguration nearCfg = Ignition.loadSpringBean(bais, "nearCacheConfiguration");
+
+                    ignite.createNearCache(VisorTaskUtils.unescapeName(arg.name()), nearCfg);
+                }
+                else {
+                    CacheConfiguration cacheCfg = Ignition.loadSpringBean(bais, "cacheConfiguration");
+
+                    ignite.createCache(cacheCfg);
+                }
+            }
+            catch (IOException e) {
+                throw new  IgniteException(e);
+            }
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(VisorCacheStartJob.class, this);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryArg.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryArg.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryArg.java
index becebda..5050414 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryArg.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryArg.java
@@ -32,17 +32,22 @@ public class VisorQueryArg implements Serializable {
     /** Query text. */
     private final String qryTxt;
 
+    /** Flag whether to execute query locally. */
+    private final boolean local;
+
     /** Result batch size. */
     private final int pageSize;
 
     /**
      * @param cacheName Cache name for query.
      * @param qryTxt Query text.
+     * @param local Flag whether to execute query locally.
      * @param pageSize Result batch size.
      */
-    public VisorQueryArg(String cacheName, String qryTxt, int pageSize) {
+    public VisorQueryArg(String cacheName, String qryTxt, boolean local, int pageSize) {
         this.cacheName = cacheName;
         this.qryTxt = qryTxt;
+        this.local = local;
         this.pageSize = pageSize;
     }
 
@@ -61,6 +66,13 @@ public class VisorQueryArg implements Serializable {
     }
 
     /**
+     * @return {@code true} if query should be executed locally.
+     */
+    public boolean local() {
+        return local;
+    }
+
+    /**
      * @return Page size.
      */
     public int pageSize() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java
index ebf62fa..4a9daad 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java
@@ -75,6 +75,7 @@ public class VisorQueryJob extends VisorJob<VisorQueryArg, IgniteBiTuple<? exten
             if (scan) {
                 ScanQuery<Object, Object> qry = new ScanQuery<>(null);
                 qry.setPageSize(arg.pageSize());
+                qry.setLocal(arg.local());
 
                 long start = U.currentTimeMillis();
 
@@ -100,6 +101,7 @@ public class VisorQueryJob extends VisorJob<VisorQueryArg, IgniteBiTuple<? exten
             else {
                 SqlFieldsQuery qry = new SqlFieldsQuery(arg.queryTxt());
                 qry.setPageSize(arg.pageSize());
+                qry.setLocal(arg.local());
 
                 long start = U.currentTimeMillis();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java
index 7cfc18f..e8ae76d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java
@@ -120,6 +120,16 @@ public class VisorTaskUtils {
     }
 
     /**
+     * @param name Escaped name.
+     * @return Name or {@code null} for default name.
+     */
+    public static String unescapeName(String name) {
+        assert name != null;
+
+        return DFLT_EMPTY_NAME.equals(name) ? null : name;
+    }
+
+    /**
      * @param a First name.
      * @param b Second name.
      * @return {@code true} if both names equals.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncSupport.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncSupport.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncSupport.java
index 76ebcee..be05a38 100644
--- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncSupport.java
+++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncSupport.java
@@ -22,9 +22,9 @@ package org.apache.ignite.lang;
  */
 public interface IgniteAsyncSupport {
     /**
-     * Gets component with asynchronous mode enabled.
+     * Gets instance of this component with asynchronous mode enabled.
      *
-     * @return Component with asynchronous mode enabled.
+     * @return Instance of this component with asynchronous mode enabled.
      */
     public IgniteAsyncSupport withAsync();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/services/Service.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/services/Service.java b/modules/core/src/main/java/org/apache/ignite/services/Service.java
index 2bd5649..4f927a3 100644
--- a/modules/core/src/main/java/org/apache/ignite/services/Service.java
+++ b/modules/core/src/main/java/org/apache/ignite/services/Service.java
@@ -55,10 +55,7 @@ import java.io.*;
  * ...
  * GridServices svcs = grid.services();
  *
- * GridFuture&lt;?&gt; fut = svcs.deployClusterSingleton("mySingleton", new MyGridService());
- *
- * // Wait for deployment to complete.
- * fut.get();
+ * svcs.deployClusterSingleton("mySingleton", new MyGridService());
  * </pre>
  * Or from grid configuration on startup:
  * <pre name="code" class="java">

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
index b43f8a5..871512c 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
@@ -67,7 +67,7 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
     private String name;
 
     /** Grid SPI context. */
-    private volatile IgniteSpiContext spiCtx = new GridDummySpiContext(null, false);
+    private volatile IgniteSpiContext spiCtx = new GridDummySpiContext(null, false, null);
 
     /** Discovery listener. */
     private GridLocalEventListener paramsLsnr;
@@ -190,7 +190,7 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
         ClusterNode locNode = spiCtx == null ? null : spiCtx.localNode();
 
         // Set dummy no-op context.
-        spiCtx = new GridDummySpiContext(locNode, true);
+        spiCtx = new GridDummySpiContext(locNode, true, spiCtx);
     }
 
     /**
@@ -551,15 +551,24 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
         /** */
         private final boolean stopping;
 
+        /** */
+        private final MessageFactory msgFactory;
+
+        /** */
+        private final MessageFormatter msgFormatter;
+
         /**
          * Create temp SPI context.
          *
          * @param locNode Local node.
          * @param stopping Node stopping flag.
+         * @param spiCtx SPI context.
          */
-        GridDummySpiContext(ClusterNode locNode, boolean stopping) {
+        GridDummySpiContext(ClusterNode locNode, boolean stopping, @Nullable IgniteSpiContext spiCtx) {
             this.locNode = locNode;
             this.stopping = stopping;
+            this.msgFactory = spiCtx != null ? spiCtx.messageFactory() : null;
+            this.msgFormatter = spiCtx != null ? spiCtx.messageFormatter() : null;
         }
 
         /** {@inheritDoc} */
@@ -711,12 +720,12 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
 
         /** {@inheritDoc} */
         @Override public MessageFormatter messageFormatter() {
-            return null;
+            return msgFormatter;
         }
 
         /** {@inheritDoc} */
         @Override public MessageFactory messageFactory() {
-            return null;
+            return msgFactory;
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
index 2d5c541..fd17791 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
@@ -203,7 +203,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter
     public static final int DFLT_ACK_SND_THRESHOLD = 16;
 
     /** Default socket write timeout. */
-    public static final long DFLT_SOCK_WRITE_TIMEOUT = GridNioServer.DFLT_SES_WRITE_TIMEOUT;
+    public static final long DFLT_SOCK_WRITE_TIMEOUT = 200;
 
     /** No-op runnable. */
     private static final IgniteRunnable NOOP = new IgniteRunnable() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySpi.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySpi.java
index e3182c4..4196306 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySpi.java
@@ -226,10 +226,6 @@ public class TcpClientDiscoverySpi extends TcpDiscoverySpiAdapter implements Tcp
         if (netTimeout < 3000)
             U.warn(log, "Network timeout is too low (at least 3000 ms recommended): " + netTimeout);
 
-        // Warn on odd heartbeat frequency.
-        if (hbFreq < 2000)
-            U.warn(log, "Heartbeat frequency is too high (at least 2000 ms recommended): " + hbFreq);
-
         registerMBean(gridName, this, TcpClientDiscoverySpiMBean.class);
 
         try {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
index 206a8c3..ed0e9dd 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
@@ -288,6 +288,10 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
     @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
     private ConcurrentLinkedDeque<String> debugLog;
 
+    /** */
+    private final CopyOnWriteArrayList<IgniteInClosure<TcpDiscoveryAbstractMessage>> sendMsgLsnrs =
+        new CopyOnWriteArrayList<>();
+
     /** {@inheritDoc} */
     @IgniteInstanceResource
     @Override public void injectResources(Ignite ignite) {
@@ -853,10 +857,6 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
         if (netTimeout < 3000)
             U.warn(log, "Network timeout is too low (at least 3000 ms recommended): " + netTimeout);
 
-        // Warn on odd heartbeat frequency.
-        if (hbFreq < 2000)
-            U.warn(log, "Heartbeat frequency is too high (at least 2000 ms recommended): " + hbFreq);
-
         registerMBean(gridName, this, TcpDiscoverySpiMBean.class);
 
         if (ipFinder instanceof TcpDiscoveryMulticastIpFinder) {
@@ -2068,13 +2068,16 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
 
     /**
      * <strong>FOR TEST ONLY!!!</strong>
-     * <p>
-     * This method is intended for test purposes only.
-     *
-     * @param msg Message.
      */
-    void onBeforeMessageSentAcrossRing(Serializable msg) {
-        // No-op.
+    public void addSendMessageListener(IgniteInClosure<TcpDiscoveryAbstractMessage> msg) {
+        sendMsgLsnrs.add(msg);
+    }
+
+    /**
+     * <strong>FOR TEST ONLY!!!</strong>
+     */
+    public void removeSendMessageListener(IgniteInClosure<TcpDiscoveryAbstractMessage> msg) {
+        sendMsgLsnrs.remove(msg);
     }
 
     /**
@@ -2683,11 +2686,30 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
 
             assert ring.hasRemoteNodes();
 
-            onBeforeMessageSentAcrossRing(msg);
+            for (IgniteInClosure<TcpDiscoveryAbstractMessage> msgLsnr : sendMsgLsnrs)
+                msgLsnr.apply(msg);
 
             if (redirectToClients(msg)) {
-                for (ClientMessageWorker clientMsgWorker : clientMsgWorkers.values())
-                    clientMsgWorker.addMessage(msg);
+                byte[] marshalledMsg = null;
+
+                for (ClientMessageWorker clientMsgWorker : clientMsgWorkers.values()) {
+                    // Send a clone to client to avoid ConcurrentModificationException
+                    TcpDiscoveryAbstractMessage msgClone;
+
+                    try {
+                        if (marshalledMsg == null)
+                            marshalledMsg = marsh.marshal(msg);
+
+                        msgClone = marsh.unmarshal(marshalledMsg, null);
+                    }
+                    catch (IgniteCheckedException e) {
+                        U.error(log, "Failed to marshal message: " + msg, e);
+
+                        msgClone = msg;
+                    }
+
+                    clientMsgWorker.addMessage(msgClone);
+                }
             }
 
             Collection<TcpDiscoveryNode> failedNodes;
@@ -3930,18 +3952,6 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
                 long topVer;
 
                 if (locNodeCoord) {
-                    if (!msg.client() && ipFinder.isShared()) {
-                        try {
-                            ipFinder.unregisterAddresses(leftNode.socketAddresses());
-                        }
-                        catch (IgniteSpiException e) {
-                            if (log.isDebugEnabled())
-                                log.debug("Failed to unregister left node address: " + leftNode);
-
-                            onException("Failed to unregister left node address: " + leftNode, e);
-                        }
-                    }
-
                     topVer = ring.incrementTopologyVersion();
 
                     msg.topologyVersion(topVer);
@@ -4109,20 +4119,6 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
                 long topVer;
 
                 if (locNodeCoord) {
-                    if (!node.isClient() && ipFinder.isShared()) {
-                        try {
-                            ipFinder.unregisterAddresses(node.socketAddresses());
-                        }
-                        catch (IgniteSpiException e) {
-                            if (log.isDebugEnabled())
-                                log.debug("Failed to unregister failed node address [node=" + node +
-                                    ", err=" + e.getMessage() + ']');
-
-                            onException("Failed to unregister failed node address [node=" + node +
-                                ", err=" + e.getMessage() + ']', e);
-                        }
-                    }
-
                     topVer = ring.incrementTopologyVersion();
 
                     msg.topologyVersion(topVer);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiAdapter.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiAdapter.java
index 26f6869..802da02 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiAdapter.java
@@ -51,20 +51,20 @@ abstract class TcpDiscoverySpiAdapter extends IgniteSpiAdapter implements Discov
     /** Default port to listen (value is <tt>47500</tt>). */
     public static final int DFLT_PORT = 47500;
 
-    /** Default socket operations timeout in milliseconds (value is <tt>2,000ms</tt>). */
-    public static final long DFLT_SOCK_TIMEOUT = 2000;
+    /** Default socket operations timeout in milliseconds (value is <tt>200ms</tt>). */
+    public static final long DFLT_SOCK_TIMEOUT = 200;
 
-    /** Default timeout for receiving message acknowledgement in milliseconds (value is <tt>5,000ms</tt>). */
-    public static final long DFLT_ACK_TIMEOUT = 5000;
+    /** Default timeout for receiving message acknowledgement in milliseconds (value is <tt>50ms</tt>). */
+    public static final long DFLT_ACK_TIMEOUT = 50;
 
-    /** Default network timeout in milliseconds (value is <tt>5,000ms</tt>). */
+    /** Default network timeout in milliseconds (value is <tt>5000ms</tt>). */
     public static final long DFLT_NETWORK_TIMEOUT = 5000;
 
     /** Default value for thread priority (value is <tt>10</tt>). */
     public static final int DFLT_THREAD_PRI = 10;
 
-    /** Default heartbeat messages issuing frequency (value is <tt>2,000ms</tt>). */
-    public static final long DFLT_HEARTBEAT_FREQ = 2000;
+    /** Default heartbeat messages issuing frequency (value is <tt>100ms</tt>). */
+    public static final long DFLT_HEARTBEAT_FREQ = 100;
 
     /** Default size of topology snapshots history. */
     public static final int DFLT_TOP_HISTORY_SIZE = 1000;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java b/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java
new file mode 100644
index 0000000..0c4e2d1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java
@@ -0,0 +1,111 @@
+/*
+ * 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.stream;
+
+import org.apache.ignite.*;
+
+import java.util.*;
+
+/**
+ * Convenience adapter for streamers. Adapters are optional components for
+ * streaming from different data sources. The purpose of adapters is to
+ * convert different message formats into Ignite stream key-value tuples
+ * and feed the tuples into the provided {@link org.apache.ignite.IgniteDataStreamer}.
+ */
+public abstract class StreamAdapter<T, K, V> {
+    /** Tuple extractor. */
+    private StreamTupleExtractor<T, K, V> extractor;
+
+    /** Streamer. */
+    private IgniteDataStreamer<K, V> stmr;
+
+    /** Ignite. */
+    private Ignite ignite;
+
+    /**
+     * Empty constructor.
+     */
+    protected StreamAdapter() {
+        // No-op.
+    }
+
+    /**
+     * Stream adapter.
+     *
+     * @param stmr Streamer.
+     * @param extractor Tuple extractor.
+     */
+    protected StreamAdapter(IgniteDataStreamer<K, V> stmr, StreamTupleExtractor<T, K, V> extractor) {
+        this.stmr = stmr;
+        this.extractor = extractor;
+    }
+
+    /**
+     * @return Provided data streamer.
+     */
+    public IgniteDataStreamer<K, V> getStreamer() {
+        return stmr;
+    }
+
+    /**
+     * @param stmr Ignite data streamer.
+     */
+    public void setStreamer(IgniteDataStreamer<K, V> stmr) {
+        this.stmr = stmr;
+    }
+
+    /**
+     * @return Provided tuple extractor.
+     */
+    public StreamTupleExtractor<T, K, V> getTupleExtractor() {
+        return extractor;
+    }
+
+    /**
+     * @param extractor Extractor for key-value tuples from messages.
+     */
+    public void setTupleExtractor(StreamTupleExtractor<T, K, V> extractor) {
+        this.extractor = extractor;
+    }
+
+    /**
+     * @return Provided {@link Ignite} instance.
+     */
+    public Ignite getIgnite() {
+        return ignite;
+    }
+
+    /**
+     * @param ignite {@link Ignite} instance.
+     */
+    public void setIgnite(Ignite ignite) {
+        this.ignite = ignite;
+    }
+
+    /**
+     * Converts given message to a tuple and adds it to the underlying streamer.
+     *
+     * @param msg Message to convert.
+     */
+    protected void addMessage(T msg) {
+        Map.Entry<K, V> e = extractor.extract(msg);
+
+        if (e != null)
+            stmr.addData(e);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/stream/StreamTupleExtractor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/stream/StreamTupleExtractor.java b/modules/core/src/main/java/org/apache/ignite/stream/StreamTupleExtractor.java
new file mode 100644
index 0000000..d2a4ede
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/stream/StreamTupleExtractor.java
@@ -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.
+ */
+
+package org.apache.ignite.stream;
+
+import java.util.*;
+
+/**
+ * Stream tuple extractor to convert messages to Ignite key-value tuples.
+ */
+public interface StreamTupleExtractor<T, K, V> {
+    /**
+     * Extracts a key-value tuple from a message.
+     *
+     * @param msg Message.
+     * @return Key-value tuple.
+     */
+    public Map.Entry<K, V> extract(T msg);
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketMessageConverter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketMessageConverter.java b/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketMessageConverter.java
new file mode 100644
index 0000000..8161d86
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketMessageConverter.java
@@ -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.
+ */
+
+package org.apache.ignite.stream.socket;
+
+/**
+ * Socket message converter.
+ */
+public interface SocketMessageConverter<T> {
+    /**
+     * Converter message represented by array of bytes to object.
+     *
+     * @param msg Message.
+     * @return Converted object.
+     */
+    public T convert(byte[] msg);
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketStreamer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketStreamer.java b/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketStreamer.java
new file mode 100644
index 0000000..07ce77e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketStreamer.java
@@ -0,0 +1,218 @@
+/*
+ * 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.stream.socket;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.util.nio.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.marshaller.jdk.*;
+import org.apache.ignite.stream.*;
+
+import org.jetbrains.annotations.*;
+
+import java.net.*;
+import java.nio.*;
+
+/**
+ * Server that receives data from TCP socket, converts it to key-value pairs using {@link StreamTupleExtractor} and
+ * streams into {@link IgniteDataStreamer} instance.
+ * <p>
+ * By default server uses size-based message processing. That is every message sent over the socket is prepended with
+ * 4-byte integer header containing message size. If message delimiter is defined (see {@link #setDelimiter}) then
+ * delimiter-based message processing will be used. That is every message sent over the socket is appended with
+ * provided delimiter.
+ * <p>
+ * Received messages through socket converts to Java object using standard serialization. Conversion functionality
+ * can be customized via user defined {@link SocketMessageConverter} (e.g. in order to convert messages from
+ * non Java clients).
+ */
+public class SocketStreamer<T, K, V> extends StreamAdapter<T, K, V> {
+    /** Default threads. */
+    private static final int DFLT_THREADS = Runtime.getRuntime().availableProcessors();
+
+    /** Logger. */
+    private IgniteLogger log;
+
+    /** Address. */
+    private InetAddress addr;
+
+    /** Server port. */
+    private int port;
+
+    /** Threads number. */
+    private int threads = DFLT_THREADS;
+
+    /** Direct mode. */
+    private boolean directMode;
+
+    /** Delimiter. */
+    private byte[] delim;
+
+    /** Converter. */
+    private SocketMessageConverter<T> converter;
+
+    /** Server. */
+    private GridNioServer<byte[]> srv;
+
+    /**
+     * Sets server address.
+     *
+     * @param addr Address.
+     */
+    public void setAddr(InetAddress addr) {
+        this.addr = addr;
+    }
+
+    /**
+     * Sets port number.
+     *
+     * @param port Port.
+     */
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+    /**
+     * Sets threadds amount.
+     *
+     * @param threads Threads.
+     */
+    public void setThreads(int threads) {
+        this.threads = threads;
+    }
+
+    /**
+     * Sets direct mode flag.
+     *
+     * @param directMode Direct mode.
+     */
+    public void setDirectMode(boolean directMode) {
+        this.directMode = directMode;
+    }
+
+    /**
+     * Sets message delimiter.
+     *
+     * @param delim Delimiter.
+     */
+    public void setDelimiter(byte[] delim) {
+        this.delim = delim;
+    }
+
+    /**
+     * Sets message converter.
+     *
+     * @param converter Converter.
+     */
+    public void setConverter(SocketMessageConverter<T> converter) {
+        this.converter = converter;
+    }
+
+    /**
+     * Starts streamer.
+     *
+     * @throws IgniteException If failed.
+     */
+    public void start() {
+        A.notNull(getTupleExtractor(), "tupleExtractor");
+        A.notNull(getStreamer(), "streamer");
+        A.notNull(getIgnite(), "ignite");
+        A.ensure(threads > 0, "threads > 0");
+
+        log = getIgnite().log();
+
+        GridNioServerListener<byte[]> lsnr = new GridNioServerListenerAdapter<byte[]>() {
+            @Override public void onConnected(GridNioSession ses) {
+                assert ses.accepted();
+
+                if (log.isDebugEnabled())
+                    log.debug("Accepted connection: " + ses.remoteAddress());
+            }
+
+            @Override public void onDisconnected(GridNioSession ses, @Nullable Exception e) {
+                if (e != null)
+                    log.error("Connection failed with exception", e);
+            }
+
+            @Override public void onMessage(GridNioSession ses, byte[] msg) {
+                addMessage(converter.convert(msg));
+            }
+        };
+
+        ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
+
+        GridNioParser parser = F.isEmpty(delim) ? new GridBufferedParser(directMode, byteOrder) :
+            new GridDelimitedParser(delim, directMode);
+
+        if (converter == null)
+            converter = new DefaultConverter<>();
+
+        GridNioFilter codec = new GridNioCodecFilter(parser, log, directMode);
+
+        GridNioFilter[] filters = new GridNioFilter[] {codec};
+
+        try {
+            srv = new GridNioServer.Builder<byte[]>()
+                .address(addr == null ? InetAddress.getLocalHost() : addr)
+                .port(port)
+                .listener(lsnr)
+                .logger(log)
+                .selectorCount(threads)
+                .byteOrder(byteOrder)
+                .filters(filters)
+                .build();
+        }
+        catch (IgniteCheckedException | UnknownHostException e) {
+            throw new IgniteException(e);
+        }
+
+        srv.start();
+
+        if (log.isDebugEnabled())
+            log.debug("Socket streaming server started on " + addr + ':' + port);
+    }
+
+    /**
+     * Stops streamer.
+     */
+    public void stop() {
+        srv.stop();
+
+        if (log.isDebugEnabled())
+            log.debug("Socket streaming server stopped");
+    }
+
+    /**
+     * Converts message to Java object using Jdk marshaller.
+     */
+    private static class DefaultConverter<T> implements SocketMessageConverter<T> {
+        /** Marshaller. */
+        private static final JdkMarshaller MARSH = new JdkMarshaller();
+
+        /** {@inheritDoc} */
+        @Override public T convert(byte[] msg) {
+            try {
+                return MARSH.unmarshal(msg, null);
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException(e);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/stream/socket/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/stream/socket/package-info.java b/modules/core/src/main/java/org/apache/ignite/stream/socket/package-info.java
new file mode 100644
index 0000000..e1cef65
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/stream/socket/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Contains socket streamer implementation.
+ */
+package org.apache.ignite.stream.socket;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/resources/META-INF/classnames.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties
index a79d5b8..b3eed46 100644
--- a/modules/core/src/main/resources/META-INF/classnames.properties
+++ b/modules/core/src/main/resources/META-INF/classnames.properties
@@ -115,6 +115,7 @@ org.apache.ignite.configuration.CollectionConfiguration
 org.apache.ignite.configuration.DeploymentMode
 org.apache.ignite.configuration.IgniteReflectionFactory
 org.apache.ignite.configuration.NearCacheConfiguration
+org.apache.ignite.configuration.TopologyValidator
 org.apache.ignite.configuration.TransactionConfiguration
 org.apache.ignite.events.CacheEvent
 org.apache.ignite.events.CacheQueryExecutedEvent
@@ -248,6 +249,7 @@ org.apache.ignite.internal.managers.communication.GridIoManager$ConcurrentHashMa
 org.apache.ignite.internal.managers.communication.GridIoMessage
 org.apache.ignite.internal.managers.communication.GridIoPolicy
 org.apache.ignite.internal.managers.communication.GridIoUserMessage
+org.apache.ignite.internal.managers.communication.GridLifecycleAwareMessageFilter
 org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean
 org.apache.ignite.internal.managers.deployment.GridDeploymentPerVersionStore$2
 org.apache.ignite.internal.managers.deployment.GridDeploymentRequest
@@ -321,13 +323,13 @@ org.apache.ignite.internal.processors.cache.GridCacheAdapter$72
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$73
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$74
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$9
-org.apache.ignite.internal.processors.cache.GridCacheAdapter$GlobalClearAllCallable
+org.apache.ignite.internal.processors.cache.GridCacheAdapter$GlobalClearAllJob
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$GlobalClearCallable
-org.apache.ignite.internal.processors.cache.GridCacheAdapter$GlobalClearKeySetCallable
+org.apache.ignite.internal.processors.cache.GridCacheAdapter$GlobalClearKeySetJob
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$GlobalSizeCallable
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$LoadCacheClosure
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$LoadKeysCallable
-org.apache.ignite.internal.processors.cache.GridCacheAdapter$SizeCallable
+org.apache.ignite.internal.processors.cache.GridCacheAdapter$SizeJob
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$UpdateGetTimeStatClosure
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$UpdatePutAndGetTimeStatClosure
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$UpdatePutTimeStatClosure
@@ -445,6 +447,7 @@ org.apache.ignite.internal.processors.cache.IgniteCacheProxy$2
 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$4
 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$5
 org.apache.ignite.internal.processors.cache.IgniteCacheProxy$6
+org.apache.ignite.internal.processors.cache.IgniteCacheProxy$7
 org.apache.ignite.internal.processors.cache.KeyCacheObject
 org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl
 org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityProxy
@@ -452,8 +455,9 @@ org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresMa
 org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager$QueueHeaderPredicate
 org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager$RemoveSetDataCallable
 org.apache.ignite.internal.processors.cache.distributed.GridCacheCommittedTxInfo
-org.apache.ignite.internal.processors.cache.distributed.GridCacheOptimisticCheckPreparedTxRequest
-org.apache.ignite.internal.processors.cache.distributed.GridCacheOptimisticCheckPreparedTxResponse
+org.apache.ignite.internal.processors.cache.distributed.GridCacheTxRecoveryFuture$1
+org.apache.ignite.internal.processors.cache.distributed.GridCacheTxRecoveryRequest
+org.apache.ignite.internal.processors.cache.distributed.GridCacheTxRecoveryResponse
 org.apache.ignite.internal.processors.cache.distributed.GridCacheTtlUpdateRequest
 org.apache.ignite.internal.processors.cache.distributed.GridDistributedBaseMessage
 org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheAdapter
@@ -725,6 +729,7 @@ org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$11
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$12
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$13
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$14
+org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$15
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$2
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$3
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$4
@@ -762,9 +767,11 @@ org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter$Po
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter$PostLockClosure2
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter$PostMissClosure
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager$2
+org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager$3
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager$AtomicInt
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager$CommitListener
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager$CommittedVersion
+org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager$NodeFailureTimeoutObject$1
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxMap
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxMap$1
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxMap$1$1
@@ -809,6 +816,7 @@ org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$Discove
 org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$DiscoveryDataItem
 org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$StartRequestData
 org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor$3
+org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor$4
 org.apache.ignite.internal.processors.datastreamer.DataStreamerCacheUpdaters$Batched
 org.apache.ignite.internal.processors.datastreamer.DataStreamerCacheUpdaters$BatchedSorted
 org.apache.ignite.internal.processors.datastreamer.DataStreamerCacheUpdaters$Individual
@@ -1132,7 +1140,6 @@ org.apache.ignite.internal.util.lang.GridAbsClosure
 org.apache.ignite.internal.util.lang.GridAbsClosureX
 org.apache.ignite.internal.util.lang.GridCloseableIterator
 org.apache.ignite.internal.util.lang.GridClosureException
-org.apache.ignite.internal.util.lang.GridComputeJobWrapper
 org.apache.ignite.internal.util.lang.GridFunc$1
 org.apache.ignite.internal.util.lang.GridFunc$10
 org.apache.ignite.internal.util.lang.GridFunc$100
@@ -1383,6 +1390,8 @@ org.apache.ignite.internal.visor.cache.VisorCacheMetrics
 org.apache.ignite.internal.visor.cache.VisorCacheMetricsCollectorTask
 org.apache.ignite.internal.visor.cache.VisorCacheMetricsCollectorTask$VisorCacheMetricsCollectorJob
 org.apache.ignite.internal.visor.cache.VisorCacheNearConfiguration
+org.apache.ignite.internal.visor.cache.VisorCacheNodesTask
+org.apache.ignite.internal.visor.cache.VisorCacheNodesTask$VisorCacheNodesJob
 org.apache.ignite.internal.visor.cache.VisorCacheQueryConfiguration
 org.apache.ignite.internal.visor.cache.VisorCacheQueryMetrics
 org.apache.ignite.internal.visor.cache.VisorCacheRebalanceConfiguration
@@ -1390,6 +1399,9 @@ org.apache.ignite.internal.visor.cache.VisorCacheRebalanceTask
 org.apache.ignite.internal.visor.cache.VisorCacheRebalanceTask$VisorCachesRebalanceJob
 org.apache.ignite.internal.visor.cache.VisorCacheResetMetricsTask
 org.apache.ignite.internal.visor.cache.VisorCacheResetMetricsTask$VisorCacheResetMetricsJob
+org.apache.ignite.internal.visor.cache.VisorCacheStartTask
+org.apache.ignite.internal.visor.cache.VisorCacheStartTask$VisorCacheStartArg
+org.apache.ignite.internal.visor.cache.VisorCacheStartTask$VisorCacheStartJob
 org.apache.ignite.internal.visor.cache.VisorCacheStopTask
 org.apache.ignite.internal.visor.cache.VisorCacheStopTask$VisorCacheStopJob
 org.apache.ignite.internal.visor.cache.VisorCacheStoreConfiguration

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/resources/ignite.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/main/resources/ignite.properties b/modules/core/src/main/resources/ignite.properties
index 549bde3..78e294f 100644
--- a/modules/core/src/main/resources/ignite.properties
+++ b/modules/core/src/main/resources/ignite.properties
@@ -15,7 +15,7 @@
 # limitations under the License.
 #
 
-ignite.version=1.0.0
+ignite.version=1.2.0-SNAPSHOT
 ignite.build=0
 ignite.revision=DEV
 ignite.rel.date=01011970

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/GridUpdateNotifierSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridUpdateNotifierSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridUpdateNotifierSelfTest.java
index 2b119ec..abc9109 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridUpdateNotifierSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridUpdateNotifierSelfTest.java
@@ -18,10 +18,13 @@
 package org.apache.ignite.internal;
 
 import org.apache.ignite.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.*;
 import org.apache.ignite.testframework.junits.common.*;
-import org.h2.constant.*;
 import org.jetbrains.annotations.*;
 
+import java.util.*;
 import java.util.concurrent.*;
 
 /**
@@ -29,6 +32,8 @@ import java.util.concurrent.*;
  */
 @GridCommonTest(group = "Kernal Self")
 public class GridUpdateNotifierSelfTest extends GridCommonAbstractTest {
+    private String updateStatusParams;
+
     /** {@inheritDoc} */
     @Override protected long getTestTimeout() {
         return 30 * 1000;
@@ -39,6 +44,12 @@ public class GridUpdateNotifierSelfTest extends GridCommonAbstractTest {
         super.beforeTestsStarted();
 
         System.setProperty(IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER, "true");
+
+        Properties props = U.field(IgniteProperties.class, "PROPS");
+
+        updateStatusParams = props.getProperty("ignite.update.status.params");
+
+        props.setProperty("ignite.update.status.params", "ver=" + IgniteProperties.get("ignite.version"));
     }
 
     /** {@inheritDoc} */
@@ -46,14 +57,20 @@ public class GridUpdateNotifierSelfTest extends GridCommonAbstractTest {
         super.afterTestsStopped();
 
         System.setProperty(IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER, "false");
+
+        Properties props = U.field(IgniteProperties.class, "PROPS");
+
+        props.setProperty("ignite.update.status.params", updateStatusParams);
     }
 
     /**
      * @throws Exception If failed.
      */
     public void testNotifier() throws Exception {
-        GridUpdateNotifier ntf = new GridUpdateNotifier(null, IgniteProperties.get("ignite.version"),
-            TEST_GATEWAY, false);
+        String nodeVer = IgniteProperties.get("ignite.version");
+
+        GridUpdateNotifier ntf = new GridUpdateNotifier(null, nodeVer,
+            TEST_GATEWAY, Collections.<PluginProvider>emptyList(), false);
 
         ntf.checkForNewVersion(new SelfExecutor(), log);
 
@@ -63,6 +80,13 @@ public class GridUpdateNotifierSelfTest extends GridCommonAbstractTest {
 
         assertNotNull("Ignite latest version has not been detected.", ver);
 
+        byte nodeMaintenance = IgniteProductVersion.fromString(nodeVer).maintenance();
+
+        byte lastMaintenance = IgniteProductVersion.fromString(ver).maintenance();
+
+        assertTrue("Wrong latest version.", (nodeMaintenance == 0 && lastMaintenance == 0) ||
+            (nodeMaintenance > 0 && lastMaintenance > 0));
+
         ntf.reportStatus(log);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetFromJobTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetFromJobTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetFromJobTest.java
new file mode 100644
index 0000000..5859bec
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetFromJobTest.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;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.testframework.*;
+
+import java.util.concurrent.atomic.*;
+
+/**
+ * Job tries to get cache during topology change.
+ */
+public class CacheGetFromJobTest extends GridCacheAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTopologyChange() throws Exception {
+        final AtomicReference<Exception> err = new AtomicReference<>();
+
+        final AtomicInteger id = new AtomicInteger(1);
+
+        IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new CA() {
+            @Override public void apply() {
+                info("Run topology change.");
+
+                try {
+                    for (int i = 0; i < 5; i++) {
+                        info("Topology change: " + i);
+
+                        startGrid(id.getAndIncrement());
+                    }
+                }
+                catch (Exception e) {
+                    err.set(e);
+
+                    log.error("Unexpected exception in topology-change-thread: " + e, e);
+                }
+            }
+        }, 3, "topology-change-thread");
+
+        int cntr = 0;
+
+        while (!fut.isDone()) {
+            grid(0).compute().broadcast(new TestJob());
+
+            cntr++;
+        }
+
+        log.info("Job execution count: " + cntr);
+
+        Exception err0 = err.get();
+
+        if (err0 != null)
+            throw err0;
+    }
+
+    /**
+     * Test job.
+     */
+    private static class TestJob implements IgniteCallable<Object> {
+        /** Ignite. */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** */
+        public TestJob() {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object call() throws Exception {
+            IgniteCache cache = ignite.cache(null);
+
+            assertNotNull(cache);
+
+            assertEquals(0, cache.localSize());
+
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheOffheapMapEntrySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheOffheapMapEntrySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheOffheapMapEntrySelfTest.java
new file mode 100644
index 0000000..8c7d33d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheOffheapMapEntrySelfTest.java
@@ -0,0 +1,168 @@
+/*
+ * 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.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
+import org.apache.ignite.internal.processors.cache.local.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ * Cache map entry self test.
+ */
+public class CacheOffheapMapEntrySelfTest extends GridCacheAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        startGrids(1);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        // No-op.
+    }
+
+    /**
+     * @param gridName Grid name.
+     * @param memoryMode Memory mode.
+     * @param atomicityMode Atomicity mode.
+     * @param cacheMode Cache mode.
+     * @param cacheName Cache name.
+     * @return Cache configuration.
+     * @throws Exception If failed.
+     */
+    private CacheConfiguration cacheConfiguration(String gridName,
+        CacheMemoryMode memoryMode,
+        CacheAtomicityMode atomicityMode,
+        CacheMode cacheMode,
+        String cacheName)
+        throws Exception
+    {
+        CacheConfiguration cfg = super.cacheConfiguration(gridName);
+
+        cfg.setCacheMode(cacheMode);
+        cfg.setAtomicityMode(atomicityMode);
+        cfg.setMemoryMode(memoryMode);
+        cfg.setName(cacheName);
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCacheMapEntry() throws Exception {
+        checkCacheMapEntry(ONHEAP_TIERED, ATOMIC, LOCAL, GridLocalCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_TIERED, ATOMIC, LOCAL, GridLocalCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_VALUES, ATOMIC, LOCAL, GridLocalCacheEntry.class);
+
+        checkCacheMapEntry(ONHEAP_TIERED, TRANSACTIONAL, LOCAL, GridLocalCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_TIERED, TRANSACTIONAL, LOCAL, GridLocalCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_VALUES, TRANSACTIONAL, LOCAL, GridLocalCacheEntry.class);
+
+        checkCacheMapEntry(ONHEAP_TIERED, ATOMIC, PARTITIONED, GridNearCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_TIERED, ATOMIC, PARTITIONED, GridNearOffHeapCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_VALUES, ATOMIC, PARTITIONED, GridNearOffHeapCacheEntry.class);
+
+        checkCacheMapEntry(ONHEAP_TIERED, TRANSACTIONAL, PARTITIONED, GridNearCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_TIERED, TRANSACTIONAL, PARTITIONED, GridNearOffHeapCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_VALUES, TRANSACTIONAL, PARTITIONED, GridNearOffHeapCacheEntry.class);
+
+        checkCacheMapEntry(ONHEAP_TIERED, ATOMIC, REPLICATED, GridDhtAtomicCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_TIERED, ATOMIC, REPLICATED, GridDhtAtomicOffHeapCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_VALUES, ATOMIC, REPLICATED, GridDhtAtomicOffHeapCacheEntry.class);
+
+        checkCacheMapEntry(ONHEAP_TIERED, TRANSACTIONAL, REPLICATED, GridDhtColocatedCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_TIERED, TRANSACTIONAL, REPLICATED, GridDhtColocatedOffHeapCacheEntry.class);
+
+        checkCacheMapEntry(OFFHEAP_VALUES, TRANSACTIONAL, REPLICATED, GridDhtColocatedOffHeapCacheEntry.class);
+    }
+
+    /**
+     * @param memoryMode Cache memory mode.
+     * @param atomicityMode Cache atomicity mode.
+     * @param cacheMode Cache mode.
+     * @param entryCls Class of cache map entry.
+     * @throws Exception If failed.
+     */
+    private void checkCacheMapEntry(CacheMemoryMode memoryMode,
+        CacheAtomicityMode atomicityMode,
+        CacheMode cacheMode,
+        Class<?> entryCls)
+        throws Exception
+    {
+        log.info("Test cache [memMode=" + memoryMode +
+            ", atomicityMode=" + atomicityMode +
+            ", cacheMode=" + cacheMode + ']');
+
+        CacheConfiguration cfg = cacheConfiguration(grid(0).name(),
+            memoryMode,
+            atomicityMode,
+            cacheMode,
+            "Cache");
+
+        try (IgniteCache jcache = grid(0).getOrCreateCache(cfg)) {
+            GridCacheAdapter<Integer, String> cache = ((IgniteKernal)grid(0)).internalCache(jcache.getName());
+
+            Integer key = primaryKey(grid(0).cache(null));
+
+            cache.put(key, "val");
+
+            GridCacheEntryEx entry = cache.entryEx(key);
+
+            entry.unswap(true);
+
+            assertNotNull(entry);
+
+            assertEquals(entry.getClass(), entryCls);
+        }
+    }
+}


[16/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java
new file mode 100644
index 0000000..4f74303
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java
@@ -0,0 +1,768 @@
+/*
+ * 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.distributed.near;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.cluster.*;
+import org.apache.ignite.internal.processors.affinity.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.distributed.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.internal.processors.cache.transactions.*;
+import org.apache.ignite.internal.transactions.*;
+import org.apache.ignite.internal.util.*;
+import org.apache.ignite.internal.util.future.*;
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.internal.util.tostring.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.transactions.*;
+import org.jetbrains.annotations.*;
+import org.jsr166.*;
+
+import java.util.*;
+import java.util.concurrent.atomic.*;
+
+import static org.apache.ignite.internal.processors.cache.GridCacheOperation.*;
+import static org.apache.ignite.transactions.TransactionState.*;
+
+/**
+ *
+ */
+public class GridNearOptimisticTxPrepareFuture extends GridNearTxPrepareFutureAdapter
+    implements GridCacheMvccFuture<IgniteInternalTx> {
+    /** */
+    private Collection<IgniteTxKey> lockKeys = new GridConcurrentHashSet<>();
+
+    /**
+     * @param cctx Context.
+     * @param tx Transaction.
+     */
+    public GridNearOptimisticTxPrepareFuture(GridCacheSharedContext cctx, GridNearTxLocal tx) {
+        super(cctx, tx);
+
+        assert tx.optimistic() : tx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onOwnerChanged(GridCacheEntryEx entry, GridCacheMvccCandidate owner) {
+        if (log.isDebugEnabled())
+            log.debug("Transaction future received owner changed callback: " + entry);
+
+        if ((entry.context().isNear() || entry.context().isLocal()) && owner != null && tx.hasWriteKey(entry.txKey())) {
+            lockKeys.remove(entry.txKey());
+
+            // This will check for locks.
+            onDone();
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<? extends ClusterNode> nodes() {
+        return F.viewReadOnly(futures(), new IgniteClosure<IgniteInternalFuture<?>, ClusterNode>() {
+            @Nullable @Override public ClusterNode apply(IgniteInternalFuture<?> f) {
+                if (isMini(f))
+                    return ((MiniFuture)f).node();
+
+                return cctx.discovery().localNode();
+            }
+        });
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onNodeLeft(UUID nodeId) {
+        boolean found = false;
+
+        for (IgniteInternalFuture<?> fut : futures()) {
+            if (isMini(fut)) {
+                MiniFuture f = (MiniFuture) fut;
+
+                if (f.node().id().equals(nodeId)) {
+                    f.onResult(new ClusterTopologyCheckedException("Remote node left grid: " + nodeId));
+
+                    found = true;
+                }
+            }
+        }
+
+        return found;
+    }
+
+    /**
+     * @param nodeId Failed node ID.
+     * @param mappings Remaining mappings.
+     * @param e Error.
+     */
+    void onError(@Nullable UUID nodeId, @Nullable Iterable<GridDistributedTxMapping> mappings, Throwable e) {
+        if (err.compareAndSet(null, e)) {
+            boolean marked = tx.setRollbackOnly();
+
+            if (e instanceof IgniteTxOptimisticCheckedException) {
+                assert nodeId != null : "Missing node ID for optimistic failure exception: " + e;
+
+                tx.removeKeysMapping(nodeId, mappings);
+            }
+
+            if (e instanceof IgniteTxRollbackCheckedException) {
+                if (marked) {
+                    try {
+                        tx.rollback();
+                    }
+                    catch (IgniteCheckedException ex) {
+                        U.error(log, "Failed to automatically rollback transaction: " + tx, ex);
+                    }
+                }
+            }
+
+            onComplete();
+        }
+    }
+
+    /**
+     * @return {@code True} if all locks are owned.
+     */
+    private boolean checkLocks() {
+        boolean locked = lockKeys.isEmpty();
+
+        if (locked) {
+            if (log.isDebugEnabled())
+                log.debug("All locks are acquired for near prepare future: " + this);
+        }
+        else {
+            if (log.isDebugEnabled())
+                log.debug("Still waiting for locks [fut=" + this + ", keys=" + lockKeys + ']');
+        }
+
+        return locked;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onResult(UUID nodeId, GridNearTxPrepareResponse res) {
+        if (!isDone()) {
+            for (IgniteInternalFuture<IgniteInternalTx> fut : pending()) {
+                if (isMini(fut)) {
+                    MiniFuture f = (MiniFuture)fut;
+
+                    if (f.futureId().equals(res.miniId())) {
+                        assert f.node().id().equals(nodeId);
+
+                        f.onResult(nodeId, res);
+                    }
+                }
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onDone(IgniteInternalTx t, Throwable err) {
+        // If locks were not acquired yet, delay completion.
+        if (isDone() || (err == null && !checkLocks()))
+            return false;
+
+        this.err.compareAndSet(null, err);
+
+        if (err == null)
+            tx.state(PREPARED);
+
+        if (super.onDone(tx, err)) {
+            // Don't forget to clean up.
+            cctx.mvcc().removeFuture(this);
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * @param f Future.
+     * @return {@code True} if mini-future.
+     */
+    private boolean isMini(IgniteInternalFuture<?> f) {
+        return f.getClass().equals(MiniFuture.class);
+    }
+
+    /**
+     * Completeness callback.
+     */
+    private void onComplete() {
+        if (super.onDone(tx, err.get()))
+            // Don't forget to clean up.
+            cctx.mvcc().removeFuture(this);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void prepare() {
+        // Obtain the topology version to use.
+        AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(Thread.currentThread().getId());
+
+        if (topVer != null) {
+            tx.topologyVersion(topVer);
+
+            prepare0();
+
+            return;
+        }
+
+        prepareOnTopology();
+    }
+
+    /**
+     *
+     */
+    private void prepareOnTopology() {
+        GridDhtTopologyFuture topFut = topologyReadLock();
+
+        try {
+            if (topFut == null) {
+                assert isDone();
+
+                return;
+            }
+
+            if (topFut.isDone()) {
+                StringBuilder invalidCaches = new StringBuilder();
+
+                boolean cacheInvalid = false;
+
+                for (GridCacheContext ctx : cctx.cacheContexts()) {
+                    if (tx.activeCacheIds().contains(ctx.cacheId()) && !topFut.isCacheTopologyValid(ctx)) {
+                        if (cacheInvalid)
+                            invalidCaches.append(", ");
+
+                        invalidCaches.append(U.maskName(ctx.name()));
+
+                        cacheInvalid = true;
+                    }
+                }
+
+                if (cacheInvalid) {
+                    onDone(new IgniteCheckedException("Failed to perform cache operation (cache topology is not valid): " +
+                        invalidCaches.toString()));
+
+                    return;
+                }
+
+                tx.topologyVersion(topFut.topologyVersion());
+
+                prepare0();
+            }
+            else {
+                topFut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
+                    @Override public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
+                        cctx.kernalContext().closure().runLocalSafe(new GridPlainRunnable() {
+                            @Override public void run() {
+                                prepareOnTopology();
+                            }
+                        });
+                    }
+                });
+            }
+        }
+        finally {
+            topologyReadUnlock();
+        }
+    }
+
+    /**
+     * Acquires topology read lock.
+     *
+     * @return Topology ready future.
+     */
+    private GridDhtTopologyFuture topologyReadLock() {
+        if (tx.activeCacheIds().isEmpty())
+            return cctx.exchange().lastTopologyFuture();
+
+        GridCacheContext<?, ?> nonLocCtx = null;
+
+        for (int cacheId : tx.activeCacheIds()) {
+            GridCacheContext<?, ?> cacheCtx = cctx.cacheContext(cacheId);
+
+            if (!cacheCtx.isLocal()) {
+                nonLocCtx = cacheCtx;
+
+                break;
+            }
+        }
+
+        if (nonLocCtx == null)
+            return cctx.exchange().lastTopologyFuture();
+
+        nonLocCtx.topology().readLock();
+
+        if (nonLocCtx.topology().stopping()) {
+            onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " +
+                nonLocCtx.name()));
+
+            return null;
+        }
+
+        return nonLocCtx.topology().topologyVersionFuture();
+    }
+
+    /**
+     * Releases topology read lock.
+     */
+    private void topologyReadUnlock() {
+        if (!tx.activeCacheIds().isEmpty()) {
+            GridCacheContext<?, ?> nonLocCtx = null;
+
+            for (int cacheId : tx.activeCacheIds()) {
+                GridCacheContext<?, ?> cacheCtx = cctx.cacheContext(cacheId);
+
+                if (!cacheCtx.isLocal()) {
+                    nonLocCtx = cacheCtx;
+
+                    break;
+                }
+            }
+
+            if (nonLocCtx != null)
+                nonLocCtx.topology().readUnlock();
+        }
+    }
+
+    /**
+     * Initializes future.
+     */
+    private void prepare0() {
+        try {
+            if (!tx.state(PREPARING)) {
+                if (tx.setRollbackOnly()) {
+                    if (tx.timedOut())
+                        onError(null, null, new IgniteTxTimeoutCheckedException("Transaction timed out and " +
+                            "was rolled back: " + this));
+                    else
+                        onError(null, null, new IgniteCheckedException("Invalid transaction state for prepare " +
+                            "[state=" + tx.state() + ", tx=" + this + ']'));
+                }
+                else
+                    onError(null, null, new IgniteTxRollbackCheckedException("Invalid transaction state for " +
+                        "prepare [state=" + tx.state() + ", tx=" + this + ']'));
+
+                return;
+            }
+
+            // Make sure to add future before calling prepare.
+            cctx.mvcc().addFuture(this);
+
+            prepare(
+                tx.optimistic() && tx.serializable() ? tx.readEntries() : Collections.<IgniteTxEntry>emptyList(),
+                tx.writeEntries());
+
+            markInitialized();
+        }
+        catch (TransactionTimeoutException | TransactionOptimisticException e) {
+            onError(cctx.localNodeId(), null, e);
+        }
+        catch (IgniteCheckedException e) {
+            onDone(e);
+        }
+    }
+
+    /**
+     * @param reads Read entries.
+     * @param writes Write entries.
+     * @throws IgniteCheckedException If transaction is group-lock and some key was mapped to to the local node.
+     */
+    private void prepare(
+        Iterable<IgniteTxEntry> reads,
+        Iterable<IgniteTxEntry> writes
+    ) throws IgniteCheckedException {
+        AffinityTopologyVersion topVer = tx.topologyVersion();
+
+        assert topVer.topologyVersion() > 0;
+
+        txMapping = new GridDhtTxMapping();
+
+        ConcurrentLinkedDeque8<GridDistributedTxMapping> mappings = new ConcurrentLinkedDeque8<>();
+
+        if (!F.isEmpty(reads) || !F.isEmpty(writes)) {
+            for (int cacheId : tx.activeCacheIds()) {
+                GridCacheContext<?, ?> cacheCtx = cctx.cacheContext(cacheId);
+
+                if (CU.affinityNodes(cacheCtx, topVer).isEmpty()) {
+                    onDone(new ClusterTopologyCheckedException("Failed to map keys for cache (all " +
+                        "partition nodes left the grid): " + cacheCtx.name()));
+
+                    return;
+                }
+            }
+        }
+
+        // Assign keys to primary nodes.
+        GridDistributedTxMapping cur = null;
+
+        for (IgniteTxEntry read : reads) {
+            GridDistributedTxMapping updated = map(read, topVer, cur, false);
+
+            if (cur != updated) {
+                mappings.offer(updated);
+
+                if (updated.node().isLocal()) {
+                    if (read.context().isNear())
+                        tx.nearLocallyMapped(true);
+                    else if (read.context().isColocated())
+                        tx.colocatedLocallyMapped(true);
+                }
+
+                cur = updated;
+            }
+        }
+
+        for (IgniteTxEntry write : writes) {
+            GridDistributedTxMapping updated = map(write, topVer, cur, true);
+
+            if (cur != updated) {
+                mappings.offer(updated);
+
+                if (updated.node().isLocal()) {
+                    if (write.context().isNear())
+                        tx.nearLocallyMapped(true);
+                    else if (write.context().isColocated())
+                        tx.colocatedLocallyMapped(true);
+                }
+
+                cur = updated;
+            }
+        }
+
+        if (isDone()) {
+            if (log.isDebugEnabled())
+                log.debug("Abandoning (re)map because future is done: " + this);
+
+            return;
+        }
+
+        tx.addEntryMapping(mappings);
+
+        cctx.mvcc().recheckPendingLocks();
+
+        txMapping.initLast(mappings);
+
+        tx.transactionNodes(txMapping.transactionNodes());
+
+        checkOnePhase();
+
+        proceedPrepare(mappings);
+    }
+
+    /**
+     * Continues prepare after previous mapping successfully finished.
+     *
+     * @param mappings Queue of mappings.
+     */
+    private void proceedPrepare(final ConcurrentLinkedDeque8<GridDistributedTxMapping> mappings) {
+        if (isDone())
+            return;
+
+        final GridDistributedTxMapping m = mappings.poll();
+
+        if (m == null)
+            return;
+
+        assert !m.empty();
+
+        final ClusterNode n = m.node();
+
+        GridNearTxPrepareRequest req = new GridNearTxPrepareRequest(
+            futId,
+            tx.topologyVersion(),
+            tx,
+            tx.optimistic() && tx.serializable() ? m.reads() : null,
+            m.writes(),
+            m.near(),
+            txMapping.transactionNodes(),
+            m.last(),
+            m.lastBackups(),
+            tx.onePhaseCommit(),
+            tx.needReturnValue() && tx.implicit(),
+            tx.implicitSingle(),
+            m.explicitLock(),
+            tx.subjectId(),
+            tx.taskNameHash());
+
+        for (IgniteTxEntry txEntry : m.writes()) {
+            if (txEntry.op() == TRANSFORM)
+                req.addDhtVersion(txEntry.txKey(), null);
+        }
+
+        // Must lock near entries separately.
+        if (m.near()) {
+            try {
+                tx.optimisticLockEntries(req.writes());
+
+                tx.userPrepare();
+            }
+            catch (IgniteCheckedException e) {
+                onError(null, null, e);
+            }
+        }
+
+        final MiniFuture fut = new MiniFuture(m, mappings);
+
+        req.miniId(fut.futureId());
+
+        add(fut); // Append new future.
+
+        // If this is the primary node for the keys.
+        if (n.isLocal()) {
+            // At this point, if any new node joined, then it is
+            // waiting for this transaction to complete, so
+            // partition reassignments are not possible here.
+            IgniteInternalFuture<GridNearTxPrepareResponse> prepFut = cctx.tm().txHandler().prepareTx(n.id(), tx, req);
+
+            prepFut.listen(new CI1<IgniteInternalFuture<GridNearTxPrepareResponse>>() {
+                @Override public void apply(IgniteInternalFuture<GridNearTxPrepareResponse> prepFut) {
+                    try {
+                        fut.onResult(n.id(), prepFut.get());
+                    }
+                    catch (IgniteCheckedException e) {
+                        fut.onResult(e);
+                    }
+                }
+            });
+        }
+        else {
+            try {
+                cctx.io().send(n, req, tx.ioPolicy());
+            }
+            catch (IgniteCheckedException e) {
+                // Fail the whole thing.
+                fut.onResult(e);
+            }
+        }
+    }
+
+    /**
+     * @param entry Transaction entry.
+     * @param topVer Topology version.
+     * @param cur Current mapping.
+     * @throws IgniteCheckedException If transaction is group-lock and local node is not primary for key.
+     * @return Mapping.
+     */
+    private GridDistributedTxMapping map(
+        IgniteTxEntry entry,
+        AffinityTopologyVersion topVer,
+        GridDistributedTxMapping cur,
+        boolean waitLock
+    ) throws IgniteCheckedException {
+        GridCacheContext cacheCtx = entry.context();
+
+        List<ClusterNode> nodes = cacheCtx.affinity().nodes(entry.key(), topVer);
+
+        txMapping.addMapping(nodes);
+
+        ClusterNode primary = F.first(nodes);
+
+        assert primary != null;
+
+        if (log.isDebugEnabled()) {
+            log.debug("Mapped key to primary node [key=" + entry.key() +
+                ", part=" + cacheCtx.affinity().partition(entry.key()) +
+                ", primary=" + U.toShortString(primary) + ", topVer=" + topVer + ']');
+        }
+
+        // Must re-initialize cached entry while holding topology lock.
+        if (cacheCtx.isNear())
+            entry.cached(cacheCtx.nearTx().entryExx(entry.key(), topVer));
+        else if (!cacheCtx.isLocal())
+            entry.cached(cacheCtx.colocated().entryExx(entry.key(), topVer, true));
+        else
+            entry.cached(cacheCtx.local().entryEx(entry.key(), topVer));
+
+        if (cacheCtx.isNear() || cacheCtx.isLocal()) {
+            if (waitLock && entry.explicitVersion() == null)
+                lockKeys.add(entry.txKey());
+        }
+
+        if (cur == null || !cur.node().id().equals(primary.id()) || cur.near() != cacheCtx.isNear()) {
+            cur = new GridDistributedTxMapping(primary);
+
+            // Initialize near flag right away.
+            cur.near(cacheCtx.isNear());
+        }
+
+        cur.add(entry);
+
+        if (entry.explicitVersion() != null) {
+            tx.markExplicit(primary.id());
+
+            cur.markExplicitLock();
+        }
+
+        entry.nodeId(primary.id());
+
+        if (cacheCtx.isNear()) {
+            while (true) {
+                try {
+                    GridNearCacheEntry cached = (GridNearCacheEntry)entry.cached();
+
+                    cached.dhtNodeId(tx.xidVersion(), primary.id());
+
+                    break;
+                }
+                catch (GridCacheEntryRemovedException ignore) {
+                    entry.cached(cacheCtx.near().entryEx(entry.key()));
+                }
+            }
+        }
+
+        return cur;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        Collection<String> futs = F.viewReadOnly(futures(), new C1<IgniteInternalFuture<?>, String>() {
+            @Override public String apply(IgniteInternalFuture<?> f) {
+                return "[node=" + ((MiniFuture)f).node().id() +
+                    ", loc=" + ((MiniFuture)f).node().isLocal() +
+                    ", done=" + f.isDone() + "]";
+            }
+        });
+
+        return S.toString(GridNearOptimisticTxPrepareFuture.class, this,
+            "futs", futs,
+            "super", super.toString());
+    }
+
+    /**
+     *
+     */
+    private class MiniFuture extends GridFutureAdapter<IgniteInternalTx> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** */
+        private final IgniteUuid futId = IgniteUuid.randomUuid();
+
+        /** Keys. */
+        @GridToStringInclude
+        private GridDistributedTxMapping m;
+
+        /** Flag to signal some result being processed. */
+        private AtomicBoolean rcvRes = new AtomicBoolean(false);
+
+        /** Mappings to proceed prepare. */
+        private ConcurrentLinkedDeque8<GridDistributedTxMapping> mappings;
+
+        /**
+         * @param m Mapping.
+         * @param mappings Queue of mappings to proceed with.
+         */
+        MiniFuture(
+            GridDistributedTxMapping m,
+            ConcurrentLinkedDeque8<GridDistributedTxMapping> mappings
+        ) {
+            this.m = m;
+            this.mappings = mappings;
+        }
+
+        /**
+         * @return Future ID.
+         */
+        IgniteUuid futureId() {
+            return futId;
+        }
+
+        /**
+         * @return Node ID.
+         */
+        public ClusterNode node() {
+            return m.node();
+        }
+
+        /**
+         * @return Keys.
+         */
+        public GridDistributedTxMapping mapping() {
+            return m;
+        }
+
+        /**
+         * @param e Error.
+         */
+        void onResult(Throwable e) {
+            if (rcvRes.compareAndSet(false, true)) {
+                if (log.isDebugEnabled())
+                    log.debug("Failed to get future result [fut=" + this + ", err=" + e + ']');
+
+                // Fail.
+                onDone(e);
+            }
+            else
+                U.warn(log, "Received error after another result has been processed [fut=" +
+                    GridNearOptimisticTxPrepareFuture.this + ", mini=" + this + ']', e);
+        }
+
+        /**
+         * @param e Node failure.
+         */
+        void onResult(ClusterTopologyCheckedException e) {
+            if (isDone())
+                return;
+
+            if (rcvRes.compareAndSet(false, true)) {
+                if (log.isDebugEnabled())
+                    log.debug("Remote node left grid while sending or waiting for reply (will not retry): " + this);
+
+                // Fail the whole future (make sure not to remap on different primary node
+                // to prevent multiple lock coordinators).
+                onError(null, null, e);
+            }
+        }
+
+        /**
+         * @param nodeId Failed node ID.
+         * @param res Result callback.
+         */
+        void onResult(UUID nodeId, GridNearTxPrepareResponse res) {
+            if (isDone())
+                return;
+
+            if (rcvRes.compareAndSet(false, true)) {
+                if (res.error() != null) {
+                    // Fail the whole compound future.
+                    onError(nodeId, mappings, res.error());
+                }
+                else {
+                    onPrepareResponse(m, res);
+
+                    // Proceed prepare before finishing mini future.
+                    if (mappings != null)
+                        proceedPrepare(mappings);
+
+                    // Finish this mini future.
+                    onDone(tx);
+                }
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(MiniFuture.class, this, "done", isDone(), "cancelled", isCancelled(), "err", error());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java
new file mode 100644
index 0000000..bce62c1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java
@@ -0,0 +1,347 @@
+/*
+ * 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.distributed.near;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.cluster.*;
+import org.apache.ignite.internal.processors.affinity.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.distributed.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.internal.processors.cache.transactions.*;
+import org.apache.ignite.internal.transactions.*;
+import org.apache.ignite.internal.util.future.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+
+import static org.apache.ignite.internal.processors.cache.GridCacheOperation.*;
+import static org.apache.ignite.transactions.TransactionState.*;
+
+/**
+ *
+ */
+public class GridNearPessimisticTxPrepareFuture extends GridNearTxPrepareFutureAdapter {
+    /**
+     * @param cctx Context.
+     * @param tx Transaction.
+     */
+    public GridNearPessimisticTxPrepareFuture(GridCacheSharedContext cctx, GridNearTxLocal tx) {
+        super(cctx, tx);
+
+        assert tx.pessimistic() : tx;
+
+        // Should wait for all mini futures completion before finishing tx.
+        ignoreChildFailures(IgniteCheckedException.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<? extends ClusterNode> nodes() {
+        return F.viewReadOnly(futures(), new IgniteClosure<IgniteInternalFuture<?>, ClusterNode>() {
+            @Nullable @Override public ClusterNode apply(IgniteInternalFuture<?> f) {
+                return ((MiniFuture)f).node();
+            }
+        });
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onNodeLeft(UUID nodeId) {
+        boolean found = false;
+
+        for (IgniteInternalFuture<?> fut : futures()) {
+            MiniFuture f = (MiniFuture)fut;
+
+            if (f.node().id().equals(nodeId)) {
+                f.onNodeLeft(new ClusterTopologyCheckedException("Remote node left grid: " + nodeId));
+
+                found = true;
+            }
+        }
+
+        return found;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onResult(UUID nodeId, GridNearTxPrepareResponse res) {
+        if (!isDone()) {
+            for (IgniteInternalFuture<IgniteInternalTx> fut : pending()) {
+                MiniFuture f = (MiniFuture)fut;
+
+                if (f.futureId().equals(res.miniId())) {
+                    assert f.node().id().equals(nodeId);
+
+                    if (log.isDebugEnabled())
+                        log.debug("Remote node left grid while sending or waiting for reply (will not retry): " + f);
+
+                    f.onResult(res);
+                }
+            }
+        }
+    }
+    /** {@inheritDoc} */
+    @Override public void prepare() {
+        if (!tx.state(PREPARING)) {
+            if (tx.setRollbackOnly()) {
+                if (tx.timedOut())
+                    onDone(new IgniteTxTimeoutCheckedException("Transaction timed out and was rolled back: " + tx));
+                else
+                    onDone(new IgniteCheckedException("Invalid transaction state for prepare " +
+                        "[state=" + tx.state() + ", tx=" + this + ']'));
+            }
+            else
+                onDone(new IgniteTxRollbackCheckedException("Invalid transaction state for prepare " +
+                    "[state=" + tx.state() + ", tx=" + this + ']'));
+
+            return;
+        }
+
+        try {
+            tx.userPrepare();
+
+            cctx.mvcc().addFuture(this);
+
+            preparePessimistic();
+        }
+        catch (IgniteCheckedException e) {
+            onDone(e);
+        }
+    }
+
+    /**
+     *
+     */
+    private void preparePessimistic() {
+        Map<IgniteBiTuple<ClusterNode, Boolean>, GridDistributedTxMapping> mappings = new HashMap<>();
+
+        AffinityTopologyVersion topVer = tx.topologyVersion();
+
+        txMapping = new GridDhtTxMapping();
+
+        for (IgniteTxEntry txEntry : tx.allEntries()) {
+            GridCacheContext cacheCtx = txEntry.context();
+
+            List<ClusterNode> nodes = cacheCtx.affinity().nodes(txEntry.key(), topVer);
+
+            ClusterNode primary = F.first(nodes);
+
+            boolean near = cacheCtx.isNear();
+
+            IgniteBiTuple<ClusterNode, Boolean> key = F.t(primary, near);
+
+            GridDistributedTxMapping nodeMapping = mappings.get(key);
+
+            if (nodeMapping == null) {
+                nodeMapping = new GridDistributedTxMapping(primary);
+
+                nodeMapping.near(cacheCtx.isNear());
+
+                mappings.put(key, nodeMapping);
+            }
+
+            txEntry.nodeId(primary.id());
+
+            nodeMapping.add(txEntry);
+
+            txMapping.addMapping(nodes);
+        }
+
+        tx.transactionNodes(txMapping.transactionNodes());
+
+        checkOnePhase();
+
+        for (final GridDistributedTxMapping m : mappings.values()) {
+            final ClusterNode node = m.node();
+
+            GridNearTxPrepareRequest req = new GridNearTxPrepareRequest(
+                futId,
+                tx.topologyVersion(),
+                tx,
+                m.reads(),
+                m.writes(),
+                m.near(),
+                txMapping.transactionNodes(),
+                true,
+                txMapping.transactionNodes().get(node.id()),
+                tx.onePhaseCommit(),
+                tx.needReturnValue() && tx.implicit(),
+                tx.implicitSingle(),
+                m.explicitLock(),
+                tx.subjectId(),
+                tx.taskNameHash());
+
+            for (IgniteTxEntry txEntry : m.writes()) {
+                if (txEntry.op() == TRANSFORM)
+                    req.addDhtVersion(txEntry.txKey(), null);
+            }
+
+            final MiniFuture fut = new MiniFuture(m);
+
+            req.miniId(fut.futureId());
+
+            add(fut);
+
+            if (node.isLocal()) {
+                IgniteInternalFuture<GridNearTxPrepareResponse> prepFut = cctx.tm().txHandler().prepareTx(node.id(),
+                    tx,
+                    req);
+
+                prepFut.listen(new CI1<IgniteInternalFuture<GridNearTxPrepareResponse>>() {
+                    @Override public void apply(IgniteInternalFuture<GridNearTxPrepareResponse> prepFut) {
+                        try {
+                            fut.onResult(prepFut.get());
+                        }
+                        catch (IgniteCheckedException e) {
+                            fut.onError(e);
+                        }
+                    }
+                });
+            }
+            else {
+                try {
+                    cctx.io().send(node, req, tx.ioPolicy());
+                }
+                catch (ClusterTopologyCheckedException e) {
+                    fut.onNodeLeft(e);
+                }
+                catch (IgniteCheckedException e) {
+                    fut.onError(e);
+                }
+            }
+        }
+
+        markInitialized();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onDone(@Nullable IgniteInternalTx res, @Nullable Throwable err) {
+        if (err != null)
+            this.err.compareAndSet(null, err);
+
+        err = this.err.get();
+
+        if (err == null)
+            tx.state(PREPARED);
+
+        if (super.onDone(tx, err)) {
+            cctx.mvcc().removeFuture(this);
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        Collection<String> futs = F.viewReadOnly(futures(), new C1<IgniteInternalFuture<?>, String>() {
+            @Override public String apply(IgniteInternalFuture<?> f) {
+                return "[node=" + ((MiniFuture)f).node().id() +
+                    ", loc=" + ((MiniFuture)f).node().isLocal() +
+                    ", done=" + f.isDone() + "]";
+            }
+        });
+
+        return S.toString(GridNearPessimisticTxPrepareFuture.class, this,
+            "futs", futs,
+            "super", super.toString());
+    }
+
+    /**
+     *
+     */
+    private class MiniFuture extends GridFutureAdapter<IgniteInternalTx> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** */
+        private final IgniteUuid futId = IgniteUuid.randomUuid();
+
+        /** */
+        private GridDistributedTxMapping m;
+
+        /**
+         * @param m Mapping.
+         */
+        MiniFuture(GridDistributedTxMapping m) {
+            this.m = m;
+        }
+
+        /**
+         * @return Future ID.
+         */
+        IgniteUuid futureId() {
+            return futId;
+        }
+
+        /**
+         * @return Node ID.
+         */
+        public ClusterNode node() {
+            return m.node();
+        }
+
+        /**
+         * @param res Response.
+         */
+        void onResult(GridNearTxPrepareResponse res) {
+            if (res.error() != null)
+                onError(res.error());
+            else {
+                onPrepareResponse(m, res);
+
+                onDone(tx);
+            }
+        }
+
+        /**
+         * @param e Error.
+         */
+        void onNodeLeft(ClusterTopologyCheckedException e) {
+            onError(e);
+        }
+
+        /**
+         * @param e Error.
+         */
+        void onError(Throwable e) {
+            if (isDone()) {
+                U.warn(log, "Received error when future is done [fut=" + this + ", err=" + e + ", tx=" + tx + ']');
+
+                return;
+            }
+
+            if (log.isDebugEnabled())
+                log.debug("Error on tx prepare [fut=" + this + ", err=" + e + ", tx=" + tx +  ']');
+
+            if (err.compareAndSet(null, e))
+                tx.setRollbackOnly();
+
+            onDone(e);
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(MiniFuture.class, this, "done", isDone(), "cancelled", isCancelled(), "err", error());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
index 581c7e0..df7a65f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
@@ -301,14 +301,10 @@ public class GridNearTransactionalCache<K, V> extends GridNearCacheAdapter<K, V>
                                         req.isInvalidate(),
                                         req.timeout(),
                                         req.txSize(),
-                                        req.groupLockKey(),
                                         req.subjectId(),
                                         req.taskNameHash()
                                     );
 
-                                    if (req.groupLock())
-                                        tx.groupLockKey(txKey);
-
                                     tx = ctx.tm().onCreated(null, tx);
 
                                     if (tx == null || !ctx.tm().onStarted(tx))

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishRequest.java
index 7b0b811..b44f821 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFinishRequest.java
@@ -97,7 +97,7 @@ public class GridNearTxFinishRequest extends GridDistributedTxFinishRequest {
         @Nullable UUID subjId,
         int taskNameHash) {
         super(xidVer, futId, null, threadId, commit, invalidate, sys, plc, syncCommit, syncRollback, baseVer,
-            committedVers, rolledbackVers, txSize, null);
+            committedVers, rolledbackVers, txSize);
 
         this.explicitLock = explicitLock;
         this.storeEnabled = storeEnabled;
@@ -170,37 +170,37 @@ public class GridNearTxFinishRequest extends GridDistributedTxFinishRequest {
         }
 
         switch (writer.state()) {
-            case 20:
+            case 19:
                 if (!writer.writeBoolean("explicitLock", explicitLock))
                     return false;
 
                 writer.incrementState();
 
-            case 21:
+            case 20:
                 if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
                 writer.incrementState();
 
-            case 22:
+            case 21:
                 if (!writer.writeBoolean("storeEnabled", storeEnabled))
                     return false;
 
                 writer.incrementState();
 
-            case 23:
+            case 22:
                 if (!writer.writeUuid("subjId", subjId))
                     return false;
 
                 writer.incrementState();
 
-            case 24:
+            case 23:
                 if (!writer.writeInt("taskNameHash", taskNameHash))
                     return false;
 
                 writer.incrementState();
 
-            case 25:
+            case 24:
                 if (!writer.writeMessage("topVer", topVer))
                     return false;
 
@@ -222,7 +222,7 @@ public class GridNearTxFinishRequest extends GridDistributedTxFinishRequest {
             return false;
 
         switch (reader.state()) {
-            case 20:
+            case 19:
                 explicitLock = reader.readBoolean("explicitLock");
 
                 if (!reader.isLastRead())
@@ -230,7 +230,7 @@ public class GridNearTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 21:
+            case 20:
                 miniId = reader.readIgniteUuid("miniId");
 
                 if (!reader.isLastRead())
@@ -238,7 +238,7 @@ public class GridNearTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 22:
+            case 21:
                 storeEnabled = reader.readBoolean("storeEnabled");
 
                 if (!reader.isLastRead())
@@ -246,7 +246,7 @@ public class GridNearTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 23:
+            case 22:
                 subjId = reader.readUuid("subjId");
 
                 if (!reader.isLastRead())
@@ -254,7 +254,7 @@ public class GridNearTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 24:
+            case 23:
                 taskNameHash = reader.readInt("taskNameHash");
 
                 if (!reader.isLastRead())
@@ -262,7 +262,7 @@ public class GridNearTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 25:
+            case 24:
                 topVer = reader.readMessage("topVer");
 
                 if (!reader.isLastRead())
@@ -282,7 +282,7 @@ public class GridNearTxFinishRequest extends GridDistributedTxFinishRequest {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 26;
+        return 25;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 c665354..c38965d 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
@@ -61,8 +61,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
 
     /** Future. */
     @GridToStringExclude
-    private final AtomicReference<IgniteInternalFuture<IgniteInternalTx>> prepFut =
-        new AtomicReference<>();
+    private final AtomicReference<IgniteInternalFuture<?>> prepFut = new AtomicReference<>();
 
     /** */
     @GridToStringExclude
@@ -103,8 +102,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
      * @param timeout Timeout.
      * @param storeEnabled Store enabled flag.
      * @param txSize Transaction size.
-     * @param grpLockKey Group lock key if this is a group lock transaction.
-     * @param partLock {@code True} if this is a group-lock transaction and the whole partition should be locked.
      * @param subjId Subject ID.
      * @param taskNameHash Task name hash code.
      */
@@ -119,8 +116,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
         long timeout,
         boolean storeEnabled,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
-        boolean partLock,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
@@ -138,8 +133,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
             false,
             storeEnabled,
             txSize,
-            grpLockKey,
-            partLock,
             subjId,
             taskNameHash);
 
@@ -273,9 +266,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
 
     /** {@inheritDoc} */
     @Override public Collection<IgniteTxEntry> optimisticLockEntries() {
-        if (groupLock())
-            return super.optimisticLockEntries();
-
         return optimisticLockEntries;
     }
 
@@ -388,15 +378,16 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
     /**
      * @param nodeId Node ID.
      * @param dhtVer DHT version.
+     * @param writeVer Write version.
      */
-    void addDhtVersion(UUID nodeId, GridCacheVersion dhtVer) {
+    void addDhtVersion(UUID nodeId, GridCacheVersion dhtVer, GridCacheVersion writeVer) {
         // This step is very important as near and DHT versions grow separately.
         cctx.versions().onReceived(nodeId, dhtVer);
 
         GridDistributedTxMapping m = mappings.get(nodeId);
 
         if (m != null)
-            m.dhtVersion(dhtVer);
+            m.dhtVersion(dhtVer, writeVer);
     }
 
     /**
@@ -417,13 +408,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
         }
     }
 
-    /** {@inheritDoc} */
-    @Override protected void addGroupTxMapping(Collection<IgniteTxKey> keys) {
-        super.addGroupTxMapping(keys);
-
-        addKeyMapping(cctx.localNode(), keys);
-    }
-
     /**
      * Adds key mapping to dht mapping.
      *
@@ -563,9 +547,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
         Collection<GridCacheVersion> committedVers,
         Collection<GridCacheVersion> rolledbackVers)
     {
-        Collection<IgniteTxEntry> entries = groupLock() ?
-            Collections.singletonList(groupLockEntry()) :
-            F.concat(false, mapping.reads(), mapping.writes());
+        Collection<IgniteTxEntry> entries = F.concat(false, mapping.reads(), mapping.writes());
 
         for (IgniteTxEntry txEntry : entries) {
             while (true) {
@@ -682,12 +664,13 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<IgniteInternalTx> prepareAsync() {
-        GridNearTxPrepareFuture fut = (GridNearTxPrepareFuture)prepFut.get();
+    @Override public IgniteInternalFuture<?> prepareAsync() {
+        GridNearTxPrepareFutureAdapter fut = (GridNearTxPrepareFutureAdapter)prepFut.get();
 
         if (fut == null) {
             // Future must be created before any exception can be thrown.
-            fut = new GridNearTxPrepareFuture<>(cctx, this);
+            fut = optimistic() ? new GridNearOptimisticTxPrepareFuture(cctx, this) :
+                new GridNearPessimisticTxPrepareFuture(cctx, this);
 
             if (!prepFut.compareAndSet(null, fut))
                 return prepFut.get();
@@ -698,41 +681,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
 
         mapExplicitLocks();
 
-        // For pessimistic mode we don't distribute prepare request and do not lock topology version
-        // as it was fixed on first lock.
-        if (pessimistic()) {
-            if (!state(PREPARING)) {
-                if (setRollbackOnly()) {
-                    if (timedOut())
-                        fut.onError(new IgniteTxTimeoutCheckedException("Transaction timed out and was " +
-                            "rolled back: " + this));
-                    else
-                        fut.onError(new IgniteCheckedException("Invalid transaction state for prepare [state=" +
-                            state() + ", tx=" + this + ']'));
-                }
-                else
-                    fut.onError(new IgniteTxRollbackCheckedException("Invalid transaction state for prepare " +
-                        "[state=" + state() + ", tx=" + this + ']'));
-
-                return fut;
-            }
-
-            try {
-                userPrepare();
-
-                // Make sure to add future before calling prepare.
-                cctx.mvcc().addFuture(fut);
-
-                fut.prepare();
-            }
-            catch (IgniteCheckedException e) {
-                fut.onError(e);
-            }
-        }
-        else {
-            // In optimistic mode we must wait for topology map update.
-            fut.prepare();
-        }
+        fut.prepare();
 
         return fut;
     }
@@ -752,10 +701,10 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
 
         cctx.mvcc().addFuture(fut);
 
-        IgniteInternalFuture<IgniteInternalTx> prepareFut = prepFut.get();
+        IgniteInternalFuture<?> prepareFut = prepFut.get();
 
-        prepareFut.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
-            @Override public void apply(IgniteInternalFuture<IgniteInternalTx> f) {
+        prepareFut.listen(new CI1<IgniteInternalFuture<?>>() {
+            @Override public void apply(IgniteInternalFuture<?> f) {
                 GridNearTxFinishFuture fut0 = commitFut.get();
 
                 try {
@@ -799,7 +748,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
 
         cctx.mvcc().addFuture(fut);
 
-        IgniteInternalFuture<IgniteInternalTx> prepFut = this.prepFut.get();
+        IgniteInternalFuture<?> prepFut = this.prepFut.get();
 
         if (prepFut == null || prepFut.isDone()) {
             try {
@@ -823,8 +772,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
             }
         }
         else {
-            prepFut.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
-                @Override public void apply(IgniteInternalFuture<IgniteInternalTx> f) {
+            prepFut.listen(new CI1<IgniteInternalFuture<?>>() {
+                @Override public void apply(IgniteInternalFuture<?> f) {
                     try {
                         // Check for errors in prepare future.
                         f.get();
@@ -867,12 +816,11 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
      * @return Future that will be completed when locks are acquired.
      */
     @SuppressWarnings("TypeMayBeWeakened")
-    public IgniteInternalFuture<IgniteInternalTx> prepareAsyncLocal(
+    public IgniteInternalFuture<GridNearTxPrepareResponse> prepareAsyncLocal(
         @Nullable Collection<IgniteTxEntry> reads,
         @Nullable Collection<IgniteTxEntry> writes,
         Map<UUID, Collection<UUID>> txNodes, boolean last,
-        Collection<UUID> lastBackups,
-        IgniteInClosure<GridNearTxPrepareResponse> completeCb
+        Collection<UUID> lastBackups
     ) {
         if (state() != PREPARING) {
             if (timedOut())
@@ -887,15 +835,14 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
 
         init();
 
-        GridDhtTxPrepareFuture fut = new GridDhtTxPrepareFuture<>(
+        GridDhtTxPrepareFuture fut = new GridDhtTxPrepareFuture(
             cctx,
             this,
             IgniteUuid.randomUuid(),
             Collections.<IgniteTxKey, GridCacheVersion>emptyMap(),
             last,
             needReturnValue() && implicit(),
-            lastBackups,
-            completeCb);
+            lastBackups);
 
         try {
             // At this point all the entries passed in must be enlisted in transaction because this is an
@@ -934,7 +881,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
             }
         }
 
-        return fut;
+        return chainOnePhasePrepare(fut);
     }
 
     /**
@@ -950,7 +897,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
         if (pessimistic())
             prepareAsync();
 
-        IgniteInternalFuture<IgniteInternalTx> prep = prepFut.get();
+        IgniteInternalFuture<?> prep = prepFut.get();
 
         // Do not create finish future if there are no remote nodes.
         if (F.isEmpty(dhtMap) && F.isEmpty(nearMap)) {
@@ -986,8 +933,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
             }
         }
         else
-            prep.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
-                @Override public void apply(IgniteInternalFuture<IgniteInternalTx> f) {
+            prep.listen(new CI1<IgniteInternalFuture<?>>() {
+                @Override public void apply(IgniteInternalFuture<?> f) {
                     try {
                         f.get(); // Check for errors of a parent future.
 
@@ -1023,7 +970,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
 
         cctx.mvcc().addFuture(fut);
 
-        IgniteInternalFuture<IgniteInternalTx> prep = prepFut.get();
+        IgniteInternalFuture<?> prep = prepFut.get();
 
         if (prep == null || prep.isDone()) {
             try {
@@ -1039,8 +986,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
             fut.finish();
         }
         else
-            prep.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
-                @Override public void apply(IgniteInternalFuture<IgniteInternalTx> f) {
+            prep.listen(new CI1<IgniteInternalFuture<?>>() {
+                @Override public void apply(IgniteInternalFuture<?> f) {
                     try {
                         f.get(); // Check for errors of a parent future.
                     }
@@ -1233,7 +1180,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nullable @Override public IgniteInternalFuture<IgniteInternalTx> currentPrepareFuture() {
+    @Nullable @Override public IgniteInternalFuture<?> currentPrepareFuture() {
         return prepFut.get();
     }
 


[05/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Bytes.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Bytes.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Bytes.java
new file mode 100644
index 0000000..31eaaca
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Bytes.java
@@ -0,0 +1,113 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Bytes.
+ */
+public class GridH2Bytes extends GridH2ValueMessage {
+    /** */
+    private byte[] b;
+
+    /**
+     *
+     */
+    public GridH2Bytes() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Bytes(Value val) {
+        assert val.getType() == Value.BYTES : val.getType();
+
+        b = val.getBytesNoCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueBytes.getNoCopy(b);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByteArray("b", b))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                b = reader.readByteArray("b");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -16;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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
new file mode 100644
index 0000000..065393d
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2CacheObject.java
@@ -0,0 +1,148 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.query.h2.opt.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Cache object message.
+ */
+public class GridH2CacheObject extends GridH2ValueMessage {
+    /** */
+    private int cacheId;
+
+    /** */
+    private CacheObject obj;
+
+    /**
+     *
+     */
+    public GridH2CacheObject() {
+        // No-op.
+    }
+
+    /**
+     * @param v Value.
+     * @throws IgniteCheckedException If failed.
+     */
+    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());
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) throws IgniteCheckedException {
+        GridCacheContext<?,?> cctx = null;
+
+        if (ctx != null) {
+            cctx = ctx.cache().context().cacheContext(cacheId);
+
+            obj.finishUnmarshal(cctx.cacheObjectContext(), cctx.deploy().globalLoader());
+        }
+
+        return new GridH2ValueCacheObject(cctx, obj);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        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())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeInt("cacheId", cacheId))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeMessage("obj", obj))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -22;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Date.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Date.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Date.java
new file mode 100644
index 0000000..e5a8372
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Date.java
@@ -0,0 +1,115 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Date.
+ */
+public class GridH2Date extends GridH2ValueMessage {
+    /** */
+    private long date;
+
+    /**
+     *
+     */
+    public GridH2Date() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Date(Value val) {
+        assert val.getType() == Value.DATE : val.getType();
+
+        ValueDate d = (ValueDate)val;
+
+        date = d.getDateValue();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueDate.fromDateValue(date);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeLong("date", date))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                date = reader.readLong("date");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -14;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Decimal.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Decimal.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Decimal.java
new file mode 100644
index 0000000..70700a8
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Decimal.java
@@ -0,0 +1,134 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.math.*;
+import java.nio.*;
+
+/**
+ * H2 Decimal.
+ */
+public class GridH2Decimal extends GridH2ValueMessage {
+    /** */
+    private int scale;
+
+    /** */
+    private byte[] b;
+
+    /**
+     *
+     */
+    public GridH2Decimal() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Decimal(Value val) {
+        assert val.getType() == Value.DECIMAL : val.getType();
+
+        BigDecimal x = val.getBigDecimal();
+
+        scale = x.scale();
+        b = x.unscaledValue().toByteArray();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueDecimal.get(new BigDecimal(new BigInteger(b), scale));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByteArray("b", b))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeInt("scale", scale))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                b = reader.readByteArray("b");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                scale = reader.readInt("scale");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -10;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Double.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Double.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Double.java
new file mode 100644
index 0000000..bdb796f
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Double.java
@@ -0,0 +1,113 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Double.
+ */
+public class GridH2Double extends GridH2ValueMessage {
+    /** */
+    private double x;
+
+    /**
+     *
+     */
+    public GridH2Double() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Double(Value val) {
+        assert val.getType() == Value.DOUBLE : val.getType();
+
+        x = val.getDouble();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueDouble.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeDouble("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readDouble("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -11;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Float.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Float.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Float.java
new file mode 100644
index 0000000..676b79a
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Float.java
@@ -0,0 +1,113 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Float.
+ */
+public class GridH2Float extends GridH2ValueMessage {
+    /** */
+    private float x;
+
+    /**
+     *
+     */
+    public GridH2Float() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Float(Value val) {
+        assert val.getType() == Value.FLOAT : val.getType();
+
+        x = val.getFloat();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueFloat.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeFloat("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readFloat("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -12;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Geometry.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Geometry.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Geometry.java
new file mode 100644
index 0000000..c825a47
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Geometry.java
@@ -0,0 +1,134 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.lang.reflect.*;
+import java.nio.*;
+
+/**
+ * H2 Geometry.
+ */
+public class GridH2Geometry extends GridH2ValueMessage {
+    /** */
+    private static final Method GEOMETRY_FROM_BYTES;
+
+    /**
+     * Initialize field.
+     */
+    static {
+        try {
+            GEOMETRY_FROM_BYTES = Class.forName("org.h2.value.ValueGeometry").getMethod("get", byte[].class);
+        }
+        catch (NoSuchMethodException | ClassNotFoundException e) {
+            throw new IllegalStateException("Check H2 version in classpath.");
+        }
+    }
+
+    /** */
+    private byte[] b;
+
+    /**
+     *
+     */
+    public GridH2Geometry() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Geometry(Value val) {
+        assert val.getType() == Value.GEOMETRY : val.getType();
+
+        b = val.getBytesNoCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        try {
+            return (Value)GEOMETRY_FROM_BYTES.invoke(null, new Object[]{b});
+        }
+        catch (IllegalAccessException | InvocationTargetException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByteArray("b", b))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                b = reader.readByteArray("b");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -21;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Integer.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Integer.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Integer.java
new file mode 100644
index 0000000..fef4956
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Integer.java
@@ -0,0 +1,113 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Integer.
+ */
+public class GridH2Integer extends GridH2ValueMessage {
+    /** */
+    private int x;
+
+    /**
+     *
+     */
+    public GridH2Integer() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Integer(Value val) {
+        assert val.getType() == Value.INT : val.getType();
+
+        x = val.getInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueInt.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeInt("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readInt("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -8;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2JavaObject.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2JavaObject.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2JavaObject.java
new file mode 100644
index 0000000..17f6c9c
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2JavaObject.java
@@ -0,0 +1,113 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Java Object.
+ */
+public class GridH2JavaObject extends GridH2ValueMessage {
+    /** */
+    private byte[] b;
+
+    /**
+     *
+     */
+    public GridH2JavaObject() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2JavaObject(Value val) {
+        assert val.getType() == Value.JAVA_OBJECT : val.getType();
+
+        b = val.getBytesNoCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueJavaObject.getNoCopy(null, b, null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByteArray("b", b))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                b = reader.readByteArray("b");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -19;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Long.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Long.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Long.java
new file mode 100644
index 0000000..c798922
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Long.java
@@ -0,0 +1,113 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Long.
+ */
+public class GridH2Long extends GridH2ValueMessage {
+    /** */
+    private long x;
+
+    /**
+     *
+     */
+    public GridH2Long() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Long(Value val) {
+        assert val.getType() == Value.LONG : val.getType();
+
+        x = val.getLong();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueLong.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeLong("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readLong("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -9;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Null.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Null.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Null.java
new file mode 100644
index 0000000..a2e20d3
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Null.java
@@ -0,0 +1,78 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * Message for {@link Value#NULL}.
+ */
+public class GridH2Null extends GridH2ValueMessage {
+    /** */
+    public static GridH2Null INSTANCE = new GridH2Null();
+
+    /**
+     * Disallow new instance creation.
+     */
+    private GridH2Null() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueNull.INSTANCE;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        return reader.beforeMessageRead() && super.readFrom(buf, reader);
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -4;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Short.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Short.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Short.java
new file mode 100644
index 0000000..9064559
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Short.java
@@ -0,0 +1,113 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Short.
+ */
+public class GridH2Short extends GridH2ValueMessage {
+    /** */
+    private short x;
+
+    /**
+     *
+     */
+    public GridH2Short() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Short(Value val) {
+        assert val.getType() == Value.SHORT : val.getType();
+
+        x = val.getShort();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueShort.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeShort("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readShort("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -7;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2String.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2String.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2String.java
new file mode 100644
index 0000000..3ea3248
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2String.java
@@ -0,0 +1,115 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 String.
+ */
+public class GridH2String extends GridH2ValueMessage {
+    /** */
+    private String x;
+
+    /**
+     *
+     */
+    public GridH2String() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2String(Value val) {
+        assert val.getType() == Value.STRING ||
+            val.getType() == Value.STRING_FIXED ||
+            val.getType() == Value.STRING_IGNORECASE : val.getType();
+
+        x = val.getString();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueString.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeString("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readString("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -17;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Time.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Time.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Time.java
new file mode 100644
index 0000000..ec34248
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Time.java
@@ -0,0 +1,116 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Time.
+ */
+public class GridH2Time extends GridH2ValueMessage {
+    /** */
+    private long nanos;
+
+    /**
+     *
+     */
+    public GridH2Time() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Time(Value val) {
+        assert val.getType() == Value.TIME : val.getType();
+
+        ValueTime t = (ValueTime)val;
+
+        nanos = t.getNanos();
+    }
+
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueTime.fromNanos(nanos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeLong("nanos", nanos))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                nanos = reader.readLong("nanos");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -13;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Timestamp.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Timestamp.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Timestamp.java
new file mode 100644
index 0000000..973782b
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Timestamp.java
@@ -0,0 +1,133 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Timestamp.
+ */
+public class GridH2Timestamp extends GridH2ValueMessage {
+    /** */
+    private long date;
+
+    /** */
+    private long nanos;
+
+    /**
+     *
+     */
+    public GridH2Timestamp() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Timestamp(Value val) {
+        assert val.getType() == Value.TIMESTAMP : val.getType();
+
+        ValueTimestamp t = (ValueTimestamp)val;
+
+        date = t.getDateValue();
+        nanos = t.getNanos();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueTimestamp.fromDateValueAndNanos(date, nanos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeLong("date", date))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeLong("nanos", nanos))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                date = reader.readLong("date");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                nanos = reader.readLong("nanos");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -15;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Uuid.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Uuid.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Uuid.java
new file mode 100644
index 0000000..f23b827
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Uuid.java
@@ -0,0 +1,133 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Uuid.
+ */
+public class GridH2Uuid extends GridH2ValueMessage {
+    /** */
+    private long high;
+
+    /** */
+    private long low;
+
+    /**
+     *
+     */
+    public GridH2Uuid() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Uuid(Value val) {
+        assert val.getType() == Value.UUID : val.getType();
+
+        ValueUuid uuid = (ValueUuid)val;
+
+        high = uuid.getHigh();
+        low = uuid.getLow();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueUuid.get(high, low);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeLong("high", high))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeLong("low", low))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                high = reader.readLong("high");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                low = reader.readLong("low");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -20;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessage.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessage.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessage.java
new file mode 100644
index 0000000..577de40
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessage.java
@@ -0,0 +1,49 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * Abstract message wrapper for H2 values.
+ */
+public abstract class GridH2ValueMessage implements Message {
+    /**
+     * Gets H2 value.
+     *
+     * @param ctx Kernal context.
+     * @return Value.
+     * @throws IgniteCheckedException If failed.
+     */
+    public abstract Value value(GridKernalContext ctx) throws IgniteCheckedException;
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java
new file mode 100644
index 0000000..d193910
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java
@@ -0,0 +1,201 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.query.h2.opt.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+
+/**
+ * H2 Value message factory.
+ */
+public class GridH2ValueMessageFactory implements MessageFactory {
+    /** {@inheritDoc} */
+    @Nullable @Override public Message create(byte type) {
+        switch (type) {
+            case -4:
+                return GridH2Null.INSTANCE;
+
+            case -5:
+                return new GridH2Boolean();
+
+            case -6:
+                return new GridH2Byte();
+
+            case -7:
+                return new GridH2Short();
+
+            case -8:
+                return new GridH2Integer();
+
+            case -9:
+                return new GridH2Long();
+
+            case -10:
+                return new GridH2Decimal();
+
+            case -11:
+                return new GridH2Double();
+
+            case -12:
+                return new GridH2Float();
+
+            case -13:
+                return new GridH2Time();
+
+            case -14:
+                return new GridH2Date();
+
+            case -15:
+                return new GridH2Timestamp();
+
+            case -16:
+                return new GridH2Bytes();
+
+            case -17:
+                return new GridH2String();
+
+            case -18:
+                return new GridH2Array();
+
+            case -19:
+                return new GridH2JavaObject();
+
+            case -20:
+                return new GridH2Uuid();
+
+            case -21:
+                return new GridH2Geometry();
+
+            case -22:
+                return new GridH2CacheObject();
+        }
+
+        return null;
+    }
+
+    /**
+     * @param src Source values.
+     * @param dst Destination collection.
+     * @return Destination collection.
+     * @throws IgniteCheckedException If failed.
+     */
+    public static Collection<Message> toMessages(Collection<Value[]> src, Collection<Message> dst)
+        throws IgniteCheckedException {
+        for (Value[] row : src) {
+            for (Value val : row)
+                dst.add(toMessage(val));
+        }
+
+        return dst;
+    }
+
+    /**
+     * @param src Source iterator.
+     * @param dst Array to fill with values.
+     * @param ctx Kernal context.
+     * @return Filled array.
+     * @throws IgniteCheckedException If failed.
+     */
+    public static Value[] fillArray(Iterator<Message> src, Value[] dst, GridKernalContext ctx)
+        throws IgniteCheckedException {
+        for (int i = 0; i < dst.length; i++) {
+            Message msg = src.next();
+
+            dst[i] = ((GridH2ValueMessage)msg).value(ctx);
+        }
+
+        return dst;
+    }
+
+    /**
+     * @param v Value.
+     * @return Message.
+     * @throws IgniteCheckedException If failed.
+     */
+    public static Message toMessage(Value v) throws IgniteCheckedException {
+        switch (v.getType()) {
+            case Value.NULL:
+                return GridH2Null.INSTANCE;
+
+            case Value.BOOLEAN:
+                return new GridH2Boolean(v);
+
+            case Value.BYTE:
+                return new GridH2Byte(v);
+
+            case Value.SHORT:
+                return new GridH2Short(v);
+
+            case Value.INT:
+                return new GridH2Integer(v);
+
+            case Value.LONG:
+                return new GridH2Long(v);
+
+            case Value.DECIMAL:
+                return new GridH2Decimal(v);
+
+            case Value.DOUBLE:
+                return new GridH2Double(v);
+
+            case Value.FLOAT:
+                return new GridH2Float(v);
+
+            case Value.DATE:
+                return new GridH2Date(v);
+
+            case Value.TIME:
+                return new GridH2Time(v);
+
+            case Value.TIMESTAMP:
+                return new GridH2Timestamp(v);
+
+            case Value.BYTES:
+                return new GridH2Bytes(v);
+
+            case Value.STRING:
+            case Value.STRING_FIXED:
+            case Value.STRING_IGNORECASE:
+                return new GridH2String(v);
+
+            case Value.ARRAY:
+                return new GridH2Array(v);
+
+            case Value.JAVA_OBJECT:
+                if (v instanceof GridH2ValueCacheObject)
+                    return new GridH2CacheObject((GridH2ValueCacheObject)v);
+
+                return new GridH2JavaObject(v);
+
+            case Value.UUID:
+                return new GridH2Uuid(v);
+
+            case Value.GEOMETRY:
+                return new GridH2Geometry(v);
+
+            default:
+                throw new IllegalStateException("Unsupported H2 type: " + v.getType());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapAndSwapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapAndSwapSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapAndSwapSelfTest.java
index 226f0fc..0c55551 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapAndSwapSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapAndSwapSelfTest.java
@@ -30,6 +30,7 @@ import org.apache.ignite.lang.*;
 import org.apache.ignite.spi.discovery.tcp.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.spi.swapspace.*;
 import org.apache.ignite.spi.swapspace.file.*;
 import org.apache.ignite.testframework.junits.common.*;
 
@@ -79,6 +80,14 @@ public class GridCacheOffHeapAndSwapSelfTest extends GridCommonAbstractTest {
     /** */
     private final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
 
+    /**
+     * Creates a SwapSpaceSpi.
+     * @return the Spi
+     */
+    protected SwapSpaceSpi spi() {
+        return new FileSwapSpaceSpi();
+    }
+
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
@@ -91,7 +100,7 @@ public class GridCacheOffHeapAndSwapSelfTest extends GridCommonAbstractTest {
 
         cfg.setNetworkTimeout(2000);
 
-        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
+        cfg.setSwapSpaceSpi(spi());
 
         CacheConfiguration<?,?> cacheCfg = defaultCacheConfiguration();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapSelfTest.java
index 460a64c..2d6855e 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapSelfTest.java
@@ -29,6 +29,7 @@ import org.apache.ignite.marshaller.optimized.*;
 import org.apache.ignite.spi.discovery.tcp.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.spi.swapspace.*;
 import org.apache.ignite.spi.swapspace.file.*;
 import org.apache.ignite.testframework.junits.common.*;
 
@@ -65,6 +66,14 @@ public class GridCacheOffHeapSelfTest extends GridCommonAbstractTest {
     /** PeerClassLoadingLocalClassPathExclude enable. */
     private boolean excluded;
 
+    /**
+     * Creates a SwapSpaceSpi.
+     * @return the Spi
+     */
+    protected SwapSpaceSpi spi() {
+        return new FileSwapSpaceSpi();
+    }
+
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
@@ -77,7 +86,7 @@ public class GridCacheOffHeapSelfTest extends GridCommonAbstractTest {
 
         cfg.setNetworkTimeout(2000);
 
-        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
+        cfg.setSwapSpaceSpi(spi());
 
         CacheConfiguration<?,?> cacheCfg = defaultCacheConfiguration();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffheapIndexGetSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffheapIndexGetSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffheapIndexGetSelfTest.java
new file mode 100644
index 0000000..4e40040
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffheapIndexGetSelfTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.spi.swapspace.file.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+import static org.apache.ignite.configuration.DeploymentMode.*;
+
+/**
+ * Tests off heap storage when both offheaped and swapped entries exists.
+ */
+public class GridCacheOffheapIndexGetSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final long OFFHEAP_MEM = 10L * 1024L;
+
+    /** */
+    private final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(ipFinder);
+
+        cfg.setDiscoverySpi(disco);
+
+        cfg.setNetworkTimeout(2000);
+
+        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
+
+        CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+        cacheCfg.setSwapEnabled(true);
+        cacheCfg.setCacheMode(PARTITIONED);
+        cacheCfg.setBackups(1);
+        cacheCfg.setOffHeapMaxMemory(OFFHEAP_MEM);
+        cacheCfg.setEvictSynchronized(true);
+        cacheCfg.setEvictSynchronizedKeyBufferSize(1);
+        cacheCfg.setAtomicityMode(TRANSACTIONAL);
+        cacheCfg.setMemoryMode(OFFHEAP_TIERED);
+        cacheCfg.setEvictionPolicy(null);
+        cacheCfg.setOffHeapMaxMemory(OFFHEAP_MEM);
+        cacheCfg.setIndexedTypes(Long.class, Long.class);
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        cfg.setDeploymentMode(SHARED);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        grid(0).cache(null).clear();
+    }
+
+    /**
+     * Tests behavior on offheaped entries.
+     *
+     * @throws Exception If failed.
+     */
+    public void testGet() throws Exception {
+        fail("https://issues.apache.org/jira/browse/IGNITE-873");
+
+        IgniteCache<Long, Long> cache = grid(0).cache(null);
+
+        for (long i = 0; i < 100; i++)
+            cache.put(i, i);
+
+        for (long i = 0; i < 100; i++)
+            assertEquals((Long)i, cache.get(i));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
index c2722fa..3159589 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
@@ -27,6 +27,7 @@ import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.query.*;
 import org.apache.ignite.internal.processors.datastructures.*;
 import org.apache.ignite.internal.processors.query.*;
+import org.apache.ignite.internal.processors.query.h2.sql.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.marshaller.optimized.*;
 import org.apache.ignite.spi.discovery.*;
@@ -298,6 +299,26 @@ public abstract class IgniteCacheAbstractFieldsQuerySelfTest extends GridCommonA
         }
     }
 
+    /**
+     *
+     */
+    public void testExplain() {
+        List<List<?>> res = grid(0).cache(null).query(new SqlFieldsQuery(
+            "explain select p.age, p.name, o.name " +
+            "from Person p, Organization o where p.orgId = o.id")).getAll();
+
+        for (List<?> row : res)
+            X.println("____ : " + row);
+
+        if (cacheMode() == PARTITIONED) {
+            assertEquals(2, res.size());
+
+            assertTrue(((String)res.get(1).get(0)).contains(GridSqlQuerySplitter.TABLE_FUNC_NAME));
+        }
+        else
+            assertEquals(1, res.size());
+    }
+
     /** @throws Exception If failed. */
     public void testExecuteWithMetaData() throws Exception {
         QueryCursorImpl<List<?>> cursor = (QueryCursorImpl<List<?>>)grid(0).cache(null).query(new SqlFieldsQuery(

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java
new file mode 100644
index 0000000..b2095a8
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java
@@ -0,0 +1,56 @@
+/*
+ *  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.cache.query.*;
+import org.apache.ignite.configuration.*;
+
+import javax.cache.*;
+
+/**
+ * Checks behavior on exception while unmarshalling key.
+ */
+public class IgniteCacheP2pUnmarshallingQueryErrorTest extends IgniteCacheP2pUnmarshallingErrorTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.getCacheConfiguration()[0].setIndexedTypes(TestKey.class, String.class);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testResponseMessageOnUnmarshallingFailed() {
+        readCnt.set(Integer.MAX_VALUE);
+
+        jcache(0).put(new TestKey(String.valueOf(++key)), "");
+
+        //GridCacheQueryRequest unmarshalling failed test
+        readCnt.set(1);
+
+        try {
+            jcache(0).query(new SqlQuery<TestKey, String>(String.class, "field like '" + key + "'")).getAll();
+
+            assert false : "p2p marshalling failed, but error response was not sent";
+        }
+        catch (CacheException e) {
+            // No-op
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest.java
new file mode 100644
index 0000000..8b09d0f
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.cache.*;
+import org.apache.ignite.configuration.*;
+
+/**
+ * Test queries in off-heap tired mode.
+ */
+public class IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest extends IgniteCacheQueryMultiThreadedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration cacheConfiguration() {
+        CacheConfiguration ccfg = super.cacheConfiguration();
+
+        ccfg.setCacheMode(CacheMode.REPLICATED);
+        ccfg.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED);
+        ccfg.setOffHeapMaxMemory(0);
+
+        return ccfg;
+    }
+}


[22/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/IgniteServices.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteServices.java b/modules/core/src/main/java/org/apache/ignite/IgniteServices.java
index f800085..7d1ca7c 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteServices.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteServices.java
@@ -126,10 +126,7 @@ import java.util.*;
  * ...
  * GridServices svcs = grid.services();
  *
- * GridFuture&lt;?&gt; fut = svcs.deployClusterSingleton("mySingleton", new MyGridService());
- *
- * // Wait for deployment to complete.
- * fut.get();
+ * svcs.deployClusterSingleton("mySingleton", new MyGridService());
  * </pre>
  */
 public interface IgniteServices extends IgniteAsyncSupport {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 4931bdd..df6b2ee 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
@@ -175,7 +175,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
     /** Eviction key buffer size. */
     private int evictKeyBufSize = DFLT_EVICT_KEY_BUFFER_SIZE;
 
-    /** Synchronous eviction timeout. */
+    /** Synchronous eviction concurrency level. */
     private int evictSyncConcurrencyLvl = DFLT_EVICT_SYNCHRONIZED_CONCURRENCY_LEVEL;
 
     /** Synchronous eviction timeout. */
@@ -417,11 +417,14 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets cache name.
      *
      * @param name Cache name. May be <tt>null</tt>, but may not be empty string.
+     * @return {@code this} for chaining.
      */
-    public void setName(String name) {
+    public CacheConfiguration setName(String name) {
         A.ensure(name == null || !name.isEmpty(), "Name cannot be null or empty.");
 
         this.name = name;
+
+        return this;
     }
 
     /**
@@ -439,9 +442,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets cache eviction policy.
      *
      * @param evictPlc Cache expiration policy.
+     * @return {@code this} for chaining.
      */
-    public void setEvictionPolicy(@Nullable EvictionPolicy evictPlc) {
+    public CacheConfiguration setEvictionPolicy(@Nullable EvictionPolicy evictPlc) {
         this.evictPlc = evictPlc;
+
+        return this;
     }
 
     /**
@@ -453,9 +459,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
 
     /**
      * @param nearCfg Near cache configuration.
+     * @return {@code this} for chaining.
      */
-    public void setNearConfiguration(NearCacheConfiguration<K, V> nearCfg) {
+    public CacheConfiguration setNearConfiguration(NearCacheConfiguration<K, V> nearCfg) {
         this.nearCfg = nearCfg;
+
+        return this;
     }
 
     /**
@@ -472,9 +481,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets write synchronization mode.
      *
      * @param writeSync Write synchronization mode.
+     * @return {@code this} for chaining.
      */
-    public void setWriteSynchronizationMode(CacheWriteSynchronizationMode writeSync) {
+    public CacheConfiguration setWriteSynchronizationMode(CacheWriteSynchronizationMode writeSync) {
         this.writeSync = writeSync;
+
+        return this;
     }
 
     /**
@@ -490,9 +502,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets filter which determines on what nodes the cache should be started.
      *
      * @param nodeFilter Predicate specifying on which nodes the cache should be started.
+     * @return {@code this} for chaining.
      */
-    public void setNodeFilter(IgnitePredicate<ClusterNode> nodeFilter) {
+    public CacheConfiguration setNodeFilter(IgnitePredicate<ClusterNode> nodeFilter) {
         this.nodeFilter = nodeFilter;
+
+        return this;
     }
 
     /**
@@ -519,9 +534,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * (or the rest of the nodes for replicated cache).
      *
      * @param evictSync {@code true} if synchronized, {@code false} if not.
+     * @return {@code this} for chaining.
      */
-    public void setEvictSynchronized(boolean evictSync) {
+    public CacheConfiguration setEvictSynchronized(boolean evictSync) {
         this.evictSync = evictSync;
+
+        return this;
     }
 
     /**
@@ -539,9 +557,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets eviction key buffer size.
      *
      * @param evictKeyBufSize Eviction key buffer size.
+     * @return {@code this} for chaining.
      */
-    public void setEvictSynchronizedKeyBufferSize(int evictKeyBufSize) {
+    public CacheConfiguration setEvictSynchronizedKeyBufferSize(int evictKeyBufSize) {
         this.evictKeyBufSize = evictKeyBufSize;
+
+        return this;
     }
 
     /**
@@ -570,9 +591,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets concurrency level for synchronized evictions.
      *
      * @param evictSyncConcurrencyLvl Concurrency level for synchronized evictions.
+     * @return {@code this} for chaining.
      */
-    public void setEvictSynchronizedConcurrencyLevel(int evictSyncConcurrencyLvl) {
+    public CacheConfiguration setEvictSynchronizedConcurrencyLevel(int evictSyncConcurrencyLvl) {
         this.evictSyncConcurrencyLvl = evictSyncConcurrencyLvl;
+
+        return this;
     }
 
     /**
@@ -593,9 +617,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets timeout for synchronized evictions.
      *
      * @param evictSyncTimeout Timeout for synchronized evictions.
+     * @return {@code this} for chaining.
      */
-    public void setEvictSynchronizedTimeout(long evictSyncTimeout) {
+    public CacheConfiguration setEvictSynchronizedTimeout(long evictSyncTimeout) {
         this.evictSyncTimeout = evictSyncTimeout;
+
+        return this;
     }
 
     /**
@@ -622,9 +649,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets maximum eviction overflow ratio.
      *
      * @param evictMaxOverflowRatio Maximum eviction overflow ratio.
+     * @return {@code this} for chaining.
      */
-    public void setEvictMaxOverflowRatio(float evictMaxOverflowRatio) {
+    public CacheConfiguration setEvictMaxOverflowRatio(float evictMaxOverflowRatio) {
         this.evictMaxOverflowRatio = evictMaxOverflowRatio;
+
+        return this;
     }
 
     /**
@@ -648,9 +678,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets eviction filter.
      *
      * @param evictFilter Eviction filter.
+     * @return {@code this} for chaining.
      */
-    public void setEvictionFilter(EvictionFilter<K, V> evictFilter) {
+    public CacheConfiguration setEvictionFilter(EvictionFilter<K, V> evictFilter) {
         this.evictFilter = evictFilter;
+
+        return this;
     }
 
     /**
@@ -674,9 +707,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param eagerTtl {@code True} if Ignite should eagerly remove expired cache entries.
      * @see #isEagerTtl()
+     * @return {@code this} for chaining.
      */
-    public void setEagerTtl(boolean eagerTtl) {
+    public CacheConfiguration setEagerTtl(boolean eagerTtl) {
         this.eagerTtl = eagerTtl;
+
+        return this;
     }
 
     /**
@@ -693,9 +729,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Initial size for internal hash map.
      *
      * @param startSize Cache start size.
+     * @return {@code this} for chaining.
      */
-    public void setStartSize(int startSize) {
+    public CacheConfiguration setStartSize(int startSize) {
         this.startSize = startSize;
+
+        return this;
     }
 
     /**
@@ -734,9 +773,13 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * When not set, default value is {@link #DFLT_LOAD_PREV_VAL}.
      *
      * @param loadPrevVal Load previous value flag.
+     * @return {@code this} for chaining.
+     * @return {@code this} for chaining.
      */
-    public void setLoadPreviousValue(boolean loadPrevVal) {
+    public CacheConfiguration setLoadPreviousValue(boolean loadPrevVal) {
         this.loadPrevVal = loadPrevVal;
+
+        return this;
     }
 
     /**
@@ -755,8 +798,10 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * @param storeFactory Cache store factory.
      */
     @SuppressWarnings("unchecked")
-    public void setCacheStoreFactory(Factory<? extends CacheStore<? super K, ? super V>> storeFactory) {
+    public CacheConfiguration setCacheStoreFactory(Factory<? extends CacheStore<? super K, ? super V>> storeFactory) {
         this.storeFactory = storeFactory;
+
+        return this;
     }
 
     /**
@@ -772,9 +817,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets affinity for cache keys.
      *
      * @param aff Cache key affinity.
+     * @return {@code this} for chaining.
      */
-    public void setAffinity(AffinityFunction aff) {
+    public CacheConfiguration setAffinity(AffinityFunction aff) {
         this.aff = aff;
+
+        return this;
     }
 
     /**
@@ -792,9 +840,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets caching mode.
      *
      * @param cacheMode Caching mode.
+     * @return {@code this} for chaining.
      */
-    public void setCacheMode(CacheMode cacheMode) {
+    public CacheConfiguration setCacheMode(CacheMode cacheMode) {
         this.cacheMode = cacheMode;
+
+        return this;
     }
 
     /**
@@ -812,9 +863,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets cache atomicity mode.
      *
      * @param atomicityMode Cache atomicity mode.
+     * @return {@code this} for chaining.
      */
-    public void setAtomicityMode(CacheAtomicityMode atomicityMode) {
+    public CacheConfiguration setAtomicityMode(CacheAtomicityMode atomicityMode) {
         this.atomicityMode = atomicityMode;
+
+        return this;
     }
 
     /**
@@ -832,9 +886,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * cache (for other atomicity modes it will be ignored).
      *
      * @param atomicWriteOrderMode Cache write ordering mode.
+     * @return {@code this} for chaining.
      */
-    public void setAtomicWriteOrderMode(CacheAtomicWriteOrderMode atomicWriteOrderMode) {
+    public CacheConfiguration setAtomicWriteOrderMode(CacheAtomicWriteOrderMode atomicWriteOrderMode) {
         this.atomicWriteOrderMode = atomicWriteOrderMode;
+
+        return this;
     }
 
     /**
@@ -854,9 +911,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * If not set, default value is {@link #DFLT_BACKUPS}.
      *
      * @param backups Number of backup nodes for one partition.
+     * @return {@code this} for chaining.
      */
-    public void setBackups(int backups) {
+    public CacheConfiguration setBackups(int backups) {
         this.backups = backups;
+
+        return this;
     }
 
     /**
@@ -873,9 +933,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets default lock timeout in milliseconds. By default this value is defined by {@link #DFLT_LOCK_TIMEOUT}.
      *
      * @param dfltLockTimeout Default lock timeout.
+     * @return {@code this} for chaining.
      */
-    public void setDefaultLockTimeout(long dfltLockTimeout) {
+    public CacheConfiguration setDefaultLockTimeout(long dfltLockTimeout) {
         this.dfltLockTimeout = dfltLockTimeout;
+
+        return this;
     }
 
     /**
@@ -891,9 +954,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets invalidation flag for near cache entries in this transaction. Default is {@code false}.
      *
      * @param invalidate Flag to set this cache into invalidation-based mode. Default value is {@code false}.
+     * @return {@code this} for chaining.
      */
-    public void setInvalidate(boolean invalidate) {
+    public CacheConfiguration setInvalidate(boolean invalidate) {
         this.invalidate = invalidate;
+
+        return this;
     }
 
     /**
@@ -910,18 +976,24 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param tmLookupClsName Name of class implementing GridCacheTmLookup interface that is used to
      *      receive JTA transaction manager.
+     * @return {@code this} for chaining.
      */
-    public void setTransactionManagerLookupClassName(String tmLookupClsName) {
+    public CacheConfiguration setTransactionManagerLookupClassName(String tmLookupClsName) {
         this.tmLookupClsName = tmLookupClsName;
+
+        return this;
     }
 
     /**
      * Sets cache rebalance mode.
      *
      * @param rebalanceMode Rebalance mode.
+     * @return {@code this} for chaining.
      */
-    public void setRebalanceMode(CacheRebalanceMode rebalanceMode) {
+    public CacheConfiguration setRebalanceMode(CacheRebalanceMode rebalanceMode) {
         this.rebalanceMode = rebalanceMode;
+
+        return this;
     }
 
     /**
@@ -959,9 +1031,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param rebalanceOrder Cache rebalance order.
      * @see #getRebalanceOrder()
+     * @return {@code this} for chaining.
      */
-    public void setRebalanceOrder(int rebalanceOrder) {
+    public CacheConfiguration setRebalanceOrder(int rebalanceOrder) {
         this.rebalanceOrder = rebalanceOrder;
+
+        return this;
     }
 
     /**
@@ -980,9 +1055,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets rebalance batch size.
      *
      * @param rebalanceBatchSize Rebalance batch size.
+     * @return {@code this} for chaining.
      */
-    public void setRebalanceBatchSize(int rebalanceBatchSize) {
+    public CacheConfiguration setRebalanceBatchSize(int rebalanceBatchSize) {
         this.rebalanceBatchSize = rebalanceBatchSize;
+
+        return this;
     }
 
     /**
@@ -999,9 +1077,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Flag indicating whether swap storage is enabled or not.
      *
      * @param swapEnabled {@code True} if swap storage is enabled.
+     * @return {@code this} for chaining.
      */
-    public void setSwapEnabled(boolean swapEnabled) {
+    public CacheConfiguration setSwapEnabled(boolean swapEnabled) {
         this.swapEnabled = swapEnabled;
+
+        return this;
     }
 
     /**
@@ -1025,9 +1106,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param maxConcurrentAsyncOps Maximum number of concurrent asynchronous operations.
      * @see #getMaxConcurrentAsyncOperations()
+     * @return {@code this} for chaining.
      */
-    public void setMaxConcurrentAsyncOperations(int maxConcurrentAsyncOps) {
+    public CacheConfiguration setMaxConcurrentAsyncOperations(int maxConcurrentAsyncOps) {
         this.maxConcurrentAsyncOps = maxConcurrentAsyncOps;
+
+        return this;
     }
 
     /**
@@ -1045,9 +1129,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets flag indicating whether write-behind is enabled.
      *
      * @param writeBehindEnabled {@code true} if write-behind is enabled.
+     * @return {@code this} for chaining.
      */
-    public void setWriteBehindEnabled(boolean writeBehindEnabled) {
+    public CacheConfiguration setWriteBehindEnabled(boolean writeBehindEnabled) {
         this.writeBehindEnabled = writeBehindEnabled;
+
+        return this;
     }
 
     /**
@@ -1070,9 +1157,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param writeBehindFlushSize Write-behind cache flush size.
      * @see #getWriteBehindFlushSize()
+     * @return {@code this} for chaining.
      */
-    public void setWriteBehindFlushSize(int writeBehindFlushSize) {
+    public CacheConfiguration setWriteBehindFlushSize(int writeBehindFlushSize) {
         this.writeBehindFlushSize = writeBehindFlushSize;
+
+        return this;
     }
 
     /**
@@ -1096,9 +1186,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param writeBehindFlushFreq Write-behind flush frequency in milliseconds.
      * @see #getWriteBehindFlushFrequency()
+     * @return {@code this} for chaining.
      */
-    public void setWriteBehindFlushFrequency(long writeBehindFlushFreq) {
+    public CacheConfiguration setWriteBehindFlushFrequency(long writeBehindFlushFreq) {
         this.writeBehindFlushFreq = writeBehindFlushFreq;
+
+        return this;
     }
 
     /**
@@ -1120,9 +1213,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param writeBehindFlushThreadCnt Count of flush threads.
      * @see #getWriteBehindFlushThreadCount()
+     * @return {@code this} for chaining.
      */
-    public void setWriteBehindFlushThreadCount(int writeBehindFlushThreadCnt) {
+    public CacheConfiguration setWriteBehindFlushThreadCount(int writeBehindFlushThreadCnt) {
         this.writeBehindFlushThreadCnt = writeBehindFlushThreadCnt;
+
+        return this;
     }
 
     /**
@@ -1144,9 +1240,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param writeBehindBatchSize Maximum batch size.
      * @see #getWriteBehindBatchSize()
+     * @return {@code this} for chaining.
      */
-    public void setWriteBehindBatchSize(int writeBehindBatchSize) {
+    public CacheConfiguration setWriteBehindBatchSize(int writeBehindBatchSize) {
         this.writeBehindBatchSize = writeBehindBatchSize;
+
+        return this;
     }
 
     /**
@@ -1166,9 +1265,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * for rebalancing than specified here (but never less threads).
      *
      * @param rebalancePoolSize Size of rebalancing thread pool.
+     * @return {@code this} for chaining.
      */
-    public void setRebalanceThreadPoolSize(int rebalancePoolSize) {
+    public CacheConfiguration setRebalanceThreadPoolSize(int rebalancePoolSize) {
         this.rebalancePoolSize = rebalancePoolSize;
+
+        return this;
     }
 
     /**
@@ -1186,9 +1288,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets rebalance timeout (ms).
      *
      * @param rebalanceTimeout Rebalance timeout (ms).
+     * @return {@code this} for chaining.
      */
-    public void setRebalanceTimeout(long rebalanceTimeout) {
+    public CacheConfiguration setRebalanceTimeout(long rebalanceTimeout) {
         this.rebalanceTimeout = rebalanceTimeout;
+
+        return this;
     }
 
     /**
@@ -1221,9 +1326,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets rebalance delay (see {@link #getRebalanceDelay()} for more information).
      *
      * @param rebalanceDelay Rebalance delay to set.
+     * @return {@code this} for chaining.
      */
-    public void setRebalanceDelay(long rebalanceDelay) {
+    public CacheConfiguration setRebalanceDelay(long rebalanceDelay) {
         this.rebalanceDelay = rebalanceDelay;
+
+        return this;
     }
 
     /**
@@ -1254,9 +1362,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param rebalanceThrottle Time in milliseconds to wait between rebalance messages to avoid overloading of CPU,
      * {@code 0} to disable throttling.
+     * @return {@code this} for chaining.
      */
-    public void setRebalanceThrottle(long rebalanceThrottle) {
+    public CacheConfiguration setRebalanceThrottle(long rebalanceThrottle) {
         this.rebalanceThrottle = rebalanceThrottle;
+
+        return this;
     }
 
     /**
@@ -1278,9 +1389,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * described in {@link AffinityKeyMapper} documentation.
      *
      * @param affMapper Affinity mapper.
+     * @return {@code this} for chaining.
      */
-    public void setAffinityMapper(AffinityKeyMapper affMapper) {
+    public CacheConfiguration setAffinityMapper(AffinityKeyMapper affMapper) {
         this.affMapper = affMapper;
+
+        return this;
     }
 
     /**
@@ -1322,9 +1436,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * off-heap space without affecting JVM performance at all.
      *
      * @param offHeapMaxMem Maximum memory in bytes available to off-heap memory space.
+     * @return {@code this} for chaining.
      */
-    public void setOffHeapMaxMemory(long offHeapMaxMem) {
+    public CacheConfiguration setOffHeapMaxMemory(long offHeapMaxMem) {
         this.offHeapMaxMem = offHeapMaxMem;
+
+        return this;
     }
 
     /**
@@ -1343,9 +1460,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets memory mode for cache.
      *
      * @param memMode Memory mode.
+     * @return {@code this} for chaining.
      */
-    public void setMemoryMode(CacheMemoryMode memMode) {
+    public CacheConfiguration setMemoryMode(CacheMemoryMode memMode) {
         this.memMode = memMode;
+
+        return this;
     }
 
     /**
@@ -1362,9 +1482,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets cache interceptor.
      *
      * @param interceptor Cache interceptor.
+     * @return {@code this} for chaining.
      */
-    public void setInterceptor(CacheInterceptor<K, V> interceptor) {
+    public CacheConfiguration setInterceptor(CacheInterceptor<K, V> interceptor) {
         this.interceptor = interceptor;
+
+        return this;
     }
 
     /**
@@ -1380,9 +1503,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets collection of type metadata objects.
      *
      * @param typeMeta Collection of type metadata.
+     * @return {@code this} for chaining.
      */
-    public void setTypeMetadata(Collection<CacheTypeMetadata> typeMeta) {
+    public CacheConfiguration setTypeMetadata(Collection<CacheTypeMetadata> typeMeta) {
         this.typeMeta = typeMeta;
+
+        return this;
     }
 
     /**
@@ -1402,9 +1528,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets read from backup flag.
      *
      * @param readFromBackup {@code true} to allow reads from backups.
+     * @return {@code this} for chaining.
      */
-    public void setReadFromBackup(boolean readFromBackup) {
+    public CacheConfiguration setReadFromBackup(boolean readFromBackup) {
         this.readFromBackup = readFromBackup;
+
+        return this;
     }
 
     /**
@@ -1423,9 +1552,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param cpOnRead Copy on get flag.
      * @see #isCopyOnRead
+     * @return {@code this} for chaining.
      */
-    public void setCopyOnRead(boolean cpOnRead) {
+    public CacheConfiguration setCopyOnRead(boolean cpOnRead) {
         this.cpOnRead = cpOnRead;
+
+        return this;
     }
 
     /**
@@ -1433,9 +1565,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * to be used as user-defined functions from SQL queries.
      *
      * @param cls One or more classes with SQL functions.
+     * @return {@code this} for chaining.
      */
-    public void setSqlFunctionClasses(Class<?>... cls) {
+    public CacheConfiguration setSqlFunctionClasses(Class<?>... cls) {
         this.sqlFuncCls = cls;
+
+        return this;
     }
 
     /**
@@ -1461,9 +1596,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Gets timeout in milliseconds after which long query warning will be printed.
      *
      * @param longQryWarnTimeout Timeout in milliseconds.
+     * @return {@code this} for chaining.
      */
-    public void setLongQueryWarningTimeout(long longQryWarnTimeout) {
+    public CacheConfiguration setLongQueryWarningTimeout(long longQryWarnTimeout) {
         this.longQryWarnTimeout = longQryWarnTimeout;
+
+        return this;
     }
 
     /**
@@ -1483,9 +1621,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * also allows having special characters in table and field names.
      *
      * @param sqlEscapeAll Flag value.
+     * @return {@code this} for chaining.
      */
-    public void setSqlEscapeAll(boolean sqlEscapeAll) {
+    public CacheConfiguration setSqlEscapeAll(boolean sqlEscapeAll) {
         this.sqlEscapeAll = sqlEscapeAll;
+
+        return this;
     }
 
     /**
@@ -1517,19 +1658,22 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * from package {@link org.apache.ignite.cache.query.annotations}.
      *
      * @param indexedTypes Key and value type pairs.
+     * @return {@code this} for chaining.
      */
-    public void setIndexedTypes(Class<?>... indexedTypes) {
+    public CacheConfiguration setIndexedTypes(Class<?>... indexedTypes) {
         A.ensure(indexedTypes == null || (indexedTypes.length & 1) == 0,
             "Number of indexed types is expected to be even. Refer to method javadoc for details.");
 
         this.indexedTypes = indexedTypes;
+
+        return this;
     }
 
     /**
      * Number of SQL rows which will be cached onheap to avoid deserialization on each SQL index access.
      * This setting only makes sense when offheap is enabled for this cache.
      *
-     * @return size Cache size.
+     * @return Cache size.
      * @see #setOffHeapMaxMemory(long)
      */
     public int getSqlOnheapRowCacheSize() {
@@ -1542,9 +1686,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param size Cache size.
      * @see #setOffHeapMaxMemory(long)
+     * @return {@code this} for chaining.
      */
-    public void setSqlOnheapRowCacheSize(int size) {
+    public CacheConfiguration setSqlOnheapRowCacheSize(int size) {
         this.sqlOnheapRowCacheSize = size;
+
+        return this;
     }
 
     /**
@@ -1560,9 +1707,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Sets cache plugin configurations.
      *
      * @param pluginCfgs Cache plugin configurations.
+     * @return {@code this} for chaining.
      */
-    public void setPluginConfigurations(CachePluginConfiguration... pluginCfgs) {
+    public CacheConfiguration setPluginConfigurations(CachePluginConfiguration... pluginCfgs) {
         this.pluginCfgs = pluginCfgs;
+
+        return this;
     }
 
     /**
@@ -1576,9 +1726,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
     /**
      * Sets topology validator.
      * @param topValidator validator.
+     * @return {@code this} for chaining.
      */
-    public void setTopologyValidator(TopologyValidator topValidator) {
+    public CacheConfiguration setTopologyValidator(TopologyValidator topValidator) {
         this.topValidator = topValidator;
+
+        return this;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
index 76f3043..ebe2b8e 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
@@ -533,9 +533,12 @@ public class IgniteConfiguration {
      * or in-memory data grid storage.
      *
      * @param daemon Daemon flag.
+     * @return {@code this} for chaining.
      */
-    public void setDaemon(boolean daemon) {
+    public IgniteConfiguration setDaemon(boolean daemon) {
         this.daemon = daemon;
+
+        return this;
     }
 
     /**
@@ -543,9 +546,12 @@ public class IgniteConfiguration {
      *
      * @param gridName Grid name to set. Can be {@code null}, which is default
      *      grid name.
+     * @return {@code this} for chaining.
      */
-    public void setGridName(String gridName) {
+    public IgniteConfiguration setGridName(String gridName) {
         this.gridName = gridName;
+
+        return this;
     }
 
     /**
@@ -577,9 +583,12 @@ public class IgniteConfiguration {
      *
      * @param userAttrs User attributes for this node.
      * @see IgniteConfiguration#getUserAttributes()
+     * @return {@code this} for chaining.
      */
-    public void setUserAttributes(Map<String, ?> userAttrs) {
+    public IgniteConfiguration setUserAttributes(Map<String, ?> userAttrs) {
         this.userAttrs = userAttrs;
+
+        return this;
     }
 
     /**
@@ -598,9 +607,12 @@ public class IgniteConfiguration {
      *
      * @param log Logger to use within grid.
      * @see IgniteConfiguration#getGridLogger()
+     * @return {@code this} for chaining.
      */
-    public void setGridLogger(IgniteLogger log) {
+    public IgniteConfiguration setGridLogger(IgniteLogger log) {
         this.log = log;
+
+        return this;
     }
 
     /**
@@ -715,9 +727,12 @@ public class IgniteConfiguration {
      *
      * @param poolSize Thread pool size to use within grid.
      * @see IgniteConfiguration#getPublicThreadPoolSize()
+     * @return {@code this} for chaining.
      */
-    public void setPublicThreadPoolSize(int poolSize) {
+    public IgniteConfiguration setPublicThreadPoolSize(int poolSize) {
         pubPoolSize = poolSize;
+
+        return this;
     }
 
     /**
@@ -725,9 +740,12 @@ public class IgniteConfiguration {
      *
      * @param poolSize Thread pool size to use within grid.
      * @see IgniteConfiguration#getSystemThreadPoolSize()
+     * @return {@code this} for chaining.
      */
-    public void setSystemThreadPoolSize(int poolSize) {
+    public IgniteConfiguration setSystemThreadPoolSize(int poolSize) {
         sysPoolSize = poolSize;
+
+        return this;
     }
 
     /**
@@ -735,9 +753,12 @@ public class IgniteConfiguration {
      *
      * @param poolSize Thread pool size to use within grid.
      * @see IgniteConfiguration#getManagementThreadPoolSize()
+     * @return {@code this} for chaining.
      */
-    public void setManagementThreadPoolSize(int poolSize) {
+    public IgniteConfiguration setManagementThreadPoolSize(int poolSize) {
         mgmtPoolSize = poolSize;
+
+        return this;
     }
 
     /**
@@ -745,9 +766,12 @@ public class IgniteConfiguration {
      *
      * @param poolSize Thread pool size to use within grid.
      * @see IgniteConfiguration#getPeerClassLoadingThreadPoolSize()
+     * @return {@code this} for chaining.
      */
-    public void setPeerClassLoadingThreadPoolSize(int poolSize) {
+    public IgniteConfiguration setPeerClassLoadingThreadPoolSize(int poolSize) {
         p2pPoolSize = poolSize;
+
+        return this;
     }
 
     /**
@@ -755,9 +779,12 @@ public class IgniteConfiguration {
      *
      * @param poolSize Executor service to use for outgoing IGFS messages.
      * @see IgniteConfiguration#getIgfsThreadPoolSize()
+     * @return {@code this} for chaining.
      */
-    public void setIgfsThreadPoolSize(int poolSize) {
+    public IgniteConfiguration setIgfsThreadPoolSize(int poolSize) {
         igfsPoolSize = poolSize;
+
+        return this;
     }
 
     /**
@@ -766,9 +793,12 @@ public class IgniteConfiguration {
      * @param poolSize Default executor service size to use for utility cache messages.
      * @see IgniteConfiguration#getUtilityCacheThreadPoolSize()
      * @see IgniteConfiguration#getUtilityCacheKeepAliveTime()
+     * @return {@code this} for chaining.
      */
-    public void setUtilityCachePoolSize(int poolSize) {
+    public IgniteConfiguration setUtilityCachePoolSize(int poolSize) {
         utilityCachePoolSize = poolSize;
+
+        return this;
     }
 
     /**
@@ -777,9 +807,12 @@ public class IgniteConfiguration {
      * @param keepAliveTime Keep alive time of executor service to use for utility cache messages.
      * @see IgniteConfiguration#getUtilityCacheThreadPoolSize()
      * @see IgniteConfiguration#getUtilityCacheKeepAliveTime()
+     * @return {@code this} for chaining.
      */
-    public void setUtilityCacheKeepAliveTime(long keepAliveTime) {
+    public IgniteConfiguration setUtilityCacheKeepAliveTime(long keepAliveTime) {
         utilityCacheKeepAliveTime = keepAliveTime;
+
+        return this;
     }
 
     /**
@@ -788,9 +821,12 @@ public class IgniteConfiguration {
      * @param poolSize Default executor service size to use for marshaller messages.
      * @see IgniteConfiguration#getMarshallerCacheThreadPoolSize()
      * @see IgniteConfiguration#getMarshallerCacheKeepAliveTime()
+     * @return {@code this} for chaining.
      */
-    public void setMarshallerCachePoolSize(int poolSize) {
+    public IgniteConfiguration setMarshallerCachePoolSize(int poolSize) {
         marshCachePoolSize = poolSize;
+
+        return this;
     }
 
     /**
@@ -799,9 +835,12 @@ public class IgniteConfiguration {
      * @param keepAliveTime Keep alive time of executor service to use for marshaller messages.
      * @see IgniteConfiguration#getMarshallerCacheThreadPoolSize()
      * @see IgniteConfiguration#getMarshallerCacheKeepAliveTime()
+     * @return {@code this} for chaining.
      */
-    public void setMarshallerCacheKeepAliveTime(long keepAliveTime) {
+    public IgniteConfiguration setMarshallerCacheKeepAliveTime(long keepAliveTime) {
         marshCacheKeepAliveTime = keepAliveTime;
+
+        return this;
     }
 
     /**
@@ -824,9 +863,12 @@ public class IgniteConfiguration {
      * @param ggHome {@code Ignition} installation folder.
      * @see IgniteConfiguration#getIgniteHome()
      * @see IgniteSystemProperties#IGNITE_HOME
+     * @return {@code this} for chaining.
      */
-    public void setIgniteHome(String ggHome) {
+    public IgniteConfiguration setIgniteHome(String ggHome) {
         this.ggHome = ggHome;
+
+        return this;
     }
 
     /**
@@ -849,9 +891,12 @@ public class IgniteConfiguration {
      *
      * @param ggWork {@code Ignite} work folder.
      * @see IgniteConfiguration#getWorkDirectory()
+     * @return {@code this} for chaining.
      */
-    public void setWorkDirectory(String ggWork) {
+    public IgniteConfiguration setWorkDirectory(String ggWork) {
         this.ggWork = ggWork;
+
+        return this;
     }
 
     /**
@@ -869,9 +914,12 @@ public class IgniteConfiguration {
      * Sets initialized and started MBean server.
      *
      * @param mbeanSrv Initialized and started MBean server.
+     * @return {@code this} for chaining.
      */
-    public void setMBeanServer(MBeanServer mbeanSrv) {
+    public IgniteConfiguration setMBeanServer(MBeanServer mbeanSrv) {
         this.mbeanSrv = mbeanSrv;
+
+        return this;
     }
 
     /**
@@ -888,9 +936,12 @@ public class IgniteConfiguration {
      *
      * @param nodeId Unique identifier for local node.
      * @see IgniteConfiguration#getNodeId()
+     * @return {@code this} for chaining.
      */
-    public void setNodeId(UUID nodeId) {
+    public IgniteConfiguration setNodeId(UUID nodeId) {
         this.nodeId = nodeId;
+
+        return this;
     }
 
     /**
@@ -909,9 +960,12 @@ public class IgniteConfiguration {
      *
      * @param marsh Marshaller to use within grid.
      * @see IgniteConfiguration#getMarshaller()
+     * @return {@code this} for chaining.
      */
-    public void setMarshaller(Marshaller marsh) {
+    public IgniteConfiguration setMarshaller(Marshaller marsh) {
         this.marsh = marsh;
+
+        return this;
     }
 
 
@@ -949,9 +1003,12 @@ public class IgniteConfiguration {
      * Sets marshal local jobs flag.
      *
      * @param marshLocJobs {@code True} if local jobs should be marshalled.
+     * @return {@code this} for chaining.
      */
-    public void setMarshalLocalJobs(boolean marshLocJobs) {
+    public IgniteConfiguration setMarshalLocalJobs(boolean marshLocJobs) {
         this.marshLocJobs = marshLocJobs;
+
+        return this;
     }
 
     /**
@@ -959,9 +1016,12 @@ public class IgniteConfiguration {
      *
      * @param p2pEnabled {@code true} if peer class loading is
      *      enabled, {@code false} otherwise.
+     * @return {@code this} for chaining.
      */
-    public void setPeerClassLoadingEnabled(boolean p2pEnabled) {
+    public IgniteConfiguration setPeerClassLoadingEnabled(boolean p2pEnabled) {
         this.p2pEnabled = p2pEnabled;
+
+        return this;
     }
 
     /**
@@ -983,9 +1043,12 @@ public class IgniteConfiguration {
      *
      * @param p2pLocClsPathExcl List of P2P loaded packages. Package
      *      name supports '*' at the end like in package import clause.
+     * @return {@code this} for chaining.
      */
-    public void setPeerClassLoadingLocalClassPathExclude(String... p2pLocClsPathExcl) {
+    public IgniteConfiguration setPeerClassLoadingLocalClassPathExclude(String... p2pLocClsPathExcl) {
         this.p2pLocClsPathExcl = p2pLocClsPathExcl;
+
+        return this;
     }
 
     /**
@@ -1007,9 +1070,12 @@ public class IgniteConfiguration {
      * @param metricsHistSize Number of metrics kept in history to use for
      *      metric totals and averages calculations.
      * @see #DFLT_METRICS_HISTORY_SIZE
+     * @return {@code this} for chaining.
      */
-    public void setMetricsHistorySize(int metricsHistSize) {
+    public IgniteConfiguration setMetricsHistorySize(int metricsHistSize) {
         this.metricsHistSize = metricsHistSize;
+
+        return this;
     }
 
     /**
@@ -1043,9 +1109,12 @@ public class IgniteConfiguration {
      * {@link #DFLT_METRICS_UPDATE_FREQ} is used.
      *
      * @param metricsUpdateFreq Job metrics update frequency in milliseconds.
+     * @return {@code this} for chaining.
      */
-    public void setMetricsUpdateFrequency(long metricsUpdateFreq) {
+    public IgniteConfiguration setMetricsUpdateFrequency(long metricsUpdateFreq) {
         this.metricsUpdateFreq = metricsUpdateFreq;
+
+        return this;
     }
 
     /**
@@ -1066,9 +1135,12 @@ public class IgniteConfiguration {
      *
      * @param metricsExpTime The metricsExpTime to set.
      * @see #DFLT_METRICS_EXPIRE_TIME
+     * @return {@code this} for chaining.
      */
-    public void setMetricsExpireTime(long metricsExpTime) {
+    public IgniteConfiguration setMetricsExpireTime(long metricsExpTime) {
         this.metricsExpTime = metricsExpTime;
+
+        return this;
     }
 
     /**
@@ -1092,9 +1164,12 @@ public class IgniteConfiguration {
      *
      * @param netTimeout Maximum timeout for network requests.
      * @see #DFLT_NETWORK_TIMEOUT
+     * @return {@code this} for chaining.
      */
-    public void setNetworkTimeout(long netTimeout) {
+    public IgniteConfiguration setNetworkTimeout(long netTimeout) {
         this.netTimeout = netTimeout;
+
+        return this;
     }
 
     /**
@@ -1118,9 +1193,12 @@ public class IgniteConfiguration {
      * {@link #DFLT_SEND_RETRY_DELAY} is used.
      *
      * @param sndRetryDelay Interval between message send retries.
+     * @return {@code this} for chaining.
      */
-    public void setNetworkSendRetryDelay(long sndRetryDelay) {
+    public IgniteConfiguration setNetworkSendRetryDelay(long sndRetryDelay) {
         this.sndRetryDelay = sndRetryDelay;
+
+        return this;
     }
 
     /**
@@ -1144,9 +1222,12 @@ public class IgniteConfiguration {
      * {@link #DFLT_SEND_RETRY_CNT} is used.
      *
      * @param sndRetryCnt Message send retries count.
+     * @return {@code this} for chaining.
      */
-    public void setNetworkSendRetryCount(int sndRetryCnt) {
+    public IgniteConfiguration setNetworkSendRetryCount(int sndRetryCnt) {
         this.sndRetryCnt = sndRetryCnt;
+
+        return this;
     }
 
     /**
@@ -1164,9 +1245,12 @@ public class IgniteConfiguration {
      * Sets number of samples used for clock synchronization.
      *
      * @param clockSyncSamples Number of samples.
+     * @return {@code this} for chaining.
      */
-    public void setClockSyncSamples(int clockSyncSamples) {
+    public IgniteConfiguration setClockSyncSamples(int clockSyncSamples) {
         this.clockSyncSamples = clockSyncSamples;
+
+        return this;
     }
 
     /**
@@ -1184,9 +1268,12 @@ public class IgniteConfiguration {
      * Sets clock synchronization frequency in milliseconds.
      *
      * @param clockSyncFreq Clock synchronization frequency.
+     * @return {@code this} for chaining.
      */
-    public void setClockSyncFrequency(long clockSyncFreq) {
+    public IgniteConfiguration setClockSyncFrequency(long clockSyncFreq) {
         this.clockSyncFreq = clockSyncFreq;
+
+        return this;
     }
 
     /**
@@ -1211,9 +1298,12 @@ public class IgniteConfiguration {
      *
      * @param lifecycleBeans Collection of lifecycle beans.
      * @see LifecycleEventType
+     * @return {@code this} for chaining.
      */
-    public void setLifecycleBeans(LifecycleBean... lifecycleBeans) {
+    public IgniteConfiguration setLifecycleBeans(LifecycleBean... lifecycleBeans) {
         this.lifecycleBeans = lifecycleBeans;
+
+        return this;
     }
 
     /**
@@ -1231,9 +1321,12 @@ public class IgniteConfiguration {
      *
      * @param evtSpi Fully configured instance of {@link EventStorageSpi}.
      * @see IgniteConfiguration#getEventStorageSpi()
+     * @return {@code this} for chaining.
      */
-    public void setEventStorageSpi(EventStorageSpi evtSpi) {
+    public IgniteConfiguration setEventStorageSpi(EventStorageSpi evtSpi) {
         this.evtSpi = evtSpi;
+
+        return this;
     }
 
     /**
@@ -1251,9 +1344,12 @@ public class IgniteConfiguration {
      *
      * @param discoSpi Fully configured instance of {@link DiscoverySpi}.
      * @see IgniteConfiguration#getDiscoverySpi()
+     * @return {@code this} for chaining.
      */
-    public void setDiscoverySpi(DiscoverySpi discoSpi) {
+    public IgniteConfiguration setDiscoverySpi(DiscoverySpi discoSpi) {
         this.discoSpi = discoSpi;
+
+        return this;
     }
 
     /**
@@ -1269,9 +1365,12 @@ public class IgniteConfiguration {
      * Sets segmentation policy.
      *
      * @param segPlc Segmentation policy.
+     * @return {@code this} for chaining.
      */
-    public void setSegmentationPolicy(SegmentationPolicy segPlc) {
+    public IgniteConfiguration setSegmentationPolicy(SegmentationPolicy segPlc) {
         this.segPlc = segPlc;
+
+        return this;
     }
 
     /**
@@ -1293,9 +1392,12 @@ public class IgniteConfiguration {
      * Sets wait for segment on start flag.
      *
      * @param waitForSegOnStart {@code True} to wait for segment on start.
+     * @return {@code this} for chaining.
      */
-    public void setWaitForSegmentOnStart(boolean waitForSegOnStart) {
+    public IgniteConfiguration setWaitForSegmentOnStart(boolean waitForSegOnStart) {
         this.waitForSegOnStart = waitForSegOnStart;
+
+        return this;
     }
 
     /**
@@ -1320,9 +1422,12 @@ public class IgniteConfiguration {
      *
      * @param allResolversPassReq {@code True} if all segmentation resolvers should
      *      succeed for node to be in the correct segment.
+     * @return {@code this} for chaining.
      */
-    public void setAllSegmentationResolversPassRequired(boolean allResolversPassReq) {
+    public IgniteConfiguration setAllSegmentationResolversPassRequired(boolean allResolversPassReq) {
         this.allResolversPassReq = allResolversPassReq;
+
+        return this;
     }
 
     /**
@@ -1341,9 +1446,12 @@ public class IgniteConfiguration {
      * Sets segmentation resolve attempts count.
      *
      * @param segResolveAttempts Segmentation resolve attempts.
+     * @return {@code this} for chaining.
      */
-    public void setSegmentationResolveAttempts(int segResolveAttempts) {
+    public IgniteConfiguration setSegmentationResolveAttempts(int segResolveAttempts) {
         this.segResolveAttempts = segResolveAttempts;
+
+        return this;
     }
 
     /**
@@ -1362,9 +1470,12 @@ public class IgniteConfiguration {
      * Sets segmentation resolvers.
      *
      * @param segResolvers Segmentation resolvers.
+     * @return {@code this} for chaining.
      */
-    public void setSegmentationResolvers(SegmentationResolver... segResolvers) {
+    public IgniteConfiguration setSegmentationResolvers(SegmentationResolver... segResolvers) {
         this.segResolvers = segResolvers;
+
+        return this;
     }
 
     /**
@@ -1385,9 +1496,12 @@ public class IgniteConfiguration {
      * Sets network segment check frequency.
      *
      * @param segChkFreq Segment check frequency.
+     * @return {@code this} for chaining.
      */
-    public void setSegmentCheckFrequency(long segChkFreq) {
+    public IgniteConfiguration setSegmentCheckFrequency(long segChkFreq) {
         this.segChkFreq = segChkFreq;
+
+        return this;
     }
 
     /**
@@ -1405,9 +1519,12 @@ public class IgniteConfiguration {
      *
      * @param commSpi Fully configured instance of {@link CommunicationSpi}.
      * @see IgniteConfiguration#getCommunicationSpi()
+     * @return {@code this} for chaining.
      */
-    public void setCommunicationSpi(CommunicationSpi commSpi) {
+    public IgniteConfiguration setCommunicationSpi(CommunicationSpi commSpi) {
         this.commSpi = commSpi;
+
+        return this;
     }
 
     /**
@@ -1430,9 +1547,12 @@ public class IgniteConfiguration {
      * @param colSpi Fully configured instance of {@link CollisionSpi} or
      *      {@code null} if no SPI provided.
      * @see IgniteConfiguration#getCollisionSpi()
+     * @return {@code this} for chaining.
      */
-    public void setCollisionSpi(CollisionSpi colSpi) {
+    public IgniteConfiguration setCollisionSpi(CollisionSpi colSpi) {
         this.colSpi = colSpi;
+
+        return this;
     }
 
     /**
@@ -1450,9 +1570,12 @@ public class IgniteConfiguration {
      *
      * @param deploySpi Fully configured instance of {@link DeploymentSpi}.
      * @see IgniteConfiguration#getDeploymentSpi()
+     * @return {@code this} for chaining.
      */
-    public void setDeploymentSpi(DeploymentSpi deploySpi) {
+    public IgniteConfiguration setDeploymentSpi(DeploymentSpi deploySpi) {
         this.deploySpi = deploySpi;
+
+        return this;
     }
 
     /**
@@ -1470,9 +1593,12 @@ public class IgniteConfiguration {
      *
      * @param cpSpi Fully configured instance of {@link CheckpointSpi}.
      * @see IgniteConfiguration#getCheckpointSpi()
+     * @return {@code this} for chaining.
      */
-    public void setCheckpointSpi(CheckpointSpi... cpSpi) {
+    public IgniteConfiguration setCheckpointSpi(CheckpointSpi... cpSpi) {
         this.cpSpi = cpSpi;
+
+        return this;
     }
 
     /**
@@ -1491,9 +1617,12 @@ public class IgniteConfiguration {
      * @param failSpi Fully configured instance of {@link FailoverSpi} or
      *      {@code null} if no SPI provided.
      * @see IgniteConfiguration#getFailoverSpi()
+     * @return {@code this} for chaining.
      */
-    public void setFailoverSpi(FailoverSpi... failSpi) {
+    public IgniteConfiguration setFailoverSpi(FailoverSpi... failSpi) {
         this.failSpi = failSpi;
+
+        return this;
     }
 
     /**
@@ -1533,9 +1662,12 @@ public class IgniteConfiguration {
      *
      * @param discoStartupDelay Time in milliseconds for when nodes
      *      can be out-of-sync during startup.
+     * @return {@code this} for chaining.
      */
-    public void setDiscoveryStartupDelay(long discoStartupDelay) {
+    public IgniteConfiguration setDiscoveryStartupDelay(long discoStartupDelay) {
         this.discoStartupDelay = discoStartupDelay;
+
+        return this;
     }
 
     /**
@@ -1544,9 +1676,12 @@ public class IgniteConfiguration {
      * @param loadBalancingSpi Fully configured instance of {@link LoadBalancingSpi} or
      *      {@code null} if no SPI provided.
      * @see IgniteConfiguration#getLoadBalancingSpi()
+     * @return {@code this} for chaining.
      */
-    public void setLoadBalancingSpi(LoadBalancingSpi... loadBalancingSpi) {
+    public IgniteConfiguration setLoadBalancingSpi(LoadBalancingSpi... loadBalancingSpi) {
         this.loadBalancingSpi = loadBalancingSpi;
+
+        return this;
     }
 
     /**
@@ -1555,9 +1690,12 @@ public class IgniteConfiguration {
      * @param swapSpaceSpi Fully configured instances of {@link SwapSpaceSpi} or
      *      <tt>null</tt> if no SPI provided.
      * @see IgniteConfiguration#getSwapSpaceSpi()
+     * @return {@code this} for chaining.
      */
-    public void setSwapSpaceSpi(SwapSpaceSpi swapSpaceSpi) {
+    public IgniteConfiguration setSwapSpaceSpi(SwapSpaceSpi swapSpaceSpi) {
         this.swapSpaceSpi = swapSpaceSpi;
+
+        return this;
     }
 
     /**
@@ -1578,9 +1716,12 @@ public class IgniteConfiguration {
      *
      * @param indexingSpi Fully configured instance of {@link IndexingSpi}.
      * @see IgniteConfiguration#getIndexingSpi()
+     * @return {@code this} for chaining.
      */
-    public void setIndexingSpi(IndexingSpi indexingSpi) {
+    public IgniteConfiguration setIndexingSpi(IndexingSpi indexingSpi) {
         this.indexingSpi = indexingSpi;
+
+        return this;
     }
 
     /**
@@ -1605,18 +1746,24 @@ public class IgniteConfiguration {
      * Sets address resolver for addresses mapping determination.
      *
      * @param addrRslvr Address resolver.
+     * @return {@code this} for chaining.
      */
-    public void setAddressResolver(AddressResolver addrRslvr) {
+    public IgniteConfiguration setAddressResolver(AddressResolver addrRslvr) {
         this.addrRslvr = addrRslvr;
+
+        return this;
     }
 
     /**
      * Sets task classes and resources sharing mode.
      *
      * @param deployMode Task classes and resources sharing mode.
+     * @return {@code this} for chaining.
      */
-    public void setDeploymentMode(DeploymentMode deployMode) {
+    public IgniteConfiguration setDeploymentMode(DeploymentMode deployMode) {
         this.deployMode = deployMode;
+
+        return this;
     }
 
     /**
@@ -1634,9 +1781,12 @@ public class IgniteConfiguration {
      * missed resources caching.
      *
      * @param p2pMissedCacheSize Size of missed resources cache.
+     * @return {@code this} for chaining.
      */
-    public void setPeerClassLoadingMissedResourcesCacheSize(int p2pMissedCacheSize) {
+    public IgniteConfiguration setPeerClassLoadingMissedResourcesCacheSize(int p2pMissedCacheSize) {
         this.p2pMissedCacheSize = p2pMissedCacheSize;
+
+        return this;
     }
 
     /**
@@ -1666,8 +1816,10 @@ public class IgniteConfiguration {
      * @param cacheCfg Cache configurations.
      */
     @SuppressWarnings({"ZeroLengthArrayAllocation"})
-    public void setCacheConfiguration(CacheConfiguration... cacheCfg) {
+    public IgniteConfiguration setCacheConfiguration(CacheConfiguration... cacheCfg) {
         this.cacheCfg = cacheCfg == null ? new CacheConfiguration[0] : cacheCfg;
+
+        return this;
     }
 
     /**
@@ -1683,9 +1835,12 @@ public class IgniteConfiguration {
      * Sets client mode flag.
      *
      * @param clientMode Client mode flag.
+     * @return {@code this} for chaining.
      */
-    public void setClientMode(boolean clientMode) {
+    public IgniteConfiguration setClientMode(boolean clientMode) {
         this.clientMode = clientMode;
+
+        return this;
     }
 
     /**
@@ -1716,9 +1871,12 @@ public class IgniteConfiguration {
      *
      * @param cacheSanityCheckEnabled {@code True} if cache sanity check is enabled.
      * @see #isCacheSanityCheckEnabled()
+     * @return {@code this} for chaining.
      */
-    public void setCacheSanityCheckEnabled(boolean cacheSanityCheckEnabled) {
+    public IgniteConfiguration setCacheSanityCheckEnabled(boolean cacheSanityCheckEnabled) {
         this.cacheSanityCheckEnabled = cacheSanityCheckEnabled;
+
+        return this;
     }
 
     /**
@@ -1743,9 +1901,12 @@ public class IgniteConfiguration {
      * Note, that either the include event types or the exclude event types can be established.
      *
      * @param inclEvtTypes Include event types.
+     * @return {@code this} for chaining.
      */
-    public void setIncludeEventTypes(int... inclEvtTypes) {
+    public IgniteConfiguration setIncludeEventTypes(int... inclEvtTypes) {
         this.inclEvtTypes = inclEvtTypes;
+
+        return this;
     }
 
     /**
@@ -1753,9 +1914,12 @@ public class IgniteConfiguration {
      * override all default local bind settings within Ignite or any of its SPIs.
      *
      * @param locHost Local IP address or host to bind to.
+     * @return {@code this} for chaining.
      */
-    public void setLocalHost(String locHost) {
+    public IgniteConfiguration setLocalHost(String locHost) {
         this.locHost = locHost;
+
+        return this;
     }
 
     /**
@@ -1791,9 +1955,12 @@ public class IgniteConfiguration {
      * Sets time server port base.
      *
      * @param timeSrvPortBase Time server port base.
+     * @return {@code this} for chaining.
      */
-    public void setTimeServerPortBase(int timeSrvPortBase) {
+    public IgniteConfiguration setTimeServerPortBase(int timeSrvPortBase) {
         this.timeSrvPortBase = timeSrvPortBase;
+
+        return this;
     }
 
     /**
@@ -1809,9 +1976,12 @@ public class IgniteConfiguration {
      * Sets time server port range.
      *
      * @param timeSrvPortRange Time server port range.
+     * @return {@code this} for chaining.
      */
-    public void setTimeServerPortRange(int timeSrvPortRange) {
+    public IgniteConfiguration setTimeServerPortRange(int timeSrvPortRange) {
         this.timeSrvPortRange = timeSrvPortRange;
+
+        return this;
     }
 
     /**
@@ -1832,9 +2002,12 @@ public class IgniteConfiguration {
      * See {@link #getIncludeProperties()} for more info.
      *
      * @param includeProps Array of system or environment property names to include into node attributes.
+     * @return {@code this} for chaining.
      */
-    public void setIncludeProperties(String... includeProps) {
+    public IgniteConfiguration setIncludeProperties(String... includeProps) {
         this.includeProps = includeProps;
+
+        return this;
     }
 
     /**
@@ -1858,9 +2031,12 @@ public class IgniteConfiguration {
      * If not provided, then default value {@link #DFLT_METRICS_LOG_FREQ} is used.
      *
      * @param metricsLogFreq Frequency of metrics log print out.
+     * @return {@code this} for chaining.
      */
-    public void setMetricsLogFrequency(long metricsLogFreq) {
+    public IgniteConfiguration setMetricsLogFrequency(long metricsLogFreq) {
         this.metricsLogFreq = metricsLogFreq;
+
+        return this;
     }
 
     /**
@@ -1876,9 +2052,12 @@ public class IgniteConfiguration {
      * Sets IGFS (Ignite In-Memory File System) configurations.
      *
      * @param igfsCfg IGFS configurations.
+     * @return {@code this} for chaining.
      */
-    public void setFileSystemConfiguration(FileSystemConfiguration... igfsCfg) {
+    public IgniteConfiguration setFileSystemConfiguration(FileSystemConfiguration... igfsCfg) {
         this.igfsCfg = igfsCfg;
+
+        return this;
     }
 
     /**
@@ -1894,9 +2073,12 @@ public class IgniteConfiguration {
      * Sets hadoop configuration.
      *
      * @param hadoopCfg Hadoop configuration.
+     * @return {@code this} for chaining.
      */
-    public void setHadoopConfiguration(HadoopConfiguration hadoopCfg) {
+    public IgniteConfiguration setHadoopConfiguration(HadoopConfiguration hadoopCfg) {
         this.hadoopCfg = hadoopCfg;
+
+        return this;
     }
 
     /**
@@ -1908,9 +2090,12 @@ public class IgniteConfiguration {
 
     /**
      * @param connectorCfg Connector configuration.
+     * @return {@code this} for chaining.
      */
-    public void setConnectorConfiguration(ConnectorConfiguration connectorCfg) {
+    public IgniteConfiguration setConnectorConfiguration(ConnectorConfiguration connectorCfg) {
         this.connectorCfg = connectorCfg;
+
+        return this;
     }
 
     /**
@@ -1926,9 +2111,12 @@ public class IgniteConfiguration {
      * Sets configurations for services to be deployed on the grid.
      *
      * @param svcCfgs Configurations for services to be deployed on the grid.
+     * @return {@code this} for chaining.
      */
-    public void setServiceConfiguration(ServiceConfiguration... svcCfgs) {
+    public IgniteConfiguration setServiceConfiguration(ServiceConfiguration... svcCfgs) {
         this.svcCfgs = svcCfgs;
+
+        return this;
     }
 
     /**
@@ -1947,9 +2135,12 @@ public class IgniteConfiguration {
      * Each listener is mapped to array of event types.
      *
      * @param lsnrs Pre-configured event listeners map.
+     * @return {@code this} for chaining.
      */
-    public void setLocalEventListeners(Map<IgnitePredicate<? extends Event>, int[]> lsnrs) {
+    public IgniteConfiguration setLocalEventListeners(Map<IgnitePredicate<? extends Event>, int[]> lsnrs) {
         this.lsnrs = lsnrs;
+
+        return this;
     }
 
     /**
@@ -1967,9 +2158,12 @@ public class IgniteConfiguration {
      *
      * @param warmupClos Warmup closure to execute.
      * @see #getWarmupClosure()
+     * @return {@code this} for chaining.
      */
-    public void setWarmupClosure(IgniteInClosure<IgniteConfiguration> warmupClos) {
+    public IgniteConfiguration setWarmupClosure(IgniteInClosure<IgniteConfiguration> warmupClos) {
         this.warmupClos = warmupClos;
+
+        return this;
     }
 
     /**
@@ -1985,9 +2179,12 @@ public class IgniteConfiguration {
      * Sets transactions configuration.
      *
      * @param txCfg Transactions configuration.
+     * @return {@code this} for chaining.
      */
-    public void setTransactionConfiguration(TransactionConfiguration txCfg) {
+    public IgniteConfiguration setTransactionConfiguration(TransactionConfiguration txCfg) {
         this.txCfg = txCfg;
+
+        return this;
     }
 
     /**
@@ -1999,9 +2196,12 @@ public class IgniteConfiguration {
 
     /**
      * @param pluginCfgs Plugin configurations.
+     * @return {@code this} for chaining.
      */
-    public void setPluginConfigurations(PluginConfiguration... pluginCfgs) {
+    public IgniteConfiguration setPluginConfigurations(PluginConfiguration... pluginCfgs) {
         this.pluginCfgs = pluginCfgs;
+
+        return this;
     }
 
     /**
@@ -2013,9 +2213,12 @@ public class IgniteConfiguration {
 
     /**
      * @param atomicCfg Atomic data structures configuration.
+     * @return {@code this} for chaining.
      */
-    public void setAtomicConfiguration(AtomicConfiguration atomicCfg) {
+    public IgniteConfiguration setAtomicConfiguration(AtomicConfiguration atomicCfg) {
         this.atomicCfg = atomicCfg;
+
+        return this;
     }
 
     /**
@@ -2024,9 +2227,12 @@ public class IgniteConfiguration {
      * {@link ExpiryPolicy ExpiryPolicys}).
      *
      * @param classLdr Class loader.
+     * @return {@code this} for chaining.
      */
-    public void setClassLoader(ClassLoader classLdr) {
+    public IgniteConfiguration setClassLoader(ClassLoader classLdr) {
         this.classLdr = classLdr;
+
+        return this;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/GridDirectCollection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridDirectCollection.java b/modules/core/src/main/java/org/apache/ignite/internal/GridDirectCollection.java
index 61144d6..58c1c29 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridDirectCollection.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridDirectCollection.java
@@ -17,10 +17,13 @@
 
 package org.apache.ignite.internal;
 
+import org.apache.ignite.plugin.extensions.communication.*;
+
 import java.lang.annotation.*;
 
 /**
  * Annotates iterable fields.
+ * Note that for any {@link Message} implementations it is enough to set item type to {@code Message.class}.
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.FIELD)

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java
index c60646e..505204d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal;
 import org.apache.ignite.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.events.*;
+import org.apache.ignite.internal.interop.*;
 import org.apache.ignite.internal.managers.deployment.*;
 import org.apache.ignite.internal.managers.discovery.*;
 import org.apache.ignite.internal.managers.eventstorage.*;
@@ -124,6 +125,9 @@ class GridEventConsumeHandler implements GridContinuousHandler {
         if (filter != null)
             ctx.resource().injectGeneric(filter);
 
+        if (filter instanceof InteropAwareEventFilter)
+            ((InteropAwareEventFilter)filter).initialize(ctx);
+
         final boolean loc = nodeId.equals(ctx.localNodeId());
 
         lsnr = new GridLocalEventListener() {
@@ -188,6 +192,28 @@ class GridEventConsumeHandler implements GridContinuousHandler {
 
         if (lsnr != null)
             ctx.event().removeLocalEventListener(lsnr, types);
+
+        RuntimeException err = null;
+
+        try {
+            if (filter instanceof InteropAwareEventFilter)
+                ((InteropAwareEventFilter)filter).close();
+        }
+        catch(RuntimeException ex) {
+            err = ex;
+        }
+
+        try {
+            if (cb instanceof InteropLocalEventListener)
+                ((InteropLocalEventListener)cb).close();
+        }
+        catch (RuntimeException ex) {
+            if (err == null)
+                err = ex;
+        }
+
+        if (err != null)
+            throw err;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/GridUpdateNotifier.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridUpdateNotifier.java b/modules/core/src/main/java/org/apache/ignite/internal/GridUpdateNotifier.java
index 8210025..dc22128 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridUpdateNotifier.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridUpdateNotifier.java
@@ -21,6 +21,7 @@ import org.apache.ignite.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.internal.util.worker.*;
+import org.apache.ignite.plugin.*;
 import org.jetbrains.annotations.*;
 import org.w3c.dom.*;
 import org.xml.sax.*;
@@ -28,6 +29,7 @@ import org.xml.sax.*;
 import javax.xml.parsers.*;
 import java.io.*;
 import java.net.*;
+import java.util.*;
 import java.util.concurrent.*;
 
 import static java.net.URLEncoder.*;
@@ -57,6 +59,9 @@ class GridUpdateNotifier {
     /** Latest version. */
     private volatile String latestVer;
 
+    /** Download url for latest version. */
+    private volatile String downloadUrl;
+
     /** HTML parsing helper. */
     private final DocumentBuilder documentBuilder;
 
@@ -72,6 +77,8 @@ class GridUpdateNotifier {
     /** System properties */
     private final String vmProps;
 
+    private final Map<String, String> pluginVers;
+
     /** Kernal gateway */
     private final GridKernalGateway gw;
 
@@ -83,12 +90,13 @@ class GridUpdateNotifier {
      *
      * @param gridName gridName
      * @param ver Compound Ignite version.
-     * @param reportOnlyNew Whether or not to report only new version.
      * @param gw Kernal gateway.
+     * @param pluginProviders Kernal gateway.
+     * @param reportOnlyNew Whether or not to report only new version.
      * @throws IgniteCheckedException If failed.
      */
-    GridUpdateNotifier(String gridName, String ver, GridKernalGateway gw, boolean reportOnlyNew)
-        throws IgniteCheckedException {
+    GridUpdateNotifier(String gridName, String ver, GridKernalGateway gw, Collection<PluginProvider> pluginProviders,
+        boolean reportOnlyNew) throws IgniteCheckedException {
         try {
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 
@@ -108,9 +116,15 @@ class GridUpdateNotifier {
             url = "http://tiny.cc/updater/update_status_ignite.php";
 
             this.gridName = gridName == null ? "null" : gridName;
-            this.reportOnlyNew = reportOnlyNew;
             this.gw = gw;
 
+            pluginVers = U.newHashMap(pluginProviders.size());
+
+            for (PluginProvider provider : pluginProviders)
+                pluginVers.put(provider.name() + "-plugin-version", provider.version());
+
+            this.reportOnlyNew = reportOnlyNew;
+
             vmProps = getSystemProperties();
         }
         catch (ParserConfigurationException e) {
@@ -197,6 +211,9 @@ class GridUpdateNotifier {
         U.cancel(checker);
 
         String latestVer = this.latestVer;
+        String downloadUrl = this.downloadUrl;
+
+        downloadUrl = downloadUrl != null ? downloadUrl : IgniteKernal.SITE;
 
         if (latestVer != null)
             if (latestVer.equals(ver)) {
@@ -204,7 +221,7 @@ class GridUpdateNotifier {
                     throttle(log, false, "Your version is up to date.");
             }
             else
-                throttle(log, true, "New version is available at " + IgniteKernal.SITE + ": " + latestVer);
+                throttle(log, true, "New version is available at " + downloadUrl + ": " + latestVer);
         else
             if (!reportOnlyNew)
                 throttle(log, false, "Update status is not available.");
@@ -262,12 +279,18 @@ class GridUpdateNotifier {
             try {
                 String stackTrace = gw != null ? gw.userStackTrace() : null;
 
+                SB plugins = new SB();
+
+                for (Map.Entry<String, String> p : pluginVers.entrySet())
+                    plugins.a("&").a(p.getKey()).a("=").a(encode(p.getValue(), CHARSET));
+
                 String postParams =
                     "gridName=" + encode(gridName, CHARSET) +
                     (!F.isEmpty(UPD_STATUS_PARAMS) ? "&" + UPD_STATUS_PARAMS : "") +
                     (topSize > 0 ? "&topSize=" + topSize : "") +
                     (!F.isEmpty(stackTrace) ? "&stackTrace=" + encode(stackTrace, CHARSET) : "") +
-                    (!F.isEmpty(vmProps) ? "&vmProps=" + encode(vmProps, CHARSET) : "");
+                    (!F.isEmpty(vmProps) ? "&vmProps=" + encode(vmProps, CHARSET) : "") +
+                    plugins.toString();
 
                 URLConnection conn = new URL(url).openConnection();
 
@@ -311,8 +334,11 @@ class GridUpdateNotifier {
                             log.debug("Failed to connect to Ignite update server. " + e.getMessage());
                     }
 
-                    if (dom != null)
+                    if (dom != null) {
                         latestVer = obtainVersionFrom(dom);
+
+                        downloadUrl = obtainDownloadUrlFrom(dom);
+                    }
                 }
             }
             catch (Exception e) {
@@ -327,7 +353,7 @@ class GridUpdateNotifier {
          * @param node W3C DOM node.
          * @return Version or {@code null} if one's not found.
          */
-        @Nullable private String obtainVersionFrom(Node node) {
+        @Nullable private String obtainMeta(String metaName, Node node) {
             assert node != null;
 
             if (node instanceof Element && "meta".equals(node.getNodeName().toLowerCase())) {
@@ -335,7 +361,7 @@ class GridUpdateNotifier {
 
                 String name = meta.getAttribute("name");
 
-                if (("version").equals(name)) {
+                if (metaName.equals(name)) {
                     String content = meta.getAttribute("content");
 
                     if (content != null && !content.isEmpty())
@@ -346,7 +372,7 @@ class GridUpdateNotifier {
             NodeList childNodes = node.getChildNodes();
 
             for (int i = 0; i < childNodes.getLength(); i++) {
-                String ver = obtainVersionFrom(childNodes.item(i));
+                String ver = obtainMeta(metaName, childNodes.item(i));
 
                 if (ver != null)
                     return ver;
@@ -354,5 +380,25 @@ class GridUpdateNotifier {
 
             return null;
         }
+
+        /**
+         * Gets the version from the current {@code node}, if one exists.
+         *
+         * @param node W3C DOM node.
+         * @return Version or {@code null} if one's not found.
+         */
+        @Nullable private String obtainVersionFrom(Node node) {
+            return obtainMeta("version", node);
+        }
+
+        /**
+         * Gets the download url from the current {@code node}, if one exists.
+         *
+         * @param node W3C DOM node.
+         * @return download url or {@code null} if one's not found.
+         */
+        @Nullable private String obtainDownloadUrlFrom(Node node) {
+            return obtainMeta("downloadUrl", node);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
index 6ed8a63..4b937b1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
@@ -18,6 +18,8 @@
 package org.apache.ignite.internal;
 
 import org.apache.ignite.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.jetbrains.annotations.*;
 
 import java.lang.reflect.*;
@@ -58,7 +60,8 @@ public enum IgniteComponentType {
     INDEXING(
         null,
         "org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing",
-        "ignite-indexing"
+        "ignite-indexing",
+        "org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessageFactory"
     ),
 
     /** Nodes starting using SSH. */
@@ -91,6 +94,9 @@ public enum IgniteComponentType {
     /** Module name. */
     private final String module;
 
+    /** Optional message factory for component. */
+    private final String msgFactoryCls;
+
     /**
      * Constructor.
      *
@@ -99,9 +105,22 @@ public enum IgniteComponentType {
      * @param module Module name.
      */
     IgniteComponentType(String noOpClsName, String clsName, String module) {
+        this(noOpClsName, clsName, module, null);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param noOpClsName Class name for no-op implementation.
+     * @param clsName Class name.
+     * @param module Module name.
+     * @param msgFactoryCls {@link MessageFactory} class for the component.
+     */
+    IgniteComponentType(String noOpClsName, String clsName, String module, String msgFactoryCls) {
         this.noOpClsName = noOpClsName;
         this.clsName = clsName;
         this.module = module;
+        this.msgFactoryCls = msgFactoryCls;
     }
 
     /**
@@ -273,6 +292,21 @@ public enum IgniteComponentType {
     }
 
     /**
+     * Creates message factory for the component.
+     *
+     * @return Message factory or {@code null} if none or the component is not in classpath.
+     * @throws IgniteCheckedException If failed.
+     */
+    @Nullable public MessageFactory messageFactory() throws IgniteCheckedException {
+        Class<?> cls;
+
+        if (msgFactoryCls == null || null == (cls = U.classForName(msgFactoryCls, null)))
+            return null;
+
+        return (MessageFactory)U.newInstance(cls);
+    }
+
+    /**
      * @param err Creation error.
      * @return Component creation exception.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index d9d0e3d..c4b93b8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -118,7 +118,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
     @GridToStringExclude
     private GridKernalContextImpl ctx;
 
-    /** */
+    /** Configuration. */
     private IgniteConfiguration cfg;
 
     /** */
@@ -221,7 +221,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
 
     /** {@inheritDoc} */
     @Override public IgniteCompute compute() {
-        return ctx.cluster().get().compute();
+        return ((ClusterGroupAdapter)ctx.cluster().get().forServers()).compute();
     }
 
     /** {@inheritDoc} */
@@ -236,7 +236,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
 
     /** {@inheritDoc} */
     @Override public IgniteServices services() {
-        return ctx.cluster().get().services();
+        return ((ClusterGroupAdapter)ctx.cluster().get().forServers()).services();
     }
 
     /** {@inheritDoc} */
@@ -611,22 +611,6 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
 
         boolean notifyEnabled = IgniteSystemProperties.getBoolean(IGNITE_UPDATE_NOTIFIER, true);
 
-        verChecker = null;
-
-        if (notifyEnabled) {
-            try {
-                verChecker = new GridUpdateNotifier(gridName, VER_STR, gw, false);
-
-                verChecker.checkForNewVersion(execSvc, log);
-            }
-            catch (IgniteCheckedException e) {
-                if (log.isDebugEnabled())
-                    log.debug("Failed to create GridUpdateNotifier: " + e);
-            }
-        }
-
-        final GridUpdateNotifier verChecker0 = verChecker;
-
         // Ack 3-rd party licenses location.
         if (log.isInfoEnabled() && cfg.getIgniteHome() != null)
             log.info("3-rd party licenses can be found at: " + cfg.getIgniteHome() + File.separatorChar + "libs" +
@@ -696,6 +680,45 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
 
             startProcessor(new IgnitePluginProcessor(ctx, cfg));
 
+            verChecker = null;
+
+            if (notifyEnabled) {
+                try {
+                    verChecker = new GridUpdateNotifier(gridName, VER_STR, gw, ctx.plugins().allProviders(), false);
+
+                    updateNtfTimer = new Timer("ignite-update-notifier-timer");
+
+                    // Setup periodic version check.
+                    updateNtfTimer.scheduleAtFixedRate(new GridTimerTask() {
+                        private boolean first = true;
+
+                        @Override public void safeRun() throws InterruptedException {
+                            if (!first)
+                                verChecker.topologySize(cluster().nodes().size());
+
+                            verChecker.checkForNewVersion(execSvc, log);
+
+                            // Just wait for 10 secs.
+                            Thread.sleep(PERIODIC_VER_CHECK_CONN_TIMEOUT);
+
+                            // Report status if one is available.
+                            // No-op if status is NOT available.
+                            verChecker.reportStatus(log);
+
+                            if (first) {
+                                first = false;
+
+                                verChecker.reportOnlyNew(true);
+                            }
+                        }
+                    }, 0, PERIODIC_VER_CHECK_DELAY);
+                }
+                catch (IgniteCheckedException e) {
+                    if (log.isDebugEnabled())
+                        log.debug("Failed to create GridUpdateNotifier: " + e);
+                }
+            }
+
             // Off-heap processor has no dependencies.
             startProcessor(new GridOffHeapProcessor(ctx));
 
@@ -836,34 +859,6 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
         // Mark start timestamp.
         startTime = U.currentTimeMillis();
 
-        // Ack latest version information.
-        if (verChecker0 != null)
-            verChecker0.reportStatus(log);
-
-        if (notifyEnabled) {
-            assert verChecker0 != null;
-
-            verChecker0.reportOnlyNew(true);
-
-            updateNtfTimer = new Timer("ignite-update-notifier-timer");
-
-            // Setup periodic version check.
-            updateNtfTimer.scheduleAtFixedRate(new GridTimerTask() {
-                @Override public void safeRun() throws InterruptedException {
-                    verChecker0.topologySize(cluster().nodes().size());
-
-                    verChecker0.checkForNewVersion(execSvc, log);
-
-                    // Just wait for 10 secs.
-                    Thread.sleep(PERIODIC_VER_CHECK_CONN_TIMEOUT);
-
-                    // Report status if one is available.
-                    // No-op if status is NOT available.
-                    verChecker0.reportStatus(log);
-                }
-            }, PERIODIC_VER_CHECK_DELAY, PERIODIC_VER_CHECK_DELAY);
-        }
-
         String intervalStr = IgniteSystemProperties.getString(IGNITE_STARVATION_CHECK_INTERVAL);
 
         // Start starvation checker if enabled.
@@ -2302,7 +2297,8 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
         guard();
 
         try {
-            ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), null, false).get();
+            if (ctx.cache().cache(cacheCfg.getName()) == null)
+                ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), null, false).get();
 
             return ctx.cache().publicJCache(cacheCfg.getName());
         }
@@ -2346,7 +2342,14 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
         guard();
 
         try {
-            ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), nearCfg, false).get();
+            IgniteInternalCache<Object, Object> cache = ctx.cache().cache(cacheCfg.getName());
+
+            if (cache == null)
+                ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), nearCfg, false).get();
+            else {
+                if (cache.configuration().getNearConfiguration() == null)
+                    ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), nearCfg, false).get();
+            }
 
             return ctx.cache().publicJCache(cacheCfg.getName());
         }
@@ -2385,7 +2388,14 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
         guard();
 
         try {
-            ctx.cache().dynamicStartCache(null, cacheName, nearCfg, false).get();
+            IgniteInternalCache<Object, Object> internalCache = ctx.cache().cache(cacheName);
+
+            if (internalCache == null)
+                ctx.cache().dynamicStartCache(null, cacheName, nearCfg, false).get();
+            else {
+                if (internalCache.configuration().getNearConfiguration() == null)
+                    ctx.cache().dynamicStartCache(null, cacheName, nearCfg, false).get();
+            }
 
             return ctx.cache().publicJCache(cacheName);
         }
@@ -2423,7 +2433,8 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
         guard();
 
         try {
-            ctx.cache().getOrCreateFromTemplate(cacheName).get();
+            if (ctx.cache().cache(cacheName) == null)
+                ctx.cache().getOrCreateFromTemplate(cacheName).get();
 
             return ctx.cache().publicJCache(cacheName);
         }


[12/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
index c86c5a4..6f544e0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
@@ -20,10 +20,8 @@ package org.apache.ignite.internal.util.lang;
 import org.apache.ignite.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.compute.*;
-import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.util.*;
-import org.apache.ignite.internal.util.future.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
@@ -31,9 +29,6 @@ import org.jetbrains.annotations.*;
 import org.jsr166.*;
 
 import javax.cache.*;
-import java.io.*;
-import java.lang.reflect.*;
-import java.math.*;
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
@@ -74,13 +69,6 @@ public class GridFunc {
     };
 
     /** */
-    private static final IgnitePredicate<Boolean> IDENTITY_PRED = new P1<Boolean>() {
-        @Override public boolean apply(Boolean e) {
-            return e;
-        }
-    };
-
-    /** */
     private static final IgnitePredicate<Object> ALWAYS_TRUE = new P1<Object>() {
         @Override public boolean apply(Object e) {
             return true;
@@ -128,34 +116,6 @@ public class GridFunc {
     };
 
     /** */
-    public static final IgnitePredicate<String> EMPTY_STRING = new P1<String>() {
-        @Override public boolean apply(String s) {
-            return isEmpty(s);
-        }
-    };
-
-    /** */
-    public static final IgnitePredicate<String> NOT_EMPTY_STRING = new P1<String>() {
-        @Override public boolean apply(String s) {
-            return !isEmpty(s);
-        }
-    };
-
-    /** */
-    public static final IgnitePredicate EMPTY_COLLECTION = new P1<Collection>() {
-        @Override public boolean apply(Collection c) {
-            return isEmpty(c);
-        }
-    };
-
-    /** */
-    public static final IgnitePredicate NOT_EMPTY_COLLECTION = new P1<Collection>() {
-        @Override public boolean apply(Collection c) {
-            return !isEmpty(c);
-        }
-    };
-
-    /** */
     private static final IgniteCallable<?> LIST_FACTORY = new IgniteCallable<List>() {
         @Override public List call() {
             return new ArrayList();
@@ -266,84 +226,6 @@ public class GridFunc {
     };
 
     /** */
-    private static final IgniteInClosure<?> PRINTLN = new CI1() {
-        @Override public void apply(Object o) {
-            System.out.println(o);
-        }
-
-        @Override public String toString() {
-            return "Print line closure.";
-        }
-    };
-
-    /** */
-    private static final IgniteInClosure<?> PRINT = new CI1() {
-        @Override public void apply(Object o) {
-            System.out.print(o);
-        }
-
-        @Override public String toString() {
-            return "Print closure.";
-        }
-    };
-
-    /** */
-    private static final IgniteOutClosure<?> NILL = new CO() {
-        @Nullable @Override public Object apply() {
-            return null;
-        }
-
-        @Override public String toString() {
-            return "Nill closure.";
-        }
-    };
-
-    /** */
-    private static final IgniteClosure<Runnable, GridAbsClosure> R2C = new C1<Runnable, GridAbsClosure>() {
-        @Override public GridAbsClosure apply(Runnable r) {
-            return as(r);
-        }
-
-        @Override public String toString() {
-            return "Runnable to absolute closure transformer.";
-        }
-    };
-
-    /** */
-    private static final IgniteClosure<ClusterGroup, IgnitePredicate<ClusterNode>> P2P =
-        new C1<ClusterGroup, IgnitePredicate<ClusterNode>>() {
-            @Override public IgnitePredicate<ClusterNode> apply(ClusterGroup e) {
-                return e.predicate();
-            }
-
-            @Override public String toString() {
-                return "Projection to its predicate transformer closure.";
-            }
-    };
-
-    /** */
-    private static final IgniteClosure<Object, Class<?>> CLAZZ = new C1<Object, Class<?>>() {
-        @Override public Class<?> apply(Object o) {
-            return o.getClass();
-        }
-
-        @Override public String toString() {
-            return "Object to class transformer closure.";
-        }
-    };
-
-    /** */
-    private static final IgniteClosure MAP_ENTRY_KEY = new IgniteClosure() {
-        @Override public Object apply(Object o) {
-            return ((Map.Entry)o).getKey();
-        }
-
-        @Override public String toString() {
-            return "Map entry to key transformer closure.";
-        }
-    };
-
-    /** */
     private static final IgniteClosure CACHE_ENTRY_KEY = new IgniteClosure() {
         @Override public Object apply(Object o) {
             return ((Cache.Entry)o).getKey();
@@ -354,16 +236,6 @@ public class GridFunc {
         }
     };
 
-    /** */
-    private static final IgniteClosure MAP_ENTRY_VAL = new IgniteClosure() {
-        @Override public Object apply(Object o) {
-            return ((Map.Entry)o).getValue();
-        }
-
-        @Override public String toString() {
-            return "Map entry to value transformer closure.";
-        }
-    };
 
     /** */
     private static final IgniteClosure CACHE_ENTRY_VAL_GET = new IgniteClosure() {
@@ -390,18 +262,6 @@ public class GridFunc {
     };
 
     /** */
-    private static final IgnitePredicate CACHE_ENTRY_NO_PEEK_VAL = new IgnitePredicate() {
-        @SuppressWarnings({"unchecked"})
-        @Override public boolean apply(Object o) {
-            return ((Cache.Entry)o).getValue() == null;
-        }
-
-        @Override public String toString() {
-            return "Cache entry no-peek-value predicate.";
-        }
-    };
-
-    /** */
     private static final IgniteClosure<ClusterNode, UUID> NODE2ID = new IgniteClosure<ClusterNode, UUID>() {
         @Override public UUID apply(ClusterNode n) {
             return n.id();
@@ -442,44 +302,6 @@ public class GridFunc {
     };
 
     /**
-     * Gets breaker predicate which will return a predicate that will
-     * evaluate to {@code firstVal} when checked the first time,
-     * but then will always evaluate to the opposite value.
-     *
-     * @param firstVal First value.
-     * @param <T> Predicate type.
-     * @return Breaker predicate.
-     */
-    public static <T> IgnitePredicate<T> breaker(final boolean firstVal) {
-        return new IgnitePredicate<T>() {
-            private boolean b = true;
-
-            @Override public boolean apply(T e) {
-                if (b) {
-                    b = false;
-
-                    return firstVal;
-                }
-
-                return !firstVal;
-            }
-
-            @Override public String toString() {
-                return "Breaker predicate.";
-            }
-        };
-    }
-
-    /**
-     * Gets closure that transform a grid projection into its predicate.
-     *
-     * @return Closure transforming a grid projection into its predicate.
-     */
-    public static IgniteClosure<ClusterGroup, IgnitePredicate<ClusterNode>> predicate() {
-        return P2P;
-    }
-
-    /**
      * Gets predicate that evaluates to {@code true} only for given local node ID.
      *
      * @param locNodeId Local node ID.
@@ -510,4868 +332,2608 @@ public class GridFunc {
     }
 
     /**
-     * Returns out closure that always returns {@code null}.
-     *
-     * @return Out closure that always returns {@code null}.
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> IgniteOutClosure<T> nill() {
-        return (IgniteOutClosure<T>)NILL;
-    }
-
-    /**
-     * Creates closure that will reflectively call a method with the given name on
-     * closure's argument and return result of that call.
-     * <p>
-     * Method reflects the typedef for {@link org.apache.ignite.lang.IgniteClosure} which is {@link C1}.
+     * Creates new collection by removing duplicates from the given collection.
      *
-     * @param mtdName Method name.
-     * @param args Optional set of arguments for the method call.
-     * @param <R> Type of closure return value.
-     * @param <T> Type of closure argument.
-     * @return Reflective closure.
-     * @throws GridClosureException Thrown in case of any reflective invocation errors.
+     * @param c Collection to remove duplicates from.
+     * @param <T> Type of the collection.
+     * @return De-duped collection.
      */
-    public static <T, R> IgniteClosure<T, R> cInvoke(final String mtdName, final Object... args) {
-        A.notNull(mtdName, "mtdName");
-
-        return new C1<T, R>() {
-            private Method mtd;
+    public static <T> Collection<T> dedup(Collection<? extends T> c) {
+        A.notNull(c, "c");
 
-            @SuppressWarnings("unchecked")
-            @Override public R apply(T t) {
-                try {
-                    // No synchronization allows for double creation - ignoring...
-                    if (mtd == null) {
-                        mtd = method(t.getClass(), mtdName, args);
+        Collection<T> set = new GridLeanSet<>();
 
-                        mtd.setAccessible(true);
-                    }
+        set.addAll(c);
 
-                    return (R)mtd.invoke(t, args);
-                }
-                catch (Exception e) {
-                    throw wrap(e);
-                }
-            }
-        };
+        return set;
     }
 
     /**
-     * Creates in closure that will reflectively call a method with the given name on
-     * closure's argument.
+     * Calculates sum of all elements.
      * <p>
-     * Method reflects the typedef for {@link org.apache.ignite.lang.IgniteClosure} which is {@link C1}.
+     * <img src="{@docRoot}/img/sum.png">
      *
-     * @param mtdName Method name.
-     * @param args Optional set of arguments for the method call.
-     * @param <T> Type of closure argument.
-     * @return Reflective in closure.
-     * @throws GridClosureException Thrown in case of any reflective invocation errors.
+     * @param c Collection of elements.
+     * @return Sum of all elements.
      */
-    public static <T> IgniteInClosure<T> ciInvoke(final String mtdName, final Object... args) {
-        A.notNull(mtdName, "mtdName");
-
-        return new CI1<T>() {
-            private Method mtd;
+    public static int sumInt(Iterable<Integer> c) {
+        A.notNull(c, "c");
 
-            @Override public void apply(T t) {
-                try {
-                    // No synchronization allows for double creation - ignoring...
-                    if (mtd == null) {
-                        mtd = method(t.getClass(), mtdName, args);
+        int sum = 0;
 
-                        mtd.setAccessible(true);
-                    }
+        for (int t : c)
+            sum += t;
 
-                    mtd.invoke(t, args);
-                }
-                catch (Exception e) {
-                    throw wrap(e);
-                }
-            }
-        };
+        return sum;
     }
 
     /**
-     * Creates out closure that will reflectively call a method with the given name on provided
-     * object and return result of that call.
-     * <p>
-     * Method reflects the typedef for {@link org.apache.ignite.lang.IgniteOutClosure} which is {@link CO}.
+     * Gets reducer which always returns {@code true} from {@link org.apache.ignite.lang.IgniteReducer#collect(Object)}
+     * method and passed in {@code element} from {@link org.apache.ignite.lang.IgniteReducer#reduce()} method.
      *
-     * @param o Target object to call the method on.
-     * @param mtdName Method name.
-     * @param args Optional set of arguments for the method call.
-     * @param <R> Type of closure return value.
-     * @return Reflective out closure.
-     * @throws GridClosureException Thrown in case of any reflective invocation errors.
+     * @param elem Element to return from {@link org.apache.ignite.lang.IgniteReducer#reduce()} method.
+     * @param <T> Reducer element type.
+     * @return Passed in element.
      */
-    public static <R> IgniteOutClosure<R> coInvoke(final Object o, final String mtdName, final Object... args) {
-        A.notNull(o, "o", mtdName, "mtdName");
-
-        return new CO<R>() {
-            private Method mtd;
-
-            @SuppressWarnings("unchecked")
-            @Override public R apply() {
-                try {
-                    // No synchronization allows for double creation - ignoring...
-                    if (mtd == null) {
-                        mtd = method(o.getClass(), mtdName, args);
-
-                        mtd.setAccessible(true);
-                    }
+    public static <T> IgniteReducer<T, T> identityReducer(final T elem) {
+        return new R1<T, T>() {
+            @Override public boolean collect(T e) {
+                return true;
+            }
 
-                    return (R)mtd.invoke(o, args);
-                }
-                catch (Exception e) {
-                    throw wrap(e);
-                }
+            @Override public T reduce() {
+                return elem;
             }
         };
     }
 
     /**
-     * Creates absolute closure that will reflectively call a method with the given name on provided object.
+     * Gets reducer closure that calculates sum of integer elements.
      * <p>
-     * Method reflects the typedef for {@link GridAbsClosure} which is {@link CA}.
+     * <img src="{@docRoot}/img/sum.png">
      *
-     * @param o Target object to call the method on.
-     * @param mtdName Method name.
-     * @param args Optional set of arguments for the method call.
-     * @return Reflective absolute closure.
-     * @throws GridClosureException Thrown in case of any reflective invocation errors.
+     * @return Reducer that calculates sum of integer elements.
      */
-    public static GridAbsClosure caInvoke(final Object o, final String mtdName, @Nullable final Object... args) {
-        A.notNull(o, "o", mtdName, "mtdName");
-
-        return new CA() {
-            /** */
-            private Method mtd;
+    public static IgniteReducer<Integer, Integer> sumIntReducer() {
+        return new R1<Integer, Integer>() {
+            private AtomicInteger sum = new AtomicInteger(0);
 
-            @SuppressWarnings("unchecked")
-            @Override public void apply() {
-                try {
-                    // No synchronization allows for double creation - ignoring...
-                    if (mtd == null) {
-                        mtd = method(o.getClass(), mtdName, args);
+            @Override public boolean collect(Integer e) {
+                if (e != null)
+                    sum.addAndGet(e);
 
-                        mtd.setAccessible(true);
-                    }
+                return true;
+            }
 
-                    mtd.invoke(o, args);
-                }
-                catch (Exception e) {
-                    throw wrap(e);
-                }
+            @Override public Integer reduce() {
+                return sum.get();
             }
         };
     }
 
     /**
-     * Creates out closure that will reflectively call a static method with the given name
-     * and return result of that call.
+     * Gets reducer closure that calculates sum of long integer elements.
      * <p>
-     * Method reflects the typedef for {@link org.apache.ignite.lang.IgniteOutClosure} which is {@link CO}.
+     * <img src="{@docRoot}/img/sum.png">
      *
-     * @param cls Class to call a static method on.
-     * @param mtdName Method name.
-     * @param args Optional set of arguments for the method call.
-     * @param <R> Type of closure return value.
-     * @return Reflective out closure.
-     * @throws GridClosureException Thrown in case of any reflective invocation errors.
+     * @return Reducer that calculates sum of long integer elements.
      */
-    public static <R> IgniteOutClosure<R> coInvoke(final Class<?> cls, final String mtdName,
-        @Nullable final Object... args) {
-        A.notNull(cls, "cls", mtdName, "mtdName");
-
-        return new CO<R>() {
-            /** */
-            private Method mtd;
+    public static IgniteReducer<Long, Long> sumLongReducer() {
+        return new R1<Long, Long>() {
+            private AtomicLong sum = new AtomicLong(0);
 
-            @SuppressWarnings("unchecked")
-            @Override public R apply() {
-                try {
-                    // No synchronization allows for double creation - ignoring...
-                    if (mtd == null) {
-                        mtd = method(cls, mtdName, args);
+            @Override public boolean collect(Long e) {
+                if (e != null)
+                    sum.addAndGet(e);
 
-                        mtd.setAccessible(true);
-                    }
+                return true;
+            }
 
-                    return (R)mtd.invoke(null, args);
-                }
-                catch (Exception e) {
-                    throw wrap(e);
-                }
+            @Override public Long reduce() {
+                return sum.get();
             }
         };
     }
 
     /**
-     * Creates absolute closure that will reflectively call a static method with the given name.
-     * <p>
-     * Method reflects the typedef for {@link GridAbsClosure} which is {@link CA}.
+     * Creates a range list containing numbers in given range.
      *
-     * @param cls Class to call a static method on.
-     * @param mtdName Method name.
-     * @param args Optional set of arguments for the method call.
-     * @return Reflective absolute closure.
-     * @throws GridClosureException Thrown in case of any reflective invocation errors.
+     * @param fromIncl Inclusive start of the range.
+     * @param toExcl Exclusive stop of the range.
+     * @return List containing numbers in range.
      */
-    public static GridAbsClosure caInvoke(final Class<?> cls, final String mtdName, @Nullable final Object... args) {
-        A.notNull(cls, "cls", mtdName, "mtdName");
+    public static List<Integer> range(int fromIncl, int toExcl) {
+        A.ensure(fromIncl >= 0, "fromIncl >= 0");
+        A.ensure(toExcl >= 0, "toExcl >= 0");
+        A.ensure(toExcl >= fromIncl, "toExcl > fromIncl");
 
-        return new CA() {
-            /** */
-            private Method mtd;
+        if (toExcl == fromIncl)
+            return Collections.emptyList();
 
-            @SuppressWarnings("unchecked")
-            @Override public void apply() {
-                try {
-                    // No synchronization allows for double creation - ignoring...
-                    if (mtd == null) {
-                        mtd = method(cls, mtdName, args);
+        List<Integer> list = new ArrayList<>(toExcl - fromIncl);
 
-                        mtd.setAccessible(true);
-                    }
+        for (int i = fromIncl; i < toExcl; i++)
+            list.add(i);
 
-                    mtd.invoke(null, args);
-                }
-                catch (Exception e) {
-                    throw wrap(e);
-                }
-            }
-        };
+        return list;
     }
 
     /**
-     * Looks up the method with given parameters.
+     * Gets reducer closure that concatenates strings using provided delimiter.
      *
-     * @param cls Class to look up in.
-     * @param mtdName Method name to look up.
-     * @param args Optional set of method parameters.
-     * @return Method instance.
-     * @throws Exception Thrown in case of any reflective errors.
+     * @param delim Delimiter (optional).
+     * @return Reducer that concatenates strings using provided delimeter.
      */
-    private static Method method(Class<?> cls, String mtdName, @Nullable Object... args) throws Exception {
-        assert cls != null;
-        assert mtdName != null;
-
-        int cnt = 0;
-
-        Method m = null;
-
-        for (Method mtd : cls.getDeclaredMethods())
-            if (mtd.getName().equals(mtdName)) {
-                cnt++;
-
-                m = mtd;
-            }
+    public static IgniteReducer<String, String> concatReducer(@Nullable final String delim) {
+        return new R1<String, String>() {
+            private SB sb = new SB();
 
-        if (cnt == 0)
-            throw new NoSuchMethodException(cls.getName() + '#' + mtdName);
+            private boolean first = true;
 
-        // If there is only one method with provided name we
-        // don't use lookup that requires parameters' types since
-        // it is a lot more complex to deal with type inheritance there.
-        if (cnt == 1)
-            return m;
+            private final Object lock = new Object();
 
-        if (!isEmpty(args)) {
-            assert args != null;
+            @Override public boolean collect(String s) {
+                synchronized (lock) {
+                    if (!first && !isEmpty(delim))
+                        sb.a(delim);
 
-            Class<?>[] types = new Class[args.length];
+                    sb.a(s);
 
-            int i = 0;
+                    first = false;
+                }
 
-            for (Object arg : args) {
-                // This is not going to work in cases when method expects
-                // an interface or supertype. Accept this limitation for now...
-                types[i++] = arg.getClass();
+                return true;
             }
 
-            return cls.getDeclaredMethod(mtdName, types);
-        }
-        else
-            return cls.getDeclaredMethod(mtdName);
+            @Override public String reduce() {
+                synchronized (lock) {
+                    return sb.toString();
+                }
+            }
+        };
     }
 
     /**
-     * Gets closure that converts object to its runtime class.
+     * Concatenates strings using provided delimiter.
      *
-     * @return Closure that converts object to its runtime class.
-     */
-    public static IgniteClosure<Object, Class<?>> clazz() {
-        return CLAZZ;
-    }
-
-    /**
-     * Creates new collection by removing duplicates from the given collection.
-     *
-     * @param c Collection to remove duplicates from.
-     * @param <T> Type of the collection.
-     * @return De-duped collection.
+     * @param c Input collection.
+     * @param delim Delimiter (optional).
+     * @return Concatenated string.
      */
-    public static <T> Collection<T> dedup(Collection<? extends T> c) {
+    public static String concat(Iterable<String> c, @Nullable String delim) {
         A.notNull(c, "c");
 
-        Collection<T> set = new GridLeanSet<>();
-
-        set.addAll(c);
-
-        return set;
+        return reduce(c, concatReducer(delim));
     }
 
     /**
-     * Calculates sum of all elements.
+     * Gets collections of data items from grid job res casted to specified type.
      * <p>
-     * <img src="{@docRoot}/img/sum.png">
-     *
-     * @param c Collection of elements.
-     * @return Sum of all elements.
-     */
-    public static int sumInt(Iterable<Integer> c) {
-        A.notNull(c, "c");
-
-        int sum = 0;
-
-        for (int t : c) {
-            sum += t;
-        }
-
-        return sum;
-    }
-
-    /**
-     * Calculates sum of all elements.
+     * Here's the typical example of how this method is used in {@code reduce()} method
+     * implementation (this example sums up all the values of {@code Integer} type):
+     * <pre name="code" class="java">
+     * public Integer reduce(List&lt;GridComputeJobResult&gt; res) throws IgniteCheckedException {
+     *     return F.sum(F.&lt;Integer&gt;jobResults(res));
+     * }
+     * </pre>
      * <p>
-     * <img src="{@docRoot}/img/sum.png">
+     * Note that this method doesn't create a new collection but simply iterates over the input one.
      *
-     * @param c Collection of elements.
-     * @return Sum of all elements.
+     * @param res Collection of grid job res.
+     * @param <T> Type of the data item to cast to. See {@link org.apache.ignite.compute.ComputeJobResult#getData()} method.
+     * @return Collections of data items casted to type {@code T}.
+     * @see org.apache.ignite.compute.ComputeJobResult#getData()
      */
-    public static double sumDouble(Iterable<Double> c) {
-        A.notNull(c, "c");
+    public static <T> Collection<T> jobResults(@Nullable Collection<? extends ComputeJobResult> res) {
+        if (isEmpty(res))
+            return Collections.emptyList();
 
-        double sum = 0;
+        assert res != null;
 
-        for (double t : c) {
-            sum += t;
-        }
+        Collection<T> c = new ArrayList<>(res.size());
 
-        return sum;
+        for (ComputeJobResult r : res)
+            c.add(r.<T>getData());
+
+        return c;
     }
 
     /**
-     * Calculates sum of all elements.
+     * Convenient utility method that returns collection of node IDs for a given
+     * collection of grid nodes.
      * <p>
-     * <img src="{@docRoot}/img/sum.png">
+     * Note that this method doesn't create a new collection but simply iterates
+     * over the input one.
      *
-     * @param c Collection of elements.
-     * @return Sum of all elements.
+     * @param nodes Collection of grid nodes.
+     * @return Collection of node IDs for given collection of grid nodes.
      */
-    public static BigDecimal sumBigDecimal(Iterable<BigDecimal> c) {
-        A.notNull(c, "c");
-
-        BigDecimal sum = BigDecimal.ZERO;
-
-        for (BigDecimal t : c) {
-            sum = sum.add(t);
-        }
+    public static Collection<UUID> nodeIds(@Nullable Collection<? extends ClusterNode> nodes) {
+        if (nodes == null || nodes.isEmpty())
+            return Collections.emptyList();
 
-        return sum;
+        return F.viewReadOnly(nodes, node2id());
     }
 
     /**
-     * Calculates sum of all elements.
+     * Convenient utility method that returns collection of node ID8s for a given
+     * collection of grid nodes. ID8 is a shorter string representation of node ID,
+     * mainly the first 8 characters.
      * <p>
-     * <img src="{@docRoot}/img/sum.png">
+     * Note that this method doesn't create a new collection but simply iterates
+     * over the input one.
      *
-     * @param c Collection of elements.
-     * @return Sum of all elements.
+     * @param nodes Collection of grid nodes.
+     * @return Collection of node IDs for given collection of grid nodes.
      */
-    public static BigInteger sumBigInt(Iterable<BigInteger> c) {
-        A.notNull(c, "c");
-
-        BigInteger sum = BigInteger.ZERO;
-
-        for (BigInteger t : c) {
-            sum = sum.add(t);
-        }
+    public static Collection<String> nodeId8s(@Nullable Collection<? extends ClusterNode> nodes) {
+        if (nodes == null || nodes.isEmpty())
+            return Collections.emptyList();
 
-        return sum;
+        return F.viewReadOnly(nodes, NODE2ID8);
     }
 
     /**
-     * Calculates arithmetic mean.
+     * Convenient utility method that returns collection of node ID8s for a given
+     * collection of node IDs. ID8 is a shorter string representation of node ID,
+     * mainly the first 8 characters.
      * <p>
-     * <img src="{@docRoot}/img/avg.png">
+     * Note that this method doesn't create a new collection but simply iterates
+     * over the input one.
      *
-     * @param c Input collection.
-     * @return Arithmetic mean of the input collection.
+     * @param ids Collection of nodeIds.
+     * @return Collection of node IDs for given collection of grid nodes.
      */
-    public static double avg(Iterable<? extends Number> c) {
-        A.notNull(c, "c");
-
-        double sum = 0;
-
-        int i = 0;
-
-        for (Number t : c) {
-            sum += t.doubleValue();
-
-            i++;
-        }
+    public static Collection<String> id8s(@Nullable Collection<UUID> ids) {
+        if (ids == null || ids.isEmpty())
+            return Collections.emptyList();
 
-        return sum / i;
+        return F.viewReadOnly(ids, ID2ID8);
     }
 
     /**
-     * Gets reducer closure that calculates arithmetic mean.
-     * <p>
-     * <img src="{@docRoot}/img/avg.png">
+     * Creates absolute closure that does <tt>System.out.println(msg)</tt>.
      *
-     * @return Reducer closure that calculated arithmetic mean.
+     * @param msg Message to print.
+     * @return Absolute closure that print message.
      */
-    public static <T extends Number> IgniteReducer<T, Double> avgReducer() {
-        return new R1<T, Double>() {
-            private double sum;
-            private int i;
-
-            private final Object lock = new Object();
-
-            @Override public boolean collect(T e) {
-                if (e != null)
-                    synchronized (lock) {
-                        sum += e.doubleValue();
-                        i++;
-                    }
-
-                return true;
-            }
-
-            @Override public Double reduce() {
-                synchronized (lock) {
-                    return sum / i;
-                }
+    public static GridAbsClosure println(final String msg) {
+        return new CA() {
+            @Override public void apply() {
+                System.out.println(msg);
             }
         };
     }
 
     /**
-     * Calculates quadratic mean.
-     * <p>
-     * <img src="{@docRoot}/img/qavg.png">
+     * Gets random value from given collection.
      *
-     * @param c Input collection.
-     * @return Quadratic mean of the input collection.
+     * @param c Input collection (no {@code null} and not emtpy).
+     * @param <T> Type of the collection.
+     * @return Random value from the input collection.
      */
-    public static double qavg(Iterable<? extends Number> c) {
+    @SuppressWarnings("UnusedDeclaration")
+    public static <T> T rand(Collection<? extends T> c) {
         A.notNull(c, "c");
 
-        double sum = 0;
+        int n = ThreadLocalRandom8.current().nextInt(c.size());
 
         int i = 0;
 
-        for (Number t : c) {
-            double d = t.doubleValue();
-
-            sum += d * d;
-
-            i++;
+        for (T t : c) {
+            if (i++ == n)
+                return t;
         }
 
-        return Math.sqrt(sum / i);
+        throw new ConcurrentModificationException();
     }
 
     /**
-     * Gets reducer closure that calculates quadratic mean.
-     * <p>
-     * <img src="{@docRoot}/img/qavg.png">
+     * Gets random value from given list. For random-access lists this
+     * operation is O(1), otherwise O(n).
      *
-     * @return Reducer closure that calculated quadratic mean.
+     * @param l Input collection.
+     * @param <T> Type of the list elements.
+     * @return Random value from the input list.
      */
-    public static <T extends Number> IgniteReducer<T, Double> qavgReducer() {
-        return new R1<T, Double>() {
-            private double sum;
-            private int i;
-
-            private final Object lock = new Object();
-
-            @Override public boolean collect(T e) {
-                if (e != null) {
-                    double d = e.doubleValue();
-
-                    synchronized (lock) {
-                        sum += d * d;
-
-                        i++;
-                    }
-                }
-
-                return true;
-            }
+    public static <T> T rand(List<T> l) {
+        A.notNull(l, "l");
 
-            @Override public Double reduce() {
-                synchronized (lock) {
-                    return Math.sqrt(sum / i);
-                }
-            }
-        };
+        return l.get(ThreadLocalRandom8.current().nextInt(l.size()));
     }
 
     /**
-     * Calculates geometric mean.
-     * <p>
-     * <img src="{@docRoot}/img/gavg.png">
+     * Gets random value from given array. This operation
+     * does not iterate through array elements and returns immediately.
      *
      * @param c Input collection.
-     * @return Geometric mean of the input collection.
+     * @param <T> Type of the collection.
+     * @return Random value from the input collection.
      */
-    public static double gavg(Iterable<? extends Number> c) {
+    public static <T> T rand(T... c) {
         A.notNull(c, "c");
 
-        double sum = 0;
-
-        int i = 0;
-
-        for (Number t : c) {
-            sum *= t.doubleValue();
-
-            i++;
-        }
-
-        return Math.pow(sum, 1f / i);
+        return c[ThreadLocalRandom8.current().nextInt(c.length)];
     }
 
     /**
-     * Gets reducer closure that calculates geometric mean.
-     * <p>
-     * <img src="{@docRoot}/img/gavg.png">
+     * Concatenates an element to a collection. If {@code copy} flag is {@code true}, then
+     * a new collection will be created and the element and passed in collection will be
+     * copied into the new one. The returned collection will be modifiable. If {@code copy}
+     * flag is {@code false}, then a read-only view will be created over the element and given
+     * collections and no copying will happen.
      *
-     * @return Reducer closure that calculated geometric mean.
+     * @param cp Copy flag.
+     * @param t First element.
+     * @param c Second collection.
+     * @param <T> Element type.
+     * @return Concatenated collection.
      */
-    public static <T extends Number> IgniteReducer<T, Double> gavgReducer() {
-        return new R1<T, Double>() {
-            private double sum;
-            private int i;
+    public static <T> Collection<T> concat(boolean cp, @Nullable final T t, @Nullable final Collection<T> c) {
+        if (cp) {
+            if (isEmpty(c)) {
+                Collection<T> l = new ArrayList<>(1);
 
-            private final Object lock = new Object();
+                l.add(t);
 
-            @Override public boolean collect(T e) {
-                if (e != null)
-                    synchronized (lock) {
-                        sum *= e.doubleValue();
+                return l;
+            }
 
-                        i++;
-                    }
+            assert c != null;
 
-                return true;
-            }
+            Collection<T> ret = new ArrayList<>(c.size() + 1);
 
-            @Override public Double reduce() {
-                synchronized (lock) {
-                    return Math.pow(sum, 1f / i);
-                }
-            }
-        };
-    }
+            ret.add(t);
+            ret.addAll(c);
 
-    /**
-     * Calculates weighted mean.
-     * <p>
-     * <img src="{@docRoot}/img/wavg.png">
-     *
-     * @param c Collection of elements.
-     * @param w Collection of weights.
-     * @return Weighted mean of the input collection.
-     */
-    public static double wavg(Collection<? extends Number> c, Collection<? extends Number> w) {
-        A.notNull(c, "c", w, "w");
-        A.ensure(c.size() == w.size(), "c.size() == w.size()");
+            return ret;
+        }
+        else {
+            if (isEmpty(c))
+                return Collections.singletonList(t);
 
-        double sumC = 0;
-        double sumW = 0;
+            assert c != null;
 
-        Iterator<? extends Number> iterC = c.iterator();
-        Iterator<? extends Number> iterW = w.iterator();
+            return new GridSerializableCollection<T>() {
+                @NotNull
+                @Override public Iterator<T> iterator() {
+                    return new GridSerializableIterator<T>() {
+                        private Iterator<T> it;
 
-        while (iterC.hasNext()) {
-            assert iterW.hasNext();
+                        @Override public boolean hasNext() {
+                            return it == null || it.hasNext();
+                        }
 
-            double dc = iterC.next().doubleValue();
-            double dw = iterW.next().doubleValue();
+                        @Nullable @Override public T next() {
+                            if (it == null) {
+                                it = c.iterator();
 
-            sumW += dw;
-            sumC += dw * dc;
-        }
+                                return t;
+                            }
 
-        return sumC / sumW;
-    }
+                            return it.next();
+                        }
 
-    /**
-     * Calculates harmonic mean.
-     * <p>
-     * <img src="{@docRoot}/img/havg.png">
+                        @Override public void remove() {
+                            throw new UnsupportedOperationException();
+                        }
+                    };
+                }
+
+                @Override public int size() {
+                    return c.size() + 1;
+                }
+
+                @Override public boolean equals(Object obj) {
+                    return obj instanceof Collection && eqNotOrdered(this, (Collection)obj);
+                }
+            };
+        }
+    }
+
+    /**
+     * Concatenates 2 collections into one. If {@code copy} flag is {@code true}, then
+     * a new collection will be created and these collections will be copied into the
+     * new one. The returned collection will be modifiable. If {@code copy} flag is
+     * {@code false}, then a read-only view will be created over given collections
+     * and no copying will happen.
      *
-     * @param c Input collection.
-     * @return Harmonic mean of the input collection.
+     * @param cp Copy flag.
+     * @param c1 First collection.
+     * @param c2 Second collection.
+     * @param <T> Element type.
+     * @return Concatenated {@code non-null} collection.
      */
-    public static double havg(Iterable<? extends Number> c) {
-        A.notNull(c, "c");
+    public static <T> Collection<T> concat(boolean cp, @Nullable final Collection<T> c1,
+        @Nullable final Collection<T> c2) {
+        if (cp) {
+            if (isEmpty(c1) && isEmpty(c2))
+                return new ArrayList<>(0);
 
-        double sum = 0;
+            if (isEmpty(c1))
+                return new ArrayList<>(c2);
 
-        int i = 0;
+            if (isEmpty(c2))
+                return new ArrayList<>(c1);
 
-        for (Number t : c) {
+            Collection<T> c = new ArrayList<>(c1.size() + c2.size());
 
-            sum += 1 / t.doubleValue();
+            c.addAll(c1);
+            c.addAll(c2);
 
-            i++;
+            return c;
         }
+        else {
+            if (isEmpty(c1) && isEmpty(c2))
+                return Collections.emptyList();
 
-        return i / sum;
-    }
-
-    /**
-     * Gets reducer closure that collects only a single value and returns it
-     * without any transformations.
-     *
-     * @return Reducer closure that collects and returns single value.
-     */
-    public static <T> IgniteReducer<T, T> singleReducer() {
-        return new R1<T, T>() {
-            private T obj;
+            if (isEmpty(c1) || isEmpty(c2)) {
+                Collection<T> c = isEmpty(c1) ? c2 : c1;
 
-            @Override public boolean collect(T e) {
-                // No synchronization needed here.
-                obj = e;
+                assert c != null;
 
-                return false;
+                return c;
             }
 
-            @Override public T reduce() {
-                return obj;
-            }
-        };
+            return new GridSerializableCollection<T>() {
+                @NotNull
+                @Override public Iterator<T> iterator() {
+                    return new GridSerializableIterator<T>() {
+                        private Iterator<T> it1 = c1.iterator();
+                        private Iterator<T> it2 = c2.iterator();
+
+                        @Override public boolean hasNext() {
+                            if (it1 != null)
+                                if (!it1.hasNext())
+                                    it1 = null;
+                                else
+                                    return true;
+
+                            return it2.hasNext();
+                        }
+
+                        @Override public T next() {
+                            return it1 != null ? it1.next() : it2.next();
+                        }
+
+                        @Override public void remove() {
+                            throw new UnsupportedOperationException();
+                        }
+                    };
+                }
+
+                @Override public boolean contains(Object o) {
+                    return c1.contains(o) || c2.contains(o);
+                }
+
+                @Override public int size() {
+                    return c1.size() + c2.size();
+                }
+
+                @Override public boolean equals(Object obj) {
+                    return obj instanceof Collection && eqNotOrdered(this, (Collection<?>)obj);
+                }
+            };
+        }
     }
 
     /**
-     * Gets reducer which always returns {@code true} from {@link org.apache.ignite.lang.IgniteReducer#collect(Object)}
-     * method and passed in {@code element} from {@link org.apache.ignite.lang.IgniteReducer#reduce()} method.
+     * Concatenates an elements to an array.
      *
-     * @param elem Element to return from {@link org.apache.ignite.lang.IgniteReducer#reduce()} method.
-     * @param <T> Reducer element type.
-     * @param <R> Return element type.
-     * @return Passed in element.
+     * @param arr Array.
+     * @param obj One or more elements.
+     * @return Concatenated array.
      */
-    public static <T, R> IgniteReducer<T, R> continuousReducer(final R elem) {
-        return new R1<T, R>() {
-            @Override public boolean collect(T e) {
-                return true;
-            }
+    public static <T> T[] concat(@Nullable T[] arr, T... obj) {
+        T[] newArr;
 
-            @Override public R reduce() {
-                return elem;
-            }
-        };
+        if (arr == null || arr.length == 0)
+            newArr = obj;
+        else {
+            newArr = Arrays.copyOf(arr, arr.length + obj.length);
+
+            System.arraycopy(obj, 0, newArr, arr.length, obj.length);
+        }
+
+        return newArr;
     }
 
     /**
-     * Gets reducer which always returns {@code true} from {@link org.apache.ignite.lang.IgniteReducer#collect(Object)}
-     * method and passed in {@code element} from {@link org.apache.ignite.lang.IgniteReducer#reduce()} method.
+     * Concatenates multiple iterators as single one.
      *
-     * @param elem Element to return from {@link org.apache.ignite.lang.IgniteReducer#reduce()} method.
-     * @param <T> Reducer element type.
-     * @return Passed in element.
+     * @param iters Iterators.
+     * @return Single iterator.
      */
-    public static <T> IgniteReducer<T, T> identityReducer(final T elem) {
-        return new R1<T, T>() {
-            @Override public boolean collect(T e) {
-                return true;
-            }
+    @SuppressWarnings("unchecked")
+    public static <T> Iterator<T> concat(Iterator<T> ... iters) {
+        if (iters.length == 1)
+            return iters[0];
 
-            @Override public T reduce() {
-                return elem;
-            }
-        };
+        return concat(asList(iters).iterator());
     }
 
     /**
-     * Gets reducer closure that calculates harmonic mean.
-     * <p>
-     * <img src="{@docRoot}/img/havg.png">
+     * Concatenates multiple iterators as single one.
      *
-     * @return Reducer closure that calculated harmonic mean.
+     * @param iters Iterator over iterators.
+     * @return Single iterator.
      */
-    public static <T extends Number> IgniteReducer<T, Double> havgReducer() {
-        return new R1<T, Double>() {
-            private double sum;
-            private int i;
+    @SuppressWarnings("unchecked")
+    public static <T> Iterator<T> concat(final Iterator<Iterator<T>> iters) {
+        if (!iters.hasNext())
+            return Collections.<T>emptySet().iterator();
 
-            private final Object lock = new Object();
+        return new Iterator<T>() {
+            private Iterator<T> it = iters.next();
 
-            @Override public boolean collect(T e) {
-                if (e != null)
-                    synchronized (lock) {
-                        sum += 1 / e.doubleValue();
+            private Iterator<T> last;
 
-                        i++;
-                    }
+            private T next;
 
-                return true;
+            {
+                advance();
             }
 
-            @Override public Double reduce() {
-                synchronized (lock) {
-                    return i / sum;
-                }
-            }
-        };
-    }
+            private void advance() {
+                for (;;) {
+                    if (it.hasNext()) {
+                        next = it.next();
 
-    /**
-     * Gets reducer closure that calculates sum of integer elements.
-     * <p>
-     * <img src="{@docRoot}/img/sum.png">
-     *
-     * @return Reducer that calculates sum of integer elements.
-     */
-    public static IgniteReducer<Integer, Integer> sumIntReducer() {
-        return new R1<Integer, Integer>() {
-            private AtomicInteger sum = new AtomicInteger(0);
+                        assert next != null;
 
-            @Override public boolean collect(Integer e) {
-                if (e != null)
-                    sum.addAndGet(e);
+                        return;
+                    }
 
-                return true;
-            }
+                    if (!iters.hasNext())
+                        return;
 
-            @Override public Integer reduce() {
-                return sum.get();
+                    it = iters.next();
+                }
             }
-        };
-    }
-
-    /**
-     * Gets reducer closure that calculates sum of long integer elements.
-     * <p>
-     * <img src="{@docRoot}/img/sum.png">
-     *
-     * @return Reducer that calculates sum of long integer elements.
-     */
-    public static IgniteReducer<Long, Long> sumLongReducer() {
-        return new R1<Long, Long>() {
-            private AtomicLong sum = new AtomicLong(0);
 
-            @Override public boolean collect(Long e) {
-                if (e != null)
-                    sum.addAndGet(e);
-
-                return true;
+            @Override public boolean hasNext() {
+                return next != null;
             }
 
-            @Override public Long reduce() {
-                return sum.get();
-            }
-        };
-    }
+            @Override public T next() {
+                T res = next;
 
-    /**
-     * Gets reducer closure that calculates sum of all elements.
-     * <p>
-     * <img src="{@docRoot}/img/sum.png">
-     *
-     * @return Reducer that calculates sum of all elements.
-     */
-    @SuppressWarnings("unchecked")
-    public static IgniteReducer<Double, Double> sumDoubleReducer() {
-        return new R1<Double, Double>() {
-            private double sum;
+                if (res == null)
+                    throw new NoSuchElementException();
 
-            private final Object lock = new Object();
+                next = null;
 
-            @Override public boolean collect(Double e) {
-                if (e != null)
-                    synchronized (lock) {
-                        sum += e;
-                    }
+                last = it;
 
-                return true;
+                advance();
+
+                return res;
             }
 
-            @Override public Double reduce() {
-                synchronized (lock) {
-                    return sum;
-                }
+            @Override public void remove() {
+                if (last == null)
+                    throw new IllegalStateException();
+
+                last.remove();
             }
         };
     }
 
     /**
-     * Creates a range list containing numbers in given range.
+     * Loses all elements in input collection that are contained in {@code filter} collection.
      *
-     * @param fromIncl Inclusive start of the range.
-     * @param toExcl Exclusive stop of the range.
-     * @return List containing numbers in range.
+     * @param c Input collection.
+     * @param cp If {@code true} method creates new collection not modifying input,
+     *      otherwise does <tt>in-place</tt> modifications.
+     * @param filter Filter collection. If {@code filter} collection is empty or
+     *      {@code null} - no elements are lost.
+     * @param <T> Type of collections.
+     * @return Collection of remaining elements
      */
-    public static List<Integer> range(int fromIncl, int toExcl) {
-        A.ensure(fromIncl >= 0, "fromIncl >= 0");
-        A.ensure(toExcl >= 0, "toExcl >= 0");
-        A.ensure(toExcl >= fromIncl, "toExcl > fromIncl");
-
-        if (toExcl == fromIncl)
-            return Collections.emptyList();
-
-        List<Integer> list = new ArrayList<>(toExcl - fromIncl);
-
-        for (int i = fromIncl; i < toExcl; i++)
-            list.add(i);
+    public static <T0, T extends T0> Collection<T> lose(Collection<T> c, boolean cp,
+        @Nullable Collection<T0> filter) {
+        A.notNull(c, "c");
 
-        return list;
+        return lose(c, cp, F0.in(filter));
     }
 
     /**
-     * Gets reducer closure that calculates sum of all elements.
-     * <p>
-     * <img src="{@docRoot}/img/sum.png">
+     * Loses all elements in input collection that are evaluated to {@code true} by
+     * all given predicates.
      *
-     * @return Reducer that calculates sum of all elements.
+     * @param c Input collection.
+     * @param cp If {@code true} method creates new collection without modifying the input one,
+     *      otherwise does <tt>in-place</tt> modifications.
+     * @param p Predicates to filter by. If no predicates provided - no elements are lost.
+     * @param <T> Type of collections.
+     * @return Collection of remaining elements.
      */
-    @SuppressWarnings("unchecked")
-    public static IgniteReducer<BigDecimal, BigDecimal> sumBigDecimalReducer() {
-        return new R1<BigDecimal, BigDecimal>() {
-            private BigDecimal sum = BigDecimal.ZERO;
+    public static <T> Collection<T> lose(Collection<T> c, boolean cp, @Nullable IgnitePredicate<? super T>... p) {
+        A.notNull(c, "c");
 
-            private final Object lock = new Object();
+        Collection<T> res;
 
-            @Override public boolean collect(BigDecimal e) {
-                if (e != null)
-                    synchronized (lock) {
-                        sum = sum.add(e);
-                    }
+        if (!cp) {
+            res = c;
 
-                return true;
-            }
+            if (isEmpty(p))
+                res.clear();
+            else if (!isAlwaysFalse(p))
+                for (Iterator<T> iter = res.iterator(); iter.hasNext();)
+                    if (isAll(iter.next(), p))
+                        iter.remove();
+        }
+        else {
+            res = new LinkedList<>();
 
-            @Override public BigDecimal reduce() {
-                synchronized (lock) {
-                    return sum;
-                }
-            }
-        };
+            if (!isEmpty(p) && !isAlwaysTrue(p))
+                for (T t : c)
+                    if (!isAll(t, p))
+                        res.add(t);
+        }
+
+        return res;
     }
 
     /**
-     * Gets reducer closure that calculates sum of all elements.
-     * <p>
-     * <img src="{@docRoot}/img/sum.png">
+     * Loses all entries in input map that are evaluated to {@code true} by all given predicates.
      *
-     * @return Reducer that calculates sum of all elements.
+     * @param m Map to filter.
+     * @param cp If {@code true} method creates new map not modifying input, otherwise does
+     *      <tt>in-place</tt> modifications.
+     * @param p Optional set of predicates to use for filtration. If none provided - original map
+     *  will (or its copy) be returned.
+     * @param <K> Type of the free variable for the predicate and type of map's keys.
+     * @param <V> Type of the free variable for the predicate and type of map's values.
+     * @return Filtered map.
      */
-    @SuppressWarnings("unchecked")
-    public static IgniteReducer<BigInteger, BigInteger> sumBigIntegerReducer() {
-        return new R1<BigInteger, BigInteger>() {
-            private BigInteger sum = BigInteger.ZERO;
+    @SuppressWarnings({"unchecked"})
+    public static <K, V> Map<K, V> lose(Map<K, V> m, boolean cp,
+        @Nullable IgnitePredicate<? super Map.Entry<K, V>>... p) {
+        A.notNull(m, "m");
 
-            private final Object lock = new Object();
+        Map<K, V> res;
 
-            @Override public boolean collect(BigInteger e) {
-                if (e != null)
-                    synchronized (lock) {
-                        sum = sum.add(e);
-                    }
+        if (!cp) {
+            res = m;
 
-                return true;
-            }
+            if (isEmpty(p))
+                res.clear();
+            else if (!isAlwaysFalse(p))
+                for (Iterator<Map.Entry<K, V>> iter = m.entrySet().iterator(); iter.hasNext();)
+                    if (isAll(iter.next(), p))
+                        iter.remove();
+        }
+        else {
+            res = U.newHashMap(m.size());
 
-            @Override public BigInteger reduce() {
-                synchronized (lock) {
-                    return sum;
-                }
-            }
-        };
+            if (!isEmpty(p) && !isAlwaysTrue(p))
+                for (Map.Entry<K, V> e : m.entrySet())
+                    if (!F.isAll(e, p))
+                        res.put(e.getKey(), e.getValue());
+        }
+
+        return res;
     }
 
     /**
-     * Gets reducer closure that concatenates strings using provided delimiter.
+     * Loses all entries in input map which keys are evaluated to {@code true} by all
+     * given predicates.
      *
-     * @param delim Delimiter (optional).
-     * @return Reducer that concatenates strings using provided delimeter.
+     * @param m Map to filter.
+     * @param cp If {@code true} method creates new map not modifying input, otherwise does
+     *      <tt>in-place</tt> modifications.
+     * @param p Optional set of predicates to use for filtration. If none provided - original
+     *      map (or its copy) will be returned.
+     * @param <K> Type of the free variable for the predicate and type of map's keys.
+     * @param <V> Type of map's values.
+     * @return Filtered map.
      */
-    public static IgniteReducer<String, String> concatReducer(@Nullable final String delim) {
-        return new R1<String, String>() {
-            private SB sb = new SB();
-
-            private boolean first = true;
-
-            private final Object lock = new Object();
-
-            @Override public boolean collect(String s) {
-                synchronized (lock) {
-                    if (!first && !isEmpty(delim))
-                        sb.a(delim);
-
-                    sb.a(s);
-
-                    first = false;
-                }
-
-                return true;
-            }
-
-            @Override public String reduce() {
-                synchronized (lock) {
-                    return sb.toString();
-                }
+    public static <K, V> Map<K, V> loseKeys(
+        Map<K, V> m,
+        boolean cp,
+        @Nullable final IgnitePredicate<? super K>... p
+    ) {
+        return lose(m, cp, new P1<Map.Entry<K, V>>() {
+            @Override public boolean apply(Map.Entry<K, V> e) {
+                return isAll(e.getKey(), p);
             }
-        };
+        });
     }
 
     /**
-     * Concatenates strings using provided delimiter.
+     * Loses all entries in input map which values are evaluated to {@code true} by all
+     * given predicates.
      *
-     * @param c Input collection.
-     * @param delim Delimiter (optional).
-     * @return Concatenated string.
+     * @param m Map to filter.
+     * @param cp If {@code true} method creates new map not modifying input, otherwise does
+     *      <tt>in-place</tt> modifications.
+     * @param p Optional set of predicates to use for filtration. If none provided - original
+     *      map (or its copy) will be returned.
+     * @param <K> Type of the free variable for the predicate and type of map's keys.
+     * @param <V> Type of map's values.
+     * @return Filtered map.
      */
-    public static String concat(Iterable<String> c, @Nullable String delim) {
-        A.notNull(c, "c");
-
-        return reduce(c, concatReducer(delim));
+    public static <K, V> Map<K, V> loseValues(Map<K, V> m, boolean cp,
+        @Nullable final IgnitePredicate<? super V>... p) {
+        return lose(m, cp, new P1<Map.Entry<K, V>>() {
+            @Override public boolean apply(Map.Entry<K, V> e) {
+                return isAll(e.getValue(), p);
+            }
+        });
     }
 
     /**
-     * Gets collections of data items from grid job res casted to specified type.
-     * <p>
-     * Here's the typical example of how this method is used in {@code reduce()} method
-     * implementation (this example sums up all the values of {@code Integer} type):
-     * <pre name="code" class="java">
-     * public Integer reduce(List&lt;GridComputeJobResult&gt; res) throws IgniteCheckedException {
-     *     return F.sum(F.&lt;Integer&gt;jobResults(res));
-     * }
-     * </pre>
-     * <p>
-     * Note that this method doesn't create a new collection but simply iterates over the input one.
+     * Loses all elements in input list that are contained in {@code filter} collection.
      *
-     * @param res Collection of grid job res.
-     * @param <T> Type of the data item to cast to. See {@link org.apache.ignite.compute.ComputeJobResult#getData()} method.
-     * @return Collections of data items casted to type {@code T}.
-     * @see org.apache.ignite.compute.ComputeJobResult#getData()
+     * @param c Input list.
+     * @param cp If {@code true} method creates new list not modifying input,
+     *      otherwise does <tt>in-place</tt> modifications.
+     * @param filter Filter collection. If {@code filter} collection is empty or
+     *      {@code null} - no elements are lost.
+     * @param <T> Type of list.
+     * @return List of remaining elements
      */
-    public static <T> Collection<T> jobResults(@Nullable Collection<? extends ComputeJobResult> res) {
-        if (isEmpty(res))
-            return Collections.emptyList();
+    public static <T> List<T> loseList(List<T> c, boolean cp, @Nullable Collection<? super T> filter) {
+        A.notNull(c, "c");
 
-        assert res != null;
+        List<T> res;
 
-        Collection<T> c = new ArrayList<>(res.size());
+        if (!cp) {
+            res = c;
 
-        for (ComputeJobResult r : res)
-            c.add(r.<T>getData());
+            if (filter != null)
+                res.removeAll(filter);
+        }
+        else {
+            res = new LinkedList<>();
 
-        return c;
+            for (T t : c) {
+                if (filter == null || !filter.contains(t))
+                    res.add(t);
+            }
+        }
+
+        return res;
     }
 
     /**
-     * Convenient utility method that returns collection of node IDs for a given
-     * collection of grid nodes.
-     * <p>
-     * Note that this method doesn't create a new collection but simply iterates
-     * over the input one.
+     * Loses all elements in input list for which any of the predicates evaluate to {@code true}.
      *
-     * @param nodes Collection of grid nodes.
-     * @return Collection of node IDs for given collection of grid nodes.
+     * @param c Input list.
+     * @param cp If {@code true} method creates new list not modifying input,
+     *      otherwise does <tt>in-place</tt> modifications.
+     * @param p Looses all elements for which any of the predicates evaluate to {@code true}.
+     * @param <T> Type of list.
+     * @return List of remaining elements
      */
-    public static Collection<UUID> nodeIds(@Nullable Collection<? extends ClusterNode> nodes) {
-        if (nodes == null || nodes.isEmpty())
-            return Collections.emptyList();
+    public static <T> List<T> filterList(List<T> c, boolean cp, @Nullable IgnitePredicate<T>... p) {
+        A.notNull(c, "c");
 
-        return F.viewReadOnly(nodes, node2id());
-    }
+        List<T> res;
 
-    /**
-     * Convenient utility method that returns collection of node ID8s for a given
-     * collection of grid nodes. ID8 is a shorter string representation of node ID,
-     * mainly the first 8 characters.
-     * <p>
-     * Note that this method doesn't create a new collection but simply iterates
-     * over the input one.
-     *
-     * @param nodes Collection of grid nodes.
-     * @return Collection of node IDs for given collection of grid nodes.
-     */
-    public static Collection<String> nodeId8s(@Nullable Collection<? extends ClusterNode> nodes) {
-        if (nodes == null || nodes.isEmpty())
-            return Collections.emptyList();
+        if (!cp) {
+            res = c;
 
-        return F.viewReadOnly(nodes, node2id8());
-    }
+            if (p != null)
+                for (Iterator<T> it = c.iterator(); it.hasNext();)
+                    if (isAny(it.next(), p))
+                        it.remove();
+        }
+        else {
+            res = new ArrayList<>(c.size());
 
-    /**
-     * Convenient utility method that returns collection of node ID8s for a given
-     * collection of node IDs. ID8 is a shorter string representation of node ID,
-     * mainly the first 8 characters.
-     * <p>
-     * Note that this method doesn't create a new collection but simply iterates
-     * over the input one.
-     *
-     * @param ids Collection of nodeIds.
-     * @return Collection of node IDs for given collection of grid nodes.
-     */
-    public static Collection<String> id8s(@Nullable Collection<UUID> ids) {
-        if (ids == null || ids.isEmpty())
-            return Collections.emptyList();
+            for (T t : c)
+                if (!isAny(t, p))
+                    res.add(t);
+        }
 
-        return F.viewReadOnly(ids, id2id8());
+        return res;
     }
 
     /**
-     * Convenient utility method that returns collection of node attributes for a given
-     * collection of grid nodes.
-     * <p>
-     * Note that this method doesn't create a new collection but simply iterates over the input one.
+     * Gets closure which converts node to node ID.
      *
-     * @param nodes Collection of grid nodes.
-     * @param attr Name of the attribute to return from each node.
-     * @param <T> Type of the attribute.
-     * @return Collection of node attributes for given collection of grid nodes.
+     * @return Closure which converts node to node ID.
      */
-    public static <T> Collection<T> nodeAttributes(Collection<? extends ClusterNode> nodes, String attr) {
-        A.notNull(nodes, "nodes", attr, "attr");
-
-        Collection<T> c = new ArrayList<>(nodes.size());
-
-        for (ClusterNode n : nodes)
-            c.add(n.<T>attribute(attr));
-
-        return c;
+    public static IgniteClosure<ClusterNode, UUID> node2id() {
+        return NODE2ID;
     }
 
     /**
-     * Gets closure that calls {@code System.out.println()} on its bound variable.
+     * Creates grid node predicate evaluating on the given node ID.
      *
-     * @param <T> Type of the bound variable.
-     * @return Closure that calls {@code System.out.println()} on its bound variable.
+     * @param nodeId Node ID for which returning predicate will evaluate to {@code true}.
+     * @return Grid node predicate evaluating on the given node ID.
+     * @see #idForNodeId(UUID)
+     * @see #nodeIds(Collection)
      */
-    @SuppressWarnings("unchecked")
-    public static <T> IgniteInClosure<T> println() {
-        return (IgniteInClosure<T>)PRINTLN;
-    }
+    public static <T extends ClusterNode> IgnitePredicate<T> nodeForNodeId(final UUID nodeId) {
+        A.notNull(nodeId, "nodeId");
 
-    /**
-     * Creates absolute closure that does <tt>System.out.println(msg)</tt>.
-     *
-     * @param msg Message to print.
-     * @return Absolute closure that print message.
-     */
-    public static GridAbsClosure println(final String msg) {
-        return new CA() {
-            @Override public void apply() {
-                System.out.println(msg);
+        return new P1<T>() {
+            @Override public boolean apply(ClusterNode e) {
+                return e.id().equals(nodeId);
             }
         };
     }
 
     /**
-     * Creates absolute closure that does <tt>System.out.print(msg)</tt>.
+     * Creates grid node predicate evaluating on the given node IDs.
      *
-     * @param msg Message to print.
-     * @return Absolute closure that print message.
+     * @param nodeIds Collection of node IDs.
+     * @return Grid node predicate evaluating on the given node IDs.
+     * @see #idForNodeId(UUID)
+     * @see #nodeIds(Collection)
      */
-    public static GridAbsClosure print(final String msg) {
-        return new CA() {
-            @Override public void apply() {
-                System.out.print(msg);
-            }
-        };
-    }
+    public static <T extends ClusterNode> IgnitePredicate<T> nodeForNodeIds(@Nullable final Collection<UUID>
+        nodeIds) {
+        if (isEmpty(nodeIds))
+            return alwaysFalse();
 
-    /**
-     * Gets closure that prints out its bound variable.
-     *
-     * @param pre String value to print before each variable.
-     * @param post String value to print after each variable.
-     * @param <T> Type of the bound variable.
-     * @return Closure that calls {@code System.out.print(pre); System.out.print(t); System.out.println(post)}
-     *      on its bound variable.
-     */
-    public static <T> IgniteInClosure<T> println(@Nullable final String pre, @Nullable final String post) {
-        return new CI1<T>() {
-            @Override public void apply(T t) {
-                String sPre = pre == null ? "" : pre;
-                String sPost = post == null ? "" : post;
+        assert nodeIds != null;
 
-                System.out.println(sPre + t + sPost);
+        return new P1<T>() {
+            @Override public boolean apply(ClusterNode e) {
+                return nodeIds.contains(e.id());
             }
         };
     }
 
     /**
-     * Gets closure that prints out its bound variable.
+     * Creates {@link UUID} predicate evaluating on the given node ID.
      *
-     * @param fmt Format string as for {@link PrintStream#printf(String, Object...)} method.
-     * @param <T> Type of the bound variable.
-     * @return Closure that prints out its bound variable.
+     * @param nodeId Node ID for which returning predicate will evaluate to {@code true}.
+     * @return {@link UUID} predicate evaluating on the given node ID.
+     * @see #nodeForNodeId(UUID)
+     * @see #nodeIds(Collection)
      */
-    public static <T> IgniteInClosure<T> printf(final String fmt) {
-        return new CI1<T>() {
-            @Override public void apply(T t) {
-                System.out.printf(fmt, t);
+    public static IgnitePredicate<UUID> idForNodeId(final UUID nodeId) {
+        A.notNull(nodeId, "nodeId");
+
+        return new P1<UUID>() {
+            @Override public boolean apply(UUID id) {
+                return id.equals(nodeId);
             }
         };
     }
 
     /**
-     * Gets closure that prints out its bound variable
+     * Creates predicates that evaluates to {@code true} for each node in given collection.
+     * Note that if collection is empty the result predicate will always evaluate to {@code false}.
+     * Implementation simply creates {@link GridNodePredicate} instance.
      *
-     * @return Closure that prints out its bound variable.
+     * @param nodes Collection of nodes. If none provided - result predicate will always
+     *      return {@code false}.
+     * @return Predicates that evaluates to {@code true} for each node in given collection.
      */
-    @SuppressWarnings("unchecked")
-    public static <T> IgniteInClosure<T> print() {
-        return (IgniteInClosure<T>)PRINT;
+    public static IgnitePredicate<ClusterNode> nodeForNodes(ClusterNode... nodes) {
+        return new GridNodePredicate(nodes);
     }
 
     /**
-     * Gets closure that prints out its bound variable.
+     * Retains all elements in input collection that are contained in {@code filter}.
      *
-     * @param pre String value to print before each variable.
-     * @param post String value to print after each variable.
-     * @return Closure that prints out its bound variable.
+     * @param c Input collection.
+     * @param cp If {@code true} method creates collection not modifying input, otherwise does
+     *      <tt>in-place</tt> modifications.
+     * @param filter Filter collection. If filter collection is {@code null} or empty -
+     *      an empty collection will be returned.
+     * @param <T> Type of collections.
+     * @return Collection of retain elements.
      */
-    public static <T> IgniteInClosure<T> print(@Nullable final String pre, @Nullable final String post) {
-        return new CI1<T>() {
-            @Override public void apply(T t) {
-                String sPre = pre == null ? "" : pre;
-                String sPost = post == null ? "" : post;
+    public static <T0, T extends T0> Collection<T> retain(Collection<T> c, boolean cp,
+        @Nullable Collection<? extends T0> filter) {
+        A.notNull(c, "c");
 
-                System.out.print(sPre + t + sPost);
-            }
-        };
+        return retain(c, cp, F0.in(filter));
     }
 
     /**
-     * Gets random value from given collection.
+     * Retains all elements in input collection that are evaluated to {@code true}
+     * by all given predicates.
      *
-     * @param c Input collection (no {@code null} and not emtpy).
-     * @param <T> Type of the collection.
-     * @return Random value from the input collection.
+     * @param c Input collection.
+     * @param cp If {@code true} method creates collection not modifying input, otherwise does
+     *      <tt>in-place</tt> modifications.
+     * @param p Predicates to filter by. If no predicates provides - all elements
+     *      will be retained.
+     * @param <T> Type of collections.
+     * @return Collection of retain elements.
      */
-    @SuppressWarnings("UnusedDeclaration")
-    public static <T> T rand(Collection<? extends T> c) {
+    public static <T> Collection<T> retain(Collection<T> c, boolean cp, @Nullable IgnitePredicate<? super T>... p) {
         A.notNull(c, "c");
 
-        int n = ThreadLocalRandom8.current().nextInt(c.size());
-
-        int i = 0;
-
-        for (T t : c) {
-            if (i++ == n)
-                return t;
-        }
-
-        throw new ConcurrentModificationException();
+        return lose(c, cp, not(p));
     }
 
     /**
-     * Gets random value from given collection which may be modified concurrently.
+     * Retains only up to first {@code num} elements in the input collection.
      *
      * @param c Input collection.
-     * @param <T> Type of the collection.
-     * @return Random value from the input collection.
+     * @param cp If {@code true} method creates collection not modifying input, otherwise does
+     *      <tt>in-place</tt> modifications.
+     * @param num Maximum number of elements to retain (the actual number can be
+     *      less if the input collection contains less elements).
+     * @param <T> Type of the collections.
+     * @return Collection contains up to {@code num} first elements from the input collection.
      */
-    @Nullable public static <T> T randConcurrent(Collection<? extends T> c) {
+    public static <T> Collection<T> retain(Collection<T> c, boolean cp, int num) {
         A.notNull(c, "c");
+        A.ensure(num >= 0, "num >= 0");
 
-        int size = c.size();
+        Collection<T> res;
 
-        if (size == 0)
-            return null;
+        if (!cp) {
+            res = c;
 
-        int n = ThreadLocalRandom8.current().nextInt(size);
+            if (num < res.size()) {
+                int i = 0;
 
-        int i = 0;
+                for (Iterator<T> iter = res.iterator(); iter.hasNext();) {
+                    iter.next();
 
-        T res = null;
+                    if (i++ >= num)
+                        iter.remove();
+                }
+            }
+        }
+        else {
+            res = new ArrayList<>(num);
 
-        for (T t : c) {
-            if (i++ == n)
-                return t;
+            Iterator<? extends T> iter = c.iterator();
 
-            res = t;
+            for (int i = 0; i < num && iter.hasNext(); i++)
+                res.add(iter.next());
         }
 
         return res;
     }
 
     /**
-     * Gets random value from given list. For random-access lists this
-     * operation is O(1), otherwise O(n).
+     * Curries given closure.
      *
-     * @param l Input collection.
-     * @param <T> Type of the list elements.
-     * @return Random value from the input list.
+     * @param f Closure.
+     * @param e Parameter.
+     * @param <T> Input type.
+     * @param <R> Output type.
+     * @return Curried closure.
      */
-    public static <T> T rand(List<T> l) {
-        A.notNull(l, "l");
-
-        return l.get(ThreadLocalRandom8.current().nextInt(l.size()));
+    public static <T, R> IgniteOutClosure<R> curry(final IgniteClosure<? super T, R> f, final T e) {
+        return new IgniteOutClosure<R>() {
+            @Override public R apply() {
+                return f.apply(e);
+            }
+        };
     }
 
     /**
-     * Gets random value from given array. This operation
-     * does not iterate through array elements and returns immediately.
+     * Curries given closure.
      *
-     * @param c Input collection.
-     * @param <T> Type of the collection.
-     * @return Random value from the input collection.
+     * @param f Closure.
+     * @param e Parameter.
+     * @param <T> Input type.
+     * @return Curried closure.
      */
-    public static <T> T rand(T... c) {
-        A.notNull(c, "c");
-
-        return c[ThreadLocalRandom8.current().nextInt(c.length)];
+    public static <T> GridAbsClosure curry(final IgniteInClosure<? super T> f, final T e) {
+        return new GridAbsClosure() {
+            @Override public void apply() {
+                f.apply(e);
+            }
+        };
     }
 
     /**
-     * Concatenates an element to a collection. If {@code copy} flag is {@code true}, then
-     * a new collection will be created and the element and passed in collection will be
-     * copied into the new one. The returned collection will be modifiable. If {@code copy}
-     * flag is {@code false}, then a read-only view will be created over the element and given
-     * collections and no copying will happen.
+     * Converts array to {@link List}. Note that resulting list cannot
+     * be altered in size, as it it based on the passed in array -
+     * only current elements can be changed.
+     * <p>
+     * Note that unlike {@link Arrays#asList(Object[])}, this method is
+     * {@code null}-safe. If {@code null} is passed in, then empty list
+     * will be returned.
      *
-     * @param cp Copy flag.
-     * @param t First element.
-     * @param c Second collection.
-     * @param <T> Element type.
-     * @return Concatenated collection.
+     * @param vals Array of values
+     * @param <T> Array type.
+     * @return {@link List} instance for array.
      */
-    public static <T> Collection<T> concat(boolean cp, @Nullable final T t, @Nullable final Collection<T> c) {
-        if (cp) {
-            if (isEmpty(c)) {
-                Collection<T> l = new ArrayList<>(1);
+    public static <T> List<T> asList(@Nullable T... vals) {
+        return isEmpty(vals) ? Collections.<T>emptyList() : Arrays.asList(vals);
+    }
 
-                l.add(t);
+    /**
+     * Creates new empty iterator.
+     *
+     * @param <T> Type of the iterator.
+     * @return Newly created empty iterator.
+     */
+    public static <T> GridIterator<T> emptyIterator() {
+        return new GridEmptyIterator<>();
+    }
 
-                return l;
+    /**
+     * Flattens collection-of-collections and returns collection over the
+     * elements of the inner collections. This method doesn't create any
+     * new collections or copies any elements.
+     * <p>
+     * Note that due to non-copying nature of implementation, the
+     * {@link Collection#size() size()} method of resulting collection will have to
+     * iterate over all elements to produce size. Method {@link Collection#isEmpty() isEmpty()},
+     * however, is constant time and is much more preferable to use instead
+     * of {@code 'size()'} method when checking if list is not empty.
+     *
+     * @param c Input collection of collections.
+     * @param <T> Type of the inner collections.
+     * @return Iterable over the elements of the inner collections.
+     */
+    public static <T> Collection<T> flatCollections(@Nullable final Collection<? extends Collection<T>> c) {
+        if (F.isEmpty(c))
+            return Collections.emptyList();
+
+        return new GridSerializableCollection<T>() {
+            @NotNull
+            @Override public Iterator<T> iterator() {
+                return flat((Iterable<? extends Iterable<T>>)c);
             }
 
-            assert c != null;
+            @Override public int size() {
+                return F.size(iterator());
+            }
 
-            Collection<T> ret = new ArrayList<>(c.size() + 1);
+            @Override public boolean isEmpty() {
+                return !iterator().hasNext();
+            }
+        };
+    }
 
-            ret.add(t);
-            ret.addAll(c);
+    /**
+     * Flattens iterable-of-iterables and returns iterable over the
+     * elements of the inner collections. This method doesn't create any
+     * new collections or copies any elements.
+     *
+     * @param c Input collection of collections.
+     * @param <T> Type of the inner collections.
+     * @return Iterable over the elements of the inner collections.
+     */
+    public static <T> GridIterator<T> flat(@Nullable final Iterable<? extends Iterable<T>> c) {
+        return isEmpty(c) ? GridFunc.<T>emptyIterator() : new GridIteratorAdapter<T>() {
+            /** */
+            private Iterator<? extends Iterable<T>> a = c.iterator();
 
-            return ret;
-        }
-        else {
-            if (isEmpty(c))
-                return Collections.singletonList(t);
+            /** */
+            private Iterator<T> b;
 
-            assert c != null;
+            /** */
+            private boolean moved = true;
 
-            return new GridSerializableCollection<T>() {
-                @NotNull
-                @Override public Iterator<T> iterator() {
-                    return new GridSerializableIterator<T>() {
-                        private Iterator<T> it;
+            /** */
+            private boolean more;
 
-                        @Override public boolean hasNext() {
-                            return it == null || it.hasNext();
-                        }
+            @Override public boolean hasNextX() {
+                if (!moved)
+                    return more;
 
-                        @Nullable @Override public T next() {
-                            if (it == null) {
-                                it = c.iterator();
+                moved = false;
 
-                                return t;
-                            }
+                if (b != null && b.hasNext())
+                    return more = true;
 
-                            return it.next();
-                        }
+                while (a.hasNext()) {
+                    b = a.next().iterator();
 
-                        @Override public void remove() {
-                            throw new UnsupportedOperationException();
-                        }
-                    };
+                    if (b.hasNext())
+                        return more = true;
                 }
 
-                @Override public int size() {
-                    return c.size() + 1;
-                }
+                return more = false;
+            }
 
-                @Override public boolean equals(Object obj) {
-                    return obj instanceof Collection && eqNotOrdered(this, (Collection)obj);
+            @Override public T nextX() {
+                if (hasNext()) {
+                    moved = true;
+
+                    return b.next();
                 }
-            };
-        }
+
+                throw new NoSuchElementException();
+            }
+
+            @Override public void removeX() {
+                assert b != null;
+
+                b.remove();
+            }
+        };
     }
 
     /**
-     * Concatenates 2 collections into one. If {@code copy} flag is {@code true}, then
-     * a new collection will be created and these collections will be copied into the
-     * new one. The returned collection will be modifiable. If {@code copy} flag is
-     * {@code false}, then a read-only view will be created over given collections
-     * and no copying will happen.
+     * Flattens iterable-of-iterators and returns iterator over the
+     * elements of the inner collections. This method doesn't create any
+     * new collections or copies any elements.
      *
-     * @param cp Copy flag.
-     * @param c1 First collection.
-     * @param c2 Second collection.
-     * @param <T> Element type.
-     * @return Concatenated {@code non-null} collection.
+     * @param c Input iterable of iterators.
+     * @return Iterator over the elements of given iterators.
      */
-    public static <T> Collection<T> concat(boolean cp, @Nullable final Collection<T> c1,
-        @Nullable final Collection<T> c2) {
-        if (cp) {
-            if (isEmpty(c1) && isEmpty(c2))
-                return new ArrayList<>(0);
+    public static <T> Iterator<T> flatIterators(@Nullable final Iterable<Iterator<T>> c) {
+        return isEmpty(c) ? GridFunc.<T>emptyIterator() : new GridIteratorAdapter<T>() {
+            /** */
+            private Iterator<? extends Iterator<T>> a = c.iterator();
 
-            if (isEmpty(c1))
-                return new ArrayList<>(c2);
+            /** */
+            private Iterator<T> b;
 
-            if (isEmpty(c2))
-                return new ArrayList<>(c1);
+            /** */
+            private boolean moved = true;
 
-            assert c1 != null && c2 != null;
+            /** */
+            private boolean more;
 
-            Collection<T> c = new ArrayList<>(c1.size() + c2.size());
+            @Override public boolean hasNextX() {
+                if (!moved)
+                    return more;
 
-            c.addAll(c1);
-            c.addAll(c2);
+                moved = false;
 
-            return c;
-        }
-        else {
-            if (isEmpty(c1) && isEmpty(c2))
-                return Collections.emptyList();
+                if (b != null && b.hasNext())
+                    return more = true;
 
-            if (isEmpty(c1) || isEmpty(c2)) {
-                Collection<T> c = isEmpty(c1) ? c2 : c1;
+                while (a.hasNext()) {
+                    b = a.next();
 
-                assert c != null;
+                    if (b.hasNext())
+                        return more = true;
+                }
 
-                return c;
+                return more = false;
             }
 
-            assert c1 != null && c2 != null;
-
-            return new GridSerializableCollection<T>() {
-                @NotNull
-                @Override public Iterator<T> iterator() {
-                    return new GridSerializableIterator<T>() {
-                        private Iterator<T> it1 = c1.iterator();
-                        private Iterator<T> it2 = c2.iterator();
-
-                        @Override public boolean hasNext() {
-                            if (it1 != null)
-                                if (!it1.hasNext())
-                                    it1 = null;
-                                else
-                                    return true;
-
-                            return it2.hasNext();
-                        }
-
-                        @Override public T next() {
-                            return it1 != null ? it1.next() : it2.next();
-                        }
+            @Override public T nextX() {
+                if (hasNext()) {
+                    moved = true;
 
-                        @Override public void remove() {
-                            throw new UnsupportedOperationException();
-                        }
-                    };
+                    return b.next();
                 }
 
-                @Override public boolean contains(Object o) {
-                    return c1.contains(o) || c2.contains(o);
-                }
+                throw new NoSuchElementException();
+            }
 
-                @Override public int size() {
-                    return c1.size() + c2.size();
-                }
+            @Override public void removeX() {
+                assert b != null;
 
-                @Override public boolean equals(Object obj) {
-                    return obj instanceof Collection && eqNotOrdered(this, (Collection<?>)obj);
-                }
-            };
-        }
+                b.remove();
+            }
+        };
     }
 
     /**
-     * Concatenates an elements to an array.
+     * Converts given runnable to an absolute closure.
      *
-     * @param arr Array.
-     * @param obj One or more elements.
-     * @return Concatenated array.
+     * @param r Runnable to convert to closure. If {@code null} - no-op closure is returned.
+     * @return Closure that wraps given runnable. Note that wrapping closure always returns {@code null}.
      */
-    public static <T> T[] concat(@Nullable T[] arr, T... obj) {
-        T[] newArr;
-
-        if (arr == null || arr.length == 0)
-            newArr = obj;
-        else {
-            newArr = Arrays.copyOf(arr, arr.length + obj.length);
-
-            System.arraycopy(obj, 0, newArr, arr.length, obj.length);
-        }
-
-        return newArr;
-    }
+    public static GridAbsClosure as(@Nullable final Runnable r) {
+        return new CA() {
+            @Override public void apply() {
+                if (r != null)
+                    r.run();
+            }
+        };
+    }
 
     /**
-     * Concatenates multiple iterators as single one.
+     * Gets size of the given collection with provided optional predicates.
      *
-     * @param iters Iterators.
-     * @return Single iterator.
+     * @param c Collection to size.
+     * @param p Optional predicates that filters out elements from count.
+     * @param <T> Type of the iterator.
+     * @return Number of elements in the collection for which all given predicates
+     *      evaluates to {@code true}. If no predicates is provided - all elements are counted.
      */
-    @SuppressWarnings("unchecked")
-    public static <T> Iterator<T> concat(Iterator<T> ... iters) {
-        if (iters.length == 1)
-            return iters[0];
-
-        return concat(asList(iters).iterator());
+    public static <T> int size(@Nullable Collection<? extends T> c, @Nullable IgnitePredicate<? super T>... p) {
+        return c == null || c.isEmpty() ? 0 : isEmpty(p) || isAlwaysTrue(p) ? c.size() : size(c.iterator(), p);
     }
 
     /**
-     * Concatenates multiple iterators as single one.
+     * Gets size of the given iterator with provided optional predicates. Iterator
+     * will be traversed to get the count.
      *
-     * @param iters Iterator over iterators.
-     * @return Single iterator.
+     * @param it Iterator to size.
+     * @param p Optional predicates that filters out elements from count.
+     * @param <T> Type of the iterator.
+     * @return Number of elements in the iterator for which all given predicates
+     *      evaluates to {@code true}. If no predicates is provided - all elements are counted.
      */
-    @SuppressWarnings("unchecked")
-    public static <T> Iterator<T> concat(final Iterator<Iterator<T>> iters) {
-        if (!iters.hasNext())
-            return Collections.<T>emptySet().iterator();
-
-        return new Iterator<T>() {
-            privat

<TRUNCATED>


[21/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 58a8c8d..d54e06f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -532,22 +532,6 @@ public class IgnitionEx {
     }
 
     /**
-     * Start Grid passing a closure which will modify configuration before it is passed to start routine.
-     *
-     * @param springCfgPath Spring config path.
-     * @param gridName Grid name.
-     * @param cfgClo Configuration closure.
-     * @return Started Grid.
-     * @throws IgniteCheckedException If failed.
-     */
-    public static Ignite startWithClosure(@Nullable String springCfgPath, @Nullable String gridName,
-        IgniteClosure<IgniteConfiguration, IgniteConfiguration> cfgClo) throws IgniteCheckedException {
-        URL url = U.resolveSpringUrl(springCfgPath);
-
-        return start(url, gridName, null, cfgClo);
-    }
-
-    /**
      * Loads all grid configurations specified within given Spring XML configuration file.
      * <p>
      * Usually Spring XML configuration file will contain only one Grid definition. Note that
@@ -734,7 +718,40 @@ public class IgnitionEx {
      */
     public static Ignite start(URL springCfgUrl, @Nullable String gridName,
         @Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException {
-        return start(springCfgUrl, gridName, springCtx, null);
+        A.notNull(springCfgUrl, "springCfgUrl");
+
+        boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null;
+
+        IgniteBiTuple<Object, Object> t = null;
+
+        if (isLog4jUsed) {
+            try {
+                t = U.addLog4jNoOpLogger();
+            }
+            catch (IgniteCheckedException ignore) {
+                isLog4jUsed = false;
+            }
+        }
+
+        Collection<Handler> savedHnds = null;
+
+        if (!isLog4jUsed)
+            savedHnds = U.addJavaNoOpLogger();
+
+        IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> cfgMap;
+
+        try {
+            cfgMap = loadConfigurations(springCfgUrl);
+        }
+        finally {
+            if (isLog4jUsed && t != null)
+                U.removeLog4jNoOpLogger(t);
+
+            if (!isLog4jUsed)
+                U.removeJavaNoOpLogger(savedHnds);
+        }
+
+        return startConfigurations(cfgMap, springCfgUrl, gridName, springCtx);
     }
 
     /**
@@ -780,73 +797,6 @@ public class IgnitionEx {
      */
     public static Ignite start(InputStream springCfgStream, @Nullable String gridName,
         @Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException {
-        return start(springCfgStream, gridName, springCtx, null);
-    }
-
-    /**
-     * Internal Spring-based start routine.
-     *
-     * @param springCfgUrl Spring XML configuration file URL. This cannot be {@code null}.
-     * @param gridName Grid name that will override default.
-     * @param springCtx Optional Spring application context.
-     * @param cfgClo Optional closure to change configuration before it is used to start the grid.
-     * @return Started grid.
-     * @throws IgniteCheckedException If failed.
-     */
-    private static Ignite start(final URL springCfgUrl, @Nullable String gridName,
-        @Nullable GridSpringResourceContext springCtx,
-        @Nullable IgniteClosure<IgniteConfiguration, IgniteConfiguration> cfgClo)
-        throws IgniteCheckedException {
-        A.notNull(springCfgUrl, "springCfgUrl");
-
-        boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null;
-
-        IgniteBiTuple<Object, Object> t = null;
-
-        if (isLog4jUsed) {
-            try {
-                t = U.addLog4jNoOpLogger();
-            }
-            catch (IgniteCheckedException ignore) {
-                isLog4jUsed = false;
-            }
-        }
-
-        Collection<Handler> savedHnds = null;
-
-        if (!isLog4jUsed)
-            savedHnds = U.addJavaNoOpLogger();
-
-        IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> cfgMap;
-
-        try {
-            cfgMap = loadConfigurations(springCfgUrl);
-        }
-        finally {
-            if (isLog4jUsed && t != null)
-                U.removeLog4jNoOpLogger(t);
-
-            if (!isLog4jUsed)
-                U.removeJavaNoOpLogger(savedHnds);
-        }
-
-        return startConfigurations(cfgMap, springCfgUrl, gridName, springCtx, cfgClo);
-    }
-
-    /**
-     * Internal Spring-based start routine.
-     *
-     * @param springCfgStream Input stream containing Spring XML configuration. This cannot be {@code null}.
-     * @param gridName Grid name that will override default.
-     * @param springCtx Optional Spring application context.
-     * @param cfgClo Optional closure to change configuration before it is used to start the grid.
-     * @return Started grid.
-     * @throws IgniteCheckedException If failed.
-     */
-    private static Ignite start(final InputStream springCfgStream, @Nullable String gridName,
-        @Nullable GridSpringResourceContext springCtx,
-        @Nullable IgniteClosure<IgniteConfiguration, IgniteConfiguration> cfgClo)
-        throws IgniteCheckedException {
         A.notNull(springCfgStream, "springCfgUrl");
 
         boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null;
@@ -880,7 +830,7 @@ public class IgnitionEx {
                 U.removeJavaNoOpLogger(savedHnds);
         }
 
-        return startConfigurations(cfgMap, null, gridName, springCtx, cfgClo);
+        return startConfigurations(cfgMap, null, gridName, springCtx);
     }
 
     /**
@@ -890,7 +840,6 @@ public class IgnitionEx {
      * @param springCfgUrl Spring XML configuration file URL.
      * @param gridName Grid name that will override default.
      * @param springCtx Optional Spring application context.
-     * @param cfgClo Optional closure to change configuration before it is used to start the grid.
      * @return Started grid.
      * @throws IgniteCheckedException If failed.
      */
@@ -898,8 +847,7 @@ public class IgnitionEx {
         IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> cfgMap,
         URL springCfgUrl,
         @Nullable String gridName,
-        @Nullable GridSpringResourceContext springCtx,
-        @Nullable IgniteClosure<IgniteConfiguration, IgniteConfiguration> cfgClo)
+        @Nullable GridSpringResourceContext springCtx)
         throws IgniteCheckedException {
         List<IgniteNamedInstance> grids = new ArrayList<>(cfgMap.size());
 
@@ -910,12 +858,6 @@ public class IgnitionEx {
                 if (cfg.getGridName() == null && !F.isEmpty(gridName))
                     cfg.setGridName(gridName);
 
-                if (cfgClo != null) {
-                    cfg = cfgClo.apply(cfg);
-
-                    assert cfg != null;
-                }
-
                 // Use either user defined context or our one.
                 IgniteNamedInstance grid = start0(
                     new GridStartContext(cfg, springCfgUrl, springCtx == null ? cfgMap.get2() : springCtx));
@@ -1600,9 +1542,9 @@ public class IgnitionEx {
                     igfsExecSvc, restExecSvc,
                     new CA() {
                         @Override public void apply() {
-                        startLatch.countDown();
-                    }
-                });
+                            startLatch.countDown();
+                        }
+                    });
 
                 state = STARTED;
 
@@ -1775,15 +1717,7 @@ public class IgnitionEx {
             Marshaller marsh = myCfg.getMarshaller();
 
             if (marsh == null) {
-                if (!U.isHotSpot()) {
-                    U.warn(log, "OptimizedMarshaller is not supported on this JVM " +
-                        "(only Java HotSpot VMs are supported). Switching to standard JDK marshalling - " +
-                        "object serialization performance will be significantly slower.",
-                        "To enable fast marshalling upgrade to recent 1.6 or 1.7 HotSpot VM release.");
-
-                    marsh = new JdkMarshaller();
-                }
-                else if (!OptimizedMarshaller.available()) {
+                if (!OptimizedMarshaller.available()) {
                     U.warn(log, "OptimizedMarshaller is not supported on this JVM " +
                         "(only recent 1.6 and 1.7 versions HotSpot VMs are supported). " +
                         "To enable fast marshalling upgrade to recent 1.6 or 1.7 HotSpot VM release. " +
@@ -1796,11 +1730,6 @@ public class IgnitionEx {
                 else
                     marsh = new OptimizedMarshaller();
             }
-            else if (marsh instanceof OptimizedMarshaller && !U.isHotSpot()) {
-                U.warn(log, "Using OptimizedMarshaller on untested JVM (only Java HotSpot VMs were tested) - " +
-                    "object serialization behavior could yield unexpected results.",
-                    "Using GridOptimizedMarshaller on untested JVM.");
-            }
 
             myCfg.setMarshaller(marsh);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientConfiguration.java
index 3d01afa..ee16f94 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientConfiguration.java
@@ -160,7 +160,7 @@ public class GridClientConfiguration {
      * @throws GridClientException If parsing configuration failed.
      */
     public GridClientConfiguration(Properties in) throws GridClientException {
-        this("gg.client", in);
+        this("ignite.client", in);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
index 528de10..120350b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
@@ -66,10 +66,10 @@ public class DirectByteBufferStream {
     private static final short[] SHORT_ARR_EMPTY = new short[0];
 
     /** */
-    private static final int[] INT_ARR_EMPTY = new int[0];
+    private static final int[] INT_ARR_EMPTY = U.EMPTY_INTS;
 
     /** */
-    private static final long[] LONG_ARR_EMPTY = new long[0];
+    private static final long[] LONG_ARR_EMPTY = U.EMPTY_LONGS;
 
     /** */
     private static final float[] FLOAT_ARR_EMPTY = new float[0];

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropAwareEventFilter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropAwareEventFilter.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropAwareEventFilter.java
new file mode 100644
index 0000000..8dbc73b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropAwareEventFilter.java
@@ -0,0 +1,37 @@
+/*
+ * 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.interop;
+
+import org.apache.ignite.events.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.lang.*;
+
+/**
+ * Special version of predicate for events with initialize/close callbacks.
+ */
+public interface InteropAwareEventFilter<E extends Event> extends IgnitePredicate<E> {
+    /**
+     * Initializes the filter.
+     */
+    public void initialize(GridKernalContext ctx);
+
+    /**
+     * Closes the filter.
+     */
+    public void close();
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrap.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrap.java
new file mode 100644
index 0000000..820bef9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrap.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.interop;
+
+import org.apache.ignite.configuration.*;
+
+/**
+ * Interop bootstrap. Responsible for starting Ignite node in interop mode.
+ */
+public interface InteropBootstrap {
+    /**
+     * Start Ignite node.
+     *
+     * @param cfg Configuration.
+     * @param envPtr Environment pointer.
+     * @return Ignite node.
+     */
+    public InteropProcessor start(IgniteConfiguration cfg, long envPtr);
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrapFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrapFactory.java
new file mode 100644
index 0000000..b61ca89
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropBootstrapFactory.java
@@ -0,0 +1,39 @@
+/*
+ * 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.interop;
+
+import java.io.*;
+
+/**
+ * Interop bootstrap factory.
+ */
+public interface InteropBootstrapFactory extends Serializable {
+    /**
+     * Get bootstrap factory ID.
+     *
+     * @return ID.
+     */
+    public int id();
+
+    /**
+     * Create bootstrap instance.
+     *
+     * @return Bootstrap instance.
+     */
+    public InteropBootstrap create();
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropException.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropException.java
new file mode 100644
index 0000000..d74b9d4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropException.java
@@ -0,0 +1,71 @@
+/*
+ * 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.interop;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.jetbrains.annotations.*;
+
+/**
+ * Interop checked exception.
+ */
+public class InteropException extends IgniteCheckedException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Create empty exception.
+     */
+    public InteropException() {
+        // No-op.
+    }
+
+    /**
+     * Creates new exception with given error message.
+     *
+     * @param msg Error message.
+     */
+    public InteropException(String msg) {
+        super(msg);
+    }
+
+    /**
+     * Creates new grid exception with given throwable as a cause and
+     * source of error message.
+     *
+     * @param cause Non-null throwable cause.
+     */
+    public InteropException(Throwable cause) {
+        this(cause.getMessage(), cause);
+    }
+
+    /**
+     * Creates new exception with given error message and optional nested exception.
+     *
+     * @param msg Error message.
+     * @param cause Optional nested exception (can be {@code null}).
+     */
+    public InteropException(String msg, @Nullable Throwable cause) {
+        super(msg, cause);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(InteropException.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java
new file mode 100644
index 0000000..3ccd361
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java
@@ -0,0 +1,166 @@
+/*
+ * 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.interop;
+
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.resource.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.jetbrains.annotations.*;
+
+import java.lang.ref.*;
+import java.net.*;
+import java.security.*;
+import java.util.*;
+
+/**
+ * Entry point for interop nodes.
+ */
+@SuppressWarnings("UnusedDeclaration")
+public class InteropIgnition {
+    /**
+     * Start Ignite node in interop mode.
+     *
+     * @param springCfgPath Spring configuration path.
+     * @param gridName Grid name.
+     * @param factoryId Factory ID.
+     * @param envPtr Environment pointer.
+     * @return Ignite instance.
+     */
+    public static InteropProcessor start(@Nullable String springCfgPath, @Nullable String gridName, int factoryId,
+        long envPtr) {
+        IgniteConfiguration cfg = configuration(springCfgPath);
+
+        if (gridName != null)
+            cfg.setGridName(gridName);
+
+        InteropBootstrap bootstrap = bootstrap(factoryId);
+
+        InteropProcessor proc = bootstrap.start(cfg, envPtr);
+
+        trackFinalization(proc);
+
+        return proc;
+    }
+
+    /**
+     * Create configuration.
+     *
+     * @param springCfgPath Path to Spring XML.
+     * @return Configuration.
+     */
+    private static IgniteConfiguration configuration(@Nullable String springCfgPath) {
+        try {
+            URL url = springCfgPath == null ? U.resolveIgniteUrl(IgnitionEx.DFLT_CFG) :
+                U.resolveSpringUrl(springCfgPath);
+
+            IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> t = IgnitionEx.loadConfiguration(url);
+
+            return t.get1();
+        }
+        catch (IgniteCheckedException e) {
+            throw new IgniteException("Failed to instantiate configuration from Spring XML: " + springCfgPath, e);
+        }
+    }
+
+    /**
+     * Create bootstrap for the given factory ID.
+     *
+     * @param factoryId Factory ID.
+     * @return Bootstrap.
+     */
+    private static InteropBootstrap bootstrap(final int factoryId) {
+        InteropBootstrapFactory factory = AccessController.doPrivileged(
+            new PrivilegedAction<InteropBootstrapFactory>() {
+            @Override public InteropBootstrapFactory run() {
+                for (InteropBootstrapFactory factory : ServiceLoader.load(InteropBootstrapFactory.class)) {
+                    if (factory.id() == factoryId)
+                        return factory;
+                }
+
+                return null;
+            }
+        });
+
+        if (factory == null)
+            throw new IgniteException("Interop factory is not found (did you put into the classpath?): " + factoryId);
+
+        return factory.create();
+    }
+
+    /**
+     * Track processor finalization.
+     *
+     * @param proc Processor.
+     */
+    private static void trackFinalization(InteropProcessor proc) {
+        Thread thread = new Thread(new Finalizer(proc));
+
+        thread.setDaemon(true);
+
+        thread.start();
+    }
+
+    /**
+     * Finalizer runnable.
+     */
+    private static class Finalizer implements Runnable {
+        /** Queue where we expect notification to appear. */
+        private final ReferenceQueue<InteropProcessor> queue;
+
+        /** Phantom reference to processor.  */
+        private final PhantomReference<InteropProcessor> proc;
+
+        /** Cleanup runnable. */
+        private final Runnable cleanup;
+
+        /**
+         * Constructor.
+         *
+         * @param proc Processor.
+         */
+        public Finalizer(InteropProcessor proc) {
+            queue = new ReferenceQueue<>();
+
+            this.proc = new PhantomReference<>(proc, queue);
+
+            cleanup = proc.cleanupCallback();
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            try {
+                queue.remove(0);
+
+                cleanup.run();
+            }
+            catch (InterruptedException ignore) {
+                // No-op.
+            }
+        }
+    }
+
+    /**
+     * Private constructor.
+     */
+    private InteropIgnition() {
+        // No-op.
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropLocalEventListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropLocalEventListener.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropLocalEventListener.java
new file mode 100644
index 0000000..180863b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropLocalEventListener.java
@@ -0,0 +1,28 @@
+/*
+ * 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.interop;
+
+/**
+ * Special version of listener for events with close callbacks.
+ */
+public interface InteropLocalEventListener {
+    /**
+     * Closes the listener.
+     */
+    public void close();
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropNoCallbackException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropNoCallbackException.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropNoCallbackException.java
new file mode 100644
index 0000000..6fd614a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropNoCallbackException.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.interop;
+
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+/**
+ * Exception raised when interop callback is not set in native platform.
+ */
+@SuppressWarnings("UnusedDeclaration")
+public class InteropNoCallbackException extends InteropException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Constructor.
+     */
+    public InteropNoCallbackException() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param msg Message.
+     */
+    public InteropNoCallbackException(String msg) {
+        super(msg);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(InteropNoCallbackException.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java
new file mode 100644
index 0000000..aa4f877
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java
@@ -0,0 +1,36 @@
+/*
+ * 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.interop;
+
+import org.jetbrains.annotations.*;
+
+/**
+ * Interop processor.
+ */
+public interface InteropProcessor {
+    /**
+     * Get stop runnable to perform cleanup when interop is not longer used.
+     * <p/>
+     * <b>NOTE!</b> This runnable is called when current instance of interop processor is eligible for garbage
+     * collection. Therefore you should <b>never</b> store any references to Ignite internal inside it. Otherwise
+     * this runnable will never be called.
+     *
+     * @return Stop runnable. If {@code null} is returned, then no cleanup is expected.
+     */
+    @Nullable public Runnable cleanupCallback();
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
index 1ad6c8d..c877d57 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
@@ -35,6 +35,7 @@ import org.apache.ignite.marshaller.*;
 import org.apache.ignite.plugin.extensions.communication.*;
 import org.apache.ignite.spi.*;
 import org.apache.ignite.spi.communication.*;
+import org.apache.ignite.thread.*;
 import org.jetbrains.annotations.*;
 import org.jsr166.*;
 
@@ -55,6 +56,9 @@ import static org.jsr166.ConcurrentLinkedHashMap.QueuePolicy.*;
  * Grid communication manager.
  */
 public class GridIoManager extends GridManagerAdapter<CommunicationSpi<Serializable>> {
+    /** Empty array of message factories. */
+    public static final MessageFactory[] EMPTY = {};
+
     /** Max closed topics to store. */
     public static final int MAX_CLOSED_TOPICS = 10240;
 
@@ -183,7 +187,12 @@ public class GridIoManager extends GridManagerAdapter<CommunicationSpi<Serializa
         mgmtPool = ctx.getManagementExecutorService();
         utilityCachePool = ctx.utilityCachePool();
         marshCachePool = ctx.marshallerCachePool();
-        affPool = Executors.newFixedThreadPool(1);
+        affPool = new IgniteThreadPoolExecutor(
+            "aff-" + ctx.gridName(),
+            1,
+            1,
+            0,
+            new LinkedBlockingQueue<Runnable>());
 
         getSpi().setListener(commLsnr = new CommunicationListener<Serializable>() {
             @Override public void onMessage(UUID nodeId, Serializable msg, IgniteRunnable msgC) {
@@ -224,7 +233,24 @@ public class GridIoManager extends GridManagerAdapter<CommunicationSpi<Serializa
             };
         }
 
-        msgFactory = new GridIoMessageFactory(ctx.plugins().extensions(MessageFactory.class));
+        MessageFactory[] msgs = ctx.plugins().extensions(MessageFactory.class);
+
+        if (msgs == null)
+            msgs = EMPTY;
+
+        List<MessageFactory> compMsgs = new ArrayList<>();
+
+        for (IgniteComponentType compType : IgniteComponentType.values()) {
+            MessageFactory f = compType.messageFactory();
+
+            if (f != null)
+                compMsgs.add(f);
+        }
+
+        if (!compMsgs.isEmpty())
+            msgs = F.concat(msgs, compMsgs.toArray(new MessageFactory[compMsgs.size()]));
+
+        msgFactory = new GridIoMessageFactory(msgs);
 
         if (log.isDebugEnabled())
             log.debug(startInfo());
@@ -1671,10 +1697,10 @@ public class GridIoManager extends GridManagerAdapter<CommunicationSpi<Serializa
             this.predLsnr = predLsnr;
 
             if (predLsnr != null) {
-                ctx.resource().injectGeneric(predLsnr);
-
                 if (predLsnr instanceof GridLifecycleAwareMessageFilter)
-                    ((GridLifecycleAwareMessageFilter)predLsnr).initialize();
+                    ((GridLifecycleAwareMessageFilter)predLsnr).initialize(ctx);
+                else
+                    ctx.resource().injectGeneric(predLsnr);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index b82147b..7fe8da8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -166,12 +166,12 @@ public class GridIoMessageFactory implements MessageFactory {
                 break;
 
             case 16:
-                msg = new GridCacheOptimisticCheckPreparedTxRequest();
+                msg = new GridCacheTxRecoveryRequest();
 
                 break;
 
             case 17:
-                msg = new GridCacheOptimisticCheckPreparedTxResponse();
+                msg = new GridCacheTxRecoveryResponse();
 
                 break;
 
@@ -595,6 +595,14 @@ public class GridIoMessageFactory implements MessageFactory {
 
                 break;
 
+            case 112:
+                msg = new GridCacheSqlQuery();
+
+                break;
+
+            // [-3..112] - this
+            // [120..123] - DR
+            // [-4..-22] - SQL
             default:
                 if (ext != null) {
                     for (MessageFactory factory : ext) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridLifecycleAwareMessageFilter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridLifecycleAwareMessageFilter.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridLifecycleAwareMessageFilter.java
index cb99d2e..f8cd78f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridLifecycleAwareMessageFilter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridLifecycleAwareMessageFilter.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.managers.communication;
 
+import org.apache.ignite.internal.*;
 import org.apache.ignite.lang.*;
 
 /**
@@ -25,8 +26,10 @@ import org.apache.ignite.lang.*;
 public interface GridLifecycleAwareMessageFilter<K, V> extends IgniteBiPredicate<K, V> {
     /**
      * Initializes the filter.
+     *
+     * @param ctx Kernal context.
      */
-    public void initialize();
+    public void initialize(GridKernalContext ctx);
 
     /**
      * Closes the filter.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java
index 6ebe480..95c5eb1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java
@@ -22,6 +22,7 @@ import org.apache.ignite.cluster.*;
 import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.events.*;
+import org.apache.ignite.internal.interop.*;
 import org.apache.ignite.internal.managers.*;
 import org.apache.ignite.internal.managers.communication.*;
 import org.apache.ignite.internal.managers.deployment.*;
@@ -50,9 +51,6 @@ import static org.apache.ignite.internal.managers.communication.GridIoPolicy.*;
  * Grid event storage SPI manager.
  */
 public class GridEventStorageManager extends GridManagerAdapter<EventStorageSpi> {
-    /** */
-    private static final int[] EMPTY = new int[0];
-
     /** Local event listeners. */
     private final ConcurrentMap<Integer, Set<GridLocalEventListener>> lsnrs = new ConcurrentHashMap8<>();
 
@@ -106,7 +104,7 @@ public class GridEventStorageManager extends GridManagerAdapter<EventStorageSpi>
         int[] cfgInclEvtTypes0 = ctx.config().getIncludeEventTypes();
 
         if (F.isEmpty(cfgInclEvtTypes0))
-            cfgInclEvtTypes = EMPTY;
+            cfgInclEvtTypes = U.EMPTY_INTS;
         else {
             cfgInclEvtTypes0 = copy(cfgInclEvtTypes0);
 
@@ -653,6 +651,14 @@ public class GridEventStorageManager extends GridManagerAdapter<EventStorageSpi>
             }
         }
 
+        if (lsnr instanceof UserListenerWrapper)
+        {
+            IgnitePredicate p = ((UserListenerWrapper)lsnr).listener();
+
+            if (p instanceof InteropLocalEventListener)
+                ((InteropLocalEventListener)p).close();
+        }
+
         return found;
     }
 
@@ -755,7 +761,20 @@ public class GridEventStorageManager extends GridManagerAdapter<EventStorageSpi>
     public <T extends Event> Collection<T> localEvents(IgnitePredicate<T> p) {
         assert p != null;
 
-        return getSpi().localEvents(p);
+        if (p instanceof InteropAwareEventFilter) {
+            InteropAwareEventFilter p0 = (InteropAwareEventFilter)p;
+
+            p0.initialize(ctx);
+
+            try {
+                return getSpi().localEvents(p0);
+            }
+            finally {
+                p0.close();
+            }
+        }
+        else
+            return getSpi().localEvents(p);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java
index 5cb150e..9a81cd1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java
@@ -89,9 +89,7 @@ public class GridIndexingManager extends GridManagerAdapter<IndexingSpi> {
     public <K, V> void store(final String space, final K key, final V val, long expirationTime) throws IgniteCheckedException {
         assert key != null;
         assert val != null;
-
-        if (!enabled())
-            return;
+        assert enabled();
 
         if (!busyLock.enterBusy())
             throw new IllegalStateException("Failed to write to index (grid is stopping).");
@@ -115,9 +113,7 @@ public class GridIndexingManager extends GridManagerAdapter<IndexingSpi> {
     @SuppressWarnings("unchecked")
     public void remove(String space, Object key) throws IgniteCheckedException {
         assert key != null;
-
-        if (!enabled())
-            return;
+        assert enabled();
 
         if (!busyLock.enterBusy())
             throw new IllegalStateException("Failed to remove from index (grid is stopping).");
@@ -190,8 +186,7 @@ public class GridIndexingManager extends GridManagerAdapter<IndexingSpi> {
      * @throws IgniteSpiException If failed.
      */
     public void onSwap(String spaceName, Object key) throws IgniteSpiException {
-        if (!enabled())
-            return;
+        assert enabled();
 
         if (!busyLock.enterBusy())
             throw new IllegalStateException("Failed to process swap event (grid is stopping).");
@@ -214,8 +209,7 @@ public class GridIndexingManager extends GridManagerAdapter<IndexingSpi> {
      */
     public void onUnswap(String spaceName, Object key, Object val)
         throws IgniteSpiException {
-        if (!enabled())
-            return;
+        assert enabled();
 
         if (!busyLock.enterBusy())
             throw new IllegalStateException("Failed to process swap event (grid is stopping).");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 33a747d..ad033a7 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
@@ -75,7 +75,7 @@ public class CacheObjectImpl extends CacheObjectAdapter {
             return (T)val;
         }
         catch (IgniteCheckedException e) {
-            throw new IgniteException("Failed to unmarshal object.", e);
+            throw new IgniteException("Failed to unmarshall object.", e);
         }
 
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java
index d8da9ef..6f6f422 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheDescriptor.java
@@ -18,6 +18,8 @@
 package org.apache.ignite.internal.processors.cache;
 
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.plugin.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
@@ -56,13 +58,17 @@ public class DynamicCacheDescriptor {
     /** Template configuration flag. */
     private boolean template;
 
+    /** Cache plugin manager. */
+    private final CachePluginManager pluginMgr;
+
     /**
      * @param cacheCfg Cache configuration.
      * @param cacheType Cache type.
      * @param template {@code True} if this is template configuration.
      * @param deploymentId Deployment ID.
      */
-    public DynamicCacheDescriptor(CacheConfiguration cacheCfg,
+    public DynamicCacheDescriptor(GridKernalContext ctx,
+        CacheConfiguration cacheCfg,
         CacheType cacheType,
         boolean template,
         IgniteUuid deploymentId) {
@@ -70,6 +76,7 @@ public class DynamicCacheDescriptor {
         this.cacheType = cacheType;
         this.template = template;
         this.deploymentId = deploymentId;
+        pluginMgr = new CachePluginManager(ctx, cacheCfg);
     }
 
     /**
@@ -149,6 +156,13 @@ public class DynamicCacheDescriptor {
     }
 
     /**
+     * @return Cache plugin manager.
+     */
+    public CachePluginManager pluginManager() {
+        return pluginMgr;
+    }
+
+    /**
      * Sets cancelled flag.
      */
     public void onCancelled() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 3f4e97b..d390037 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -21,10 +21,10 @@ import org.apache.ignite.*;
 import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.affinity.*;
 import org.apache.ignite.cluster.*;
+import org.apache.ignite.compute.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.cluster.*;
-import org.apache.ignite.internal.compute.*;
 import org.apache.ignite.internal.processors.affinity.*;
 import org.apache.ignite.internal.processors.cache.affinity.*;
 import org.apache.ignite.internal.processors.cache.distributed.*;
@@ -489,7 +489,12 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
     /** {@inheritDoc} */
     @Override public boolean isEmpty() {
-        return values().isEmpty();
+        try {
+            return localSize(CachePeekModes.ONHEAP_ONLY) == 0;
+        }
+        catch (IgniteCheckedException e) {
+            throw new IgniteException(e);
+        }
     }
 
     /** {@inheritDoc} */
@@ -1083,7 +1088,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         // Clear local cache synchronously.
         clearLocally();
 
-        clearRemotes(0, new GlobalClearAllCallable(name()));
+        clearRemotes(0, null);
     }
 
     /** {@inheritDoc} */
@@ -1091,7 +1096,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         // Clear local cache synchronously.
         clearLocally(key);
 
-        clearRemotes(0, new GlobalClearKeySetCallable<K, V>(name(), Collections.singleton(key)));
+        clearRemotes(0, Collections.singleton(key));
     }
 
     /** {@inheritDoc} */
@@ -1099,83 +1104,57 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         // Clear local cache synchronously.
         clearLocallyAll(keys);
 
-        clearRemotes(0, new GlobalClearKeySetCallable<K, V>(name(), keys));
+        clearRemotes(0, keys);
     }
 
     /** {@inheritDoc} */
     @Override public IgniteInternalFuture<?> clearAsync(K key) {
-        return clearAsync(new GlobalClearKeySetCallable<K, V>(name(), Collections.singleton(key)));
+        return clearKeysAsync(Collections.singleton(key));
     }
 
     /** {@inheritDoc} */
     @Override public IgniteInternalFuture<?> clearAsync(Set<? extends K> keys) {
-        return clearAsync(new GlobalClearKeySetCallable<K, V>(name(), keys));
+        return clearKeysAsync(keys);
     }
 
     /**
      * @param timeout Timeout for clearLocally all task in milliseconds (0 for never).
      *      Set it to larger value for large caches.
-     * @param clearCall Global clear callable object.
+     * @param keys Keys to clear or {@code null} if all cache should be cleared.
      * @throws IgniteCheckedException In case of cache could not be cleared on any of the nodes.
      */
-    private void clearRemotes(long timeout, GlobalClearCallable clearCall) throws IgniteCheckedException {
-        try {
-            // Send job to remote nodes only.
-            Collection<ClusterNode> nodes =
-                ctx.grid().cluster().forCacheNodes(name(), true, true, false).forRemotes().nodes();
-
-            IgniteInternalFuture<Object> fut = null;
-
-            if (!nodes.isEmpty()) {
-                ctx.kernalContext().task().setThreadContext(TC_TIMEOUT, timeout);
+    private void clearRemotes(long timeout, @Nullable final Set<? extends K> keys) throws IgniteCheckedException {
+        // Send job to remote nodes only.
+        Collection<ClusterNode> nodes =
+            ctx.grid().cluster().forCacheNodes(name(), true, true, false).forRemotes().nodes();
 
-                fut = ctx.closures().callAsyncNoFailover(BROADCAST, clearCall, nodes, true);
-            }
+        if (!nodes.isEmpty()) {
+            ctx.kernalContext().task().setThreadContext(TC_TIMEOUT, timeout);
 
-            if (fut != null)
-                fut.get();
-        }
-        catch (ClusterGroupEmptyCheckedException ignore) {
-            if (log.isDebugEnabled())
-                log.debug("All remote nodes left while cache clearLocally [cacheName=" + name() + "]");
-        }
-        catch (ComputeTaskTimeoutCheckedException e) {
-            U.warn(log, "Timed out waiting for remote nodes to finish cache clear (consider increasing " +
-                "'networkTimeout' configuration property) [cacheName=" + name() + "]");
+            ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
 
-            throw e;
+            ctx.kernalContext().task().execute(
+                new ClearTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), keys), null).get();
         }
     }
 
     /** {@inheritDoc} */
     @Override public IgniteInternalFuture<?> clearAsync() {
-        return clearAsync(new GlobalClearAllCallable(name()));
+        return clearKeysAsync(null);
     }
 
     /**
-     * @param clearCall Global clear callable object.
+     * @param keys Keys to clear or {@code null} if all cache should be cleared.
      * @return Future.
      */
-    private IgniteInternalFuture<?> clearAsync(GlobalClearCallable clearCall) {
+    private IgniteInternalFuture<?> clearKeysAsync(final Set<? extends K> keys) {
         Collection<ClusterNode> nodes = ctx.grid().cluster().forCacheNodes(name(), true, true, false).nodes();
 
         if (!nodes.isEmpty()) {
-            IgniteInternalFuture<Object> fut =
-                ctx.closures().callAsyncNoFailover(BROADCAST, clearCall, nodes, true);
-
-            return fut.chain(new CX1<IgniteInternalFuture<Object>, Object>() {
-                @Override public Object applyx(IgniteInternalFuture<Object> fut) throws IgniteCheckedException {
-                    try {
-                        return fut.get();
-                    }
-                    catch (ClusterGroupEmptyCheckedException ignore) {
-                        if (log.isDebugEnabled())
-                            log.debug("All remote nodes left while cache clearLocally [cacheName=" + name() + "]");
+            ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
 
-                        return null;
-                    }
-                }
-            });
+            return ctx.kernalContext().task().execute(
+                new ClearTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), keys), null);
         }
         else
             return new GridFinishedFuture<>();
@@ -2715,6 +2694,22 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     }
 
     /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public void removeAll() throws IgniteCheckedException {
+        assert ctx.isLocal();
+
+        for (Iterator<KeyCacheObject> it = ctx.swap().offHeapKeyIterator(true, true, AffinityTopologyVersion.NONE);
+             it.hasNext(); )
+            remove((K)it.next());
+
+        for (Iterator<KeyCacheObject> it = ctx.swap().swapKeyIterator(true, true, AffinityTopologyVersion.NONE);
+             it.hasNext(); )
+            remove((K)it.next());
+
+        removeAll(keySet());
+    }
+
+    /** {@inheritDoc} */
     @Override public void removeAll(final Collection<? extends K> keys) throws IgniteCheckedException {
         boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
@@ -3562,7 +3557,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Integer> sizeAsync(CachePeekMode[] peekModes) {
+    @Override public IgniteInternalFuture<Integer> sizeAsync(final CachePeekMode[] peekModes) {
         assert peekModes != null;
 
         PeekModes modes = parsePeekModes(peekModes, true);
@@ -3576,22 +3571,10 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         if (nodes.isEmpty())
             return new GridFinishedFuture<>(0);
 
-        IgniteInternalFuture<Collection<Integer>> fut =
-            ctx.closures().broadcastNoFailover(new SizeCallable(ctx.name(), peekModes), null, nodes);
+        ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
 
-        return fut.chain(new CX1<IgniteInternalFuture<Collection<Integer>>, Integer>() {
-            @Override public Integer applyx(IgniteInternalFuture<Collection<Integer>> fut)
-            throws IgniteCheckedException {
-                Collection<Integer> res = fut.get();
-
-                int totalSize = 0;
-
-                for (Integer size : res)
-                    totalSize += size;
-
-                return totalSize;
-            }
-        });
+        return ctx.kernalContext().task().execute(
+            new SizeTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes), null);
     }
 
     /** {@inheritDoc} */
@@ -3818,16 +3801,6 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     }
 
     /** {@inheritDoc} */
-    @Override public Iterator<Map.Entry<K, V>> swapIterator() throws IgniteCheckedException {
-        return ctx.swap().lazySwapIterator();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator<Map.Entry<K, V>> offHeapIterator() throws IgniteCheckedException {
-        return ctx.swap().lazyOffHeapIterator();
-    }
-
-    /** {@inheritDoc} */
     @Override public long offHeapEntriesCount() {
         return ctx.swap().offHeapEntriesCount();
     }
@@ -3909,50 +3882,6 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     }
 
     /**
-     * Gets cache global size (with or without backups).
-     *
-     * @param primaryOnly {@code True} if only primary sizes should be included.
-     * @return Global size.
-     * @throws IgniteCheckedException If internal task execution failed.
-     */
-    private int globalSize(boolean primaryOnly) throws IgniteCheckedException {
-        try {
-            // Send job to remote nodes only.
-            Collection<ClusterNode> nodes = ctx.grid().cluster().forCacheNodes(name()).forRemotes().nodes();
-
-            IgniteInternalFuture<Collection<Integer>> fut = null;
-
-            if (!nodes.isEmpty()) {
-                ctx.kernalContext().task().setThreadContext(TC_TIMEOUT, gridCfg.getNetworkTimeout());
-
-                fut = ctx.closures().broadcastNoFailover(new GlobalSizeCallable(name(), primaryOnly), null, nodes);
-            }
-
-            // Get local value.
-            int globalSize = primaryOnly ? primarySize() : size();
-
-            if (fut != null) {
-                for (Integer i : fut.get())
-                    globalSize += i;
-            }
-
-            return globalSize;
-        }
-        catch (ClusterGroupEmptyCheckedException ignore) {
-            if (log.isDebugEnabled())
-                log.debug("All remote nodes left while cache clearLocally [cacheName=" + name() + "]");
-
-            return primaryOnly ? primarySize() : size();
-        }
-        catch (ComputeTaskTimeoutCheckedException e) {
-            U.warn(log, "Timed out waiting for remote nodes to finish cache clear (consider increasing " +
-                "'networkTimeout' configuration property) [cacheName=" + name() + "]");
-
-            throw e;
-        }
-    }
-
-    /**
      * @param op Cache operation.
      * @param <T> Return type.
      * @return Operation result.
@@ -3977,9 +3906,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
                 READ_COMMITTED,
                 tCfg.getDefaultTxTimeout(),
                 !ctx.skipStore(),
-                0,
-                /** group lock keys */null,
-                /** partition lock */false
+                0
             );
 
             assert tx != null;
@@ -4048,9 +3975,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
                 READ_COMMITTED,
                 ctx.kernalContext().config().getTransactionConfiguration().getDefaultTxTimeout(),
                 !ctx.skipStore(),
-                0,
-                null,
-                false);
+                0);
 
         return asyncOp(tx, op);
     }
@@ -4893,67 +4818,25 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     }
 
     /**
-     * Internal callable which performs clear operation on a cache with the given name.
-     */
-    @GridInternal
-    private static abstract class GlobalClearCallable implements Callable<Object>, Externalizable {
-        /** Cache name. */
-        protected String cacheName;
-
-        /** Injected grid instance. */
-        @IgniteInstanceResource
-        protected Ignite ignite;
-
-        /**
-         * Empty constructor for serialization.
-         */
-        public GlobalClearCallable() {
-            // No-op.
-        }
-
-        /**
-         * @param cacheName Cache name.
-         */
-        protected GlobalClearCallable(String cacheName) {
-            this.cacheName = cacheName;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            U.writeString(out, cacheName);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            cacheName = U.readString(in);
-        }
-    }
-
-    /**
      * Global clear all.
      */
     @GridInternal
-    private static class GlobalClearAllCallable extends GlobalClearCallable {
+    private static class GlobalClearAllJob extends TopologyVersionAwareJob {
         /** */
         private static final long serialVersionUID = 0L;
 
         /**
-         * Empty constructor for serialization.
-         */
-        public GlobalClearAllCallable() {
-            // No-op.
-        }
-
-        /**
          * @param cacheName Cache name.
+         * @param topVer Affinity topology version.
          */
-        private GlobalClearAllCallable(String cacheName) {
-            super(cacheName);
+        private GlobalClearAllJob(String cacheName, AffinityTopologyVersion topVer) {
+            super(cacheName, topVer);
         }
 
         /** {@inheritDoc} */
-        @Override public Object call() throws Exception {
-            ((IgniteEx)ignite).cachex(cacheName).clearLocally();
+        @Nullable @Override public Object localExecute(@Nullable IgniteInternalCache cache) {
+            if (cache != null)
+                cache.clearLocally();
 
             return null;
         }
@@ -4963,176 +4846,71 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
      * Global clear keys.
      */
     @GridInternal
-    private static class GlobalClearKeySetCallable<K, V> extends GlobalClearCallable {
+    private static class GlobalClearKeySetJob<K> extends TopologyVersionAwareJob {
         /** */
         private static final long serialVersionUID = 0L;
 
         /** Keys to remove. */
-        private Set<? extends K> keys;
-
-        /**
-         * Empty constructor for serialization.
-         */
-        public GlobalClearKeySetCallable() {
-            // No-op.
-        }
+        private final Set<? extends K> keys;
 
         /**
          * @param cacheName Cache name.
+         * @param topVer Affinity topology version.
          * @param keys Keys to clear.
          */
-        private GlobalClearKeySetCallable(String cacheName, Set<? extends K> keys) {
-            super(cacheName);
+        private GlobalClearKeySetJob(String cacheName, AffinityTopologyVersion topVer, Set<? extends K> keys) {
+            super(cacheName, topVer);
 
             this.keys = keys;
         }
 
         /** {@inheritDoc} */
-        @Override public Object call() throws Exception {
-            ((IgniteEx)ignite).<K, V>cachex(cacheName).clearLocallyAll(keys);
+        @Nullable @Override public Object localExecute(@Nullable IgniteInternalCache cache) {
+            if (cache != null)
+                cache.clearLocallyAll(keys);
 
             return null;
         }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            super.writeExternal(out);
-
-            out.writeObject(keys);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            super.readExternal(in);
-
-            keys = (Set<K>) in.readObject();
-        }
     }
 
     /**
      * Internal callable for global size calculation.
      */
     @GridInternal
-    private static class SizeCallable extends IgniteClosureX<Object, Integer> implements Externalizable {
+    private static class SizeJob extends TopologyVersionAwareJob {
         /** */
         private static final long serialVersionUID = 0L;
 
-        /** Cache name. */
-        private String cacheName;
-
         /** Peek modes. */
-        private CachePeekMode[] peekModes;
-
-        /** Injected grid instance. */
-        @IgniteInstanceResource
-        private Ignite ignite;
-
-        /**
-         * Required by {@link Externalizable}.
-         */
-        public SizeCallable() {
-            // No-op.
-        }
+        private final CachePeekMode[] peekModes;
 
         /**
          * @param cacheName Cache name.
+         * @param topVer Affinity topology version.
          * @param peekModes Cache peek modes.
          */
-        private SizeCallable(String cacheName, CachePeekMode[] peekModes) {
-            this.cacheName = cacheName;
-            this.peekModes = peekModes;
-        }
+        private SizeJob(String cacheName, AffinityTopologyVersion topVer, CachePeekMode[] peekModes) {
+            super(cacheName, topVer);
 
-        /** {@inheritDoc} */
-        @Override public Integer applyx(Object o) throws IgniteCheckedException {
-            IgniteInternalCache<Object, Object> cache = ((IgniteEx)ignite).cachex(cacheName);
-
-            assert cache != null : cacheName;
-
-            return cache.localSize(peekModes);
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings("ForLoopReplaceableByForEach")
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            U.writeString(out, cacheName);
-
-            out.writeInt(peekModes.length);
-
-            for (int i = 0; i < peekModes.length; i++)
-                U.writeEnum(out, peekModes[i]);
+            this.peekModes = peekModes;
         }
 
         /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            cacheName = U.readString(in);
-
-            int len = in.readInt();
+        @Nullable @Override public Object localExecute(@Nullable IgniteInternalCache cache) {
+            if (cache == null)
+                return 0;
 
-            peekModes = new CachePeekMode[len];
-
-            for (int i = 0; i < len; i++)
-                peekModes[i] = CachePeekMode.fromOrdinal(in.readByte());
+            try {
+                return cache.localSize(peekModes);
+            }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
         }
 
         /** {@inheritDoc} */
         public String toString() {
-            return S.toString(SizeCallable.class, this);
-        }
-    }
-
-    /**
-     * Internal callable which performs {@link IgniteInternalCache#size()} or {@link IgniteInternalCache#primarySize()}
-     * operation on a cache with the given name.
-     */
-    @GridInternal
-    private static class GlobalSizeCallable implements IgniteClosure<Object, Integer>, Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Cache name. */
-        private String cacheName;
-
-        /** Primary only flag. */
-        private boolean primaryOnly;
-
-        /** Injected grid instance. */
-        @IgniteInstanceResource
-        private Ignite ignite;
-
-        /**
-         * Empty constructor for serialization.
-         */
-        public GlobalSizeCallable() {
-            // No-op.
-        }
-
-        /**
-         * @param cacheName Cache name.
-         * @param primaryOnly Primary only flag.
-         */
-        private GlobalSizeCallable(String cacheName, boolean primaryOnly) {
-            this.cacheName = cacheName;
-            this.primaryOnly = primaryOnly;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Integer apply(Object o) {
-            IgniteInternalCache<Object, Object> cache = ((IgniteEx)ignite).cachex(cacheName);
-
-            return primaryOnly ? cache.primarySize() : cache.size();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            U.writeString(out, cacheName);
-            out.writeBoolean(primaryOnly);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            cacheName = U.readString(in);
-            primaryOnly = in.readBoolean();
+            return S.toString(SizeJob.class, this);
         }
     }
 
@@ -5697,4 +5475,209 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
             metrics.addPutAndGetTimeNanos(System.nanoTime() - start);
         }
     }
+
+    /**
+     * Delayed callable class.
+     */
+    protected static abstract class TopologyVersionAwareJob extends ComputeJobAdapter {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Injected job context. */
+        @JobContextResource
+        protected ComputeJobContext jobCtx;
+
+        /** Injected grid instance. */
+        @IgniteInstanceResource
+        protected Ignite ignite;
+
+        /** Affinity topology version. */
+        protected final AffinityTopologyVersion topVer;
+
+        /** Cache name. */
+        protected final String cacheName;
+
+        /**
+         * @param cacheName Cache name.
+         * @param topVer Affinity topology version.
+         */
+        public TopologyVersionAwareJob(String cacheName, AffinityTopologyVersion topVer) {
+            assert topVer != null;
+
+            this.cacheName = cacheName;
+            this.topVer = topVer;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public final Object execute() {
+            if (!waitAffinityReadyFuture())
+                return null;
+
+            IgniteInternalCache cache = ((IgniteKernal)ignite).context().cache().cache(cacheName);
+
+            return localExecute(cache);
+        }
+
+        /**
+         * @param cache Cache.
+         * @return Local execution result.
+         */
+        @Nullable protected abstract Object localExecute(@Nullable IgniteInternalCache cache);
+
+        /**
+         * Holds (suspends) job execution until our cache version becomes equal to remote cache's version.
+         *
+         * @return {@code True} if topology check passed.
+         */
+        private boolean waitAffinityReadyFuture() {
+            GridCacheProcessor cacheProc = ((IgniteKernal)ignite).context().cache();
+
+            AffinityTopologyVersion locTopVer = cacheProc.context().exchange().readyAffinityVersion();
+
+            if (locTopVer.compareTo(topVer) < 0) {
+                IgniteInternalFuture<?> fut = cacheProc.context().exchange().affinityReadyFuture(topVer);
+
+                if (fut != null && !fut.isDone()) {
+                    jobCtx.holdcc();
+
+                    fut.listen(new CI1<IgniteInternalFuture<?>>() {
+                        @Override
+                        public void apply(IgniteInternalFuture<?> t) {
+                            jobCtx.callcc();
+                        }
+                    });
+
+                    return false;
+                }
+            }
+
+            return true;
+        }
+    }
+
+    /**
+     * Size task.
+     */
+    private static class SizeTask extends ComputeTaskAdapter<Object, Integer> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Cache name. */
+        private final String cacheName;
+
+        /** Affinity topology version. */
+        private final AffinityTopologyVersion topVer;
+
+        /** Peek modes. */
+        private final CachePeekMode[] peekModes;
+
+        /**
+         * @param cacheName Cache name.
+         * @param topVer Affinity topology version.
+         * @param peekModes Cache peek modes.
+         */
+        public SizeTask(String cacheName, AffinityTopologyVersion topVer, CachePeekMode[] peekModes) {
+            this.cacheName = cacheName;
+            this.topVer = topVer;
+            this.peekModes = peekModes;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+            @Nullable Object arg) throws IgniteException {
+            Map<ComputeJob, ClusterNode> jobs = new HashMap();
+
+            for (ClusterNode node : subgrid)
+                jobs.put(new SizeJob(cacheName, topVer, peekModes), node);
+
+            return jobs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
+            IgniteException e = res.getException();
+
+            if (e != null) {
+                if (e instanceof ClusterTopologyException)
+                    return ComputeJobResultPolicy.WAIT;
+
+                throw new IgniteException("Remote job threw exception.", e);
+            }
+
+            return ComputeJobResultPolicy.WAIT;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Integer reduce(List<ComputeJobResult> results) throws IgniteException {
+            int size = 0;
+
+            for (ComputeJobResult res : results) {
+                if (res.getException() == null && res != null)
+                    size += res.<Integer>getData();
+            }
+
+            return size;
+        }
+    }
+
+    /**
+     * Clear task.
+     */
+    private static class ClearTask<K> extends ComputeTaskAdapter<Object, Object> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Cache name. */
+        private final String cacheName;
+
+        /** Affinity topology version. */
+        private final AffinityTopologyVersion topVer;
+
+        /** Keys to clear. */
+        private final Set<? extends K> keys;
+
+        /**
+         * @param cacheName Cache name.
+         * @param topVer Affinity topology version.
+         * @param keys Keys to clear.
+         */
+        public ClearTask(String cacheName, AffinityTopologyVersion topVer, Set<? extends K> keys) {
+            this.cacheName = cacheName;
+            this.topVer = topVer;
+            this.keys = keys;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+            @Nullable Object arg) throws IgniteException {
+            Map<ComputeJob, ClusterNode> jobs = new HashMap();
+
+            for (ClusterNode node : subgrid) {
+                jobs.put(keys == null ? new GlobalClearAllJob(cacheName, topVer) :
+                        new GlobalClearKeySetJob<K>(cacheName, topVer, keys),
+                    node);
+            }
+
+            return jobs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
+            IgniteException e = res.getException();
+
+            if (e != null) {
+                if (e instanceof ClusterTopologyException)
+                    return ComputeJobResultPolicy.WAIT;
+
+                throw new IgniteException("Remote job threw exception.", e);
+            }
+
+            return ComputeJobResultPolicy.WAIT;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteException {
+            return null;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 48dcee7..2eeaed6 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
@@ -1655,6 +1655,13 @@ public class GridCacheContext<K, V> implements Externalizable {
     }
 
     /**
+     * @return {@code True} if should use entry with offheap value pointer.
+     */
+    public boolean useOffheapEntry() {
+        return cacheCfg.getMemoryMode() == OFFHEAP_TIERED || cacheCfg.getMemoryMode() == OFFHEAP_VALUES;
+    }
+
+    /**
      * Converts temporary offheap object to heap-based.
      *
      * @param obj Object.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
index 9135c16..d565af1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
@@ -751,7 +751,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter {
             U.error(log, "Failed to evict entry from cache: " + e, ex);
         }
 
-        if (memoryMode == OFFHEAP_TIERED) {
+        if (!cctx.isNear() && memoryMode == OFFHEAP_TIERED) {
             try {
                 evict0(cctx.cache(), e, cctx.versions().next(), null, false);
             }


[14/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
index 1c02356..eb8825e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
@@ -179,9 +179,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
     /** */
     protected int txSize;
 
-    /** Group lock key, if any. */
-    protected IgniteTxKey grpLockKey;
-
     /** */
     @GridToStringExclude
     private AtomicReference<GridFutureAdapter<IgniteInternalTx>> finFut = new AtomicReference<>();
@@ -233,7 +230,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
      * @param isolation Isolation.
      * @param timeout Timeout.
      * @param txSize Transaction size.
-     * @param grpLockKey Group lock key if this is group-lock transaction.
      */
     protected IgniteTxAdapter(
         GridCacheSharedContext<?, ?> cctx,
@@ -249,7 +245,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
         boolean invalidate,
         boolean storeEnabled,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
@@ -269,7 +264,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
         this.invalidate = invalidate;
         this.storeEnabled = storeEnabled;
         this.txSize = txSize;
-        this.grpLockKey = grpLockKey;
         this.subjId = subjId;
         this.taskNameHash = taskNameHash;
 
@@ -294,7 +288,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
      * @param isolation Isolation.
      * @param timeout Timeout.
      * @param txSize Transaction size.
-     * @param grpLockKey Group lock key if this is group-lock transaction.
      */
     protected IgniteTxAdapter(
         GridCacheSharedContext<?, ?> cctx,
@@ -308,7 +301,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
         TransactionIsolation isolation,
         long timeout,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
@@ -323,7 +315,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
         this.isolation = isolation;
         this.timeout = timeout;
         this.txSize = txSize;
-        this.grpLockKey = grpLockKey;
         this.subjId = subjId;
         this.taskNameHash = taskNameHash;
 
@@ -387,30 +378,7 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
 
     /** {@inheritDoc} */
     @Override public Collection<IgniteTxEntry> optimisticLockEntries() {
-        if (!groupLock())
-            return writeEntries();
-        else {
-            if (!F.isEmpty(invalidParts)) {
-                assert invalidParts.size() == 1 : "Only one partition expected for group lock transaction " +
-                    "[tx=" + this + ", invalidParts=" + invalidParts + ']';
-                assert groupLockEntry() == null : "Group lock key should be rejected " +
-                    "[tx=" + this + ", groupLockEntry=" + groupLockEntry() + ']';
-                assert F.isEmpty(writeMap()) : "All entries should be rejected for group lock transaction " +
-                    "[tx=" + this + ", writes=" + writeMap() + ']';
-
-                return Collections.emptyList();
-            }
-
-            IgniteTxEntry grpLockEntry = groupLockEntry();
-
-            assert grpLockEntry != null || (near() && !local()):
-                "Group lock entry was not enlisted into transaction [tx=" + this +
-                ", grpLockKey=" + groupLockKey() + ']';
-
-            return grpLockEntry == null ?
-                Collections.<IgniteTxEntry>emptyList() :
-                Collections.singletonList(grpLockEntry);
-        }
+        return writeEntries();
     }
 
     /** {@inheritDoc} */
@@ -482,16 +450,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
         cctx.tm().uncommitTx(this);
     }
 
-    /**
-     * This method uses unchecked assignment to cast group lock key entry to transaction generic signature.
-     *
-     * @return Group lock tx entry.
-     */
-    @SuppressWarnings("unchecked")
-    public IgniteTxEntry groupLockEntry() {
-        return this.entry(groupLockKey());
-    }
-
     /** {@inheritDoc} */
     @Override public UUID otherNodeId() {
         return null;
@@ -603,16 +561,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
     public abstract boolean isStarted();
 
     /** {@inheritDoc} */
-    @Override public boolean groupLock() {
-        return grpLockKey != null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteTxKey groupLockKey() {
-        return grpLockKey;
-    }
-
-    /** {@inheritDoc} */
     @Override public int size() {
         return txSize;
     }
@@ -798,9 +746,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
 
         GridCacheVersion explicit = txEntry == null ? null : txEntry.explicitVersion();
 
-        assert !txEntry.groupLockEntry() || groupLock() : "Can not have group-locked tx entries in " +
-            "non-group-lock transactions [txEntry=" + txEntry + ", tx=" + this + ']';
-
         return local() && !cacheCtx.isDht() ?
             entry.lockedByThread(threadId()) || (explicit != null && entry.lockedBy(explicit)) :
             // If candidate is not there, then lock was explicit.
@@ -817,9 +762,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
 
         GridCacheVersion explicit = txEntry == null ? null : txEntry.explicitVersion();
 
-        assert !txEntry.groupLockEntry() || groupLock() : "Can not have group-locked tx entries in " +
-            "non-group-lock transactions [txEntry=" + txEntry + ", tx=" + this + ']';
-
         return local() && !cacheCtx.isDht() ?
             entry.lockedByThreadUnsafe(threadId()) || (explicit != null && entry.lockedByUnsafe(explicit)) :
             // If candidate is not there, then lock was explicit.
@@ -1008,7 +950,7 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public IgniteInternalFuture<IgniteInternalTx> currentPrepareFuture() {
+    @Nullable @Override public IgniteInternalFuture<?> currentPrepareFuture() {
         return null;
     }
 
@@ -1554,7 +1496,7 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
     /** {@inheritDoc} */
     @Override public String toString() {
         return GridToStringBuilder.toString(IgniteTxAdapter.class, this,
-            "duration", (U.currentTimeMillis() - startTime) + "ms", "grpLock", groupLock(),
+            "duration", (U.currentTimeMillis() - startTime) + "ms",
             "onePhaseCommit", onePhaseCommit);
     }
 
@@ -1779,16 +1721,6 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
         }
 
         /** {@inheritDoc} */
-        @Override public boolean groupLock() {
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @Nullable @Override public IgniteTxKey groupLockKey() {
-            throw new IllegalStateException("Deserialized transaction can only be used as read-only.");
-        }
-
-        /** {@inheritDoc} */
         @Override public boolean markPreparing() {
             throw new IllegalStateException("Deserialized transaction can only be used as read-only.");
         }
@@ -1964,7 +1896,7 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override public <K, V> GridTuple<CacheObject> peek(GridCacheContext ctx,
+        @Nullable @Override public GridTuple<CacheObject> peek(GridCacheContext ctx,
             boolean failFast,
             KeyCacheObject key,
             @Nullable CacheEntryPredicate[] filter) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
index 0d7aeaf..247d350 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
@@ -137,9 +137,6 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
     @GridDirectTransient
     private boolean locMapped;
 
-    /** Group lock entry flag. */
-    private boolean grpLock;
-
     /** Expiry policy. */
     @GridDirectTransient
     private ExpiryPolicy expiryPlc;
@@ -277,22 +274,6 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
     }
 
     /**
-     * @return {@code True} if this entry was added in group lock transaction and
-     *      this is not a group lock entry.
-     */
-    public boolean groupLockEntry() {
-        return grpLock;
-    }
-
-    /**
-     * @param grpLock {@code True} if this entry was added in group lock transaction and
-     *      this is not a group lock entry.
-     */
-    public void groupLockEntry(boolean grpLock) {
-        this.grpLock = grpLock;
-    }
-
-    /**
      * @param ctx Context.
      * @return Clean copy of this entry.
      */
@@ -311,7 +292,6 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
         cp.ttl = ttl;
         cp.conflictExpireTime = conflictExpireTime;
         cp.explicitVer = explicitVer;
-        cp.grpLock = grpLock;
         cp.conflictVer = conflictVer;
         cp.expiryPlc = expiryPlc;
         cp.flags = flags;
@@ -851,30 +831,24 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
                 writer.incrementState();
 
             case 7:
-                if (!writer.writeBoolean("grpLock", grpLock))
-                    return false;
-
-                writer.incrementState();
-
-            case 8:
                 if (!writer.writeMessage("key", key))
                     return false;
 
                 writer.incrementState();
 
-            case 9:
+            case 8:
                 if (!writer.writeByteArray("transformClosBytes", transformClosBytes))
                     return false;
 
                 writer.incrementState();
 
-            case 10:
+            case 9:
                 if (!writer.writeLong("ttl", ttl))
                     return false;
 
                 writer.incrementState();
 
-            case 11:
+            case 10:
                 if (!writer.writeMessage("val", val))
                     return false;
 
@@ -950,14 +924,6 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
                 reader.incrementState();
 
             case 7:
-                grpLock = reader.readBoolean("grpLock");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 8:
                 key = reader.readMessage("key");
 
                 if (!reader.isLastRead())
@@ -965,7 +931,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
 
                 reader.incrementState();
 
-            case 9:
+            case 8:
                 transformClosBytes = reader.readByteArray("transformClosBytes");
 
                 if (!reader.isLastRead())
@@ -973,7 +939,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
 
                 reader.incrementState();
 
-            case 10:
+            case 9:
                 ttl = reader.readLong("ttl");
 
                 if (!reader.isLastRead())
@@ -981,7 +947,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
 
                 reader.incrementState();
 
-            case 11:
+            case 10:
                 val = reader.readMessage("val");
 
                 if (!reader.isLastRead())
@@ -1001,7 +967,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 12;
+        return 11;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java
index 6b45fee..f466bf2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java
@@ -31,7 +31,6 @@ import org.apache.ignite.internal.util.future.*;
 import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.lang.*;
 import org.jetbrains.annotations.*;
 
 import java.util.*;
@@ -53,9 +52,14 @@ public class IgniteTxHandler {
     /** Shared cache context. */
     private GridCacheSharedContext<?, ?> ctx;
 
-    public IgniteInternalFuture<IgniteInternalTx> processNearTxPrepareRequest(final UUID nearNodeId,
+    /**
+     * @param nearNodeId Node ID.
+     * @param req Request.
+     * @return Prepare future.
+     */
+    public IgniteInternalFuture<?> processNearTxPrepareRequest(final UUID nearNodeId,
         final GridNearTxPrepareRequest req) {
-        return prepareTx(nearNodeId, null, req, null);
+        return prepareTx(nearNodeId, null, req);
     }
 
     /**
@@ -114,16 +118,16 @@ public class IgniteTxHandler {
             }
         });
 
-        ctx.io().addHandler(0, GridCacheOptimisticCheckPreparedTxRequest.class,
-            new CI2<UUID, GridCacheOptimisticCheckPreparedTxRequest>() {
-                @Override public void apply(UUID nodeId, GridCacheOptimisticCheckPreparedTxRequest req) {
+        ctx.io().addHandler(0, GridCacheTxRecoveryRequest.class,
+            new CI2<UUID, GridCacheTxRecoveryRequest>() {
+                @Override public void apply(UUID nodeId, GridCacheTxRecoveryRequest req) {
                     processCheckPreparedTxRequest(nodeId, req);
                 }
             });
 
-        ctx.io().addHandler(0, GridCacheOptimisticCheckPreparedTxResponse.class,
-            new CI2<UUID, GridCacheOptimisticCheckPreparedTxResponse>() {
-                @Override public void apply(UUID nodeId, GridCacheOptimisticCheckPreparedTxResponse res) {
+        ctx.io().addHandler(0, GridCacheTxRecoveryResponse.class,
+            new CI2<UUID, GridCacheTxRecoveryResponse>() {
+                @Override public void apply(UUID nodeId, GridCacheTxRecoveryResponse res) {
                     processCheckPreparedTxResponse(nodeId, res);
                 }
             });
@@ -135,29 +139,26 @@ public class IgniteTxHandler {
      * @param req Near prepare request.
      * @return Future for transaction.
      */
-    public IgniteInternalFuture<IgniteInternalTx> prepareTx(
+    public IgniteInternalFuture<GridNearTxPrepareResponse> prepareTx(
         UUID nearNodeId,
         @Nullable GridNearTxLocal locTx,
-        GridNearTxPrepareRequest req,
-        @Nullable IgniteInClosure<GridNearTxPrepareResponse> completeCb
+        GridNearTxPrepareRequest req
     ) {
         assert nearNodeId != null;
         assert req != null;
 
         if (locTx != null) {
-            assert completeCb != null;
-
             if (req.near()) {
                 // Make sure not to provide Near entries to DHT cache.
                 req.cloneEntries();
 
-                return prepareNearTx(nearNodeId, req, completeCb);
+                return prepareNearTx(nearNodeId, req);
             }
             else
-                return prepareColocatedTx(locTx, req, completeCb);
+                return prepareColocatedTx(locTx, req);
         }
         else
-            return prepareNearTx(nearNodeId, req, null);
+            return prepareNearTx(nearNodeId, req);
     }
 
     /**
@@ -167,28 +168,25 @@ public class IgniteTxHandler {
      * @param req Near prepare request.
      * @return Prepare future.
      */
-    private IgniteInternalFuture<IgniteInternalTx> prepareColocatedTx(
+    private IgniteInternalFuture<GridNearTxPrepareResponse> prepareColocatedTx(
         final GridNearTxLocal locTx,
-        final GridNearTxPrepareRequest req,
-        final IgniteInClosure<GridNearTxPrepareResponse> completeCb
+        final GridNearTxPrepareRequest req
     ) {
-
         IgniteInternalFuture<Object> fut = new GridFinishedFuture<>(); // TODO force preload keys.
 
         return new GridEmbeddedFuture<>(
             fut,
-            new C2<Object, Exception, IgniteInternalFuture<IgniteInternalTx>>() {
-                @Override public IgniteInternalFuture<IgniteInternalTx> apply(Object o, Exception ex) {
+            new C2<Object, Exception, IgniteInternalFuture<GridNearTxPrepareResponse>>() {
+                @Override public IgniteInternalFuture<GridNearTxPrepareResponse> apply(Object o, Exception ex) {
                     if (ex != null)
                         throw new GridClosureException(ex);
 
-                    IgniteInternalFuture<IgniteInternalTx> fut = locTx.prepareAsyncLocal(
+                    IgniteInternalFuture<GridNearTxPrepareResponse> fut = locTx.prepareAsyncLocal(
                         req.reads(),
                         req.writes(),
                         req.transactionNodes(),
                         req.last(),
-                        req.lastBackups(),
-                        completeCb);
+                        req.lastBackups());
 
                     if (locTx.isRollbackOnly())
                         locTx.rollbackAsync();
@@ -196,18 +194,16 @@ public class IgniteTxHandler {
                     return fut;
                 }
             },
-            new C2<IgniteInternalTx, Exception, IgniteInternalTx>() {
-                @Nullable @Override public IgniteInternalTx apply(IgniteInternalTx tx, Exception e) {
+            new C2<GridNearTxPrepareResponse, Exception, GridNearTxPrepareResponse>() {
+                @Nullable @Override public GridNearTxPrepareResponse apply(GridNearTxPrepareResponse res, Exception e) {
                     if (e != null) {
-                        // tx can be null of exception occurred.
-                        if (tx != null)
-                            tx.setRollbackOnly(); // Just in case.
+                        locTx.setRollbackOnly(); // Just in case.
 
                         if (!(e instanceof IgniteTxOptimisticCheckedException))
-                            U.error(log, "Failed to prepare DHT transaction: " + tx, e);
+                            U.error(log, "Failed to prepare transaction: " + locTx, e);
                     }
 
-                    return tx;
+                    return res;
                 }
             }
         );
@@ -220,10 +216,9 @@ public class IgniteTxHandler {
      * @param req Near prepare request.
      * @return Prepare future.
      */
-    private IgniteInternalFuture<IgniteInternalTx> prepareNearTx(
+    private IgniteInternalFuture<GridNearTxPrepareResponse> prepareNearTx(
         final UUID nearNodeId,
-        final GridNearTxPrepareRequest req,
-        IgniteInClosure<GridNearTxPrepareResponse> completeCb
+        final GridNearTxPrepareRequest req
     ) {
         ClusterNode nearNode = ctx.node(nearNodeId);
 
@@ -276,8 +271,6 @@ public class IgniteTxHandler {
                 req.isInvalidate(),
                 false,
                 req.txSize(),
-                req.groupLockKey(),
-                req.partitionLock(),
                 req.transactionNodes(),
                 req.subjectId(),
                 req.taskNameHash()
@@ -308,7 +301,7 @@ public class IgniteTxHandler {
             if (req.returnValue())
                 tx.needReturnValue(true);
 
-            IgniteInternalFuture<IgniteInternalTx> fut = tx.prepareAsync(
+            IgniteInternalFuture<GridNearTxPrepareResponse> fut = tx.prepareAsync(
                 req.reads(),
                 req.writes(),
                 req.dhtVersions(),
@@ -316,8 +309,7 @@ public class IgniteTxHandler {
                 req.miniId(),
                 req.transactionNodes(),
                 req.last(),
-                req.lastBackups(),
-                completeCb);
+                req.lastBackups());
 
             if (tx.isRollbackOnly()) {
                 try {
@@ -330,8 +322,8 @@ public class IgniteTxHandler {
 
             final GridDhtTxLocal tx0 = tx;
 
-            fut.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
-                @Override public void apply(IgniteInternalFuture<IgniteInternalTx> txFut) {
+            fut.listen(new CI1<IgniteInternalFuture<?>>() {
+                @Override public void apply(IgniteInternalFuture<?> txFut) {
                     try {
                         txFut.get();
                     }
@@ -347,7 +339,7 @@ public class IgniteTxHandler {
             return fut;
         }
         else
-            return new GridFinishedFuture<>((IgniteInternalTx)null);
+            return new GridFinishedFuture<>((GridNearTxPrepareResponse)null);
     }
 
     /**
@@ -355,7 +347,7 @@ public class IgniteTxHandler {
      * @param res Response.
      */
     private void processNearTxPrepareResponse(UUID nodeId, GridNearTxPrepareResponse res) {
-        GridNearTxPrepareFuture fut = (GridNearTxPrepareFuture)ctx.mvcc()
+        GridNearTxPrepareFutureAdapter fut = (GridNearTxPrepareFutureAdapter)ctx.mvcc()
             .<IgniteInternalTx>future(res.version(), res.futureId());
 
         if (fut == null) {
@@ -392,8 +384,7 @@ public class IgniteTxHandler {
      * @param res Response.
      */
     private void processDhtTxPrepareResponse(UUID nodeId, GridDhtTxPrepareResponse res) {
-        GridDhtTxPrepareFuture fut = (GridDhtTxPrepareFuture)ctx.mvcc().
-            <IgniteInternalTx>future(res.version(), res.futureId());
+        GridDhtTxPrepareFuture fut = (GridDhtTxPrepareFuture)ctx.mvcc().future(res.version(), res.futureId());
 
         if (fut == null) {
             if (log.isDebugEnabled())
@@ -437,6 +428,7 @@ public class IgniteTxHandler {
 
     /**
      * @param nodeId Node ID.
+     * @param locTx Local transaction.
      * @param req Request.
      * @return Future.
      */
@@ -560,8 +552,6 @@ public class IgniteTxHandler {
                             req.isInvalidate(),
                             req.storeEnabled(),
                             req.txSize(),
-                            req.groupLockKey(),
-                            false,
                             null,
                             req.subjectId(),
                             req.taskNameHash()));
@@ -1008,7 +998,6 @@ public class IgniteTxHandler {
                     req.isInvalidate(),
                     req.timeout(),
                     req.writes() != null ? Math.max(req.writes().size(), req.txSize()) : req.txSize(),
-                    req.groupLockKey(),
                     req.nearXidVersion(),
                     req.transactionNodes(),
                     req.subjectId(),
@@ -1094,6 +1083,7 @@ public class IgniteTxHandler {
     }
 
     /**
+     * @param cacheCtx Context.
      * @param key Key
      * @param ver Version.
      * @throws IgniteCheckedException If invalidate failed.
@@ -1141,7 +1131,6 @@ public class IgniteTxHandler {
                     req.timeout(),
                     req.nearWrites(),
                     req.txSize(),
-                    req.groupLockKey(),
                     req.subjectId(),
                     req.taskNameHash()
                 );
@@ -1178,12 +1167,13 @@ public class IgniteTxHandler {
      * @param req Request.
      */
     protected void processCheckPreparedTxRequest(final UUID nodeId,
-        final GridCacheOptimisticCheckPreparedTxRequest req)
+        final GridCacheTxRecoveryRequest req)
     {
         if (log.isDebugEnabled())
             log.debug("Processing check prepared transaction requests [nodeId=" + nodeId + ", req=" + req + ']');
 
-        IgniteInternalFuture<Boolean> fut = ctx.tm().txsPreparedOrCommitted(req.nearXidVersion(), req.transactions());
+        IgniteInternalFuture<Boolean> fut = req.nearTxCheck() ? ctx.tm().txCommitted(req.nearXidVersion()) :
+            ctx.tm().txsPreparedOrCommitted(req.nearXidVersion(), req.transactions());
 
         if (fut == null || fut.isDone()) {
             boolean prepared;
@@ -1225,10 +1215,10 @@ public class IgniteTxHandler {
      * @param prepared {@code True} if all transaction prepared or committed.
      */
     private void sendCheckPreparedResponse(UUID nodeId,
-        GridCacheOptimisticCheckPreparedTxRequest req,
+        GridCacheTxRecoveryRequest req,
         boolean prepared) {
-        GridCacheOptimisticCheckPreparedTxResponse res =
-            new GridCacheOptimisticCheckPreparedTxResponse(req.version(), req.futureId(), req.miniId(), prepared);
+        GridCacheTxRecoveryResponse res =
+            new GridCacheTxRecoveryResponse(req.version(), req.futureId(), req.miniId(), prepared);
 
         try {
             if (log.isDebugEnabled())
@@ -1250,11 +1240,11 @@ public class IgniteTxHandler {
      * @param nodeId Node ID.
      * @param res Response.
      */
-    protected void processCheckPreparedTxResponse(UUID nodeId, GridCacheOptimisticCheckPreparedTxResponse res) {
+    protected void processCheckPreparedTxResponse(UUID nodeId, GridCacheTxRecoveryResponse res) {
         if (log.isDebugEnabled())
             log.debug("Processing check prepared transaction response [nodeId=" + nodeId + ", res=" + res + ']');
 
-        GridCacheOptimisticCheckPreparedTxFuture fut = (GridCacheOptimisticCheckPreparedTxFuture)ctx.mvcc().
+        GridCacheTxRecoveryFuture fut = (GridCacheTxRecoveryFuture)ctx.mvcc().
             <Boolean>future(res.version(), res.futureId());
 
         if (fut == null) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
index dfce09c..d57786e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
@@ -86,9 +86,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
     /** Base for completed versions. */
     private GridCacheVersion completedBase;
 
-    /** Flag indicating partition lock in group lock transaction. */
-    private boolean partLock;
-
     /** Flag indicating that transformed values should be sent to remote nodes. */
     private boolean sndTransformedVals;
 
@@ -123,8 +120,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
      * @param isolation Isolation.
      * @param timeout Timeout.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key if this is a group-lock transaction.
-     * @param partLock {@code True} if this is a group-lock transaction and lock is acquired for whole partition.
      */
     protected IgniteTxLocalAdapter(
         GridCacheSharedContext cctx,
@@ -139,17 +134,11 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
         boolean invalidate,
         boolean storeEnabled,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
-        boolean partLock,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
         super(cctx, xidVer, implicit, implicitSingle, /*local*/true, sys, plc, concurrency, isolation, timeout,
-            invalidate, storeEnabled, txSize, grpLockKey, subjId, taskNameHash);
-
-        assert !partLock || grpLockKey != null;
-
-        this.partLock = partLock;
+            invalidate, storeEnabled, txSize, subjId, taskNameHash);
 
         minVer = xidVer;
     }
@@ -182,11 +171,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
     }
 
     /** {@inheritDoc} */
-    @Override public boolean partitionLock() {
-        return partLock;
-    }
-
-    /** {@inheritDoc} */
     @Override public Throwable commitError() {
         return commitErr.get();
     }
@@ -330,7 +314,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
 
     /** {@inheritDoc} */
     @SuppressWarnings({"RedundantTypeArguments"})
-    @Nullable @Override public <K, V> GridTuple<CacheObject> peek(
+    @Nullable @Override public GridTuple<CacheObject> peek(
         GridCacheContext cacheCtx,
         boolean failFast,
         KeyCacheObject key,
@@ -499,7 +483,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
         CacheStoreManager store = store();
 
         if (store != null && store.isWriteThrough() && storeEnabled() &&
-            (!internal() || groupLock()) && (near() || store.isWriteToStoreFromDht())) {
+            !internal() && (near() || store.isWriteToStoreFromDht())) {
             try {
                 if (writeEntries != null) {
                     Map<Object, IgniteBiTuple<Object, GridCacheVersion>> putMap = null;
@@ -679,9 +663,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
         if (!empty || colocated())
             cctx.tm().addCommittedTx(this);
 
-        if (groupLock())
-            addGroupTxMapping(writeSet());
-
         if (!empty) {
             batchStoreCommit(writeMap().values());
 
@@ -738,7 +719,9 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                                     // in order to keep near entries on backup nodes until
                                     // backup remote transaction completes.
                                     if (cacheCtx.isNear()) {
-                                        ((GridNearCacheEntry)cached).recordDhtVersion(txEntry.dhtVersion());
+                                        if (txEntry.op() == CREATE || txEntry.op() == UPDATE ||
+                                            txEntry.op() == DELETE || txEntry.op() == TRANSFORM)
+                                            ((GridNearCacheEntry)cached).recordDhtVersion(txEntry.dhtVersion());
 
                                         if ((txEntry.op() == CREATE || txEntry.op() == UPDATE) &&
                                             txEntry.conflictExpireTime() == CU.EXPIRE_TIME_CALCULATE) {
@@ -909,10 +892,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                                             log.debug("Ignoring READ entry when committing: " + txEntry);
                                     }
                                     else {
-                                        assert !groupLock() || txEntry.groupLockEntry() || ownsLock(txEntry.cached()):
-                                            "Transaction does not own lock for group lock entry during  commit [tx=" +
-                                                this + ", txEntry=" + txEntry + ']';
-
                                         if (conflictCtx == null || !conflictCtx.isUseOld()) {
                                             if (txEntry.ttl() != CU.TTL_NOT_CHANGED)
                                                 cached.updateTtl(null, txEntry.ttl());
@@ -927,7 +906,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                                 // we are not changing obsolete entries.
                                 // (innerSet and innerRemove will throw an exception
                                 // if an entry is obsolete).
-                                if (txEntry.op() != READ && !txEntry.groupLockEntry())
+                                if (txEntry.op() != READ)
                                     checkCommitLocks(cached);
 
                                 // Break out of while loop.
@@ -996,7 +975,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
         else {
             CacheStoreManager store = store();
 
-            if (store != null && (!internal() || groupLock())) {
+            if (store != null && !internal()) {
                 try {
                     store.sessionEnd(this, true);
                 }
@@ -1102,7 +1081,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                 CacheStoreManager store = store();
 
                 if (store != null && (near() || store.isWriteToStoreFromDht())) {
-                    if (!internal() || groupLock())
+                    if (!internal())
                         store.sessionEnd(this, false);
                 }
             }
@@ -1152,8 +1131,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
 
         cacheCtx.checkSecurity(SecurityPermission.CACHE_READ);
 
-        groupLockSanityCheck(cacheCtx, keys);
-
         boolean single = keysCnt == 1;
 
         Collection<KeyCacheObject> lockKeys = null;
@@ -1185,7 +1162,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                         cacheCtx.addResult(map, key, val, skipVals, keepCacheObjects, deserializePortable, false);
                 }
                 else {
-                    assert txEntry.op() == TRANSFORM || (groupLock() && !txEntry.groupLockEntry());
+                    assert txEntry.op() == TRANSFORM;
 
                     while (true) {
                         try {
@@ -1263,7 +1240,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
 
                         CacheObject val = null;
 
-                        if (!pessimistic() || readCommitted() || groupLock() && !skipVals) {
+                        if (!pessimistic() || readCommitted() && !skipVals) {
                             IgniteCacheExpiryPolicy accessPlc =
                                 optimistic() ? accessPolicy(cacheCtx, txKey, expiryPlc) : null;
 
@@ -1311,8 +1288,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                                 null,
                                 skipStore);
 
-                            if (groupLock())
-                                txEntry.groupLockEntry(true);
 
                             // As optimization, mark as checked immediately
                             // for non-pessimistic if value is not null.
@@ -1527,7 +1502,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                             nextVer = cctx.versions().next(topologyVersion());
 
                         while (true) {
-                            assert txEntry != null || readCommitted() || groupLock() || skipVals;
+                            assert txEntry != null || readCommitted() || skipVals;
 
                             GridCacheEntryEx e = txEntry == null ? entryEx(cacheCtx, txKey) : txEntry.cached();
 
@@ -1544,8 +1519,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                                         log.debug("Got removed entry in transaction getAll method " +
                                             "(will try again): " + e);
 
-                                    if (pessimistic() && !readCommitted() && !isRollbackOnly() &&
-                                        (!groupLock() || F.eq(e.key(), groupLockKey()))) {
+                                    if (pessimistic() && !readCommitted() && !isRollbackOnly()) {
                                         U.error(log, "Inconsistent transaction state (entry got removed while " +
                                             "holding lock) [entry=" + e + ", tx=" + IgniteTxLocalAdapter.this + "]");
 
@@ -1563,7 +1537,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                                 // In pessimistic mode, we should always be able to set.
                                 assert set || !pessimistic();
 
-                                if (readCommitted() || groupLock() || skipVals) {
+                                if (readCommitted() || skipVals) {
                                     cacheCtx.evicts().touch(e, topologyVersion());
 
                                     if (visibleVal != null) {
@@ -1654,7 +1628,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                 return new GridFinishedFuture<>(retMap);
 
             // Handle locks.
-            if (pessimistic() && !readCommitted() && !groupLock() && !skipVals) {
+            if (pessimistic() && !readCommitted() && !skipVals) {
                 if (expiryPlc == null)
                     expiryPlc = cacheCtx.expiry();
 
@@ -1760,7 +1734,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                             }
                         }
 
-                        if (!missed.isEmpty() && (cacheCtx.isReplicated() || cacheCtx.isLocal())) {
+                        if (!missed.isEmpty() && cacheCtx.isLocal()) {
                             return checkMissed(cacheCtx,
                                 retMap,
                                 missed,
@@ -1811,7 +1785,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                 }
             }
             else {
-                assert optimistic() || readCommitted() || groupLock() || skipVals;
+                assert optimistic() || readCommitted() || skipVals;
 
                 final Collection<KeyCacheObject> redos = new ArrayList<>();
 
@@ -2036,11 +2010,9 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
             if (invokeMap != null)
                 transform = true;
 
-            groupLockSanityCheck(cacheCtx, keys);
-
             for (Object key : keys) {
                 if (key == null) {
-                    setRollbackOnly();
+                    rollback();
 
                     throw new NullPointerException("Null key.");
                 }
@@ -2191,15 +2163,12 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                                 drVer,
                                 skipStore);
 
-                            if (!implicit() && readCommitted())
+                            if (!implicit() && readCommitted() && !cacheCtx.offheapTiered())
                                 cacheCtx.evicts().touch(entry, topologyVersion());
 
-                            if (groupLock() && !lockOnly)
-                                txEntry.groupLockEntry(true);
-
                             enlisted.add(cacheKey);
 
-                            if ((!pessimistic() && !implicit()) || (groupLock() && !lockOnly)) {
+                            if (!pessimistic() && !implicit()) {
                                 txEntry.markValid();
 
                                 if (old == null) {
@@ -2644,7 +2613,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                 null,
                 opCtx != null && opCtx.skipStore());
 
-            if (pessimistic() && !groupLock()) {
+            if (pessimistic()) {
                 // Loose all skipped.
                 final Set<KeyCacheObject> loaded = loadFut.get();
 
@@ -2867,7 +2836,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
             // Acquire locks only after having added operation to the write set.
             // Otherwise, during rollback we will not know whether locks need
             // to be rolled back.
-            if (pessimistic() && !groupLock()) {
+            if (pessimistic()) {
                 // Loose all skipped.
                 final Collection<KeyCacheObject> passedKeys = F.view(enlisted, F0.notIn(loadFut.get()));
 
@@ -2934,19 +2903,17 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
                     assert loadFut.isDone();
 
                     return nonInterruptable(commitAsync().chain(new CX1<IgniteInternalFuture<IgniteInternalTx>, GridCacheReturn>() {
-                        @Override
-                        public GridCacheReturn applyx(IgniteInternalFuture<IgniteInternalTx> txFut)
+                        @Override public GridCacheReturn applyx(IgniteInternalFuture<IgniteInternalTx> txFut)
                             throws IgniteCheckedException {
                             txFut.get();
 
-                            return (GridCacheReturn)implicitRes;
+                            return implicitRes;
                         }
                     }));
                 }
                 else
                     return nonInterruptable(loadFut.chain(new CX1<IgniteInternalFuture<Set<KeyCacheObject>>, GridCacheReturn>() {
-                        @Override
-                        public GridCacheReturn applyx(IgniteInternalFuture<Set<KeyCacheObject>> f)
+                        @Override public GridCacheReturn applyx(IgniteInternalFuture<Set<KeyCacheObject>> f)
                             throws IgniteCheckedException {
                             f.get();
 
@@ -2987,108 +2954,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
     }
 
     /**
-     * Adds key mapping to transaction.
-     * @param keys Keys to add.
-     */
-    protected void addGroupTxMapping(Collection<IgniteTxKey> keys) {
-        // No-op. This method is overriden in transactions that store key to remote node mapping
-        // for commit.
-    }
-
-    /**
-     * Checks that affinity keys are enlisted in group transaction on start.
-     *
-     * @param cacheCtx Cache context.
-     * @param keys Keys to check.
-     * @throws IgniteCheckedException If sanity check failed.
-     */
-    private <K> void groupLockSanityCheck(GridCacheContext cacheCtx, Iterable<? extends K> keys)
-        throws IgniteCheckedException
-    {
-        if (groupLock() && cctx.kernalContext().config().isCacheSanityCheckEnabled()) {
-            // Note that affinity is called without mapper on purpose.
-            int affinityPart = cacheCtx.config().getAffinity().partition(grpLockKey.key());
-
-            for (K key : keys) {
-                if (partitionLock()) {
-                    int part = cacheCtx.affinity().partition(key);
-
-                    if (affinityPart != part)
-                        throw new IgniteCheckedException("Failed to enlist key into group-lock transaction (given " +
-                            "key does not belong to locked partition) [key=" + key + ", affinityPart=" + affinityPart +
-                            ", part=" + part + ", groupLockKey=" + grpLockKey + ']');
-                }
-                else {
-                    KeyCacheObject cacheKey =
-                        cacheCtx.toCacheKeyObject(cacheCtx.config().getAffinityMapper().affinityKey(key));
-
-                    IgniteTxKey affinityKey = cacheCtx.txKey(cacheKey);
-
-                    if (!grpLockKey.equals(affinityKey))
-                        throw new IgniteCheckedException("Failed to enlist key into group-lock transaction (affinity key was " +
-                            "not enlisted to transaction on start) [key=" + key + ", affinityKey=" + affinityKey +
-                            ", groupLockKey=" + grpLockKey + ']');
-                }
-            }
-        }
-    }
-
-    /**
-     * Performs keys locking for affinity-based group lock transactions.
-     * @return Lock future.
-     */
-    @Override public <K> IgniteInternalFuture<?> groupLockAsync(GridCacheContext cacheCtx, Collection<K> keys) {
-        assert groupLock();
-
-        try {
-            init();
-
-            GridCacheReturn ret = new GridCacheReturn(localResult(), false);
-
-            Collection<KeyCacheObject> enlisted = new ArrayList<>();
-
-            Set<KeyCacheObject> skipped = enlistWrite(
-                cacheCtx,
-                keys,
-                /** cached entry */null,
-                /** expiry - leave unchanged */null,
-                /** implicit */false,
-                /** lookup map */null,
-                /** invoke map */null,
-                /** invoke arguments */null,
-                /** retval */false,
-                /** lock only */true,
-                CU.empty0(),
-                ret,
-                enlisted,
-                null,
-                null,
-                cacheCtx.skipStore()
-            ).get();
-
-            // No keys should be skipped with empty filter.
-            assert F.isEmpty(skipped);
-
-            // Lock group key in pessimistic mode only.
-            return pessimistic() ?
-                cacheCtx.cache().txLockAsync(enlisted,
-                    lockTimeout(),
-                    this,
-                    false,
-                    false,
-                    isolation,
-                    isInvalidate(),
-                    -1L) :
-                new GridFinishedFuture<>();
-        }
-        catch (IgniteCheckedException e) {
-            setRollbackOnly();
-
-            return new GridFinishedFuture<Object>(e);
-        }
-    }
-
-    /**
      * Initializes read map.
      *
      * @return {@code True} if transaction was successfully  started.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalEx.java
index 61041e1..14562ab 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalEx.java
@@ -58,14 +58,9 @@ public interface IgniteTxLocalEx extends IgniteInternalTx {
     public void userRollback() throws IgniteCheckedException;
 
     /**
-     * @return Group lock entry if this is a group-lock transaction.
-     */
-    @Nullable public IgniteTxEntry groupLockEntry();
-
-    /**
      * @param cacheCtx Cache context.
      * @param keys Keys to get.
-     * @param cached Cached entry if this method is called from entry wrapper.
+     * @param cached Cached entry if this method is called from entry wrapper
      *      Cached entry is passed if and only if there is only one key in collection of keys.
      * @param deserializePortable Deserialize portable flag.
      * @param skipVals Skip values flag.
@@ -144,20 +139,6 @@ public interface IgniteTxLocalEx extends IgniteInternalTx {
         Map<KeyCacheObject, GridCacheVersion> drMap);
 
     /**
-     * Performs keys locking for affinity-based group lock transactions.
-     *
-     * @param cacheCtx Cache context.
-     * @param keys Keys to lock.
-     * @return Lock future.
-     */
-    public <K> IgniteInternalFuture<?> groupLockAsync(GridCacheContext cacheCtx, Collection<K> keys);
-
-    /**
-     * @return {@code True} if keys from the same partition are allowed to be enlisted in group-lock transaction.
-     */
-    public boolean partitionLock();
-
-    /**
      * @return Return value for
      */
     public GridCacheReturn implicitSingleResult();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
index c494602..4666cca 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
@@ -347,8 +347,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @param isolation Isolation.
      * @param timeout transaction timeout.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key if this is a group-lock transaction.
-     * @param partLock {@code True} if partition is locked.
      * @return New transaction.
      */
     public IgniteTxLocalAdapter newTx(
@@ -359,9 +357,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
         TransactionIsolation isolation,
         long timeout,
         boolean storeEnabled,
-        int txSize,
-        @Nullable IgniteTxKey grpLockKey,
-        boolean partLock) {
+        int txSize) {
         assert sysCacheCtx == null || sysCacheCtx.systemTx();
 
         UUID subjId = null; // TODO GG-9141 how to get subj ID?
@@ -379,8 +375,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             timeout,
             storeEnabled,
             txSize,
-            grpLockKey,
-            partLock,
             subjId,
             taskNameHash);
 
@@ -639,6 +633,30 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
+     * @return Any transaction associated with the current thread.
+     */
+    public IgniteInternalTx anyActiveThreadTx() {
+        long threadId = Thread.currentThread().getId();
+
+        IgniteInternalTx tx = threadMap.get(threadId);
+
+        if (tx != null && tx.topologyVersionSnapshot() != null)
+            return tx;
+
+        for (GridCacheContext cacheCtx : cctx.cache().context().cacheContexts()) {
+            if (!cacheCtx.systemTx())
+                continue;
+
+            tx = sysThreadMap.get(new TxThreadKey(threadId, cacheCtx.cacheId()));
+
+            if (tx != null && tx.topologyVersionSnapshot() != null)
+                return tx;
+        }
+
+        return null;
+    }
+
+    /**
      * @return Local transaction.
      */
     @Nullable public IgniteInternalTx localTxx() {
@@ -727,14 +745,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * @param txId Transaction ID.
-     * @return Transaction with given ID.
-     */
-    @Nullable public IgniteInternalTx txx(GridCacheVersion txId) {
-        return idMap.get(txId);
-    }
-
-    /**
      * Handles prepare stage of 2PC.
      *
      * @param tx Transaction to prepare.
@@ -1215,13 +1225,10 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             cctx.kernalContext().dataStructures().onTxCommitted(tx);
 
             // 4. Unlock write resources.
-            if (tx.groupLock())
-                unlockGroupLocks(tx);
-            else
-                unlockMultiple(tx, tx.writeEntries());
+            unlockMultiple(tx, tx.writeEntries());
 
             // 5. For pessimistic transaction, unlock read resources if required.
-            if (tx.pessimistic() && !tx.readCommitted() && !tx.groupLock())
+            if (tx.pessimistic() && !tx.readCommitted())
                 unlockMultiple(tx, tx.readEntries());
 
             // 6. Notify evictions.
@@ -1449,7 +1456,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @param tx Transaction to notify evictions for.
      */
     private void notifyEvitions(IgniteInternalTx tx) {
-        if (tx.internal() && !tx.groupLock())
+        if (tx.internal())
             return;
 
         for (IgniteTxEntry txEntry : tx.allEntries())
@@ -1625,51 +1632,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * Unlocks entries locked by group transaction.
-     *
-     * @param txx Transaction.
-     */
-    @SuppressWarnings("unchecked")
-    private void unlockGroupLocks(IgniteInternalTx txx) {
-        IgniteTxKey grpLockKey = txx.groupLockKey();
-
-        assert grpLockKey != null;
-
-        if (grpLockKey == null)
-            return;
-
-        IgniteTxEntry txEntry = txx.entry(grpLockKey);
-
-        assert txEntry != null || (txx.near() && !txx.local());
-
-        if (txEntry != null) {
-            GridCacheContext cacheCtx = txEntry.context();
-
-            // Group-locked entries must be locked.
-            while (true) {
-                try {
-                    GridCacheEntryEx entry = txEntry.cached();
-
-                    assert entry != null;
-
-                    entry.txUnlock(txx);
-
-                    break;
-                }
-                catch (GridCacheEntryRemovedException ignored) {
-                    if (log.isDebugEnabled())
-                        log.debug("Got removed entry in TM unlockGroupLocks(..) method (will retry): " + txEntry);
-
-                    GridCacheAdapter cache = cacheCtx.cache();
-
-                    // Renew cache entry.
-                    txEntry.cached(cache.entryEx(txEntry.key()));
-                }
-            }
-        }
-    }
-
-    /**
      * @param tx Owning transaction.
      * @param entries Entries to unlock.
      */
@@ -1770,6 +1732,45 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
+     * @param ver Version.
+     * @return Future for flag indicating if transactions was committed.
+     */
+    public IgniteInternalFuture<Boolean> txCommitted(GridCacheVersion ver) {
+        final GridFutureAdapter<Boolean> resFut = new GridFutureAdapter<>();
+
+        final IgniteInternalTx tx = cctx.tm().tx(ver);
+
+        if (tx != null) {
+            assert tx.near() && tx.local() : tx;
+
+            if (log.isDebugEnabled())
+                log.debug("Found near transaction, will wait for completion: " + tx);
+
+            tx.finishFuture().listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
+                @Override public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
+                    TransactionState state = tx.state();
+
+                    if (log.isDebugEnabled())
+                        log.debug("Near transaction finished with state: " + state);
+
+                    resFut.onDone(state == COMMITTED);
+                }
+            });
+
+            return resFut;
+        }
+
+        Boolean committed = completedVers.get(ver);
+
+        if (log.isDebugEnabled())
+            log.debug("Near transaction committed: " + committed);
+
+        resFut.onDone(committed != null && committed);
+
+        return resFut;
+    }
+
+    /**
      * @param nearVer Near version ID.
      * @param txNum Number of transactions.
      * @param fut Result future.
@@ -1785,7 +1786,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             if (nearVer.equals(tx.nearXidVersion())) {
                 TransactionState state = tx.state();
 
-                IgniteInternalFuture<IgniteInternalTx> prepFut = tx.currentPrepareFuture();
+                IgniteInternalFuture<?> prepFut = tx.currentPrepareFuture();
 
                 if (prepFut != null && !prepFut.isDone()) {
                     if (log.isDebugEnabled())
@@ -1797,8 +1798,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
 
                     final Collection<GridCacheVersion> processedVers0 = processedVers;
 
-                    prepFut.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
-                        @Override public void apply(IgniteInternalFuture<IgniteInternalTx> prepFut) {
+                    prepFut.listen(new CI1<IgniteInternalFuture<?>>() {
+                        @Override public void apply(IgniteInternalFuture<?> prepFut) {
                             if (log.isDebugEnabled())
                                 log.debug("Transaction prepare future finished: " + tx);
 
@@ -1900,40 +1901,12 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * Gets local transaction for pessimistic tx recovery.
-     *
-     * @param nearXidVer Near tx ID.
-     * @return Near local or colocated local transaction.
-     */
-    @Nullable public IgniteInternalTx localTxForRecovery(GridCacheVersion nearXidVer, boolean markFinalizing) {
-        // First check if we have near transaction with this ID.
-        IgniteInternalTx tx = idMap.get(nearXidVer);
-
-        if (tx == null) {
-            // Check all local transactions and mark them as waiting for recovery to prevent finish race.
-            for (IgniteInternalTx txEx : idMap.values()) {
-                if (nearXidVer.equals(txEx.nearXidVersion())) {
-                    if (!markFinalizing || !txEx.markFinalizing(RECOVERY_WAIT))
-                        tx = txEx;
-                }
-            }
-        }
-
-        // Either we found near transaction or one of transactions is being committed by user.
-        // Wait for it and send reply.
-        if (tx != null && tx.local())
-            return tx;
-
-        return null;
-    }
-
-    /**
      * Commits or rolls back prepared transaction.
      *
      * @param tx Transaction.
      * @param commit Whether transaction should be committed or rolled back.
      */
-    public void finishOptimisticTxOnRecovery(final IgniteInternalTx tx, boolean commit) {
+    public void finishTxOnRecovery(final IgniteInternalTx tx, boolean commit) {
         if (log.isDebugEnabled())
             log.debug("Finishing prepared transaction [tx=" + tx + ", commit=" + commit + ']');
 
@@ -1958,67 +1931,28 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * Commits or rolls back pessimistic transaction.
+     * Commits transaction in case when node started transaction failed, but all related
+     * transactions were prepared (invalidates transaction if it is not fully prepared).
      *
-     * @param tx Transaction to finish.
-     * @param commitInfo Commit information.
+     * @param tx Transaction.
      */
-    public void finishPessimisticTxOnRecovery(final IgniteInternalTx tx, GridCacheCommittedTxInfo commitInfo) {
-        if (!tx.markFinalizing(RECOVERY_FINISH)) {
-            if (log.isDebugEnabled())
-                log.debug("Will not try to finish pessimistic transaction (could not mark as finalizing): " + tx);
-
-            return;
-        }
-
-        if (tx instanceof GridDistributedTxRemoteAdapter) {
-            IgniteTxRemoteEx rmtTx = (IgniteTxRemoteEx)tx;
-
-            rmtTx.doneRemote(tx.xidVersion(),
-                Collections.<GridCacheVersion>emptyList(),
-                Collections.<GridCacheVersion>emptyList(),
-                Collections.<GridCacheVersion>emptyList());
-        }
-
-        try {
-            tx.prepare();
-
-            if (commitInfo != null) {
-                for (IgniteTxEntry entry : commitInfo.recoveryWrites()) {
-                    IgniteTxEntry write = tx.writeMap().get(entry.txKey());
-
-                    if (write != null) {
-                        GridCacheEntryEx cached = write.cached();
-
-                        IgniteTxEntry recovered = entry.cleanCopy(write.context());
+    public void commitIfPrepared(IgniteInternalTx tx) {
+        assert tx instanceof GridDhtTxLocal || tx instanceof GridDhtTxRemote  : tx;
+        assert !F.isEmpty(tx.transactionNodes()) : tx;
+        assert tx.nearXidVersion() != null : tx;
 
-                        if (cached == null || cached.detached())
-                            cached = write.context().cache().entryEx(entry.key(), tx.topologyVersion());
-
-                        recovered.cached(cached);
-
-                        tx.writeMap().put(entry.txKey(), recovered);
-
-                        continue;
-                    }
-
-                    // If write was not found, check read.
-                    IgniteTxEntry read = tx.readMap().remove(entry.txKey());
+        GridCacheTxRecoveryFuture fut = new GridCacheTxRecoveryFuture(
+            cctx,
+            tx,
+            tx.originatingNodeId(),
+            tx.transactionNodes());
 
-                    if (read != null)
-                        tx.writeMap().put(entry.txKey(), entry);
-                }
+        cctx.mvcc().addFuture(fut);
 
-                tx.commitAsync().listen(new CommitListener(tx));
-            }
-            else
-                tx.rollbackAsync();
-        }
-        catch (IgniteCheckedException e) {
-            U.error(log, "Failed to prepare pessimistic transaction (will invalidate): " + tx, e);
+        if (log.isDebugEnabled())
+            log.debug("Checking optimistic transaction state on remote nodes [tx=" + tx + ", fut=" + fut + ']');
 
-            salvageTx(tx);
-        }
+        fut.prepare();
     }
 
     /**
@@ -2065,11 +1999,11 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                             if (tx.state() == PREPARED)
                                 commitIfPrepared(tx);
                             else {
-                                IgniteInternalFuture<IgniteInternalTx> prepFut = tx.currentPrepareFuture();
+                                IgniteInternalFuture<?> prepFut = tx.currentPrepareFuture();
 
                                 if (prepFut != null) {
-                                    prepFut.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
-                                        @Override public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
+                                    prepFut.listen(new CI1<IgniteInternalFuture<?>>() {
+                                        @Override public void apply(IgniteInternalFuture<?> fut) {
                                             if (tx.state() == PREPARED)
                                                 commitIfPrepared(tx);
                                             else if (tx.setRollbackOnly())
@@ -2091,31 +2025,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                 cctx.kernalContext().gateway().readUnlock();
             }
         }
-
-        /**
-         * Commits optimistic transaction in case when node started transaction failed, but all related
-         * transactions were prepared (invalidates transaction if it is not fully prepared).
-         *
-         * @param tx Transaction.
-         */
-        private void commitIfPrepared(IgniteInternalTx tx) {
-            assert tx instanceof GridDhtTxLocal || tx instanceof GridDhtTxRemote  : tx;
-            assert !F.isEmpty(tx.transactionNodes()) : tx;
-            assert tx.nearXidVersion() != null : tx;
-
-            GridCacheOptimisticCheckPreparedTxFuture fut = new GridCacheOptimisticCheckPreparedTxFuture<>(
-                cctx,
-                tx,
-                evtNodeId,
-                tx.transactionNodes());
-
-            cctx.mvcc().addFuture(fut);
-
-            if (log.isDebugEnabled())
-                log.debug("Checking optimistic transaction state on remote nodes [tx=" + tx + ", fut=" + fut + ']');
-
-            fut.prepare();
-        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
index a69e033..db3d350 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
@@ -1420,6 +1420,8 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
                         GridDrType.DR_LOAD);
 
                     cctx.evicts().touch(entry, topVer);
+
+                    CU.unwindEvicts(cctx);
                 }
                 catch (GridDhtInvalidPartitionException | GridCacheEntryRemovedException ignored) {
                     // No-op.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java
index 319b696..aa6427d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java
@@ -202,7 +202,10 @@ public class IgfsDataManager extends IgfsManager {
 
     /** {@inheritDoc} */
     @Override protected void onKernalStart0() throws IgniteCheckedException {
+        igfsCtx.kernalContext().cache().getOrStartCache(igfsCtx.configuration().getDataCacheName());
         dataCachePrj = igfsCtx.kernalContext().cache().internalCache(igfsCtx.configuration().getDataCacheName());
+
+        igfsCtx.kernalContext().cache().getOrStartCache(igfsCtx.configuration().getDataCacheName());
         dataCache = igfsCtx.kernalContext().cache().internalCache(igfsCtx.configuration().getDataCacheName());
 
         metrics = igfsCtx.igfs().localMetrics();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDeleteWorker.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDeleteWorker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDeleteWorker.java
index 250b3a0..1b2d3fe 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDeleteWorker.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDeleteWorker.java
@@ -21,6 +21,7 @@ import org.apache.ignite.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.cluster.*;
 import org.apache.ignite.internal.managers.communication.*;
 import org.apache.ignite.internal.managers.eventstorage.*;
 import org.apache.ignite.internal.util.future.*;
@@ -155,6 +156,9 @@ public class IgfsDeleteWorker extends IgfsThread {
         try {
             info = meta.info(TRASH_ID);
         }
+        catch(ClusterTopologyServerNotFoundException e) {
+            LT.warn(log, e, "Server nodes not found.");
+        }
         catch (IgniteCheckedException e) {
             U.error(log, "Cannot obtain trash directory info.", e);
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java
index 35ca8bb..e33e0d4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java
@@ -108,7 +108,7 @@ public class IgfsMetaManager extends IgfsManager {
 
     /** {@inheritDoc} */
     @Override protected void onKernalStart0() throws IgniteCheckedException {
-        metaCache = igfsCtx.kernalContext().cache().cache(cfg.getMetaCacheName());
+        metaCache = igfsCtx.kernalContext().cache().getOrStartCache(cfg.getMetaCacheName());
 
         assert metaCache != null;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsUtils.java
index 2a915ec..4b0234f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsUtils.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.igfs;
 
 import org.apache.ignite.*;
 import org.apache.ignite.igfs.*;
+import org.apache.ignite.internal.cluster.*;
 import org.apache.ignite.internal.util.typedef.*;
 
 import java.lang.reflect.*;
@@ -50,9 +51,13 @@ public class IgfsUtils {
             if (err0 != null)
                 // Dealing with a kind of IGFS error, wrap it once again, preserving message and root cause.
                 err0 = newIgfsException(err0.getClass(), err0.getMessage(), err0);
-            else
-                // Unknown error nature.
-                err0 = new IgfsException("Generic IGFS error occurred.", err);
+            else {
+                if (err instanceof ClusterTopologyServerNotFoundException)
+                    err0 = new IgfsException("Cache server nodes not found.", err);
+                else
+                    // Unknown error nature.
+                    err0 = new IgfsException("Generic IGFS error occurred.", err);
+            }
         }
 
         return err0;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
index ebedadb..a99c4c0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
@@ -293,6 +293,23 @@ public class GridOffHeapProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Gets iterator over contents of the given space.
+     *
+     * @param spaceName Space name.
+     * @param c Key/value closure.
+     * @param part Partition.
+     * @return Iterator.
+     */
+    public <T> GridCloseableIterator<T> iterator(@Nullable String spaceName,
+        CX2<T2<Long, Integer>, T2<Long, Integer>, T> c, int part) {
+        assert c != null;
+
+        GridOffHeapPartitionedMap m = offheap(spaceName);
+
+        return m == null ? new GridEmptyCloseableIterator<T>() : m.iterator(c, part);
+    }
+
+    /**
      * Gets number of elements in the given space.
      *
      * @param spaceName Space name. Optional.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 fe029eb..0bb820d 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
@@ -26,6 +26,7 @@ import org.apache.ignite.internal.processors.cache.query.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.apache.ignite.spi.indexing.*;
 import org.jetbrains.annotations.*;
 
@@ -148,6 +149,22 @@ public interface GridQueryIndexing {
     public void unregisterCache(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException;
 
     /**
+     * Checks if the given class can be mapped to a simple SQL type.
+     *
+     * @param cls Class.
+     * @return {@code true} If can.
+     */
+    public boolean isSqlType(Class<?> cls);
+
+    /**
+     * Checks if the given class is GEOMETRY.
+     *
+     * @param cls Class.
+     * @return {@code true} If this is geometry.
+     */
+    public boolean isGeometryClass(Class<?> cls);
+
+    /**
      * Registers type if it was not known before or updates it otherwise.
      *
      * @param spaceName Space name.
@@ -178,8 +195,8 @@ public interface GridQueryIndexing {
      * @param expirationTime Expiration time or 0 if never expires.
      * @throws IgniteCheckedException If failed.
      */
-    public void store(@Nullable String spaceName, GridQueryTypeDescriptor type, Object key, Object val, byte[] ver,
-        long expirationTime) throws IgniteCheckedException;
+    public void store(@Nullable String spaceName, GridQueryTypeDescriptor type, CacheObject key, CacheObject val,
+        byte[] ver, long expirationTime) throws IgniteCheckedException;
 
     /**
      * Removes index entry by key.
@@ -189,7 +206,7 @@ public interface GridQueryIndexing {
      * @param val Value.
      * @throws IgniteCheckedException If failed.
      */
-    public void remove(@Nullable String spaceName, Object key, Object val) throws IgniteCheckedException;
+    public void remove(@Nullable String spaceName, CacheObject key, CacheObject val) throws IgniteCheckedException;
 
     /**
      * Will be called when entry with given key is swapped.
@@ -198,7 +215,7 @@ public interface GridQueryIndexing {
      * @param key Key.
      * @throws IgniteCheckedException If failed.
      */
-    public void onSwap(@Nullable String spaceName, Object key) throws IgniteCheckedException;
+    public void onSwap(@Nullable String spaceName, CacheObject key) throws IgniteCheckedException;
 
     /**
      * Will be called when entry with given key is unswapped.
@@ -206,10 +223,9 @@ public interface GridQueryIndexing {
      * @param spaceName Space name.
      * @param key Key.
      * @param val Value.
-     * @param valBytes Value bytes.
      * @throws IgniteCheckedException If failed.
      */
-    public void onUnswap(@Nullable String spaceName, Object key, Object val, byte[] valBytes) throws IgniteCheckedException;
+    public void onUnswap(@Nullable String spaceName, CacheObject key, CacheObject val) throws IgniteCheckedException;
 
     /**
      * Rebuilds all indexes of given type.
@@ -225,4 +241,11 @@ public interface GridQueryIndexing {
      * @return Backup filter.
      */
     public IndexingQueryFilter backupFilter();
+
+    /**
+     * Gets message factory.
+     *
+     * @return Message factory.
+     */
+    public MessageFactory messageFactory();
 }


[10/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheRemoveAllSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheRemoveAllSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheRemoveAllSelfTest.java
new file mode 100644
index 0000000..f5de96f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheRemoveAllSelfTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.testframework.*;
+
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+/**
+ * Test remove all method.
+ */
+public class CacheRemoveAllSelfTest extends GridCacheAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected long getTestTimeout() {
+        return 60000;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRemoveAll() throws Exception {
+        IgniteCache<Integer, String> cache = grid(0).cache(null);
+
+        for (int i = 0; i < 10_000; ++i)
+            cache.put(i, "val");
+
+        final AtomicInteger igniteId = new AtomicInteger(gridCount());
+
+        IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                for (int i = 0; i < 2; ++i)
+                    startGrid(igniteId.getAndIncrement());
+
+                return true;
+            }
+        }, 3, "start-node-thread");
+
+        cache.removeAll();
+
+        fut.get();
+
+        U.sleep(5000);
+
+        for (int i = 0; i < igniteId.get(); ++i) {
+            IgniteCache locCache = grid(i).cache(null);
+
+            assertEquals("Local size: " + locCache.localSize() + "\n" +
+                "On heap: " + locCache.localSize(CachePeekMode.ONHEAP) + "\n" +
+                "Off heap: " + locCache.localSize(CachePeekMode.OFFHEAP) + "\n" +
+                "Swap: " + locCache.localSize(CachePeekMode.SWAP) + "\n" +
+                "Primary: " + locCache.localSize(CachePeekMode.PRIMARY) + "\n" +
+                "Backup: " + locCache.localSize(CachePeekMode.BACKUP),
+                0, locCache.localSize());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFailoverSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFailoverSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFailoverSelfTest.java
index 4cb7365..5d9ad35 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFailoverSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFailoverSelfTest.java
@@ -25,12 +25,12 @@ import org.apache.ignite.internal.cluster.*;
 import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.spi.discovery.tcp.*;
 import org.apache.ignite.testframework.*;
 import org.apache.ignite.transactions.*;
 import org.jetbrains.annotations.*;
 
 import javax.cache.*;
-import java.util.*;
 import java.util.concurrent.atomic.*;
 
 import static org.apache.ignite.cache.CacheRebalanceMode.*;
@@ -70,6 +70,12 @@ public abstract class GridCacheAbstractFailoverSelfTest extends GridCacheAbstrac
 
         cfg.getTransactionConfiguration().setTxSerializableEnabled(true);
 
+        TcpDiscoverySpi discoSpi = (TcpDiscoverySpi)cfg.getDiscoverySpi();
+
+        discoSpi.setSocketTimeout(10_000);
+        discoSpi.setAckTimeout(10_000);
+        discoSpi.setNetworkTimeout(10_000);
+
         return cfg;
     }
 
@@ -177,11 +183,11 @@ public abstract class GridCacheAbstractFailoverSelfTest extends GridCacheAbstrac
                 info("Run topology change.");
 
                 try {
+                    String name = "new-node-" + Thread.currentThread().getName();
+
                     for (int i = 0; i < TOP_CHANGE_CNT && err.get() == null; i++) {
                         info("Topology change " + i);
 
-                        String name = UUID.randomUUID().toString();
-
                         try {
                             final Ignite g = startGrid(name);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
index 4dc371c..70d8f9c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
@@ -50,6 +50,7 @@ import static java.util.concurrent.TimeUnit.*;
 import static org.apache.ignite.cache.CacheAtomicityMode.*;
 import static org.apache.ignite.cache.CacheMemoryMode.*;
 import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.cache.CachePeekMode.*;
 import static org.apache.ignite.events.EventType.*;
 import static org.apache.ignite.testframework.GridTestUtils.*;
 import static org.apache.ignite.transactions.TransactionConcurrency.*;
@@ -121,15 +122,15 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
     /**
      * @return {@code True} if values should be stored off-heap.
      */
-    protected boolean offHeapValues() {
-        return false;
+    protected CacheMemoryMode memoryMode() {
+        return ONHEAP_TIERED;
     }
 
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        if (offHeapValues())
+        if (memoryMode() == OFFHEAP_TIERED || memoryMode() == OFFHEAP_VALUES)
             cfg.setSwapSpaceSpi(new GridTestSwapSpaceSpi());
 
         return cfg;
@@ -139,8 +140,8 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
     @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
         CacheConfiguration ccfg = super.cacheConfiguration(gridName);
 
-        if (offHeapValues()) {
-            ccfg.setMemoryMode(CacheMemoryMode.OFFHEAP_VALUES);
+        if (memoryMode() == OFFHEAP_TIERED || memoryMode() == OFFHEAP_VALUES) {
+            ccfg.setMemoryMode(memoryMode());
             ccfg.setOffHeapMaxMemory(0);
         }
 
@@ -272,7 +273,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
             // Will actually delete entry from map.
             CU.invalidate(jcache(i), "key0");
 
-            assertNull("Failed check for grid: " + i, jcache(i).localPeek("key0", CachePeekMode.ONHEAP));
+            assertNull("Failed check for grid: " + i, jcache(i).localPeek("key0", ONHEAP));
 
             Collection<String> keysCol = mapped.get(grid(i).localNode());
 
@@ -288,20 +289,20 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                 if (ctx.affinity().localNode(key, new AffinityTopologyVersion(ctx.discovery().topologyVersion())))
                     sum++;
 
-            assertEquals("Incorrect key size on cache #" + i, sum, jcache(i).localSize(CachePeekMode.ALL));
+            assertEquals("Incorrect key size on cache #" + i, sum, jcache(i).localSize(ALL));
         }
 
         for (int i = 0; i < gridCount(); i++) {
             Collection<String> keysCol = mapped.get(grid(i).localNode());
 
             assertEquals("Failed check for grid: " + i, !F.isEmpty(keysCol) ? keysCol.size() : 0,
-                jcache(i).localSize(CachePeekMode.PRIMARY));
+                jcache(i).localSize(PRIMARY));
         }
 
         int globalPrimarySize = map.size();
 
         for (int i = 0; i < gridCount(); i++)
-            assertEquals(globalPrimarySize, jcache(i).size(CachePeekMode.PRIMARY));
+            assertEquals(globalPrimarySize, jcache(i).size(PRIMARY));
 
         int times = 1;
 
@@ -313,7 +314,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         int globalSize = globalPrimarySize * times;
 
         for (int i = 0; i < gridCount(); i++)
-            assertEquals(globalSize, jcache(i).size(CachePeekMode.ALL));
+            assertEquals(globalSize, jcache(i).size(ALL));
     }
 
     /**
@@ -735,7 +736,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         assertNull(cache.get("key3"));
 
         for (int i = 0; i < gridCount(); i++)
-            assertNull("Failed for cache: " + i, jcache(i).localPeek("key3", CachePeekMode.ONHEAP));
+            assertNull("Failed for cache: " + i, jcache(i).localPeek("key3", ONHEAP));
 
         cache.remove("key1");
         cache.put("key2", 1);
@@ -750,7 +751,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         assertNull(cache.get("key3"));
 
         for (int i = 0; i < gridCount(); i++)
-            assertNull(jcache(i).localPeek("key3", CachePeekMode.ONHEAP));
+            assertNull(jcache(i).localPeek("key3", ONHEAP));
     }
 
     /**
@@ -789,7 +790,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         assertNull(cache.get("key3"));
 
         for (int i = 0; i < gridCount(); i++)
-            assertNull("Failed for cache: " + i, jcache(i).localPeek("key3", CachePeekMode.ONHEAP));
+            assertNull("Failed for cache: " + i, jcache(i).localPeek("key3", ONHEAP));
 
         cache.remove("key1");
         cache.put("key2", 1);
@@ -804,7 +805,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         assertNull(cache.get("key3"));
 
         for (int i = 0; i < gridCount(); i++)
-            assertNull(jcache(i).localPeek("key3", CachePeekMode.ONHEAP));
+            assertNull(jcache(i).localPeek("key3", ONHEAP));
     }
 
     /**
@@ -874,9 +875,9 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         Map<String, EntryProcessorResult<String>> res = cache.invokeAll(F.asSet("key1", "key2", "key3"), RMV_PROCESSOR);
 
         for (int i = 0; i < gridCount(); i++) {
-            assertNull(jcache(i).localPeek("key1", CachePeekMode.ONHEAP));
-            assertNull(jcache(i).localPeek("key2", CachePeekMode.ONHEAP));
-            assertNull(jcache(i).localPeek("key3", CachePeekMode.ONHEAP));
+            assertNull(jcache(i).localPeek("key1", ONHEAP));
+            assertNull(jcache(i).localPeek("key2", ONHEAP));
+            assertNull(jcache(i).localPeek("key3", ONHEAP));
         }
 
         assertEquals("null", res.get("key1").get());
@@ -1232,7 +1233,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         assertNull(cache.get("key3"));
 
         for (int i = 0; i < gridCount(); i++)
-            assertNull(jcache(i).localPeek("key3", CachePeekMode.ONHEAP));
+            assertNull(jcache(i).localPeek("key3", ONHEAP));
     }
 
     /**
@@ -1271,7 +1272,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         assertNull(cache.get("k1"));
 
         for (int i = 0; i < gridCount(); i++)
-            assertNull(jcache(i).localPeek("k1", CachePeekMode.ONHEAP));
+            assertNull(jcache(i).localPeek("k1", ONHEAP));
 
         final EntryProcessor<String, Integer, Integer> errProcessor = new EntryProcessor<String, Integer, Integer>() {
             @Override public Integer process(MutableEntry<String, Integer> e, Object... args) {
@@ -1692,7 +1693,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         for (int i = 0; i < gridCount(); i++) {
             info("Peek on node [i=" + i + ", id=" + grid(i).localNode().id() + ", val=" +
-                grid(i).cache(null).localPeek("key", CachePeekMode.ONHEAP) + ']');
+                grid(i).cache(null).localPeek("key", ONHEAP) + ']');
         }
 
         assertEquals((Integer)1, cache.getAndPutIfAbsent("key", 2));
@@ -2001,10 +2002,10 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         for (int i = 0; i < gridCount(); i++) {
             info("Peek key on grid [i=" + i + ", nodeId=" + grid(i).localNode().id() +
-                ", peekVal=" + grid(i).cache(null).localPeek("key", CachePeekMode.ONHEAP) + ']');
+                ", peekVal=" + grid(i).cache(null).localPeek("key", ONHEAP) + ']');
 
             info("Peek key2 on grid [i=" + i + ", nodeId=" + grid(i).localNode().id() +
-                ", peekVal=" + grid(i).cache(null).localPeek("key2", CachePeekMode.ONHEAP) + ']');
+                ", peekVal=" + grid(i).cache(null).localPeek("key2", ONHEAP) + ']');
         }
 
         assertEquals((Integer)6, cache.get("key2"));
@@ -2233,7 +2234,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      * @throws Exception If failed.
      */
     public void testDeletedEntriesFlag() throws Exception {
-        if (cacheMode() != LOCAL && cacheMode() != REPLICATED) {
+        if (cacheMode() != LOCAL && cacheMode() != REPLICATED && memoryMode() != OFFHEAP_TIERED) {
             int cnt = 3;
 
             IgniteCache<String, Integer> cache = jcache();
@@ -2288,9 +2289,9 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                 String key = String.valueOf(i);
 
                 if (grid(0).affinity(null).mapKeyToPrimaryAndBackups(key).contains(grid(g).localNode()))
-                    assertEquals((Integer)i, jcache(g).localPeek(key, CachePeekMode.ONHEAP));
+                    assertEquals((Integer)i, peek(jcache(g), key));
                 else
-                    assertNull(jcache(g).localPeek(key, CachePeekMode.ONHEAP));
+                    assertNull(peek(jcache(g), key));
             }
         }
     }
@@ -2475,6 +2476,8 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
             }
         }, NullPointerException.class, null);
 
+        assertEquals(0, grid(0).cache(null).localSize());
+
         GridTestUtils.assertThrows(log, new Callable<Void>() {
             @Override public Void call() throws Exception {
                 cache.removeAll(null);
@@ -2569,7 +2572,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         Set<String> keys = new HashSet<>(primaryKeysForCache(cache, 2));
 
         for (String key : keys)
-            assertNull(cache.localPeek(key, CachePeekMode.ONHEAP));
+            assertNull(cache.localPeek(key, ONHEAP));
 
         Map<String, Integer> vals = new HashMap<>();
 
@@ -2584,17 +2587,17 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         }
 
         for (String key : keys)
-            assertEquals(vals.get(key), cache.localPeek(key, CachePeekMode.ONHEAP));
+            assertEquals(vals.get(key), peek(cache, key));
 
         cache.clear();
 
         for (String key : keys)
-            assertNull(cache.localPeek(key, CachePeekMode.ONHEAP));
+            assertNull(peek(cache, key));
 
         loadAll(cache, keys, true);
 
         for (String key : keys)
-            assertEquals(vals.get(key), cache.localPeek(key, CachePeekMode.ONHEAP));
+            assertEquals(vals.get(key), peek(cache, key));
     }
 
     /**
@@ -2703,7 +2706,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
             try {
                 cache.clear();
 
-                assertEquals(vals.get(first), peek(cache, first));
+                assertEquals(vals.get(first), cache.localPeek(first, ONHEAP));
             }
             finally {
                 lock.unlock();
@@ -2734,14 +2737,14 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         cache.localEvict(Sets.union(ImmutableSet.of("key1", "key2"), keys));
 
-        assert cache.localSize(CachePeekMode.ONHEAP) == 0;
+        assert cache.localSize(ONHEAP) == 0;
 
         cache.clear();
 
         cache.localPromote(ImmutableSet.of("key2", "key1"));
 
-        assert cache.localPeek("key1", CachePeekMode.ONHEAP) == null;
-        assert cache.localPeek("key2", CachePeekMode.ONHEAP) == null;
+        assert cache.localPeek("key1", ONHEAP) == null;
+        assert cache.localPeek("key2", ONHEAP) == null;
     }
 
     /**
@@ -2906,13 +2909,13 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         Ignite ignite = primaryIgnite("key");
         IgniteCache<String, Integer> cache = ignite.cache(null);
 
-        assert cache.localPeek("key", CachePeekMode.ONHEAP) == null;
+        assert peek(cache, "key") == null;
 
         cache.put("key", 1);
 
         cache.replace("key", 2);
 
-        assert cache.localPeek("key", CachePeekMode.ONHEAP) == 2;
+        assertEquals(2, peek(cache, "key").intValue());
     }
 
     /**
@@ -2944,7 +2947,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                 cache.remove("key");
 
                 assertNull(cache.get("key")); // localPeek ignores transactions.
-                assertNotNull(cache.localPeek("key")); // localPeek ignores transactions.
+                assertNotNull(peek(cache, "key")); // localPeek ignores transactions.
 
                 tx.commit();
             }
@@ -2960,7 +2963,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         cache.put("key", 1);
         cache.remove("key");
 
-        assertNull(cache.localPeek("key", CachePeekMode.ONHEAP));
+        assertNull(peek(cache, "key"));
     }
 
     /**
@@ -2986,11 +2989,11 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         // Expired entry should not be swapped.
         cache.localEvict(Collections.singleton(key));
 
-        assertNull(cache.localPeek(key, CachePeekMode.ONHEAP));
+        assertNull(peek(cache, "key"));
 
         cache.localPromote(Collections.singleton(key));
 
-        assertNull(cache.localPeek(key, CachePeekMode.ONHEAP));
+        assertNull(cache.localPeek(key, ONHEAP));
 
         assertTrue(cache.localSize() == 0);
 
@@ -3021,7 +3024,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         c.put(key, 1);
 
-        assertEquals(Integer.valueOf(1), c.localPeek(key, CachePeekMode.ONHEAP));
+        assertEquals(Integer.valueOf(1), peek(c, key));
 
         int ttl = 500;
 
@@ -3031,7 +3034,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         Thread.sleep(ttl + 100);
 
-        assert c.localPeek(key, CachePeekMode.ONHEAP) == null;
+        assert peek(c, key) == null;
 
         assert c.localSize() == 0 : "Cache is not empty.";
     }
@@ -3058,7 +3061,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
             Thread.sleep(ttl + 100);
 
-            assertNull(c.localPeek(key, CachePeekMode.ONHEAP));
+            assertNull(c.localPeek(key, ONHEAP));
 
             assert c.localSize() == 0;
         }
@@ -3092,6 +3095,9 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      * @throws Exception If failed.
      */
     private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
+        if (memoryMode() == OFFHEAP_TIERED)
+            return;
+
         int ttl = 1000;
 
         final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
@@ -3361,15 +3367,15 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         cache.put(key2, 2);
         cache.put(key3, 3);
 
-        assert cache.localPeek(key1, CachePeekMode.ONHEAP) == 1;
-        assert cache.localPeek(key2, CachePeekMode.ONHEAP) == 2;
-        assert cache.localPeek(key3, CachePeekMode.ONHEAP) == 3;
+        assert peek(cache, key1) == 1;
+        assert peek(cache, key2) == 2;
+        assert peek(cache, key3) == 3;
 
         cache.localEvict(F.asList(key1, key2));
 
-        assert cache.localPeek(key1, CachePeekMode.ONHEAP) == null;
-        assert cache.localPeek(key2, CachePeekMode.ONHEAP) == null;
-        assert cache.localPeek(key3, CachePeekMode.ONHEAP) == 3;
+        assert cache.localPeek(key1, ONHEAP) == null;
+        assert cache.localPeek(key2, ONHEAP) == null;
+        assert peek(cache, key3) == 3;
 
         loadAll(cache, ImmutableSet.of(key1, key2), true);
 
@@ -3391,7 +3397,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      * @throws Exception If failed.
      */
     public void testUnswap() throws Exception {
-        GridCacheAdapter<String, Integer> cache = ((IgniteKernal)grid(0)).internalCache();
+        IgniteCache<String, Integer> cache = grid(0).cache(null);
 
         List<String> keys = primaryKeysForCache(jcache(), 3);
 
@@ -3408,17 +3414,11 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         Collection<String> locKeys = new HashSet<>();
 
-        if (cache.context().affinityNode()) {
-            locKeys.addAll(cache.primaryKeySet());
+        if (grid(0).context().cache().cache(null).context().affinityNode()) {
+            Iterable<Cache.Entry<String, Integer>> entries = cache.localEntries(PRIMARY, BACKUP);
 
-            info("Local keys (primary): " + locKeys);
-
-            locKeys.addAll(cache.keySet(new CacheEntryPredicateAdapter() {
-                @Override public boolean apply(GridCacheEntryEx e) {
-                    return grid(0).affinity(null).isBackup(grid(0).localNode(),
-                        e.key().value(e.context().cacheObjectContext(), false));
-                }
-            }));
+            for (Cache.Entry<String, Integer> entry : entries)
+                locKeys.add(entry.getKey());
 
             info("Local keys (primary + backup): " + locKeys);
         }
@@ -3444,57 +3444,67 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
             }, EVT_CACHE_OBJECT_SWAPPED, EVT_CACHE_OBJECT_UNSWAPPED);
         }
 
-        cache.evictAll(Collections.singleton(k2));
-        cache.evictAll(Collections.singleton(k3));
+        cache.localEvict(F.asList(k2, k3));
 
-        assertNotNull(cache.localPeek(k1, new CachePeekMode[] {CachePeekMode.ONHEAP, CachePeekMode.OFFHEAP}, null));
-        assertNull(cache.localPeek(k2, new CachePeekMode[] {CachePeekMode.ONHEAP, CachePeekMode.OFFHEAP}, null));
-        assertNull(cache.localPeek(k3, new CachePeekMode[] {CachePeekMode.ONHEAP, CachePeekMode.OFFHEAP}, null));
+        if (memoryMode() == OFFHEAP_TIERED) {
+            assertNotNull(cache.localPeek(k1, ONHEAP, OFFHEAP));
+            assertNotNull(cache.localPeek(k2, ONHEAP, OFFHEAP));
+            assertNotNull(cache.localPeek(k3, ONHEAP, OFFHEAP));
+        }
+        else {
+            assertNotNull(cache.localPeek(k1, ONHEAP, OFFHEAP));
+            assertNull(cache.localPeek(k2, ONHEAP, OFFHEAP));
+            assertNull(cache.localPeek(k3, ONHEAP, OFFHEAP));
+        }
 
         int cnt = 0;
 
         if (locKeys.contains(k2)) {
-            assertNull(cache.localPeek(k2, ONHEAP_PEEK_MODES, null));
+            assertNull(cache.localPeek(k2, ONHEAP_PEEK_MODES));
 
-            cache.promoteAll(Collections.singleton(k2));
+            cache.localPromote(Collections.singleton(k2));
 
-            assertEquals((Integer) 2, cache.localPeek(k2, ONHEAP_PEEK_MODES, null));
+            assertEquals((Integer) 2, cache.localPeek(k2, ONHEAP_PEEK_MODES));
 
             cnt++;
         }
         else {
-            cache.promoteAll(Collections.singleton(k2));
+            cache.localPromote(Collections.singleton(k2));
 
-            assertNull(cache.localPeek(k2, ONHEAP_PEEK_MODES, null));
+            assertNull(cache.localPeek(k2, ONHEAP_PEEK_MODES));
         }
 
         if (locKeys.contains(k3)) {
-            assertNull(cache.localPeek(k3, ONHEAP_PEEK_MODES, null));
+            assertNull(cache.localPeek(k3, ONHEAP_PEEK_MODES));
 
-            cache.promoteAll(Collections.singleton(k3));
+            cache.localPromote(Collections.singleton(k3));
 
-            assertEquals((Integer)3, cache.localPeek(k3, ONHEAP_PEEK_MODES, null));
+            assertEquals((Integer)3, cache.localPeek(k3, ONHEAP_PEEK_MODES));
 
             cnt++;
         }
         else {
-            cache.promoteAll(Collections.singleton(k3));
+            cache.localPromote(Collections.singleton(k3));
 
-            assertNull(cache.localPeek(k3, ONHEAP_PEEK_MODES, null));
+            assertNull(cache.localPeek(k3, ONHEAP_PEEK_MODES));
         }
 
-        assertEquals(cnt, swapEvts.get());
-        assertEquals(cnt, unswapEvts.get());
+        if (memoryMode() != OFFHEAP_TIERED) {
+            assertEquals(cnt, swapEvts.get());
+            assertEquals(cnt, unswapEvts.get());
+        }
 
-        cache.evictAll(Collections.singleton(k1));
+        cache.localEvict(Collections.singleton(k1));
 
         assertEquals((Integer)1, cache.get(k1));
 
         if (locKeys.contains(k1))
             cnt++;
 
-        assertEquals(cnt, swapEvts.get());
-        assertEquals(cnt, unswapEvts.get());
+        if (memoryMode() != OFFHEAP_TIERED) {
+            assertEquals(cnt, swapEvts.get());
+            assertEquals(cnt, unswapEvts.get());
+        }
 
         cache.clear();
 
@@ -3506,14 +3516,21 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         swapEvts.set(0);
         unswapEvts.set(0);
 
-        cache.evictAll(Collections.singleton(k2));
-        cache.evictAll(Collections.singleton(k3));
+        cache.localEvict(Collections.singleton(k2));
+        cache.localEvict(Collections.singleton(k3));
 
-        assertNotNull(cache.localPeek(k1, new CachePeekMode[] {CachePeekMode.ONHEAP, CachePeekMode.OFFHEAP}, null));
-        assertNull(cache.localPeek(k2, new CachePeekMode[] {CachePeekMode.ONHEAP, CachePeekMode.OFFHEAP}, null));
-        assertNull(cache.localPeek(k3, new CachePeekMode[] {CachePeekMode.ONHEAP, CachePeekMode.OFFHEAP}, null));
+        if (memoryMode() == OFFHEAP_TIERED) {
+            assertNotNull(cache.localPeek(k1, ONHEAP, OFFHEAP));
+            assertNotNull(cache.localPeek(k2, ONHEAP, OFFHEAP));
+            assertNotNull(cache.localPeek(k3, ONHEAP, OFFHEAP));
+        }
+        else {
+            assertNotNull(cache.localPeek(k1, ONHEAP, OFFHEAP));
+            assertNull(cache.localPeek(k2, ONHEAP, OFFHEAP));
+            assertNull(cache.localPeek(k3, ONHEAP, OFFHEAP));
+        }
 
-        cache.promoteAll(F.asList(k2, k3));
+        cache.localPromote(F.asSet(k2, k3));
 
         cnt = 0;
 
@@ -3523,8 +3540,10 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         if (locKeys.contains(k3))
             cnt++;
 
-        assertEquals(cnt, swapEvts.get());
-        assertEquals(cnt, unswapEvts.get());
+        if (memoryMode() != OFFHEAP_TIERED) {
+            assertEquals(cnt, swapEvts.get());
+            assertEquals(cnt, unswapEvts.get());
+        }
     }
 
     /**
@@ -3557,7 +3576,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         Thread.sleep(ttl + 100);
 
         // Peek will actually remove entry from cache.
-        assertNull(cache.localPeek(key, CachePeekMode.ONHEAP));
+        assertNull(cache.localPeek(key, ONHEAP));
 
         assert cache.localSize() == 0;
 
@@ -3654,6 +3673,13 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                         assertTrue(cache.remove("key" + i));
                 }
             });
+
+            CU.inTx(ignite(0), jcache(), concurrency, isolation, new CIX1<IgniteCache<String, Integer>>() {
+                @Override public void applyx(IgniteCache<String, Integer> cache) {
+                    for (int i = 0; i < cnt; i++)
+                        assertNull(cache.get("key" + i));
+                }
+            });
         }
     }
 
@@ -3745,6 +3771,9 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      * @throws Exception If failed.
      */
     protected void checkSize(Collection<String> keys) throws Exception {
+        if (memoryMode() == OFFHEAP_TIERED)
+            return;
+
         if (nearEnabled())
             assertEquals(keys.size(), jcache().localSize(CachePeekMode.ALL));
         else {
@@ -3768,7 +3797,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                     }
                 }
 
-                assertEquals("Incorrect size on cache #" + i, size, jcache(i).localSize(CachePeekMode.ALL));
+                assertEquals("Incorrect size on cache #" + i, size, jcache(i).localSize(ALL));
             }
         }
     }
@@ -3779,8 +3808,8 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      */
     protected void checkKeySize(Collection<String> keys) throws Exception {
         if (nearEnabled())
-            assertEquals("Invalid key size: " + jcache().localSize(CachePeekMode.ALL),
-                keys.size(), jcache().localSize(CachePeekMode.ALL));
+            assertEquals("Invalid key size: " + jcache().localSize(ALL),
+                keys.size(), jcache().localSize(ALL));
         else {
             for (int i = 0; i < gridCount(); i++) {
                 GridCacheContext<String, Integer> ctx = context(i);
@@ -3791,7 +3820,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                     if (ctx.affinity().localNode(key, ctx.discovery().topologyVersionEx()))
                         size++;
 
-                assertEquals("Incorrect key size on cache #" + i, size, jcache(i).localSize(CachePeekMode.ALL));
+                assertEquals("Incorrect key size on cache #" + i, size, jcache(i).localSize(ALL));
             }
         }
     }
@@ -4390,7 +4419,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         assertFalse(cacheSkipStore.iterator().hasNext());
         assertTrue(map.size() == 0);
-        assertTrue(cache.size(CachePeekMode.ALL) == 0);
+        assertTrue(cache.size(ALL) == 0);
 
         // putAll/removeAll from multiple nodes.
 
@@ -4479,8 +4508,8 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         assertTrue(map.containsKey(rmvKey));
 
-        assertTrue(cache.size(CachePeekMode.ALL) == 0);
-        assertTrue(cacheSkipStore.size(CachePeekMode.ALL) == 0);
+        assertTrue(cache.size(ALL) == 0);
+        assertTrue(cacheSkipStore.size(ALL) == 0);
 
         cache.remove(rmvKey);
 
@@ -4723,8 +4752,8 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         for (int i = 0; i < keys.size(); i++)
             putToStore(keys.get(i), i);
 
-        assertTrue(cacheSkipStore.size(CachePeekMode.ALL) == 0);
-        assertTrue(cache.size(CachePeekMode.ALL) == 0);
+        assertTrue(cacheSkipStore.size(ALL) == 0);
+        assertTrue(cache.size(ALL) == 0);
         assertTrue(map.size() != 0);
 
         try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
@@ -4813,8 +4842,8 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      */
     private void checkEmpty(IgniteCache<String, Integer> cache, IgniteCache<String, Integer> cacheSkipStore)
         throws Exception {
-        assertTrue(cache.size(CachePeekMode.ALL) == 0);
-        assertTrue(cacheSkipStore.size(CachePeekMode.ALL) == 0);
+        assertTrue(cache.size(ALL) == 0);
+        assertTrue(cacheSkipStore.size(ALL) == 0);
         assertTrue(map.size() == 0);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
index 342eb5a..efd0185 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
@@ -393,8 +393,8 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     @Nullable protected <K, V> V peek(IgniteCache<K, V> cache, K key) throws Exception {
-        return offheapTiered(cache) ? cache.localPeek(key, CachePeekMode.SWAP) : cache.localPeek(key,
-            CachePeekMode.ONHEAP);
+        return offheapTiered(cache) ? cache.localPeek(key, CachePeekMode.SWAP, CachePeekMode.OFFHEAP) :
+            cache.localPeek(key, CachePeekMode.ONHEAP);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapReloadSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapReloadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapReloadSelfTest.java
index 78f01f0..7d4eefc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapReloadSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapReloadSelfTest.java
@@ -24,7 +24,6 @@ import org.apache.ignite.cache.store.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.spi.discovery.tcp.*;
@@ -35,7 +34,6 @@ import org.apache.ignite.spi.swapspace.file.*;
 import org.apache.ignite.testframework.junits.common.*;
 
 import javax.cache.*;
-import javax.cache.configuration.*;
 import java.util.*;
 import java.util.concurrent.*;
 
@@ -51,6 +49,18 @@ public class GridCacheSwapReloadSelfTest extends GridCommonAbstractTest {
     /** IP finder. */
     private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
 
+    /**
+     * Creates swap space spi.
+     * @return The swap spi.
+     */
+    protected SwapSpaceSpi spi() {
+        FileSwapSpaceSpi swap = new FileSwapSpaceSpi();
+
+        swap.setWriteBufferSize(1);
+
+        return swap;
+    }
+
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
@@ -62,11 +72,9 @@ public class GridCacheSwapReloadSelfTest extends GridCommonAbstractTest {
 
         cfg.setDiscoverySpi(disco);
 
-        FileSwapSpaceSpi swap = new FileSwapSpaceSpi();
-
-        swap.setWriteBufferSize(1);
+        SwapSpaceSpi spi = spi();
 
-        cfg.setSwapSpaceSpi(swap);
+        cfg.setSwapSpaceSpi(spi);
 
         CacheConfiguration cacheCfg = defaultCacheConfiguration();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java
index a873bb0..bb449e0 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java
@@ -77,7 +77,7 @@ public abstract class IgniteCacheEntryListenerAbstractTest extends IgniteCacheAb
         super.afterTest();
 
         for (int i = 0; i < gridCount(); i++) {
-            GridContinuousProcessor proc = ((IgniteKernal)grid(i)).context().continuous();
+            GridContinuousProcessor proc = grid(i).context().continuous();
 
             ConcurrentMap<?, ?> syncMsgFuts = GridTestUtils.getFieldValue(proc, "syncMsgFuts");
 
@@ -712,7 +712,7 @@ public abstract class IgniteCacheEntryListenerAbstractTest extends IgniteCacheAb
 
         expirePlcCache.put(key, 10);
 
-        U.sleep(200);
+        U.sleep(700);
 
         if (!eagerTtl())
             assertNull(primaryCache(key, cache.getName()).get(key)); // Provoke expire event if eager ttl is disabled.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNearLockValueSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNearLockValueSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNearLockValueSelfTest.java
new file mode 100644
index 0000000..5cc9d04
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNearLockValueSelfTest.java
@@ -0,0 +1,145 @@
+/*
+ * 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.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.managers.communication.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.apache.ignite.spi.*;
+import org.apache.ignite.spi.communication.tcp.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.apache.ignite.transactions.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+
+import static org.apache.ignite.transactions.TransactionConcurrency.*;
+import static org.apache.ignite.transactions.TransactionIsolation.*;
+
+/**
+ *
+ */
+public class IgniteCacheNearLockValueSelfTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGridsMultiThreaded(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        if (getTestGridName(0).equals(gridName))
+            cfg.setClientMode(true);
+
+        cfg.setCommunicationSpi(new TestCommunicationSpi());
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDhtVersion() throws Exception {
+        CacheConfiguration<Object, Object> pCfg = new CacheConfiguration<>("partitioned");
+
+        pCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+
+        try (IgniteCache<Object, Object> cache = ignite(0).getOrCreateCache(pCfg, new NearCacheConfiguration<>())) {
+            cache.put("key1", "val1");
+
+            for (int i = 0; i < 3; i++) {
+                ((TestCommunicationSpi)ignite(0).configuration().getCommunicationSpi()).clear();
+                ((TestCommunicationSpi)ignite(1).configuration().getCommunicationSpi()).clear();
+
+                try (Transaction tx = ignite(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                    cache.get("key1");
+
+                    tx.commit();
+                }
+
+                TestCommunicationSpi comm = (TestCommunicationSpi)ignite(0).configuration().getCommunicationSpi();
+
+                assertEquals(1, comm.requests().size());
+
+                GridCacheAdapter<Object, Object> primary = ((IgniteKernal)grid(1)).internalCache("partitioned");
+
+                GridCacheEntryEx dhtEntry = primary.peekEx(primary.context().toCacheKeyObject("key1"));
+
+                assertNotNull(dhtEntry);
+
+                GridNearLockRequest req = comm.requests().iterator().next();
+
+                assertEquals(dhtEntry.version(), req.dhtVersion(0));
+
+                // Check entry version in near cache after commit.
+                GridCacheAdapter<Object, Object> near = ((IgniteKernal)grid(0)).internalCache("partitioned");
+
+                GridNearCacheEntry nearEntry = (GridNearCacheEntry)near.peekEx(near.context().toCacheKeyObject("key1"));
+
+                assertNotNull(nearEntry);
+
+                assertEquals(dhtEntry.version(), nearEntry.dhtVersion());
+            }
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TestCommunicationSpi extends TcpCommunicationSpi {
+        /** */
+        private Collection<GridNearLockRequest> reqs = new ConcurrentLinkedDeque<>();
+
+        /** {@inheritDoc} */
+        @Override public void sendMessage(ClusterNode node, Message msg) throws IgniteSpiException {
+            if (msg instanceof GridIoMessage) {
+                GridIoMessage ioMsg = (GridIoMessage)msg;
+
+                if (ioMsg.message() instanceof GridNearLockRequest)
+                    reqs.add((GridNearLockRequest)ioMsg.message());
+            }
+
+            super.sendMessage(node, msg);
+        }
+
+        /**
+         * @return Collected requests.
+         */
+        public Collection<GridNearLockRequest> requests() {
+            return reqs;
+        }
+
+        /**
+         *
+         */
+        public void clear() {
+            reqs.clear();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingErrorTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingErrorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingErrorTest.java
new file mode 100644
index 0000000..5aa0ac8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingErrorTest.java
@@ -0,0 +1,189 @@
+/*
+ *  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.cache.*;
+import org.apache.ignite.cache.query.annotations.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+
+import javax.cache.*;
+import java.io.*;
+import java.util.concurrent.atomic.*;
+
+/**
+ * Checks behavior on exception while unmarshalling key.
+ */
+public class IgniteCacheP2pUnmarshallingErrorTest extends IgniteCacheAbstractTest {
+    /** Allows to change behavior of readExternal method. */
+    protected static AtomicInteger readCnt = new AtomicInteger();
+
+    /** Iterable key. */
+    protected static int key = 0;
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 3;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
+        return CacheAtomicWriteOrderMode.PRIMARY;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        if (gridName.endsWith("0"))
+            cfg.setClientMode(true);
+
+        return cfg;
+    }
+
+    /** Test key 1. */
+    public static class TestKey implements Externalizable {
+        /** Test key 1. */
+        public TestKey(String field) {
+            this.field = field;
+        }
+
+        /** Test key 1. */
+        public TestKey() {
+        }
+
+        /** Field. */
+        @QuerySqlField(index = true)
+        private String field;
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            TestKey key = (TestKey)o;
+
+            return !(field != null ? !field.equals(key.field) : key.field != null);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return field != null ? field.hashCode() : 0;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeObject(field);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            field = (String)in.readObject();
+
+            if (readCnt.decrementAndGet() <= 0) {
+                throw new IOException("Class can not be unmarshalled");
+            }
+        }
+    }
+
+    /**
+     * Sends put atomically and handles fail.
+     */
+    protected void failAtomicPut(int k) {
+        try {
+            jcache(0).put(new TestKey(String.valueOf(k)), "");
+
+            assert false : "p2p marshalling failed, but error response was not sent";
+        }
+        catch (CacheException e) {
+            assert X.hasCause(e, IOException.class);
+        }
+
+        assert readCnt.get() == 0; //ensure we have read count as expected.
+    }
+
+    /**
+     * Sends get atomically and handles fail.
+     */
+    protected void failAtomicGet(int k) {
+        try {
+            jcache(0).get(new TestKey(String.valueOf(k)));
+
+            assert false : "p2p marshalling failed, but error response was not sent";
+        }
+        catch (CacheException e) {
+            assert X.hasCause(e, IOException.class);
+        }
+    }
+
+    /**
+     * Tests that correct response will be sent to client node in case of unmarshalling failed.
+     */
+    public void testResponseMessageOnUnmarshallingFailed() throws Exception {
+        //GridNearAtomicUpdateRequest unmarshalling failed test
+        readCnt.set(1);
+
+        failAtomicPut(++key);
+
+        //Check that cache is empty.
+        readCnt.set(Integer.MAX_VALUE);
+
+        assert jcache(0).get(new TestKey(String.valueOf(key))) == null;
+
+        //GridDhtAtomicUpdateRequest unmarshalling failed test
+        readCnt.set(2);
+
+        failAtomicPut(++key);
+
+        //Check that cache is not empty.
+        readCnt.set(Integer.MAX_VALUE);
+
+        assert jcache(0).get(new TestKey(String.valueOf(key))) != null;
+
+        //GridNearGetRequest unmarshalling failed test
+        readCnt.set(1);
+
+        failAtomicGet(++key);
+
+        //GridNearGetResponse unmarshalling failed test
+        readCnt.set(Integer.MAX_VALUE);
+
+        jcache(0).put(new TestKey(String.valueOf(++key)), "");
+
+        readCnt.set(2);
+
+        failAtomicGet(key);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingNearErrorTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingNearErrorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingNearErrorTest.java
new file mode 100644
index 0000000..732d12d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingNearErrorTest.java
@@ -0,0 +1,56 @@
+/*
+ *  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.cache.eviction.fifo.*;
+import org.apache.ignite.configuration.*;
+
+/**
+ * Checks behavior on exception while unmarshalling key.
+ */
+public class IgniteCacheP2pUnmarshallingNearErrorTest extends IgniteCacheP2pUnmarshallingErrorTest {
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return new NearCacheConfiguration();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.getCacheConfiguration()[0].setEvictMaxOverflowRatio(0);
+        cfg.getCacheConfiguration()[0].setEvictSynchronized(true);
+        cfg.getCacheConfiguration()[0].setEvictSynchronizedKeyBufferSize(1);
+        cfg.getCacheConfiguration()[0].setEvictionPolicy(new FifoEvictionPolicy(1));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testResponseMessageOnUnmarshallingFailed() throws InterruptedException {
+        //GridCacheEvictionRequest unmarshalling failed test
+        readCnt.set(5); //2 for each put
+
+        jcache(0).put(new TestKey(String.valueOf(++key)), "");
+        jcache(0).put(new TestKey(String.valueOf(++key)), "");
+
+        //Eviction request unmarshalling failed but ioManager does not hangs up.
+
+        Thread.sleep(1000); //todo: wait for eviction complete
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingRebalanceErrorTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingRebalanceErrorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingRebalanceErrorTest.java
new file mode 100644
index 0000000..49f58f9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingRebalanceErrorTest.java
@@ -0,0 +1,80 @@
+/*
+ *  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.cache.affinity.*;
+import org.apache.ignite.internal.util.typedef.*;
+
+import javax.cache.*;
+import java.io.*;
+
+/**
+ * Checks behavior on exception while unmarshalling key.
+ */
+public class IgniteCacheP2pUnmarshallingRebalanceErrorTest extends IgniteCacheP2pUnmarshallingErrorTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 2;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testResponseMessageOnUnmarshallingFailed() throws Exception {
+        //GridDhtPartitionSupplyMessage unmarshalling failed test
+        readCnt.set(Integer.MAX_VALUE);
+
+        for (int i = 0; i <= 20; i++) {
+            jcache(0).put(new TestKey(String.valueOf(++key)), "");
+        }
+
+        readCnt.set(1);
+
+        startGrid(3);
+
+        //GridDhtPartitionSupplyMessage unmarshalling failed but ioManager does not hangs up.
+
+        Thread.sleep(1000);
+
+        //GridDhtForceKeysRequest unmarshalling failed test
+        stopGrid(3);
+
+        readCnt.set(Integer.MAX_VALUE);
+
+        for (int i = 0; i <= 1000; i++) {
+            jcache(0).put(new TestKey(String.valueOf(++key)), "");
+        }
+
+        startGrid(3);
+
+        Affinity<Object> aff = affinity(grid(3).cache(null));
+
+        while (!aff.isPrimary(grid(3).localNode(), new TestKey(String.valueOf(key)))) {
+            --key;
+        }
+
+        readCnt.set(1);
+
+        try {
+            jcache(3).get(new TestKey(String.valueOf(key)));
+            assert false : "p2p marshalling failed, but error response was not sent";
+        }
+        catch (CacheException e) {
+            assert X.hasCause(e, IOException.class);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingTxErrorTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingTxErrorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingTxErrorTest.java
new file mode 100644
index 0000000..a4e2753
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingTxErrorTest.java
@@ -0,0 +1,109 @@
+/*
+ *  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.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.transactions.*;
+
+import javax.cache.*;
+import java.io.*;
+
+/**
+ * Checks behavior on exception while unmarshalling key.
+ */
+public class IgniteCacheP2pUnmarshallingTxErrorTest extends IgniteCacheP2pUnmarshallingErrorTest {
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        if (!gridName.endsWith("0"))
+            cfg.getCacheConfiguration()[0].setRebalanceDelay(-1); //allows to check GridDhtLockRequest fail.
+
+        return cfg;
+    }
+
+    /**
+     * Sends put with optimistic lock and handles fail.
+     */
+    protected void failOptimistic() {
+        try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
+
+            jcache(0).put(new TestKey(String.valueOf(++key)), "");
+
+            tx.commit();
+
+            assert false : "p2p marshalling failed, but error response was not sent";
+        }
+        catch (IgniteException e) {
+            assert X.hasCause(e, IOException.class);
+        }
+
+        assert readCnt.get() == 0; //ensure we have read count as expected.
+    }
+
+    /**
+     * Sends put with pessimistic lock and handles fail.
+     */
+    protected void failPessimictic() {
+        try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
+
+            jcache(0).put(new TestKey(String.valueOf(++key)), "");
+
+            assert false : "p2p marshalling failed, but error response was not sent";
+        }
+        catch (CacheException e) {
+            assert X.hasCause(e, IOException.class);
+        }
+
+        assert readCnt.get() == 0; //ensure we have read count as expected.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testResponseMessageOnUnmarshallingFailed() {
+        //GridNearTxPrepareRequest unmarshalling failed test
+        readCnt.set(2);
+
+        failOptimistic();
+
+        //GridDhtTxPrepareRequest unmarshalling failed test
+        readCnt.set(3);
+
+        failOptimistic();
+
+        //GridNearLockRequest unmarshalling failed test
+        readCnt.set(2);
+
+        failPessimictic();
+
+        //GridDhtLockRequest unmarshalling failed test
+        readCnt.set(3);
+
+        try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
+            jcache(0).put(new TestKey(String.valueOf(++key)), ""); //No failure at client side.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
index c2eb56f..7cd8414 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
@@ -26,6 +26,7 @@ import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.spi.*;
+import org.apache.ignite.spi.swapspace.*;
 import org.apache.ignite.spi.swapspace.file.*;
 
 import javax.cache.*;
@@ -54,11 +55,19 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
+        cfg.setSwapSpaceSpi(spi());
 
         return cfg;
     }
 
+    /**
+     * Creates a SwapSpaceSpi.
+     * @return the Spi
+     */
+    protected SwapSpaceSpi spi() {
+        return new FileSwapSpaceSpi();
+    }
+
     /** {@inheritDoc} */
     @Override protected NearCacheConfiguration nearConfiguration() {
         return null;
@@ -231,7 +240,7 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
             for (Integer key : keys)
                 cache0.put(key, val);
 
-            FileSwapSpaceSpi swap = (FileSwapSpaceSpi)ignite(nodeIdx).configuration().getSwapSpaceSpi();
+            SwapSpaceSpi swap = ignite(nodeIdx).configuration().getSwapSpaceSpi();
 
             Set<Integer> swapKeys = new HashSet<>();
 
@@ -614,7 +623,7 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
      * @return Tuple with primary and backup keys.
      */
     private T2<List<Integer>, List<Integer>> swapKeys(int nodeIdx) {
-        FileSwapSpaceSpi swap = (FileSwapSpaceSpi)ignite(nodeIdx).configuration().getSwapSpaceSpi();
+        SwapSpaceSpi swap = ignite(nodeIdx).configuration().getSwapSpaceSpi();
 
         IgniteSpiCloseableIterator<Integer> it = swap.keyIterator(SPACE_NAME, null);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
index 72b76d7..095221e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
@@ -26,6 +26,9 @@ import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.managers.discovery.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.lang.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
 import org.apache.ignite.testframework.*;
 import org.apache.ignite.testframework.junits.common.*;
 
@@ -40,6 +43,9 @@ import java.util.concurrent.atomic.*;
 @SuppressWarnings("unchecked")
 public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest {
     /** */
+    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
     private static final String DYNAMIC_CACHE_NAME = "TestDynamicCache";
 
     /** */
@@ -51,8 +57,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest {
     /** */
     public static final IgnitePredicate<ClusterNode> NODE_FILTER = new IgnitePredicate<ClusterNode>() {
         /** {@inheritDoc} */
-        @Override
-        public boolean apply(ClusterNode n) {
+        @Override public boolean apply(ClusterNode n) {
             Boolean val = n.attribute(TEST_ATTRIBUTE_NAME);
 
             return val != null && val;
@@ -78,6 +83,8 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest {
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
         cfg.setUserAttributes(F.asMap(TEST_ATTRIBUTE_NAME, testAttribute));
 
         CacheConfiguration cacheCfg = new CacheConfiguration();
@@ -157,8 +164,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest {
         futs.clear();
 
         GridTestUtils.runMultiThreaded(new Callable<Object>() {
-            @Override
-            public Object call() throws Exception {
+            @Override public Object call() throws Exception {
                 futs.add(kernal.context().cache().dynamicStopCache(DYNAMIC_CACHE_NAME));
 
                 return null;
@@ -218,8 +224,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest {
         futs.clear();
 
         GridTestUtils.runMultiThreaded(new Callable<Object>() {
-            @Override
-            public Object call() throws Exception {
+            @Override public Object call() throws Exception {
                 IgniteEx kernal = grid(ThreadLocalRandom.current().nextInt(nodeCount()));
 
                 futs.add(kernal.context().cache().dynamicStopCache(DYNAMIC_CACHE_NAME));
@@ -940,8 +945,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest {
 
                 latches[i] = new CountDownLatch(1);
                 lsnrs[i] = new IgnitePredicate<CacheEvent>() {
-                    @Override
-                    public boolean apply(CacheEvent e) {
+                    @Override public boolean apply(CacheEvent e) {
                         switch (e.type()) {
                             case EventType.EVT_CACHE_NODES_LEFT:
                                 latches[idx].countDown();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/OffHeapTieredTransactionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/OffHeapTieredTransactionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/OffHeapTieredTransactionSelfTest.java
new file mode 100644
index 0000000..671d6c4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/OffHeapTieredTransactionSelfTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.apache.ignite.transactions.*;
+
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.transactions.TransactionConcurrency.*;
+import static org.apache.ignite.transactions.TransactionIsolation.*;
+
+/**
+ * Off-heap tiered test.
+ */
+public class OffHeapTieredTransactionSelfTest extends GridCommonAbstractTest {
+    /** IP finder. */
+    private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration ccfg = defaultCacheConfiguration();
+
+        ccfg.setMemoryMode(OFFHEAP_TIERED);
+        ccfg.setAtomicityMode(TRANSACTIONAL);
+        ccfg.setOffHeapMaxMemory(0);
+        ccfg.setSwapEnabled(true);
+        ccfg.setCacheMode(REPLICATED);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(ipFinder);
+
+        cfg.setDiscoverySpi(disco);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        cfg.getTransactionConfiguration().setTxSerializableEnabled(true);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long getTestTimeout() {
+        return 30_000;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        startGrids(2);
+
+        awaitPartitionMapExchange();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception In case of error.
+     */
+    public void testPutAll() throws Exception {
+        IgniteCache<String, Integer> cache = grid(0).cache(null);
+
+        final int KEYS = 5;
+
+        Map<String, Integer> data = new LinkedHashMap<>();
+
+        for (int i = 0; i < KEYS; i++)
+            data.put("key_" + i, i);
+
+        checkPutAll(cache, data, OPTIMISTIC, READ_COMMITTED);
+
+        checkPutAll(cache, data, OPTIMISTIC, REPEATABLE_READ);
+
+        checkPutAll(cache, data, OPTIMISTIC, SERIALIZABLE);
+
+        checkPutAll(cache, data, PESSIMISTIC, READ_COMMITTED);
+
+        checkPutAll(cache, data, PESSIMISTIC, REPEATABLE_READ);
+
+        checkPutAll(cache, data, PESSIMISTIC, SERIALIZABLE);
+    }
+
+    /**
+     * @throws Exception In case of error.
+     */
+    private void checkPutAll(IgniteCache<String, Integer> cache, Map<String, Integer> data,
+        TransactionConcurrency txConcurrency, TransactionIsolation txIsolation) throws Exception {
+        IgniteTransactions txs = cache.unwrap(Ignite.class).transactions();
+
+        try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
+            cache.putAll(data);
+
+            tx.commit();
+        }
+
+        for (Map.Entry<String, Integer> entry : data.entrySet())
+            assertEquals(entry.getValue(), cache.get(entry.getKey()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLoadingConcurrentGridStartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLoadingConcurrentGridStartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLoadingConcurrentGridStartSelfTest.java
new file mode 100644
index 0000000..798494f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLoadingConcurrentGridStartSelfTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.distributed;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.store.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.jetbrains.annotations.*;
+
+import javax.cache.*;
+import javax.cache.configuration.*;
+import javax.cache.integration.*;
+import java.io.*;
+import java.util.concurrent.*;
+
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ * Tests for cache data loading during simultaneous grids start.
+ */
+public class CacheLoadingConcurrentGridStartSelfTest extends GridCommonAbstractTest {
+    /** Grids count */
+    private static int GRIDS_CNT = 5;
+
+    /** Keys count */
+    private static int KEYS_CNT = 1_000_000;
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        ccfg.setCacheMode(PARTITIONED);
+
+        ccfg.setBackups(1);
+
+        ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory(new TestCacheStoreAdapter()));
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception if failed
+     */
+    public void testLoadCacheWithDataStreamer() throws Exception {
+        IgniteInClosure<Ignite> f = new IgniteInClosure<Ignite>() {
+            @Override public void apply(Ignite grid) {
+                try (IgniteDataStreamer<Integer, String> dataStreamer = grid.dataStreamer(null)) {
+                    for (int i = 0; i < KEYS_CNT; i++)
+                        dataStreamer.addData(i, Integer.toString(i));
+                }
+            }
+        };
+
+        loadCache(f);
+    }
+
+    /**
+     * @throws Exception if failed
+     */
+    public void testLoadCacheFromStore() throws Exception {
+        loadCache(new IgniteInClosure<Ignite>() {
+            @Override public void apply(Ignite grid) {
+                grid.cache(null).loadCache(null);
+            }
+        });
+    }
+
+    /**
+     * Loads cache using closure and asserts cache size.
+     *
+     * @param f cache loading closure
+     * @throws Exception if failed
+     */
+    private void loadCache(IgniteInClosure<Ignite> f) throws Exception {
+        Ignite g0 = startGrid(0);
+
+        IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Ignite>() {
+            @Override public Ignite call() throws Exception {
+                return startGridsMultiThreaded(1, GRIDS_CNT - 1);
+            }
+        });
+
+        try {
+            f.apply(g0);
+        }
+        finally {
+            fut.get();
+        }
+
+        assertCacheSize();
+    }
+
+    /** Asserts cache size. */
+    private void assertCacheSize() {
+        IgniteCache<Integer, String> cache = grid(0).cache(null);
+
+        assertEquals(KEYS_CNT, cache.size(CachePeekMode.PRIMARY));
+
+        int total = 0;
+
+        for (int i = 0; i < GRIDS_CNT; i++)
+            total += grid(i).cache(null).localSize(CachePeekMode.PRIMARY);
+
+        assertEquals(KEYS_CNT, total);
+    }
+
+    /**
+     * Cache store adapter.
+     */
+    private static class TestCacheStoreAdapter extends CacheStoreAdapter<Integer, String> implements Serializable {
+        /** {@inheritDoc} */
+        @Override public void loadCache(IgniteBiInClosure<Integer, String> f, Object... args) {
+            for (int i = 0; i < KEYS_CNT; i++)
+                f.apply(i, Integer.toString(i));
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public String load(Integer i) throws CacheLoaderException {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Cache.Entry<? extends Integer, ? extends String> entry)
+            throws CacheWriterException {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void delete(Object o) throws CacheWriterException {
+            // No-op.
+        }
+    }
+}


[07/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/stream/socket/SocketStreamerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/stream/socket/SocketStreamerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/stream/socket/SocketStreamerSelfTest.java
new file mode 100644
index 0000000..752e43c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/stream/socket/SocketStreamerSelfTest.java
@@ -0,0 +1,315 @@
+/*
+ * 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.stream.socket;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.events.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.marshaller.*;
+import org.apache.ignite.marshaller.jdk.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.stream.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.concurrent.*;
+
+import static org.apache.ignite.events.EventType.*;
+
+/**
+ * Tests {@link SocketStreamer}.
+ */
+public class SocketStreamerSelfTest extends GridCommonAbstractTest {
+    /** IP finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** Grid count. */
+    private final static int GRID_CNT = 3;
+
+    /** Count. */
+    private static final int CNT = 500;
+
+    /** Delimiter. */
+    private static final byte[] DELIM = new byte[] {0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0};
+
+    /** Port. */
+    private static int port;
+
+    /** Ignite. */
+    private static Ignite ignite;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration() throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration();
+
+        CacheConfiguration ccfg = cacheConfiguration(cfg, null);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        return cfg;
+    }
+
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        ignite = startGrids(GRID_CNT);
+        ignite.<Integer, String>getOrCreateCache(defaultCacheConfiguration());
+
+        try (ServerSocket sock = new ServerSocket(0)) {
+            port = sock.getLocalPort();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        ignite.cache(null).clear();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSizeBasedDefaultConverter() throws Exception {
+        test(null, null, new Runnable() {
+            @Override public void run() {
+                try (Socket sock = new Socket(InetAddress.getLocalHost(), port);
+                     OutputStream os = new BufferedOutputStream(sock.getOutputStream())) {
+                    Marshaller marsh = new JdkMarshaller();
+
+                    for (int i = 0; i < CNT; i++) {
+                        byte[] msg = marsh.marshal(new Tuple(i));
+
+                        os.write(msg.length >>> 24);
+                        os.write(msg.length >>> 16);
+                        os.write(msg.length >>> 8);
+                        os.write(msg.length);
+
+                        os.write(msg);
+                    }
+                }
+                catch (IOException | IgniteCheckedException e) {
+                    throw new IgniteException(e);
+                }
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSizeBasedCustomConverter() throws Exception {
+        SocketMessageConverter<Tuple> converter = new SocketMessageConverter<Tuple>() {
+            @Override public Tuple convert(byte[] msg) {
+                int i = (msg[0] & 0xFF) << 24;
+                i |= (msg[1] & 0xFF) << 16;
+                i |= (msg[2] & 0xFF) << 8;
+                i |= msg[3] & 0xFF;
+
+                return new Tuple(i);
+            }
+        };
+
+        test(converter, null, new Runnable() {
+            @Override public void run() {
+                try(Socket sock = new Socket(InetAddress.getLocalHost(), port);
+                    OutputStream os = new BufferedOutputStream(sock.getOutputStream())) {
+
+                    for (int i = 0; i < CNT; i++) {
+                        os.write(0);
+                        os.write(0);
+                        os.write(0);
+                        os.write(4);
+
+                        os.write(i >>> 24);
+                        os.write(i >>> 16);
+                        os.write(i >>> 8);
+                        os.write(i);
+                    }
+                }
+                catch (IOException e) {
+                    throw new IgniteException(e);
+                }
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDelimiterBasedDefaultConverter() throws Exception {
+        test(null, DELIM, new Runnable() {
+            @Override public void run() {
+                try(Socket sock = new Socket(InetAddress.getLocalHost(), port);
+                    OutputStream os = new BufferedOutputStream(sock.getOutputStream())) {
+                    Marshaller marsh = new JdkMarshaller();
+
+                    for (int i = 0; i < CNT; i++) {
+                        byte[] msg = marsh.marshal(new Tuple(i));
+
+                        os.write(msg);
+                        os.write(DELIM);
+                    }
+                }
+                catch (IOException | IgniteCheckedException e) {
+                    throw new IgniteException(e);
+                }
+            }
+        });
+
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDelimiterBasedCustomConverter() throws Exception {
+        SocketMessageConverter<Tuple> converter = new SocketMessageConverter<Tuple>() {
+            @Override public Tuple convert(byte[] msg) {
+                int i = (msg[0] & 0xFF) << 24;
+                i |= (msg[1] & 0xFF) << 16;
+                i |= (msg[2] & 0xFF) << 8;
+                i |= msg[3] & 0xFF;
+
+                return new Tuple(i);
+            }
+        };
+
+        test(converter, DELIM, new Runnable() {
+            @Override public void run() {
+                try(Socket sock = new Socket(InetAddress.getLocalHost(), port);
+                    OutputStream os = new BufferedOutputStream(sock.getOutputStream())) {
+
+                    for (int i = 0; i < CNT; i++) {
+                        os.write(i >>> 24);
+                        os.write(i >>> 16);
+                        os.write(i >>> 8);
+                        os.write(i);
+
+                        os.write(DELIM);
+                    }
+                }
+                catch (IOException e) {
+                    throw new IgniteException(e);
+                }
+            }
+        });
+    }
+
+    /**
+     * @param converter Converter.
+     * @param r Runnable..
+     */
+    private void test(@Nullable SocketMessageConverter<Tuple> converter, @Nullable byte[] delim, Runnable r) throws Exception
+    {
+        SocketStreamer<Tuple, Integer, String> sockStmr = null;
+
+        try (IgniteDataStreamer<Integer, String> stmr = ignite.dataStreamer(null)) {
+
+            stmr.allowOverwrite(true);
+            stmr.autoFlushFrequency(10);
+
+            sockStmr = new SocketStreamer<>();
+
+            IgniteCache<Integer, String> cache = ignite.cache(null);
+
+            sockStmr.setIgnite(ignite);
+
+            sockStmr.setStreamer(stmr);
+
+            sockStmr.setPort(port);
+
+            sockStmr.setDelimiter(delim);
+
+            sockStmr.setTupleExtractor(new StreamTupleExtractor<Tuple, Integer, String>() {
+                @Override public Map.Entry<Integer, String> extract(Tuple msg) {
+                    return new IgniteBiTuple<>(msg.key, msg.val);
+                }
+            });
+
+            if (converter != null)
+                sockStmr.setConverter(converter);
+
+            final CountDownLatch latch = new CountDownLatch(CNT);
+
+            IgniteBiPredicate<UUID, CacheEvent> locLsnr = new IgniteBiPredicate<UUID, CacheEvent>() {
+                @Override public boolean apply(UUID uuid, CacheEvent evt) {
+                    latch.countDown();
+
+                    return true;
+                }
+            };
+
+            ignite.events(ignite.cluster().forCacheNodes(null)).remoteListen(locLsnr, null, EVT_CACHE_OBJECT_PUT);
+
+            sockStmr.start();
+
+            r.run();
+
+            latch.await();
+
+            assertEquals(CNT, cache.size(CachePeekMode.PRIMARY));
+
+            for (int i = 0; i < CNT; i++)
+                assertEquals(Integer.toString(i), cache.get(i));
+        }
+        finally {
+            if (sockStmr != null)
+                sockStmr.stop();
+        }
+
+    }
+
+    /**
+     * Tuple.
+     */
+    private static class Tuple implements Serializable {
+        /** Serial version uid. */
+        private static final long serialVersionUID = 0L;
+
+        /** Key. */
+        private final int key;
+
+        /** Value. */
+        private final String val;
+
+        /**
+         * @param key Key.
+         */
+        Tuple(int key) {
+            this.key = key;
+            this.val = Integer.toString(key);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/stream/socket/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/stream/socket/package-info.java b/modules/core/src/test/java/org/apache/ignite/stream/socket/package-info.java
new file mode 100644
index 0000000..2e28469
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/stream/socket/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Contains tests for socket streamer.
+ */
+package org.apache.ignite.stream.socket;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 2b33d7e..6382059 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -24,6 +24,7 @@ import org.apache.ignite.internal.processors.affinity.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.closure.*;
 import org.apache.ignite.internal.processors.continuous.*;
+import org.apache.ignite.internal.processors.service.*;
 import org.apache.ignite.internal.product.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.messaging.*;
@@ -47,6 +48,7 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTest(IgniteStartUpTestSuite.suite());
         suite.addTest(IgniteExternalizableSelfTestSuite.suite());
         suite.addTest(IgniteP2PSelfTestSuite.suite());
+        suite.addTest(IgniteCacheP2pUnmarshallingErrorTestSuit.suite());
 
         suite.addTest(new TestSuite(GridSelfTest.class));
         suite.addTest(new TestSuite(GridProjectionSelfTest.class));
@@ -60,6 +62,7 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTestSuite(GridProductVersionSelfTest.class);
         suite.addTestSuite(GridAffinityProcessorRendezvousSelfTest.class);
         suite.addTestSuite(GridClosureProcessorSelfTest.class);
+        suite.addTestSuite(ClosureServiceClientsNodesTest.class);
         suite.addTestSuite(GridStartStopSelfTest.class);
         suite.addTestSuite(GridProjectionForCachesSelfTest.class);
         suite.addTestSuite(GridProjectionForCachesOnDaemonNodeSelfTest.class);
@@ -72,6 +75,7 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTestSuite(GridLifecycleAwareSelfTest.class);
         suite.addTestSuite(GridMessageListenSelfTest.class);
         suite.addTestSuite(GridFailFastNodeFailureDetectionSelfTest.class);
+        suite.addTestSuite(OffHeapTieredTransactionSelfTest.class);
 
         return suite;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java
index 8918a29..0852496 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java
@@ -44,6 +44,7 @@ public class IgniteCacheEvictionSelfTestSuite extends TestSuite {
         suite.addTest(new TestSuite(GridCacheLruEvictionPolicySelfTest.class));
         suite.addTest(new TestSuite(GridCacheLruNearEvictionPolicySelfTest.class));
         suite.addTest(new TestSuite(GridCacheNearOnlyLruNearEvictionPolicySelfTest.class));
+        suite.addTest(new TestSuite(RandomEvictionPolicyCacheSizeSelfTest.class));
         suite.addTest(new TestSuite(GridCacheRandomEvictionPolicySelfTest.class));
         suite.addTest(new TestSuite(GridCacheNearEvictionSelfTest.class));
         suite.addTest(new TestSuite(GridCacheAtomicNearEvictionSelfTest.class));

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java
index 529bd23..dd3ce27 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java
@@ -54,11 +54,6 @@ public class IgniteCacheFailoverTestSuite extends TestSuite {
         suite.addTestSuite(GridCacheAtomicPrimaryWriteOrderFailoverSelfTest.class);
         suite.addTestSuite(GridCacheAtomicReplicatedFailoverSelfTest.class);
 
-        // TODO IGNITE-157.
-        // suite.addTestSuite(GridCachePartitionedFailoverSelfTest.class);
-        // suite.addTestSuite(GridCacheColocatedFailoverSelfTest.class);
-        // suite.addTestSuite(GridCacheReplicatedFailoverSelfTest.class);
-
         suite.addTestSuite(IgniteCacheAtomicNodeJoinTest.class);
         suite.addTestSuite(IgniteCacheTxNodeJoinTest.class);
         suite.addTestSuite(IgniteCacheTxFairAffinityNodeJoinTest.class);
@@ -66,6 +61,11 @@ public class IgniteCacheFailoverTestSuite extends TestSuite {
         suite.addTestSuite(IgniteCacheTxNearDisabledPutGetRestartTest.class);
         suite.addTestSuite(IgniteCacheTxNearDisabledFairAffinityPutGetRestartTest.class);
 
+        // TODO IGNITE-882.
+        //suite.addTestSuite(GridCachePartitionedFailoverSelfTest.class);
+        //suite.addTestSuite(GridCacheColocatedFailoverSelfTest.class);
+        //suite.addTestSuite(GridCacheReplicatedFailoverSelfTest.class);
+
         return suite;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java
index acf6c64..369e041 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java
@@ -60,6 +60,16 @@ public class IgniteCacheFullApiSelfTestSuite extends TestSuite {
         suite.addTestSuite(GridCacheAtomicPrimaryWriteOrderOffHeapFullApiSelfTest.class);
         suite.addTestSuite(GridCachePartitionedNearDisabledOffHeapFullApiSelfTest.class);
 
+        // One node with off-heap tiered mode.
+        suite.addTestSuite(GridCacheLocalOffHeapTieredFullApiSelfTest.class);
+        suite.addTestSuite(GridCacheLocalAtomicOffHeapTieredFullApiSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedOffHeapTieredFullApiSelfTest.class);
+        suite.addTestSuite(GridCachePartitionedOffHeapTieredFullApiSelfTest.class);
+        suite.addTestSuite(GridCacheAtomicOffHeapTieredFullApiSelfTest.class);
+        suite.addTestSuite(GridCacheAtomicPrimaryWriteOrderOffHeapTieredFullApiSelfTest.class);
+        suite.addTestSuite(GridCachePartitionedNearDisabledOffHeapTieredFullApiSelfTest.class);
+        suite.addTestSuite(GridCachePartitionedNearDisabledOffHeapTieredAtomicFullApiSelfTest.class);
+
         // Multi-node.
         suite.addTestSuite(GridCacheReplicatedMultiNodeFullApiSelfTest.class);
         suite.addTestSuite(GridCacheReplicatedMultiNodeP2PDisabledFullApiSelfTest.class);
@@ -112,6 +122,14 @@ public class IgniteCacheFullApiSelfTestSuite extends TestSuite {
         suite.addTestSuite(GridCacheAtomicPrimaryWrityOrderOffHeapMultiNodeFullApiSelfTest.class);
         suite.addTestSuite(GridCachePartitionedNearDisabledOffHeapMultiNodeFullApiSelfTest.class);
 
+        // Multi-node with off-heap tiered mode.
+        suite.addTestSuite(GridCacheReplicatedOffHeapTieredMultiNodeFullApiSelfTest.class);
+        suite.addTestSuite(GridCachePartitionedOffHeapTieredMultiNodeFullApiSelfTest.class);
+        suite.addTestSuite(GridCacheAtomicOffHeapTieredMultiNodeFullApiSelfTest.class);
+        suite.addTestSuite(GridCacheAtomicPrimaryWrityOrderOffHeapTieredMultiNodeFullApiSelfTest.class);
+        suite.addTestSuite(GridCachePartitionedNearDisabledOffHeapTieredMultiNodeFullApiSelfTest.class);
+        suite.addTestSuite(GridCachePartitionedNearDisabledAtomicOffHeapTieredMultiNodeFullApiSelfTest.class);
+
         // Private cache API.
         suite.addTestSuite(GridCacheExLocalFullApiSelfTest.class);
         suite.addTestSuite(GridCacheExReplicatedFullApiSelfTest.class);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheP2pUnmarshallingErrorTestSuit.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheP2pUnmarshallingErrorTestSuit.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheP2pUnmarshallingErrorTestSuit.java
new file mode 100644
index 0000000..9b40280
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheP2pUnmarshallingErrorTestSuit.java
@@ -0,0 +1,41 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.*;
+import org.apache.ignite.internal.processors.cache.*;
+
+/**
+ * Checks behavior on exception while unmarshalling key.
+ */
+public class IgniteCacheP2pUnmarshallingErrorTestSuit extends TestSuite {
+    /**
+     * @return Suite.
+     * @throws Exception If failed.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("P2p Unmarshalling Test Suite");
+
+        suite.addTestSuite(IgniteCacheP2pUnmarshallingErrorTest.class);
+        suite.addTestSuite(IgniteCacheP2pUnmarshallingNearErrorTest.class);
+        suite.addTestSuite(IgniteCacheP2pUnmarshallingRebalanceErrorTest.class);
+        suite.addTestSuite(IgniteCacheP2pUnmarshallingTxErrorTest.class);
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheRestartTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheRestartTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheRestartTestSuite.java
index 0ced1c8..24945dd 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheRestartTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheRestartTestSuite.java
@@ -21,7 +21,6 @@ import junit.framework.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.cache.distributed.*;
 import org.apache.ignite.internal.processors.cache.distributed.near.*;
-import org.apache.ignite.internal.processors.cache.distributed.replicated.*;
 
 /**
  * In-Memory Data Grid stability test suite on changing topology.
@@ -36,11 +35,10 @@ public class IgniteCacheRestartTestSuite extends TestSuite {
 
         suite.addTestSuite(GridCachePartitionedTxSalvageSelfTest.class);
 
-        // TODO: GG-7419: Enable when fixed.
-        // suite.addTestSuite(GridCachePartitionedNodeRestartTest.class);
-        // suite.addTestSuite(GridCachePartitionedOptimisticTxNodeRestartTest.class);
-        // TODO: uncomment when fix GG-1969
-        // suite.addTestSuite(GridCacheReplicatedNodeRestartSelfTest.class);
+        // TODO IGNITE-882.
+        //suite.addTestSuite(GridCachePartitionedNodeRestartTest.class);
+        //suite.addTestSuite(GridCachePartitionedOptimisticTxNodeRestartTest.class);
+        //suite.addTestSuite(GridCacheReplicatedNodeRestartSelfTest.class);
 
         suite.addTestSuite(IgniteCacheAtomicNodeRestartTest.class);
         // suite.addTestSuite(IgniteCacheAtomicReplicatedNodeRestartSelfTest.class); // TODO IGNITE-747
@@ -48,6 +46,7 @@ public class IgniteCacheRestartTestSuite extends TestSuite {
         suite.addTestSuite(IgniteCacheAtomicPutAllFailoverSelfTest.class);
         suite.addTestSuite(IgniteCachePutAllRestartTest.class);
         suite.addTestSuite(GridCachePutAllFailoverSelfTest.class);
+        suite.addTestSuite(CacheGetFromJobTest.class);
 
         return suite;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index 6e70052..3fa3d9d 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -23,17 +23,11 @@ import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.affinity.fair.*;
 import org.apache.ignite.cache.store.*;
 import org.apache.ignite.cache.store.jdbc.*;
-import org.apache.ignite.internal.processors.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.cache.context.*;
 import org.apache.ignite.internal.processors.cache.distributed.*;
 import org.apache.ignite.internal.processors.cache.distributed.dht.*;
-import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.*;
 import org.apache.ignite.internal.processors.cache.distributed.near.*;
-import org.apache.ignite.internal.processors.cache.distributed.replicated.*;
-import org.apache.ignite.internal.processors.cache.distributed.replicated.preloader.*;
-import org.apache.ignite.internal.processors.cache.integration.*;
-import org.apache.ignite.internal.processors.cache.local.*;
 import org.apache.ignite.internal.processors.datastreamer.*;
 
 /**
@@ -159,295 +153,7 @@ public class IgniteCacheTestSuite extends TestSuite {
 //        suite.addTestSuite(GridCacheNearTxExceptionSelfTest.class);
 //        suite.addTestSuite(GridCacheStopSelfTest.class); TODO IGNITE-257
 
-        // Local cache.
-        suite.addTestSuite(GridCacheLocalBasicApiSelfTest.class);
-        suite.addTestSuite(GridCacheLocalBasicStoreSelfTest.class);
-        suite.addTestSuite(GridCacheLocalAtomicBasicStoreSelfTest.class);
-        suite.addTestSuite(GridCacheLocalGetAndTransformStoreSelfTest.class);
-        suite.addTestSuite(GridCacheLocalAtomicGetAndTransformStoreSelfTest.class);
-        suite.addTestSuite(GridCacheLocalLoadAllSelfTest.class);
-        suite.addTestSuite(GridCacheLocalLockSelfTest.class);
-        suite.addTestSuite(GridCacheLocalMultithreadedSelfTest.class);
-        suite.addTestSuite(GridCacheLocalTxSingleThreadedSelfTest.class);
-        suite.addTestSuite(GridCacheLocalTxTimeoutSelfTest.class);
-        suite.addTestSuite(GridCacheLocalEventSelfTest.class);
-        suite.addTestSuite(GridCacheLocalEvictionEventSelfTest.class);
-        suite.addTestSuite(GridCacheVariableTopologySelfTest.class);
-        suite.addTestSuite(GridCacheLocalTxMultiThreadedSelfTest.class);
-        suite.addTestSuite(GridCacheTransformEventSelfTest.class);
-        suite.addTestSuite(GridCacheLocalIsolatedNodesSelfTest.class);
-
-        // Partitioned cache.
-        suite.addTestSuite(GridCachePartitionedGetSelfTest.class);
-        suite.addTest(new TestSuite(GridCachePartitionedBasicApiTest.class));
-        suite.addTest(new TestSuite(GridCacheNearMultiGetSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheNearJobExecutionSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheNearOneNodeSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheNearMultiNodeSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheAtomicNearMultiNodeSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheNearReadersSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheAtomicNearReadersSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedAffinitySelfTest.class));
-        suite.addTest(new TestSuite(GridCacheRendezvousAffinityFunctionExcludeNeighborsSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheRendezvousAffinityClientSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedProjectionAffinitySelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedBasicOpSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedBasicStoreSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedGetAndTransformStoreSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedAtomicGetAndTransformStoreSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedBasicStoreMultiNodeSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedNearDisabledBasicStoreMultiNodeSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedEventSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedLockSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedMultiNodeLockSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedMultiNodeSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedMultiThreadedPutGetSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedNodeFailureSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedExplicitLockNodeFailureSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedTxSingleThreadedSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheColocatedTxSingleThreadedSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedTxTimeoutSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheFinishPartitionsSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtEntrySelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtInternalEntrySelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtMappingSelfTest.class));
-//        suite.addTest(new TestSuite(GridCachePartitionedTxMultiThreadedSelfTest.class)); TODO-gg-4066
-        suite.addTest(new TestSuite(GridCacheDhtPreloadSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtPreloadOffHeapSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtPreloadBigDataSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtPreloadPutGetSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtPreloadDisabledSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtPreloadMultiThreadedSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheColocatedPreloadRestartSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheNearPreloadRestartSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtPreloadStartStopSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtPreloadUnloadSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedAffinityFilterSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedPreloadLifecycleSelfTest.class));
-//        suite.addTest(new TestSuite(GridCacheLoadingConcurrentGridStartTest.class));  TODO-ignite-500
-        suite.addTest(new TestSuite(GridCacheDhtPreloadDelayedSelfTest.class));
-        suite.addTest(new TestSuite(GridPartitionedBackupLoadSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedLoadCacheSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionNotLoadedEventSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtEvictionsDisabledSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheNearEvictionEventSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheAtomicNearEvictionEventSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtEvictionSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheReplicatedEvictionSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtEvictionNearReadersSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheDhtAtomicEvictionNearReadersSelfTest.class));
-//        suite.addTest(new TestSuite(GridCachePartitionedTopologyChangeSelfTest.class)); TODO-gg-5489
-        suite.addTest(new TestSuite(GridCachePartitionedPreloadEventsSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedUnloadEventsSelfTest.class));
-        suite.addTest(new TestSuite(GridCachePartitionedAffinityHashIdResolverSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheColocatedOptimisticTransactionSelfTest.class));
-        suite.addTestSuite(GridCacheAtomicMessageCountSelfTest.class);
-        suite.addTest(new TestSuite(GridCacheNearPartitionedClearSelfTest.class));
-
-        suite.addTest(new TestSuite(GridCacheDhtExpiredEntriesPreloadSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheNearExpiredEntriesPreloadSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheAtomicExpiredEntriesPreloadSelfTest.class));
-
-        suite.addTest(new TestSuite(GridCacheOffheapUpdateSelfTest.class));
-
-        // TODO: GG-7242, GG-7243: Enabled when fixed.
-//        suite.addTest(new TestSuite(GridCacheDhtRemoveFailureTest.class));
-//        suite.addTest(new TestSuite(GridCacheNearRemoveFailureTest.class));
-        // TODO: GG-7201: Enable when fixed.
-        //suite.addTest(new TestSuite(GridCacheDhtAtomicRemoveFailureTest.class));
-
-        suite.addTest(new TestSuite(GridCacheNearPrimarySyncSelfTest.class));
-        suite.addTest(new TestSuite(GridCacheColocatedPrimarySyncSelfTest.class));
-
-        // Value consistency tests.
-        suite.addTestSuite(GridCacheValueConsistencyAtomicSelfTest.class);
-        suite.addTestSuite(GridCacheValueConsistencyAtomicPrimaryWriteOrderSelfTest.class);
-        suite.addTestSuite(GridCacheValueConsistencyAtomicNearEnabledSelfTest.class);
-        suite.addTestSuite(GridCacheValueConsistencyAtomicPrimaryWriteOrderNearEnabledSelfTest.class);
-        suite.addTestSuite(GridCacheValueConsistencyTransactionalSelfTest.class);
-        suite.addTestSuite(GridCacheValueConsistencyTransactionalNearEnabledSelfTest.class);
-        suite.addTestSuite(GridCacheValueBytesPreloadingSelfTest.class);
-
-        // Replicated cache.
-        suite.addTestSuite(GridCacheReplicatedBasicApiTest.class);
-        suite.addTestSuite(GridCacheReplicatedBasicOpSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedBasicStoreSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedGetAndTransformStoreSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedAtomicGetAndTransformStoreSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedEventSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedSynchronousCommitTest.class);
-
-        // TODO: GG-7437.
-        // suite.addTestSuite(GridCacheReplicatedInvalidateSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedLockSelfTest.class);
-        // TODO: enable when GG-7437 is fixed.
-        //suite.addTestSuite(GridCacheReplicatedMultiNodeLockSelfTest.class);
-        //suite.addTestSuite(GridCacheReplicatedMultiNodeSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedNodeFailureSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedTxSingleThreadedSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedTxTimeoutSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedPreloadSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedPreloadOffHeapSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedPreloadLifecycleSelfTest.class);
-        suite.addTestSuite(GridCacheSyncReplicatedPreloadSelfTest.class);
-
-        suite.addTestSuite(GridCacheDeploymentSelfTest.class);
-        suite.addTestSuite(GridCacheDeploymentOffHeapSelfTest.class);
-
-        suite.addTestSuite(GridCachePutArrayValueSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedUnswapAdvancedSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedEvictionEventSelfTest.class);
-        // TODO: GG-7569.
-        // suite.addTestSuite(GridCacheReplicatedTxMultiThreadedSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedPreloadEventsSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedPreloadStartStopEventsSelfTest.class);
-        // TODO: GG-7434
-        // suite.addTestSuite(GridReplicatedTxPreloadTest.class);
-
-        suite.addTestSuite(IgniteTxReentryNearSelfTest.class);
-        suite.addTestSuite(IgniteTxReentryColocatedSelfTest.class);
-
-        suite.addTestSuite(GridCacheOrderedPreloadingSelfTest.class);
-
-        // Test for byte array value special case.
-//        suite.addTestSuite(GridCacheLocalByteArrayValuesSelfTest.class);
-        suite.addTestSuite(GridCacheNearPartitionedP2PEnabledByteArrayValuesSelfTest.class);
-        suite.addTestSuite(GridCacheNearPartitionedP2PDisabledByteArrayValuesSelfTest.class);
-        suite.addTestSuite(GridCachePartitionedOnlyP2PEnabledByteArrayValuesSelfTest.class);
-        suite.addTestSuite(GridCachePartitionedOnlyP2PDisabledByteArrayValuesSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedP2PEnabledByteArrayValuesSelfTest.class);
-        suite.addTestSuite(GridCacheReplicatedP2PDisabledByteArrayValuesSelfTest.class);
-
-        // Near-only cache.
-        suite.addTest(IgniteCacheNearOnlySelfTestSuite.suite());
-
-        // Test cache with daemon nodes.
-        suite.addTestSuite(GridCacheDaemonNodeLocalSelfTest.class);
-        suite.addTestSuite(GridCacheDaemonNodePartitionedSelfTest.class);
-        suite.addTestSuite(GridCacheDaemonNodeReplicatedSelfTest.class);
-
-        // Write-behind.
-        suite.addTest(IgniteCacheWriteBehindTestSuite.suite());
-
-        // Transform.
-        suite.addTestSuite(GridCachePartitionedTransformWriteThroughBatchUpdateSelfTest.class);
-
-        suite.addTestSuite(GridCacheEntryVersionSelfTest.class);
-        suite.addTestSuite(GridCacheVersionSelfTest.class);
-
-        // Memory leak tests.
-        suite.addTestSuite(GridCacheReferenceCleanupSelfTest.class);
-        suite.addTestSuite(GridCacheReloadSelfTest.class);
-
-        suite.addTestSuite(GridCacheMixedModeSelfTest.class);
-
-        // Cache metrics.
-        suite.addTest(IgniteCacheMetricsSelfTestSuite.suite());
-
-        // Topology validator.
-        suite.addTest(IgniteTopologyValidatorTestSuit.suite());
-
-        // Eviction.
-        suite.addTest(IgniteCacheEvictionSelfTestSuite.suite());
-
-        // Iterators.
-        suite.addTest(IgniteCacheIteratorsSelfTestSuite.suite());
-
-        // Add tx recovery test suite.
-        suite.addTest(IgniteCacheTxRecoverySelfTestSuite.suite());
-
-        // Cache interceptor tests.
-        suite.addTest(IgniteCacheInterceptorSelfTestSuite.suite());
-
-        // Multi node update.
-        suite.addTestSuite(GridCacheMultinodeUpdateSelfTest.class);
-        // TODO: GG-5353.
-        // suite.addTestSuite(GridCacheMultinodeUpdateNearEnabledSelfTest.class);
-        // suite.addTestSuite(GridCacheMultinodeUpdateNearEnabledNoBackupsSelfTest.class);
-        suite.addTestSuite(GridCacheMultinodeUpdateAtomicSelfTest.class);
-        suite.addTestSuite(GridCacheMultinodeUpdateAtomicNearEnabledSelfTest.class);
-
-        suite.addTestSuite(IgniteCacheAtomicLoadAllTest.class);
-        suite.addTestSuite(IgniteCacheAtomicLocalLoadAllTest.class);
-        suite.addTestSuite(IgniteCacheTxLoadAllTest.class);
-        suite.addTestSuite(IgniteCacheTxLocalLoadAllTest.class);
-
-        suite.addTestSuite(IgniteCacheAtomicLoaderWriterTest.class);
-        suite.addTestSuite(IgniteCacheTxLoaderWriterTest.class);
-
-        suite.addTestSuite(IgniteCacheAtomicStoreSessionTest.class);
-        suite.addTestSuite(IgniteCacheTxStoreSessionTest.class);
-        suite.addTestSuite(IgniteCacheAtomicStoreSessionWriteBehindTest.class);
-        suite.addTestSuite(IgniteCacheTxStoreSessionWriteBehindTest.class);
-
-        suite.addTestSuite(IgniteCacheAtomicNoReadThroughTest.class);
-        suite.addTestSuite(IgniteCacheAtomicNearEnabledNoReadThroughTest.class);
-        suite.addTestSuite(IgniteCacheAtomicLocalNoReadThroughTest.class);
-        suite.addTestSuite(IgniteCacheTxNoReadThroughTest.class);
-        suite.addTestSuite(IgniteCacheTxNearEnabledNoReadThroughTest.class);
-        suite.addTestSuite(IgniteCacheTxLocalNoReadThroughTest.class);
-
-        suite.addTestSuite(IgniteCacheAtomicNoLoadPreviousValueTest.class);
-        suite.addTestSuite(IgniteCacheAtomicNearEnabledNoLoadPreviousValueTest.class);
-        suite.addTestSuite(IgniteCacheAtomicLocalNoLoadPreviousValueTest.class);
-        suite.addTestSuite(IgniteCacheTxNoLoadPreviousValueTest.class);
-        suite.addTestSuite(IgniteCacheTxNearEnabledNoLoadPreviousValueTest.class);
-        suite.addTestSuite(IgniteCacheTxLocalNoLoadPreviousValueTest.class);
-
-        suite.addTestSuite(IgniteCacheAtomicNoWriteThroughTest.class);
-        suite.addTestSuite(IgniteCacheAtomicNearEnabledNoWriteThroughTest.class);
-        suite.addTestSuite(IgniteCacheAtomicLocalNoWriteThroughTest.class);
-        suite.addTestSuite(IgniteCacheTxNoWriteThroughTest.class);
-        suite.addTestSuite(IgniteCacheTxNearEnabledNoWriteThroughTest.class);
-        suite.addTestSuite(IgniteCacheTxLocalNoWriteThroughTest.class);
-
-        suite.addTestSuite(IgniteCacheAtomicPeekModesTest.class);
-        suite.addTestSuite(IgniteCacheAtomicNearPeekModesTest.class);
-        suite.addTestSuite(IgniteCacheAtomicReplicatedPeekModesTest.class);
-        suite.addTestSuite(IgniteCacheAtomicLocalPeekModesTest.class);
-        suite.addTestSuite(IgniteCacheTxPeekModesTest.class);
-        suite.addTestSuite(IgniteCacheTxNearPeekModesTest.class);
-        suite.addTestSuite(IgniteCacheTxLocalPeekModesTest.class);
-        suite.addTestSuite(IgniteCacheTxReplicatedPeekModesTest.class);
-
-        // TODO: IGNITE-114.
-        // suite.addTestSuite(IgniteCacheInvokeReadThroughTest.class);
-        // suite.addTestSuite(GridCacheVersionMultinodeTest.class);
-
-        suite.addTestSuite(IgniteCacheNearReadCommittedTest.class);
-        suite.addTestSuite(IgniteCacheAtomicCopyOnReadDisabledTest.class);
-        suite.addTestSuite(IgniteCacheTxCopyOnReadDisabledTest.class);
-
-        suite.addTestSuite(IgniteCacheTxPreloadNoWriteTest.class);
-
-        suite.addTestSuite(IgniteDynamicCacheStartSelfTest.class);
-        suite.addTestSuite(IgniteCacheDynamicStopSelfTest.class);
-        suite.addTestSuite(IgniteCacheConfigurationTemplateTest.class);
-        suite.addTestSuite(IgniteCacheConfigurationDefaultTemplateTest.class);
-
-        suite.addTestSuite(GridCacheTxLoadFromStoreOnLockSelfTest.class);
-
-        suite.addTestSuite(GridCacheMarshallingNodeJoinSelfTest.class);
-
-        suite.addTestSuite(IgniteCacheJdbcBlobStoreNodeRestartTest.class);
-
-        suite.addTestSuite(IgniteCacheAtomicLocalStoreValueTest.class);
-        suite.addTestSuite(IgniteCacheAtomicStoreValueTest.class);
-        suite.addTestSuite(IgniteCacheAtomicNearEnabledStoreValueTest.class);
-        suite.addTestSuite(IgniteCacheAtomicPrimaryWriteOrderStoreValueTest.class);
-        suite.addTestSuite(IgniteCacheAtomicPrimaryWriteOrderNearEnabledStoreValueTest.class);
-        suite.addTestSuite(IgniteCacheTxLocalStoreValueTest.class);
-        suite.addTestSuite(IgniteCacheTxStoreValueTest.class);
-        suite.addTestSuite(IgniteCacheTxNearEnabledStoreValueTest.class);
-
-        suite.addTestSuite(IgniteCacheLockFailoverSelfTest.class);
-        suite.addTestSuite(IgniteCacheMultiTxLockSelfTest.class);
-
-        suite.addTestSuite(IgniteInternalCacheTypesTest.class);
-
-        suite.addTestSuite(IgniteExchangeFutureHistoryTest.class);
-
-        suite.addTestSuite(CacheNoValueClassOnServerNodeTest.class);
+        suite.addTestSuite(IgniteCacheNearLockValueSelfTest.class);
 
         return suite;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
new file mode 100644
index 0000000..7fa0a03
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
@@ -0,0 +1,144 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.distributed.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
+import org.apache.ignite.internal.processors.cache.distributed.replicated.*;
+import org.apache.ignite.internal.processors.cache.local.*;
+
+/**
+ * Test suite.
+ */
+public class IgniteCacheTestSuite2 extends TestSuite {
+    /**
+     * @return IgniteCache test suite.
+     * @throws Exception Thrown in case of the failure.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("IgniteCache Test Suite part 2");
+
+        // Local cache.
+        suite.addTestSuite(GridCacheLocalBasicApiSelfTest.class);
+        suite.addTestSuite(GridCacheLocalBasicStoreSelfTest.class);
+        suite.addTestSuite(GridCacheLocalAtomicBasicStoreSelfTest.class);
+        suite.addTestSuite(GridCacheLocalGetAndTransformStoreSelfTest.class);
+        suite.addTestSuite(GridCacheLocalAtomicGetAndTransformStoreSelfTest.class);
+        suite.addTestSuite(GridCacheLocalLoadAllSelfTest.class);
+        suite.addTestSuite(GridCacheLocalLockSelfTest.class);
+        suite.addTestSuite(GridCacheLocalMultithreadedSelfTest.class);
+        suite.addTestSuite(GridCacheLocalTxSingleThreadedSelfTest.class);
+        suite.addTestSuite(GridCacheLocalTxTimeoutSelfTest.class);
+        suite.addTestSuite(GridCacheLocalEventSelfTest.class);
+        suite.addTestSuite(GridCacheLocalEvictionEventSelfTest.class);
+        suite.addTestSuite(GridCacheVariableTopologySelfTest.class);
+        suite.addTestSuite(GridCacheLocalTxMultiThreadedSelfTest.class);
+        suite.addTestSuite(GridCacheTransformEventSelfTest.class);
+        suite.addTestSuite(GridCacheLocalIsolatedNodesSelfTest.class);
+
+        // Partitioned cache.
+        suite.addTestSuite(GridCachePartitionedGetSelfTest.class);
+        suite.addTest(new TestSuite(GridCachePartitionedBasicApiTest.class));
+        suite.addTest(new TestSuite(GridCacheNearMultiGetSelfTest.class));
+        suite.addTest(new TestSuite(NoneRebalanceModeSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheNearJobExecutionSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheNearOneNodeSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheNearMultiNodeSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheAtomicNearMultiNodeSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheNearReadersSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheNearReaderPreloadSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheAtomicNearReadersSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedAffinitySelfTest.class));
+        suite.addTest(new TestSuite(GridCacheRendezvousAffinityFunctionExcludeNeighborsSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheRendezvousAffinityClientSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedProjectionAffinitySelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedBasicOpSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedBasicStoreSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedGetAndTransformStoreSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedAtomicGetAndTransformStoreSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedBasicStoreMultiNodeSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedNearDisabledBasicStoreMultiNodeSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedEventSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedLockSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedNearDisabledLockSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedMultiNodeLockSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedMultiNodeSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedMultiThreadedPutGetSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedNodeFailureSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedExplicitLockNodeFailureSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedTxSingleThreadedSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheColocatedTxSingleThreadedSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedTxTimeoutSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheFinishPartitionsSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtEntrySelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtInternalEntrySelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtMappingSelfTest.class));
+//        suite.addTest(new TestSuite(GridCachePartitionedTxMultiThreadedSelfTest.class)); TODO-gg-4066
+        suite.addTest(new TestSuite(GridCacheDhtPreloadSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtPreloadOffHeapSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtPreloadBigDataSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtPreloadPutGetSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtPreloadDisabledSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtPreloadMultiThreadedSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheColocatedPreloadRestartSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheNearPreloadRestartSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtPreloadStartStopSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtPreloadUnloadSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedAffinityFilterSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedPreloadLifecycleSelfTest.class));
+        suite.addTest(new TestSuite(CacheLoadingConcurrentGridStartSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtPreloadDelayedSelfTest.class));
+        suite.addTest(new TestSuite(GridPartitionedBackupLoadSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedLoadCacheSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionNotLoadedEventSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtEvictionsDisabledSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheNearEvictionEventSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheAtomicNearEvictionEventSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtEvictionSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheReplicatedEvictionSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtEvictionNearReadersSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheDhtAtomicEvictionNearReadersSelfTest.class));
+//        suite.addTest(new TestSuite(GridCachePartitionedTopologyChangeSelfTest.class)); TODO-gg-5489
+        suite.addTest(new TestSuite(GridCachePartitionedPreloadEventsSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedUnloadEventsSelfTest.class));
+        suite.addTest(new TestSuite(GridCachePartitionedAffinityHashIdResolverSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheColocatedOptimisticTransactionSelfTest.class));
+        suite.addTestSuite(GridCacheAtomicMessageCountSelfTest.class);
+        suite.addTest(new TestSuite(GridCacheNearPartitionedClearSelfTest.class));
+
+        suite.addTest(new TestSuite(GridCacheDhtExpiredEntriesPreloadSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheNearExpiredEntriesPreloadSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheAtomicExpiredEntriesPreloadSelfTest.class));
+
+        suite.addTest(new TestSuite(GridCacheOffheapUpdateSelfTest.class));
+
+        // TODO: GG-7242, GG-7243: Enabled when fixed.
+//        suite.addTest(new TestSuite(GridCacheDhtRemoveFailureTest.class));
+//        suite.addTest(new TestSuite(GridCacheNearRemoveFailureTest.class));
+        // TODO: GG-7201: Enable when fixed.
+        //suite.addTest(new TestSuite(GridCacheDhtAtomicRemoveFailureTest.class));
+
+        suite.addTest(new TestSuite(GridCacheNearPrimarySyncSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheColocatedPrimarySyncSelfTest.class));
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java
new file mode 100644
index 0000000..c2b56ca
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite3.java
@@ -0,0 +1,142 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.distributed.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
+import org.apache.ignite.internal.processors.cache.distributed.replicated.*;
+import org.apache.ignite.internal.processors.cache.distributed.replicated.preloader.*;
+import org.apache.ignite.internal.processors.cache.local.*;
+
+/**
+ * Test suite.
+ */
+public class IgniteCacheTestSuite3 extends TestSuite {
+    /**
+     * @return IgniteCache test suite.
+     * @throws Exception Thrown in case of the failure.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("IgniteCache Test Suite part 3");
+
+        // Value consistency tests.
+        suite.addTestSuite(GridCacheValueConsistencyAtomicSelfTest.class);
+        suite.addTestSuite(GridCacheValueConsistencyAtomicPrimaryWriteOrderSelfTest.class);
+        suite.addTestSuite(GridCacheValueConsistencyAtomicNearEnabledSelfTest.class);
+        suite.addTestSuite(GridCacheValueConsistencyAtomicPrimaryWriteOrderNearEnabledSelfTest.class);
+        suite.addTestSuite(GridCacheValueConsistencyTransactionalSelfTest.class);
+        suite.addTestSuite(GridCacheValueConsistencyTransactionalNearEnabledSelfTest.class);
+        suite.addTestSuite(GridCacheValueBytesPreloadingSelfTest.class);
+
+        // Replicated cache.
+        suite.addTestSuite(GridCacheReplicatedBasicApiTest.class);
+        suite.addTestSuite(GridCacheReplicatedBasicOpSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedBasicStoreSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedGetAndTransformStoreSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedAtomicGetAndTransformStoreSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedEventSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedSynchronousCommitTest.class);
+
+        // TODO: GG-7437.
+        // suite.addTestSuite(GridCacheReplicatedInvalidateSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedLockSelfTest.class);
+        // TODO: enable when GG-7437 is fixed.
+        //suite.addTestSuite(GridCacheReplicatedMultiNodeLockSelfTest.class);
+        //suite.addTestSuite(GridCacheReplicatedMultiNodeSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedNodeFailureSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedTxSingleThreadedSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedTxTimeoutSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedPreloadSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedPreloadOffHeapSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedPreloadLifecycleSelfTest.class);
+        suite.addTestSuite(GridCacheSyncReplicatedPreloadSelfTest.class);
+
+        suite.addTestSuite(GridCacheDeploymentSelfTest.class);
+        suite.addTestSuite(GridCacheDeploymentOffHeapSelfTest.class);
+
+        suite.addTestSuite(GridCachePutArrayValueSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedUnswapAdvancedSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedEvictionEventSelfTest.class);
+        // TODO: GG-7569.
+        // suite.addTestSuite(GridCacheReplicatedTxMultiThreadedSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedPreloadEventsSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedPreloadStartStopEventsSelfTest.class);
+        // TODO: GG-7434
+        // suite.addTestSuite(GridReplicatedTxPreloadTest.class);
+
+        suite.addTestSuite(IgniteTxReentryNearSelfTest.class);
+        suite.addTestSuite(IgniteTxReentryColocatedSelfTest.class);
+
+        suite.addTestSuite(GridCacheOrderedPreloadingSelfTest.class);
+
+        // Test for byte array value special case.
+//        suite.addTestSuite(GridCacheLocalByteArrayValuesSelfTest.class);
+        suite.addTestSuite(GridCacheNearPartitionedP2PEnabledByteArrayValuesSelfTest.class);
+        suite.addTestSuite(GridCacheNearPartitionedP2PDisabledByteArrayValuesSelfTest.class);
+        suite.addTestSuite(GridCachePartitionedOnlyP2PEnabledByteArrayValuesSelfTest.class);
+        suite.addTestSuite(GridCachePartitionedOnlyP2PDisabledByteArrayValuesSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedP2PEnabledByteArrayValuesSelfTest.class);
+        suite.addTestSuite(GridCacheReplicatedP2PDisabledByteArrayValuesSelfTest.class);
+
+        // Near-only cache.
+        suite.addTest(IgniteCacheNearOnlySelfTestSuite.suite());
+
+        // Test cache with daemon nodes.
+        suite.addTestSuite(GridCacheDaemonNodeLocalSelfTest.class);
+        suite.addTestSuite(GridCacheDaemonNodePartitionedSelfTest.class);
+        suite.addTestSuite(GridCacheDaemonNodeReplicatedSelfTest.class);
+
+        // Write-behind.
+        suite.addTest(IgniteCacheWriteBehindTestSuite.suite());
+
+        // Transform.
+        suite.addTestSuite(GridCachePartitionedTransformWriteThroughBatchUpdateSelfTest.class);
+
+        suite.addTestSuite(GridCacheEntryVersionSelfTest.class);
+        suite.addTestSuite(GridCacheVersionSelfTest.class);
+
+        // Memory leak tests.
+        suite.addTestSuite(GridCacheReferenceCleanupSelfTest.class);
+        suite.addTestSuite(GridCacheReloadSelfTest.class);
+
+        suite.addTestSuite(GridCacheMixedModeSelfTest.class);
+
+        // Cache metrics.
+        suite.addTest(IgniteCacheMetricsSelfTestSuite.suite());
+
+        // Topology validator.
+        suite.addTest(IgniteTopologyValidatorTestSuit.suite());
+
+        // Eviction.
+        suite.addTest(IgniteCacheEvictionSelfTestSuite.suite());
+
+        // Iterators.
+        suite.addTest(IgniteCacheIteratorsSelfTestSuite.suite());
+
+        // Cache interceptor tests.
+        suite.addTest(IgniteCacheInterceptorSelfTestSuite.suite());
+
+        suite.addTestSuite(IgniteTxGetAfterStopTest.class);
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java
new file mode 100644
index 0000000..aaf7e5b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java
@@ -0,0 +1,135 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.*;
+import org.apache.ignite.internal.processors.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.distributed.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
+import org.apache.ignite.internal.processors.cache.integration.*;
+
+/**
+ * Test suite.
+ */
+public class IgniteCacheTestSuite4 extends TestSuite {
+    /**
+     * @return IgniteCache test suite.
+     * @throws Exception Thrown in case of the failure.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("IgniteCache Test Suite part 4");
+
+        // Multi node update.
+        suite.addTestSuite(GridCacheMultinodeUpdateSelfTest.class);
+        // TODO: GG-5353.
+        // suite.addTestSuite(GridCacheMultinodeUpdateNearEnabledSelfTest.class);
+        // suite.addTestSuite(GridCacheMultinodeUpdateNearEnabledNoBackupsSelfTest.class);
+        suite.addTestSuite(GridCacheMultinodeUpdateAtomicSelfTest.class);
+        suite.addTestSuite(GridCacheMultinodeUpdateAtomicNearEnabledSelfTest.class);
+
+        suite.addTestSuite(IgniteCacheAtomicLoadAllTest.class);
+        suite.addTestSuite(IgniteCacheAtomicLocalLoadAllTest.class);
+        suite.addTestSuite(IgniteCacheTxLoadAllTest.class);
+        suite.addTestSuite(IgniteCacheTxLocalLoadAllTest.class);
+
+        suite.addTestSuite(IgniteCacheAtomicLoaderWriterTest.class);
+        suite.addTestSuite(IgniteCacheTxLoaderWriterTest.class);
+
+        suite.addTestSuite(IgniteCacheAtomicStoreSessionTest.class);
+        suite.addTestSuite(IgniteCacheTxStoreSessionTest.class);
+        suite.addTestSuite(IgniteCacheAtomicStoreSessionWriteBehindTest.class);
+        suite.addTestSuite(IgniteCacheTxStoreSessionWriteBehindTest.class);
+
+        suite.addTestSuite(IgniteCacheAtomicNoReadThroughTest.class);
+        suite.addTestSuite(IgniteCacheAtomicNearEnabledNoReadThroughTest.class);
+        suite.addTestSuite(IgniteCacheAtomicLocalNoReadThroughTest.class);
+        suite.addTestSuite(IgniteCacheTxNoReadThroughTest.class);
+        suite.addTestSuite(IgniteCacheTxNearEnabledNoReadThroughTest.class);
+        suite.addTestSuite(IgniteCacheTxLocalNoReadThroughTest.class);
+
+        suite.addTestSuite(IgniteCacheAtomicNoLoadPreviousValueTest.class);
+        suite.addTestSuite(IgniteCacheAtomicNearEnabledNoLoadPreviousValueTest.class);
+        suite.addTestSuite(IgniteCacheAtomicLocalNoLoadPreviousValueTest.class);
+        suite.addTestSuite(IgniteCacheTxNoLoadPreviousValueTest.class);
+        suite.addTestSuite(IgniteCacheTxNearEnabledNoLoadPreviousValueTest.class);
+        suite.addTestSuite(IgniteCacheTxLocalNoLoadPreviousValueTest.class);
+
+        suite.addTestSuite(IgniteCacheAtomicNoWriteThroughTest.class);
+        suite.addTestSuite(IgniteCacheAtomicNearEnabledNoWriteThroughTest.class);
+        suite.addTestSuite(IgniteCacheAtomicLocalNoWriteThroughTest.class);
+        suite.addTestSuite(IgniteCacheTxNoWriteThroughTest.class);
+        suite.addTestSuite(IgniteCacheTxNearEnabledNoWriteThroughTest.class);
+        suite.addTestSuite(IgniteCacheTxLocalNoWriteThroughTest.class);
+
+        suite.addTestSuite(IgniteCacheAtomicPeekModesTest.class);
+        suite.addTestSuite(IgniteCacheAtomicNearPeekModesTest.class);
+        suite.addTestSuite(IgniteCacheAtomicReplicatedPeekModesTest.class);
+        suite.addTestSuite(IgniteCacheAtomicLocalPeekModesTest.class);
+        suite.addTestSuite(IgniteCacheTxPeekModesTest.class);
+        suite.addTestSuite(IgniteCacheTxNearPeekModesTest.class);
+        suite.addTestSuite(IgniteCacheTxLocalPeekModesTest.class);
+        suite.addTestSuite(IgniteCacheTxReplicatedPeekModesTest.class);
+
+        // TODO: IGNITE-114.
+        // suite.addTestSuite(IgniteCacheInvokeReadThroughTest.class);
+        // suite.addTestSuite(GridCacheVersionMultinodeTest.class);
+
+        suite.addTestSuite(IgniteCacheNearReadCommittedTest.class);
+        suite.addTestSuite(IgniteCacheAtomicCopyOnReadDisabledTest.class);
+        suite.addTestSuite(IgniteCacheTxCopyOnReadDisabledTest.class);
+
+        suite.addTestSuite(IgniteCacheTxPreloadNoWriteTest.class);
+
+        suite.addTestSuite(IgniteDynamicCacheStartSelfTest.class);
+        suite.addTestSuite(IgniteCacheDynamicStopSelfTest.class);
+        suite.addTestSuite(IgniteCacheConfigurationTemplateTest.class);
+        suite.addTestSuite(IgniteCacheConfigurationDefaultTemplateTest.class);
+
+        suite.addTestSuite(GridCacheTxLoadFromStoreOnLockSelfTest.class);
+
+        suite.addTestSuite(GridCacheMarshallingNodeJoinSelfTest.class);
+
+        suite.addTestSuite(IgniteCacheJdbcBlobStoreNodeRestartTest.class);
+
+        suite.addTestSuite(IgniteCacheAtomicLocalStoreValueTest.class);
+        suite.addTestSuite(IgniteCacheAtomicStoreValueTest.class);
+        suite.addTestSuite(IgniteCacheAtomicNearEnabledStoreValueTest.class);
+        suite.addTestSuite(IgniteCacheAtomicPrimaryWriteOrderStoreValueTest.class);
+        suite.addTestSuite(IgniteCacheAtomicPrimaryWriteOrderNearEnabledStoreValueTest.class);
+        suite.addTestSuite(IgniteCacheTxLocalStoreValueTest.class);
+        suite.addTestSuite(IgniteCacheTxStoreValueTest.class);
+        suite.addTestSuite(IgniteCacheTxNearEnabledStoreValueTest.class);
+
+        suite.addTestSuite(IgniteCacheLockFailoverSelfTest.class);
+        suite.addTestSuite(IgniteCacheMultiTxLockSelfTest.class);
+
+        suite.addTestSuite(IgniteInternalCacheTypesTest.class);
+
+        suite.addTestSuite(IgniteExchangeFutureHistoryTest.class);
+
+        suite.addTestSuite(CacheNoValueClassOnServerNodeTest.class);
+
+        suite.addTestSuite(CacheRemoveAllSelfTest.class);
+
+        suite.addTestSuite(CacheOffheapMapEntrySelfTest.class);
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTxRecoverySelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTxRecoverySelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTxRecoverySelfTestSuite.java
index e832099..1bd0e5f 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTxRecoverySelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTxRecoverySelfTestSuite.java
@@ -33,6 +33,10 @@ public class IgniteCacheTxRecoverySelfTestSuite extends TestSuite {
     public static TestSuite suite() throws Exception {
         TestSuite suite = new TestSuite("Cache tx recovery test suite");
 
+        suite.addTestSuite(IgniteCachePartitionedPrimaryNodeFailureRecoveryTest.class);
+        suite.addTestSuite(IgniteCachePartitionedNearDisabledPrimaryNodeFailureRecoveryTest.class);
+        suite.addTestSuite(IgniteCachePartitionedTwoBackupsPrimaryNodeFailureRecoveryTest.class);
+
         suite.addTestSuite(GridCachePartitionedTxOriginatingNodeFailureSelfTest.class);
         suite.addTestSuite(GridCachePartitionedNearDisabledTxOriginatingNodeFailureSelfTest.class);
         suite.addTestSuite(GridCacheReplicatedTxOriginatingNodeFailureSelfTest.class);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgfsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgfsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgfsTestSuite.java
index 11e22b1..f8dac3d 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgfsTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgfsTestSuite.java
@@ -59,6 +59,9 @@ public class IgniteIgfsTestSuite extends TestSuite {
         suite.addTest(new TestSuite(IgfsDualSyncSelfTest.class));
         suite.addTest(new TestSuite(IgfsDualAsyncSelfTest.class));
 
+        suite.addTest(new TestSuite(IgfsClientCacheSelfTest.class));
+        suite.addTest(new TestSuite(IgfsOneClientNodeTest.class));
+
         suite.addTest(new TestSuite(IgfsModeResolverSelfTest.class));
 
         suite.addTestSuite(IgfsFragmentizerSelfTest.class);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStreamTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStreamTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStreamTestSuite.java
new file mode 100644
index 0000000..61be976
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteStreamTestSuite.java
@@ -0,0 +1,39 @@
+/*
+ * 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.testsuites;
+
+import org.apache.ignite.stream.socket.*;
+
+import junit.framework.*;
+
+/**
+ * Stream test suite.
+ */
+public class IgniteStreamTestSuite extends TestSuite {
+    /**
+     * @return Stream tests suite.
+     * @throws Exception If failed.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Ignite Stream Test Suite");
+
+        suite.addTest(new TestSuite(SocketStreamerSelfTest.class));
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
index 941b06e..32cd038 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
@@ -67,6 +67,7 @@ public class IgniteUtilSelfTestSuite extends TestSuite {
         suite.addTestSuite(GridNioSelfTest.class);
         suite.addTestSuite(GridNioFilterChainSelfTest.class);
         suite.addTestSuite(GridNioSslSelfTest.class);
+        suite.addTestSuite(GridNioDelimitedBufferTest.class);
 
         return suite;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/extdata/p2p/pom.xml
----------------------------------------------------------------------
diff --git a/modules/extdata/p2p/pom.xml b/modules/extdata/p2p/pom.xml
index 0f8fdc0..b6a4a9e 100644
--- a/modules/extdata/p2p/pom.xml
+++ b/modules/extdata/p2p/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-extdata-p2p</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/extdata/uri/pom.xml
----------------------------------------------------------------------
diff --git a/modules/extdata/uri/pom.xml b/modules/extdata/uri/pom.xml
index df69c93..c81b2c1 100644
--- a/modules/extdata/uri/pom.xml
+++ b/modules/extdata/uri/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-extdata-uri</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/gce/pom.xml
----------------------------------------------------------------------
diff --git a/modules/gce/pom.xml b/modules/gce/pom.xml
index b12bb18..471a98b 100644
--- a/modules/gce/pom.xml
+++ b/modules/gce/pom.xml
@@ -20,9 +20,7 @@
 <!--
     POM file.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
 
     <parent>
@@ -33,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-gce</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>
@@ -91,4 +89,4 @@
 
     </dependencies>
 
-</project>
\ No newline at end of file
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/geospatial/pom.xml
----------------------------------------------------------------------
diff --git a/modules/geospatial/pom.xml b/modules/geospatial/pom.xml
index 1ce3370..0283930 100644
--- a/modules/geospatial/pom.xml
+++ b/modules/geospatial/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-geospatial</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
index 8566960..b80944c 100644
--- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
+++ b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
@@ -57,13 +57,31 @@ public class GridH2IndexingGeoSelfTest extends GridCacheAbstractSelfTest {
     /** {@inheritDoc} */
     @Override protected Class<?>[] indexedTypes() {
         return new Class<?>[]{
-            Integer.class, EnemyCamp.class
+            Integer.class, EnemyCamp.class,
+            Long.class, Geometry.class // Geometry must be indexed here.
         };
     }
 
     /**
      * @throws Exception If failed.
      */
+    public void testPrimitiveGeometry() throws Exception {
+        IgniteCache<Long, Geometry> cache = grid(0).cache(null);
+
+        WKTReader r = new WKTReader();
+
+        for (long i = 0; i < 100; i++)
+            cache.put(i, r.read("POINT(" + i + " " + i + ")"));
+
+        List<List<?>> res = cache.query(new SqlFieldsQuery("explain select _key from Geometry where _val && ?")
+            .setArgs(r.read("POLYGON((5 70, 5 80, 30 80, 30 70, 5 70))")).setLocal(true)).getAll();
+
+        assertTrue("__ explain: " + res, res.get(0).get(0).toString().contains("_val_idx"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     @SuppressWarnings("unchecked")
     public void testGeo() throws Exception {
         IgniteCache<Integer, EnemyCamp> cache = grid(0).cache(null);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/hadoop/pom.xml
----------------------------------------------------------------------
diff --git a/modules/hadoop/pom.xml b/modules/hadoop/pom.xml
index 231808f..6910093 100644
--- a/modules/hadoop/pom.xml
+++ b/modules/hadoop/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-hadoop</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/v2/HadoopV2Context.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/v2/HadoopV2Context.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/v2/HadoopV2Context.java
index 3f8e2b6..53159b1 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/v2/HadoopV2Context.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/v2/HadoopV2Context.java
@@ -89,12 +89,12 @@ public class HadoopV2Context extends JobContextImpl implements MapContext, Reduc
 
                 inputSplit = new FileSplit(new Path(fileBlock.file()), fileBlock.start(), fileBlock.length(), null);
             }
-            else if (split instanceof HadoopExternalSplit)
-                throw new UnsupportedOperationException(); // TODO
-            else if (split instanceof HadoopSplitWrapper)
-                inputSplit = (InputSplit) HadoopUtils.unwrapSplit((HadoopSplitWrapper) split);
             else
-                throw new IllegalStateException();
+                try {
+                    inputSplit = (InputSplit) ((HadoopV2TaskContext)ctx).getNativeSplit(split);
+                } catch (IgniteCheckedException e) {
+                    throw new IllegalStateException(e);
+                }
         }
 
         return inputSplit;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
index 183087c..179f7f0 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
@@ -129,7 +129,7 @@ public class IgniteHadoopTestSuite extends TestSuite {
      * @throws Exception If failed.
      */
     public static void downloadHive() throws Exception {
-        String ver = IgniteSystemProperties.getString("hive.version", "0.13.1");
+        String ver = IgniteSystemProperties.getString("hive.version", "1.2.0");
 
         X.println("Will use Hive version: " + ver);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/hibernate/pom.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate/pom.xml b/modules/hibernate/pom.xml
index ed4dc07..8c2dcbb 100644
--- a/modules/hibernate/pom.xml
+++ b/modules/hibernate/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-hibernate</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/pom.xml
----------------------------------------------------------------------
diff --git a/modules/indexing/pom.xml b/modules/indexing/pom.xml
index 6ff6039..7aab5e8 100644
--- a/modules/indexing/pom.xml
+++ b/modules/indexing/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-indexing</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>


[23/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/dev-tools/slurp.sh
----------------------------------------------------------------------
diff --git a/dev-tools/slurp.sh b/dev-tools/slurp.sh
new file mode 100755
index 0000000..7edc776
--- /dev/null
+++ b/dev-tools/slurp.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+#
+# 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.
+#
+
+#
+# Copy this script file at root of ignite repo.
+# Fill all variables.
+#
+
+#
+# Default branch name. Need to use last version of "jiraslurp" scripts.
+#
+DEFAULT_BRANCH='ignite-sprint-5'
+
+#
+# TC URL. It is 10.30.0.229 for public TC from agents.
+#
+TC_URL='10.30.0.229'
+
+#
+# Jira user name to add comments aboyt triggered builds.
+#
+JIRA_USER='tc_commenter'
+
+#
+# Jira password.
+#
+JIRA_PWD=''
+
+#
+# TC user which have permissions to trigger new builds.
+#
+TASK_RUNNER_USER='task_runner'
+
+#
+# TC user password.
+#
+TASK_RUNNER_PWD=''
+
+echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
+echo "<"$(date + "%D - %H:%M:%S")"> Starting task triggering"
+echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
+
+# Useful settings
+#cd /home/teamcity/jobs/incubator-ignite/
+#
+#export JAVA_HOME=<java_home>
+#export PATH=$PATH:<gradle_path>
+
+git fetch
+
+git checkout ${DEFAULT_BRANCH}
+
+git pull
+
+export TC_URL=${TC_URL}
+export JIRA_USER=${JIRA_USER}
+export JIRA_PWD=${JIRA_PWD}
+export TASK_RUNNER_PWD=${TASK_RUNNER_PWD}
+export TASK_RUNNER_USER=${TASK_RUNNER_USER}
+
+gradle slurp -b dev-tools/build.gradle

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/dev-tools/src/main/groovy/jiraslurp.groovy
----------------------------------------------------------------------
diff --git a/dev-tools/src/main/groovy/jiraslurp.groovy b/dev-tools/src/main/groovy/jiraslurp.groovy
new file mode 100644
index 0000000..8498cf0
--- /dev/null
+++ b/dev-tools/src/main/groovy/jiraslurp.groovy
@@ -0,0 +1,544 @@
+/*
+ * 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.
+ */
+
+/*
+ * Start of util methods.
+ */
+
+def envVariable = { name, defaultVar ->
+    def res = System.getenv(name as String)
+
+    if (res == 'null' || res == null)
+        return defaultVar
+
+    res
+}
+
+def envVariableAsList = { name, defaultList ->
+    def list = System.getenv(name as String)?.split(' ') as List
+
+    if (list == 'null' || list == null)
+        return defaultList
+
+    list
+}
+
+/**
+ * Monitors given process and show errors if exist.
+ */
+def checkprocess = { process ->
+    process.waitFor()
+
+    if (process.exitValue() != 0) {
+        println "Return code: " + process.exitValue()
+//        println "Errout:\n" + process.err.text
+
+        assert process.exitValue() == 0 || process.exitValue() == 128
+    }
+}
+
+def exec = {command, envp, dir ->
+    println "Executing command '$command'..."
+
+    def ps = command.execute(envp, dir)
+
+    try {
+        println "Command output:"
+
+        println ps.text
+    }
+    catch (Throwable e) {
+        // Do nothing.
+        println "Error: could not get caommand output."
+    }
+
+    checkprocess ps
+}
+
+def execGit = {command ->
+    exec(command, null, new File("../"))
+}
+
+/**
+ * Util method to send http request.
+ */
+def sendHttpRequest = { requestMethod, urlString, user, pwd, postData, contentType ->
+    URL url = new URL(urlString as String);
+
+    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+
+    String encoded = new sun.misc.BASE64Encoder().encode("$user:$pwd".getBytes());
+
+    conn.setRequestProperty("Authorization", "Basic " + encoded);
+
+    conn.setDoOutput(true);
+    conn.setRequestMethod(requestMethod);
+
+    if (postData) {
+        conn.setRequestProperty("Content-Type", contentType);
+        conn.setRequestProperty("Content-Length", String.valueOf(postData.length()));
+
+        OutputStream os = conn.getOutputStream();
+        os.write(postData.getBytes());
+        os.flush();
+        os.close();
+    }
+
+    conn.connect();
+
+    // Read response.
+    BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+
+    String response = "";
+    String line;
+
+    while ((line = br.readLine()) != null)
+        response += line
+
+    br.close();
+
+    response
+}
+
+/**
+ * Util method to send http POST request.
+ */
+def sendPostRequest = { urlString, user, pwd, postData, contentType ->
+    sendHttpRequest("POST", urlString, user, pwd, postData, contentType);
+}
+
+/**
+ * Util method to send http GET request.
+ */
+def sendGetRequest = { urlString, user, pwd->
+    sendHttpRequest("GET", urlString, user, pwd, null, null);
+}
+
+/*
+ * End of util methods.
+ */
+
+/**
+ * Parsing a special filter from Apache Ignite JIRA and picking up latest by ID
+ * attachments to process.
+ */
+final GIT_REPO = "https://git1-us-west.apache.org/repos/asf/incubator-ignite.git"
+final JIRA_URL = "https://issues.apache.org"
+final ATTACHMENT_URL = "$JIRA_URL/jira/secure/attachment"
+final HISTORY_FILE = "${System.getProperty("user.home")}/validated-jira.txt"
+final LAST_SUCCESSFUL_ARTIFACT = "guestAuth/repository/download/Ignite_PatchValidation_PatchChecker/.lastSuccessful/$HISTORY_FILE"
+final NL = System.getProperty("line.separator")
+
+final def JIRA_CMD = System.getProperty('JIRA_COMMAND', 'jira.sh')
+
+// Envariement variables.
+final def TC_PROJECT_NAME = envVariable("PROJECT_NAME", "Ignite")
+final def TC_BUILD_EXCLUDE_LIST = envVariableAsList("BUILD_ID_EXCLUDES", ["Ignite_RunAllTestBuilds"])
+
+final def JIRA_USER = System.getenv('JIRA_USER')
+final def JIRA_PWD = System.getenv('JIRA_PWD')
+
+final def CONTRIBUTORS = []
+
+def contributors = {
+    if (!CONTRIBUTORS) {
+        def response = sendGetRequest(
+            "$JIRA_URL/jira/rest/api/2/project/12315922/role/10010" as String,
+            JIRA_USER,
+            JIRA_PWD)
+
+        println "Response on contributors request = $response"
+
+        def json = new groovy.json.JsonSlurper().parseText(response)
+
+        json.actors.each {
+            CONTRIBUTORS.add(it.name)
+        }
+
+        println "Contributors list: $CONTRIBUTORS"
+    }
+
+    CONTRIBUTORS
+}
+
+/**
+ * Gets jiras for which test tasks were already triggered.
+ *
+ * @return List of pairs [jira,attachemntId].
+ */
+def readHistory = {
+    final int MAX_HISTORY = 5000
+
+    List validated_list = []
+
+    def validated = new File(HISTORY_FILE)
+
+    if (validated.exists()) {
+        validated_list = validated.text.split('\n')
+    }
+
+    // Let's make sure the preserved history isn't too long
+    if (validated_list.size > MAX_HISTORY) {
+        validated_list = validated_list[validated_list.size - MAX_HISTORY..validated_list.size - 1]
+
+        validated.delete()
+        validated << validated_list.join(NL)
+    }
+
+    println "History=$validated_list"
+
+    validated_list
+}
+
+/**
+ * Accepting the <jira> XML element from JIRA stream
+ * @return <code>null</code> or <code>JIRA-###,latest_attach_id</code>
+ */
+def getLatestAttachment = { jira ->
+    def attachment = jira.attachments[0].attachment.list()
+        .sort { it.@id.toInteger() }
+        .reverse()
+        .find {
+            def fName = it.@name.toString()
+
+            contributors().contains(it.@author as String) &&
+                (fName.endsWith(".patch") || fName.endsWith(".txt") || fName.endsWith(".diff"))
+        }
+
+    String row = null
+
+    if (attachment == null) {
+        println "${jira.key} is in invalid state: there was not found '.{patch/txt/diff}'-file from approved user."
+    }
+    else {
+        row = "${jira.key},${attachment.@id}"
+    }
+}
+
+/**
+ * Checks all "Patch availiable" jiras on attached ".patch"-files from approved users.
+ */
+def findAttachments = {
+    // See https://issues.apache.org/jira/issues/?filter=12330308 (the same).
+    def JIRA_FILTER =
+        "https://issues.apache.org/jira/sr/jira.issueviews:searchrequest-xml/12330308/SearchRequest-12330308.xml?tempMax=100&field=key&field=attachments"
+    def rss = new XmlSlurper().parse(JIRA_FILTER)
+
+    final List history = readHistory {}
+
+    LinkedHashMap<String, String> attachments = [:]
+
+    rss.channel.item.each { jira ->
+        String row = getLatestAttachment(jira)
+
+        if (row != null && !history.contains(row)) {
+            def pair = row.split(',')
+
+            attachments.put(pair[0] as String, pair[1] as String)
+        }
+    }
+
+    attachments
+}
+
+/**
+ * Store jira with attachment id to hostory.
+ */
+def addToHistory = {jira, attachmentId ->
+    def validated = new File(HISTORY_FILE)
+
+    assert validated.exists(), "History file does not exist."
+
+    validated << NL + "$jira,$attachmentId"
+}
+
+def tryGitAmAbort = {
+    try {
+        checkprocess "git am --abort".execute(null, new File("../"))
+
+        println "Succsessfull: git am --abort."
+    }
+    catch (Throwable e) {
+        println "Error: git am --abort fails: "
+    }
+}
+
+/**
+ * Applys patch from jira to given git state.
+ */
+def applyPatch = { jira, attachementURL ->
+    // Delete all old IGNITE-*-*.patch files.
+    def directory = new File("./")
+
+    println "Remove IGNITE-*-*.patch files in ${directory.absolutePath} and its subdirectories..."
+
+    def classPattern = ~/.*IGNITE-.*-.*\.patch/
+
+    directory.eachFileRecurse(groovy.io.FileType.FILES)
+        { file ->
+            if (file ==~ classPattern){
+                println "Deleting ${file}..."
+
+                file.delete()
+            }
+        }
+
+    // Main logic.
+    println "Patch apllying with jira='$jira' and attachment='$ATTACHMENT_URL/$attachementURL/'."
+
+    def userEmail = System.getenv("env.GIT_USER_EMAIL");
+    def userName = System.getenv("env.GIT_USER_NAME");
+
+    def patchFile = new File("${jira}-${attachementURL}.patch")
+
+    println "Getting patch content."
+
+    def attachmentUrl = new URL("$ATTACHMENT_URL/$attachementURL/")
+
+    HttpURLConnection conn = (HttpURLConnection)attachmentUrl.openConnection();
+    conn.setRequestProperty("Content-Type", "text/x-patch;charset=utf-8");
+    conn.setRequestProperty("X-Content-Type-Options", "nosniff");
+    conn.connect();
+
+    patchFile << conn.getInputStream()
+
+    println "Got patch content."
+
+    try {
+        tryGitAmAbort()
+
+        execGit "git branch"
+
+        execGit "git config user.email \"$userEmail\""
+        execGit "git config user.name \"$userName\""
+
+        // Create a new uniqueue branch to applying patch
+        def newTestBranch = "test-branch-${jira}-${attachementURL}-${System.currentTimeMillis()}"
+        execGit "git checkout -b ${newTestBranch}"
+
+        execGit "git branch"
+
+        println "Trying to apply patch."
+
+        execGit "git am dev-tools/${patchFile.name}"
+
+        println "Patch was applied successfully."
+    }
+    catch (Throwable e) {
+        println "Patch was not applied successfully. Aborting patch applying."
+
+        tryGitAmAbort()
+
+        throw e;
+    }
+}
+
+def JIRA_xml = { jiranum ->
+    "https://issues.apache.org/jira/si/jira.issueviews:issue-xml/$jiranum/${jiranum}.xml"
+}
+
+/**
+ * Gets all builds from TC project.
+ */
+def getTestBuilds = { ->
+    def tcURL = System.getenv('TC_URL')
+
+    def project = new XmlSlurper().parse("http://$tcURL:80/guestAuth/app/rest/projects/id:$TC_PROJECT_NAME")
+
+    def buildIds = []
+
+    def count = Integer.valueOf(project.buildTypes.@count as String)
+
+    for (int i = 0; i < count; i++) {
+        def id = project.buildTypes.buildType[i].@id
+
+        if (TC_BUILD_EXCLUDE_LIST == null || !TC_BUILD_EXCLUDE_LIST.contains(id))
+            buildIds.add(id)
+    }
+
+    buildIds
+}
+
+/**
+ * Adds comment to jira ticket.
+ */
+def addJiraComment = { jiraNum, comment ->
+    try {
+        println "Comment: $comment"
+
+        def jsonComment = "{\n \"body\": \"${comment}\"\n}";
+
+        def response = sendPostRequest(
+            "$JIRA_URL/jira/rest/api/2/issue/$jiraNum/comment" as String,
+            JIRA_USER,
+            JIRA_PWD,
+            jsonComment,
+            "application/json")
+
+        println "Response: $response"
+    }
+    catch (Exception e) {
+        e.printStackTrace()
+    }
+}
+
+/**
+ * Runs all given test builds to validate last patch from given jira.
+ */
+def runAllTestBuilds = {builds, jiraNum ->
+    def tcURL = System.getenv('TC_URL')
+    def user = System.getenv('TASK_RUNNER_USER')
+    def pwd = System.getenv('TASK_RUNNER_PWD')
+
+    def triggeredBuilds = [:]
+
+    builds.each {
+        try {
+            println "Triggering $it build for $jiraNum jira..."
+
+            String postData
+
+            if (jiraNum == 'null' || jiraNum == null) {
+                postData = "<build>" +
+                        "  <buildType id='$it'/>" +
+                        "</build>";
+            }
+            else {
+                postData = "<build>" +
+                        "  <buildType id='$it'/>" +
+                        "  <comment>" +
+                        "    <text>Auto triggered build to validate last attached patch file at $jiraNum.</text>" +
+                        "  </comment>" +
+                        "  <properties>" +
+                        "    <property name='env.JIRA_NUM' value='$jiraNum'/>" +
+                        "  </properties>" +
+                        "</build>";
+            }
+
+            println "Request: $postData"
+
+            def response = sendPostRequest(
+                "http://$tcURL:80/httpAuth/app/rest/buildQueue" as String,
+                user,
+                pwd,
+                postData,
+                "application/xml")
+
+            println "Response: $response"
+
+            def build = new XmlSlurper().parseText(response)
+
+            triggeredBuilds.put(build.buildType.@name, build.@webUrl)
+        }
+        catch (Exception e) {
+            e.printStackTrace()
+        }
+    }
+
+    // Format comment for jira.
+    def triggeredBuildsComment = "There was triggered next test builds for last attached patch-file:\\n"
+
+    def n = 1;
+
+    triggeredBuilds.each { name, url ->
+        def prefix = n < 10 ? "0" : ""
+
+        triggeredBuildsComment += "${prefix}${n}. ${url as String} - ${name as String}\\n"
+
+        n++
+    }
+
+    addJiraComment(jiraNum, triggeredBuildsComment)
+}
+
+/**
+ * Main.
+ *
+ * Modes:
+ * 1. "slurp" mode - triggers all TC test builds for all jiras with valid attachment
+ * (Jira in "patch availiable" state, there is attached file from approved user with "patch" extension)
+ * 2. "patchApply" mode - gets last valid patch file from given jira number and applies it.
+ * 3. "runAllBuilds" - triggers given jira number for all TC test builds.
+ *
+ * Main workflow:
+ * 1. run in "slurp" mode
+ * 2. each triggered build uses "patchApply" mode to apply latest valid patch.
+ */
+args.each {
+    println "Arg=$it"
+
+    def parameters = it.split(",")
+
+    println parameters
+
+    if (parameters.length >= 1 && parameters[0] == "slurp") {
+        println "Running in 'slurp' mode."
+
+        def builds = getTestBuilds()
+
+        println "Test builds to be triggered=$builds"
+
+        def attachments = findAttachments()
+
+        // For each ticket with new attachment, let's trigger remove build
+        attachments.each { k, v ->
+            //  Trailing slash is important for download; only need to pass JIRA number
+            println "Triggering the test builds for: $k = $ATTACHMENT_URL/$v/"
+
+            runAllTestBuilds(builds, k)
+
+            addToHistory(k, v)
+        }
+    }
+    else if (parameters.length >= 1 && parameters[0] == "patchApply") {
+        if (parameters.length < 2 || parameters[1] == 'null') {
+            println "There is no jira number to apply. Exit."
+
+            return
+        }
+
+        def jiraNum = parameters[1]
+
+        println "Running in 'patch apply' mode with jira number '$jiraNum'"
+
+        // Extract JIRA rss from the and pass the ticket element into attachment extraction
+        def rss = new XmlSlurper().parse(JIRA_xml(parameters[1]))
+
+        String row = getLatestAttachment(rss.channel.item)
+
+        println "Got row: $row."
+
+        if (row != null) {
+            def pair = row.split(',')
+            def jira = pair[0]
+            def attachementURL = pair[1]
+
+            applyPatch(jira, attachementURL)
+        }
+    }
+    else if (parameters.length > 1 && parameters[0] == "runAllBuilds" ) {
+        def jiraNum = parameters[1]
+
+        println "Running in 'all builds' mode with jira number='$jiraNum'."
+
+        def builds = getTestBuilds()
+
+        println "Test builds to be triggered=$builds"
+
+        runAllTestBuilds(builds, jiraNum)
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 9dda753..78c5852 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -28,7 +28,7 @@
     </parent>
 
     <artifactId>ignite-examples</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java
index 5e95892..966fce2 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java
@@ -30,11 +30,9 @@ import java.util.*;
  * Stream random numbers into the streaming cache.
  * To start the example, you should:
  * <ul>
- *     <li>Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.</li>
+ *     <li>Start a few nodes using {@link ExampleNodeStartup}.</li>
  *     <li>Start streaming using {@link StreamTransformerExample}.</li>
  * </ul>
- * <p>
- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM.
  */
 public class StreamTransformerExample {
     /** Random number generator. */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
index 0fbce68..baae5af 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
@@ -31,11 +31,9 @@ import java.util.*;
  * Stream random numbers into the streaming cache.
  * To start the example, you should:
  * <ul>
- *     <li>Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.</li>
+ *     <li>Start a few nodes using {@link ExampleNodeStartup}.</li>
  *     <li>Start streaming using {@link StreamVisitorExample}.</li>
  * </ul>
- * <p>
- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM.
  */
 public class StreamVisitorExample {
     /** Random number generator. */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/src/main/java/org/apache/ignite/examples/streaming/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/package-info.java b/examples/src/main/java/org/apache/ignite/examples/streaming/package-info.java
index 43dea13..43fbab3 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/package-info.java
@@ -16,7 +16,6 @@
  */
 
 /**
- * <!-- Package description. -->
  * Demonstrates usage of data streamer.
  */
 package org.apache.ignite.examples.streaming;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/CacheConfig.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/CacheConfig.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/CacheConfig.java
index bb2a18e..d17b97d 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/CacheConfig.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/CacheConfig.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.examples.streaming.wordcount;
 
 import org.apache.ignite.cache.affinity.*;
-import org.apache.ignite.cache.eviction.fifo.*;
 import org.apache.ignite.configuration.*;
 
 import javax.cache.configuration.*;
@@ -27,7 +26,7 @@ import javax.cache.expiry.*;
 import static java.util.concurrent.TimeUnit.*;
 
 /**
- * Configuration for the streaming cache to store the stream of random numbers.
+ * Configuration for the streaming cache to store the stream of words.
  * This cache is configured with sliding window of 1 second, which means that
  * data older than 1 second will be automatically removed from the cache.
  */
@@ -44,10 +43,6 @@ public class CacheConfig {
         // Sliding window of 1 seconds.
         cfg.setExpiryPolicyFactory(FactoryBuilder.factoryOf(new CreatedExpiryPolicy(new Duration(SECONDS, 1))));
 
-        // Do not allow more than 1 million entries.
-        // Allows to run this example with smaller available memory.
-        cfg.setEvictionPolicy(new FifoEvictionPolicy<>(1_000_000));
-
         return cfg;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/QueryWords.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/QueryWords.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/QueryWords.java
index 3bd9d3d..58c6ef2 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/QueryWords.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/QueryWords.java
@@ -28,14 +28,18 @@ import java.util.*;
  * Periodically query popular numbers from the streaming cache.
  * To start the example, you should:
  * <ul>
- *     <li>Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.</li>
+ *     <li>Start a few nodes using {@link ExampleNodeStartup}.</li>
  *     <li>Start streaming using {@link StreamWords}.</li>
- *     <li>Start querying popular numbers using {@link QueryWords}.</li>
+ *     <li>Start querying popular words using {@link QueryWords}.</li>
  * </ul>
- * <p>
- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM.
  */
 public class QueryWords {
+    /**
+     * Schedules words query execution.
+     *
+     * @param args Command line arguments (none required).
+     * @throws Exception If failed.
+     */
     public static void main(String[] args) throws Exception {
         // Mark this cluster member as client.
         Ignition.setClientMode(true);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/StreamWords.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/StreamWords.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/StreamWords.java
index c59fa51..6024c4b 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/StreamWords.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/StreamWords.java
@@ -27,14 +27,18 @@ import java.io.*;
  * Stream words into Ignite cache.
  * To start the example, you should:
  * <ul>
- *     <li>Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.</li>
+ *     <li>Start a few nodes using {@link ExampleNodeStartup}.</li>
  *     <li>Start streaming using {@link StreamWords}.</li>
- *     <li>Start querying popular numbers using {@link QueryWords}.</li>
+ *     <li>Start querying popular words using {@link QueryWords}.</li>
  * </ul>
- * <p>
- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM.
  */
 public class StreamWords {
+    /**
+     * Starts words streaming.
+     *
+     * @param args Command line arguments (none required).
+     * @throws Exception If failed.
+     */
     public static void main(String[] args) throws Exception {
         // Mark this cluster member as client.
         Ignition.setClientMode(true);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/package-info.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/package-info.java
index 010f86a..5d48ae3 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/package-info.java
@@ -16,7 +16,6 @@
  */
 
 /**
- * <!-- Package description. -->
  * Streaming word count example.
  */
 package org.apache.ignite.examples.streaming.wordcount;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerClient.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerClient.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerClient.java
new file mode 100644
index 0000000..c4d7b8c
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerClient.java
@@ -0,0 +1,82 @@
+/*
+ * 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.examples.streaming.wordcount.socket;
+
+import org.apache.ignite.examples.*;
+import org.apache.ignite.examples.streaming.wordcount.*;
+import org.apache.ignite.stream.socket.*;
+
+import java.io.*;
+import java.net.*;
+
+/**
+ * Example demonstrates streaming of data from external components into Ignite cache.
+ * <p>
+ * {@code WordsSocketStreamerClient} is simple socket streaming client implementation that sends words to socket server
+ * based on {@link SocketStreamer} using message delimiter based protocol. Example illustrates usage of TCP socket
+ * streamer in case of non-Java clients. In this example words are zero-terminated strings.
+ * <p>
+ * To start the example, you should:
+ * <ul>
+ *     <li>Start a few nodes using {@link ExampleNodeStartup}.</li>
+ *     <li>Start socket server using {@link WordsSocketStreamerServer}.</li>
+ *     <li>Start a few socket clients using {@link WordsSocketStreamerClient}.</li>
+ *     <li>Start querying popular words using {@link QueryWords}.</li>
+ * </ul>
+ */
+public class WordsSocketStreamerClient {
+    /** Port. */
+    private static final int PORT = 5555;
+
+    /** Delimiter. */
+    private static final byte[] DELIM = new byte[] {0};
+
+    /**
+     * @param args Args.
+     */
+    public static void main(String[] args) throws IOException {
+        InetAddress addr = InetAddress.getLocalHost();
+
+        try (
+            Socket sock = new Socket(addr, PORT);
+            OutputStream oos = new BufferedOutputStream(sock.getOutputStream())
+        ) {
+            System.out.println("Words streaming started.");
+
+            while (true) {
+                try (InputStream in = WordsSocketStreamerClient.class.getResourceAsStream("../alice-in-wonderland.txt");
+                     LineNumberReader rdr = new LineNumberReader(new InputStreamReader(in))) {
+                    for (String line = rdr.readLine(); line != null; line = rdr.readLine()) {
+                        for (String word : line.split(" ")) {
+                            if (!word.isEmpty()) {
+                                // Stream words into Ignite through socket.
+                                byte[] arr = word.getBytes("ASCII");
+
+                                // Write message
+                                oos.write(arr);
+
+                                // Write message delimiter
+                                oos.write(DELIM);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerServer.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerServer.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerServer.java
new file mode 100644
index 0000000..9e68096
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerServer.java
@@ -0,0 +1,124 @@
+/*
+ * 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.examples.streaming.wordcount.socket;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.affinity.*;
+import org.apache.ignite.examples.*;
+import org.apache.ignite.examples.streaming.wordcount.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.stream.*;
+import org.apache.ignite.stream.socket.*;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+/**
+ * Example demonstrates streaming of data from external components into Ignite cache.
+ * <p>
+ * {@code WordsSocketStreamerServer} is simple socket streaming server implementation that
+ * receives words from socket using {@link SocketStreamer} and message delimiter based protocol
+ * and streams them into Ignite cache. Example illustrates usage of TCP socket streamer in case of non-Java clients.
+ * In this example words are zero-terminated strings.
+ * <p>
+ * To start the example, you should:
+ * <ul>
+ *     <li>Start a few nodes using {@link ExampleNodeStartup}.</li>
+ *     <li>Start socket server using {@link WordsSocketStreamerServer}.</li>
+ *     <li>Start a few socket clients using {@link WordsSocketStreamerClient}.</li>
+ *     <li>Start querying popular words using {@link QueryWords}.</li>
+ * </ul>
+ */
+public class WordsSocketStreamerServer {
+    /** Port. */
+    private static final int PORT = 5555;
+
+    /** Delimiter. */
+    private static final byte[] DELIM = new byte[] {0};
+
+    /**
+     * Starts socket streaming server.
+     *
+     * @param args Command line arguments (none required).
+     * @throws Exception If failed.
+     */
+    public static void main(String[] args) throws Exception {
+        // Mark this cluster member as client.
+        Ignition.setClientMode(true);
+
+        Ignite ignite = Ignition.start("examples/config/example-ignite.xml");
+
+        if (!ExamplesUtils.hasServerNodes(ignite)) {
+            ignite.close();
+
+            return;
+        }
+
+        // The cache is configured with sliding window holding 1 second of the streaming data.
+        IgniteCache<AffinityUuid, String> stmCache = ignite.getOrCreateCache(CacheConfig.wordCache());
+
+        IgniteDataStreamer<AffinityUuid, String> stmr = ignite.dataStreamer(stmCache.getName());
+
+        InetAddress addr = InetAddress.getLocalHost();
+
+        // Configure socket streamer
+        SocketStreamer<String, AffinityUuid, String> sockStmr = new SocketStreamer<>();
+
+        sockStmr.setAddr(addr);
+
+        sockStmr.setPort(PORT);
+
+        sockStmr.setDelimiter(DELIM);
+
+        sockStmr.setIgnite(ignite);
+
+        sockStmr.setStreamer(stmr);
+
+        // Converter from zero-terminated string to Java strings.
+        sockStmr.setConverter(new SocketMessageConverter<String>() {
+            @Override public String convert(byte[] msg) {
+                try {
+                    return new String(msg, "ASCII");
+                }
+                catch (UnsupportedEncodingException e) {
+                    throw new IgniteException(e);
+                }
+            }
+        });
+
+        sockStmr.setTupleExtractor(new StreamTupleExtractor<String, AffinityUuid, String>() {
+            @Override public Map.Entry<AffinityUuid, String> extract(String word) {
+                // By using AffinityUuid we ensure that identical
+                // words are processed on the same cluster node.
+                return new IgniteBiTuple<>(new AffinityUuid(word), word);
+            }
+        });
+
+        try {
+            sockStmr.start();
+        }
+        catch (IgniteException e) {
+            System.err.println("Streaming server didn't start due to an error: ");
+
+            e.printStackTrace();
+
+            ignite.close();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/package-info.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/package-info.java
new file mode 100644
index 0000000..048299f
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Contains {@link org.apache.ignite.stream.socket.SocketStreamer} usage examples.
+ */
+package org.apache.ignite.examples.streaming.wordcount.socket;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/aop/pom.xml
----------------------------------------------------------------------
diff --git a/modules/aop/pom.xml b/modules/aop/pom.xml
index ef44603..85e9608 100644
--- a/modules/aop/pom.xml
+++ b/modules/aop/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-aop</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/aws/pom.xml
----------------------------------------------------------------------
diff --git a/modules/aws/pom.xml b/modules/aws/pom.xml
index 43f24bc..e5cdae7 100644
--- a/modules/aws/pom.xml
+++ b/modules/aws/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-aws</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/clients/config/grid-client-config.properties
----------------------------------------------------------------------
diff --git a/modules/clients/config/grid-client-config.properties b/modules/clients/config/grid-client-config.properties
index b6bce8d..d25352b 100644
--- a/modules/clients/config/grid-client-config.properties
+++ b/modules/clients/config/grid-client-config.properties
@@ -16,89 +16,89 @@
 #
 
 # Required. Comma-separated list of servers to connect to in format "host:port".
-gg.client.servers=localhost:11211
+ignite.client.servers=localhost:11211
 
 # Optional. Default client load balancer. Default value is "".
 # Balancer may be "random", "roundrobin" or full class name for "your.balancer.ImplementationClass"
-#gg.client.balancer=
+#ignite.client.balancer=
 
 # Optional. Socket connect timeout (ms). Default value is "0".
-#gg.client.connectTimeout=10000
+#ignite.client.connectTimeout=10000
 
 # Optional. Credentials if grid requires authentication. Default value is "".
-#gg.client.credentials=
+#ignite.client.credentials=
 
 # Optional. Flag indicating whether topology cache is enabled. Default value is "false".
-#gg.client.cacheTop=false
+#ignite.client.cacheTop=false
 
 # Optional. Max time of connection idleness (ms). Default value is "30000".
-#gg.client.idleTimeout=30000
+#ignite.client.idleTimeout=30000
 
 # Optional. Client protocol, one of TCP or HTTP. Default value is "TCP".
-#gg.client.protocol=TCP
+#ignite.client.protocol=TCP
 
 # Optional. TCP_NODELAY communication flag. Default value is "true".
-#gg.client.tcp.noDelay=true
+#ignite.client.tcp.noDelay=true
 
 # Optional. Topology refresh frequency (ms). Default value is "2000".
-#gg.client.topology.refresh=2000
+#ignite.client.topology.refresh=2000
 
 #
 # Data configurations.
 #
 
 # Optional. List of comma-separated names of data configurations. Default value is "".
-#gg.client.data.configurations=cfg1, cfg2
+#ignite.client.data.configurations=cfg1, cfg2
 
 # Optional. Cache name (space) to work with (for configuration 'cfg1').
-#gg.client.data.cfg1.name=
+#ignite.client.data.cfg1.name=
 
 # Optional. Specific load balancer for configuration 'cfg1'. Default value is "".
 # Balancer may be "random", "roundrobin" or full class name for "your.balancer.ImplementationClass"
-#gg.client.data.cfg1.balancer=random
+#ignite.client.data.cfg1.balancer=random
 
 # Optional. Specific affinity for configuration 'cfg1'. Default value is "".
 # Affinity may be "" (no affinity), "partitioned" or full class name for "your.affinity.ImplementationClass"
-#gg.client.data.cfg1.affinity=
+#ignite.client.data.cfg1.affinity=
 
 # Optional. Cache name (space) to work with (for configuration 'cfg2').
-#gg.client.data.cfg2.name=partitioned
+#ignite.client.data.cfg2.name=partitioned
 
 # Optional. Specific load balancer for configuration 'cfg2'. Default value is "".
 # Balancer may be "random", "roundrobin" or full class name for "your.balancer.ImplementationClass"
-#gg.client.data.cfg2.balancer=roundrobin
+#ignite.client.data.cfg2.balancer=roundrobin
 
 # Optional. Specific affinity for configuration 'cfg2'. Default value is "".
 # Affinity may be "" (no affinity), "partitioned" or full class name for "your.affinity.ImplementationClass"
-#gg.client.data.cfg2.affinity=partitioned
+#ignite.client.data.cfg2.affinity=partitioned
 
 #
 # SSL configuration.
 #
 
 # Optional. SSL enabled. Default value is "false".
-#gg.client.ssl.enabled=false
+#ignite.client.ssl.enabled=false
 
 # Optional. SSL protocol. Default value is "TLS".
-#gg.client.ssl.protocol=TLS
+#ignite.client.ssl.protocol=TLS
 
 # Optional. Key manager algorithm. Default value is "SunX509".
-#gg.client.ssl.key.algorithm=SunX509
+#ignite.client.ssl.key.algorithm=SunX509
 
 # Optional. Keystore to be used by client to connect with Ignite topology over SSL. Default value is "".
-#gg.client.ssl.keystore.location=
+#ignite.client.ssl.keystore.location=
 
 # Optional. Default value is "".
-#gg.client.ssl.keystore.password=
+#ignite.client.ssl.keystore.password=
 
 # Optional. Default value is "jks".
-#gg.client.ssl.keystore.type=jks
+#ignite.client.ssl.keystore.type=jks
 
 # Optional. Truststore to be used by client to connect with Ignite topology over SSL. Default value is "".
-#gg.client.ssl.truststore.location=
+#ignite.client.ssl.truststore.location=
 
 # Optional. Default value is "".
-#gg.client.ssl.truststore.password=
+#ignite.client.ssl.truststore.password=
 
 # Optional. Default value is "jks".
-#gg.client.ssl.truststore.type=jks
+#ignite.client.ssl.truststore.type=jks

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/clients/pom.xml
----------------------------------------------------------------------
diff --git a/modules/clients/pom.xml b/modules/clients/pom.xml
index ca93673..2132f24 100644
--- a/modules/clients/pom.xml
+++ b/modules/clients/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-clients</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/clients/src/test/java/org/apache/ignite/internal/client/impl/ClientPropertiesConfigurationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/impl/ClientPropertiesConfigurationSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/impl/ClientPropertiesConfigurationSelfTest.java
index 6e2a1eb..8e981d1 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/client/impl/ClientPropertiesConfigurationSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/impl/ClientPropertiesConfigurationSelfTest.java
@@ -85,8 +85,8 @@ public class ClientPropertiesConfigurationSelfTest extends GridCommonAbstractTes
         for (Map.Entry<Object, Object> e : props.entrySet())
             props2.put("new." + e.getKey(), e.getValue());
 
-        validateConfig(0, new GridClientConfiguration("new.gg.client", props2));
-        validateConfig(0, new GridClientConfiguration("new.gg.client.", props2));
+        validateConfig(0, new GridClientConfiguration("new.ignite.client", props2));
+        validateConfig(0, new GridClientConfiguration("new.ignite.client.", props2));
 
         // Validate loaded test configuration.
         File tmp = uncommentProperties(GRID_CLIENT_CONFIG);
@@ -100,14 +100,14 @@ public class ClientPropertiesConfigurationSelfTest extends GridCommonAbstractTes
         for (Map.Entry<Object, Object> e : props.entrySet())
             props2.put("new." + e.getKey(), e.getValue());
 
-        validateConfig(2, new GridClientConfiguration("new.gg.client", props2));
-        validateConfig(2, new GridClientConfiguration("new.gg.client.", props2));
+        validateConfig(2, new GridClientConfiguration("new.ignite.client", props2));
+        validateConfig(2, new GridClientConfiguration("new.ignite.client.", props2));
 
         // Validate loaded test configuration with empty key prefixes.
         props2 = new Properties();
 
         for (Map.Entry<Object, Object> e : props.entrySet())
-            props2.put(e.getKey().toString().replace("gg.client.", ""), e.getValue());
+            props2.put(e.getKey().toString().replace("ignite.client.", ""), e.getValue());
 
         validateConfig(2, new GridClientConfiguration("", props2));
         validateConfig(2, new GridClientConfiguration(".", props2));
@@ -156,7 +156,7 @@ public class ClientPropertiesConfigurationSelfTest extends GridCommonAbstractTes
         Collection<String> lines = new ArrayList<>();
 
         while (it.hasNext())
-            lines.add(it.nextLine().replace("#gg.client.", "gg.client."));
+            lines.add(it.nextLine().replace("#ignite.client.", "ignite.client."));
 
         IgniteUtils.closeQuiet(in);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractConnectivitySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractConnectivitySelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractConnectivitySelfTest.java
index 7272b2c..5aec7e5 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractConnectivitySelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractConnectivitySelfTest.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.client.integration;
 
 import org.apache.ignite.*;
 import org.apache.ignite.internal.client.*;
+import org.apache.ignite.internal.util.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
@@ -123,6 +124,19 @@ public abstract class ClientAbstractConnectivitySelfTest extends GridCommonAbstr
     }
 
     /**
+     * Simple test of address list filtering.
+     * @throws Exception
+     */
+    public void testResolveReachableOneAddress() throws Exception {
+        InetAddress addr = InetAddress.getByAddress(new byte[] {127, 0, 0, 1} );
+
+        List <InetAddress> filtered = IgniteUtils.filterReachable(Collections.singletonList(addr));
+
+        assertEquals(1, filtered.size());
+        assertEquals(addr, filtered.get(0));
+    }
+
+    /**
      * Tests correct behavior in case of 1 REST-enabled node
      * with explicitly specified loopback address setting.
      *

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/cloud/pom.xml
----------------------------------------------------------------------
diff --git a/modules/cloud/pom.xml b/modules/cloud/pom.xml
index 38c126f..e27dc2a 100644
--- a/modules/cloud/pom.xml
+++ b/modules/cloud/pom.xml
@@ -17,9 +17,7 @@
   limitations under the License.
 -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
     <modelVersion>4.0.0</modelVersion>
 
@@ -31,7 +29,7 @@
     </parent>
 
     <artifactId>ignite-cloud</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <properties>
         <jcloud.version>1.9.0</jcloud.version>
@@ -105,4 +103,4 @@
 
     </dependencies>
 
-</project>
\ No newline at end of file
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java
----------------------------------------------------------------------
diff --git a/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java b/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java
index 2637742..7555b16 100644
--- a/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java
+++ b/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java
@@ -30,6 +30,7 @@ import org.jclouds.*;
 import org.jclouds.compute.*;
 import org.jclouds.compute.domain.*;
 import org.jclouds.domain.*;
+import org.jclouds.googlecloud.*;
 import org.jclouds.location.reference.*;
 
 import java.io.*;
@@ -97,7 +98,7 @@ import java.util.concurrent.atomic.*;
  *                     &lt;bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.cloud.TcpDiscoveryCloudIpFinder"/&gt;
  *                         &lt;property name="provider" value="google-compute-engine"/&gt;
  *                         &lt;property name="identity" value="your_service_account_email"/&gt;
- *                         &lt;property name="credentialPath" value="path_to_pem_file"/&gt;
+ *                         &lt;property name="credentialPath" value="path_to_json_key"/&gt;
  *                         &lt;property name="zones"&gt;
  *                             &lt;list&gt;
  *                                 &lt;value>us-central1-a&lt/value&gt;
@@ -253,8 +254,7 @@ public class TcpDiscoveryCloudIpFinder extends TcpDiscoveryIpFinderAdapter {
     /**
      * Sets the path to a credential that is used during authentication on the cloud.
      *
-     * This method should be used when an access key or private key is stored in a plain or PEM file without
-     * a passphrase.
+     * This method should be used when an access key or private key is stored in a file.
      * Content of the file, referred by @{code credentialPath}, is fully read and used as a access key or private key
      * during authentication.
      *
@@ -322,7 +322,7 @@ public class TcpDiscoveryCloudIpFinder extends TcpDiscoveryIpFinderAdapter {
                     throw new IgniteSpiException("Both credential and credentialPath are set. Use only one method.");
 
                 if (credentialPath != null)
-                    credential = getPrivateKeyFromFile();
+                    credential = getCredentialFromFile();
 
                 try {
                     ContextBuilder ctxBuilder = ContextBuilder.newBuilder(provider);
@@ -398,13 +398,22 @@ public class TcpDiscoveryCloudIpFinder extends TcpDiscoveryIpFinderAdapter {
     }
 
     /**
-     * Retrieves a private key from the secrets file.
+     * Reads credential info from {@link #credentialPath} and returns in a string format.
      *
-     * @return Private key
+     * @return Credential in {@code String} representation.
+     * @throws IgniteSpiException In case of error.
      */
-    private String getPrivateKeyFromFile() throws IgniteSpiException {
+    private String getCredentialFromFile() throws IgniteSpiException {
         try {
-            return Files.toString(new File(credentialPath), Charsets.UTF_8);
+            String fileContents = Files.toString(new File(credentialPath), Charsets.UTF_8);
+
+            if (provider.equals("google-compute-engine")) {
+                Supplier<Credentials> credentialSupplier = new GoogleCredentialsFromJson(fileContents);
+
+                return credentialSupplier.get().credential;
+            }
+
+            return fileContents;
         }
         catch (IOException e) {
             throw new IgniteSpiException("Failed to retrieve the private key from the file: " + credentialPath, e);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java b/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java
index 7ac1994..d1d945f 100644
--- a/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java
+++ b/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java
@@ -101,14 +101,11 @@ public class TcpDiscoveryCloudIpFinderSelfTest extends
 
         if (provider.equals("google-compute-engine"))
             ipFinder.setCredentialPath(IgniteCloudTestSuite.getSecretKey(provider));
-        else {
+        else
             ipFinder.setCredential(IgniteCloudTestSuite.getSecretKey(provider));
-        }
 
         Collection<InetSocketAddress> addresses = ipFinder.getRegisteredAddresses();
 
-        assert addresses.size() > 0;
-
         for (InetSocketAddress addr : addresses)
             info("Registered instance: " + addr.getAddress().getHostAddress() + ":" + addr.getPort());
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/codegen/pom.xml
----------------------------------------------------------------------
diff --git a/modules/codegen/pom.xml b/modules/codegen/pom.xml
index 9e03dab..32bd7c2 100644
--- a/modules/codegen/pom.xml
+++ b/modules/codegen/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-codegen</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java b/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
index f75bcf4..0540148 100644
--- a/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
+++ b/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.codegen;
 
 import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.processors.datastreamer.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.plugin.extensions.communication.*;
@@ -46,6 +45,9 @@ public class MessageCodeGenerator {
     private static final String DFLT_SRC_DIR = U.getIgniteHome() + "/modules/core/src/main/java";
 
     /** */
+    private static final String INDEXING_SRC_DIR = U.getIgniteHome() + "/modules/indexing/src/main/java";
+
+    /** */
     private static final Class<?> BASE_CLS = Message.class;
 
     /** */
@@ -140,7 +142,7 @@ public class MessageCodeGenerator {
 
         MessageCodeGenerator gen = new MessageCodeGenerator(srcDir);
 
-        gen.generateAndWrite(DataStreamerEntry.class);
+//        gen.generateAndWrite(DataStreamerEntry.class);
 
 //        gen.generateAndWrite(GridDistributedLockRequest.class);
 //        gen.generateAndWrite(GridDistributedLockResponse.class);
@@ -163,8 +165,8 @@ public class MessageCodeGenerator {
 //        gen.generateAndWrite(GridDhtTxFinishRequest.class);
 //        gen.generateAndWrite(GridDhtTxFinishResponse.class);
 //
-//        gen.generateAndWrite(GridCacheOptimisticCheckPreparedTxRequest.class);
-//        gen.generateAndWrite(GridCacheOptimisticCheckPreparedTxResponse.class);
+//        gen.generateAndWrite(GridCacheTxRecoveryRequest.class);
+//        gen.generateAndWrite(GridCacheTxRecoveryResponse.class);
 
 //        gen.generateAndWrite(GridQueryCancelRequest.class);
 //        gen.generateAndWrite(GridQueryFailResponse.class);
@@ -172,6 +174,26 @@ public class MessageCodeGenerator {
 //        gen.generateAndWrite(GridQueryNextPageResponse.class);
 //        gen.generateAndWrite(GridQueryRequest.class);
 //        gen.generateAndWrite(GridCacheSqlQuery.class);
+
+//        gen.generateAndWrite(GridH2Null.class);
+//        gen.generateAndWrite(GridH2Boolean.class);
+//        gen.generateAndWrite(GridH2Byte.class);
+//        gen.generateAndWrite(GridH2Short.class);
+//        gen.generateAndWrite(GridH2Integer.class);
+//        gen.generateAndWrite(GridH2Long.class);
+//        gen.generateAndWrite(GridH2Decimal.class);
+//        gen.generateAndWrite(GridH2Double.class);
+//        gen.generateAndWrite(GridH2Float.class);
+//        gen.generateAndWrite(GridH2Time.class);
+//        gen.generateAndWrite(GridH2Date.class);
+//        gen.generateAndWrite(GridH2Timestamp.class);
+//        gen.generateAndWrite(GridH2Bytes.class);
+//        gen.generateAndWrite(GridH2String.class);
+//        gen.generateAndWrite(GridH2Array.class);
+//        gen.generateAndWrite(GridH2JavaObject.class);
+//        gen.generateAndWrite(GridH2Uuid.class);
+//        gen.generateAndWrite(GridH2Geometry.class);
+//        gen.generateAndWrite(GridH2CacheObject.class);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/pom.xml
----------------------------------------------------------------------
diff --git a/modules/core/pom.xml b/modules/core/pom.xml
index 62612f8..0460b46 100644
--- a/modules/core/pom.xml
+++ b/modules/core/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-core</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/META-INF/LICENSE
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/META-INF/LICENSE b/modules/core/src/main/java/META-INF/LICENSE
new file mode 100644
index 0000000..7649b39
--- /dev/null
+++ b/modules/core/src/main/java/META-INF/LICENSE
@@ -0,0 +1,238 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+
+
+
+==============================================================================
+Apache Ignite (incubating) Subcomponents:
+
+The Apache Ignite project contains subcomponents with separate copyright
+notices and license terms. Your use of the source code for the these
+subcomponents is subject to the terms and conditions of the following
+licenses.
+
+
+==============================================================================
+For SnapTree:
+==============================================================================
+This product bundles SnapTree, which is available under a
+"3-clause BSD" license.  For details, see
+https://github.com/nbronson/snaptree/blob/master/LICENSE.
+
+==============================================================================
+For JSR 166 classes in "org.jsr166" package
+==============================================================================
+This product bundles JSR-166 classes which are donated to public domain.
+For details, see CC0 1.0 Universal (1.0), Public Domain Dedication,
+http://creativecommons.org/publicdomain/zero/1.0/
+
+==============================================================================
+For books used for tests in "org.apache.ignite.internal.processors.hadoop.books"
+==============================================================================
+This code bundles book text files used for testing purposes which contain
+the following header:
+
+This eBook is for the use of anyone anywhere at no cost and with
+almost no restrictions whatsoever.  You may copy it, give it away or
+re-use it under the terms of the Project Gutenberg License included
+with this eBook or online at www.gutenberg.org

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/META-INF/NOTICE
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/META-INF/NOTICE b/modules/core/src/main/java/META-INF/NOTICE
new file mode 100644
index 0000000..298d05b
--- /dev/null
+++ b/modules/core/src/main/java/META-INF/NOTICE
@@ -0,0 +1,12 @@
+Apache Ignite (incubating)
+Copyright 2015 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+
+This software includes code from IntelliJ IDEA Community Edition
+Copyright (C) JetBrains s.r.o.
+https://www.jetbrains.com/idea/
+Licensed under Apache License, Version 2.0.
+http://search.maven.org/#artifactdetails%7Corg.jetbrains%7Cannotations%7C13.0%7Cjar

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/Ignite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java
index 40c9bbb..209946b 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignite.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java
@@ -103,9 +103,9 @@ public interface Ignite extends AutoCloseable {
     public IgniteCluster cluster();
 
     /**
-     * Gets {@code compute} facade over all cluster nodes.
+     * Gets {@code compute} facade over all cluster nodes started in server mode.
      *
-     * @return Compute instance over all cluster nodes.
+     * @return Compute instance over all cluster nodes started in server mode.
      */
     public IgniteCompute compute();
 
@@ -154,9 +154,9 @@ public interface Ignite extends AutoCloseable {
     public IgniteEvents events(ClusterGroup grp);
 
     /**
-     * Gets {@code services} facade over all cluster nodes.
+     * Gets {@code services} facade over all cluster nodes started in server mode.
      *
-     * @return Services facade over all cluster nodes.
+     * @return Services facade over all cluster nodes started in server mode.
      */
     public IgniteServices services();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index d99902a..f9007a2 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -499,6 +499,11 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
         CacheEntryProcessor<K, V, T> entryProcessor, Object... args);
 
     /**
+     * Completely deletes the cache with all its data from the system on all cluster nodes.
+     */
+    @Override void close();
+
+    /**
      * This cache node to re-balance its partitions. This method is usually used when
      * {@link CacheConfiguration#getRebalanceDelay()} configuration parameter has non-zero value.
      * When many nodes are started or stopped almost concurrently, it is more efficient to delay

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
index a7c2eae..17ec221 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
@@ -90,101 +90,101 @@ import java.util.logging.*;
  *         <th>Optional</th>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.protocol</b></td>
+ *         <td><b>ignite.client.protocol</b></td>
  *         <td>Communication protocol ({@code TCP} or {@code HTTP}).</td>
  *         <td>{@code TCP}</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.connectTimeout</b></td>
+ *         <td><b>ignite.client.connectTimeout</b></td>
  *         <td>Socket connection timeout.</td>
  *         <td>{@code 0} (infinite timeout)</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.tcp.noDelay</b></td>
+ *         <td><b>ignite.client.tcp.noDelay</b></td>
  *         <td>Flag indicating whether TCP_NODELAY flag should be enabled for outgoing connections.</td>
  *         <td>{@code true}</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.ssl.enabled</b></td>
+ *         <td><b>ignite.client.ssl.enabled</b></td>
  *         <td>Flag indicating that {@code SSL} is needed for connection.</td>
  *         <td>{@code false}</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.ssl.protocol</b></td>
+ *         <td><b>ignite.client.ssl.protocol</b></td>
  *         <td>SSL protocol ({@code SSL} or {@code TLS}).</td>
  *         <td>{@code TLS}</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.ssl.key.algorithm</b></td>
+ *         <td><b>ignite.client.ssl.key.algorithm</b></td>
  *         <td>Key manager algorithm.</td>
  *         <td>{@code SunX509}</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.ssl.keystore.location</b></td>
+ *         <td><b>ignite.client.ssl.keystore.location</b></td>
  *         <td>Key store to be used by client to connect with Ignite topology.</td>
  *         <td>&nbsp;</td>
  *         <td>No (if {@code SSL} is enabled)</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.ssl.keystore.password</b></td>
+ *         <td><b>ignite.client.ssl.keystore.password</b></td>
  *         <td>Key store password.</td>
  *         <td>&nbsp;</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.ssl.keystore.type</b></td>
+ *         <td><b>ignite.client.ssl.keystore.type</b></td>
  *         <td>Key store type.</td>
  *         <td>{@code jks}</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.ssl.truststore.location</b></td>
+ *         <td><b>ignite.client.ssl.truststore.location</b></td>
  *         <td>Trust store to be used by client to connect with Ignite topology.</td>
  *         <td>&nbsp;</td>
  *         <td>No (if {@code SSL} is enabled)</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.ssl.truststore.password</b></td>
+ *         <td><b>ignite.client.ssl.truststore.password</b></td>
  *         <td>Trust store password.</td>
  *         <td>&nbsp;</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.ssl.truststore.type</b></td>
+ *         <td><b>ignite.client.ssl.truststore.type</b></td>
  *         <td>Trust store type.</td>
  *         <td>{@code jks}</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.credentials</b></td>
+ *         <td><b>ignite.client.credentials</b></td>
  *         <td>Client credentials used in authentication process.</td>
  *         <td>&nbsp;</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.cache.top</b></td>
+ *         <td><b>ignite.client.cache.top</b></td>
  *         <td>
  *             Flag indicating that topology is cached internally. Cache will be refreshed in
- *             the background with interval defined by {@code gg.client.topology.refresh}
+ *             the background with interval defined by {@code ignite.client.topology.refresh}
  *             property (see below).
  *         </td>
  *         <td>{@code false}</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.topology.refresh</b></td>
+ *         <td><b>ignite.client.topology.refresh</b></td>
  *         <td>Topology cache refresh frequency (ms).</td>
  *         <td>{@code 2000}</td>
  *         <td>Yes</td>
  *     </tr>
  *     <tr>
- *         <td><b>gg.client.idleTimeout</b></td>
+ *         <td><b>ignite.client.idleTimeout</b></td>
  *         <td>Maximum amount of time that connection can be idle before it is closed (ms).</td>
  *         <td>{@code 30000}</td>
  *         <td>Yes</td>
@@ -225,7 +225,7 @@ import java.util.logging.*;
 @SuppressWarnings("JavadocReference")
 public class IgniteJdbcDriver implements Driver {
     /** Prefix for property names. */
-    private static final String PROP_PREFIX = "gg.jdbc.";
+    private static final String PROP_PREFIX = "ignite.jdbc.";
 
     /** Hostname property name. */
     public static final String PROP_HOST = PROP_PREFIX + "host";
@@ -236,11 +236,8 @@ public class IgniteJdbcDriver implements Driver {
     /** Cache name property name. */
     public static final String PROP_CACHE = PROP_PREFIX + "cache";
 
-    /** Node ID URL parameter name. */
-    public static final String PARAM_NODE_ID = "nodeId";
-
     /** Node ID property name. */
-    public static final String PROP_NODE_ID = PROP_PREFIX + PARAM_NODE_ID;
+    public static final String PROP_NODE_ID = PROP_PREFIX + "nodeId";
 
     /** URL prefix. */
     public static final String URL_PREFIX = "jdbc:ignite://";
@@ -290,40 +287,40 @@ public class IgniteJdbcDriver implements Driver {
         props[1] = new PropertyInfo("Port number", info.getProperty(PROP_PORT), "");
         props[2] = new PropertyInfo("Cache name", info.getProperty(PROP_CACHE), "");
         props[3] = new PropertyInfo("Node ID", info.getProperty(PROP_NODE_ID, ""));
-        props[4] = new PropertyInfo("gg.client.protocol", info.getProperty("gg.client.protocol", "TCP"),
+        props[4] = new PropertyInfo("ignite.client.protocol", info.getProperty("ignite.client.protocol", "TCP"),
             "Communication protocol (TCP or HTTP).");
-        props[5] = new PropertyInfo("gg.client.connectTimeout", info.getProperty("gg.client.connectTimeout", "0"),
+        props[5] = new PropertyInfo("ignite.client.connectTimeout", info.getProperty("ignite.client.connectTimeout", "0"),
             "Socket connection timeout.");
-        props[6] = new PropertyInfo("gg.client.tcp.noDelay", info.getProperty("gg.client.tcp.noDelay", "true"),
+        props[6] = new PropertyInfo("ignite.client.tcp.noDelay", info.getProperty("ignite.client.tcp.noDelay", "true"),
             "Flag indicating whether TCP_NODELAY flag should be enabled for outgoing connections.");
-        props[7] = new PropertyInfo("gg.client.ssl.enabled", info.getProperty("gg.client.ssl.enabled", "false"),
+        props[7] = new PropertyInfo("ignite.client.ssl.enabled", info.getProperty("ignite.client.ssl.enabled", "false"),
             "Flag indicating that SSL is needed for connection.");
-        props[8] = new PropertyInfo("gg.client.ssl.protocol", info.getProperty("gg.client.ssl.protocol", "TLS"),
+        props[8] = new PropertyInfo("ignite.client.ssl.protocol", info.getProperty("ignite.client.ssl.protocol", "TLS"),
             "SSL protocol.");
-        props[9] = new PropertyInfo("gg.client.ssl.key.algorithm", info.getProperty("gg.client.ssl.key.algorithm",
+        props[9] = new PropertyInfo("ignite.client.ssl.key.algorithm", info.getProperty("ignite.client.ssl.key.algorithm",
             "SunX509"), "Key manager algorithm.");
-        props[10] = new PropertyInfo("gg.client.ssl.keystore.location",
-            info.getProperty("gg.client.ssl.keystore.location", ""),
+        props[10] = new PropertyInfo("ignite.client.ssl.keystore.location",
+            info.getProperty("ignite.client.ssl.keystore.location", ""),
             "Key store to be used by client to connect with Ignite topology.");
-        props[11] = new PropertyInfo("gg.client.ssl.keystore.password",
-            info.getProperty("gg.client.ssl.keystore.password", ""), "Key store password.");
-        props[12] = new PropertyInfo("gg.client.ssl.keystore.type", info.getProperty("gg.client.ssl.keystore.type",
+        props[11] = new PropertyInfo("ignite.client.ssl.keystore.password",
+            info.getProperty("ignite.client.ssl.keystore.password", ""), "Key store password.");
+        props[12] = new PropertyInfo("ignite.client.ssl.keystore.type", info.getProperty("ignite.client.ssl.keystore.type",
             "jks"), "Key store type.");
-        props[13] = new PropertyInfo("gg.client.ssl.truststore.location",
-            info.getProperty("gg.client.ssl.truststore.location", ""),
+        props[13] = new PropertyInfo("ignite.client.ssl.truststore.location",
+            info.getProperty("ignite.client.ssl.truststore.location", ""),
             "Trust store to be used by client to connect with Ignite topology.");
-        props[14] = new PropertyInfo("gg.client.ssl.keystore.password",
-            info.getProperty("gg.client.ssl.truststore.password", ""), "Trust store password.");
-        props[15] = new PropertyInfo("gg.client.ssl.truststore.type", info.getProperty("gg.client.ssl.truststore.type",
+        props[14] = new PropertyInfo("ignite.client.ssl.keystore.password",
+            info.getProperty("ignite.client.ssl.truststore.password", ""), "Trust store password.");
+        props[15] = new PropertyInfo("ignite.client.ssl.truststore.type", info.getProperty("ignite.client.ssl.truststore.type",
             "jks"), "Trust store type.");
-        props[16] = new PropertyInfo("gg.client.credentials", info.getProperty("gg.client.credentials", ""),
+        props[16] = new PropertyInfo("ignite.client.credentials", info.getProperty("ignite.client.credentials", ""),
             "Client credentials used in authentication process.");
-        props[17] = new PropertyInfo("gg.client.cache.top", info.getProperty("gg.client.cache.top", "false"),
+        props[17] = new PropertyInfo("ignite.client.cache.top", info.getProperty("ignite.client.cache.top", "false"),
             "Flag indicating that topology is cached internally. Cache will be refreshed in the background with " +
                 "interval defined by topologyRefreshFrequency property (see below).");
-        props[18] = new PropertyInfo("gg.client.topology.refresh", info.getProperty("gg.client.topology.refresh",
+        props[18] = new PropertyInfo("ignite.client.topology.refresh", info.getProperty("ignite.client.topology.refresh",
             "2000"), "Topology cache refresh frequency (ms).");
-        props[19] = new PropertyInfo("gg.client.idleTimeout", info.getProperty("gg.client.idleTimeout", "30000"),
+        props[19] = new PropertyInfo("ignite.client.idleTimeout", info.getProperty("ignite.client.idleTimeout", "30000"),
             "Maximum amount of time that connection can be idle before it is closed (ms).");
 
         return props;



[04/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedSelfTest.java
index 66e2470..23a97c9 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryMultiThreadedSelfTest.java
@@ -86,6 +86,17 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends GridCommonAbstractTes
         cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
         cfg.setMarshaller(new OptimizedMarshaller(false));
 
+        cfg.setCacheConfiguration(cacheConfiguration());
+
+        GridQueryProcessor.idxCls = FakeIndexing.class;
+
+        return cfg;
+    }
+
+    /**
+     * @return Cache configuration.
+     */
+    protected CacheConfiguration cacheConfiguration() {
         CacheConfiguration<?,?> cacheCfg = defaultCacheConfiguration();
 
         cacheCfg.setCacheMode(PARTITIONED);
@@ -106,26 +117,22 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends GridCommonAbstractTes
         if (offheapEnabled())
             cacheCfg.setOffHeapMaxMemory(evictsEnabled() ? 1000 : 0); // Small offheap for evictions.
 
-        cfg.setCacheConfiguration(cacheCfg);
-
-        GridQueryProcessor.idxCls = FakeIndexing.class;
-
-        return cfg;
+        return cacheCfg;
     }
 
     /**
      *
      */
     private static class FakeIndexing extends IgniteH2Indexing {
-        @Override public void onSwap(@Nullable String spaceName, Object key) throws IgniteCheckedException {
+        @Override public void onSwap(@Nullable String spaceName, CacheObject key) throws IgniteCheckedException {
             super.onSwap(spaceName, key);
 
             idxSwapCnt.incrementAndGet();
         }
 
-        @Override public void onUnswap(@Nullable String spaceName, Object key, Object val, byte[] valBytes)
+        @Override public void onUnswap(@Nullable String spaceName, CacheObject key, CacheObject val)
         throws IgniteCheckedException {
-            super.onUnswap(spaceName, key, val, valBytes);
+            super.onUnswap(spaceName, key, val);
 
             idxUnswapCnt.incrementAndGet();
         }
@@ -235,6 +242,9 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends GridCommonAbstractTes
         final IgniteCache<Integer, String> c = g.cache(null);
         final IgniteCache<Integer, Long> cl = g.cache(null);
 
+        if (c.getConfiguration(CacheConfiguration.class).getMemoryMode() == CacheMemoryMode.OFFHEAP_TIERED)
+            return;
+
         assertEquals(0, g.cache(null).localSize());
         assertEquals(0, c.query(new SqlQuery(String.class, "1 = 1")).getAll().size());
         assertEquals(0, cl.query(new SqlQuery(Long.class, "1 = 1")).getAll().size());
@@ -307,6 +317,9 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends GridCommonAbstractTes
         final IgniteCache<Integer, Long> c = g.cache(null);
         final IgniteCache<Integer, String> c1 = g.cache(null);
 
+        if (c.getConfiguration(CacheConfiguration.class).getMemoryMode() == CacheMemoryMode.OFFHEAP_TIERED)
+            return;
+
         assertEquals(0, g.cache(null).localSize());
         assertEquals(0, c1.query(new SqlQuery(String.class, "1 = 1")).getAll().size());
         assertEquals(0, c.query(new SqlQuery(Long.class, "1 = 1")).getAll().size());
@@ -379,6 +392,9 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends GridCommonAbstractTes
         // Put test values into cache.
         final IgniteCache<Integer, Object> c = g.cache(null);
 
+        if (c.getConfiguration(CacheConfiguration.class).getMemoryMode() == CacheMemoryMode.OFFHEAP_TIERED)
+            return;
+
         assertEquals(0, g.cache(null).size());
         assertEquals(0, c.query(new SqlQuery(Object.class, "1 = 1")).getAll().size());
 
@@ -450,6 +466,9 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends GridCommonAbstractTes
         // Put test values into cache.
         final IgniteCache<Integer, TestValue> c = g.cache(null);
 
+        if (c.getConfiguration(CacheConfiguration.class).getMemoryMode() == CacheMemoryMode.OFFHEAP_TIERED)
+            return;
+
         assertEquals(0, g.cache(null).localSize());
         assertEquals(0, c.query(new SqlQuery(TestValue.class, "1 = 1")).getAll().size());
 
@@ -691,7 +710,7 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends GridCommonAbstractTes
      */
     private static class TestValue implements Serializable {
         /** Value. */
-        @QuerySqlField
+        @QuerySqlField(index = true)
         private int val;
 
         /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
index c489d35..48dc6f2 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
@@ -78,5 +78,11 @@ public class IgniteCacheLocalQuerySelfTest extends IgniteCacheAbstractQuerySelfT
         assert iter.next() != null;
         assert iter.next() != null;
         assert !iter.hasNext();
+
+        // Test explain for primitive index.
+        List<List<?>> res = cache.query(new SqlFieldsQuery(
+            "explain select _key from String where _val > 'value1'").setLocal(true)).getAll();
+
+        assertTrue("__ explain: \n" + res, ((String)res.get(0).get(0)).contains("_val_idx"));
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 d52e173..3ec67b2 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
@@ -19,14 +19,20 @@ package org.apache.ignite.internal.processors.query.h2;
 
 import org.apache.ignite.*;
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.apache.ignite.spi.*;
 import org.apache.ignite.testframework.*;
 import org.apache.ignite.testframework.junits.common.*;
+import org.h2.util.*;
+import org.jetbrains.annotations.*;
 
+import java.nio.*;
 import java.util.*;
 import java.util.concurrent.*;
 
@@ -108,14 +114,14 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
      * @param age Age.
      * @return AA.
      */
-    private Map<String, Object> aa(long id, String name, int age) {
+    private CacheObject aa(long id, String name, int age) {
         Map<String, Object> map = new HashMap<>();
 
         map.put("id", id);
         map.put("name", name);
         map.put("age", age);
 
-        return map;
+        return new TestCacheObject(map);
     }
 
     /**
@@ -125,12 +131,12 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
      * @param txt Text.
      * @return AB.
      */
-    private Map<String, Object> ab(long id, String name, int age, String txt) {
-        Map<String, Object> map = aa(id, name, age);
+    private CacheObject ab(long id, String name, int age, String txt) {
+        Map<String, Object> map = aa(id, name, age).value(null, false);
 
         map.put("txt", txt);
 
-        return map;
+        return new TestCacheObject(map);
     }
 
     /**
@@ -140,12 +146,12 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
      * @param sex Sex.
      * @return BA.
      */
-    private Map<String, Object> ba(long id, String name, int age, boolean sex) {
-        Map<String, Object> map = aa(id, name, age);
+    private CacheObject ba(long id, String name, int age, boolean sex) {
+        Map<String, Object> map = aa(id, name, age).value(null, false);
 
         map.put("sex", sex);
 
-        return map;
+        return new TestCacheObject(map);
     }
 
     /**
@@ -169,6 +175,14 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
     }
 
     /**
+     * @param key Key.
+     * @return Cache object.
+     */
+    private CacheObject key(int key) {
+        return new TestCacheObject(key);
+    }
+
+    /**
      * @throws Exception If failed.
      */
     public void testSpi() throws Exception {
@@ -202,16 +216,16 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         assertFalse(spi.query(typeBA.space(), "select * from B.A", Collections.emptySet(), typeBA, null).hasNext());
 
         // Nothing to remove.
-        spi.remove("A", 1, aa(1, "", 10));
-        spi.remove("B", 1, ba(1, "", 10, true));
+        spi.remove("A", key(1), aa(1, "", 10));
+        spi.remove("B", key(1), ba(1, "", 10, true));
 
-        spi.store(typeAA.space(), typeAA, 1, aa(1, "Vasya", 10), "v1".getBytes(), 0);
+        spi.store(typeAA.space(), typeAA, key(1), aa(1, "Vasya", 10), "v1".getBytes(), 0);
 
         assertEquals(1, spi.size(typeAA.space(), typeAA, null));
         assertEquals(0, spi.size(typeAB.space(), typeAB, null));
         assertEquals(0, spi.size(typeBA.space(), typeBA, null));
 
-        spi.store(typeAB.space(), typeAB, 1, ab(1, "Vasya", 20, "Some text about Vasya goes here."),
+        spi.store(typeAB.space(), typeAB, key(1), ab(1, "Vasya", 20, "Some text about Vasya goes here."),
             "v2".getBytes(), 0);
 
         // In one space all keys must be unique.
@@ -219,33 +233,33 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         assertEquals(1, spi.size(typeAB.space(), typeAB, null));
         assertEquals(0, spi.size(typeBA.space(), typeBA, null));
 
-        spi.store(typeBA.space(), typeBA, 1, ba(2, "Petya", 25, true), "v3".getBytes(), 0);
+        spi.store(typeBA.space(), typeBA, key(1), ba(2, "Petya", 25, true), "v3".getBytes(), 0);
 
         // No replacement because of different space.
         assertEquals(0, spi.size(typeAA.space(), typeAA, null));
         assertEquals(1, spi.size(typeAB.space(), typeAB, null));
         assertEquals(1, spi.size(typeBA.space(), typeBA, null));
 
-        spi.store(typeBA.space(), typeBA, 1, ba(2, "Kolya", 25, true), "v4".getBytes(), 0);
+        spi.store(typeBA.space(), typeBA, key(1), ba(2, "Kolya", 25, true), "v4".getBytes(), 0);
 
         // Replacement in the same table.
         assertEquals(0, spi.size(typeAA.space(), typeAA, null));
         assertEquals(1, spi.size(typeAB.space(), typeAB, null));
         assertEquals(1, spi.size(typeBA.space(), typeBA, null));
 
-        spi.store(typeAA.space(), typeAA, 2, aa(2, "Valera", 19), "v5".getBytes(), 0);
+        spi.store(typeAA.space(), typeAA, key(2), aa(2, "Valera", 19), "v5".getBytes(), 0);
 
         assertEquals(1, spi.size(typeAA.space(), typeAA, null));
         assertEquals(1, spi.size(typeAB.space(), typeAB, null));
         assertEquals(1, spi.size(typeBA.space(), typeBA, null));
 
-        spi.store(typeAA.space(), typeAA, 3, aa(3, "Borya", 18), "v6".getBytes(), 0);
+        spi.store(typeAA.space(), typeAA, key(3), aa(3, "Borya", 18), "v6".getBytes(), 0);
 
         assertEquals(2, spi.size(typeAA.space(), typeAA, null));
         assertEquals(1, spi.size(typeAB.space(), typeAB, null));
         assertEquals(1, spi.size(typeBA.space(), typeBA, null));
 
-        spi.store(typeAB.space(), typeAB, 4, ab(4, "Vitalya", 20, "Very Good guy"), "v7".getBytes(), 0);
+        spi.store(typeAB.space(), typeAB, key(4), ab(4, "Vitalya", 20, "Very Good guy"), "v7".getBytes(), 0);
 
         assertEquals(2, spi.size(typeAA.space(), typeAA, null));
         assertEquals(2, spi.size(typeAB.space(), typeAB, null));
@@ -256,23 +270,23 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
             spi.query(typeAA.space(), "from a order by age", Collections.emptySet(), typeAA, null);
 
         assertTrue(res.hasNext());
-        assertEquals(aa(3, "Borya", 18), value(res.next()));
+        assertEquals(aa(3, "Borya", 18).value(null, false), value(res.next()));
         assertTrue(res.hasNext());
-        assertEquals(aa(2, "Valera", 19), value(res.next()));
+        assertEquals(aa(2, "Valera", 19).value(null, false), value(res.next()));
         assertFalse(res.hasNext());
 
         res = spi.query(typeAB.space(), "from b order by name", Collections.emptySet(), typeAB, null);
 
         assertTrue(res.hasNext());
-        assertEquals(ab(1, "Vasya", 20, "Some text about Vasya goes here."), value(res.next()));
+        assertEquals(ab(1, "Vasya", 20, "Some text about Vasya goes here.").value(null, false), value(res.next()));
         assertTrue(res.hasNext());
-        assertEquals(ab(4, "Vitalya", 20, "Very Good guy"), value(res.next()));
+        assertEquals(ab(4, "Vitalya", 20, "Very Good guy").value(null, false), value(res.next()));
         assertFalse(res.hasNext());
 
         res = spi.query(typeBA.space(), "from a", Collections.emptySet(), typeBA, null);
 
         assertTrue(res.hasNext());
-        assertEquals(ba(2, "Kolya", 25, true), value(res.next()));
+        assertEquals(ba(2, "Kolya", 25, true).value(null, false), value(res.next()));
         assertFalse(res.hasNext());
 
         // Text queries
@@ -280,7 +294,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
             typeAB, null);
 
         assertTrue(txtRes.hasNext());
-        assertEquals(ab(4, "Vitalya", 20, "Very Good guy"), value(txtRes.next()));
+        assertEquals(ab(4, "Vitalya", 20, "Very Good guy").value(null, false), value(txtRes.next()));
         assertFalse(txtRes.hasNext());
 
         // Fields query
@@ -307,13 +321,13 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         assertFalse(fieldsRes.iterator().hasNext());
 
         // Remove
-        spi.remove(typeAA.space(), 2, aa(2, "Valera", 19));
+        spi.remove(typeAA.space(), key(2), aa(2, "Valera", 19));
 
         assertEquals(1, spi.size(typeAA.space(), typeAA, null));
         assertEquals(2, spi.size(typeAB.space(), typeAB, null));
         assertEquals(1, spi.size(typeBA.space(), typeBA, null));
 
-        spi.remove(typeBA.space(), 1, ba(2, "Kolya", 25, true));
+        spi.remove(typeBA.space(), key(1), ba(2, "Kolya", 25, true));
 
         assertEquals(1, spi.size(typeAA.space(), typeAA, null));
         assertEquals(2, spi.size(typeAB.space(), typeAB, null));
@@ -352,7 +366,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         spi.unregisterType(typeBA.space(), typeBA);
 
         // Should not store but should not fail as well.
-        spi.store(typeAA.space(), typeAA, 10, aa(1, "Fail", 100500), "v220".getBytes(), 0);
+        spi.store(typeAA.space(), typeAA, key(10), aa(1, "Fail", 100500), "v220".getBytes(), 0);
 
         assertEquals(-1, spi.size(typeAA.space(), typeAA, null));
     }
@@ -526,4 +540,68 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
             return textIdx == null;
         }
     }
+
+    /**
+     */
+    private static class TestCacheObject implements CacheObject {
+        /** */
+        private Object val;
+
+        /**
+         * @param val Value.
+         */
+        private TestCacheObject(Object val) {
+            this.val = val;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+            return (T)val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+            return Utils.serialize(val, null);
+        }
+
+        /** {@inheritDoc} */
+        @Override public byte type() {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public byte directType() {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public byte fieldsCount() {
+            throw new UnsupportedOperationException();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 7cdf0bc..99366f0 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
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.query.h2.sql;
 
+import org.apache.ignite.*;
 import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.affinity.*;
 import org.apache.ignite.cache.query.*;
@@ -180,6 +181,21 @@ public class BaseH2CompareQueryTest extends AbstractH2CompareQueryTest {
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testInvalidQuery() throws Exception {
+        final SqlFieldsQuery sql = new SqlFieldsQuery("SELECT firstName from Person where id <> ? and orgId <> ?");
+
+        GridTestUtils.assertThrows(log, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                pCache.query(sql.setArgs(3));
+
+                return null;
+            }
+        }, IgniteException.class, "Invalid number of query parameters.");
+    }
+
+    /**
      * @throws Exception
      */
     // TODO: IGNITE-705

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
index ce05980..f42963a 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
@@ -59,6 +59,7 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
         suite.addTestSuite(IgniteCacheLargeResultSelfTest.class);
         suite.addTestSuite(GridCacheQueryInternalKeysSelfTest.class);
         suite.addTestSuite(IgniteCacheQueryMultiThreadedSelfTest.class);
+        suite.addTestSuite(IgniteCacheQueryMultiThreadedOffHeapTiredSelfTest.class);
         suite.addTestSuite(IgniteCacheQueryEvictsMultiThreadedSelfTest.class);
         suite.addTestSuite(IgniteCacheQueryOffheapMultiThreadedSelfTest.class);
         suite.addTestSuite(IgniteCacheQueryOffheapEvictsMultiThreadedSelfTest.class);
@@ -111,6 +112,9 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
 
         suite.addTestSuite(GridCacheQueryMetricsSelfTest.class);
 
+        //Unmarshallig query test.
+        suite.addTestSuite(IgniteCacheP2pUnmarshallingQueryErrorTest.class);
+
         return suite;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
index a2ccc82..ae45120 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
@@ -46,6 +46,8 @@ public class IgniteCacheWithIndexingTestSuite extends TestSuite {
         suite.addTestSuite(CacheTtlOnheapAtomicLocalSelfTest.class);
         suite.addTestSuite(CacheTtlOnheapAtomicPartitionedSelfTest.class);
 
+        suite.addTestSuite(GridCacheOffheapIndexGetSelfTest.class);
+
         suite.addTestSuite(CacheConfigurationP2PTest.class);
 
         return suite;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/jcl/pom.xml
----------------------------------------------------------------------
diff --git a/modules/jcl/pom.xml b/modules/jcl/pom.xml
index 8a3cec3..907844b 100644
--- a/modules/jcl/pom.xml
+++ b/modules/jcl/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-jcl</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/jta/pom.xml
----------------------------------------------------------------------
diff --git a/modules/jta/pom.xml b/modules/jta/pom.xml
index 9287f12..3b70ad3 100644
--- a/modules/jta/pom.xml
+++ b/modules/jta/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-jta</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/jta/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManager.java
----------------------------------------------------------------------
diff --git a/modules/jta/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManager.java b/modules/jta/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManager.java
index 56bd676..9af29d6 100644
--- a/modules/jta/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManager.java
+++ b/modules/jta/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManager.java
@@ -85,9 +85,7 @@ public class CacheJtaManager extends CacheJtaManagerAdapter {
                                 tCfg.getDefaultTxIsolation(),
                                 tCfg.getDefaultTxTimeout(),
                                 /*store enabled*/true,
-                                /*tx size*/0,
-                                /*group lock keys*/null,
-                                /*partition lock*/false
+                                /*tx size*/0
                             );
                         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/log4j/pom.xml
----------------------------------------------------------------------
diff --git a/modules/log4j/pom.xml b/modules/log4j/pom.xml
index dff0a7e..b0dd5f3 100644
--- a/modules/log4j/pom.xml
+++ b/modules/log4j/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>ignite-log4j</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
 
     <dependencies>
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/README.txt
----------------------------------------------------------------------
diff --git a/modules/mesos/README.txt b/modules/mesos/README.txt
new file mode 100644
index 0000000..75a62f8
--- /dev/null
+++ b/modules/mesos/README.txt
@@ -0,0 +1,28 @@
+Apache Ignite Mesos Module
+------------------------
+
+Apache Ignite Mesos module provides integration Apache Ignite with Apache Mesos.
+
+Importing Apache Ignite Mesos Module In Maven Project
+-------------------------------------
+
+If you are using Maven to manage dependencies of your project, you can add Cloud module
+dependency like this (replace '${ignite.version}' with actual Ignite version you are
+interested in):
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+                        http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    ...
+    <dependencies>
+        ...
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-mesos</artifactId>
+            <version>${ignite.version}</version>
+        </dependency>
+        ...
+    </dependencies>
+    ...
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/licenses/apache-2.0.txt
----------------------------------------------------------------------
diff --git a/modules/mesos/licenses/apache-2.0.txt b/modules/mesos/licenses/apache-2.0.txt
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/modules/mesos/licenses/apache-2.0.txt
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/licenses/jetty-epl-license.txt
----------------------------------------------------------------------
diff --git a/modules/mesos/licenses/jetty-epl-license.txt b/modules/mesos/licenses/jetty-epl-license.txt
new file mode 100644
index 0000000..f5f0c89
--- /dev/null
+++ b/modules/mesos/licenses/jetty-epl-license.txt
@@ -0,0 +1,69 @@
+Eclipse Public License, Version 1.0 (EPL-1.0)
+(plain text)
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+i) changes to the Program, and
+ii) additions to the Program;
+where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
+b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
+c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
+d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+b) its license agreement:
+i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
+iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+b) a copy of this Agreement must be included with each copy of the Program.
+Contributors may not remove or alter any copyright notices contained within the Program.
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Los
 ses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) 
 above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/pom.xml
----------------------------------------------------------------------
diff --git a/modules/mesos/pom.xml b/modules/mesos/pom.xml
new file mode 100644
index 0000000..eca4fa9
--- /dev/null
+++ b/modules/mesos/pom.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<!--
+    POM file.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.ignite</groupId>
+    <artifactId>ignite-mesos</artifactId>
+    <version>1.1.1-SNAPSHOT</version>
+
+    <properties>
+        <jetty.version>9.2.10.v20150310</jetty.version>
+        <mesos.version>0.22.0</mesos.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.mesos</groupId>
+            <artifactId>mesos</artifactId>
+            <version>${mesos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-server</artifactId>
+            <version>${jetty.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.11</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.1</version>
+                <configuration>
+                    <source>1.7</source>
+                    <target>1.7</target>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <version>2.4.1</version>
+                <configuration>
+                    <descriptorRefs>
+                        <descriptorRef>jar-with-dependencies</descriptorRef>
+                    </descriptorRefs>
+                    <archive>
+                        <manifest>
+                            <mainClass>org.apache.ignite.mesos.IgniteFramework</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>make-assembly</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
new file mode 100644
index 0000000..6663625
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
@@ -0,0 +1,519 @@
+/*
+ * 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.mesos;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.logging.*;
+import java.util.regex.*;
+
+/**
+ * Cluster settings.
+ */
+public class ClusterProperties {
+    /** */
+    private static final Logger log = Logger.getLogger(ClusterProperties.class.getSimpleName());
+
+    /** Unlimited. */
+    public static final double UNLIMITED = Double.MAX_VALUE;
+
+    /** */
+    public static final String MESOS_MASTER_URL = "MESOS_MASTER_URL";
+
+    /** */
+    public static final String DEFAULT_MESOS_MASTER_URL = "zk://localhost:2181/mesos";
+
+    /** Mesos master url. */
+    private String mesosUrl = DEFAULT_MESOS_MASTER_URL;
+
+    /** */
+    public static final String IGNITE_CLUSTER_NAME = "IGNITE_CLUSTER_NAME";
+
+    /** */
+    public static final String DEFAULT_CLUSTER_NAME = "ignite-cluster";
+
+    /** Mesos master url. */
+    private String clusterName = DEFAULT_CLUSTER_NAME;
+
+    /** */
+    public static final String IGNITE_HTTP_SERVER_HOST = "IGNITE_HTTP_SERVER_HOST";
+
+    /** Http server host. */
+    private String httpServerHost = null;
+
+    /** */
+    public static final String IGNITE_HTTP_SERVER_PORT = "IGNITE_HTTP_SERVER_PORT";
+
+    /** */
+    public static final String DEFAULT_HTTP_SERVER_PORT = "48610";
+
+    /** Http server host. */
+    private int httpServerPort = Integer.valueOf(DEFAULT_HTTP_SERVER_PORT);
+
+    /** */
+    public static final String IGNITE_TOTAL_CPU = "IGNITE_TOTAL_CPU";
+
+    /** CPU limit. */
+    private double cpu = UNLIMITED;
+
+    /** */
+    public static final String IGNITE_RUN_CPU_PER_NODE = "IGNITE_RUN_CPU_PER_NODE";
+
+    /** CPU limit. */
+    private double cpuPerNode = UNLIMITED;
+
+    /** */
+    public static final String IGNITE_TOTAL_MEMORY = "IGNITE_TOTAL_MEMORY";
+
+    /** Memory limit. */
+    private double mem = UNLIMITED;
+
+    /** */
+    public static final String IGNITE_MEMORY_PER_NODE = "IGNITE_MEMORY_PER_NODE";
+
+    /** Memory limit. */
+    private double memPerNode = UNLIMITED;
+
+    /** */
+    public static final String IGNITE_TOTAL_DISK_SPACE = "IGNITE_TOTAL_DISK_SPACE";
+
+    /** Disk space limit. */
+    private double disk = UNLIMITED;
+
+    /** */
+    public static final String IGNITE_DISK_SPACE_PER_NODE = "IGNITE_DISK_SPACE_PER_NODE";
+
+    /** Disk space limit. */
+    private double diskPerNode = UNLIMITED;
+
+    /** */
+    public static final String IGNITE_NODE_COUNT = "IGNITE_NODE_COUNT";
+
+    /** Node count limit. */
+    private double nodeCnt = UNLIMITED;
+
+    /** */
+    public static final String IGNITE_MIN_CPU_PER_NODE = "IGNITE_MIN_CPU_PER_NODE";
+
+    /** */
+    public static final double DEFAULT_RESOURCE_MIN_CPU = 1;
+
+    /** Min memory per node. */
+    private double minCpu = DEFAULT_RESOURCE_MIN_CPU;
+
+    /** */
+    public static final String IGNITE_MIN_MEMORY_PER_NODE = "IGNITE_MIN_MEMORY_PER_NODE";
+
+    /** */
+    public static final double DEFAULT_RESOURCE_MIN_MEM = 256;
+
+    /** Min memory per node. */
+    private double minMemory = DEFAULT_RESOURCE_MIN_MEM;
+
+    /** */
+    public static final String IGNITE_VERSION = "IGNITE_VERSION";
+
+    /** */
+    public static final String DEFAULT_IGNITE_VERSION = "latest";
+
+    /** Ignite version. */
+    private String igniteVer = DEFAULT_IGNITE_VERSION;
+
+    /** */
+    public static final String IGNITE_PACKAGE_URL = "IGNITE_PACKAGE_URL";
+
+    /** Ignite package url. */
+    private String ignitePackageUrl = null;
+
+    /** */
+    public static final String IGNITE_WORK_DIR = "IGNITE_WORK_DIR";
+
+    /** */
+    public static final String DEFAULT_IGNITE_WORK_DIR = "ignite-releases/";
+
+    /** Ignite version. */
+    private String igniteWorkDir = DEFAULT_IGNITE_WORK_DIR;
+
+    /** */
+    public static final String IGNITE_USERS_LIBS = "IGNITE_USERS_LIBS";
+
+    /** Path to users libs. */
+    private String userLibs = null;
+
+    /** */
+    public static final String IGNITE_USERS_LIBS_URL = "IGNITE_USERS_LIBS_URL";
+
+    /** URL to users libs. */
+    private String userLibsUrl = null;
+
+    /** */
+    public static final String IGNITE_CONFIG_XML = "IGNITE_XML_CONFIG";
+
+    /** Ignite config. */
+    private String igniteCfg = null;
+
+    /** */
+    public static final String IGNITE_CONFIG_XML_URL = "IGNITE_CONFIG_XML_URL";
+
+    /** Url to ignite config. */
+    private String igniteCfgUrl = null;
+
+    /** */
+    public static final String IGNITE_HOSTNAME_CONSTRAINT = "IGNITE_HOSTNAME_CONSTRAINT";
+
+    /** Url to ignite config. */
+    private Pattern hostnameConstraint = null;
+
+    /** */
+    public ClusterProperties() {
+        // No-op.
+    }
+
+    /**
+     * @return Cluster name.
+     */
+    public String clusterName() {
+        return clusterName;
+    }
+
+    /**
+     * @return CPU count limit.
+     */
+    public double cpus() {
+        return cpu;
+    }
+
+    /**
+     * Sets CPU count limit.
+     */
+    public void cpus(double cpu) {
+        this.cpu = cpu;
+    }
+
+    /**
+     * @return CPU count limit.
+     */
+    public double cpusPerNode() {
+        return cpuPerNode;
+    }
+
+    /**
+     * Sets CPU count limit.
+     */
+    public void cpusPerNode(double cpu) {
+        this.cpuPerNode = cpu;
+    }
+
+    /**
+     * @return mem limit.
+     */
+    public double memory() {
+        return mem;
+    }
+
+    /**
+     * Sets mem limit.
+     *
+     * @param mem Memory.
+     */
+    public void memory(double mem) {
+        this.mem = mem;
+    }
+
+    /**
+     * @return mem limit.
+     */
+    public double memoryPerNode() {
+        return memPerNode;
+    }
+
+    /**
+     * Sets mem limit.
+     *
+     * @param mem Memory.
+     */
+    public void memoryPerNode(double mem) {
+         this.memPerNode = mem;
+    }
+
+    /**
+     * @return disk limit.
+     */
+    public double disk() {
+        return disk;
+    }
+
+    /**
+     * @return disk limit per node.
+     */
+    public double diskPerNode() {
+        return diskPerNode;
+    }
+
+    /**
+     * @return instance count limit.
+     */
+    public double instances() {
+        return nodeCnt;
+    }
+
+    /**
+     * @return min memory per node.
+     */
+    public double minMemoryPerNode() {
+        return minMemory;
+    }
+
+    /**
+     * Sets min memory.
+     *
+     * @param minMemory Min memory.
+     */
+    public void minMemoryPerNode(double minMemory) {
+        this.minMemory = minMemory;
+    }
+
+    /**
+     * Sets hostname constraint.
+     *
+     * @param pattern Hostname pattern.
+     */
+    public void hostnameConstraint(Pattern pattern) {
+        this.hostnameConstraint = pattern;
+    }
+
+    /**
+     * @return min cpu count per node.
+     */
+    public double minCpuPerNode() {
+        return minCpu;
+    }
+
+    /**
+     * Sets min cpu count per node.
+     *
+     * @param minCpu min cpu count per node.
+     */
+    public void minCpuPerNode(double minCpu) {
+        this.minCpu = minCpu;
+    }
+
+    /**
+     * @return Ignite version.
+     */
+    public String igniteVer() {
+        return igniteVer;
+    }
+
+    /**
+     * @return Working directory.
+     */
+    public String igniteWorkDir() {
+        return igniteWorkDir;
+    }
+
+    /**
+     * @return User's libs.
+     */
+    public String userLibs() {
+        return userLibs;
+    }
+
+    /**
+     * @return Ignite configuration.
+     */
+    public String igniteCfg() {
+        return igniteCfg;
+    }
+
+    /**
+     * @return Master url.
+     */
+    public String masterUrl() {
+        return mesosUrl;
+    }
+
+    /**
+     * @return Http server host.
+     */
+    public String httpServerHost() {
+        return httpServerHost;
+    }
+
+    /**
+     * @return Http server port.
+     */
+    public int httpServerPort() {
+        return httpServerPort;
+    }
+
+    /**
+     * @return Url to ignite package.
+     */
+    public String ignitePackageUrl() {
+        return ignitePackageUrl;
+    }
+
+    /**
+     * @return Url to ignite configuration.
+     */
+    public String igniteConfigUrl() {
+        return igniteCfgUrl;
+    }
+
+    /**
+     * @return Url to users libs configuration.
+     */
+    public String usersLibsUrl() {
+        return userLibsUrl;
+    }
+
+    /**
+     * @return Host name constraint.
+     */
+    public Pattern hostnameConstraint() {
+        return hostnameConstraint;
+    }
+
+    /**
+     * @param config path to config file.
+     * @return Cluster configuration.
+     */
+    public static ClusterProperties from(String config) {
+        try {
+            Properties props = null;
+
+            if (config != null) {
+                props = new Properties();
+
+                props.load(new FileInputStream(config));
+            }
+
+            ClusterProperties prop = new ClusterProperties();
+
+            prop.mesosUrl = getStringProperty(MESOS_MASTER_URL, props, DEFAULT_MESOS_MASTER_URL);
+
+            prop.httpServerHost = getStringProperty(IGNITE_HTTP_SERVER_HOST, props, getNonLoopbackAddress());
+
+            String port = System.getProperty("PORT0");
+
+            if (port != null && !port.isEmpty())
+                prop.httpServerPort = Integer.valueOf(port);
+            else
+                prop.httpServerPort = Integer.valueOf(getStringProperty(IGNITE_HTTP_SERVER_PORT, props,
+                    DEFAULT_HTTP_SERVER_PORT));
+
+            prop.clusterName = getStringProperty(IGNITE_CLUSTER_NAME, props, DEFAULT_CLUSTER_NAME);
+
+            prop.userLibsUrl = getStringProperty(IGNITE_USERS_LIBS_URL, props, null);
+            prop.ignitePackageUrl = getStringProperty(IGNITE_PACKAGE_URL, props, null);
+            prop.igniteCfgUrl = getStringProperty(IGNITE_CONFIG_XML_URL, props, null);
+
+            prop.cpu = getDoubleProperty(IGNITE_TOTAL_CPU, props, UNLIMITED);
+            prop.cpuPerNode = getDoubleProperty(IGNITE_RUN_CPU_PER_NODE, props, UNLIMITED);
+            prop.mem = getDoubleProperty(IGNITE_TOTAL_MEMORY, props, UNLIMITED);
+            prop.memPerNode = getDoubleProperty(IGNITE_MEMORY_PER_NODE, props, UNLIMITED);
+            prop.disk = getDoubleProperty(IGNITE_TOTAL_DISK_SPACE, props, UNLIMITED);
+            prop.diskPerNode = getDoubleProperty(IGNITE_DISK_SPACE_PER_NODE, props, 1024.0);
+            prop.nodeCnt = getDoubleProperty(IGNITE_NODE_COUNT, props, UNLIMITED);
+            prop.minCpu = getDoubleProperty(IGNITE_MIN_CPU_PER_NODE, props, DEFAULT_RESOURCE_MIN_CPU);
+            prop.minMemory = getDoubleProperty(IGNITE_MIN_MEMORY_PER_NODE, props, DEFAULT_RESOURCE_MIN_MEM);
+
+            prop.igniteVer = getStringProperty(IGNITE_VERSION, props, DEFAULT_IGNITE_VERSION);
+            prop.igniteWorkDir = getStringProperty(IGNITE_WORK_DIR, props, DEFAULT_IGNITE_WORK_DIR);
+            prop.igniteCfg = getStringProperty(IGNITE_CONFIG_XML, props, null);
+            prop.userLibs = getStringProperty(IGNITE_USERS_LIBS, props, null);
+
+            String pattern = getStringProperty(IGNITE_HOSTNAME_CONSTRAINT, props, null);
+
+            if (pattern != null) {
+                try {
+                    prop.hostnameConstraint = Pattern.compile(pattern);
+                }
+                catch (PatternSyntaxException e) {
+                    log.log(Level.WARNING, "IGNITE_HOSTNAME_CONSTRAINT has invalid pattern. It will be ignore.", e);
+                }
+            }
+
+            return prop;
+        }
+        catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * @param name Property name.
+     * @param fileProps Property file.
+     * @return Property value.
+     */
+    private static double getDoubleProperty(String name, Properties fileProps, Double defaultVal) {
+        if (fileProps != null && fileProps.containsKey(name))
+            return Double.valueOf(fileProps.getProperty(name));
+
+        String property = System.getProperty(name);
+
+        if (property == null)
+            property = System.getenv(name);
+
+        return property == null ? defaultVal : Double.valueOf(property);
+    }
+
+    /**
+     * @param name Property name.
+     * @param fileProps Property file.
+     * @return Property value.
+     */
+    private static String getStringProperty(String name, Properties fileProps, String defaultVal) {
+        if (fileProps != null && fileProps.containsKey(name))
+            return fileProps.getProperty(name);
+
+        String property = System.getProperty(name);
+
+        if (property == null)
+            property = System.getenv(name);
+
+        return property == null ? defaultVal : property;
+    }
+
+    /**
+     * Finds a local, non-loopback, IPv4 address
+     *
+     * @return The first non-loopback IPv4 address found, or <code>null</code> if no such addresses found
+     * @throws java.net.SocketException If there was a problem querying the network interfaces
+     */
+    public static String getNonLoopbackAddress() throws SocketException {
+        Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
+
+        while (ifaces.hasMoreElements()) {
+            NetworkInterface iface = ifaces.nextElement();
+
+            Enumeration<InetAddress> addresses = iface.getInetAddresses();
+
+            while (addresses.hasMoreElements()) {
+                InetAddress addr = addresses.nextElement();
+
+                if (addr instanceof Inet4Address && !addr.isLoopbackAddress())
+                    return addr.getHostAddress();
+            }
+        }
+
+        throw new RuntimeException("Failed. Couldn't find non-loopback address");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteFramework.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteFramework.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteFramework.java
new file mode 100644
index 0000000..3d582d9
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteFramework.java
@@ -0,0 +1,119 @@
+/*
+ * 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.mesos;
+
+import com.google.protobuf.*;
+import org.apache.ignite.mesos.resource.*;
+import org.apache.mesos.*;
+
+import java.net.*;
+import java.util.logging.*;
+
+/**
+ * Ignite mesos framework.
+ */
+public class IgniteFramework {
+    /** */
+    public static final Logger log = Logger.getLogger(IgniteFramework.class.getSimpleName());
+
+    /** Framework name. */
+    public static final String IGNITE_FRAMEWORK_NAME = "Ignite";
+
+    /**
+     * Main methods has only one optional parameter - path to properties files.
+     *
+     * @param args Args.
+     */
+    public static void main(String[] args) throws Exception {
+        final int frameworkFailoverTimeout = 0;
+
+        // Have Mesos fill in the current user.
+        Protos.FrameworkInfo.Builder frameworkBuilder = Protos.FrameworkInfo.newBuilder()
+            .setName(IGNITE_FRAMEWORK_NAME)
+            .setUser("")
+            .setFailoverTimeout(frameworkFailoverTimeout);
+
+        if (System.getenv("MESOS_CHECKPOINT") != null) {
+            log.info("Enabling checkpoint for the framework");
+
+            frameworkBuilder.setCheckpoint(true);
+        }
+
+        ClusterProperties clusterProps = ClusterProperties.from(args.length >= 1 ? args[0] : null);
+
+        String baseUrl = String.format("http://%s:%d", clusterProps.httpServerHost(), clusterProps.httpServerPort());
+
+        JettyServer httpServer = new JettyServer();
+
+        httpServer.start(
+            new InetSocketAddress(clusterProps.httpServerHost(), clusterProps.httpServerPort()),
+            new ResourceHandler(clusterProps.userLibs(), clusterProps.igniteCfg(), clusterProps.igniteWorkDir())
+        );
+
+        ResourceProvider provider = new ResourceProvider();
+
+        IgniteProvider igniteProvider = new IgniteProvider(clusterProps.igniteWorkDir());
+
+        provider.init(clusterProps, igniteProvider, baseUrl);
+
+        // Create the scheduler.
+        Scheduler scheduler = new IgniteScheduler(clusterProps, provider);
+
+        // create the driver
+        MesosSchedulerDriver driver;
+        if (System.getenv("MESOS_AUTHENTICATE") != null) {
+            log.info("Enabling authentication for the framework");
+
+            if (System.getenv("DEFAULT_PRINCIPAL") == null) {
+                log.log(Level.SEVERE, "Expecting authentication principal in the environment");
+
+                System.exit(1);
+            }
+
+            if (System.getenv("DEFAULT_SECRET") == null) {
+                log.log(Level.SEVERE, "Expecting authentication secret in the environment");
+
+                System.exit(1);
+            }
+
+            Protos.Credential credential = Protos.Credential.newBuilder()
+                .setPrincipal(System.getenv("DEFAULT_PRINCIPAL"))
+                .setSecret(ByteString.copyFrom(System.getenv("DEFAULT_SECRET").getBytes()))
+                .build();
+
+            frameworkBuilder.setPrincipal(System.getenv("DEFAULT_PRINCIPAL"));
+
+            driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), clusterProps.masterUrl(),
+                credential);
+        }
+        else {
+            frameworkBuilder.setPrincipal("ignite-framework-java");
+
+            driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), clusterProps.masterUrl());
+        }
+
+        int status = driver.run() == Protos.Status.DRIVER_STOPPED ? 0 : 1;
+
+        httpServer.stop();
+
+        // Ensure that the driver process terminates.
+        driver.stop();
+
+        System.exit(status);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteScheduler.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteScheduler.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteScheduler.java
new file mode 100644
index 0000000..fbb9994
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteScheduler.java
@@ -0,0 +1,361 @@
+/*
+ * 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.mesos;
+
+import org.apache.ignite.mesos.resource.*;
+import org.apache.mesos.*;
+
+import java.util.*;
+import java.util.concurrent.atomic.*;
+import java.util.logging.*;
+
+/**
+ * Ignite scheduler receives offers from Mesos and decides how many resources will be occupied.
+ */
+public class IgniteScheduler implements Scheduler {
+    /** Cpus. */
+    public static final String CPU = "cpus";
+
+    /** Mem. */
+    public static final String MEM = "mem";
+
+    /** Disk. */
+    public static final String DISK = "disk";
+
+    /** Default port range. */
+    public static final String DEFAULT_PORT = ":47500..47510";
+
+    /** Delimiter char. */
+    public static final String DELIM = ",";
+
+    /** Logger. */
+    private static final Logger log = Logger.getLogger(IgniteScheduler.class.getSimpleName());
+
+    /** ID generator. */
+    private AtomicInteger taskIdGenerator = new AtomicInteger();
+
+    /** Task on host. */
+    private Map<String, IgniteTask> tasks = new HashMap<>();
+
+    /** Cluster resources. */
+    private ClusterProperties clusterProps;
+
+    /** Resource provider. */
+    private ResourceProvider resourceProvider;
+
+    /**
+     * @param clusterProps Cluster limit.
+     * @param resourceProvider Resource provider.
+     */
+    public IgniteScheduler(ClusterProperties clusterProps, ResourceProvider resourceProvider) {
+        this.clusterProps = clusterProps;
+        this.resourceProvider = resourceProvider;
+    }
+
+    /** {@inheritDoc} */
+    @Override public synchronized void resourceOffers(SchedulerDriver schedulerDriver, List<Protos.Offer> offers) {
+        log.log(Level.FINE, "Offers resources: {0}", offers.size());
+
+        for (Protos.Offer offer : offers) {
+            IgniteTask igniteTask = checkOffer(offer);
+
+            // Decline offer which doesn't match by mem or cpu.
+            if (igniteTask == null) {
+                schedulerDriver.declineOffer(offer.getId());
+
+                continue;
+            }
+
+            // Generate a unique task ID.
+            Protos.TaskID taskId = Protos.TaskID.newBuilder()
+                .setValue(Integer.toString(taskIdGenerator.incrementAndGet())).build();
+
+            log.log(Level.INFO, "Launching task: {0}", igniteTask);
+
+            // Create task to run.
+            Protos.TaskInfo task = createTask(offer, igniteTask, taskId);
+
+            try {
+                schedulerDriver.launchTasks(Collections.singletonList(offer.getId()),
+                    Collections.singletonList(task),
+                    Protos.Filters.newBuilder().setRefuseSeconds(1).build());
+            }
+            catch (RuntimeException e) {
+                log.log(Level.SEVERE, "Failed launch task. Task id: {0}. Task info: {1}",
+                    new Object[]{taskId, task, e});
+
+                throw e;
+            }
+
+            tasks.put(taskId.getValue(), igniteTask);
+        }
+    }
+
+    /**
+     * Create Task.
+     *
+     * @param offer Offer.
+     * @param igniteTask Task description.
+     * @param taskId Task id.
+     * @return Task.
+     */
+    private Protos.TaskInfo createTask(Protos.Offer offer, IgniteTask igniteTask, Protos.TaskID taskId) {
+        String cfgUrl = clusterProps.igniteConfigUrl() != null ?
+            clusterProps.igniteConfigUrl() : resourceProvider.igniteConfigUrl();
+
+        Protos.CommandInfo.Builder builder = Protos.CommandInfo.newBuilder()
+            .setEnvironment(Protos.Environment.newBuilder().addVariables(Protos.Environment.Variable.newBuilder()
+                .setName("IGNITE_TCP_DISCOVERY_ADDRESSES")
+                .setValue(getAddress(offer.getHostname()))))
+            .addUris(Protos.CommandInfo.URI.newBuilder()
+                .setValue(clusterProps.ignitePackageUrl() != null ?
+                    clusterProps.ignitePackageUrl() : resourceProvider.igniteUrl())
+                .setExtract(true))
+            .addUris(Protos.CommandInfo.URI.newBuilder()
+                .setValue(cfgUrl));
+
+        // Collection user's libs.
+        Collection<String> usersLibs = new ArrayList<>();
+
+        if (clusterProps.usersLibsUrl() != null && !clusterProps.usersLibsUrl().isEmpty())
+            Collections.addAll(usersLibs, clusterProps.usersLibsUrl().split(DELIM));
+
+        if (resourceProvider.resourceUrl() != null && !resourceProvider.resourceUrl().isEmpty())
+            usersLibs.addAll(resourceProvider.resourceUrl());
+
+        for (String url : usersLibs)
+            builder.addUris(Protos.CommandInfo.URI.newBuilder().setValue(url));
+
+        String cfgName = resourceProvider.configName();
+
+        if (clusterProps.igniteConfigUrl() != null) {
+            String[] split = clusterProps.igniteConfigUrl().split("/");
+
+            cfgName = split[split.length - 1];
+        }
+
+        builder.setValue("find . -maxdepth 1 -name \"*.jar\" -exec cp {} ./gridgain-community-*/libs/ \\; && "
+            + "./gridgain-community-*/bin/ignite.sh "
+            + cfgName
+            + " -J-Xmx" + String.valueOf((int)igniteTask.mem() + "m")
+            + " -J-Xms" + String.valueOf((int)igniteTask.mem()) + "m");
+
+        return Protos.TaskInfo.newBuilder()
+            .setName("Ignite node " + taskId.getValue())
+            .setTaskId(taskId)
+            .setSlaveId(offer.getSlaveId())
+            .setCommand(builder)
+            .addResources(Protos.Resource.newBuilder()
+                .setName(CPU)
+                .setType(Protos.Value.Type.SCALAR)
+                .setScalar(Protos.Value.Scalar.newBuilder().setValue(igniteTask.cpuCores())))
+            .addResources(Protos.Resource.newBuilder()
+                .setName(MEM)
+                .setType(Protos.Value.Type.SCALAR)
+                .setScalar(Protos.Value.Scalar.newBuilder().setValue(igniteTask.mem())))
+            .addResources(Protos.Resource.newBuilder()
+                .setName(DISK)
+                .setType(Protos.Value.Type.SCALAR)
+                .setScalar(Protos.Value.Scalar.newBuilder().setValue(igniteTask.disk())))
+            .build();
+    }
+
+    /**
+     * @return Address running nodes.
+     */
+    private String getAddress(String address) {
+        if (tasks.isEmpty()) {
+            if (address != null && !address.isEmpty())
+                return address + DEFAULT_PORT;
+
+            return "";
+        }
+
+        StringBuilder sb = new StringBuilder();
+
+        for (IgniteTask task : tasks.values())
+            sb.append(task.host()).append(DEFAULT_PORT).append(DELIM);
+
+        return sb.substring(0, sb.length() - 1);
+    }
+
+    /**
+     * Check slave resources and return resources infos.
+     *
+     * @param offer Offer request.
+     * @return Ignite task description.
+     */
+    private IgniteTask checkOffer(Protos.Offer offer) {
+        // Check limit on running nodes.
+        if (clusterProps.instances() <= tasks.size())
+            return null;
+
+        double cpus = -1;
+        double mem = -1;
+        double disk = -1;
+
+        // Check host name
+        if (clusterProps.hostnameConstraint() != null
+            && clusterProps.hostnameConstraint().matcher(offer.getHostname()).matches())
+            return null;
+
+        // Collect resource on slave.
+        for (Protos.Resource resource : offer.getResourcesList()) {
+            if (resource.getName().equals(CPU)) {
+                if (resource.getType().equals(Protos.Value.Type.SCALAR))
+                    cpus = resource.getScalar().getValue();
+                else
+                    log.log(Level.FINE, "Cpus resource was not a scalar: {0}" + resource.getType());
+            }
+            else if (resource.getName().equals(MEM)) {
+                if (resource.getType().equals(Protos.Value.Type.SCALAR))
+                    mem = resource.getScalar().getValue();
+                else
+                    log.log(Level.FINE, "Mem resource was not a scalar: {0}", resource.getType());
+            }
+            else if (resource.getName().equals(DISK))
+                if (resource.getType().equals(Protos.Value.Type.SCALAR))
+                    disk = resource.getScalar().getValue();
+                else
+                    log.log(Level.FINE, "Disk resource was not a scalar: {0}", resource.getType());
+        }
+
+        // Check that slave satisfies min requirements.
+        if (cpus < clusterProps.minCpuPerNode() || mem < clusterProps.minMemoryPerNode()) {
+            log.log(Level.FINE, "Offer not sufficient for slave request: {0}", offer.getResourcesList());
+
+            return null;
+        }
+
+        double totalCpus = 0;
+        double totalMem = 0;
+        double totalDisk = 0;
+
+        // Collect occupied resources.
+        for (IgniteTask task : tasks.values()) {
+            totalCpus += task.cpuCores();
+            totalMem += task.mem();
+            totalDisk += task.disk();
+        }
+
+        cpus = Math.min(clusterProps.cpus() - totalCpus, Math.min(cpus, clusterProps.cpusPerNode()));
+        mem = Math.min(clusterProps.memory() - totalMem, Math.min(mem, clusterProps.memoryPerNode()));
+        disk = Math.min(clusterProps.disk() - totalDisk, Math.min(disk, clusterProps.diskPerNode()));
+
+        if ((clusterProps.cpusPerNode() != ClusterProperties.UNLIMITED && clusterProps.cpusPerNode() != cpus)
+            || (clusterProps.memoryPerNode() != ClusterProperties.UNLIMITED && clusterProps.memoryPerNode() != mem)) {
+            log.log(Level.FINE, "Offer not sufficient for slave request: {0}", offer.getResourcesList());
+
+            return null;
+        }
+
+        if (cpus > 0 && mem > 0)
+            return new IgniteTask(offer.getHostname(), cpus, mem, disk);
+        else {
+            log.log(Level.FINE, "Offer not sufficient for slave request: {0}", offer.getResourcesList());
+
+            return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public synchronized void statusUpdate(SchedulerDriver schedulerDriver, Protos.TaskStatus taskStatus) {
+        final String taskId = taskStatus.getTaskId().getValue();
+
+        log.log(Level.INFO, "Received update event task: {0} is in state: {1}",
+            new Object[]{taskId, taskStatus.getState()});
+
+        if (taskStatus.getState().equals(Protos.TaskState.TASK_FAILED)
+            || taskStatus.getState().equals(Protos.TaskState.TASK_ERROR)
+            || taskStatus.getState().equals(Protos.TaskState.TASK_FINISHED)
+            || taskStatus.getState().equals(Protos.TaskState.TASK_KILLED)
+            || taskStatus.getState().equals(Protos.TaskState.TASK_LOST)) {
+            IgniteTask failedTask = tasks.remove(taskId);
+
+            if (failedTask != null) {
+                List<Protos.Request> requests = new ArrayList<>();
+
+                Protos.Request request = Protos.Request.newBuilder()
+                    .addResources(Protos.Resource.newBuilder()
+                        .setType(Protos.Value.Type.SCALAR)
+                        .setName(MEM)
+                        .setScalar(Protos.Value.Scalar.newBuilder().setValue(failedTask.mem())))
+                    .addResources(Protos.Resource.newBuilder()
+                        .setType(Protos.Value.Type.SCALAR)
+                        .setName(CPU)
+                        .setScalar(Protos.Value.Scalar.newBuilder().setValue(failedTask.cpuCores())))
+                    .build();
+
+                requests.add(request);
+
+                schedulerDriver.requestResources(requests);
+            }
+        }
+    }
+
+    /**
+     * @param clusterProps Cluster properties.
+     */
+    public void setClusterProps(ClusterProperties clusterProps) {
+        this.clusterProps = clusterProps;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void registered(SchedulerDriver schedulerDriver, Protos.FrameworkID frameworkID,
+        Protos.MasterInfo masterInfo) {
+        log.log(Level.INFO, "Scheduler registered. Master: {0}:{1}, framework={2}", new Object[]{masterInfo.getIp(),
+            masterInfo.getPort(), frameworkID});
+    }
+
+    /** {@inheritDoc} */
+    @Override public void disconnected(SchedulerDriver schedulerDriver) {
+        log.info("Scheduler disconnected.");
+    }
+
+    /** {@inheritDoc} */
+    @Override public void error(SchedulerDriver schedulerDriver, String s) {
+        log.log(Level.SEVERE, "Failed. Error message: {0}", s);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void frameworkMessage(SchedulerDriver schedulerDriver, Protos.ExecutorID executorID,
+        Protos.SlaveID slaveID, byte[] bytes) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void slaveLost(SchedulerDriver schedulerDriver, Protos.SlaveID slaveID) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void executorLost(SchedulerDriver schedulerDriver, Protos.ExecutorID executorID,
+        Protos.SlaveID slaveID, int i) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void offerRescinded(SchedulerDriver schedulerDriver, Protos.OfferID offerID) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void reregistered(SchedulerDriver schedulerDriver, Protos.MasterInfo masterInfo) {
+        // No-op.
+    }
+}



[18/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishRequest.java
index 9672a75..c524575 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxFinishRequest.java
@@ -18,10 +18,8 @@
 package org.apache.ignite.internal.processors.cache.distributed;
 
 import org.apache.ignite.*;
-import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.managers.communication.*;
 import org.apache.ignite.internal.processors.cache.*;
-import org.apache.ignite.internal.processors.cache.transactions.*;
 import org.apache.ignite.internal.processors.cache.version.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.lang.*;
@@ -66,9 +64,6 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
     /** Expected txSize. */
     private int txSize;
 
-    /** Group lock key. */
-    private IgniteTxKey grpLockKey;
-
     /** System transaction flag. */
     private boolean sys;
 
@@ -95,7 +90,6 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
      * @param committedVers Committed versions.
      * @param rolledbackVers Rolled back versions.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key if this is a group-lock transaction.
      */
     public GridDistributedTxFinishRequest(
         GridCacheVersion xidVer,
@@ -111,8 +105,7 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
         GridCacheVersion baseVer,
         Collection<GridCacheVersion> committedVers,
         Collection<GridCacheVersion> rolledbackVers,
-        int txSize,
-        @Nullable IgniteTxKey grpLockKey
+        int txSize
     ) {
         super(xidVer, 0);
         assert xidVer != null;
@@ -128,7 +121,6 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
         this.syncRollback = syncRollback;
         this.baseVer = baseVer;
         this.txSize = txSize;
-        this.grpLockKey = grpLockKey;
 
         completedVersions(committedVers, rolledbackVers);
     }
@@ -219,35 +211,15 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
         return commit ? syncCommit : syncRollback;
     }
 
-    /**
-     * @return {@code True} if group lock transaction.
-     */
-    public boolean groupLock() {
-        return grpLockKey != null;
-    }
-
-    /**
-     * @return Group lock key.
-     */
-    @Nullable public IgniteTxKey groupLockKey() {
-        return grpLockKey;
-    }
-
     /** {@inheritDoc}
      * @param ctx*/
     @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
         super.prepareMarshal(ctx);
-
-        if (grpLockKey != null)
-            grpLockKey.prepareMarshal(ctx.cacheContext(cacheId));
     }
 
     /** {@inheritDoc} */
     @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
         super.finishUnmarshal(ctx, ldr);
-
-        if (grpLockKey != null)
-            grpLockKey.finishUnmarshal(ctx.cacheContext(cacheId), ldr);
     }
 
     /** {@inheritDoc} */
@@ -290,48 +262,42 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
                 writer.incrementState();
 
             case 12:
-                if (!writer.writeMessage("grpLockKey", grpLockKey))
-                    return false;
-
-                writer.incrementState();
-
-            case 13:
                 if (!writer.writeBoolean("invalidate", invalidate))
                     return false;
 
                 writer.incrementState();
 
-            case 14:
+            case 13:
                 if (!writer.writeByte("plc", plc != null ? (byte)plc.ordinal() : -1))
                     return false;
 
                 writer.incrementState();
 
-            case 15:
+            case 14:
                 if (!writer.writeBoolean("syncCommit", syncCommit))
                     return false;
 
                 writer.incrementState();
 
-            case 16:
+            case 15:
                 if (!writer.writeBoolean("syncRollback", syncRollback))
                     return false;
 
                 writer.incrementState();
 
-            case 17:
+            case 16:
                 if (!writer.writeBoolean("sys", sys))
                     return false;
 
                 writer.incrementState();
 
-            case 18:
+            case 17:
                 if (!writer.writeLong("threadId", threadId))
                     return false;
 
                 writer.incrementState();
 
-            case 19:
+            case 18:
                 if (!writer.writeInt("txSize", txSize))
                     return false;
 
@@ -386,14 +352,6 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
                 reader.incrementState();
 
             case 12:
-                grpLockKey = reader.readMessage("grpLockKey");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 13:
                 invalidate = reader.readBoolean("invalidate");
 
                 if (!reader.isLastRead())
@@ -401,7 +359,7 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 14:
+            case 13:
                 byte plcOrd;
 
                 plcOrd = reader.readByte("plc");
@@ -413,7 +371,7 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 15:
+            case 14:
                 syncCommit = reader.readBoolean("syncCommit");
 
                 if (!reader.isLastRead())
@@ -421,7 +379,7 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 16:
+            case 15:
                 syncRollback = reader.readBoolean("syncRollback");
 
                 if (!reader.isLastRead())
@@ -429,7 +387,7 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 17:
+            case 16:
                 sys = reader.readBoolean("sys");
 
                 if (!reader.isLastRead())
@@ -437,7 +395,7 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 18:
+            case 17:
                 threadId = reader.readLong("threadId");
 
                 if (!reader.isLastRead())
@@ -445,7 +403,7 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
 
                 reader.incrementState();
 
-            case 19:
+            case 18:
                 txSize = reader.readInt("txSize");
 
                 if (!reader.isLastRead())
@@ -465,7 +423,7 @@ public class GridDistributedTxFinishRequest extends GridDistributedBaseMessage {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 20;
+        return 19;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxMapping.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxMapping.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxMapping.java
index 58c7725..fded3c9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxMapping.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxMapping.java
@@ -169,12 +169,13 @@ public class GridDistributedTxMapping implements Externalizable {
 
     /**
      * @param dhtVer DHT version.
+     * @param writeVer DHT writeVersion.
      */
-    public void dhtVersion(GridCacheVersion dhtVer) {
+    public void dhtVersion(GridCacheVersion dhtVer, GridCacheVersion writeVer) {
         this.dhtVer = dhtVer;
 
         for (IgniteTxEntry e : entries)
-            e.dhtVersion(dhtVer);
+            e.dhtVersion(writeVer);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java
index ec02e6e..cc2783a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java
@@ -88,18 +88,6 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
     @GridDirectCollection(GridCacheVersion.class)
     private Collection<GridCacheVersion> dhtVerVals;
 
-    /** Group lock key, if any. */
-    @GridToStringInclude
-    @GridDirectTransient
-    private IgniteTxKey grpLockKey;
-
-    /** Group lock key bytes. */
-    @GridToStringExclude
-    private byte[] grpLockKeyBytes;
-
-    /** Partition lock flag. */
-    private boolean partLock;
-
     /** Expected transaction size. */
     private int txSize;
 
@@ -130,8 +118,6 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
      * @param tx Cache transaction.
      * @param reads Read entries.
      * @param writes Write entries.
-     * @param grpLockKey Group lock key.
-     * @param partLock {@code True} if preparing group-lock transaction with partition lock.
      * @param txNodes Transaction nodes mapping.
      * @param onePhaseCommit One phase commit flag.
      */
@@ -139,8 +125,6 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
         IgniteInternalTx tx,
         @Nullable Collection<IgniteTxEntry> reads,
         Collection<IgniteTxEntry> writes,
-        IgniteTxKey grpLockKey,
-        boolean partLock,
         Map<UUID, Collection<UUID>> txNodes,
         boolean onePhaseCommit
     ) {
@@ -158,8 +142,6 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
         this.reads = reads;
         this.writes = writes;
-        this.grpLockKey = grpLockKey;
-        this.partLock = partLock;
         this.txNodes = txNodes;
         this.onePhaseCommit = onePhaseCommit;
     }
@@ -272,20 +254,6 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
     }
 
     /**
-     * @return Group lock key if preparing group-lock transaction.
-     */
-    @Nullable public IgniteTxKey groupLockKey() {
-        return grpLockKey;
-    }
-
-    /**
-     * @return {@code True} if preparing group-lock transaction with partition lock.
-     */
-    public boolean partitionLock() {
-        return partLock;
-    }
-
-    /**
      * @return Expected transaction size.
      */
     public int txSize() {
@@ -310,9 +278,6 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
         if (reads != null)
             marshalTx(reads, ctx);
 
-        if (grpLockKey != null && grpLockKeyBytes == null)
-            grpLockKeyBytes = ctx.marshaller().marshal(grpLockKey);
-
         if (dhtVers != null) {
             for (IgniteTxKey key : dhtVers.keySet()) {
                 GridCacheContext cctx = ctx.cacheContext(key.cacheId());
@@ -338,9 +303,6 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
         if (reads != null)
             unmarshalTx(reads, false, ctx, ldr);
 
-        if (grpLockKeyBytes != null && grpLockKey == null)
-            grpLockKey = ctx.marshaller().unmarshal(grpLockKeyBytes, ldr);
-
         if (dhtVerKeys != null && dhtVers == null) {
             assert dhtVerVals != null;
             assert dhtVerKeys.size() == dhtVerVals.size();
@@ -397,84 +359,72 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
                 writer.incrementState();
 
             case 11:
-                if (!writer.writeByteArray("grpLockKeyBytes", grpLockKeyBytes))
-                    return false;
-
-                writer.incrementState();
-
-            case 12:
                 if (!writer.writeBoolean("invalidate", invalidate))
                     return false;
 
                 writer.incrementState();
 
-            case 13:
+            case 12:
                 if (!writer.writeByte("isolation", isolation != null ? (byte)isolation.ordinal() : -1))
                     return false;
 
                 writer.incrementState();
 
-            case 14:
+            case 13:
                 if (!writer.writeBoolean("onePhaseCommit", onePhaseCommit))
                     return false;
 
                 writer.incrementState();
 
-            case 15:
-                if (!writer.writeBoolean("partLock", partLock))
-                    return false;
-
-                writer.incrementState();
-
-            case 16:
+            case 14:
                 if (!writer.writeByte("plc", plc != null ? (byte)plc.ordinal() : -1))
                     return false;
 
                 writer.incrementState();
 
-            case 17:
+            case 15:
                 if (!writer.writeCollection("reads", reads, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
 
-            case 18:
+            case 16:
                 if (!writer.writeBoolean("sys", sys))
                     return false;
 
                 writer.incrementState();
 
-            case 19:
+            case 17:
                 if (!writer.writeLong("threadId", threadId))
                     return false;
 
                 writer.incrementState();
 
-            case 20:
+            case 18:
                 if (!writer.writeLong("timeout", timeout))
                     return false;
 
                 writer.incrementState();
 
-            case 21:
+            case 19:
                 if (!writer.writeByteArray("txNodesBytes", txNodesBytes))
                     return false;
 
                 writer.incrementState();
 
-            case 22:
+            case 20:
                 if (!writer.writeInt("txSize", txSize))
                     return false;
 
                 writer.incrementState();
 
-            case 23:
+            case 21:
                 if (!writer.writeMessage("writeVer", writeVer))
                     return false;
 
                 writer.incrementState();
 
-            case 24:
+            case 22:
                 if (!writer.writeCollection("writes", writes, MessageCollectionItemType.MSG))
                     return false;
 
@@ -525,14 +475,6 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
                 reader.incrementState();
 
             case 11:
-                grpLockKeyBytes = reader.readByteArray("grpLockKeyBytes");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 12:
                 invalidate = reader.readBoolean("invalidate");
 
                 if (!reader.isLastRead())
@@ -540,7 +482,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 13:
+            case 12:
                 byte isolationOrd;
 
                 isolationOrd = reader.readByte("isolation");
@@ -552,7 +494,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 14:
+            case 13:
                 onePhaseCommit = reader.readBoolean("onePhaseCommit");
 
                 if (!reader.isLastRead())
@@ -560,15 +502,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 15:
-                partLock = reader.readBoolean("partLock");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 16:
+            case 14:
                 byte plcOrd;
 
                 plcOrd = reader.readByte("plc");
@@ -580,7 +514,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 17:
+            case 15:
                 reads = reader.readCollection("reads", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
@@ -588,7 +522,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 18:
+            case 16:
                 sys = reader.readBoolean("sys");
 
                 if (!reader.isLastRead())
@@ -596,7 +530,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 19:
+            case 17:
                 threadId = reader.readLong("threadId");
 
                 if (!reader.isLastRead())
@@ -604,7 +538,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 20:
+            case 18:
                 timeout = reader.readLong("timeout");
 
                 if (!reader.isLastRead())
@@ -612,7 +546,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 21:
+            case 19:
                 txNodesBytes = reader.readByteArray("txNodesBytes");
 
                 if (!reader.isLastRead())
@@ -620,7 +554,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 22:
+            case 20:
                 txSize = reader.readInt("txSize");
 
                 if (!reader.isLastRead())
@@ -628,7 +562,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 23:
+            case 21:
                 writeVer = reader.readMessage("writeVer");
 
                 if (!reader.isLastRead())
@@ -636,7 +570,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
                 reader.incrementState();
 
-            case 24:
+            case 22:
                 writes = reader.readCollection("writes", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
@@ -656,7 +590,7 @@ public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 25;
+        return 23;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
index 5c75390..ac5395d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
@@ -95,7 +95,6 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
      * @param invalidate Invalidate flag.
      * @param timeout Timeout.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key if this is a group-lock transaction.
      * @param subjId Subject ID.
      * @param taskNameHash Task name hash code.
      */
@@ -112,7 +111,6 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
         boolean invalidate,
         long timeout,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
@@ -128,7 +126,6 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
             isolation,
             timeout,
             txSize,
-            grpLockKey,
             subjId,
             taskNameHash);
 
@@ -195,18 +192,8 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
         // No-op.
     }
 
-    /**
-     * Adds group lock key to remote transaction.
-     *
-     * @param key Key.
-     */
-    public void groupLockKey(IgniteTxKey key) {
-        if (grpLockKey == null)
-            grpLockKey = key;
-    }
-
     /** {@inheritDoc} */
-    @Override public <K, V> GridTuple<CacheObject> peek(GridCacheContext cacheCtx,
+    @Override public GridTuple<CacheObject> peek(GridCacheContext cacheCtx,
         boolean failFast,
         KeyCacheObject key,
         CacheEntryPredicate[] filter)
@@ -350,7 +337,6 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
             entry.op(e.op());
             entry.ttl(e.ttl());
             entry.explicitVersion(e.explicitVersion());
-            entry.groupLockEntry(e.groupLockEntry());
 
             // Conflict resolution stuff.
             entry.conflictVersion(e.conflictVersion());
@@ -446,7 +432,7 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
                         GridCacheVersion ver = txEntry.explicitVersion() != null ? txEntry.explicitVersion() : xidVer;
 
                         // If locks haven't been acquired yet, keep waiting.
-                        if (!txEntry.groupLockEntry() && !Entry.lockedBy(ver)) {
+                        if (!Entry.lockedBy(ver)) {
                             if (log.isDebugEnabled())
                                 log.debug("Transaction does not own lock for entry (will wait) [entry=" + Entry +
                                     ", tx=" + this + ']');
@@ -607,10 +593,6 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
                                     }
                                     // No-op.
                                     else {
-                                        assert !groupLock() || txEntry.groupLockEntry() || ownsLock(txEntry.cached()):
-                                            "Transaction does not own lock for group lock entry during  commit [tx=" +
-                                                this + ", txEntry=" + txEntry + ']';
-
                                         if (conflictCtx == null || !conflictCtx.isUseOld()) {
                                             if (txEntry.ttl() != CU.TTL_NOT_CHANGED)
                                                 cached.updateTtl(null, txEntry.ttl());
@@ -651,15 +633,17 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
                             }
                         }
                         catch (Throwable ex) {
-                            uncommit();
-
-                            state(UNKNOWN);
-
                             // In case of error, we still make the best effort to commit,
                             // as there is no way to rollback at this point.
                             err = new IgniteTxHeuristicCheckedException("Commit produced a runtime exception " +
                                 "(all transaction entries will be invalidated): " + CU.txString(this), ex);
 
+                            U.error(log, "Commit failed.", err);
+
+                            uncommit();
+
+                            state(UNKNOWN);
+
                             if (ex instanceof Error)
                                 throw (Error)ex;
                         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
index 1c46fd0..10b84e2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
@@ -102,6 +102,9 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
                 GridCacheMapEntry next,
                 int hdrId)
             {
+                if (ctx.useOffheapEntry())
+                    return new GridDhtOffHeapCacheEntry(ctx, topVer, key, hash, val, next, hdrId);
+
                 return new GridDhtCacheEntry(ctx, topVer, key, hash, val, next, hdrId);
             }
         });
@@ -343,17 +346,24 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
     public GridCacheEntryEx entryExx(KeyCacheObject key, AffinityTopologyVersion topVer, boolean allowDetached, boolean touch) {
         try {
             return allowDetached && !ctx.affinity().localNode(key, topVer) ?
-                new GridDhtDetachedCacheEntry(ctx, key, key.hashCode(), null, null, 0) :
-                entryEx(key, touch);
+                createEntry(key) : entryEx(key, touch);
         }
         catch (GridDhtInvalidPartitionException e) {
             if (!allowDetached)
                 throw e;
 
-            return new GridDhtDetachedCacheEntry(ctx, key, key.hashCode(), null, null, 0);
+            return createEntry(key);
         }
     }
 
+    /**
+     * @param key Key for which entry should be returned.
+     * @return Cache entry.
+     */
+    protected GridDistributedCacheEntry createEntry(KeyCacheObject key) {
+        return new GridDhtDetachedCacheEntry(ctx, key, key.hashCode(), null, null, 0);
+    }
+
     /** {@inheritDoc} */
     @Override public void localLoad(Collection<? extends K> keys, final ExpiryPolicy plc)
         throws IgniteCheckedException {
@@ -645,8 +655,10 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
                     res.error(e);
                 }
 
-                res.invalidPartitions(fut.invalidPartitions(),
-                    new AffinityTopologyVersion(ctx.discovery().topologyVersion()));
+                if (!F.isEmpty(fut.invalidPartitions()))
+                    res.invalidPartitions(fut.invalidPartitions(), ctx.shared().exchange().readyAffinityVersion());
+                else
+                    res.invalidPartitions(fut.invalidPartitions(), req.topologyVersion());
 
                 try {
                     ctx.io().send(nodeId, res, ctx.ioPolicy());

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
index c433698..0749f66 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
@@ -49,7 +49,7 @@ import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDh
  */
 public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition> {
     /** Maximum size for delete queue. */
-    private static final int MAX_DELETE_QUEUE_SIZE = Integer.getInteger(IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE,
+    public static final int MAX_DELETE_QUEUE_SIZE = Integer.getInteger(IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE,
         200_000);
 
     /** Static logger to avoid re-creation. */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java
index 5b0275c..c57eded 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java
@@ -833,8 +833,6 @@ public final class GridDhtLockFuture<K, V> extends GridCompoundIdentityFuture<Bo
                         cnt,
                         0,
                         inTx() ? tx.size() : cnt,
-                        inTx() ? tx.groupLockKey() : null,
-                        inTx() && tx.partitionLock(),
                         inTx() ? tx.subjectId() : null,
                         inTx() ? tx.taskNameHash() : 0,
                         read ? accessTtl : -1L,

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
index 9b69571..94ec718 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
@@ -22,7 +22,6 @@ import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.affinity.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.cache.distributed.*;
-import org.apache.ignite.internal.processors.cache.transactions.*;
 import org.apache.ignite.internal.processors.cache.version.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.tostring.*;
@@ -101,8 +100,6 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
      * @param dhtCnt DHT count.
      * @param nearCnt Near count.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key.
-     * @param partLock {@code True} if partition lock.
      * @param subjId Subject ID.
      * @param taskNameHash Task name hash code.
      * @param accessTtl TTL for read operation.
@@ -125,8 +122,6 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
         int dhtCnt,
         int nearCnt,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
-        boolean partLock,
         @Nullable UUID subjId,
         int taskNameHash,
         long accessTtl,
@@ -145,8 +140,6 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
             timeout,
             dhtCnt == 0 ? nearCnt : dhtCnt,
             txSize,
-            grpLockKey,
-            partLock,
             skipStore);
 
         this.topVer = topVer;
@@ -331,55 +324,55 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
         }
 
         switch (writer.state()) {
-            case 23:
+            case 21:
                 if (!writer.writeLong("accessTtl", accessTtl))
                     return false;
 
                 writer.incrementState();
 
-            case 24:
+            case 22:
                 if (!writer.writeBitSet("invalidateEntries", invalidateEntries))
                     return false;
 
                 writer.incrementState();
 
-            case 25:
+            case 23:
                 if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
                 writer.incrementState();
 
-            case 26:
+            case 24:
                 if (!writer.writeCollection("nearKeys", nearKeys, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
 
-            case 27:
+            case 25:
                 if (!writer.writeByteArray("ownedBytes", ownedBytes))
                     return false;
 
                 writer.incrementState();
 
-            case 28:
+            case 26:
                 if (!writer.writeBitSet("preloadKeys", preloadKeys))
                     return false;
 
                 writer.incrementState();
 
-            case 29:
+            case 27:
                 if (!writer.writeUuid("subjId", subjId))
                     return false;
 
                 writer.incrementState();
 
-            case 30:
+            case 28:
                 if (!writer.writeInt("taskNameHash", taskNameHash))
                     return false;
 
                 writer.incrementState();
 
-            case 31:
+            case 29:
                 if (!writer.writeMessage("topVer", topVer))
                     return false;
 
@@ -401,7 +394,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
             return false;
 
         switch (reader.state()) {
-            case 23:
+            case 21:
                 accessTtl = reader.readLong("accessTtl");
 
                 if (!reader.isLastRead())
@@ -409,7 +402,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 24:
+            case 22:
                 invalidateEntries = reader.readBitSet("invalidateEntries");
 
                 if (!reader.isLastRead())
@@ -417,7 +410,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 25:
+            case 23:
                 miniId = reader.readIgniteUuid("miniId");
 
                 if (!reader.isLastRead())
@@ -425,7 +418,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 26:
+            case 24:
                 nearKeys = reader.readCollection("nearKeys", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
@@ -433,7 +426,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 27:
+            case 25:
                 ownedBytes = reader.readByteArray("ownedBytes");
 
                 if (!reader.isLastRead())
@@ -441,7 +434,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 28:
+            case 26:
                 preloadKeys = reader.readBitSet("preloadKeys");
 
                 if (!reader.isLastRead())
@@ -449,7 +442,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 29:
+            case 27:
                 subjId = reader.readUuid("subjId");
 
                 if (!reader.isLastRead())
@@ -457,7 +450,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 30:
+            case 28:
                 taskNameHash = reader.readInt("taskNameHash");
 
                 if (!reader.isLastRead())
@@ -465,7 +458,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 31:
+            case 29:
                 topVer = reader.readMessage("topVer");
 
                 if (!reader.isLastRead())
@@ -485,7 +478,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 32;
+        return 30;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtOffHeapCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtOffHeapCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtOffHeapCacheEntry.java
new file mode 100644
index 0000000..1191d83
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtOffHeapCacheEntry.java
@@ -0,0 +1,63 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.internal.processors.affinity.*;
+import org.apache.ignite.internal.processors.cache.*;
+
+/**
+ * Replicated cache entry for off-heap tiered or off-heap values modes.
+ */
+public class GridDhtOffHeapCacheEntry extends GridDhtCacheEntry {
+    /** Off-heap value pointer. */
+    private long valPtr;
+
+    /**
+     * @param ctx    Cache context.
+     * @param topVer Topology version at the time of creation (if negative, then latest topology is assumed).
+     * @param key    Cache key.
+     * @param hash   Key hash value.
+     * @param val    Entry value.
+     * @param next   Next entry in the linked list.
+     * @param hdrId  Header id.
+     */
+    public GridDhtOffHeapCacheEntry(GridCacheContext ctx,
+        AffinityTopologyVersion topVer,
+        KeyCacheObject key,
+        int hash,
+        CacheObject val,
+        GridCacheMapEntry next,
+        int hdrId) {
+        super(ctx, topVer, key, hash, val, next, hdrId);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean hasOffHeapPointer() {
+        return valPtr != 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long offHeapPointer() {
+        return valPtr;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void offHeapPointer(long valPtr) {
+        this.valPtr = valPtr;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
index 87026f3..26eef50 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
@@ -174,7 +174,7 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
 
                         // Invalidate key in near cache, if any.
                         if (isNearEnabled(cacheCfg))
-                            obsoleteNearEntry(key, req.version());
+                            obsoleteNearEntry(key);
 
                         break;
                     }
@@ -203,7 +203,6 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
                                     req.isInvalidate(),
                                     req.timeout(),
                                     req.txSize(),
-                                    req.groupLockKey(),
                                     req.subjectId(),
                                     req.taskNameHash());
 
@@ -222,9 +221,6 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
                                 null,
                                 req.accessTtl(),
                                 req.skipStore());
-
-                            if (req.groupLock())
-                                tx.groupLockKey(txKey);
                         }
 
                         entry = entryExx(key, req.topologyVersion());
@@ -291,7 +287,7 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
 
                     // Invalidate key in near cache, if any.
                     if (isNearEnabled(cacheCfg))
-                        obsoleteNearEntry(key, req.version());
+                        obsoleteNearEntry(key);
 
                     if (tx != null) {
                         tx.clearEntry(txKey);
@@ -810,8 +806,6 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
                                     req.isInvalidate(),
                                     false,
                                     req.txSize(),
-                                    req.groupLockKey(),
-                                    req.partitionLock(),
                                     null,
                                     req.subjectId(),
                                     req.taskNameHash());
@@ -1481,12 +1475,11 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
 
     /**
      * @param key Key
-     * @param ver Version.
      */
-    private void obsoleteNearEntry(KeyCacheObject key, GridCacheVersion ver) {
+    private void obsoleteNearEntry(KeyCacheObject key) {
         GridCacheEntryEx nearEntry = near().peekEx(key);
 
         if (nearEntry != null)
-            nearEntry.markObsolete(ver);
+            nearEntry.markObsolete(ctx.versions().next());
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishFuture.java
index 7c35fc5..7fd79e5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishFuture.java
@@ -309,7 +309,6 @@ public final class GridDhtTxFinishFuture<K, V> extends GridCompoundIdentityFutur
                 tx.rolledbackVersions(),
                 tx.pendingVersions(),
                 tx.size(),
-                tx.groupLockKey(),
                 tx.subjectId(),
                 tx.taskNameHash());
 
@@ -387,7 +386,6 @@ public final class GridDhtTxFinishFuture<K, V> extends GridCompoundIdentityFutur
                 tx.rolledbackVersions(),
                 tx.pendingVersions(),
                 tx.size(),
-                tx.groupLockKey(),
                 tx.subjectId(),
                 tx.taskNameHash());
 
@@ -439,7 +437,6 @@ public final class GridDhtTxFinishFuture<K, V> extends GridCompoundIdentityFutur
                     tx.rolledbackVersions(),
                     tx.pendingVersions(),
                     tx.size(),
-                    tx.groupLockKey(),
                     tx.subjectId(),
                     tx.taskNameHash());
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java
index d20a7c3..7b077c3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java
@@ -21,7 +21,6 @@ import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.affinity.*;
 import org.apache.ignite.internal.managers.communication.*;
 import org.apache.ignite.internal.processors.cache.distributed.*;
-import org.apache.ignite.internal.processors.cache.transactions.*;
 import org.apache.ignite.internal.processors.cache.version.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
@@ -97,7 +96,6 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
      * @param rolledbackVers Rolled back versions.
      * @param pendingVers Pending versions.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key.
      * @param subjId Subject ID.
      * @param taskNameHash Task name hash.
      */
@@ -122,12 +120,11 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
         Collection<GridCacheVersion> rolledbackVers,
         Collection<GridCacheVersion> pendingVers,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
         super(xidVer, futId, commitVer, threadId, commit, invalidate, sys, plc, syncCommit, syncRollback, baseVer,
-            committedVers, rolledbackVers, txSize, grpLockKey);
+            committedVers, rolledbackVers, txSize);
 
         assert miniId != null;
         assert nearNodeId != null;
@@ -241,55 +238,55 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
         }
 
         switch (writer.state()) {
-            case 20:
+            case 19:
                 if (!writer.writeByte("isolation", isolation != null ? (byte)isolation.ordinal() : -1))
                     return false;
 
                 writer.incrementState();
 
-            case 21:
+            case 20:
                 if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
                 writer.incrementState();
 
-            case 22:
+            case 21:
                 if (!writer.writeUuid("nearNodeId", nearNodeId))
                     return false;
 
                 writer.incrementState();
 
-            case 23:
+            case 22:
                 if (!writer.writeCollection("pendingVers", pendingVers, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
 
-            case 24:
+            case 23:
                 if (!writer.writeUuid("subjId", subjId))
                     return false;
 
                 writer.incrementState();
 
-            case 25:
+            case 24:
                 if (!writer.writeBoolean("sysInvalidate", sysInvalidate))
                     return false;
 
                 writer.incrementState();
 
-            case 26:
+            case 25:
                 if (!writer.writeInt("taskNameHash", taskNameHash))
                     return false;
 
                 writer.incrementState();
 
-            case 27:
+            case 26:
                 if (!writer.writeMessage("topVer", topVer))
                     return false;
 
                 writer.incrementState();
 
-            case 28:
+            case 27:
                 if (!writer.writeMessage("writeVer", writeVer))
                     return false;
 
@@ -311,7 +308,7 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
             return false;
 
         switch (reader.state()) {
-            case 20:
+            case 19:
                 byte isolationOrd;
 
                 isolationOrd = reader.readByte("isolation");
@@ -323,7 +320,7 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 21:
+            case 20:
                 miniId = reader.readIgniteUuid("miniId");
 
                 if (!reader.isLastRead())
@@ -331,7 +328,7 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 22:
+            case 21:
                 nearNodeId = reader.readUuid("nearNodeId");
 
                 if (!reader.isLastRead())
@@ -339,7 +336,7 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 23:
+            case 22:
                 pendingVers = reader.readCollection("pendingVers", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
@@ -347,7 +344,7 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 24:
+            case 23:
                 subjId = reader.readUuid("subjId");
 
                 if (!reader.isLastRead())
@@ -355,7 +352,7 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 25:
+            case 24:
                 sysInvalidate = reader.readBoolean("sysInvalidate");
 
                 if (!reader.isLastRead())
@@ -363,7 +360,7 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 26:
+            case 25:
                 taskNameHash = reader.readInt("taskNameHash");
 
                 if (!reader.isLastRead())
@@ -371,7 +368,7 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 27:
+            case 26:
                 topVer = reader.readMessage("topVer");
 
                 if (!reader.isLastRead())
@@ -379,7 +376,7 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
 
                 reader.incrementState();
 
-            case 28:
+            case 27:
                 writeVer = reader.readMessage("writeVer");
 
                 if (!reader.isLastRead())
@@ -399,6 +396,6 @@ public class GridDhtTxFinishRequest extends GridDistributedTxFinishRequest {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 29;
+        return 28;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocal.java
index 07ced0d..841cac8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocal.java
@@ -93,8 +93,6 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
      * @param timeout Timeout.
      * @param storeEnabled Store enabled flag.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key if this is a group-lock transaction.
-     * @param partLock {@code True} if this is a group-lock transaction and whole partition should be locked.
      * @param txNodes Transaction nodes mapping.
      */
     public GridDhtTxLocal(
@@ -115,8 +113,6 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
         boolean invalidate,
         boolean storeEnabled,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
-        boolean partLock,
         Map<UUID, Collection<UUID>> txNodes,
         UUID subjId,
         int taskNameHash
@@ -135,8 +131,6 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
             invalidate,
             storeEnabled,
             txSize,
-            grpLockKey,
-            partLock,
             subjId,
             taskNameHash);
 
@@ -284,7 +278,7 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<IgniteInternalTx> prepareAsync() {
+    @Override public IgniteInternalFuture<?> prepareAsync() {
         if (optimistic()) {
             assert isSystemInvalidate();
 
@@ -296,7 +290,6 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
                 nearMiniId,
                 null,
                 true,
-                null,
                 null);
         }
 
@@ -305,14 +298,13 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
 
         if (fut == null) {
             // Future must be created before any exception can be thrown.
-            if (!prepFut.compareAndSet(null, fut = new GridDhtTxPrepareFuture<>(
+            if (!prepFut.compareAndSet(null, fut = new GridDhtTxPrepareFuture(
                 cctx,
                 this,
                 nearMiniId,
                 Collections.<IgniteTxKey, GridCacheVersion>emptyMap(),
                 true,
                 needReturnValue(),
-                null,
                 null)))
                 return prepFut.get();
         }
@@ -371,7 +363,7 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
      * @param lastBackups IDs of backup nodes receiving last prepare request.
      * @return Future that will be completed when locks are acquired.
      */
-    public IgniteInternalFuture<IgniteInternalTx> prepareAsync(
+    public IgniteInternalFuture<GridNearTxPrepareResponse> prepareAsync(
         @Nullable Iterable<IgniteTxEntry> reads,
         @Nullable Iterable<IgniteTxEntry> writes,
         Map<IgniteTxKey, GridCacheVersion> verMap,
@@ -379,8 +371,7 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
         IgniteUuid nearMiniId,
         Map<UUID, Collection<UUID>> txNodes,
         boolean last,
-        Collection<UUID> lastBackups,
-        IgniteInClosure<GridNearTxPrepareResponse> completeCb
+        Collection<UUID> lastBackups
     ) {
         // In optimistic mode prepare still can be called explicitly from salvageTx.
         GridDhtTxPrepareFuture fut = prepFut.get();
@@ -389,21 +380,20 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
             init();
 
             // Future must be created before any exception can be thrown.
-            if (!prepFut.compareAndSet(null, fut = new GridDhtTxPrepareFuture<>(
+            if (!prepFut.compareAndSet(null, fut = new GridDhtTxPrepareFuture(
                 cctx,
                 this,
                 nearMiniId,
                 verMap,
                 last,
                 needReturnValue(),
-                lastBackups,
-                completeCb))) {
+                lastBackups))) {
                 GridDhtTxPrepareFuture f = prepFut.get();
 
                 assert f.nearMiniId().equals(nearMiniId) : "Wrong near mini id on existing future " +
                     "[futMiniId=" + f.nearMiniId() + ", miniId=" + nearMiniId + ", fut=" + f + ']';
 
-                return f;
+                return chainOnePhasePrepare(f);
             }
         }
         else {
@@ -411,7 +401,7 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
                 "[futMiniId=" + fut.nearMiniId() + ", miniId=" + nearMiniId + ", fut=" + fut + ']';
 
             // Prepare was called explicitly.
-            return fut;
+            return chainOnePhasePrepare(fut);
         }
 
         if (state() != PREPARING) {
@@ -475,7 +465,7 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
             }
         }
 
-        return fut;
+        return chainOnePhasePrepare(fut);
     }
 
     /** {@inheritDoc} */
@@ -517,8 +507,8 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
                 }
             }
             else
-                prep.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
-                    @Override public void apply(IgniteInternalFuture<IgniteInternalTx> f) {
+                prep.listen(new CI1<IgniteInternalFuture<?>>() {
+                    @Override public void apply(IgniteInternalFuture<?> f) {
                         try {
                             f.get(); // Check for errors of a parent future.
 
@@ -605,8 +595,8 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
         else {
             prepFut.complete();
 
-            prepFut.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
-                @Override public void apply(IgniteInternalFuture<IgniteInternalTx> f) {
+            prepFut.listen(new CI1<IgniteInternalFuture<?>>() {
+                @Override public void apply(IgniteInternalFuture<?> f) {
                     try {
                         f.get(); // Check for errors of a parent future.
                     }
@@ -686,7 +676,7 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter implements GridCacheMa
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nullable @Override public IgniteInternalFuture<IgniteInternalTx> currentPrepareFuture() {
+    @Nullable @Override public IgniteInternalFuture<?> currentPrepareFuture() {
         return prepFut.get();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
index 08fcaf6..54b59b8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
@@ -24,6 +24,7 @@ import org.apache.ignite.internal.processors.affinity.*;
 import org.apache.ignite.internal.managers.communication.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.cache.distributed.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
 import org.apache.ignite.internal.processors.cache.transactions.*;
 import org.apache.ignite.internal.processors.cache.version.*;
 import org.apache.ignite.internal.util.*;
@@ -93,8 +94,6 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
      * @param isolation Isolation.
      * @param timeout Timeout.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key if this is a group-lock transaction.
-     * @param partLock If this is a group-lock transaction and the whole partition should be locked.
      */
     protected GridDhtTxLocalAdapter(
         GridCacheSharedContext cctx,
@@ -110,13 +109,11 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
         boolean invalidate,
         boolean storeEnabled,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
-        boolean partLock,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
         super(cctx, xidVer, implicit, implicitSingle, sys, plc, concurrency, isolation, timeout, invalidate,
-            storeEnabled, txSize, grpLockKey, partLock, subjId, taskNameHash);
+            storeEnabled, txSize, subjId, taskNameHash);
 
         assert cctx != null;
 
@@ -732,68 +729,6 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override protected void addGroupTxMapping(Collection<IgniteTxKey> keys) {
-        assert groupLock();
-
-        for (GridDistributedTxMapping mapping : dhtMap.values())
-            mapping.entries(Collections.unmodifiableCollection(txMap.values()), true);
-
-        // Here we know that affinity key for all given keys is our group lock key.
-        // Just add entries to dht mapping.
-        // Add near readers. If near cache is disabled on all nodes, do nothing.
-        Collection<UUID> backupIds = dhtMap.keySet();
-
-        Map<ClusterNode, List<GridDhtCacheEntry>> locNearMap = null;
-
-        for (IgniteTxKey key : keys) {
-            IgniteTxEntry txEntry = entry(key);
-
-            if (!txEntry.groupLockEntry() || txEntry.context().isNear())
-                continue;
-
-            assert txEntry.cached() instanceof GridDhtCacheEntry : "Invalid entry type: " + txEntry.cached();
-
-            while (true) {
-                try {
-                    GridDhtCacheEntry entry = (GridDhtCacheEntry)txEntry.cached();
-
-                    Collection<UUID> readers = entry.readers();
-
-                    if (!F.isEmpty(readers)) {
-                        Collection<ClusterNode> nearNodes = cctx.discovery().nodes(readers, F0.notEqualTo(nearNodeId()),
-                            F.notIn(backupIds));
-
-                        if (log.isDebugEnabled())
-                            log.debug("Mapping entry to near nodes [nodes=" + U.nodeIds(nearNodes) + ", entry=" +
-                                entry + ']');
-
-                        for (ClusterNode n : nearNodes) {
-                            if (locNearMap == null)
-                                locNearMap = new HashMap<>();
-
-                            List<GridDhtCacheEntry> entries = locNearMap.get(n);
-
-                            if (entries == null)
-                                locNearMap.put(n, entries = new LinkedList<>());
-
-                            entries.add(entry);
-                        }
-                    }
-
-                    break;
-                }
-                catch (GridCacheEntryRemovedException ignored) {
-                    // Retry.
-                    txEntry.cached(txEntry.context().dht().entryExx(key.key(), topologyVersion()));
-                }
-            }
-        }
-
-        if (locNearMap != null)
-            addNearNodeEntryMapping(locNearMap);
-    }
-
-    /** {@inheritDoc} */
     @SuppressWarnings({"CatchGenericClass", "ThrowableInstanceNeverThrown"})
     @Override public boolean finish(boolean commit) throws IgniteCheckedException {
         if (log.isDebugEnabled())
@@ -885,6 +820,32 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
      */
     protected abstract void clearPrepareFuture(GridDhtTxPrepareFuture fut);
 
+    /**
+     * @return {@code True} if transaction is finished on prepare step.
+     */
+    protected final boolean commitOnPrepare() {
+        return onePhaseCommit() && !near();
+    }
+
+    /**
+     * @param prepFut Prepare future.
+     * @return If transaction if finished on prepare step returns future which is completed after transaction finish.
+     */
+    protected final IgniteInternalFuture<GridNearTxPrepareResponse> chainOnePhasePrepare(
+        final GridDhtTxPrepareFuture prepFut) {
+        if (commitOnPrepare()) {
+            return finishFuture().chain(new CX1<IgniteInternalFuture<IgniteInternalTx>, GridNearTxPrepareResponse>() {
+                @Override public GridNearTxPrepareResponse applyx(IgniteInternalFuture<IgniteInternalTx> finishFut)
+                    throws IgniteCheckedException
+                {
+                    return prepFut.get();
+                }
+            });
+        }
+
+        return prepFut;
+    }
+
     /** {@inheritDoc} */
     @Override public void rollback() throws IgniteCheckedException {
         try {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxMapping.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxMapping.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxMapping.java
index d207d76..ba2c35f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxMapping.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxMapping.java
@@ -28,7 +28,7 @@ import java.util.*;
 /**
  * DHT transaction mapping.
  */
-public class GridDhtTxMapping<K, V> {
+public class GridDhtTxMapping {
     /** Transaction nodes mapping (primary node -> related backup nodes). */
     private final Map<UUID, Collection<UUID>> txNodes = new GridLeanMap<>();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
index 3a1a80a..293cf95 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
@@ -50,19 +50,32 @@ import static org.apache.ignite.transactions.TransactionState.*;
  *
  */
 @SuppressWarnings("unchecked")
-public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFuture<IgniteInternalTx>
-    implements GridCacheMvccFuture<IgniteInternalTx> {
+public final class GridDhtTxPrepareFuture extends GridCompoundFuture<IgniteInternalTx, GridNearTxPrepareResponse>
+    implements GridCacheMvccFuture<GridNearTxPrepareResponse> {
     /** */
     private static final long serialVersionUID = 0L;
 
     /** Logger reference. */
     private static final AtomicReference<IgniteLogger> logRef = new AtomicReference<>();
 
+    /** */
+    private static final IgniteReducer<IgniteInternalTx, GridNearTxPrepareResponse> REDUCER =
+        new IgniteReducer<IgniteInternalTx, GridNearTxPrepareResponse>() {
+            @Override public boolean collect(IgniteInternalTx e) {
+                return true;
+            }
+
+            @Override public GridNearTxPrepareResponse reduce() {
+                // Nothing to aggregate.
+                return null;
+            }
+        };
+
     /** Logger. */
     private static IgniteLogger log;
 
     /** Context. */
-    private GridCacheSharedContext<K, V> cctx;
+    private GridCacheSharedContext<?, ?> cctx;
 
     /** Future ID. */
     private IgniteUuid futId;
@@ -128,15 +141,13 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
     /** */
     private boolean invoke;
 
-    /** */
-    private IgniteInClosure<GridNearTxPrepareResponse> completeCb;
-
     /**
      * @param cctx Context.
      * @param tx Transaction.
      * @param nearMiniId Near mini future id.
      * @param dhtVerMap DHT versions map.
      * @param last {@code True} if this is last prepare operation for node.
+     * @param retVal Return value flag.
      * @param lastBackups IDs of backup nodes receiving last prepare request during this prepare.
      */
     public GridDhtTxPrepareFuture(
@@ -146,19 +157,9 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
         Map<IgniteTxKey, GridCacheVersion> dhtVerMap,
         boolean last,
         boolean retVal,
-        Collection<UUID> lastBackups,
-        IgniteInClosure<GridNearTxPrepareResponse> completeCb
+        Collection<UUID> lastBackups
     ) {
-        super(cctx.kernalContext(), new IgniteReducer<IgniteInternalTx, IgniteInternalTx>() {
-            @Override public boolean collect(IgniteInternalTx e) {
-                return true;
-            }
-
-            @Override public IgniteInternalTx reduce() {
-                // Nothing to aggregate.
-                return tx;
-            }
-        });
+        super(REDUCER);
 
         this.cctx = cctx;
         this.tx = tx;
@@ -178,8 +179,6 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
 
         this.retVal = retVal;
 
-        this.completeCb = completeCb;
-
         assert dhtMap != null;
         assert nearMap != null;
     }
@@ -382,7 +381,7 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
      * @param t Error.
      */
     public void onError(Throwable t) {
-        onDone(tx, t);
+        onDone(null, t);
     }
 
     /**
@@ -415,8 +414,7 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
         if (log.isDebugEnabled())
             log.debug("Marking all local candidates as ready: " + this);
 
-        Iterable<IgniteTxEntry> checkEntries = tx.groupLock() ?
-            Collections.singletonList(tx.groupLockEntry()) : writes;
+        Iterable<IgniteTxEntry> checkEntries = writes;
 
         for (IgniteTxEntry txEntry : checkEntries) {
             GridCacheContext cacheCtx = txEntry.context();
@@ -432,10 +430,8 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
                 txEntry.cached(entry);
             }
 
-            if (tx.optimistic() && txEntry.explicitVersion() == null) {
-                if (!tx.groupLock() || tx.groupLockKey().equals(entry.txKey()))
-                    lockKeys.add(txEntry.txKey());
-            }
+            if (tx.optimistic() && txEntry.explicitVersion() == null)
+                lockKeys.add(txEntry.txKey());
 
             while (true) {
                 try {
@@ -479,7 +475,7 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
     }
 
     /** {@inheritDoc} */
-    @Override public boolean onDone(IgniteInternalTx tx0, Throwable err) {
+    @Override public boolean onDone(GridNearTxPrepareResponse res0, Throwable err) {
         assert err != null || (initialized() && !hasPending()) : "On done called for prepare future that has " +
             "pending mini futures: " + this;
 
@@ -495,16 +491,15 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
             // Must create prepare response before transaction is committed to grab correct return value.
             final GridNearTxPrepareResponse res = createPrepareResponse();
 
-            onComplete();
+            onComplete(res);
 
-            if (!tx.near()) {
+            if (tx.commitOnPrepare()) {
                 if (tx.markFinalizing(IgniteInternalTx.FinalizationStatus.USER_FINISH)) {
                     IgniteInternalFuture<IgniteInternalTx> fut = this.err.get() == null ?
                         tx.commitAsync() : tx.rollbackAsync();
 
                     fut.listen(new CIX1<IgniteInternalFuture<IgniteInternalTx>>() {
-                        @Override
-                        public void applyx(IgniteInternalFuture<IgniteInternalTx> fut) {
+                        @Override public void applyx(IgniteInternalFuture<IgniteInternalTx> fut) {
                             try {
                                 if (replied.compareAndSet(false, true))
                                     sendPrepareResponse(res);
@@ -530,15 +525,17 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
         }
         else {
             if (replied.compareAndSet(false, true)) {
+                GridNearTxPrepareResponse res = createPrepareResponse();
+
                 try {
-                    sendPrepareResponse(createPrepareResponse());
+                    sendPrepareResponse(res);
                 }
                 catch (IgniteCheckedException e) {
                     U.error(log, "Failed to send prepare response for transaction: " + tx, e);
                 }
                 finally {
                     // Will call super.onDone().
-                    onComplete();
+                    onComplete(res);
                 }
 
                 return true;
@@ -562,16 +559,12 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
     }
 
     /**
+     * @param res Response.
      * @throws IgniteCheckedException If failed to send response.
      */
     private void sendPrepareResponse(GridNearTxPrepareResponse res) throws IgniteCheckedException {
         if (!tx.nearNodeId().equals(cctx.localNodeId()))
             cctx.io().send(tx.nearNodeId(), res, tx.ioPolicy());
-        else {
-            assert completeCb != null;
-
-            completeCb.apply(res);
-        }
     }
 
     /**
@@ -586,6 +579,7 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
             tx.colocated() ? tx.xid() : tx.nearFutureId(),
             nearMiniId == null ? tx.xid() : nearMiniId,
             tx.xidVersion(),
+            tx.writeVersion(),
             tx.invalidPartitions(),
             ret,
             prepErr);
@@ -616,10 +610,10 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
             for (IgniteTxEntry e : writes) {
                 IgniteTxEntry txEntry = tx.entry(e.txKey());
 
-                GridCacheContext cacheCtx = txEntry.context();
-
                 assert txEntry != null : "Missing tx entry for key [tx=" + tx + ", key=" + e.txKey() + ']';
 
+                GridCacheContext cacheCtx = txEntry.context();
+
                 while (true) {
                     try {
                         GridCacheEntryEx entry = txEntry.cached();
@@ -682,13 +676,14 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
     /**
      * Completeness callback.
      *
+     * @param res Response.
      * @return {@code True} if {@code done} flag was changed as a result of this call.
      */
-    private boolean onComplete() {
+    private boolean onComplete(@Nullable GridNearTxPrepareResponse res) {
         if (last || tx.isSystemInvalidate())
             tx.state(PREPARED);
 
-        if (super.onDone(tx, err.get())) {
+        if (super.onDone(res, err.get())) {
             // Don't forget to clean up.
             cctx.mvcc().removeFuture(this);
 
@@ -702,7 +697,7 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
      * Completes this future.
      */
     public void complete() {
-        onComplete();
+        onComplete(null);
     }
 
     /**
@@ -717,7 +712,7 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
         if (tx.empty()) {
             tx.setRollbackOnly();
 
-            onDone(tx);
+            onDone((GridNearTxPrepareResponse)null);
         }
 
         this.reads = reads;
@@ -806,8 +801,6 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
                         tx,
                         dhtWrites,
                         nearWrites,
-                        tx.groupLockKey(),
-                        tx.partitionLock(),
                         txNodes,
                         tx.nearXidVersion(),
                         true,
@@ -821,14 +814,11 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
                         try {
                             GridDhtCacheEntry cached = (GridDhtCacheEntry)entry.cached();
 
-                            GridCacheContext<K, V> cacheCtx = cached.context();
+                            GridCacheContext<?, ?> cacheCtx = cached.context();
 
                             if (entry.explicitVersion() == null) {
                                 GridCacheMvccCandidate added = cached.candidate(version());
 
-                                assert added != null || entry.groupLockEntry() :
-                                    "Null candidate for non-group-lock entry " +
-                                        "[added=" + added + ", entry=" + entry + ']';
                                 assert added == null || added.dhtLocal() :
                                     "Got non-dht-local candidate for prepare future " +
                                         "[added=" + added + ", entry=" + entry + ']';
@@ -909,8 +899,6 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
                             tx,
                             null,
                             nearMapping.writes(),
-                            tx.groupLockKey(),
-                            tx.partitionLock(),
                             tx.transactionNodes(),
                             tx.nearXidVersion(),
                             true,
@@ -923,8 +911,6 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
                                 if (entry.explicitVersion() == null) {
                                     GridCacheMvccCandidate added = entry.cached().candidate(version());
 
-                                    assert added != null || entry.groupLockEntry() : "Null candidate for non-group-lock entry " +
-                                        "[added=" + added + ", entry=" + entry + ']';
                                     assert added == null || added.dhtLocal() : "Got non-dht-local candidate for prepare future" +
                                         "[added=" + added + ", entry=" + entry + ']';
 
@@ -977,7 +963,7 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
 
         GridCacheContext cacheCtx = entry.context();
 
-        GridDhtCacheAdapter<K, V> dht = cacheCtx.isNear() ? cacheCtx.near().dht() : cacheCtx.dht();
+        GridDhtCacheAdapter<?, ?> dht = cacheCtx.isNear() ? cacheCtx.near().dht() : cacheCtx.dht();
 
         ExpiryPolicy expiry = cacheCtx.expiryForTxEntry(entry);
 
@@ -1234,7 +1220,7 @@ public final class GridDhtTxPrepareFuture<K, V> extends GridCompoundIdentityFutu
                 boolean rec = cctx.gridEvents().isRecordable(EVT_CACHE_REBALANCE_OBJECT_LOADED);
 
                 for (GridCacheEntryInfo info : res.preloadEntries()) {
-                    GridCacheContext<K, V> cacheCtx = cctx.cacheContext(info.cacheId());
+                    GridCacheContext<?, ?> cacheCtx = cctx.cacheContext(info.cacheId());
 
                     while (true) {
                         GridCacheEntryEx entry = cacheCtx.cache().entryEx(info.key());


[06/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 1bc3409..200da77 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
@@ -31,6 +31,7 @@ import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.processors.query.h2.opt.*;
 import org.apache.ignite.internal.processors.query.h2.sql.*;
 import org.apache.ignite.internal.processors.query.h2.twostep.*;
+import org.apache.ignite.internal.processors.query.h2.twostep.msg.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.offheap.unsafe.*;
@@ -39,6 +40,7 @@ import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.marshaller.*;
 import org.apache.ignite.marshaller.jdk.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.apache.ignite.resources.*;
 import org.apache.ignite.spi.*;
 import org.apache.ignite.spi.indexing.*;
@@ -63,6 +65,7 @@ import java.io.*;
 import java.lang.reflect.*;
 import java.math.*;
 import java.sql.*;
+import java.sql.Date;
 import java.text.*;
 import java.util.*;
 import java.util.concurrent.*;
@@ -291,13 +294,15 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * @param tblToUpdate Table to update.
      * @throws IgniteCheckedException In case of error.
      */
-    private void removeKey(@Nullable String spaceName, Object key, TableDescriptor tblToUpdate)
+    private void removeKey(@Nullable String spaceName, CacheObject key, TableDescriptor tblToUpdate)
         throws IgniteCheckedException {
         try {
             Collection<TableDescriptor> tbls = tables(schema(spaceName));
 
+            Class<?> keyCls = getClass(objectContext(spaceName), key);
+
             for (TableDescriptor tbl : tbls) {
-                if (tbl != tblToUpdate && tbl.type().keyClass().isAssignableFrom(key.getClass())) {
+                if (tbl != tblToUpdate && tbl.type().keyClass().isAssignableFrom(keyCls)) {
                     if (tbl.tbl.update(key, null, 0, true)) {
                         if (tbl.luceneIdx != null)
                             tbl.luceneIdx.remove(key);
@@ -350,8 +355,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /** {@inheritDoc} */
-    @Override public void store(@Nullable String spaceName, GridQueryTypeDescriptor type, Object k, Object v, byte[] ver,
-        long expirationTime) throws IgniteCheckedException {
+    @Override public void store(@Nullable String spaceName, GridQueryTypeDescriptor type, CacheObject k, CacheObject v,
+        byte[] ver, long expirationTime) throws IgniteCheckedException {
         TableDescriptor tbl = tableDescriptor(spaceName, type);
 
         removeKey(spaceName, k, tbl);
@@ -368,14 +373,63 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             tbl.luceneIdx.store(k, v, ver, expirationTime);
     }
 
+    /**
+     * @param o Object.
+     * @return {@code true} If it is a portable object.
+     */
+    private boolean isPortable(CacheObject o) {
+        if (ctx == null)
+            return false;
+
+        return ctx.cacheObjects().isPortableObject(o);
+    }
+
+    /**
+     * @param coctx Cache object context.
+     * @param o Object.
+     * @return Object class.
+     */
+    private Class<?> getClass(CacheObjectContext coctx, CacheObject o) {
+        return isPortable(o) ?
+            Object.class :
+            o.value(coctx, false).getClass();
+    }
+
+    /**
+     * @param space Space.
+     * @return Cache object context.
+     */
+    private CacheObjectContext objectContext(String space) {
+        if (ctx == null)
+            return null;
+
+        return ctx.cache().internalCache(space).context().cacheObjectContext();
+    }
+
+    /**
+     * @param space Space.
+     * @return Cache object context.
+     */
+    private GridCacheContext cacheContext(String space) {
+        if (ctx == null)
+            return null;
+
+        return ctx.cache().internalCache(space).context();
+    }
+
     /** {@inheritDoc} */
-    @Override public void remove(@Nullable String spaceName, Object key, Object val) throws IgniteCheckedException {
+    @Override public void remove(@Nullable String spaceName, CacheObject key, CacheObject val) throws IgniteCheckedException {
         if (log.isDebugEnabled())
-            log.debug("Removing key from cache query index [locId=" + nodeId + ", key=" + key + ']');
+            log.debug("Removing key from cache query index [locId=" + nodeId + ", key=" + key + ", val=" + val + ']');
+
+        CacheObjectContext coctx = objectContext(spaceName);
+
+        Class<?> keyCls = getClass(coctx, key);
+        Class<?> valCls = val == null ? null : getClass(coctx, val);
 
         for (TableDescriptor tbl : tables(schema(spaceName))) {
-            if (tbl.type().keyClass().isAssignableFrom(key.getClass())
-                && (val == null || tbl.type().valueClass().isAssignableFrom(val.getClass()))) {
+            if (tbl.type().keyClass().isAssignableFrom(keyCls)
+                && (val == null || tbl.type().valueClass().isAssignableFrom(valCls))) {
                 if (tbl.tbl.update(key, val, 0, true)) {
                     if (tbl.luceneIdx != null)
                         tbl.luceneIdx.remove(key);
@@ -387,14 +441,16 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /** {@inheritDoc} */
-    @Override public void onSwap(@Nullable String spaceName, Object key) throws IgniteCheckedException {
+    @Override public void onSwap(@Nullable String spaceName, CacheObject key) throws IgniteCheckedException {
         Schema schema = schemas.get(schema(spaceName));
 
         if (schema == null)
             return;
 
+        Class<?> keyCls = getClass(objectContext(spaceName), key);
+
         for (TableDescriptor tbl : schema.tbls.values()) {
-            if (tbl.type().keyClass().isAssignableFrom(key.getClass())) {
+            if (tbl.type().keyClass().isAssignableFrom(keyCls)) {
                 try {
                     if (tbl.tbl.onSwap(key))
                         return;
@@ -407,13 +463,18 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /** {@inheritDoc} */
-    @Override public void onUnswap(@Nullable String spaceName, Object key, Object val, byte[] valBytes)
+    @Override public void onUnswap(@Nullable String spaceName, CacheObject key, CacheObject val)
         throws IgniteCheckedException {
         assert val != null;
 
+        CacheObjectContext coctx = objectContext(spaceName);
+
+        Class<?> keyCls = getClass(coctx, key);
+        Class<?> valCls = getClass(coctx, val);
+
         for (TableDescriptor tbl : tables(schema(spaceName))) {
-            if (tbl.type().keyClass().isAssignableFrom(key.getClass())
-                && tbl.type().valueClass().isAssignableFrom(val.getClass())) {
+            if (tbl.type().keyClass().isAssignableFrom(keyCls)
+                && tbl.type().valueClass().isAssignableFrom(valCls)) {
                 try {
                     if (tbl.tbl.onUnswap(key, val))
                         return;
@@ -514,7 +575,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                     meta = meta(rs.getMetaData());
                 }
                 catch (SQLException e) {
-                    throw new IgniteSpiException("Failed to get meta data.", e);
+                    throw new IgniteCheckedException("Failed to get meta data.", e);
                 }
             }
 
@@ -1114,6 +1175,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             log.debug("Starting cache query index...");
 
         System.setProperty("h2.serializeJavaObject", "false");
+        System.setProperty("h2.objectCacheMaxPerElementSize", "0"); // Avoid ValueJavaObject caching.
 
         if (SysProperties.serializeJavaObject) {
             U.warn(log, "Serialization of Java objects in H2 was enabled.");
@@ -1259,6 +1321,10 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             throw new IgniteCheckedException("Cache already registered: " + U.maskName(ccfg.getName()));
 
         createSchema(schema);
+
+        executeStatement(schema, "CREATE ALIAS " + GridSqlQuerySplitter.TABLE_FUNC_NAME +
+            " NOBUFFER FOR \"" + GridReduceQueryExecutor.class.getName() + ".mergeTableFunction\"");
+
         createSqlFunctions(schema, ccfg.getSqlFunctionClasses());
     }
 
@@ -1297,6 +1363,11 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         };
     }
 
+    /** {@inheritDoc} */
+    @Override public MessageFactory messageFactory() {
+        return new GridH2ValueMessageFactory();
+    }
+
     /**
      * Wrapper to store connection and flag is schema set or not.
      */
@@ -1341,6 +1412,23 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         }
     }
 
+    /** {@inheritDoc} */
+    @Override public boolean isSqlType(Class<?> cls) {
+        switch (DBTypeEnum.fromClass(cls)) {
+            case OTHER:
+            case ARRAY:
+                return false;
+
+            default:
+                return true;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isGeometryClass(Class<?> cls) {
+        return DataType.isGeometryClass(cls);
+    }
+
     /**
      * Enum that helps to map java types to database types.
      */
@@ -1551,7 +1639,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
             if (type().valueClass() == String.class) {
                 try {
-                    luceneIdx = new GridLuceneIndex(ctx, marshaller, schema.offheap, schema.spaceName, type, true);
+                    luceneIdx = new GridLuceneIndex(ctx, schema.offheap, schema.spaceName, type);
                 }
                 catch (IgniteCheckedException e1) {
                     throw new IgniteException(e1);
@@ -1564,7 +1652,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
                 if (idx.type() == FULLTEXT) {
                     try {
-                        luceneIdx = new GridLuceneIndex(ctx, marshaller, schema.offheap, schema.spaceName, type, true);
+                        luceneIdx = new GridLuceneIndex(ctx, schema.offheap, schema.spaceName, type);
                     }
                     catch (IgniteCheckedException e1) {
                         throw new IgniteException(e1);
@@ -1907,7 +1995,75 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         }
 
         /** {@inheritDoc} */
-        @Override public GridH2Row createRow(Object key, @Nullable Object val, long expirationTime)
+        @Override public Value wrap(Object obj, int type) throws IgniteCheckedException {
+            assert obj != null;
+
+            if (obj instanceof CacheObject) { // Handle cache object.
+                CacheObject co = (CacheObject)obj;
+
+                if (type == Value.JAVA_OBJECT)
+                    return new GridH2ValueCacheObject(cacheContext(schema.spaceName), co);
+
+                obj = co.value(objectContext(schema.spaceName), false);
+            }
+
+            switch (type) {
+                case Value.BOOLEAN:
+                    return ValueBoolean.get((Boolean)obj);
+                case Value.BYTE:
+                    return ValueByte.get((Byte)obj);
+                case Value.SHORT:
+                    return ValueShort.get((Short)obj);
+                case Value.INT:
+                    return ValueInt.get((Integer)obj);
+                case Value.FLOAT:
+                    return ValueFloat.get((Float)obj);
+                case Value.LONG:
+                    return ValueLong.get((Long)obj);
+                case Value.DOUBLE:
+                    return ValueDouble.get((Double)obj);
+                case Value.UUID:
+                    UUID uuid = (UUID)obj;
+                    return ValueUuid.get(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
+                case Value.DATE:
+                    return ValueDate.get((Date)obj);
+                case Value.TIME:
+                    return ValueTime.get((Time)obj);
+                case Value.TIMESTAMP:
+                    if (obj instanceof java.util.Date && !(obj instanceof Timestamp))
+                        obj = new Timestamp(((java.util.Date) obj).getTime());
+
+                    return GridH2Utils.toValueTimestamp((Timestamp)obj);
+                case Value.DECIMAL:
+                    return ValueDecimal.get((BigDecimal)obj);
+                case Value.STRING:
+                    return ValueString.get(obj.toString());
+                case Value.BYTES:
+                    return ValueBytes.get((byte[])obj);
+                case Value.JAVA_OBJECT:
+                    return ValueJavaObject.getNoCopy(obj, null, null);
+                case Value.ARRAY:
+                    Object[] arr = (Object[])obj;
+
+                    Value[] valArr = new Value[arr.length];
+
+                    for (int i = 0; i < arr.length; i++) {
+                        Object o = arr[i];
+
+                        valArr[i] = o == null ? ValueNull.INSTANCE : wrap(o, DataType.getTypeFromClass(o.getClass()));
+                    }
+
+                    return ValueArray.get(valArr);
+
+                case Value.GEOMETRY:
+                    return ValueGeometry.getFromGeometry(obj);
+            }
+
+            throw new IgniteCheckedException("Failed to wrap value[type=" + type + ", value=" + obj + "]");
+        }
+
+        /** {@inheritDoc} */
+        @Override public GridH2Row createRow(CacheObject key, @Nullable CacheObject val, long expirationTime)
             throws IgniteCheckedException {
             try {
                 if (val == null) // Only can happen for remove operation, can create simple search row.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2AbstractKeyValueRow.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2AbstractKeyValueRow.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2AbstractKeyValueRow.java
index 4a0809a..6e95710 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2AbstractKeyValueRow.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2AbstractKeyValueRow.java
@@ -20,17 +20,14 @@ package org.apache.ignite.internal.processors.query.h2.opt;
 import org.apache.ignite.*;
 import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.spi.*;
 import org.h2.message.*;
 import org.h2.result.*;
 import org.h2.value.*;
 import org.jetbrains.annotations.*;
 
 import java.lang.ref.*;
-import java.math.*;
-import java.sql.Date;
 import java.sql.*;
-import java.util.*;
+import java.util.concurrent.*;
 
 /**
  * Table row implementation based on {@link GridQueryTypeDescriptor}.
@@ -61,12 +58,16 @@ public abstract class GridH2AbstractKeyValueRow extends GridH2Row {
      * @param val Value.
      * @param valType Value type.
      * @param expirationTime Expiration time.
-     * @throws IgniteSpiException If failed.
+     * @throws IgniteCheckedException If failed.
      */
     protected GridH2AbstractKeyValueRow(GridH2RowDescriptor desc, Object key, int keyType, @Nullable Object val,
-        int valType, long expirationTime) throws IgniteSpiException {
-        super(wrap(key, keyType),
-            val == null ? null : wrap(val, valType)); // We remove by key only, so value can be null here.
+        int valType, long expirationTime) throws IgniteCheckedException {
+        super(null, null);
+
+        setValue(KEY_COL, desc.wrap(key, keyType));
+
+        if (val != null) // We remove by key only, so value can be null here.
+            setValue(VAL_COL, desc.wrap(val, valType));
 
         this.desc = desc;
         this.expirationTime = expirationTime;
@@ -84,72 +85,6 @@ public abstract class GridH2AbstractKeyValueRow extends GridH2Row {
     }
 
     /**
-     * Wraps object to respective {@link Value}.
-     *
-     * @param obj Object.
-     * @param type Value type.
-     * @return Value.
-     * @throws IgniteSpiException If failed.
-     */
-    public static Value wrap(Object obj, int type) throws IgniteSpiException {
-        assert obj != null;
-
-        switch (type) {
-            case Value.BOOLEAN:
-                return ValueBoolean.get((Boolean)obj);
-            case Value.BYTE:
-                return ValueByte.get((Byte)obj);
-            case Value.SHORT:
-                return ValueShort.get((Short)obj);
-            case Value.INT:
-                return ValueInt.get((Integer)obj);
-            case Value.FLOAT:
-                return ValueFloat.get((Float)obj);
-            case Value.LONG:
-                return ValueLong.get((Long)obj);
-            case Value.DOUBLE:
-                return ValueDouble.get((Double)obj);
-            case Value.UUID:
-                UUID uuid = (UUID)obj;
-                return ValueUuid.get(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
-            case Value.DATE:
-                return ValueDate.get((Date)obj);
-            case Value.TIME:
-                return ValueTime.get((Time)obj);
-            case Value.TIMESTAMP:
-                if (obj instanceof java.util.Date && !(obj instanceof Timestamp))
-                    obj = new Timestamp(((java.util.Date) obj).getTime());
-
-                return GridH2Utils.toValueTimestamp((Timestamp)obj);
-            case Value.DECIMAL:
-                return ValueDecimal.get((BigDecimal)obj);
-            case Value.STRING:
-                return ValueString.get(obj.toString());
-            case Value.BYTES:
-                return ValueBytes.get((byte[])obj);
-            case Value.JAVA_OBJECT:
-                return ValueJavaObject.getNoCopy(obj, null, null);
-            case Value.ARRAY:
-                Object[] arr = (Object[])obj;
-
-                Value[] valArr = new Value[arr.length];
-
-                for (int i = 0; i < arr.length; i++) {
-                    Object o = arr[i];
-
-                    valArr[i] = o == null ? ValueNull.INSTANCE : wrap(o, DataType.getTypeFromClass(o.getClass()));
-                }
-
-                return ValueArray.get(valArr);
-
-            case Value.GEOMETRY:
-                return ValueGeometry.getFromGeometry(obj);
-        }
-
-        throw new IgniteSpiException("Failed to wrap value[type=" + type + ", value=" + obj + "]");
-    }
-
-    /**
      * @return Expiration time of respective cache entry.
      */
     public long expirationTime() {
@@ -164,7 +99,7 @@ public abstract class GridH2AbstractKeyValueRow extends GridH2Row {
     /**
      * Should be called to remove reference on value.
      *
-     * @throws IgniteSpiException If failed.
+     * @throws IgniteCheckedException If failed.
      */
     public synchronized void onSwap() throws IgniteCheckedException {
         setValue(VAL_COL, null);
@@ -178,7 +113,7 @@ public abstract class GridH2AbstractKeyValueRow extends GridH2Row {
      * @throws IgniteCheckedException If failed.
      */
     public synchronized void onUnswap(Object val, boolean beforeRmv) throws IgniteCheckedException {
-        setValue(VAL_COL, wrap(val, desc.valueType()));
+        setValue(VAL_COL, desc.wrap(val, desc.valueType()));
 
         notifyAll();
     }
@@ -203,20 +138,27 @@ public abstract class GridH2AbstractKeyValueRow extends GridH2Row {
     }
 
     /**
-     * @param attempt Attempt.
+     * @param waitTime Time to await for value unswap.
      * @return Synchronized value.
      */
-    protected synchronized Value syncValue(int attempt) {
+    protected synchronized Value syncValue(long waitTime) {
         Value v = peekValue(VAL_COL);
 
-        if (v == null && attempt != 0) {
+        while (v == null && waitTime > 0) {
+            long start = System.nanoTime(); // This call must be quite rare, so performance is not a concern.
+
             try {
-                wait(attempt);
+                wait(waitTime); // Wait for value arrival to allow other threads to make a progress.
             }
             catch (InterruptedException e) {
                 throw new IgniteInterruptedException(e);
             }
 
+            long t = System.nanoTime() - start;
+
+            if (t > 0)
+                waitTime -= TimeUnit.NANOSECONDS.toMillis(t);
+
             v = peekValue(VAL_COL);
         }
 
@@ -258,7 +200,7 @@ public abstract class GridH2AbstractKeyValueRow extends GridH2Row {
                         Object valObj = desc.readFromSwap(k);
 
                         if (valObj != null) {
-                            Value upd = wrap(valObj, desc.valueType());
+                            Value upd = desc.wrap(valObj, desc.valueType());
 
                             v = updateWeakValue(upd);
 
@@ -277,7 +219,7 @@ public abstract class GridH2AbstractKeyValueRow extends GridH2Row {
 
                     if (start == 0)
                         start = U.currentTimeMillis();
-                    else if (U.currentTimeMillis() - start > 15_000) // Loop for at most 15 seconds.
+                    else if (U.currentTimeMillis() - start > 60_000) // Loop for at most 60 seconds.
                         throw new IgniteException("Failed to get value for key: " + k +
                             ". This can happen due to a long GC pause.");
                 }
@@ -317,9 +259,9 @@ public abstract class GridH2AbstractKeyValueRow extends GridH2Row {
             return ValueNull.INSTANCE;
 
         try {
-            return wrap(res, desc.fieldType(col));
+            return desc.wrap(res, desc.fieldType(col));
         }
-        catch (IgniteSpiException e) {
+        catch (IgniteCheckedException e) {
             throw DbException.convert(e);
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2KeyValueRowOffheap.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2KeyValueRowOffheap.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2KeyValueRowOffheap.java
index 9c2c1b2..f89591a 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2KeyValueRowOffheap.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2KeyValueRowOffheap.java
@@ -21,7 +21,6 @@ import org.apache.ignite.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.offheap.unsafe.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.spi.*;
 import org.h2.store.*;
 import org.h2.value.*;
 import org.jetbrains.annotations.*;
@@ -87,10 +86,10 @@ public class GridH2KeyValueRowOffheap extends GridH2AbstractKeyValueRow {
      * @param val Value.
      * @param valType Value type.
      * @param expirationTime Expiration time.
-     * @throws IgniteSpiException If failed.
+     * @throws IgniteCheckedException If failed.
      */
     public GridH2KeyValueRowOffheap(GridH2RowDescriptor desc, Object key, int keyType, @Nullable Object val, int valType,
-        long expirationTime) throws IgniteSpiException {
+        long expirationTime) throws IgniteCheckedException {
         super(desc, key, keyType, val, valType, expirationTime);
     }
 
@@ -247,7 +246,7 @@ public class GridH2KeyValueRowOffheap extends GridH2AbstractKeyValueRow {
             Value v = peekValue(VAL_COL);
 
             if (v == null) {
-                setValue(VAL_COL, wrap(val, desc.valueType()));
+                setValue(VAL_COL, desc.wrap(val, desc.valueType()));
 
                 v = peekValue(VAL_COL);
             }
@@ -273,8 +272,8 @@ public class GridH2KeyValueRowOffheap extends GridH2AbstractKeyValueRow {
     }
 
     /** {@inheritDoc} */
-    @Override protected Value syncValue(int attempt) {
-        Value v = super.syncValue(attempt);
+    @Override protected Value syncValue(long waitTime) {
+        Value v = super.syncValue(waitTime);
 
         if (v != null)
             return v;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2KeyValueRowOnheap.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2KeyValueRowOnheap.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2KeyValueRowOnheap.java
index e998d9b..ee7c79e 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2KeyValueRowOnheap.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2KeyValueRowOnheap.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.internal.processors.query.h2.opt;
 
 
-import org.apache.ignite.spi.*;
+import org.apache.ignite.*;
 import org.h2.value.*;
 import org.jetbrains.annotations.*;
 
@@ -35,10 +35,10 @@ public class GridH2KeyValueRowOnheap extends GridH2AbstractKeyValueRow {
      * @param val Value.
      * @param valType Value type.
      * @param expirationTime Expiration time.
-     * @throws IgniteSpiException If failed.
+     * @throws IgniteCheckedException If failed.
      */
     public GridH2KeyValueRowOnheap(GridH2RowDescriptor desc, Object key, int keyType, @Nullable Object val, int valType,
-        long expirationTime) throws IgniteSpiException {
+        long expirationTime) throws IgniteCheckedException {
         super(desc, key, keyType, val, valType, expirationTime);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
index c5f9551..cd65ab3 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
@@ -18,8 +18,10 @@
 package org.apache.ignite.internal.processors.query.h2.opt;
 
 import org.apache.ignite.*;
+import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.query.h2.*;
 import org.apache.ignite.internal.util.offheap.unsafe.*;
+import org.h2.value.*;
 import org.jetbrains.annotations.*;
 
 /**
@@ -40,7 +42,7 @@ public interface GridH2RowDescriptor extends GridOffHeapSmartPointerFactory<Grid
      * @return Row.
      * @throws IgniteCheckedException If failed.
      */
-    public GridH2Row createRow(Object key, @Nullable Object val, long expirationTime)
+    public GridH2Row createRow(CacheObject key, @Nullable CacheObject val, long expirationTime)
         throws IgniteCheckedException;
 
     /**
@@ -97,4 +99,14 @@ public interface GridH2RowDescriptor extends GridOffHeapSmartPointerFactory<Grid
      * @return Guard.
      */
     public GridUnsafeGuard guard();
+
+    /**
+     * Wraps object to respective {@link Value}.
+     *
+     * @param o Object.
+     * @param type Value type.
+     * @return Value.
+     * @throws IgniteCheckedException If failed.
+     */
+    public Value wrap(Object o, int type) throws IgniteCheckedException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 62b3b5e..92991af 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
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.query.h2.opt;
 
 import org.apache.ignite.*;
+import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.util.offheap.unsafe.*;
 import org.h2.api.*;
 import org.h2.command.ddl.*;
@@ -105,7 +106,7 @@ public class GridH2Table extends TableBase {
      * @return {@code true} If row was found.
      * @throws IgniteCheckedException If failed.
      */
-    public boolean onSwap(Object key) throws IgniteCheckedException {
+    public boolean onSwap(CacheObject key) throws IgniteCheckedException {
         return onSwapUnswap(key, null);
     }
 
@@ -117,7 +118,7 @@ public class GridH2Table extends TableBase {
      * @return {@code true} If row was found.
      * @throws IgniteCheckedException If failed.
      */
-    public boolean onUnswap(Object key, Object val) throws IgniteCheckedException {
+    public boolean onUnswap(CacheObject key, CacheObject val) throws IgniteCheckedException {
         assert val != null : "Key=" + key;
 
         return onSwapUnswap(key, val);
@@ -132,7 +133,7 @@ public class GridH2Table extends TableBase {
      * @throws IgniteCheckedException If failed.
      */
     @SuppressWarnings("LockAcquiredButNotSafelyReleased")
-    private boolean onSwapUnswap(Object key, @Nullable Object val) throws IgniteCheckedException {
+    private boolean onSwapUnswap(CacheObject key, @Nullable CacheObject val) throws IgniteCheckedException {
         assert key != null;
 
         GridH2TreeIndex pk = pk();
@@ -300,7 +301,8 @@ public class GridH2Table extends TableBase {
      * @return {@code true} If operation succeeded.
      * @throws IgniteCheckedException If failed.
      */
-    public boolean update(Object key, Object val, long expirationTime, boolean rmv) throws IgniteCheckedException {
+    public boolean update(CacheObject key, CacheObject val, long expirationTime, boolean rmv)
+        throws IgniteCheckedException {
         assert desc != null;
 
         GridH2Row row = desc.createRow(key, val, expirationTime);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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
new file mode 100644
index 0000000..0a37674
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
@@ -0,0 +1,191 @@
+/*
+ * 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.opt;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.*;
+import org.h2.message.*;
+import org.h2.util.*;
+import org.h2.value.*;
+
+import java.sql.*;
+
+/**
+ * H2 Value over {@link CacheObject}. Replacement for {@link ValueJavaObject}.
+ */
+public class GridH2ValueCacheObject extends Value {
+    /** */
+    private CacheObject obj;
+
+    /** */
+    private GridCacheContext<?,?> cctx;
+
+    /**
+     * @param cctx Cache context.
+     * @param obj Object.
+     */
+    public GridH2ValueCacheObject(GridCacheContext<?,?> cctx, CacheObject obj) {
+        assert obj != null;
+
+        this.obj = obj;
+        this.cctx = cctx; // Allowed to be null in tests.
+    }
+
+    /**
+     * @return Cache object.
+     */
+    public CacheObject getCacheObject() {
+        return obj;
+    }
+
+    /**
+     * @return Cache context.
+     */
+    public GridCacheContext<?,?> getCacheContext() {
+        return cctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getSQL() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getType() {
+        return Value.JAVA_OBJECT;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getPrecision() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getDisplaySize() {
+        return 64;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getString() {
+        return getObject().toString();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] getBytes() {
+        return Utils.cloneByteArray(getBytesNoCopy());
+    }
+
+    /**
+     * @return Cache object context.
+     */
+    private CacheObjectContext objectContext() {
+        return cctx == null ? null : cctx.cacheObjectContext();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] getBytesNoCopy() {
+        if (obj.type() == CacheObject.TYPE_REGULAR) {
+            // Result must be the same as `marshaller.marshall(obj.value(coctx, false));`
+            try {
+                return obj.valueBytes(objectContext());
+            }
+            catch (IgniteCheckedException e) {
+                throw DbException.convert(e);
+            }
+        }
+
+        // For portables and byte array cache object types.
+        return Utils.serialize(obj.value(objectContext(), false), null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object getObject() {
+        return obj.value(objectContext(), false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
+        prep.setObject(parameterIndex, getObject(), Types.JAVA_OBJECT);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override protected int compareSecure(Value v, CompareMode mode) {
+        Object o1 = getObject();
+        Object o2 = v.getObject();
+
+        boolean o1Comparable = o1 instanceof Comparable;
+        boolean o2Comparable = o2 instanceof Comparable;
+
+        if (o1Comparable && o2Comparable &&
+            Utils.haveCommonComparableSuperclass(o1.getClass(), o2.getClass())) {
+            Comparable<Object> c1 = (Comparable<Object>)o1;
+
+            return c1.compareTo(o2);
+        }
+
+        // Group by types.
+        if (o1.getClass() != o2.getClass()) {
+            if (o1Comparable != o2Comparable)
+                return o1Comparable ? -1 : 1;
+
+            return o1.getClass().getName().compareTo(o2.getClass().getName());
+        }
+
+        // Compare hash codes.
+        int h1 = hashCode();
+        int h2 = v.hashCode();
+
+        if (h1 == h2) {
+            if (o1.equals(o2))
+                return 0;
+
+            return Utils.compareNotNullSigned(getBytesNoCopy(), v.getBytesNoCopy());
+        }
+
+        return h1 > h2 ? 1 : -1;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return getObject().hashCode();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object other) {
+        if (!(other instanceof Value))
+            return false;
+
+        Value otherVal = (Value)other;
+
+        return otherVal.getType() == Value.JAVA_OBJECT
+            && getObject().equals(otherVal.getObject());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value convertPrecision(long precision, boolean force) {
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getMemory() {
+        return 0;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 c6d597f..f2f11be 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
@@ -19,13 +19,14 @@ package org.apache.ignite.internal.processors.query.h2.opt;
 
 import org.apache.ignite.*;
 import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.offheap.unsafe.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
-import org.apache.ignite.marshaller.*;
 import org.apache.ignite.spi.indexing.*;
 import org.apache.lucene.analysis.standard.*;
 import org.apache.lucene.document.*;
@@ -33,6 +34,7 @@ import org.apache.lucene.index.*;
 import org.apache.lucene.queryParser.*;
 import org.apache.lucene.search.*;
 import org.apache.lucene.util.*;
+import org.h2.util.*;
 import org.jetbrains.annotations.*;
 
 import java.io.*;
@@ -55,9 +57,6 @@ public class GridLuceneIndex implements Closeable {
     public static final String EXPIRATION_TIME_FIELD_NAME = "_gg_expires__";
 
     /** */
-    private final Marshaller marshaller;
-
-    /** */
     private final String spaceName;
 
     /** */
@@ -70,9 +69,6 @@ public class GridLuceneIndex implements Closeable {
     private final String[] idxdFields;
 
     /** */
-    private final boolean storeVal;
-
-    /** */
     private final AtomicLong updateCntr = new GridAtomicLong();
 
     /** */
@@ -85,20 +81,16 @@ public class GridLuceneIndex implements Closeable {
      * Constructor.
      *
      * @param ctx Kernal context.
-     * @param marshaller Indexing marshaller.
      * @param mem Unsafe memory.
      * @param spaceName Space name.
      * @param type Type descriptor.
-     * @param storeVal Store value in index.
      * @throws IgniteCheckedException If failed.
      */
-    public GridLuceneIndex(GridKernalContext ctx, Marshaller marshaller, @Nullable GridUnsafeMemory mem,
-        @Nullable String spaceName, GridQueryTypeDescriptor type, boolean storeVal) throws IgniteCheckedException {
+    public GridLuceneIndex(GridKernalContext ctx, @Nullable GridUnsafeMemory mem,
+        @Nullable String spaceName, GridQueryTypeDescriptor type) throws IgniteCheckedException {
         this.ctx = ctx;
-        this.marshaller = marshaller;
         this.spaceName = spaceName;
         this.type = type;
-        this.storeVal = storeVal;
 
         dir = new GridLuceneDirectory(mem == null ? new GridUnsafeMemory(0) : mem);
 
@@ -137,15 +129,30 @@ public class GridLuceneIndex implements Closeable {
     }
 
     /**
+     * @return Cache object context.
+     */
+    private CacheObjectContext objectContext() {
+        if (ctx == null)
+            return null;
+
+        return ctx.cache().internalCache(spaceName).context().cacheObjectContext();
+    }
+
+    /**
      * Stores given data in this fulltext index.
      *
-     * @param key Key.
-     * @param val Value.
+     * @param k Key.
+     * @param v Value.
      * @param ver Version.
      * @param expires Expiration time.
      * @throws IgniteCheckedException If failed.
      */
-    public void store(Object key, Object val, byte[] ver, long expires) throws IgniteCheckedException {
+    public void store(CacheObject k, CacheObject v, byte[] ver, long expires) throws IgniteCheckedException {
+        CacheObjectContext coctx = objectContext();
+
+        Object key = k.value(coctx, false);
+        Object val = v.value(coctx, false);
+
         Document doc = new Document();
 
         boolean stringsFound = false;
@@ -166,7 +173,7 @@ public class GridLuceneIndex implements Closeable {
             }
         }
 
-        String keyStr = org.apache.commons.codec.binary.Base64.encodeBase64String(marshaller.marshal(key));
+        String keyStr = org.apache.commons.codec.binary.Base64.encodeBase64String(k.valueBytes(coctx));
 
         try {
             // Delete first to avoid duplicates.
@@ -177,8 +184,8 @@ public class GridLuceneIndex implements Closeable {
 
             doc.add(new Field(KEY_FIELD_NAME, keyStr, Field.Store.YES, Field.Index.NOT_ANALYZED));
 
-            if (storeVal && type.valueClass() != String.class)
-                doc.add(new Field(VAL_FIELD_NAME, marshaller.marshal(val)));
+            if (type.valueClass() != String.class)
+                doc.add(new Field(VAL_FIELD_NAME, v.valueBytes(coctx)));
 
             doc.add(new Field(VER_FIELD_NAME, ver));
 
@@ -201,9 +208,10 @@ public class GridLuceneIndex implements Closeable {
      * @param key Key.
      * @throws IgniteCheckedException If failed.
      */
-    public void remove(Object key) throws IgniteCheckedException {
+    public void remove(CacheObject key) throws IgniteCheckedException {
         try {
-            writer.deleteDocuments(new Term(KEY_FIELD_NAME, org.apache.commons.codec.binary.Base64.encodeBase64String(marshaller.marshal(key))));
+            writer.deleteDocuments(new Term(KEY_FIELD_NAME,
+                org.apache.commons.codec.binary.Base64.encodeBase64String(key.valueBytes(objectContext()))));
         }
         catch (IOException e) {
             throw new IgniteCheckedException(e);
@@ -297,6 +305,9 @@ public class GridLuceneIndex implements Closeable {
         /** */
         private IgniteBiTuple<K, V> curr;
 
+        /** */
+        private CacheObjectContext coctx;
+
         /**
          * Constructor.
          *
@@ -313,6 +324,8 @@ public class GridLuceneIndex implements Closeable {
             this.docs = docs;
             this.filters = filters;
 
+            coctx = objectContext();
+
             findNext();
         }
 
@@ -328,10 +341,25 @@ public class GridLuceneIndex implements Closeable {
         }
 
         /**
+         * @param bytes Bytes.
+         * @param ldr Class loader.
+         * @return Object.
+         * @throws IgniteCheckedException If failed.
+         */
+        @SuppressWarnings("unchecked")
+        private <Z> Z unmarshall(byte[] bytes, ClassLoader ldr) throws IgniteCheckedException {
+            if (coctx == null) // For tests.
+                return (Z)Utils.deserialize(bytes, null);
+
+            return (Z)coctx.processor().unmarshal(coctx, bytes, ldr);
+        }
+
+        /**
          * Finds next element.
          *
          * @throws IgniteCheckedException If failed.
          */
+        @SuppressWarnings("unchecked")
         private void findNext() throws IgniteCheckedException {
             curr = null;
 
@@ -345,26 +373,22 @@ public class GridLuceneIndex implements Closeable {
                     throw new IgniteCheckedException(e);
                 }
 
-                String keyStr = doc.get(KEY_FIELD_NAME);
-
                 ClassLoader ldr = null;
 
                 if (ctx != null && ctx.deploy().enabled())
                     ldr = ctx.cache().internalCache(spaceName).context().deploy().globalLoader();
 
-                K k = marshaller.unmarshal(org.apache.commons.codec.binary.Base64.decodeBase64(keyStr), ldr);
+                K k = unmarshall(org.apache.commons.codec.binary.Base64.decodeBase64(doc.get(KEY_FIELD_NAME)), ldr);
 
-                byte[] valBytes = doc.getBinaryValue(VAL_FIELD_NAME);
+                V v = type.valueClass() == String.class ?
+                    (V)doc.get(VAL_STR_FIELD_NAME) :
+                    this.<V>unmarshall(doc.getBinaryValue(VAL_FIELD_NAME), ldr);
 
-                V v = valBytes != null ? marshaller.<V>unmarshal(valBytes, ldr) :
-                    type.valueClass() == String.class ?
-                    (V)doc.get(VAL_STR_FIELD_NAME): null;
+                assert v != null;
 
                 if (!filter(k, v))
                     continue;
 
-//                byte[] ver = doc.getBinaryValue(VER_FIELD_NAME); TODO rm version
-
                 curr = new IgniteBiTuple<>(k, v);
 
                 break;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperationType.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperationType.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperationType.java
index 7aefbec..a071e73 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperationType.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperationType.java
@@ -131,7 +131,7 @@ public enum GridSqlOperationType {
         @Override public String getSql(GridSqlOperation operation) {
             assert operation.opType().childrenCnt == 2;
 
-            return "(INTERSECTS(" + operation.child(0) + ", " + operation.child(1) + "))";
+            return "(INTERSECTS(" + operation.child(0).getSQL() + ", " + operation.child(1).getSQL() + "))";
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuery.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuery.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuery.java
index c40632f..207588e 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuery.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuery.java
@@ -37,6 +37,26 @@ public abstract class GridSqlQuery implements Cloneable {
     /** */
     protected GridSqlElement limit;
 
+    /** */
+    private boolean explain;
+
+    /**
+     * @param explain Explain.
+     * @return {@code this}.
+     */
+    public GridSqlQuery explain(boolean explain) {
+        this.explain = explain;
+
+        return this;
+    }
+
+    /**
+     * @return {@code true} If explain.
+     */
+    public boolean explain() {
+        return explain;
+    }
+
     /**
      * @return Offset.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
index 62ec72f..74e4748 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
@@ -158,6 +158,9 @@ public class GridSqlQueryParser {
     private static final Getter<SelectUnion, SortOrder> UNION_SORT = getter(SelectUnion.class, "sort");
 
     /** */
+    private static final Getter<Explain, Prepared> EXPLAIN_COMMAND = getter(Explain.class, "command");
+
+    /** */
     private static volatile Getter<Command,Prepared> prepared;
 
     /** */
@@ -182,7 +185,7 @@ public class GridSqlQueryParser {
 
         Prepared statement = p.get(cmd);
 
-        return new GridSqlQueryParser().parse((Query)statement);
+        return new GridSqlQueryParser().parse(statement);
     }
 
     /**
@@ -321,13 +324,16 @@ public class GridSqlQueryParser {
     /**
      * @param qry Select.
      */
-    public GridSqlQuery parse(Query qry) {
+    public GridSqlQuery parse(Prepared qry) {
         if (qry instanceof Select)
             return parse((Select)qry);
 
         if (qry instanceof SelectUnion)
             return parse((SelectUnion)qry);
 
+        if (qry instanceof Explain)
+            return parse(EXPLAIN_COMMAND.get((Explain)qry)).explain(true);
+
         throw new UnsupportedOperationException("Unknown query type: " + qry);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
index 73d7751..b1d8913 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
@@ -78,7 +78,7 @@ public class GridSqlQuerySplitter {
         if (params == null)
             params = GridCacheSqlQuery.EMPTY_PARAMS;
 
-        GridSqlQuery qry0 = GridSqlQueryParser.parse(stmt);
+        final GridSqlQuery qry0 = GridSqlQueryParser.parse(stmt);
 
         GridSqlSelect srcQry;
 
@@ -87,6 +87,8 @@ public class GridSqlQuerySplitter {
         else { // Handle UNION.
             srcQry = new GridSqlSelect().from(new GridSqlSubquery(qry0));
 
+            srcQry.explain(qry0.explain());
+
             GridSqlSelect left = leftest(qry0);
 
             int c = 0;
@@ -127,7 +129,10 @@ public class GridSqlQuerySplitter {
 
         // Create map and reduce queries.
         GridSqlSelect mapQry = srcQry.clone();
-        GridSqlSelect rdcQry = new GridSqlSelect().from(new GridSqlFunction("PUBLIC", TABLE_FUNC_NAME)); // table(mergeTable)); TODO
+
+        mapQry.explain(false);
+
+        GridSqlSelect rdcQry = new GridSqlSelect().from(new GridSqlFunction(null, TABLE_FUNC_NAME)); // table(mergeTable)); TODO
 
         // Split all select expressions into map-reduce parts.
         List<GridSqlElement> mapExps = F.addAll(
@@ -213,6 +218,8 @@ public class GridSqlQuerySplitter {
         res.addMapQuery(mergeTable, mapQry.getSQL(),
             findParams(mapQry, params, new ArrayList<>(params.length)).toArray());
 
+        res.explain(qry0.explain());
+
         return res;
     }
 
@@ -281,6 +288,10 @@ public class GridSqlQuerySplitter {
             while (target.size() < idx)
                 target.add(null);
 
+            if (params.length <= idx)
+                throw new IgniteException("Invalid number of query parameters. " +
+                    "Cannot find " + idx + " parameter.");
+
             Object param = params[idx];
 
             if (idx == target.size())

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
index 0786eac..9972bba 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
@@ -68,7 +68,7 @@ public class GridSqlSelect extends GridSqlQuery {
 
     /** {@inheritDoc} */
     @Override public String getSQL() {
-        StatementBuilder buff = new StatementBuilder("SELECT");
+        StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN SELECT" : "SELECT");
 
         if (distinct)
             buff.append(" DISTINCT");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
index 23c18ed..96beb6b 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
@@ -47,7 +47,7 @@ public class GridSqlUnion extends GridSqlQuery {
 
     /** {@inheritDoc} */
     @Override public String getSQL() {
-        StatementBuilder buff = new StatementBuilder();
+        StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN \n" : "");
 
         buff.append('(').append(left.getSQL()).append(')');
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 918a541..f15a2da 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
@@ -30,6 +30,8 @@ import org.apache.ignite.internal.processors.query.h2.twostep.messages.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.marshaller.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.h2.jdbc.*;
 import org.h2.result.*;
 import org.h2.store.*;
@@ -44,6 +46,7 @@ import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
 
 import static org.apache.ignite.events.EventType.*;
+import static org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessageFactory.*;
 
 /**
  * Map query executor.
@@ -138,6 +141,9 @@ public class GridMapQueryExecutor {
 
             ClusterNode node = ctx.discovery().node(nodeId);
 
+            if (node == null)
+                return; // Node left, ignore.
+
             boolean processed = true;
 
             if (msg instanceof GridQueryRequest)
@@ -203,7 +209,14 @@ public class GridMapQueryExecutor {
         Collection<GridCacheSqlQuery> qrys;
 
         try {
-            qrys = req.queries(ctx.config().getMarshaller());
+            qrys = req.queries();
+
+            if (!node.isLocal()) {
+                Marshaller m = ctx.config().getMarshaller();
+
+                for (GridCacheSqlQuery qry : qrys)
+                    qry.unmarshallParams(m);
+            }
         }
         catch (IgniteCheckedException e) {
             throw new IgniteException(e);
@@ -344,7 +357,10 @@ public class GridMapQueryExecutor {
             boolean loc = node.isLocal();
 
             GridQueryNextPageResponse msg = new GridQueryNextPageResponse(qr.qryReqId, qry, page,
-                page == 0 ? res.rowCount : -1, loc ? null : marshallRows(rows), loc ? rows : null);
+                page == 0 ? res.rowCount : -1 ,
+                res.cols,
+                loc ? null : toMessages(rows, new ArrayList<Message>(res.cols)),
+                loc ? rows : null);
 
             if (loc)
                 h2.reduceQueryExecutor().onMessage(ctx.localNodeId(), msg);
@@ -510,6 +526,9 @@ public class GridMapQueryExecutor {
         private final UUID qrySrcNodeId;
 
         /** */
+        private final int cols;
+
+        /** */
         private int page;
 
         /** */
@@ -538,6 +557,7 @@ public class GridMapQueryExecutor {
             }
 
             rowCount = res.getRowCount();
+            cols = res.getVisibleColumnCount();
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java
index 407341e..9136821 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java
@@ -96,14 +96,14 @@ public abstract class GridMergeIndex extends BaseIndex {
      * @param nodeId Node ID.
      */
     public void fail(UUID nodeId) {
-        addPage0(new GridResultPage(nodeId, null, false));
+        addPage0(new GridResultPage(null, nodeId, null, false));
     }
 
     /**
      * @param page Page.
      */
     public final void addPage(GridResultPage page) {
-        int pageRowsCnt = page.rows().size();
+        int pageRowsCnt = page.rowsInPage();
 
         if (pageRowsCnt != 0)
             addPage0(page);
@@ -137,7 +137,7 @@ public abstract class GridMergeIndex extends BaseIndex {
             if (last)
                 last = lastSubmitted.compareAndSet(false, true);
 
-            addPage0(new GridResultPage(page.source(), null, last));
+            addPage0(new GridResultPage(null, page.source(), null, last));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexUnsorted.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexUnsorted.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexUnsorted.java
index 93c9482..76a52e9 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexUnsorted.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexUnsorted.java
@@ -44,7 +44,7 @@ public class GridMergeIndexUnsorted extends GridMergeIndex {
 
     /** {@inheritDoc} */
     @Override protected void addPage0(GridResultPage page) {
-        if (!page.rows().isEmpty() || page.isLast() || queue.isEmpty())
+        if (page.rowsInPage() != 0 || page.isLast() || queue.isEmpty())
             queue.add(page);
     }
 
@@ -75,7 +75,7 @@ public class GridMergeIndexUnsorted extends GridMergeIndex {
 
                     fetchNextPage(page);
 
-                    iter = page.rows().iterator();
+                    iter = page.rows();
                 }
 
                 return true;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 7f42e0d..50c30a5 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
@@ -28,12 +28,13 @@ import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.cache.query.*;
 import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.processors.query.h2.*;
-import org.apache.ignite.internal.processors.query.h2.sql.*;
 import org.apache.ignite.internal.processors.query.h2.twostep.messages.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.marshaller.*;
 import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.command.*;
 import org.h2.command.ddl.*;
 import org.h2.command.dml.Query;
 import org.h2.engine.*;
@@ -151,9 +152,6 @@ public class GridReduceQueryExecutor {
                 }
             }
         }, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
-
-        h2.executeStatement("PUBLIC", "CREATE ALIAS " + GridSqlQuerySplitter.TABLE_FUNC_NAME +
-            " NOBUFFER FOR \"" + GridReduceQueryExecutor.class.getName() + ".mergeTableFunction\"");
     }
 
     /**
@@ -166,6 +164,9 @@ public class GridReduceQueryExecutor {
 
             ClusterNode node = ctx.discovery().node(nodeId);
 
+            if (node == null)
+                return; // Node left, ignore.
+
             boolean processed = true;
 
             if (msg instanceof GridQueryNextPageResponse)
@@ -230,7 +231,7 @@ public class GridReduceQueryExecutor {
         GridResultPage page;
 
         try {
-            page = new GridResultPage(node.id(), msg, false) {
+            page = new GridResultPage(ctx, node.id(), msg, false) {
                 @Override public void fetchNextPage() {
                     if (r.rmtErr != null)
                         throw new CacheException("Next page fetch failed.", r.rmtErr);
@@ -279,15 +280,16 @@ public class GridReduceQueryExecutor {
 
         String space = cctx.name();
 
-        r.conn = h2.connectionForSpace(space);
+        r.conn = (JdbcConnection)h2.connectionForSpace(space);
 
-        // TODO Add topology version.
+        // TODO    Add topology version.
         ClusterGroup dataNodes = ctx.grid().cluster().forDataNodes(space);
 
-        if (cctx.isReplicated()) {
-            assert dataNodes.node(ctx.localNodeId()) == null : "We must be on a client node.";
+        if (cctx.isReplicated() || qry.explain()) {
+            assert qry.explain() || dataNodes.node(ctx.localNodeId()) == null : "We must be on a client node.";
 
-            dataNodes = dataNodes.forRandom(); // Select random data node to run query on a replicated data.
+            // Select random data node to run query on a replicated data or get EXPLAIN PLAN from a single node.
+            dataNodes = dataNodes.forRandom();
         }
 
         final Collection<ClusterNode> nodes = dataNodes.nodes();
@@ -296,7 +298,7 @@ public class GridReduceQueryExecutor {
             GridMergeTable tbl;
 
             try {
-                tbl = createFunctionTable((JdbcConnection)r.conn, mapQry); // createTable(r.conn, mapQry); TODO
+                tbl = createFunctionTable(r.conn, mapQry, qry.explain()); // createTable(r.conn, mapQry); TODO
             }
             catch (IgniteCheckedException e) {
                 throw new IgniteException(e);
@@ -317,14 +319,32 @@ public class GridReduceQueryExecutor {
         runs.put(qryReqId, r);
 
         try {
-            send(nodes, new GridQueryRequest(qryReqId, r.pageSize, space, qry.mapQueries(),
-                ctx.config().getMarshaller().marshal(qry.mapQueries())));
+            Collection<GridCacheSqlQuery> mapQrys = qry.mapQueries();
+
+            if (qry.explain()) {
+                mapQrys = new ArrayList<>(qry.mapQueries().size());
+
+                for (GridCacheSqlQuery mapQry : qry.mapQueries())
+                    mapQrys.add(new GridCacheSqlQuery(mapQry.alias(), "EXPLAIN " + mapQry.query(), mapQry.parameters()));
+            }
+
+            if (nodes.size() != 1 || !F.first(nodes).isLocal()) { // Marshall params for remotes.
+                Marshaller m = ctx.config().getMarshaller();
+
+                for (GridCacheSqlQuery mapQry : mapQrys)
+                    mapQry.marshallParams(m);
+            }
+
+            send(nodes, new GridQueryRequest(qryReqId, r.pageSize, space, mapQrys));
 
             r.latch.await();
 
             if (r.rmtErr != null)
                 throw new CacheException("Failed to run map query remotely.", r.rmtErr);
 
+            if (qry.explain())
+                return explainPlan(r.conn, space, qry);
+
             GridCacheSqlQuery rdc = qry.reduceQuery();
 
             final ResultSet res = h2.executeSqlQueryWithTimer(space, r.conn, rdc.query(), F.asList(rdc.parameters()));
@@ -355,6 +375,55 @@ public class GridReduceQueryExecutor {
     }
 
     /**
+     * @param c Connection.
+     * @param space Space.
+     * @param qry Query.
+     * @return Cursor for plans.
+     * @throws IgniteCheckedException if failed.
+     */
+    private QueryCursor<List<?>> explainPlan(JdbcConnection c, String space, GridCacheTwoStepQuery qry)
+        throws IgniteCheckedException {
+        List<List<?>> lists = new ArrayList<>();
+
+        for (GridCacheSqlQuery mapQry : qry.mapQueries()) {
+            ResultSet rs = h2.executeSqlQueryWithTimer(space, c, "SELECT PLAN FROM " + mapQry.alias(), null);
+
+            lists.add(F.asList(getPlan(rs)));
+        }
+
+        for (GridCacheSqlQuery mapQry : qry.mapQueries()) {
+            GridMergeTable tbl = createFunctionTable(c, mapQry, false);
+
+            curFunTbl.set(tbl); // Now it will be only a single table.
+        }
+
+        GridCacheSqlQuery rdc = qry.reduceQuery();
+
+        ResultSet rs = h2.executeSqlQueryWithTimer(space, c, "EXPLAIN " + rdc.query(), F.asList(rdc.parameters()));
+
+        lists.add(F.asList(getPlan(rs)));
+
+        return new QueryCursorImpl<>(lists.iterator());
+    }
+
+    /**
+     * @param rs Result set.
+     * @return Plan.
+     * @throws IgniteCheckedException If failed.
+     */
+    private String getPlan(ResultSet rs) throws IgniteCheckedException {
+        try {
+            if (!rs.next())
+                throw new IllegalStateException();
+
+            return rs.getString(1);
+        }
+        catch (SQLException e) {
+            throw new IgniteCheckedException(e);
+        }
+    }
+
+    /**
      * @param nodes Nodes.
      * @param msg Message.
      * @throws IgniteCheckedException If failed.
@@ -495,10 +564,12 @@ public class GridReduceQueryExecutor {
     /**
      * @param conn Connection.
      * @param qry Query.
+     * @param explain Explain.
      * @return Table.
      * @throws IgniteCheckedException
      */
-    private GridMergeTable createFunctionTable(JdbcConnection conn, GridCacheSqlQuery qry) throws IgniteCheckedException {
+    private GridMergeTable createFunctionTable(JdbcConnection conn, GridCacheSqlQuery qry, boolean explain)
+        throws IgniteCheckedException {
         try {
             Session ses = (Session)conn.getSession();
 
@@ -508,17 +579,21 @@ public class GridReduceQueryExecutor {
             data.schema = ses.getDatabase().getSchema(ses.getCurrentSchemaName());
             data.create = true;
 
-            Query prepare = (Query)ses.prepare(qry.query(), false);
+            if (!explain) {
+                Prepared prepare = ses.prepare(qry.query(), false);
 
-            List<org.h2.expression.Parameter> parsedParams = prepare.getParameters();
+                List<org.h2.expression.Parameter> parsedParams = prepare.getParameters();
 
-            for (int i = Math.min(parsedParams.size(), qry.parameters().length); --i >= 0; ) {
-                Object val = qry.parameters()[i];
+                for (int i = Math.min(parsedParams.size(), qry.parameters().length); --i >= 0; ) {
+                    Object val = qry.parameters()[i];
 
-                parsedParams.get(i).setValue(DataType.convertToValue(ses, val, Value.UNKNOWN));
-            }
+                    parsedParams.get(i).setValue(DataType.convertToValue(ses, val, Value.UNKNOWN));
+                }
 
-            data.columns = generateColumnsFromQuery(prepare);
+                data.columns = generateColumnsFromQuery((Query)prepare);
+            }
+            else
+                data.columns = planColumns();
 
             return new GridMergeTable(data);
         }
@@ -530,6 +605,17 @@ public class GridReduceQueryExecutor {
     }
 
     /**
+     * @return Columns.
+     */
+    private static ArrayList<Column> planColumns() {
+        ArrayList<Column> res = new ArrayList<>(1);
+
+        res.add(new Column("PLAN", Value.STRING));
+
+        return res;
+    }
+
+    /**
      * @param conn Connection.
      * @param qry Query.
      * @return Table.
@@ -566,7 +652,7 @@ public class GridReduceQueryExecutor {
         private CountDownLatch latch;
 
         /** */
-        private Connection conn;
+        private JdbcConnection conn;
 
         /** */
         private int pageSize;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridResultPage.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridResultPage.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridResultPage.java
index 5f58b95..9392fd1 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridResultPage.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridResultPage.java
@@ -17,12 +17,18 @@
 
 package org.apache.ignite.internal.processors.query.h2.twostep;
 
+import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.query.h2.twostep.messages.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.h2.value.*;
 
+import javax.cache.*;
 import java.util.*;
 
+import static org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessageFactory.*;
+
 /**
  * Page result.
  */
@@ -34,18 +40,22 @@ public class GridResultPage {
     protected final GridQueryNextPageResponse res;
 
     /** */
-    private final Collection<Value[]> rows;
+    private final int rowsInPage;
 
     /** */
     private final boolean last;
 
+    /** */
+    private Iterator<Value[]> rows;
+
     /**
+     * @param ctx Kernal context.
      * @param src Source.
      * @param res Response.
      * @param last If this is the globally last page.
      */
     @SuppressWarnings("unchecked")
-    public GridResultPage(UUID src, GridQueryNextPageResponse res, boolean last) {
+    public GridResultPage(final GridKernalContext ctx, UUID src, GridQueryNextPageResponse res, boolean last) {
         assert src != null;
 
         this.src = src;
@@ -57,12 +67,53 @@ public class GridResultPage {
 
         // res == null means that it is a terminating dummy page for the given source node ID.
         if (res != null) {
-            Object plainRows = res.plainRows();
+            Collection<?> plainRows = res.plainRows();
+
+            if (plainRows != null) {
+                rowsInPage = plainRows.size();
+
+                rows = (Iterator<Value[]>)plainRows.iterator();
+            }
+            else {
+                final int cols = res.columns();
+
+                rowsInPage = res.values().size() / cols;
+
+                final Iterator<Message> valsIter = res.values().iterator();
+
+                rows = new Iterator<Value[]>() {
+                    /** */
+                    int rowIdx;
+
+                    @Override public boolean hasNext() {
+                        return rowIdx < rowsInPage;
+                    }
+
+                    @Override public Value[] next() {
+                        if (!hasNext())
+                            throw new NoSuchElementException();
+
+                        rowIdx++;
 
-            rows = plainRows != null ? (Collection<Value[]>)plainRows : GridMapQueryExecutor.unmarshallRows(res.rows());
+                        try {
+                            return fillArray(valsIter, new Value[cols], ctx);
+                        }
+                        catch (IgniteCheckedException e) {
+                            throw new CacheException(e);
+                        }
+                    }
+
+                    @Override public void remove() {
+                        throw new UnsupportedOperationException();
+                    }
+                };
+            }
+        }
+        else {
+            rowsInPage = 0;
+
+            rows = Collections.emptyIterator();
         }
-        else
-            rows = Collections.emptySet();
     }
 
     /**
@@ -73,10 +124,23 @@ public class GridResultPage {
     }
 
     /**
+     * @return Number on rows in this page.
+     */
+    public int rowsInPage() {
+        return rowsInPage;
+    }
+
+    /**
      * @return Rows.
      */
-    public Collection<Value[]> rows() {
-        return rows;
+    public Iterator<Value[]> rows() {
+        Iterator<Value[]> r = rows;
+
+        assert r != null;
+
+        rows = null;
+
+        return r;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Array.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Array.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Array.java
new file mode 100644
index 0000000..26fd81d
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Array.java
@@ -0,0 +1,124 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+import java.util.*;
+
+import static org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessageFactory.*;
+
+/**
+ * H2 Array.
+ */
+public class GridH2Array extends GridH2ValueMessage {
+    /** */
+    @GridDirectCollection(Message.class)
+    private Collection<Message> x;
+
+    /**
+     *
+     */
+    public GridH2Array() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     * @throws IgniteCheckedException If failed.
+     */
+    public GridH2Array(Value val) throws IgniteCheckedException {
+        assert val.getType() == Value.ARRAY : val.getType();
+
+        ValueArray arr = (ValueArray)val;
+
+        x = new ArrayList<>(arr.getList().length);
+
+        for (Value v : arr.getList())
+            x.add(toMessage(v));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) throws IgniteCheckedException {
+        return ValueArray.get(fillArray(x.iterator(), new Value[x.size()], ctx));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeCollection("x", x, MessageCollectionItemType.MSG))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readCollection("x", MessageCollectionItemType.MSG);
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -18;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Boolean.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Boolean.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Boolean.java
new file mode 100644
index 0000000..ec4e455
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Boolean.java
@@ -0,0 +1,112 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Boolean.
+ */
+public class GridH2Boolean extends GridH2ValueMessage {
+    /** */
+    private boolean x;
+
+    /**
+     *
+     */
+    public GridH2Boolean() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Boolean(Value val) {
+        assert val.getType() == Value.BOOLEAN : val.getType();
+
+        x = val.getBoolean();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueBoolean.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeBoolean("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readBoolean("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -5;
+    }
+
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Byte.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Byte.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Byte.java
new file mode 100644
index 0000000..e7c8f33
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Byte.java
@@ -0,0 +1,113 @@
+/*
+ * 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.msg;
+
+import org.apache.ignite.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Byte.
+ */
+public class GridH2Byte extends GridH2ValueMessage {
+    /** */
+    private byte x;
+
+    /**
+     *
+     */
+    public GridH2Byte() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Byte(Value val) {
+        assert val.getType() == Value.BYTE : val.getType();
+
+        x = val.getByte();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value(GridKernalContext ctx) {
+        return ValueByte.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByte("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readByte("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -6;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}


[17/24] incubator-ignite git commit: ignite-545: merge from ignite-sprint-6

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java
index c033273..73f86fd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java
@@ -104,8 +104,6 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
      * @param tx Transaction.
      * @param dhtWrites DHT writes.
      * @param nearWrites Near writes.
-     * @param grpLockKey Group lock key if preparing group-lock transaction.
-     * @param partLock {@code True} if group-lock transaction locks partition.
      * @param txNodes Transaction nodes mapping.
      * @param nearXidVer Near transaction ID.
      * @param last {@code True} if this is last prepare request for node.
@@ -118,15 +116,13 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
         GridDhtTxLocalAdapter tx,
         Collection<IgniteTxEntry> dhtWrites,
         Collection<IgniteTxEntry> nearWrites,
-        IgniteTxKey grpLockKey,
-        boolean partLock,
         Map<UUID, Collection<UUID>> txNodes,
         GridCacheVersion nearXidVer,
         boolean last,
         boolean onePhaseCommit,
         UUID subjId,
         int taskNameHash) {
-        super(tx, null, dhtWrites, grpLockKey, partLock, txNodes, onePhaseCommit);
+        super(tx, null, dhtWrites, txNodes, onePhaseCommit);
 
         assert futId != null;
         assert miniId != null;
@@ -337,79 +333,79 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
         }
 
         switch (writer.state()) {
-            case 25:
+            case 23:
                 if (!writer.writeIgniteUuid("futId", futId))
                     return false;
 
                 writer.incrementState();
 
-            case 26:
+            case 24:
                 if (!writer.writeBitSet("invalidateNearEntries", invalidateNearEntries))
                     return false;
 
                 writer.incrementState();
 
-            case 27:
+            case 25:
                 if (!writer.writeBoolean("last", last))
                     return false;
 
                 writer.incrementState();
 
-            case 28:
+            case 26:
                 if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
                 writer.incrementState();
 
-            case 29:
+            case 27:
                 if (!writer.writeUuid("nearNodeId", nearNodeId))
                     return false;
 
                 writer.incrementState();
 
-            case 30:
+            case 28:
                 if (!writer.writeCollection("nearWrites", nearWrites, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
 
-            case 31:
+            case 29:
                 if (!writer.writeMessage("nearXidVer", nearXidVer))
                     return false;
 
                 writer.incrementState();
 
-            case 32:
+            case 30:
                 if (!writer.writeCollection("ownedKeys", ownedKeys, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
 
-            case 33:
+            case 31:
                 if (!writer.writeCollection("ownedVals", ownedVals, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
 
-            case 34:
+            case 32:
                 if (!writer.writeBitSet("preloadKeys", preloadKeys))
                     return false;
 
                 writer.incrementState();
 
-            case 35:
+            case 33:
                 if (!writer.writeUuid("subjId", subjId))
                     return false;
 
                 writer.incrementState();
 
-            case 36:
+            case 34:
                 if (!writer.writeInt("taskNameHash", taskNameHash))
                     return false;
 
                 writer.incrementState();
 
-            case 37:
+            case 35:
                 if (!writer.writeMessage("topVer", topVer))
                     return false;
 
@@ -431,7 +427,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
             return false;
 
         switch (reader.state()) {
-            case 25:
+            case 23:
                 futId = reader.readIgniteUuid("futId");
 
                 if (!reader.isLastRead())
@@ -439,7 +435,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 26:
+            case 24:
                 invalidateNearEntries = reader.readBitSet("invalidateNearEntries");
 
                 if (!reader.isLastRead())
@@ -447,7 +443,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 27:
+            case 25:
                 last = reader.readBoolean("last");
 
                 if (!reader.isLastRead())
@@ -455,7 +451,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 28:
+            case 26:
                 miniId = reader.readIgniteUuid("miniId");
 
                 if (!reader.isLastRead())
@@ -463,7 +459,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 29:
+            case 27:
                 nearNodeId = reader.readUuid("nearNodeId");
 
                 if (!reader.isLastRead())
@@ -471,7 +467,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 30:
+            case 28:
                 nearWrites = reader.readCollection("nearWrites", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
@@ -479,7 +475,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 31:
+            case 29:
                 nearXidVer = reader.readMessage("nearXidVer");
 
                 if (!reader.isLastRead())
@@ -487,7 +483,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 32:
+            case 30:
                 ownedKeys = reader.readCollection("ownedKeys", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
@@ -495,7 +491,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 33:
+            case 31:
                 ownedVals = reader.readCollection("ownedVals", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
@@ -503,7 +499,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 34:
+            case 32:
                 preloadKeys = reader.readBitSet("preloadKeys");
 
                 if (!reader.isLastRead())
@@ -511,7 +507,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 35:
+            case 33:
                 subjId = reader.readUuid("subjId");
 
                 if (!reader.isLastRead())
@@ -519,7 +515,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 36:
+            case 34:
                 taskNameHash = reader.readInt("taskNameHash");
 
                 if (!reader.isLastRead())
@@ -527,7 +523,7 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
                 reader.incrementState();
 
-            case 37:
+            case 35:
                 topVer = reader.readMessage("topVer");
 
                 if (!reader.isLastRead())
@@ -547,6 +543,6 @@ public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 38;
+        return 36;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java
index 30464a5..0a69910 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java
@@ -77,7 +77,6 @@ public class GridDhtTxRemote extends GridDistributedTxRemoteAdapter {
      * @param timeout Timeout.
      * @param ctx Cache context.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key if this is a group-lock transaction.
      * @param nearXidVer Near transaction ID.
      * @param txNodes Transaction nodes mapping.
      */
@@ -97,14 +96,13 @@ public class GridDhtTxRemote extends GridDistributedTxRemoteAdapter {
         boolean invalidate,
         long timeout,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
         GridCacheVersion nearXidVer,
         Map<UUID, Collection<UUID>> txNodes,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
         super(ctx, nodeId, rmtThreadId, xidVer, commitVer, sys, plc, concurrency, isolation, invalidate, timeout,
-            txSize, grpLockKey, subjId, taskNameHash);
+            txSize, subjId, taskNameHash);
 
         assert nearNodeId != null;
         assert rmtFutId != null;
@@ -139,7 +137,6 @@ public class GridDhtTxRemote extends GridDistributedTxRemoteAdapter {
      * @param timeout Timeout.
      * @param ctx Cache context.
      * @param txSize Expected transaction size.
-     * @param grpLockKey Group lock key if transaction is group-lock.
      */
     public GridDhtTxRemote(
         GridCacheSharedContext ctx,
@@ -158,12 +155,11 @@ public class GridDhtTxRemote extends GridDistributedTxRemoteAdapter {
         boolean invalidate,
         long timeout,
         int txSize,
-        @Nullable IgniteTxKey grpLockKey,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
         super(ctx, nodeId, rmtThreadId, xidVer, commitVer, sys, plc, concurrency, isolation, invalidate, timeout,
-            txSize, grpLockKey, subjId, taskNameHash);
+            txSize, subjId, taskNameHash);
 
         assert nearNodeId != null;
         assert rmtFutId != null;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
index 8da4da5..098ec97 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
@@ -86,7 +86,9 @@ public class GridNoStorageCacheMap extends GridCacheConcurrentMap {
         boolean create)
     {
         if (create) {
-            GridCacheMapEntry entry = new GridDhtCacheEntry(ctx, topVer, key, hash(key.hashCode()), val, null, 0);
+            GridCacheMapEntry entry = ctx.useOffheapEntry() ?
+                new GridDhtOffHeapCacheEntry(ctx, topVer, key, hash(key.hashCode()), val, null, 0) :
+                new GridDhtCacheEntry(ctx, topVer, key, hash(key.hashCode()), val, null, 0);
 
             return new GridTriple<>(entry, null, null);
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
index 35ba2a9..2f41e63 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
@@ -270,7 +270,7 @@ public class GridPartitionedGetFuture<K, V> extends GridCompoundIdentityFuture<M
         AffinityTopologyVersion topVer
     ) {
         if (CU.affinityNodes(cctx, topVer).isEmpty()) {
-            onDone(new ClusterTopologyCheckedException("Failed to map keys for cache " +
+            onDone(new ClusterTopologyServerNotFoundException("Failed to map keys for cache " +
                 "(all partition nodes left the grid)."));
 
             return;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index 905f7bf..8bbfe96 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -124,6 +124,9 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                 GridCacheMapEntry next,
                 int hdrId)
             {
+                if (ctx.useOffheapEntry())
+                    return new GridDhtAtomicOffHeapCacheEntry(ctx, topVer, key, hash, val, next, hdrId);
+
                 return new GridDhtAtomicCacheEntry(ctx, topVer, key, hash, val, next, hdrId);
             }
         });
@@ -1041,7 +1044,9 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
                     // Do not check topology version for CLOCK versioning since
                     // partition exchange will wait for near update future.
-                    if (topology().topologyVersion().equals(req.topologyVersion()) ||
+                    // Also do not check topology version if topology was locked on near node by
+                    // external transaction or explicit lock.
+                    if (topology().topologyVersion().equals(req.topologyVersion()) || req.topologyLocked() ||
                         ctx.config().getAtomicWriteOrderMode() == CLOCK) {
                         ClusterNode node = ctx.discovery().node(nodeId);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicOffHeapCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicOffHeapCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicOffHeapCacheEntry.java
new file mode 100644
index 0000000..91a8e65
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicOffHeapCacheEntry.java
@@ -0,0 +1,63 @@
+/*
+ * 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.distributed.dht.atomic;
+
+import org.apache.ignite.internal.processors.affinity.*;
+import org.apache.ignite.internal.processors.cache.*;
+
+/**
+ * DHT atomic cache entry for off-heap tiered or off-heap values modes.
+ */
+public class GridDhtAtomicOffHeapCacheEntry extends GridDhtAtomicCacheEntry {
+    /** Off-heap value pointer. */
+    private long valPtr;
+
+    /**
+     * @param ctx    Cache context.
+     * @param topVer Topology version at the time of creation (if negative, then latest topology is assumed).
+     * @param key    Cache key.
+     * @param hash   Key hash value.
+     * @param val    Entry value.
+     * @param next   Next entry in the linked list.
+     * @param hdrId  Header id.
+     */
+    public GridDhtAtomicOffHeapCacheEntry(GridCacheContext ctx,
+        AffinityTopologyVersion topVer,
+        KeyCacheObject key,
+        int hash,
+        CacheObject val,
+        GridCacheMapEntry next,
+        int hdrId) {
+        super(ctx, topVer, key, hash, val, next, hdrId);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean hasOffHeapPointer() {
+        return valPtr != 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long offHeapPointer() {
+        return valPtr;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void offHeapPointer(long valPtr) {
+        this.valPtr = valPtr;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java
index d0a7620..c5b5a37 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java
@@ -88,6 +88,14 @@ public class GridDhtAtomicUpdateResponse extends GridCacheMessage implements Gri
     }
 
     /**
+     * Sets update error.
+     * @param err
+     */
+    public void onError(IgniteCheckedException err){
+        this.err = err;
+    }
+
+    /**
      * @return Gets update error.
      */
     public IgniteCheckedException error() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
index 072ab52..76e05e5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
@@ -28,6 +28,7 @@ import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.cache.distributed.dht.*;
 import org.apache.ignite.internal.processors.cache.distributed.near.*;
 import org.apache.ignite.internal.processors.cache.dr.*;
+import org.apache.ignite.internal.processors.cache.transactions.*;
 import org.apache.ignite.internal.processors.cache.version.*;
 import org.apache.ignite.internal.util.future.*;
 import org.apache.ignite.internal.util.tostring.*;
@@ -136,6 +137,9 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
     /** Task name hash. */
     private final int taskNameHash;
 
+    /** Topology locked flag. Set if atomic update is performed inside a TX or explicit lock. */
+    private boolean topLocked;
+
     /** Skip store flag. */
     private final boolean skipStore;
 
@@ -289,7 +293,23 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
      * @param waitTopFut Whether to wait for topology future.
      */
     public void map(boolean waitTopFut) {
-        mapOnTopology(keys, false, null, waitTopFut);
+        AffinityTopologyVersion topVer = null;
+
+        IgniteInternalTx tx = cctx.tm().anyActiveThreadTx();
+
+        if (tx != null && tx.topologyVersionSnapshot() != null)
+            topVer = tx.topologyVersionSnapshot();
+
+        if (topVer == null)
+            topVer = cctx.mvcc().lastExplicitLockTopologyVersion(Thread.currentThread().getId());
+
+        if (topVer == null)
+            mapOnTopology(keys, false, null, waitTopFut);
+        else {
+            topLocked = true;
+
+            map0(topVer, keys, false, null);
+        }
     }
 
     /** {@inheritDoc} */
@@ -341,7 +361,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
             updateNear(singleReq, res);
 
             if (res.error() != null)
-                onDone(addFailedKeys(res.failedKeys(), res.error()));
+                onDone(res.failedKeys() != null ? addFailedKeys(res.failedKeys(), res.error()) : res.error());
             else {
                 if (op == TRANSFORM) {
                     if (ret != null)
@@ -430,15 +450,12 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
                 }
 
                 topVer = fut.topologyVersion();
-
-                if (futVer == null)
-                    // Assign future version in topology read lock before first exception may be thrown.
-                    futVer = cctx.versions().next(topVer);
             }
             else {
                 if (waitTopFut) {
                     fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
-                        @Override public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
+                        @Override
+                        public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
                             mapOnTopology(keys, remap, oldNodeId, waitTopFut);
                         }
                     });
@@ -448,9 +465,6 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
 
                 return;
             }
-
-            if (!remap && (cctx.config().getAtomicWriteOrderMode() == CLOCK || syncMode != FULL_ASYNC))
-                cctx.mvcc().addAtomicFuture(version(), this);
         }
         finally {
             cache.topology().readUnlock();
@@ -474,6 +488,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
     }
 
     /**
+     * @param topVer Topology version.
      * @param keys Keys to map.
      * @param remap Flag indicating if this is partial remap for this future.
      * @param oldNodeId Old node ID if was remap.
@@ -494,6 +509,13 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
             return;
         }
 
+        if (futVer == null)
+            // Assign future version in topology read lock before first exception may be thrown.
+            futVer = cctx.versions().next(topVer);
+
+        if (!remap && (cctx.config().getAtomicWriteOrderMode() == CLOCK || syncMode != FULL_ASYNC))
+            cctx.mvcc().addAtomicFuture(version(), this);
+
         CacheConfiguration ccfg = cctx.config();
 
         // Assign version on near node in CLOCK ordering mode even if fastMap is false.
@@ -579,6 +601,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
                 fastMap,
                 updVer,
                 topVer,
+                topLocked,
                 syncMode,
                 op,
                 retval,
@@ -716,6 +739,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
                             fastMap,
                             updVer,
                             topVer,
+                            topLocked,
                             syncMode,
                             op,
                             retval,

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
index e0e3e26..a96a666 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
@@ -64,6 +64,9 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
     /** Topology version. */
     private AffinityTopologyVersion topVer;
 
+    /** Topology locked flag. Set if atomic update is performed inside TX or explicit lock. */
+    private boolean topLocked;
+
     /** Write synchronization mode. */
     private CacheWriteSynchronizationMode syncMode;
 
@@ -162,6 +165,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
         boolean fastMap,
         @Nullable GridCacheVersion updateVer,
         @NotNull AffinityTopologyVersion topVer,
+        boolean topLocked,
         CacheWriteSynchronizationMode syncMode,
         GridCacheOperation op,
         boolean retval,
@@ -179,6 +183,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
         this.updateVer = updateVer;
 
         this.topVer = topVer;
+        this.topLocked = topLocked;
         this.syncMode = syncMode;
         this.op = op;
         this.retval = retval;
@@ -254,6 +259,13 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
     }
 
     /**
+     * @return Topology locked flag.
+     */
+    public boolean topologyLocked() {
+        return topLocked;
+    }
+
+    /**
      * @return Cache write synchronization mode.
      */
     public CacheWriteSynchronizationMode writeSynchronizationMode() {
@@ -664,18 +676,24 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
                 writer.incrementState();
 
             case 20:
-                if (!writer.writeMessage("topVer", topVer))
+                if (!writer.writeBoolean("topLocked", topLocked))
                     return false;
 
                 writer.incrementState();
 
             case 21:
-                if (!writer.writeMessage("updateVer", updateVer))
+                if (!writer.writeMessage("topVer", topVer))
                     return false;
 
                 writer.incrementState();
 
             case 22:
+                if (!writer.writeMessage("updateVer", updateVer))
+                    return false;
+
+                writer.incrementState();
+
+            case 23:
                 if (!writer.writeCollection("vals", vals, MessageCollectionItemType.MSG))
                     return false;
 
@@ -842,7 +860,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
                 reader.incrementState();
 
             case 20:
-                topVer = reader.readMessage("topVer");
+                topLocked = reader.readBoolean("topLocked");
 
                 if (!reader.isLastRead())
                     return false;
@@ -850,7 +868,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
                 reader.incrementState();
 
             case 21:
-                updateVer = reader.readMessage("updateVer");
+                topVer = reader.readMessage("topVer");
 
                 if (!reader.isLastRead())
                     return false;
@@ -858,6 +876,14 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
                 reader.incrementState();
 
             case 22:
+                updateVer = reader.readMessage("updateVer");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 23:
                 vals = reader.readCollection("vals", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
@@ -877,7 +903,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 23;
+        return 24;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java
index 01d5722..330e43c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java
@@ -137,9 +137,17 @@ public class GridNearAtomicUpdateResponse extends GridCacheMessage implements Gr
     }
 
     /**
+     * Sets update error.
+     * @param err
+     */
+    public void error(IgniteCheckedException err){
+        this.err = err;
+    }
+
+    /**
      * @return Update error, if any.
      */
-    public Throwable error() {
+    public IgniteCheckedException error() {
         return err;
     }
 
@@ -335,10 +343,12 @@ public class GridNearAtomicUpdateResponse extends GridCacheMessage implements Gr
      * @param e Error cause.
      */
     public synchronized void addFailedKeys(Collection<KeyCacheObject> keys, Throwable e) {
-        if (failedKeys == null)
-            failedKeys = new ArrayList<>(keys.size());
+        if (keys != null) {
+            if (failedKeys == null)
+                failedKeys = new ArrayList<>(keys.size());
 
-        failedKeys.addAll(keys);
+            failedKeys.addAll(keys);
+        }
 
         if (err == null)
             err = new IgniteCheckedException("Failed to update keys on primary node.");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
index c92d9ce..05b3c7b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
@@ -86,6 +86,9 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
                 GridCacheMapEntry next,
                 int hdrId)
             {
+                if (ctx.useOffheapEntry())
+                    return new GridDhtColocatedOffHeapCacheEntry(ctx, topVer, key, hash, val, next, hdrId);
+
                 return new GridDhtColocatedCacheEntry(ctx, topVer, key, hash, val, next, hdrId);
             }
         });
@@ -126,7 +129,7 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
         boolean allowDetached
     ) {
         return allowDetached && !ctx.affinity().primary(ctx.localNode(), key, topVer) ?
-            new GridDhtDetachedCacheEntry(ctx, key, key.hashCode(), null, null, 0) : entryExx(key, topVer);
+            createEntry(key) : entryExx(key, topVer);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
index 5b74b31..372c517 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
@@ -292,7 +292,7 @@ public final class GridDhtColocatedLockFuture<K, V> extends GridCompoundIdentity
                     false,
                     false);
 
-                cand.topologyVersion(new AffinityTopologyVersion(topVer.get().topologyVersion()));
+                cand.topologyVersion(topVer.get());
             }
         }
         else {
@@ -311,7 +311,7 @@ public final class GridDhtColocatedLockFuture<K, V> extends GridCompoundIdentity
                     false,
                     false);
 
-                cand.topologyVersion(new AffinityTopologyVersion(topVer.get().topologyVersion()));
+                cand.topologyVersion(topVer.get());
             }
             else
                 cand = cand.reenter();
@@ -754,8 +754,6 @@ public final class GridDhtColocatedLockFuture<K, V> extends GridCompoundIdentity
                                         mappedKeys.size(),
                                         inTx() ? tx.size() : mappedKeys.size(),
                                         inTx() && tx.syncCommit(),
-                                        inTx() ? tx.groupLockKey() : null,
-                                        inTx() && tx.partitionLock(),
                                         inTx() ? tx.subjectId() : null,
                                         inTx() ? tx.taskNameHash() : 0,
                                         read ? accessTtl : -1L,
@@ -786,6 +784,8 @@ public final class GridDhtColocatedLockFuture<K, V> extends GridCompoundIdentity
                         catch (GridCacheEntryRemovedException ignored) {
                             if (log.isDebugEnabled())
                                 log.debug("Got removed entry in lockAsync(..) method (will retry): " + entry);
+
+                            entry = null;
                         }
                     }
 
@@ -1088,10 +1088,6 @@ public final class GridDhtColocatedLockFuture<K, V> extends GridCompoundIdentity
             // If primary node left the grid before lock acquisition, fail the whole future.
             throw newTopologyException(null, primary.id());
 
-        if (inTx() && tx.groupLock() && !primary.isLocal())
-            throw new IgniteCheckedException("Failed to start group lock transaction (local node is not primary for " +
-                " key) [key=" + key + ", primaryNodeId=" + primary.id() + ']');
-
         if (mapping == null || !primary.id().equals(mapping.node().id()))
             mapping = new GridNearLockMapping(primary, key);
         else
@@ -1279,25 +1275,18 @@ public final class GridDhtColocatedLockFuture<K, V> extends GridCompoundIdentity
 
                         GridDhtDetachedCacheEntry entry = (GridDhtDetachedCacheEntry)txEntry.cached();
 
-                        try {
-                            if (res.dhtVersion(i) == null) {
-                                onDone(new IgniteCheckedException("Failed to receive DHT version from remote node " +
-                                    "(will fail the lock): " + res));
-
-                                return;
-                            }
-
-                            // Set value to detached entry.
-                            entry.resetFromPrimary(newVal, dhtVer);
-
-                            if (log.isDebugEnabled())
-                                log.debug("Processed response for entry [res=" + res + ", entry=" + entry + ']');
-                        }
-                        catch (IgniteCheckedException e) {
-                            onDone(e);
+                        if (res.dhtVersion(i) == null) {
+                            onDone(new IgniteCheckedException("Failed to receive DHT version from remote node " +
+                                "(will fail the lock): " + res));
 
                             return;
                         }
+
+                        // Set value to detached entry.
+                        entry.resetFromPrimary(newVal, dhtVer);
+
+                        if (log.isDebugEnabled())
+                            log.debug("Processed response for entry [res=" + res + ", entry=" + entry + ']');
                     }
                     else
                         cctx.mvcc().markExplicitOwner(k, threadId);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedOffHeapCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedOffHeapCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedOffHeapCacheEntry.java
new file mode 100644
index 0000000..ed842ad
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedOffHeapCacheEntry.java
@@ -0,0 +1,63 @@
+/*
+ * 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.distributed.dht.colocated;
+
+import org.apache.ignite.internal.processors.affinity.*;
+import org.apache.ignite.internal.processors.cache.*;
+
+/**
+ * Cache entry for colocated cache for off-heap tiered or off-heap values modes.
+ */
+public class GridDhtColocatedOffHeapCacheEntry extends GridDhtColocatedCacheEntry {
+    /** Off-heap value pointer. */
+    private long valPtr;
+
+    /**
+     * @param ctx    Cache context.
+     * @param topVer Topology version at the time of creation (if negative, then latest topology is assumed).
+     * @param key    Cache key.
+     * @param hash   Key hash value.
+     * @param val    Entry value.
+     * @param next   Next entry in the linked list.
+     * @param hdrId  Header id.
+     */
+    public GridDhtColocatedOffHeapCacheEntry(GridCacheContext ctx,
+        AffinityTopologyVersion topVer,
+        KeyCacheObject key,
+        int hash,
+        CacheObject val,
+        GridCacheMapEntry next,
+        int hdrId) {
+        super(ctx, topVer, key, hash, val, next, hdrId);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean hasOffHeapPointer() {
+        return valPtr != 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long offHeapPointer() {
+        return valPtr;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void offHeapPointer(long valPtr) {
+        this.valPtr = valPtr;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
index 5c4dd13..2c84bd4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
@@ -46,10 +46,8 @@ public class GridDhtDetachedCacheEntry extends GridDistributedCacheEntry {
      *
      * @param val Value.
      * @param ver Version.
-     * @throws IgniteCheckedException If value unmarshalling failed.
      */
-    public void resetFromPrimary(CacheObject val, GridCacheVersion ver)
-        throws IgniteCheckedException {
+    public void resetFromPrimary(CacheObject val, GridCacheVersion ver) {
         value(val);
 
         this.ver = ver;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
index 61aaa14..78966d0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
@@ -451,6 +451,12 @@ public final class GridDhtForceKeysFuture<K, V> extends GridCompoundFuture<Objec
          * @param res Result callback.
          */
         void onResult(GridDhtForceKeysResponse res) {
+            if (res.error() != null) {
+                onDone(res.error());
+
+                return;
+            }
+
             Collection<KeyCacheObject> missedKeys = res.missedKeys();
 
             boolean remapMissed = false;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java
index 8919185..41ce0be 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java
@@ -42,6 +42,13 @@ public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCa
     /** Mini-future ID. */
     private IgniteUuid miniId;
 
+    /** Error. */
+    @GridDirectTransient
+    private volatile IgniteCheckedException err;
+
+    /** Serialized error. */
+    private byte[] errBytes;
+
     /** Missed (not found) keys. */
     @GridToStringInclude
     @GridDirectCollection(KeyCacheObject.class)
@@ -73,6 +80,21 @@ public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCa
         this.miniId = miniId;
     }
 
+    /**
+     * Sets error.
+     * @param err
+     */
+    public void error(IgniteCheckedException err){
+        this.err = err;
+    }
+
+    /**
+     * @return Error, if any.
+     */
+    public IgniteCheckedException error() {
+        return err;
+    }
+
     /** {@inheritDoc} */
     @Override public boolean allowForStartup() {
         return true;
@@ -142,6 +164,8 @@ public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCa
             for (GridCacheEntryInfo info : infos)
                 info.marshal(cctx);
         }
+
+        errBytes = ctx.marshaller().marshal(err);
     }
 
     /** {@inheritDoc} */
@@ -157,6 +181,8 @@ public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCa
             for (GridCacheEntryInfo info : infos)
                 info.unmarshal(cctx, ldr);
         }
+
+        err = ctx.marshaller().unmarshal(errBytes, ldr);
     }
 
     /** {@inheritDoc} */
@@ -175,24 +201,30 @@ public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCa
 
         switch (writer.state()) {
             case 3:
-                if (!writer.writeIgniteUuid("futId", futId))
+                if (!writer.writeByteArray("errBytes", errBytes))
                     return false;
 
                 writer.incrementState();
 
             case 4:
-                if (!writer.writeCollection("infos", infos, MessageCollectionItemType.MSG))
+                if (!writer.writeIgniteUuid("futId", futId))
                     return false;
 
                 writer.incrementState();
 
             case 5:
-                if (!writer.writeIgniteUuid("miniId", miniId))
+                if (!writer.writeCollection("infos", infos, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
 
             case 6:
+                if (!writer.writeIgniteUuid("miniId", miniId))
+                    return false;
+
+                writer.incrementState();
+
+            case 7:
                 if (!writer.writeCollection("missedKeys", missedKeys, MessageCollectionItemType.MSG))
                     return false;
 
@@ -215,7 +247,7 @@ public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCa
 
         switch (reader.state()) {
             case 3:
-                futId = reader.readIgniteUuid("futId");
+                errBytes = reader.readByteArray("errBytes");
 
                 if (!reader.isLastRead())
                     return false;
@@ -223,7 +255,7 @@ public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCa
                 reader.incrementState();
 
             case 4:
-                infos = reader.readCollection("infos", MessageCollectionItemType.MSG);
+                futId = reader.readIgniteUuid("futId");
 
                 if (!reader.isLastRead())
                     return false;
@@ -231,7 +263,7 @@ public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCa
                 reader.incrementState();
 
             case 5:
-                miniId = reader.readIgniteUuid("miniId");
+                infos = reader.readCollection("infos", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
                     return false;
@@ -239,6 +271,14 @@ public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCa
                 reader.incrementState();
 
             case 6:
+                miniId = reader.readIgniteUuid("miniId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 7:
                 missedKeys = reader.readCollection("missedKeys", MessageCollectionItemType.MSG);
 
                 if (!reader.isLastRead())
@@ -258,7 +298,7 @@ public class GridDhtForceKeysResponse extends GridCacheMessage implements GridCa
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 7;
+        return 8;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/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 45d332c..4b8db00 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
@@ -1252,7 +1252,7 @@ public class GridDhtPartitionsExchangeFuture extends GridFutureAdapter<AffinityT
                 cctx.kernalContext().timeout().removeTimeoutObject(old);
 
             GridTimeoutObject timeoutObj = new GridTimeoutObjectAdapter(
-                cctx.gridConfig().getNetworkTimeout() * cctx.gridConfig().getCacheConfiguration().length) {
+                cctx.gridConfig().getNetworkTimeout() * Math.max(1, cctx.gridConfig().getCacheConfiguration().length)) {
                 @Override public void onTimeout() {
                     if (isDone())
                         return;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
index 29c1d45..8258b14 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
@@ -76,6 +76,9 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
             ) {
                 // Can't hold any locks here - this method is invoked when
                 // holding write-lock on the whole cache map.
+                if (ctx.useOffheapEntry())
+                    return new GridNearOffHeapCacheEntry(ctx, key, hash, val, next, hdrId);
+
                 return new GridNearCacheEntry(ctx, key, hash, val, next, hdrId);
             }
         });
@@ -436,16 +439,6 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
     }
 
     /** {@inheritDoc} */
-    @Override public Iterator<Map.Entry<K, V>> swapIterator() throws IgniteCheckedException {
-        return dht().swapIterator();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator<Map.Entry<K, V>> offHeapIterator() throws IgniteCheckedException {
-        return dht().offHeapIterator();
-    }
-
-    /** {@inheritDoc} */
     @Override public long offHeapEntriesCount() {
         return dht().offHeapEntriesCount();
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
index c7fa4ab..9e8d76b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
@@ -204,15 +204,13 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry {
      * @param topVer Topology version.
      * @return {@code True} if reset was done.
      * @throws GridCacheEntryRemovedException If obsolete.
-     * @throws IgniteCheckedException If failed.
      */
-    @SuppressWarnings( {"RedundantTypeArguments"})
     public boolean resetFromPrimary(CacheObject val,
         GridCacheVersion ver,
         GridCacheVersion dhtVer,
         UUID primaryNodeId,
         AffinityTopologyVersion topVer)
-        throws GridCacheEntryRemovedException, IgniteCheckedException
+        throws GridCacheEntryRemovedException
     {
         assert dhtVer != null;
 
@@ -301,7 +299,7 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry {
         else {
             CacheObject val0 = valueBytesUnlocked();
 
-            return F.t(ver, val0);
+            return F.t(dhtVer, val0);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java
index 57652bd..73d877a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java
@@ -65,7 +65,7 @@ public class GridNearGetResponse extends GridCacheMessage implements GridCacheDe
 
     /** Error. */
     @GridDirectTransient
-    private Throwable err;
+    private IgniteCheckedException err;
 
     /** Serialized error. */
     private byte[] errBytes;
@@ -152,20 +152,20 @@ public class GridNearGetResponse extends GridCacheMessage implements GridCacheDe
      * @return Topology version if this response has invalid partitions.
      */
     @Override public AffinityTopologyVersion topologyVersion() {
-        return topVer;
+        return topVer != null ? topVer : super.topologyVersion();
     }
 
     /**
      * @return Error.
      */
-    public Throwable error() {
+    public IgniteCheckedException error() {
         return err;
     }
 
     /**
      * @param err Error.
      */
-    public void error(Throwable err) {
+    public void error(IgniteCheckedException err) {
         this.err = err;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
index a427b65..0ffb4e5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
@@ -890,8 +890,6 @@ public final class GridNearLockFuture<K, V> extends GridCompoundIdentityFuture<B
                                             mappedKeys.size(),
                                             inTx() ? tx.size() : mappedKeys.size(),
                                             inTx() && tx.syncCommit(),
-                                            inTx() ? tx.groupLockKey() : null,
-                                            inTx() && tx.partitionLock(),
                                             inTx() ? tx.subjectId() : null,
                                             inTx() ? tx.taskNameHash() : 0,
                                             read ? accessTtl : -1L,
@@ -1188,10 +1186,6 @@ public final class GridNearLockFuture<K, V> extends GridCompoundIdentityFuture<B
             // If primary node left the grid before lock acquisition, fail the whole future.
             throw newTopologyException(null, primary.id());
 
-        if (inTx() && tx.groupLock() && !primary.isLocal())
-            throw new IgniteCheckedException("Failed to start group lock transaction (local node is not primary for " +
-                " key) [key=" + key + ", primaryNodeId=" + primary.id() + ']');
-
         if (mapping == null || !primary.id().equals(mapping.node().id()))
             mapping = new GridNearLockMapping(primary, key);
         else
@@ -1450,11 +1444,6 @@ public final class GridNearLockFuture<K, V> extends GridCompoundIdentityFuture<B
                             // Replace old entry with new one.
                             entries.set(i, (GridDistributedCacheEntry)cctx.cache().entryEx(entry.key()));
                         }
-                        catch (IgniteCheckedException e) {
-                            onDone(e);
-
-                            return;
-                        }
                     }
 
                     i++;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
index 1ba4bfe..e71dd65 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
@@ -21,7 +21,6 @@ import org.apache.ignite.*;
 import org.apache.ignite.internal.processors.affinity.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.cache.distributed.*;
-import org.apache.ignite.internal.processors.cache.transactions.*;
 import org.apache.ignite.internal.processors.cache.version.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
@@ -105,8 +104,6 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
      * @param keyCnt Number of keys.
      * @param txSize Expected transaction size.
      * @param syncCommit Synchronous commit flag.
-     * @param grpLockKey Group lock key if this is a group-lock transaction.
-     * @param partLock If partition is locked.
      * @param subjId Subject ID.
      * @param taskNameHash Task name hash code.
      * @param accessTtl TTL for read operation.
@@ -130,8 +127,6 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
         int keyCnt,
         int txSize,
         boolean syncCommit,
-        @Nullable IgniteTxKey grpLockKey,
-        boolean partLock,
         @Nullable UUID subjId,
         int taskNameHash,
         long accessTtl,
@@ -151,8 +146,6 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
             timeout,
             keyCnt,
             txSize,
-            grpLockKey,
-            partLock,
             skipStore);
 
         assert topVer.compareTo(AffinityTopologyVersion.ZERO) > 0;
@@ -356,79 +349,79 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
         }
 
         switch (writer.state()) {
-            case 23:
+            case 21:
                 if (!writer.writeLong("accessTtl", accessTtl))
                     return false;
 
                 writer.incrementState();
 
-            case 24:
+            case 22:
                 if (!writer.writeObjectArray("dhtVers", dhtVers, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
 
-            case 25:
+            case 23:
                 if (!writer.writeObjectArray("filter", filter, MessageCollectionItemType.MSG))
                     return false;
 
                 writer.incrementState();
 
-            case 26:
+            case 24:
                 if (!writer.writeBoolean("hasTransforms", hasTransforms))
                     return false;
 
                 writer.incrementState();
 
-            case 27:
+            case 25:
                 if (!writer.writeBoolean("implicitSingleTx", implicitSingleTx))
                     return false;
 
                 writer.incrementState();
 
-            case 28:
+            case 26:
                 if (!writer.writeBoolean("implicitTx", implicitTx))
                     return false;
 
                 writer.incrementState();
 
-            case 29:
+            case 27:
                 if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
                 writer.incrementState();
 
-            case 30:
+            case 28:
                 if (!writer.writeBoolean("onePhaseCommit", onePhaseCommit))
                     return false;
 
                 writer.incrementState();
 
-            case 31:
+            case 29:
                 if (!writer.writeBoolean("retVal", retVal))
                     return false;
 
                 writer.incrementState();
 
-            case 32:
+            case 30:
                 if (!writer.writeUuid("subjId", subjId))
                     return false;
 
                 writer.incrementState();
 
-            case 33:
+            case 31:
                 if (!writer.writeBoolean("syncCommit", syncCommit))
                     return false;
 
                 writer.incrementState();
 
-            case 34:
+            case 32:
                 if (!writer.writeInt("taskNameHash", taskNameHash))
                     return false;
 
                 writer.incrementState();
 
-            case 35:
+            case 33:
                 if (!writer.writeMessage("topVer", topVer))
                     return false;
 
@@ -450,7 +443,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
             return false;
 
         switch (reader.state()) {
-            case 23:
+            case 21:
                 accessTtl = reader.readLong("accessTtl");
 
                 if (!reader.isLastRead())
@@ -458,7 +451,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 24:
+            case 22:
                 dhtVers = reader.readObjectArray("dhtVers", MessageCollectionItemType.MSG, GridCacheVersion.class);
 
                 if (!reader.isLastRead())
@@ -466,7 +459,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 25:
+            case 23:
                 filter = reader.readObjectArray("filter", MessageCollectionItemType.MSG, CacheEntryPredicate.class);
 
                 if (!reader.isLastRead())
@@ -474,7 +467,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 26:
+            case 24:
                 hasTransforms = reader.readBoolean("hasTransforms");
 
                 if (!reader.isLastRead())
@@ -482,7 +475,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 27:
+            case 25:
                 implicitSingleTx = reader.readBoolean("implicitSingleTx");
 
                 if (!reader.isLastRead())
@@ -490,7 +483,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 28:
+            case 26:
                 implicitTx = reader.readBoolean("implicitTx");
 
                 if (!reader.isLastRead())
@@ -498,7 +491,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 29:
+            case 27:
                 miniId = reader.readIgniteUuid("miniId");
 
                 if (!reader.isLastRead())
@@ -506,7 +499,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 30:
+            case 28:
                 onePhaseCommit = reader.readBoolean("onePhaseCommit");
 
                 if (!reader.isLastRead())
@@ -514,7 +507,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 31:
+            case 29:
                 retVal = reader.readBoolean("retVal");
 
                 if (!reader.isLastRead())
@@ -522,7 +515,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 32:
+            case 30:
                 subjId = reader.readUuid("subjId");
 
                 if (!reader.isLastRead())
@@ -530,7 +523,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 33:
+            case 31:
                 syncCommit = reader.readBoolean("syncCommit");
 
                 if (!reader.isLastRead())
@@ -538,7 +531,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 34:
+            case 32:
                 taskNameHash = reader.readInt("taskNameHash");
 
                 if (!reader.isLastRead())
@@ -546,7 +539,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
-            case 35:
+            case 33:
                 topVer = reader.readMessage("topVer");
 
                 if (!reader.isLastRead())
@@ -566,7 +559,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 36;
+        return 34;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/96f0956d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOffHeapCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOffHeapCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOffHeapCacheEntry.java
new file mode 100644
index 0000000..25eb869
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOffHeapCacheEntry.java
@@ -0,0 +1,60 @@
+/*
+ * 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.distributed.near;
+
+import org.apache.ignite.internal.processors.cache.*;
+
+/**
+ * Near cache entry for off-heap tiered or off-heap values modes.
+ */
+public class GridNearOffHeapCacheEntry extends GridNearCacheEntry {
+    /** Off-heap value pointer. */
+    private long valPtr;
+
+    /**
+     * @param ctx   Cache context.
+     * @param key   Cache key.
+     * @param hash  Key hash value.
+     * @param val   Entry value.
+     * @param next  Next entry in the linked list.
+     * @param hdrId Header id.
+     */
+    public GridNearOffHeapCacheEntry(GridCacheContext ctx,
+        KeyCacheObject key,
+        int hash,
+        CacheObject val,
+        GridCacheMapEntry next,
+        int hdrId) {
+        super(ctx, key, hash, val, next, hdrId);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean hasOffHeapPointer() {
+        return valPtr != 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long offHeapPointer() {
+        return valPtr;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void offHeapPointer(long valPtr) {
+        this.valPtr = valPtr;
+    }
+}