ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: ignite-5937
Date Wed, 18 Oct 2017 09:45:58 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-5937 0d69982fe -> e2264b433


ignite-5937


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

Branch: refs/heads/ignite-5937
Commit: e2264b43381e79d7946441d2e1187efd77d284a4
Parents: 0d69982
Author: sboikov <sboikov@gridgain.com>
Authored: Wed Oct 18 12:44:47 2017 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Wed Oct 18 12:44:47 2017 +0300

----------------------------------------------------------------------
 .../cache/persistence/tree/BPlusTree.java       |  35 ++++-
 .../processors/query/GridQueryIndexing.java     |   7 +-
 .../processors/query/GridQueryProcessor.java    |  15 +-
 ...IgniteClientCacheInitializationFailTest.java |   3 +-
 .../processors/query/h2/IgniteH2Indexing.java   |   8 +-
 .../query/h2/database/H2PkHashIndex.java        |   2 +-
 .../query/h2/database/H2RowFactory.java         |   4 +-
 .../processors/query/h2/database/H2Tree.java    |  13 +-
 .../query/h2/database/H2TreeIndex.java          |  21 ++-
 .../h2/database/H2TreeMvccFilterClosure.java    | 100 ++++++++++++
 .../query/h2/database/io/AbstractH2InnerIO.java |  40 ++++-
 .../query/h2/database/io/AbstractH2LeafIO.java  |  39 ++++-
 .../query/h2/database/io/H2MvccInnerIO.java     |   2 +-
 .../query/h2/database/io/H2MvccLeafIO.java      |   2 +-
 .../query/h2/database/io/H2RowLinkIO.java       |  14 ++
 .../query/h2/opt/GridH2KeyValueRowOnheap.java   |  29 +++-
 .../query/h2/opt/GridH2MetaTable.java           |   9 +-
 .../query/h2/opt/GridH2PlainRowFactory.java     | 157 ++-----------------
 .../query/h2/opt/GridH2QueryContext.java        |  13 +-
 .../processors/query/h2/opt/GridH2Row.java      |  16 ++
 .../query/h2/opt/GridH2RowDescriptor.java       |  10 +-
 .../query/h2/opt/GridH2SearchRow.java           |   6 +
 .../query/h2/opt/GridH2SearchRowAdapter.java    |  11 ++
 .../processors/query/h2/opt/GridH2Table.java    |  30 ++--
 .../query/h2/twostep/GridMapQueryExecutor.java  |   7 +-
 .../query/h2/twostep/GridMergeIndexSorted.java  |   2 +-
 .../h2/twostep/GridMergeIndexUnsorted.java      |   2 +-
 .../cache/mvcc/CacheMvccSqlQueriesTest.java     |   5 +-
 28 files changed, 392 insertions(+), 210 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
index b31a61f..9951a76 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
@@ -888,8 +888,8 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
      * @return Cursor.
      * @throws IgniteCheckedException If failed.
      */
