ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject [02/30] incubator-ignite git commit: ignite-341 - fix attempt 2
Date Fri, 27 Mar 2015 09:44:58 GMT
ignite-341 - fix attempt 2


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

Branch: refs/heads/sprint-2
Commit: e2445bbd6f67c5e186869c466cc0cdef61bde12b
Parents: 2c87164
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Mon Mar 23 13:31:56 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Mon Mar 23 13:31:56 2015 +0300

----------------------------------------------------------------------
 .../swapspace/GridSwapSpaceManager.java         |  6 +++--
 .../processors/cache/GridCacheMapEntry.java     | 16 +++++++++----
 .../processors/cache/GridCacheProcessor.java    | 17 +++++++++++--
 .../distributed/dht/GridDhtLocalPartition.java  | 24 +++++--------------
 .../cache/query/GridCacheQueryManager.java      |  4 ++--
 .../processors/query/GridQueryIndexing.java     |  3 ++-
 .../processors/query/GridQueryProcessor.java    |  4 ++--
 .../spi/swapspace/SwapSpaceSpiListener.java     |  3 ++-
 .../spi/swapspace/file/FileSwapSpaceSpi.java    |  2 +-
 .../GridSwapSpaceSpiAbstractSelfTest.java       |  9 ++++---
 .../inmemory/GridTestSwapSpaceSpi.java          |  2 +-
 .../processors/query/h2/IgniteH2Indexing.java   | 12 +++++-----
 .../query/h2/opt/GridH2AbstractKeyValueRow.java | 13 ++++++++++
 .../processors/query/h2/opt/GridH2Table.java    | 25 +++++++++++++-------
 .../h2/GridIndexingSpiAbstractSelfTest.java     |  8 +++----
 15 files changed, 92 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
