Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-959-m [created] ca924559f


ignite-959-z - debug


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

Branch: refs/heads/ignite-959-m
Commit: ff60850bac4496416d7675e0493ece79d1974212
Parents: f9fe999
Author: S.Vladykin <svlady...@gridgain.com>
Authored: Mon Jul 20 10:36:42 2015 +0300
Committer: S.Vladykin <svlady...@gridgain.com>
Committed: Mon Jul 20 10:36:42 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheMapEntry.java     |   2 +-
 .../apache/ignite/internal/util/GridDebug.java  | 189 ++++++++++---------
 .../unsafe/GridOffheapSnapTreeSelfTest.java     |   3 +-
 .../inmemory/GridTestSwapSpaceSpi.java          |  12 ++
 .../processors/query/h2/IgniteH2Indexing.java   |  12 +-
 .../query/h2/opt/GridH2AbstractKeyValueRow.java |  70 +++++--
 .../query/h2/opt/GridH2IndexBase.java           |   7 +
 .../query/h2/opt/GridH2RowDescriptor.java       |   3 +-
 .../processors/query/h2/opt/GridH2Table.java    |  39 +++-
 .../query/h2/opt/GridH2TreeIndex.java           |  20 ++
 .../IgniteCacheQueryMultiThreadedSelfTest.java  |  30 ++-
 11 files changed, 257 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/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 4680994..e91a34f 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