-    private GridCursor<T> findLowerUnbounded(L upper, Object x) throws IgniteCheckedException {
-        ForwardCursor cursor = new ForwardCursor(null, upper, x);
+    private GridCursor<T> findLowerUnbounded(L upper, TreeRowClosure<L, T> c, Object x) throws IgniteCheckedException {
+        ForwardCursor cursor = new ForwardCursor(null, upper, c, x);
 
         long firstPageId;
 
@@ -946,13 +946,24 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
      * @throws IgniteCheckedException If failed.
      */
     public final GridCursor<T> find(L lower, L upper, Object x) throws IgniteCheckedException {
+        return find(lower, upper, null, x);
+    }
+
+    /**
+     * @param lower Lower bound inclusive or {@code null} if unbounded.
+     * @param upper Upper bound inclusive or {@code null} if unbounded.
+     * @param x Implementation specific argument, {@code null} always means that we need to return full detached data row.
+     * @return Cursor.
+     * @throws IgniteCheckedException If failed.
+     */
+    public final GridCursor<T> find(L lower, L upper, TreeRowClosure<L, T> c, Object x) throws IgniteCheckedException {
         checkDestroyed();
 
         try {
             if (lower == null)
-                return findLowerUnbounded(upper, x);
+                return findLowerUnbounded(upper, c, x);
 
-            ForwardCursor cursor = new ForwardCursor(lower, upper, x);
+            ForwardCursor cursor = new ForwardCursor(lower, upper, c, x);
 
             cursor.find();
 
@@ -4751,14 +4762,18 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
         /** */
         private int row = -1;
 
+        /** */
+        private final TreeRowClosure<L, T> c;
+
         /**
          * @param lowerBound Lower bound.
          * @param upperBound Upper bound.
          * @param x Implementation specific argument, {@code null} always means that we need to return full detached data row.
          */
-        ForwardCursor(L lowerBound, L upperBound, Object x) {
+        ForwardCursor(L lowerBound, L upperBound, TreeRowClosure<L, T> c, Object x) {
             super(lowerBound, upperBound);
 
+            this.c = c;
             this.x = x;
         }
 
@@ -4782,13 +4797,17 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
             if (rows == EMPTY)
                 rows = (T[])new Object[cnt];
 
+            int resCnt = 0;
+
             for (int i = 0; i < cnt; i++) {
-                T r = getRow(io, pageAddr, startIdx + i, x);
+                if (c == null || c.apply(BPlusTree.this, io, pageAddr, startIdx + i)) {
+                    T r = getRow(io, pageAddr, startIdx + i, x);
 
-                rows = GridArrays.set(rows, i, r);
+                    rows = GridArrays.set(rows, resCnt++, r);
+                }
             }
 
-            GridArrays.clearTail(rows, cnt);
+            GridArrays.clearTail(rows, resCnt);
 
             return true;
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/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 b0a3831..265b9bc 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
@@ -217,10 +217,13 @@ public interface GridQueryIndexing {
      * @param cctx Cache context.
      * @param type Type descriptor.
      * @param row New row.
+     * @param mvccNewRow New inserted mvcc row for the same key.
      * @throws IgniteCheckedException If failed.
      */
-    public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row)
-        throws IgniteCheckedException;
+    public void store(GridCacheContext cctx,
+        GridQueryTypeDescriptor type,
+        CacheDataRow row,
+        @Nullable CacheDataRow mvccNewRow) throws IgniteCheckedException;
 
     /**
      * Removes index entry by key.

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/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 e88a234..d132539 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
@@ -1730,14 +1730,25 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                     prevRow.value(),
                     false);
 
-                if (prevValDesc != null && prevValDesc != desc)
+                if (prevValDesc != null && prevValDesc != desc) {
                     idx.remove(cctx, prevValDesc, prevRow);
+
+                    prevRow = null;
+                }
             }
 
             if (desc == null)
                 return;
 
-            idx.store(cctx, desc, newRow);
+            // TODO IGNITE-3478 index size (always inc on update?)
+            if (cctx.mvccEnabled()) {
+                idx.store(cctx, desc, newRow, null);
+
+                if (prevRow != null)
+                    idx.store(cctx, desc, prevRow, newRow);
+            }
+            else
+                idx.store(cctx, desc, newRow, null);
         }
         finally {
             busyLock.leaveBusy();

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientCacheInitializationFailTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientCacheInitializationFailTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientCacheInitializationFailTest.java
index b0b758a..ac12407 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientCacheInitializationFailTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientCacheInitializationFailTest.java
@@ -310,7 +310,8 @@ public class IgniteClientCacheInitializationFailTest extends GridCommonAbstractT
         }
 
         /** {@inheritDoc} */
-        @Override public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow val) {
+        @Override public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row,
+            @Nullable CacheDataRow mvccNewRow) throws IgniteCheckedException {
             // No-op.
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/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 57c9c57..f4bc1f2 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
@@ -539,7 +539,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /** {@inheritDoc} */
-    @Override public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row)
+    @Override public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row, @Nullable CacheDataRow mvccNewRow)
         throws IgniteCheckedException {
         String cacheName = cctx.name();
 
@@ -548,7 +548,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         if (tbl == null)
             return; // Type was rejected.
 
-        tbl.table().update(row, false);
+        tbl.table().update(row, mvccNewRow, false);
 
         if (tbl.luceneIndex() != null) {
             long expireTime = row.expireTime();
@@ -577,7 +577,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         if (tbl == null)
             return;
 
-        if (tbl.table().update(row, true)) {
+        if (tbl.table().update(row, null, true)) {
             if (tbl.luceneIndex() != null)
                 tbl.luceneIndex().remove(row.key());
         }
@@ -673,7 +673,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
             SchemaIndexCacheVisitorClosure clo = new SchemaIndexCacheVisitorClosure() {
                 @Override public void apply(CacheDataRow row) throws IgniteCheckedException {
-                    GridH2Row h2Row = rowDesc.createRow(row);
+                    GridH2Row h2Row = rowDesc.createRow(row, null);
 
                     h2Idx.put(h2Row);
                 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java
index 724396f..9a99c62 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java
@@ -204,7 +204,7 @@ public class H2PkHashIndex extends GridH2IndexBase {
             try {
                 CacheDataRow dataRow = cursor.get();
 
-                return tbl.rowDescriptor().createRow(dataRow);
+                return tbl.rowDescriptor().createRow(dataRow, null);
             }
             catch (IgniteCheckedException e) {
                 throw DbException.convert(e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java
index 0d3e7bd..409c137 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowFactory.java
@@ -60,7 +60,7 @@ public class H2RowFactory {
 
         rowBuilder.initFromLink(cctx.group(), CacheDataRowAdapter.RowData.FULL);
 
-        GridH2Row row = rowDesc.createRow(rowBuilder);
+        GridH2Row row = rowDesc.createRow(rowBuilder, null);
 
         assert row.version() != null;
 
@@ -77,6 +77,6 @@ public class H2RowFactory {
     public GridH2Row getMvccRow(long link, long mvccCrdVer, long mvccCntr) throws IgniteCheckedException {
         MvccDataRow row = new MvccDataRow(cctx.group(), 0, link, 0, null, mvccCrdVer, mvccCntr);
 
-        return rowDesc.createRow(row);
+        return rowDesc.createRow(row, null);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
index 19f4167..f5032eb 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
@@ -38,6 +38,7 @@ import org.h2.table.IndexColumn;
 import org.h2.value.Value;
 
 import static org.apache.ignite.internal.processors.cache.mvcc.CacheCoordinatorsProcessor.COUNTER_NA;
+import static org.apache.ignite.internal.processors.cache.mvcc.CacheCoordinatorsProcessor.assertMvccVersionValid;
 import static org.apache.ignite.internal.processors.cache.mvcc.CacheCoordinatorsProcessor.unmaskCoordinatorVersion;
 
 /**
@@ -79,7 +80,7 @@ public abstract class H2Tree extends BPlusTree<GridH2SearchRow, GridH2Row> {
      * @param initNew Initialize new index.
      * @throws IgniteCheckedException If failed.
      */
-    protected H2Tree(
+    H2Tree(
         String name,
         ReuseList reuseList,
         int grpId,
@@ -240,6 +241,8 @@ public abstract class H2Tree extends BPlusTree<GridH2SearchRow, GridH2Row> {
      * @return Compare result.
      */
     private int compareRows(GridH2Row r1, GridH2SearchRow r2) {
+        assert !mvccEnabled || r2.indexSearchRow() || assertMvccVersionValid(r2.mvccCoordinatorVersion(), r2.mvccCounter()) : r2;
+
         if (r1 == r2)
             return 0;
 
@@ -251,7 +254,7 @@ public abstract class H2Tree extends BPlusTree<GridH2SearchRow, GridH2Row> {
 
             if (v1 == null || v2 == null) {
                 // Can't compare further.
-                return 0;
+                return mvccCompare(r1, r2);
             }
 
             int c = compareValues(v1, v2);
@@ -260,7 +263,11 @@ public abstract class H2Tree extends BPlusTree<GridH2SearchRow, GridH2Row> {
                 return InlineIndexHelper.fixSort(c, cols[i].sortType);
         }
 
-        if (mvccEnabled) {
+        return mvccCompare(r1, r2);
+    }
+
+    private int mvccCompare(GridH2Row r1, GridH2SearchRow r2) {
+        if (mvccEnabled && !r2.indexSearchRow()) {
             long crdVer1 = r1.mvccCoordinatorVersion();
             long crdVer2 = r2.mvccCoordinatorVersion();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
index 19ba504..72b6e2a 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
@@ -29,6 +29,7 @@ import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree;
 import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO;
 import org.apache.ignite.internal.processors.query.h2.H2Cursor;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryContext;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2SearchRow;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
@@ -170,20 +171,30 @@ public class H2TreeIndex extends GridH2IndexBase {
             assert lower == null || lower instanceof GridH2SearchRow : lower;
             assert upper == null || upper instanceof GridH2SearchRow : upper;
 
-            IndexingQueryFilter f = threadLocalFilter();
             IndexingQueryCacheFilter p = null;
+            H2TreeMvccFilterClosure mvccFilter = null;
 
-            if (f != null) {
-                String cacheName = getTable().cacheName();
+            GridH2QueryContext qctx = GridH2QueryContext.get();
 
-                p = f.forCache(cacheName);
+            if (qctx != null) {
+                IndexingQueryFilter f = threadLocalFilter();
+
+                if (f != null) {
+                    String cacheName = getTable().cacheName();
+
+                    p = f.forCache(cacheName);
+                }
+
+                mvccFilter = qctx.mvccFilter();
             }
 
             int seg = threadLocalSegment();
 
             H2Tree tree = treeForRead(seg);
 
-            return new H2Cursor(tree.find((GridH2SearchRow)lower, (GridH2SearchRow)upper), p);
+            assert !cctx.mvccEnabled() || mvccFilter != null;
+
+            return new H2Cursor(tree.find((GridH2SearchRow)lower, (GridH2SearchRow)upper, mvccFilter, null), p);
         }
         catch (IgniteCheckedException e) {
             throw DbException.convert(e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeMvccFilterClosure.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeMvccFilterClosure.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeMvccFilterClosure.java
new file mode 100644
index 0000000..72384c0
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeMvccFilterClosure.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.h2.database;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.processors.cache.mvcc.MvccCoordinatorVersion;
+import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree;
+import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO;
+import org.apache.ignite.internal.processors.query.h2.database.io.H2RowLinkIO;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2SearchRow;
+
+import static org.apache.ignite.internal.processors.cache.mvcc.CacheCoordinatorsProcessor.assertMvccVersionValid;
+import static org.apache.ignite.internal.processors.cache.mvcc.CacheCoordinatorsProcessor.unmaskCoordinatorVersion;
+
+/**
+ *
+ */
+public class H2TreeMvccFilterClosure implements H2Tree.TreeRowClosure<GridH2SearchRow, GridH2Row> {
+    /** */
+    private final MvccCoordinatorVersion mvccVer;
+
+    /**
+     * @param mvccVer Mvcc version.
+     */
+    public H2TreeMvccFilterClosure(MvccCoordinatorVersion mvccVer) {
+        assert mvccVer != null;
+
+        this.mvccVer = mvccVer;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean apply(BPlusTree<GridH2SearchRow, GridH2Row> tree,
+        BPlusIO<GridH2SearchRow> io,
+        long pageAddr,
+        int idx)  throws IgniteCheckedException {
+        H2RowLinkIO rowIo = (H2RowLinkIO)io;
+
+        assert rowIo.storeMvccInfo() : rowIo;
+
+        long rowCrdVer = rowIo.getMvccCoordinatorVersion(pageAddr, idx);
+
+        assert unmaskCoordinatorVersion(rowCrdVer) == rowCrdVer : rowCrdVer;
+        assert rowCrdVer > 0 : rowCrdVer;
+
+        int cmp = Long.compare(mvccVer.coordinatorVersion(), rowCrdVer);
+
+        if (cmp == 0) {
+            long rowCntr = rowIo.getMvccCounter(pageAddr, idx);
+
+            cmp = Long.compare(mvccVer.counter(), rowCntr);
+
+            return cmp >= 0 &&
+                !newVersionAvailable(rowIo, pageAddr, idx) &&
+                !mvccVer.activeTransactions().contains(rowCntr);
+        }
+        else
+            return cmp > 0;
+    }
+
+    /**
+     * @param rowIo Row IO.
+     * @param pageAddr Page address.
+     * @param idx Item index.
+     * @return {@code True}
+     */
+    private boolean newVersionAvailable(H2RowLinkIO rowIo, long pageAddr, int idx) {
+        long newCrdVer = rowIo.getNewMvccCoordinatorVersion(pageAddr, idx);
+
+        if (newCrdVer == 0)
+            return false;
+
+        int cmp = Long.compare(mvccVer.coordinatorVersion(), newCrdVer);
+
+        if (cmp == 0) {
+            long newCntr = rowIo.getNewMvccCounter(pageAddr, idx);
+
+            assert assertMvccVersionValid(newCrdVer, newCntr);
+
+            return newCntr <= mvccVer.counter() && !mvccVer.activeTransactions().contains(newCntr);
+        }
+        else
+            return cmp < 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/AbstractH2InnerIO.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/AbstractH2InnerIO.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/AbstractH2InnerIO.java
index d09d188..bdfbe9c 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/AbstractH2InnerIO.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/AbstractH2InnerIO.java
@@ -62,6 +62,18 @@ public abstract class AbstractH2InnerIO extends BPlusInnerIO<GridH2SearchRow> im
 
             PageUtils.putLong(pageAddr, off + 8, mvccCrdVer);
             PageUtils.putLong(pageAddr, off + 16, mvccCntr);
+
+            long newMvccCrdVer = row0.newMvccCoordinatorVersion();
+
+            PageUtils.putLong(pageAddr, off + 24, newMvccCrdVer);
+
+            if (newMvccCrdVer != 0) {
+                long newMvccCntr = row0.newMvccCounter();
+
+                assert assertMvccVersionValid(newMvccCrdVer, newMvccCntr);
+
+                PageUtils.putLong(pageAddr, off + 32, newMvccCntr);
+            }
         }
     }
 
@@ -74,7 +86,7 @@ public abstract class AbstractH2InnerIO extends BPlusInnerIO<GridH2SearchRow> im
             long mvccCrdVer = getMvccCoordinatorVersion(pageAddr, idx);
             long mvccCntr = getMvccCounter(pageAddr, idx);
 
-            return ((H2Tree) tree).getRowFactory().getMvccRow(link, mvccCrdVer, mvccCntr);
+            return ((H2Tree)tree).getRowFactory().getMvccRow(link, mvccCrdVer, mvccCntr);
         }
 
         return ((H2Tree)tree).getRowFactory().getRow(link);
@@ -98,6 +110,18 @@ public abstract class AbstractH2InnerIO extends BPlusInnerIO<GridH2SearchRow> im
 
             PageUtils.putLong(dstPageAddr, off + 8, mvccCrdVer);
             PageUtils.putLong(dstPageAddr, off + 16, mvccCntr);
+
+            long newMvccCrdVer = rowIo.getNewMvccCoordinatorVersion(srcPageAddr, srcIdx);
+
+            PageUtils.putLong(dstPageAddr, off + 24, newMvccCrdVer);
+
+            if (newMvccCrdVer != 0) {
+                long newMvccCntr = rowIo.getNewMvccCounter(srcPageAddr, srcIdx);
+
+                assertMvccVersionValid(newMvccCrdVer, newMvccCntr);
+
+                PageUtils.putLong(dstPageAddr, off + 32, newMvccCntr);
+            }
         }
     }
 
@@ -119,4 +143,18 @@ public abstract class AbstractH2InnerIO extends BPlusInnerIO<GridH2SearchRow> im
 
         return PageUtils.getLong(pageAddr, offset(idx) + 16);
     }
+
+    /** {@inheritDoc} */
+    @Override public long getNewMvccCoordinatorVersion(long pageAddr, int idx) {
+        assert storeMvccInfo();
+
+        return PageUtils.getLong(pageAddr, offset(idx) + 24);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getNewMvccCounter(long pageAddr, int idx) {
+        assert storeMvccInfo();
+
+        return PageUtils.getLong(pageAddr, offset(idx) + 32);
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/AbstractH2LeafIO.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/AbstractH2LeafIO.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/AbstractH2LeafIO.java
index 738a13d..609c87e 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/AbstractH2LeafIO.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/AbstractH2LeafIO.java
@@ -22,7 +22,6 @@ import org.apache.ignite.internal.pagemem.PageUtils;
 import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree;
 import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO;
 import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO;
-import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions;
 import org.apache.ignite.internal.processors.query.h2.database.H2Tree;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2SearchRow;
@@ -63,6 +62,18 @@ public abstract class AbstractH2LeafIO extends BPlusLeafIO<GridH2SearchRow> impl
 
             PageUtils.putLong(pageAddr, off + 8, mvccCrdVer);
             PageUtils.putLong(pageAddr, off + 16, mvccCntr);
+
+            long newMvccCrdVer = row0.newMvccCoordinatorVersion();
+
+            PageUtils.putLong(pageAddr, off + 24, newMvccCrdVer);
+
+            if (newMvccCrdVer != 0) {
+                long newMvccCntr = row0.newMvccCounter();
+
+                assert assertMvccVersionValid(newMvccCrdVer, newMvccCntr);
+
+                PageUtils.putLong(pageAddr, off + 32, newMvccCntr);
+            }
         }
     }
 
@@ -82,6 +93,18 @@ public abstract class AbstractH2LeafIO extends BPlusLeafIO<GridH2SearchRow> impl
 
             PageUtils.putLong(dstPageAddr, off + 8, mvccCrdVer);
             PageUtils.putLong(dstPageAddr, off + 16, mvccCntr);
+
+            long newMvccCrdVer = getNewMvccCoordinatorVersion(srcPageAddr, srcIdx);
+
+            PageUtils.putLong(dstPageAddr, off + 24, newMvccCrdVer);
+
+            if (newMvccCrdVer != 0) {
+                long newMvccCntr = getNewMvccCounter(srcPageAddr, srcIdx);
+
+                assertMvccVersionValid(newMvccCrdVer, newMvccCntr);
+
+                PageUtils.putLong(dstPageAddr, off + 32, newMvccCntr);
+            }
         }
     }
 
@@ -118,4 +141,18 @@ public abstract class AbstractH2LeafIO extends BPlusLeafIO<GridH2SearchRow> impl
 
         return PageUtils.getLong(pageAddr, offset(idx) + 16);
     }
+
+    /** {@inheritDoc} */
+    @Override public long getNewMvccCoordinatorVersion(long pageAddr, int idx) {
+        assert storeMvccInfo();
+
+        return PageUtils.getLong(pageAddr, offset(idx) + 24);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getNewMvccCounter(long pageAddr, int idx) {
+        assert storeMvccInfo();
+
+        return PageUtils.getLong(pageAddr, offset(idx) + 32);
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2MvccInnerIO.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2MvccInnerIO.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2MvccInnerIO.java
index e3c8851..e64ab43 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2MvccInnerIO.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2MvccInnerIO.java
@@ -32,7 +32,7 @@ public class H2MvccInnerIO extends AbstractH2InnerIO {
      * @param ver Page format version.
      */
     private H2MvccInnerIO(int ver) {
-        super(T_H2_MVCC_REF_INNER, ver, 24);
+        super(T_H2_MVCC_REF_INNER, ver, 40);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2MvccLeafIO.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2MvccLeafIO.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2MvccLeafIO.java
index 7886e0f..a364432 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2MvccLeafIO.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2MvccLeafIO.java
@@ -32,7 +32,7 @@ public class H2MvccLeafIO extends AbstractH2LeafIO {
      * @param ver Page format version.
      */
     private H2MvccLeafIO(int ver) {
-        super(T_H2_MVCC_REF_LEAF, ver, 24);
+        super(T_H2_MVCC_REF_LEAF, ver, 40);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2RowLinkIO.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2RowLinkIO.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2RowLinkIO.java
index ca2b9e4..d828c44 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2RowLinkIO.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/io/H2RowLinkIO.java
@@ -43,6 +43,20 @@ public interface H2RowLinkIO {
     public long getMvccCounter(long pageAddr, int idx);
 
     /**
+     * @param pageAddr Page address.
+     * @param idx Index.
+     * @return Mvcc coordinator version.
+     */
+    public long getNewMvccCoordinatorVersion(long pageAddr, int idx);
+
+    /**
+     * @param pageAddr Page address.
+     * @param idx Index.
+     * @return Mvcc counter.
+     */
+    public long getNewMvccCounter(long pageAddr, int idx);
+
+    /**
      * @return {@code True} if IO stores mvcc information.
      */
     public boolean storeMvccInfo();

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/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 e855536..54b84da 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,6 +18,7 @@
 package org.apache.ignite.internal.processors.query.h2.opt;
 
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.processors.cache.mvcc.CacheCoordinatorsProcessor;
 import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
 import org.apache.ignite.internal.util.typedef.internal.SB;
@@ -56,17 +57,24 @@ public class GridH2KeyValueRowOnheap extends GridH2Row {
     /** */
     private Value ver;
 
+    /** */
+    private final CacheDataRow mvccNewRow;
+
     /**
      * Constructor.
      *
      * @param desc Row descriptor.
      * @param row Row.
+     * @param mvccNewRow New inserted mvcc row for the same key.
      * @param keyType Key type.
      * @param valType Value type.
      * @throws IgniteCheckedException If failed.
      */
-    public GridH2KeyValueRowOnheap(GridH2RowDescriptor desc, CacheDataRow row, int keyType, int valType)
-        throws IgniteCheckedException {
+    public GridH2KeyValueRowOnheap(GridH2RowDescriptor desc,
+        CacheDataRow row,
+        CacheDataRow mvccNewRow,
+        int keyType,
+        int valType) throws IgniteCheckedException {
         super(row);
 
         this.desc = desc;
@@ -78,6 +86,23 @@ public class GridH2KeyValueRowOnheap extends GridH2Row {
 
         if (row.version() != null)
             this.ver = desc.wrap(row.version(), Value.JAVA_OBJECT);
+
+        this.mvccNewRow = mvccNewRow;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long newMvccCoordinatorVersion() {
+        return mvccNewRow != null ? mvccNewRow.mvccCoordinatorVersion() : 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long newMvccCounter() {
+        return mvccNewRow != null ? mvccNewRow.mvccCounter() : CacheCoordinatorsProcessor.COUNTER_NA;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean indexSearchRow() {
+        return false;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2MetaTable.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2MetaTable.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2MetaTable.java
index eb94b12..38ad9d0 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2MetaTable.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2MetaTable.java
@@ -286,13 +286,8 @@ public class GridH2MetaTable extends TableBase {
         }
 
         /** {@inheritDoc} */
-        @Override public long mvccCoordinatorVersion() {
-            return 0; // TODO IGNITE-3478
-        }
-
-        /** {@inheritDoc} */
-        @Override public long mvccCounter() {
-            return 0; // TODO IGNITE-3478
+        @Override public boolean indexSearchRow() {
+            return false; // TODO IGNITE-3478, check meta table with mvcc.
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2PlainRowFactory.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2PlainRowFactory.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2PlainRowFactory.java
index 8982236..d24dc08 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2PlainRowFactory.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2PlainRowFactory.java
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.internal.processors.query.h2.opt;
 
-import org.apache.ignite.internal.processors.cache.mvcc.MvccCoordinatorVersion;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.h2.result.Row;
@@ -37,41 +36,34 @@ public class GridH2PlainRowFactory extends RowFactory {
     }
 
     /**
-     * TODO IGNITE-3478: review usages.
-     *
-     * @param ctx Query context.
      * @param data Values.
      * @return Row.
      */
-    public static Row create(GridH2QueryContext ctx, Value... data) {
-        MvccCoordinatorVersion mvccVer = ctx != null ? ctx.mvccVersion() : null;
-
+    public static Row create(Value... data) {
         switch (data.length) {
             case 0:
                 throw new IllegalStateException("Zero columns row.");
 
             case 1:
-                return mvccVer != null ? new RowKeyMvcc(data[0], mvccVer) : new RowKey(data[0]);
+                return new RowKey(data[0]);
 
             case 2:
-                return mvccVer != null ? new RowPairMvcc(data[0], data[1], mvccVer) : new RowPair(data[0], data[1]);
+                return new RowPair(data[0], data[1]);
 
             default:
-                return mvccVer != null ? new RowSimpleMvcc(data, mvccVer) : new RowSimple(data);
+                return new RowSimple(data);
         }
     }
 
     /** {@inheritDoc} */
     @Override public Row createRow(Value[] data, int memory) {
-        GridH2QueryContext ctx = GridH2QueryContext.get();
-
-        return create(ctx, data);
+        return create(data);
     }
 
     /**
      * Single value row.
      */
-    private static class RowKey extends GridH2SearchRowAdapter {
+    private static final class RowKey extends GridH2SearchRowAdapter {
         /** */
         private Value key;
 
@@ -100,13 +92,8 @@ public class GridH2PlainRowFactory extends RowFactory {
         }
 
         /** {@inheritDoc} */
-        @Override public long mvccCoordinatorVersion() {
-            return 0;
-        }
-
-        /** {@inheritDoc} */
-        @Override public long mvccCounter() {
-            return 0;
+        @Override public boolean indexSearchRow() {
+            return true;
         }
 
         /** {@inheritDoc} */
@@ -116,44 +103,9 @@ public class GridH2PlainRowFactory extends RowFactory {
     }
 
     /**
-     * Single value row.
-     */
-    private static final class RowKeyMvcc extends RowKey {
-        /** */
-        private final MvccCoordinatorVersion mvccVer;
-
-        /**
-         * @param key Key.
-         * @param mvccVer Mvcc version.
-         */
-        RowKeyMvcc(Value key, MvccCoordinatorVersion mvccVer) {
-            super(key);
-
-            assert mvccVer != null;
-
-            this.mvccVer = mvccVer;
-        }
-
-        /** {@inheritDoc} */
-        @Override public long mvccCoordinatorVersion() {
-            return mvccVer.coordinatorVersion();
-        }
-
-        /** {@inheritDoc} */
-        @Override public long mvccCounter() {
-            return mvccVer.counter();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(RowKeyMvcc.class, this);
-        }
-    }
-
-    /**
      * Row of two values.
      */
-    private static class RowPair extends GridH2SearchRowAdapter  {
+    private static final class RowPair extends GridH2SearchRowAdapter  {
         /** */
         private Value v1;
 
@@ -191,13 +143,8 @@ public class GridH2PlainRowFactory extends RowFactory {
         }
 
         /** {@inheritDoc} */
-        @Override public long mvccCoordinatorVersion() {
-            return 0;
-        }
-
-        /** {@inheritDoc} */
-        @Override public long mvccCounter() {
-            return 0;
+        @Override public boolean indexSearchRow() {
+            return true;
         }
 
         /** {@inheritDoc} */
@@ -207,45 +154,9 @@ public class GridH2PlainRowFactory extends RowFactory {
     }
 
     /**
-     *
-     */
-    private static final class RowPairMvcc extends RowPair {
-        /** */
-        private final MvccCoordinatorVersion mvccVer;
-
-        /**
-         * @param v1 First value.
-         * @param v2 Second value.
-         * @param mvccVer Mvcc version.
-         */
-        RowPairMvcc(Value v1, Value v2, MvccCoordinatorVersion mvccVer) {
-            super(v1, v2);
-
-            assert mvccVer != null;
-
-            this.mvccVer = mvccVer;
-        }
-
-        /** {@inheritDoc} */
-        @Override public long mvccCoordinatorVersion() {
-            return mvccVer.coordinatorVersion();
-        }
-
-        /** {@inheritDoc} */
-        @Override public long mvccCounter() {
-            return mvccVer.counter();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(RowPairMvcc.class, this);
-        }
-    }
-
-    /**
      * Simple array based row.
      */
-    private static class RowSimple extends GridH2SearchRowAdapter {
+    private static final class RowSimple extends GridH2SearchRowAdapter {
         /** */
         @GridToStringInclude
         private Value[] vals;
@@ -273,13 +184,8 @@ public class GridH2PlainRowFactory extends RowFactory {
         }
 
         /** {@inheritDoc} */
-        @Override public long mvccCoordinatorVersion() {
-            return 0;
-        }
-
-        /** {@inheritDoc} */
-        @Override public long mvccCounter() {
-            return 0;
+        @Override public boolean indexSearchRow() {
+            return true;
         }
 
         /** {@inheritDoc} */
@@ -287,39 +193,4 @@ public class GridH2PlainRowFactory extends RowFactory {
             return S.toString(RowSimple.class, this);
         }
     }
-
-    /**
-     *
-     */
-    private static class RowSimpleMvcc extends RowSimple {
-        /** */
-        private final MvccCoordinatorVersion mvccVer;
-
-        /**
-         * @param vals Values.
-         * @param mvccVer Mvcc version.
-         */
-        RowSimpleMvcc(Value[] vals, MvccCoordinatorVersion mvccVer) {
-            super(vals);
-
-            assert mvccVer != null;
-
-            this.mvccVer = mvccVer;
-        }
-
-        /** {@inheritDoc} */
-        @Override public long mvccCoordinatorVersion() {
-            return mvccVer.coordinatorVersion();
-        }
-
-        /** {@inheritDoc} */
-        @Override public long mvccCounter() {
-            return mvccVer.counter();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(RowSimpleMvcc.class, this);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2QueryContext.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2QueryContext.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2QueryContext.java
index 1b4e433..9444aa4 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2QueryContext.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2QueryContext.java
@@ -26,6 +26,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
 import org.apache.ignite.internal.processors.cache.mvcc.MvccCoordinatorVersion;
+import org.apache.ignite.internal.processors.query.h2.database.H2TreeMvccFilterClosure;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.spi.indexing.IndexingQueryFilter;
@@ -85,7 +86,7 @@ public class GridH2QueryContext {
     private GridH2CollocationModel qryCollocationMdl;
 
     /** */
-    private MvccCoordinatorVersion mvccVer;
+    private H2TreeMvccFilterClosure mvccFilter;
 
     /**
      * @param locNodeId Local node ID.
@@ -119,16 +120,16 @@ public class GridH2QueryContext {
     /**
      * @return Mvcc version.
      */
-    @Nullable public MvccCoordinatorVersion mvccVersion() {
-        return mvccVer;
+    @Nullable public H2TreeMvccFilterClosure mvccFilter() {
+        return mvccFilter;
     }
 
     /**
-     * @param mvccVer Mvcc version.
+     * @param mvccFilter Mvcc filter.
      * @return {@code this}.
      */
-    public GridH2QueryContext mvccVersion(MvccCoordinatorVersion mvccVer) {
-        this.mvccVer = mvccVer;
+    public GridH2QueryContext mvccFilter(H2TreeMvccFilterClosure mvccFilter) {
+        this.mvccFilter = mvccFilter;
 
         return this;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Row.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Row.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Row.java
index 156d010..3333214 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Row.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Row.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.query.h2.opt;
 
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.mvcc.CacheCoordinatorsProcessor;
 import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 
@@ -100,4 +101,19 @@ public abstract class GridH2Row extends GridH2SearchRowAdapter implements CacheD
     @Override public boolean removed() {
         throw new UnsupportedOperationException();
     }
+
+    /** {@inheritDoc} */
+    @Override public boolean indexSearchRow() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    public long newMvccCoordinatorVersion() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    public long newMvccCounter() {
+        return CacheCoordinatorsProcessor.COUNTER_NA;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/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 1d915e5..b42e2d8 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
@@ -58,6 +58,7 @@ import org.h2.value.ValueString;
 import org.h2.value.ValueTime;
 import org.h2.value.ValueTimestamp;
 import org.h2.value.ValueUuid;
+import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap.DEFAULT_COLUMNS_COUNT;
 import static org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap.KEY_COL;
@@ -276,14 +277,17 @@ public class GridH2RowDescriptor {
      * @return Row.
      * @throws IgniteCheckedException If failed.
      */
-    public GridH2Row createRow(CacheDataRow dataRow) throws IgniteCheckedException {
+    public GridH2Row createRow(CacheDataRow dataRow, @Nullable CacheDataRow mvccNewRow) throws IgniteCheckedException {
         GridH2Row row;
 
         try {
-            if (dataRow.value() == null) // Only can happen for remove operation, can create simple search row.
+            if (dataRow.value() == null) { // Only can happen for remove operation, can create simple search row.
+                assert mvccNewRow == null;
+
                 row = new GridH2KeyRowOnheap(dataRow, wrap(dataRow.key(), keyType));
+            }
             else
-                row = new GridH2KeyValueRowOnheap(this, dataRow, keyType, valType);
+                row = new GridH2KeyValueRowOnheap(this, dataRow, mvccNewRow, keyType, valType);
         }
         catch (ClassCastException e) {
             throw new IgniteCheckedException("Failed to convert key to SQL type. " +

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SearchRow.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SearchRow.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SearchRow.java
index 9a3518f..4b3940c 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SearchRow.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SearchRow.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.query.h2.opt;
 
+import org.apache.ignite.internal.processors.query.h2.database.H2Tree;
 import org.h2.result.Row;
 
 /**
@@ -32,4 +33,9 @@ public interface GridH2SearchRow extends Row {
      * @return Mvcc counter.
      */
     public long mvccCounter();
+
+    /**
+     * @return {@code True} for rows used for index search (as opposed to rows stored in {@link H2Tree}.
+     */
+    public boolean indexSearchRow();
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SearchRowAdapter.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SearchRowAdapter.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SearchRowAdapter.java
index 0087d38..2c05c68 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SearchRowAdapter.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SearchRowAdapter.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.query.h2.opt;
 
+import org.apache.ignite.internal.processors.cache.mvcc.CacheCoordinatorsProcessor;
 import org.h2.result.Row;
 import org.h2.result.SearchRow;
 import org.h2.store.Data;
@@ -100,4 +101,14 @@ public abstract class GridH2SearchRowAdapter implements GridH2SearchRow {
     @Override public Value[] getValueList() {
         throw new UnsupportedOperationException();
     }
+
+    /** {@inheritDoc} */
+    @Override public long mvccCoordinatorVersion() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long mvccCounter() {
+        return CacheCoordinatorsProcessor.COUNTER_NA;
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/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 0f33df8..81a7ed2 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
@@ -389,15 +389,16 @@ public class GridH2Table extends TableBase {
      * otherwise value and expiration time will be updated or new row will be added.
      *
      * @param row Row.
+     * @param mvccNewRow New inserted mvcc row for the same key.
      * @param rmv If {@code true} then remove, else update row.
      * @return {@code true} If operation succeeded.
      * @throws IgniteCheckedException If failed.
      */
-    public boolean update(CacheDataRow row, boolean rmv)
+    public boolean update(CacheDataRow row, @Nullable CacheDataRow mvccNewRow, boolean rmv)
         throws IgniteCheckedException {
         assert desc != null;
 
-        GridH2Row h2Row = desc.createRow(row);
+        GridH2Row h2Row = desc.createRow(row, mvccNewRow);
 
         if (rmv)
             return doUpdate(h2Row, true);
@@ -464,7 +465,7 @@ public class GridH2Table extends TableBase {
                 if (cctx.mvccEnabled()) {
                     boolean replaced = pk.putx(row);
 
-                    assert !replaced;
+                    assert replaced == (row.newMvccCoordinatorVersion() != 0);
 
                     old = null;
                 }
@@ -540,17 +541,24 @@ public class GridH2Table extends TableBase {
     private void addToIndex(GridH2IndexBase idx, Index pk, GridH2Row row, GridH2Row old, boolean tmp) {
         assert !idx.getIndexType().isUnique() : "Unique indexes are not supported: " + idx;
 
-        GridH2Row old2 = idx.put(row);
+        if (idx.ctx.mvccEnabled()) {
+            boolean replaced = idx.putx(row);
 
-        if (old2 != null) { // Row was replaced in index.
-            if (!tmp) {
-                if (!eq(pk, old2, old))
-                    throw new IllegalStateException("Row conflict should never happen, unique indexes are " +
-                        "not supported [idx=" + idx + ", old=" + old + ", old2=" + old2 + ']');
+            assert replaced == (row.newMvccCoordinatorVersion() != 0);
+        }
+        else {
+            GridH2Row old2 = idx.put(row);
+
+            if (old2 != null) { // Row was replaced in index.
+                if (!tmp) {
+                    if (!eq(pk, old2, old))
+                        throw new IllegalStateException("Row conflict should never happen, unique indexes are " +
+                                "not supported [idx=" + idx + ", old=" + old + ", old2=" + old2 + ']');
+                }
             }
+            else if (old != null) // Row was not replaced, need to remove manually.
+                idx.removex(old);
         }
-        else if (old != null) // Row was not replaced, need to remove manually.
-            idx.removex(old);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/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 fcc3296..f0144b7 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
@@ -62,6 +62,7 @@ import org.apache.ignite.internal.processors.query.GridQueryCancel;
 import org.apache.ignite.internal.processors.query.h2.H2Utils;
 import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
 import org.apache.ignite.internal.processors.query.h2.UpdateResult;
+import org.apache.ignite.internal.processors.query.h2.database.H2TreeMvccFilterClosure;
 import org.apache.ignite.internal.processors.query.h2.opt.DistributedJoinMode;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryContext;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2RetryException;
@@ -658,8 +659,10 @@ public class GridMapQueryExecutor {
                 .distributedJoinMode(distributedJoinMode)
                 .pageSize(pageSize)
                 .topologyVersion(topVer)
-                .reservations(reserved)
-                .mvccVersion(mvccVer);
+                .reservations(reserved);
+
+            if (mvccVer != null)
+                qctx.mvccFilter(new H2TreeMvccFilterClosure(mvccVer));
 
             Connection conn = h2.connectionForSchema(schemaName);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexSorted.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexSorted.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexSorted.java
index 4eeacf6..0dc8354 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexSorted.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexSorted.java
@@ -368,7 +368,7 @@ public final class GridMergeIndexSorted extends GridMergeIndex {
             if (!iter.hasNext())
                 return false;
 
-            cur = GridH2PlainRowFactory.create(null, iter.next());
+            cur = GridH2PlainRowFactory.create(iter.next());
 
             return true;
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/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 6e1ad1f..487d386 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
@@ -139,7 +139,7 @@ public final class GridMergeIndexUnsorted extends GridMergeIndex {
             }
 
             @Override public Row next() {
-                return GridH2PlainRowFactory.create(null, iter.next());
+                return GridH2PlainRowFactory.create(iter.next());
             }
 
             @Override public void remove() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/e2264b43/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlQueriesTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlQueriesTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlQueriesTest.java
index 68b1e27..01c752d 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlQueriesTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlQueriesTest.java
@@ -31,7 +31,8 @@ import static org.apache.ignite.cache.CacheMode.PARTITIONED;
 import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
 
 /**
- *
+ * TODO IGNITE-3478: text/spatial indexes with mvcc.
+ * TODO IGNITE-3478: dynamic index create.
  */
 @SuppressWarnings("unchecked")
 public class CacheMvccSqlQueriesTest extends CacheMvccAbstractTest {
@@ -83,7 +84,7 @@ public class CacheMvccSqlQueriesTest extends CacheMvccAbstractTest {
         /**
          * @param idxVal1 Indexed value 1.
          */
-        public MvccTestSqlIndexValue(int idxVal1) {
+        MvccTestSqlIndexValue(int idxVal1) {
             this.idxVal1 = idxVal1;
         }
 


Mime
View raw message