index 82e7bb5..e62e43f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
@@ -52,7 +52,8 @@ public class GridSwapSpaceManager extends GridManagerAdapter<SwapSpaceSpi>
{
     /** {@inheritDoc} */
     @Override public void start() throws IgniteCheckedException {
         getSpi().setListener(new SwapSpaceSpiListener() {
-            @Override public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable
byte[] keyBytes) {
+            @Override public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable
byte[] keyBytes,
+                @Nullable byte[] valBytes) {
                 if (ctx.event().isRecordable(evtType)) {
                     String msg = null;
 
@@ -98,9 +99,10 @@ public class GridSwapSpaceManager extends GridManagerAdapter<SwapSpaceSpi>
{
                 // Always notify grid cache processor.
                 if (evtType == EVT_SWAP_SPACE_DATA_EVICTED && spaceName != null)
{
                     assert keyBytes != null;
+                    assert valBytes != null;
 
                     // Cache cannot use default swap space.
-                    ctx.cache().onEvictFromSwap(spaceName, keyBytes);
+                    ctx.cache().onEvictFromSwap(spaceName, keyBytes, valBytes);
                 }
             }
         });

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/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 a610354..a22b35a 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
@@ -42,7 +42,6 @@ import javax.cache.processor.*;
 import java.io.*;
 import java.nio.*;
 import java.util.*;
-import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
 
 import static org.apache.ignite.events.EventType.*;
@@ -3154,7 +3153,13 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
             return val0;
         }
 
-        return null;
+        GridCacheSwapEntry swapEntry = cctx.swap().read(key, true, true);
+
+        if (swapEntry == null)
+            return null;
+
+        // TODO do we need all this val.finishUnmarshal stuff??
+        return swapEntry.value();
     }
 
     /** {@inheritDoc} */
@@ -3697,14 +3702,15 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
      * @param prevVal Previous value (if needed for index update).
      * @throws IgniteCheckedException If failed.
      */
-    protected void clearIndex(@Nullable CacheObject prevVal) throws IgniteCheckedException
{
+    protected void clearIndex(CacheObject prevVal) throws IgniteCheckedException {
         assert Thread.holdsLock(this);
 
         try {
             GridCacheQueryManager<?, ?> qryMgr = cctx.queries();
 
             if (qryMgr != null)
-                qryMgr.remove(key().value(cctx.cacheObjectContext(), false));
+                qryMgr.remove(key().value(cctx.cacheObjectContext(), false),
+                    prevVal.value(cctx.cacheObjectContext(), false));
         }
         catch (IgniteCheckedException e) {
             throw new GridCacheIndexUpdateException(e);
@@ -3721,7 +3727,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
     protected CacheObject saveValueForIndexUnlocked() throws IgniteCheckedException {
         assert Thread.holdsLock(this);
 
-        if (!cctx.cache().isMongoDataCache() && !cctx.cache().isMongoMetaCache())
+        if (cctx.queries() == null)
             return null;
 
         return rawGetOrUnmarshalUnlocked(false);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index e13177b..6b09cc9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -1439,11 +1439,13 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     /**
      * @param spaceName Space name.
      * @param keyBytes Key bytes.
+     * @param valBytes Value bytes.
      */
     @SuppressWarnings( {"unchecked"})
-    public void onEvictFromSwap(String spaceName, byte[] keyBytes) {
+    public void onEvictFromSwap(String spaceName, byte[] keyBytes, byte[] valBytes) {
         assert spaceName != null;
         assert keyBytes != null;
+        assert valBytes != null;
 
         /*
          * NOTE: this method should not have any synchronization because
@@ -1464,7 +1466,18 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 try {
                     KeyCacheObject key = cctx.toCacheKeyObject(keyBytes);
 
-                    qryMgr.remove(key.value(cctx.cacheObjectContext(), false));
+                    GridCacheSwapEntry swapEntry = GridCacheSwapEntryImpl.unmarshal(valBytes);
+
+                    CacheObject val = swapEntry.value();
+
+                    if (val == null)
+                        val = cctx.cacheObjects().toCacheObject(cctx.cacheObjectContext(),
swapEntry.type(),
+                            swapEntry.valueBytes());
+
+                    assert val != null;
+
+                    qryMgr.remove(key.value(cctx.cacheObjectContext(), false),
+                        val.value(cctx.cacheObjectContext(), false));
                 }
                 catch (IgniteCheckedException e) {
                     U.error(log, "Failed to unmarshal key evicted from swap [swapSpaceName="
+ spaceName + ']', e);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
index 66f555c..efbbe21 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
@@ -566,7 +566,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>
 
                 try {
                     if (cached.clearInternal(clearVer, swap)) {
-                        it.remove();
+                        map.remove(cached.key(), cached);
 
                         if (!cached.isInternal()) {
                             mapPubSize.decrement();
@@ -599,7 +599,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>
 
         return new Iterator<GridDhtCacheEntry>() {
             /** */
-            KeyCacheObject lastKey;
+            GridDhtCacheEntry lastEntry;
 
             @Override public boolean hasNext() {
                 return it.hasNext();
@@ -611,13 +611,11 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>
                 byte[] keyBytes = entry.getKey();
 
                 try {
-                    lastKey = cctx.toCacheKeyObject(keyBytes);
-
-                    GridDhtCacheEntry res = (GridDhtCacheEntry)cctx.cache().entryEx(lastKey,
false);
+                    KeyCacheObject key = cctx.toCacheKeyObject(keyBytes);
 
-                    res.unswap(true, true);
+                    lastEntry = (GridDhtCacheEntry)cctx.cache().entryEx(key, false);
 
-                    return res;
+                    return lastEntry;
                 }
                 catch (IgniteCheckedException e) {
                     throw new CacheException(e);
@@ -625,17 +623,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>
             }
 
             @Override public void remove() {
-                if (lastKey == null)
-                    throw new IllegalStateException();
-
-                map.remove(lastKey);
-
-                try {
-                    cctx.swap().remove(lastKey);
-                }
-                catch (IgniteCheckedException e) {
-                    U.error(log, "Failed to remove swap entry for key: " + lastKey);
-                }
+                map.remove(lastEntry.key(), lastEntry);
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
index ba1d921..66d4583 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
@@ -350,7 +350,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
      * @throws IgniteCheckedException Thrown in case of any errors.
      */
     @SuppressWarnings("SimplifiableIfStatement")
-    public void remove(Object key) throws IgniteCheckedException {
+    public void remove(Object key, Object val) throws IgniteCheckedException {
         assert key != null;
 
         if (!GridQueryProcessor.isEnabled(cctx.config()) && !(key instanceof GridCacheInternal))
@@ -360,7 +360,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
             return; // Ignore index update when node is stopping.
 
         try {
-            qryProc.remove(space, key);
+            qryProc.remove(space, key, val);
         }
         finally {
             invalidateResultCache();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/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 2caae45..62788df 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
@@ -177,9 +177,10 @@ public interface GridQueryIndexing {
      *
      * @param spaceName Space name.
      * @param key Key.
+     * @param val Value.
      * @throws IgniteCheckedException If failed.
      */
-    public void remove(@Nullable String spaceName, Object key) throws IgniteCheckedException;
+    public void remove(@Nullable String spaceName, Object key, Object val) throws IgniteCheckedException;
 
     /**
      * Will be called when entry with given key is swapped.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/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 6bd47a4..d3bfdf6 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
@@ -601,7 +601,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @throws IgniteCheckedException Thrown in case of any errors.
      */
     @SuppressWarnings("unchecked")
-    public void remove(String space, Object key) throws IgniteCheckedException {
+    public void remove(String space, Object key, Object val) throws IgniteCheckedException
{
         assert key != null;
 
         ctx.indexing().remove(space, key);
@@ -613,7 +613,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             throw new IllegalStateException("Failed to remove from index (grid is stopping).");
 
         try {
-            idx.remove(space, key);
+            idx.remove(space, key, val);
         }
         finally {
             busyLock.leaveBusy();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpiListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpiListener.java
b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpiListener.java
index 3b0f7e5..cb61a94 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpiListener.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpiListener.java
@@ -29,6 +29,7 @@ public interface SwapSpaceSpiListener {
      * @param evtType Event type. See {@link org.apache.ignite.events.SwapSpaceEvent}
      * @param spaceName Space name for this event or {@code null} for default space.
      * @param keyBytes Key bytes of affected entry. Not {@code null} only for evict notifications.
+     * @param valBytes Value bytes of affected entry. Not {@code null} only for evict notifications.
      */
-    public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable byte[] keyBytes);
+    public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable byte[] keyBytes,
@Nullable byte[] valBytes);
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
index 858db79..39a5455 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
@@ -581,7 +581,7 @@ public class FileSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceSpi,
         SwapSpaceSpiListener lsnr = evictLsnr;
 
         if (lsnr != null)
-            lsnr.onSwapEvent(evtType, spaceName, null);
+            lsnr.onSwapEvent(evtType, spaceName, null, null);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/modules/core/src/test/java/org/apache/ignite/spi/swapspace/GridSwapSpaceSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/GridSwapSpaceSpiAbstractSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/GridSwapSpaceSpiAbstractSelfTest.java
index 038198a..da673d9 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/GridSwapSpaceSpiAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/GridSwapSpaceSpiAbstractSelfTest.java
@@ -290,7 +290,8 @@ public abstract class GridSwapSpaceSpiAbstractSelfTest extends GridCommonAbstrac
         final CountDownLatch rmvLatch = new CountDownLatch(cnt);
 
         spi.setListener(new SwapSpaceSpiListener() {
-            @Override public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable
byte[] keyBytes) {
+            @Override public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable
byte[] keyBytes,
+                @Nullable byte[] valBytes) {
                 info("Received event: " + evtType);
 
                 if (evtType == EVT_SWAP_SPACE_DATA_STORED)
@@ -350,7 +351,8 @@ public abstract class GridSwapSpaceSpiAbstractSelfTest extends GridCommonAbstrac
         final CountDownLatch rmvLatch = new CountDownLatch(cnt);
 
         spi.setListener(new SwapSpaceSpiListener() {
-            @Override public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable
byte[] keyBytes) {
+            @Override public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable
byte[] keyBytes,
+                @Nullable byte[] valBytes) {
                 info("Received event: " + evtType);
 
                 if (evtType == EVT_SWAP_SPACE_DATA_STORED)
@@ -409,7 +411,8 @@ public abstract class GridSwapSpaceSpiAbstractSelfTest extends GridCommonAbstrac
         final CountDownLatch rmvLatch = new CountDownLatch(cnt);
 
         spi.setListener(new SwapSpaceSpiListener() {
-            @Override public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable
byte[] keyBytes) {
+            @Override public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable
byte[] keyBytes,
+                @Nullable byte[] valBytes) {
                 info("Received event: " + evtType);
 
                 if (evtType == EVT_SWAP_SPACE_DATA_STORED)

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/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 870f21b..1ba2c9f 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
@@ -187,7 +187,7 @@ public class GridTestSwapSpaceSpi extends IgniteSpiAdapter implements
SwapSpaceS
         SwapSpaceSpiListener lsnr0 = lsnr;
 
         if (lsnr0 != null)
-            lsnr0.onSwapEvent(evtType, spaceName, key);
+            lsnr0.onSwapEvent(evtType, spaceName, key, null);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/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 ee6aedf..8b9550d 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
@@ -277,7 +277,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * @param tblToUpdate Table to update.
      * @throws IgniteCheckedException In case of error.
      */
-    private void removeKey(@Nullable String spaceName, Object key, TableDescriptor tblToUpdate)
+    private void removeKey(@Nullable String spaceName, Object key, Object val, TableDescriptor
tblToUpdate)
         throws IgniteCheckedException {
         try {
             Collection<TableDescriptor> tbls = tables(schema(spaceName));
@@ -285,7 +285,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             if (tbls.size() > 1) {
                 for (TableDescriptor tbl : tbls) {
                     if (tbl != tblToUpdate && tbl.type().keyClass().equals(key.getClass()))
{
-                        if (tbl.tbl.update(key, null, 0)) {
+                        if (tbl.tbl.update(key, val, 0, true)) {
                             if (tbl.luceneIdx != null)
                                 tbl.luceneIdx.remove(key);
 
@@ -345,25 +345,25 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         if (tbl == null)
             return; // Type was rejected.
 
-        removeKey(spaceName, k, tbl);
+        removeKey(spaceName, k, v, tbl);
 
         if (expirationTime == 0)
             expirationTime = Long.MAX_VALUE;
 
-        tbl.tbl.update(k, v, expirationTime);
+        tbl.tbl.update(k, v, expirationTime, false);
 
         if (tbl.luceneIdx != null)
             tbl.luceneIdx.store(k, v, ver, expirationTime);
     }
 
     /** {@inheritDoc} */
-    @Override public void remove(@Nullable String spaceName, Object key) throws IgniteCheckedException
{
+    @Override public void remove(@Nullable String spaceName, Object key, Object val) throws
IgniteCheckedException {
         if (log.isDebugEnabled())
             log.debug("Removing key from cache query index [locId=" + nodeId + ", key=" +
key + ']');
 
         for (TableDescriptor tbl : tables(schema(spaceName))) {
             if (tbl.type().keyClass().equals(key.getClass())) {
-                if (tbl.tbl.update(key, null, 0)) {
+                if (tbl.tbl.update(key, val, 0, true)) {
                     if (tbl.luceneIdx != null)
                         tbl.luceneIdx.remove(key);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/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 ef4c3a8..5f52a77 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
@@ -169,6 +169,19 @@ public abstract class GridH2AbstractKeyValueRow extends GridH2Row {
     }
 
     /**
+     * @param val Value.
+     * @throws IgniteCheckedException
+     */
+    public synchronized void unswapBeforeRemove(Object val) throws IgniteCheckedException
{
+        assert val != null;
+
+        Value oldVal = super.getValue(VAL_COL);
+
+        if (oldVal == null || oldVal instanceof WeakValue)
+            onUnswap(val);
+    }
+
+    /**
      * Should be called when entry getting unswapped.
      *
      * @param val Value.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/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 71f5ff4..27e756f 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
@@ -27,6 +27,7 @@ import org.h2.message.*;
 import org.h2.result.*;
 import org.h2.schema.*;
 import org.h2.table.*;
+import org.h2.value.*;
 import org.jdk8.backport.*;
 import org.jetbrains.annotations.*;
 
@@ -295,15 +296,17 @@ public class GridH2Table extends TableBase {
      * @param key Key.
      * @param val Value.
      * @param expirationTime Expiration time.
-     * @return {@code True} if operation succeeded.
+     * @param rmv If {@code true} then remove, else update row.
+     * @return {@code true} If operation succeeded.
      * @throws IgniteCheckedException If failed.
      */
-    public boolean update(Object key, @Nullable Object val, long expirationTime) throws IgniteCheckedException
{
+    public boolean update(Object key, Object val, long expirationTime, boolean rmv) throws
IgniteCheckedException {
         assert desc != null;
+        assert val != null;
 
         GridH2Row row = desc.createRow(key, val, expirationTime);
 
-        return doUpdate(row, val == null);
+        return doUpdate(row, rmv);
     }
 
     /**
@@ -334,7 +337,7 @@ public class GridH2Table extends TableBase {
      * @throws IgniteCheckedException If failed.
      */
     @SuppressWarnings("LockAcquiredButNotSafelyReleased")
-    boolean doUpdate(GridH2Row row, boolean del) throws IgniteCheckedException {
+    boolean doUpdate(final GridH2Row row, boolean del) throws IgniteCheckedException {
         // Here we assume that each key can't be updated concurrently and case when different
indexes
         // getting updated from different threads with different rows with the same key is
impossible.
         GridUnsafeMemory mem = desc == null ? null : desc.memory();
@@ -374,15 +377,21 @@ public class GridH2Table extends TableBase {
             }
             else {
                 //  index(1) is PK, get full row from there (search row here contains only
key but no other columns).
-                row = pk.remove(row);
+                GridH2Row old = pk.remove(row);
+
+                if (old instanceof GridH2AbstractKeyValueRow) { // Unswap value.
+                    Value v = row.getValue(GridH2AbstractKeyValueRow.VAL_COL);
+
+                    ((GridH2AbstractKeyValueRow)old).unswapBeforeRemove(v);
+                }
 
-                if (row != null) {
+                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(row);
+                        Row res = index(i).remove(old);
 
-                        assert eq(pk, res, row): "\n" + row + "\n" + res;
+                        assert eq(pk, res, old): "\n" + old + "\n" + res;
                     }
                 }
                 else

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2445bbd/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
index 4bb801b..e9a9ad4 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
@@ -202,8 +202,8 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         assertFalse(spi.query(typeBA.space(), "select * from B.A", Collections.emptySet(),
typeBA, null).hasNext());
 
         // Nothing to remove.
-        spi.remove("A", 1);
-        spi.remove("B", 1);
+        spi.remove("A", 1, aa(1, "", 10));
+        spi.remove("B", 1, ba(1, "", 10, true));
 
         spi.store(typeAA.space(), typeAA, 1, aa(1, "Vasya", 10), "v1".getBytes(), 0);
 
@@ -307,13 +307,13 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         assertFalse(fieldsRes.iterator().hasNext());
 
         // Remove
-        spi.remove(typeAA.space(), 2);
+        spi.remove(typeAA.space(), 2, aa(2, "Valera", 19));
 
         assertEquals(1, spi.size(typeAA.space(), typeAA, null));
         assertEquals(2, spi.size(typeAB.space(), typeAB, null));
         assertEquals(1, spi.size(typeBA.space(), typeBA, null));
 
-        spi.remove(typeBA.space(), 1);
+        spi.remove(typeBA.space(), 1, ba(2, "Kolya", 25, true));
 
         assertEquals(1, spi.size(typeAA.space(), typeAA, null));
         assertEquals(2, spi.size(typeAB.space(), typeAB, null));


Mime
View raw message