@@ -3483,7 +3483,7 @@ public abstract class GridCacheMapEntry implements 
GridCacheEntryEx {
             GridCacheQueryManager<?, ?> qryMgr = cctx.queries();
 
             if (qryMgr != null)
-                qryMgr.remove(key(), prevVal == null ? null : prevVal);
+                qryMgr.remove(key(), prevVal);
         }
         catch (IgniteCheckedException e) {
             throw new GridCacheIndexUpdateException(e);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/modules/core/src/main/java/org/apache/ignite/internal/util/GridDebug.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/util/GridDebug.java 
b/modules/core/src/main/java/org/apache/ignite/internal/util/GridDebug.java
index 98c8664..faf1d7f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridDebug.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridDebug.java
@@ -21,13 +21,13 @@ 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 org.jsr166.*;
 
 import java.io.*;
 import java.lang.management.*;
 import java.nio.charset.*;
 import java.text.*;
 import java.util.*;
-import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
 
 /**
@@ -35,8 +35,8 @@ import java.util.concurrent.atomic.*;
  */
 public class GridDebug {
     /** */
-    private static final AtomicReference<ConcurrentLinkedQueue<Item>> que =
-        new AtomicReference<>(new ConcurrentLinkedQueue<Item>());
+    private static final AtomicReference<ConcurrentHashMap8<Long, Que>> que =
+        new AtomicReference<>(new ConcurrentHashMap8<Long, Que>());
 
     /** */
     private static final SimpleDateFormat DEBUG_DATE_FMT = new 
SimpleDateFormat("HH:mm:ss,SSS");
@@ -80,15 +80,6 @@ public class GridDebug {
     }
 
     /**
-     * Gets collected debug items queue.
-     *
-     * @return Items queue.
-     */
-    public static ConcurrentLinkedQueue<Item> queue() {
-        return que.get();
-    }
-
-    /**
      * @param allow Write log.
      */
     public static synchronized void allowWriteLog(boolean allow) {
@@ -121,10 +112,22 @@ public class GridDebug {
      * @param x Debugging data.
      */
     public static void debug(Object ... x) {
-        ConcurrentLinkedQueue<Item> q = que.get();
+//        if (true)
+//            return;
+
+        ConcurrentHashMap8<Long,Que> m = que.get();
+
+        if (m == null)
+            return;
+
+        Item i = new Item(x);
+
+        Que q = m.get(i.threadId);
 
-        if (q != null)
-            q.add(new Item(x));
+        if (q == null)
+            m.put(i.threadId, q = new Que());
+
+        q.add(i);
     }
 
     /**
@@ -174,25 +177,6 @@ public class GridDebug {
     }
 
     /**
-     * Dumps given number of last events.
-     *
-     * @param n Number of last elements to dump.
-     */
-    public static void dumpLastAndStop(int n) {
-        ConcurrentLinkedQueue<Item> q = que.getAndSet(null);
-
-        if (q == null)
-            return;
-
-        int size = q.size();
-
-        while (size-- > n)
-            q.poll();
-
-        dump(q);
-    }
-
-    /**
      * Dump given queue to stdout.
      *
      * @param que Queue.
@@ -213,58 +197,28 @@ public class GridDebug {
     }
 
     /**
-     * Dump existing queue to stdout and atomically replace it with null so 
that no subsequent logging is possible.
-     *
-     * @param x Parameters.
-     * @return Empty string (useful for assertions like {@code assert x == 0 : 
D.dumpWithStop();} ).
-     */
-    public static String dumpWithStop(Object... x) {
-        debug(x);
-        return dumpWithReset(null, null);
-    }
-
-    /**
-     * Dump existing queue to stdout and atomically replace it with new queue.
+     * Dump existing queue to stdout.
      *
-     * @return Empty string (useful for assertions like {@code assert x == 0 : 
D.dumpWithReset();} ).
-     */
-    public static String dumpWithReset() {
-        return dumpWithReset(new ConcurrentLinkedQueue<Item>(), null);
-    }
-
-    /**
-     * Dump existing queue to stdout and atomically replace it with given.
-     *
-     * @param q2 Queue.
      * @param filter Filter for logged debug items.
      * @return Empty string.
      */
-    public static String dumpWithReset(
-        @Nullable ConcurrentLinkedQueue<Item> q2,
-        @Nullable IgnitePredicate<Item> filter
-    ) {
-        ConcurrentLinkedQueue<Item> q;
+    public static String dumpWithStop(@Nullable IgnitePredicate<Item> filter) {
+        ConcurrentHashMap8<Long,Que> m;
 
         do {
-            q = que.get();
+            m = que.get();
 
-            if (q == null)
-                break; // Stopped.
+            if (m == null)
+                return ""; // Stopped.
         }
-        while (!que.compareAndSet(q, q2));
+        while (!que.compareAndSet(m, null));
 
-        Collection<Item> col = null;
+        List<Item> col = new ArrayList<>();
 
-        if (filter == null)
-            col = q;
-        else if (q != null) {
-            col = new ArrayList<>();
+        for (Que q : m.values()) // Merge all threads together.
+            q.collect(col, filter);
 
-            for (Item item : q) {
-                if (filter.apply(item))
-                    col.add(item);
-            }
-        }
+        Collections.sort(col);
 
         dump(col);
 
@@ -272,16 +226,6 @@ public class GridDebug {
     }
 
     /**
-     * Reset queue to empty one.
-     */
-    public static void reset() {
-        ConcurrentLinkedQueue<Item> old = que.get();
-
-        if (old != null) // Was not stopped.
-            que.compareAndSet(old, new ConcurrentLinkedQueue<Item>());
-    }
-
-    /**
      * Formats log entry string.
      *
      * @param ts Timestamp.
@@ -299,9 +243,9 @@ public class GridDebug {
      * Debug info queue item.
      */
     @SuppressWarnings({"PublicInnerClass", "PublicField"})
-    public static class Item {
+    public static class Item implements Comparable<Item> {
         /** */
-        public final long ts = System.currentTimeMillis();
+        public final long ts = U.currentTimeMillis();
 
         /** */
         public final String threadName;
@@ -312,6 +256,9 @@ public class GridDebug {
         /** */
         public final Object[] data;
 
+        /** */
+        public int order;
+
         /**
          * Constructor.
          *
@@ -326,8 +273,76 @@ public class GridDebug {
         }
 
         /** {@inheritDoc} */
+        @Override public int compareTo(Item o) {
+            if (ts == o.ts)
+                return order > o.order ? 1 : -1;
+
+            return ts > o.ts ? 1 : -1;
+        }
+
+        /** {@inheritDoc} */
         @Override public String toString() {
             return formatEntry(ts, threadName, threadId, data);
         }
     }
+
+    public static class Que {
+        /** */
+        private static int BLOCK_SIZE = 1024;
+
+        /** */
+        private static int MASK = BLOCK_SIZE - 1;
+
+        /** */
+        private Block last;
+
+        /** */
+        private int curIdx;
+
+        public void add(Item item) {
+            assert item != null;
+
+            int idx = curIdx & MASK;
+
+            if (idx == 0)
+                last = new Block(last, BLOCK_SIZE);
+
+            item.order = curIdx++;
+
+            last.items[idx] = item;
+        }
+
+        public void collect(Collection<Item> to, IgnitePredicate<Item> filter) 
{
+            Block b = last;
+
+            while (b != null) {
+                for (Item item : b.items) {
+                    if (item == null)
+                        break;
+
+                    if (filter == null || filter.apply(item))
+                        to.add(item);
+                }
+
+                b = b.prev;
+            }
+        }
+    }
+
+    /**
+     *
+     */
+    private static class Block {
+        /** */
+        private final Item[] items;
+
+        /** */
+        private final Block prev;
+
+        public Block(Block prev, int cap) {
+            this.prev = prev;
+
+            items = new Item[cap];
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/unsafe/GridOffheapSnapTreeSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/unsafe/GridOffheapSnapTreeSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/unsafe/GridOffheapSnapTreeSelfTest.java
index 8bb8f54..7a5f33d 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/unsafe/GridOffheapSnapTreeSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/unsafe/GridOffheapSnapTreeSelfTest.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.internal.util.offheap.unsafe;
 
 import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.testframework.junits.common.*;
 
 import java.util.*;
@@ -290,7 +289,7 @@ public class GridOffheapSnapTreeSelfTest extends 
GridCommonAbstractTest {
         @Override public void decrementRefCount() {
             int res = refs.decrementAndGet();
 
-            assert res >= 0 : D.dumpWithStop() + ptr;
+            assert res >= 0 : ptr;
         }
 
         @SuppressWarnings("SubtractionInCompareTo")

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java
 
b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java
index d8303a4..e9b3cf0 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java
@@ -50,6 +50,18 @@ public class GridTestSwapSpaceSpi extends IgniteSpiAdapter 
implements SwapSpaceS
         // No-op.
     }
 
+    /**
+     * @return Size of all spaces.
+     */
+    public int size() {
+        int size = 0;
+
+        for (Space space : spaces.values())
+            size += space.size();
+
+        return size;
+    }
+
     /** {@inheritDoc} */
     @Override public void clear(@Nullable String spaceName) throws 
IgniteSpiException {
         Space space = space(spaceName);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/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 06c0961..36f5537 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
@@ -2102,7 +2102,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
                     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());
+                        obj = new Timestamp(((java.util.Date)obj).getTime());
 
                     return GridH2Utils.toValueTimestamp((Timestamp)obj);
                 case Value.DECIMAL:
@@ -2134,11 +2134,13 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
         }
 
         /** {@inheritDoc} */
-        @Override public GridH2Row createRow(CacheObject key, @Nullable 
CacheObject val, long expirationTime)
-            throws IgniteCheckedException {
+        @Override public GridH2Row createRow(CacheObject key, @Nullable 
CacheObject val, long expirationTime,
+            boolean search) throws IgniteCheckedException {
             try {
-                if (val == null) // Only can happen for remove operation, can 
create simple search row.
-                    return new GridH2Row(wrap(key, keyType), null);
+                assert val != null || search : "Only can happen for remove or 
swap operations.";
+
+                if (search)
+                    return new GridH2Row(wrap(key, keyType), val == null ? 
null : wrap(val, valType));
 
                 return schema.offheap == null ?
                     new GridH2KeyValueRowOnheap(this, key, keyType, val, 
valType, expirationTime) :

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/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 6e95710..e784f0e 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
@@ -19,7 +19,9 @@ 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.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
 import org.h2.message.*;
 import org.h2.result.*;
 import org.h2.value.*;
@@ -102,6 +104,8 @@ public abstract class GridH2AbstractKeyValueRow extends 
GridH2Row {
      * @throws IgniteCheckedException If failed.
      */
     public synchronized void onSwap() throws IgniteCheckedException {
+        D.debug("onSwap", getValue(KEY_COL).getInt());
+
         setValue(VAL_COL, null);
     }
 
@@ -113,6 +117,8 @@ public abstract class GridH2AbstractKeyValueRow extends 
GridH2Row {
      * @throws IgniteCheckedException If failed.
      */
     public synchronized void onUnswap(Object val, boolean beforeRmv) throws 
IgniteCheckedException {
+        D.debug("onUnswap", getValue(KEY_COL).getInt(), val, val.getClass());
+
         setValue(VAL_COL, desc.wrap(val, desc.valueType()));
 
         notifyAll();
@@ -176,9 +182,11 @@ public abstract class GridH2AbstractKeyValueRow extends 
GridH2Row {
     /** {@inheritDoc} */
     @Override public Value getValue(int col) {
         if (col < DEFAULT_COLUMNS_COUNT) {
-            Value v = peekValue(col);
+            Value v = null;
 
             if (col == VAL_COL) {
+                v = syncValue(0);
+
                 long start = 0;
                 int attempt = 0;
 
@@ -194,22 +202,46 @@ public abstract class GridH2AbstractKeyValueRow extends 
GridH2Row {
                         return v;
                     }
 
-                    Object k = getValue(KEY_COL).getObject();
+                    final Object k = getValue(KEY_COL).getObject();
+
+                    final Integer kx = getValue(KEY_COL).getInt();
 
                     try {
                         Object valObj = desc.readFromSwap(k);
 
                         if (valObj != null) {
-                            Value upd = desc.wrap(valObj, desc.valueType());
-
-                            v = updateWeakValue(upd);
-
-                            return v == null ? upd : v;
+                            // Even if valObj was found in swap we still have 
to recheck if this row was concurrently
+                            // unswapped because we can racy read wrong value 
from swap here.
+                            if ((v = syncValue(0)) == null && (v = 
getOffheapValue(VAL_COL)) == null) {
+                                try {
+                                    Value upd = desc.wrap(valObj, 
desc.valueType());
+
+                                    v = updateWeakValue(upd);
+
+                                    return v == null ? upd : v;
+                                }
+                                catch (ClassCastException e) {
+                                    D.dumpWithStop(new 
IgnitePredicate<GridDebug.Item>() {
+                                        @Override public boolean 
apply(GridDebug.Item item) {
+                                            Integer k0 = null;
+
+                                            try {
+                                                k0 = desc.wrap(item.data[1], 
Value.INT).getInt();
+                                            }
+                                            catch (IgniteCheckedException e1) {
+                                                e1.printStackTrace();
+                                            }
+
+                                            return kx.equals(k0);
+                                        }
+                                    });
+
+                                    throw new IllegalStateException(e);
+                                }
+                            }
                         }
-                        else {
-                            // If nothing found in swap then we should be 
already unswapped.
+                        else // If nothing found in swap then we should be 
already unswapped.
                             v = syncValue(attempt);
-                        }
                     }
                     catch (IgniteCheckedException e) {
                         throw new IgniteException(e);
@@ -225,20 +257,22 @@ public abstract class GridH2AbstractKeyValueRow extends 
GridH2Row {
                 }
             }
 
-            if (v == null) {
-                assert col == KEY_COL : col;
+            if (col == KEY_COL) {
+                v = peekValue(KEY_COL);
 
-                v = getOffheapValue(KEY_COL);
+                if (v == null) {
+                    v = getOffheapValue(KEY_COL);
 
-                assert v != null : v;
+                    assert v != null : v;
 
-                setValue(KEY_COL, v);
+                    setValue(KEY_COL, v);
 
-                if (peekValue(VAL_COL) == null)
-                    cache();
+                    if (peekValue(VAL_COL) == null)
+                        cache();
+                }
             }
 
-            assert !(v instanceof WeakValue) : v;
+            assert v != null;
 
             return v;
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
index 1b076f0..c239eba 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
@@ -107,6 +107,13 @@ public abstract class GridH2IndexBase extends BaseIndex {
     }
 
     /**
+     * @return Validation message for index.
+     */
+    public String validate() {
+        return "???";
+    }
+
+    /**
      * Filters rows from expired ones and using predicate.
      *
      * @param iter Iterator over rows.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/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 cd65ab3..1cf1624 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
@@ -39,10 +39,11 @@ public interface GridH2RowDescriptor extends 
GridOffHeapSmartPointerFactory<Grid
      * @param key Key.
      * @param val Value.
      * @param expirationTime Expiration time in millis.
+     * @param search Create search row for remove or swap.
      * @return Row.
      * @throws IgniteCheckedException If failed.
      */
-    public GridH2Row createRow(CacheObject key, @Nullable CacheObject val, 
long expirationTime)
+    public GridH2Row createRow(CacheObject key, @Nullable CacheObject val, 
long expirationTime, boolean search)
         throws IgniteCheckedException;
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/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 92991af..0a5f55a 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
@@ -19,7 +19,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.util.*;
 import org.apache.ignite.internal.util.offheap.unsafe.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
 import org.h2.api.*;
 import org.h2.command.ddl.*;
 import org.h2.engine.*;
@@ -37,6 +40,8 @@ import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.locks.*;
 
+import static 
org.apache.ignite.internal.processors.query.h2.opt.GridH2AbstractKeyValueRow.*;
+
 /**
  * H2 Table implementation.
  */
@@ -140,7 +145,7 @@ public class GridH2Table extends TableBase {
 
         assert desc != null;
 
-        GridH2Row searchRow = desc.createRow(key, null, 0);
+        GridH2Row searchRow = desc.createRow(key, null, 0, true);
 
         GridUnsafeMemory mem = desc.memory();
 
@@ -152,6 +157,8 @@ public class GridH2Table extends TableBase {
         try {
             GridH2AbstractKeyValueRow row = 
(GridH2AbstractKeyValueRow)pk.findOne(searchRow);
 
+//            D.debug("onSwapUnswap", key, getName(), row == null, val);
+
             if (row == null)
                 return false;
 
@@ -305,7 +312,9 @@ public class GridH2Table extends TableBase {
         throws IgniteCheckedException {
         assert desc != null;
 
-        GridH2Row row = desc.createRow(key, val, expirationTime);
+        D.debug("update", key, getName(), rmv, val);
+
+        GridH2Row row = desc.createRow(key, val, expirationTime, rmv);
 
         return doUpdate(row, rmv);
     }
@@ -380,20 +389,32 @@ public class GridH2Table extends TableBase {
                 //  index(1) is PK, get full row from there (search row here 
contains only key but no other columns).
                 GridH2Row old = pk.remove(row);
 
-                if (old instanceof GridH2AbstractKeyValueRow) { // Unswap 
value.
-                    Value v = row.getValue(GridH2AbstractKeyValueRow.VAL_COL);
+                if (old != null) {
+                    if (old instanceof GridH2AbstractKeyValueRow) { // Unswap 
value.
+                        Value v = row.getValue(VAL_COL);
 
-                    if (v != null)
-                        
((GridH2AbstractKeyValueRow)old).onUnswap(v.getObject(), true);
-                }
+                        if (v != null)
+                            
((GridH2AbstractKeyValueRow)old).onUnswap(v.getObject(), true);
+                    }
 
-                if (old != null) {
                     // Remove row from all indexes.
                     // Start from 2 because 0 - Scan (don't need to update), 1 
- PK (already updated).
                     for (int i = 2, len = idxs.size(); i < len; i++) {
                         Row res = index(i).remove(old);
 
-                        assert eq(pk, res, old): "\n" + old + "\n" + res;
+                        assert eq(pk, res, old): "\n" + old + "\n" + res + 
"\n" + i + " -> " + index(i).getName() +
+                            " -> " + index(i).validate() + D.dumpWithStop(new 
IgnitePredicate<GridDebug.Item>() {
+                            @Override public boolean apply(GridDebug.Item 
item) {
+                                try {
+                                    return row.getValue(KEY_COL).getInt() == 
desc.wrap(item.data[1], Value.INT).getInt();
+                                }
+                                catch (IgniteCheckedException e1) {
+                                    e1.printStackTrace();
+                                }
+
+                                return false;
+                            }
+                        });
                     }
                 }
                 else

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
index eee624b..b3997c5 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
@@ -147,6 +147,26 @@ public class GridH2TreeIndex extends GridH2IndexBase 
implements Comparator<GridS
             U.closeQuiet((Closeable)s);
     }
 
+    /** {@inheritDoc} */
+    @Override public String validate() {
+        Iterator<GridH2Row> iter = rows();
+
+        if (iter.hasNext()) {
+            GridH2Row prev = iter.next();
+
+            while (iter.hasNext()) {
+                GridH2Row next = iter.next();
+
+                if (compareRows(prev, next) >= 0)
+                    return "Wrong order: " + prev + " > " + next;
+
+                prev = next;
+            }
+        }
+
+        return "OK";
+    }
+
     /**
      * @return Snapshot for current thread if there is one.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ff60850b/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 3e50443..547b19d 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
@@ -32,13 +32,14 @@ import org.apache.ignite.internal.util.typedef.internal.*;
 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.spi.swapspace.inmemory.*;
 import org.apache.ignite.testframework.junits.common.*;
 import org.jetbrains.annotations.*;
 
 import javax.cache.*;
 import java.io.*;
 import java.util.*;
+import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.*;
@@ -65,7 +66,10 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends 
GridCommonAbstractTes
     private static AtomicInteger idxUnswapCnt = new AtomicInteger();
 
     /** */
-    private static final long DURATION = 30 * 1000;
+    private static final long DURATION = 180 * 1000;
+
+    /** */
+    private static List<GridTestSwapSpaceSpi> swaps = new 
CopyOnWriteArrayList<>();
 
     /** Don't start grid by default. */
     public IgniteCacheQueryMultiThreadedSelfTest() {
@@ -82,7 +86,11 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends 
GridCommonAbstractTes
 
         cfg.setDiscoverySpi(disco);
 
-        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
+        GridTestSwapSpaceSpi swapSpi = new GridTestSwapSpaceSpi();
+
+        swaps.add(swapSpi);
+
+        cfg.setSwapSpaceSpi(swapSpi);
 
         cfg.setCacheConfiguration(cacheConfiguration());
 
@@ -203,12 +211,20 @@ public class IgniteCacheQueryMultiThreadedSelfTest 
extends GridCommonAbstractTes
                     c.remove(e.getKey());
             }
 
-            U.sleep(5000);
+            U.sleep(500);
 
             assertEquals("Swap keys: " + c.size(CachePeekMode.SWAP), 0, 
c.size(CachePeekMode.SWAP));
             assertEquals(0, c.size(CachePeekMode.OFFHEAP));
             assertEquals(0, c.size(CachePeekMode.PRIMARY));
             assertEquals(0, c.size());
+            assertEquals(0, swaps.get(i).size());
+
+            if (offheapEnabled()) {
+                String swapSpace = 
CU.swapSpaceName(((IgniteCacheProxy)c).context());
+
+                assertEquals(0, 
grid(i).context().offheap().allocatedSize(swapSpace));
+                assertEquals(0, 
grid(i).context().offheap().entriesCount(swapSpace));
+            }
         }
     }
 
@@ -328,8 +344,8 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends 
GridCommonAbstractTes
             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());
+        assertEquals(0, c1.query(new SqlQuery<>(String.class, "1 = 
1")).getAll().size());
+        assertEquals(0, c.query(new SqlQuery<>(Long.class, "1 = 
1")).getAll().size());
 
         Random rnd = new Random();
 
@@ -390,7 +406,7 @@ public class IgniteCacheQueryMultiThreadedSelfTest extends 
GridCommonAbstractTes
      */
     @SuppressWarnings({"TooBroadScope"})
     public void testMultiThreadedSwapUnswapLongString() throws Exception {
-        int threadCnt = 50;
+        int threadCnt = 100;
         final int keyCnt = 2000;
         final int valCnt = 10000;
 

Reply via email to