ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [01/50] [abbrv] incubator-ignite git commit: # ignite-58
Date Thu, 05 Feb 2015 16:30:08 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-164v2 3fd37e59e -> 35e2c4156


# ignite-58


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

Branch: refs/heads/ignite-164v2
Commit: 6de2cedf2f58a2ecca64078ca27274849808f884
Parents: 53d1b80
Author: sboikov <semen.boikov@inria.fr>
Authored: Thu Feb 5 07:06:03 2015 +0300
Committer: sboikov <semen.boikov@inria.fr>
Committed: Thu Feb 5 07:06:03 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/cache/CacheProjection.java    |   7 +
 .../internal/managers/GridManagerAdapter.java   |   2 +-
 .../processors/cache/GridCacheAdapter.java      | 179 +++++++++++++++++-
 .../processors/cache/GridCacheEntryEx.java      |  12 ++
 .../processors/cache/GridCacheMapEntry.java     |  36 +++-
 .../cache/GridCacheProjectionImpl.java          |   5 +
 .../processors/cache/GridCacheProxyImpl.java    |  12 ++
 .../processors/cache/GridCacheSwapManager.java  |  41 ++++-
 .../processors/cache/IgniteCacheProxy.java      |   9 +-
 .../processors/cache/GridCacheTestEntryEx.java  |   6 +
 .../cache/IgniteCacheAtomicPeekTest.java        |  49 +++++
 .../cache/IgniteCachePeekAbstractTest.java      | 183 +++++++++++++++++++
 .../processors/query/h2/IgniteH2Indexing.java   |   2 +-
 13 files changed, 524 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
index 2cf10aa..6ca3008 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
@@ -473,6 +473,13 @@ public interface CacheProjection<K, V> extends Iterable<CacheEntry<K,
V>> {
     @Nullable public V peek(K key);
 
     /**
+     * @param key Key.
+     * @param peekModes Peek modes.
+     * @return Value.
+     */
+    @Nullable public V localPeek(K key, CachePeekMode[] peekModes) throws IgniteCheckedException;
+
+    /**
      * Peeks at cached value using optional set of peek modes. This method will sequentially
      * iterate over given peek modes in the order passed in, and try to peek at value using
      * each peek mode. Once a {@code non-null} value is found, it will be immediately returned.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
index 32baa8c..db69d94 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
@@ -538,7 +538,7 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements
GridMan
                             if (cctx.isNear())
                                 cctx = cctx.near().dht().context();
 
-                            GridCacheSwapEntry e = cctx.swap().read(key);
+                            GridCacheSwapEntry e = cctx.swap().read(key, true, true);
 
                             return e != null ? (V)e.value() : null;
                         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 393a3fc..0b3372c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -667,6 +667,183 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K,
V>,
     }
 
     /** {@inheritDoc} */
+    @SuppressWarnings("ForLoopReplaceableByForEach")
+    @Nullable @Override public V localPeek(K key, CachePeekMode[] peekModes) throws IgniteCheckedException
{
+        A.notNull(key, "key");
+
+        assert peekModes != null;
+
+        if (keyCheck)
+            validateCacheKey(key);
+
+        ctx.checkSecurity(GridSecurityPermission.CACHE_READ);
+
+        boolean near = false;
+        boolean primary = false;
+        boolean backup = false;
+
+        boolean heap = false;
+        boolean offheap = false;
+        boolean swap = false;
+
+        if (peekModes.length == 0) {
+            near = true;
+            primary = true;
+            backup = true;
+
+            heap = true;
+            offheap = true;
+            swap = true;
+        }
+        else {
+            for (int i = 0; i < peekModes.length; i++) {
+                CachePeekMode peekMode = peekModes[i];
+
+                A.notNull(peekMode, "peekMode");
+
+                switch (peekMode) {
+                    case ALL:
+                        break;
+
+                    case BACKUP:
+                        backup = true;
+
+                        break;
+
+                    case PRIMARY:
+                        primary = true;
+
+                        break;
+
+                    case NEAR:
+                        near = true;
+
+                        break;
+
+                    case ONHEAP:
+                        heap = true;
+
+                        break;
+
+                    case OFFHEAP:
+                        offheap = true;
+
+                        break;
+
+                    case SWAP:
+                        swap = true;
+
+                        break;
+
+                    default:
+                        assert false : peekMode;
+                }
+            }
+        }
+
+        if (!(heap || offheap || swap)) {
+            heap = true;
+            offheap = true;
+            swap = true;
+        }
+
+        if (!(primary || backup || near)) {
+            primary = true;
+            backup = true;
+            near = true;
+        }
+
+        assert heap || offheap || swap;
+        assert primary || backup || near;
+
+        try {
+            if (ctx.portableEnabled())
+                key = (K)ctx.marshalToPortable(key);
+
+            long topVer = ctx.affinity().affinityTopologyVersion();
+
+            int part = ctx.affinity().partition(key);
+
+            boolean nearKey;
+
+            if (!(near && primary && backup)) {
+                boolean keyPrimary = ctx.affinity().primary(ctx.localNode(), part, topVer);
+
+                if (keyPrimary) {
+                    if (!primary)
+                        return null;
+
+                    nearKey = false;
+                }
+                else {
+                    boolean keyBackup = ctx.affinity().belongs(ctx.localNode(), part, topVer);
+
+                    if (keyBackup) {
+                        if (!backup)
+                            return null;
+
+                        nearKey = false;
+                    }
+                    else {
+                        if (!near)
+                            return null;
+
+                        nearKey = true;
+
+                        // Swap and offheap are disabled for near cache.
+                        offheap = false;
+                        swap = false;
+                    }
+                }
+            }
+            else {
+                nearKey = !ctx.affinity().belongs(ctx.localNode(), part, topVer);
+
+                if (nearKey) {
+                    // Swap and offheap are disabled for near cache.
+                    offheap = false;
+                    swap = false;
+                }
+            }
+
+            if (nearKey && !ctx.isNear())
+                return null;
+
+            V val = null;
+
+            if (heap) {
+                GridCacheEntryEx<K, V> e = peekEx(key);
+
+                if (e != null) {
+                    val = e.peek(heap, offheap, swap, topVer);
+
+                    offheap = false;
+                    swap = false;
+                }
+            }
+
+            if (offheap || swap) {
+                GridCacheSwapManager<K, V> swapMgr = ctx.isNear() ? ctx.near().dht().context().swap()
: ctx.swap();
+
+                GridCacheSwapEntry<V> swapEntry = swapMgr.read(key, offheap, swap);
+
+                val = swapEntry != null ? swapEntry.value() : null;
+            }
+
+            if (ctx.portableEnabled())
+                val = (V)ctx.unwrapPortableIfNeeded(val, ctx.keepPortable());
+
+            return val;
+        }
+        catch (GridCacheEntryRemovedException ignore) {
+            if (log.isDebugEnabled())
+                log.debug("Got removed entry during 'peek': " + key);
+
+            return null;
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override public V peek(K key) {
         return peek(key, (IgnitePredicate<CacheEntry<K, V>>)null);
     }
@@ -871,7 +1048,7 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K,
V>,
      * @throws IgniteCheckedException In case of any errors.
      */
     @Nullable private GridTuple<V> peekSwap(K key) throws IgniteCheckedException {
-        GridCacheSwapEntry<V> e = ctx.swap().read(key);
+        GridCacheSwapEntry<V> e = ctx.swap().read(key, true, true);
 
         return e != null ? F.t(e.value()) : null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
index 72cb9a7..808336a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
@@ -590,6 +590,18 @@ public interface GridCacheEntryEx<K, V> {
     /**
      * Peeks into entry without loading value or updating statistics.
      *
+     * @param heap Read from heap flag.
+     * @param offheap Read from offheap flag.
+     * @param swap Read from swap flag.
+     * @return Value.
+     * @throws GridCacheEntryRemovedException If entry has been removed.
+     */
+    @Nullable public V peek(boolean heap, boolean offheap, boolean swap, long topVer)
+        throws GridCacheEntryRemovedException, IgniteCheckedException;
+
+    /**
+     * Peeks into entry without loading value or updating statistics.
+     *
      * @param modes Peek modes.
      * @param filter Optional filter.
      * @return Value.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/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 8fa46f2..0006c30 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
@@ -507,7 +507,7 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
                     }
                 }
                 else
-                    e = detached() ? cctx.swap().read(this, true) : cctx.swap().readAndRemove(this);
+                    e = detached() ? cctx.swap().read(this, true, true, true) : cctx.swap().readAndRemove(this);
 
                 if (log.isDebugEnabled())
                     log.debug("Read swap entry [swapEntry=" + e + ", cacheEntry=" + this
+ ']');
@@ -2691,6 +2691,38 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
     }
 
     /** {@inheritDoc} */
+    @Nullable @Override public V peek(boolean heap,
+        boolean offheap,
+        boolean swap,
+        long topVer)
+        throws GridCacheEntryRemovedException, IgniteCheckedException
+    {
+        assert heap || offheap || swap;
+
+        try {
+            if (heap) {
+                GridTuple<V> val = peekGlobal(false, topVer, null);
+
+                if (val != null)
+                    return val.get();
+            }
+
+            if (offheap || swap) {
+                GridCacheSwapEntry<V>  e = cctx.swap().read(this, false, offheap, swap);
+
+                return e != null ? e.value() : null;
+            }
+
+            return null;
+        }
+        catch (GridCacheFilterFailedException ignored) {
+            assert false;
+
+            return null;
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override public V peek(Collection<GridCachePeekMode> modes, IgnitePredicate<CacheEntry<K,
V>>[] filter)
         throws GridCacheEntryRemovedException {
         assert modes != null;
@@ -2949,7 +2981,7 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
                 return null;
         }
 
-        GridCacheSwapEntry<V> e = cctx.swap().read(this, false);
+        GridCacheSwapEntry<V> e = cctx.swap().read(this, false, true, true);
 
         return e != null ? F.t(e.value()) : null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
index 905444b..241c3c7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
@@ -1000,6 +1000,11 @@ public class GridCacheProjectionImpl<K, V> implements GridCacheProjectionEx<K,
V
     }
 
     /** {@inheritDoc} */
+    @Nullable @Override public V localPeek(K key, CachePeekMode[] peekModes) throws IgniteCheckedException
{
+        return cache.localPeek(key, peekModes);
+    }
+
+    /** {@inheritDoc} */
     @Override public V peek(K key, @Nullable Collection<GridCachePeekMode> modes) throws
IgniteCheckedException {
         V val = cache.peek(key, modes);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
index b20628e..cf6b683 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
@@ -1217,6 +1217,18 @@ public class GridCacheProxyImpl<K, V> implements GridCacheProxy<K,
V>, Externali
     }
 
     /** {@inheritDoc} */
+    @Nullable @Override public V localPeek(K key, CachePeekMode[] peekModes) throws IgniteCheckedException
{
+        GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
+
+        try {
+            return delegate.localPeek(key, peekModes);
+        }
+        finally {
+            gate.leave(prev);
+        }
+    }
+
+    /** {@inheritDoc} */
     @Nullable @Override public V peek(K key, @Nullable Collection<GridCachePeekMode>
modes) throws IgniteCheckedException {
         GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index 4f8b9dd..6a42b8c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -429,14 +429,21 @@ public class GridCacheSwapManager<K, V> extends GridCacheManagerAdapter<K,
V> {
      * @throws IgniteCheckedException If failed.
      */
     @SuppressWarnings({"unchecked"})
-    @Nullable GridCacheSwapEntry<V> read(K key, byte[] keyBytes, boolean entryLocked)
throws IgniteCheckedException {
+    @Nullable private GridCacheSwapEntry<V> read(K key,
+        byte[] keyBytes,
+        int part,
+        boolean entryLocked,
+        boolean readOffheap,
+        boolean readSwap)
+        throws IgniteCheckedException
+    {
+        assert readOffheap || readSwap;
+
         if (!offheapEnabled && !swapEnabled)
             return null;
 
         checkIteratorQueue();
 
-        int part = cctx.affinity().partition(key);
-
         KeySwapListener<K, V> lsnr = null;
 
         try {
@@ -447,14 +454,14 @@ public class GridCacheSwapManager<K, V> extends GridCacheManagerAdapter<K,
V> {
             }
 
             // First check off-heap store.
-            if (offheapEnabled) {
+            if (readOffheap && offheapEnabled) {
                 byte[] bytes = offheap.get(spaceName, part, key, keyBytes);
 
                 if (bytes != null)
                     return swapEntry(unmarshalSwapEntry(bytes));
             }
 
-            if (!swapEnabled)
+            if (!swapEnabled || !readSwap)
                 return null;
 
             assert key != null;
@@ -589,11 +596,21 @@ public class GridCacheSwapManager<K, V> extends GridCacheManagerAdapter<K,
V> {
      * @return Read value.
      * @throws IgniteCheckedException If read failed.
      */
-    @Nullable GridCacheSwapEntry<V> read(GridCacheEntryEx<K, V> entry, boolean
locked) throws IgniteCheckedException {
+    @Nullable GridCacheSwapEntry<V> read(GridCacheEntryEx<K, V> entry,
+        boolean locked,
+        boolean readOffheap,
+        boolean readSwap)
+        throws IgniteCheckedException
+    {
         if (!offheapEnabled && !swapEnabled)
             return null;
 
-        return read(entry.key(), entry.getOrMarshalKeyBytes(), locked);
+        return read(entry.key(),
+            entry.getOrMarshalKeyBytes(),
+            entry.partition(),
+            locked,
+            readOffheap,
+            readSwap);
     }
 
     /**
@@ -628,11 +645,17 @@ public class GridCacheSwapManager<K, V> extends GridCacheManagerAdapter<K,
V> {
      * @return Read value.
      * @throws IgniteCheckedException If read failed.
      */
-    @Nullable public GridCacheSwapEntry<V> read(K key) throws IgniteCheckedException
{
+    @Nullable public GridCacheSwapEntry<V> read(K key,
+        boolean readOffheap,
+        boolean readSwap)
+        throws IgniteCheckedException
+    {
         if (!offheapEnabled && !swapEnabled)
             return null;
 
-        return read(key, CU.marshal(cctx.shared(), key), false);
+        int part = cctx.affinity().partition(key);
+
+        return read(key, CU.marshal(cctx.shared(), key), part, false, readOffheap, readSwap);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 43d231e..190cb04 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -265,14 +265,13 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter<IgniteCach
 
     /** {@inheritDoc} */
     @Nullable @Override public V localPeek(K key, CachePeekMode... peekModes) {
-        // TODO IGNITE-1.
-        if (peekModes.length != 0)
-            throw new UnsupportedOperationException();
-
         GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
 
         try {
-            return delegate.peek(key);
+            return delegate.localPeek(key, peekModes);
+        }
+        catch (IgniteCheckedException e) {
+            throw cacheException(e);
         }
         finally {
             gate.leave(prev);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
index 8c7e59d..6720f4e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
@@ -823,4 +823,10 @@ public class GridCacheTestEntryEx<K, V> extends GridMetadataAwareAdapter
impleme
     @Override public long startVersion() {
         return 0;
     }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public V peek(boolean heap, boolean offheap, boolean swap, long topVer)
+        throws GridCacheEntryRemovedException, IgniteCheckedException {
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekTest.java
new file mode 100644
index 0000000..c2085ec
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicPeekTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*;
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ *
+ */
+public class IgniteCacheAtomicPeekTest extends IgniteCachePeekAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
+        return PRIMARY;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java
new file mode 100644
index 0000000..f8aaaca
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.affinity.*;
+import org.apache.ignite.cache.eviction.fifo.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.spi.*;
+import org.apache.ignite.spi.swapspace.inmemory.*;
+
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheDistributionMode.*;
+import static org.apache.ignite.cache.CachePeekMode.*;
+
+/**
+ *
+ */
+public abstract class IgniteCachePeekAbstractTest extends IgniteCacheAbstractTest {
+    /** */
+    private static final int HEAP_ENTRIES = 10;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setSwapSpaceSpi(new GridTestSwapSpaceSpi());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheDistributionMode distributionMode() {
+        return PARTITIONED_ONLY;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception
{
+        CacheConfiguration ccfg = super.cacheConfiguration(gridName);
+
+        ccfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED);
+
+        ccfg.setOffHeapMaxMemory(512);
+
+        ccfg.setBackups(1);
+
+        if (gridName.equals(getTestGridName(0)))
+            ccfg.setDistributionMode(NEAR_PARTITIONED);
+
+        ccfg.setEvictionPolicy(new CacheFifoEvictionPolicy(HEAP_ENTRIES));
+
+        return ccfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean swapEnabled() {
+        return true;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLocalPeek() throws Exception {
+        checkStorage();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void checkAffinity() throws Exception {
+        IgniteCache<Integer, String> cache0 = jcache(0);
+
+        Integer key = nearKey(cache0);
+
+        final String val = "1";
+
+        cache0.put(key, val);
+
+        assertEquals(val, cache(0).peek(key));
+        assertEquals(val, cache0.localPeek(key, NEAR));
+        assertEquals(val, cache0.localPeek(key, ALL));
+        assertNull(cache0.localPeek(key, PRIMARY));
+        assertNull(cache0.localPeek(key, BACKUP));
+
+        CacheAffinity<Integer> aff = ignite(0).affinity(null);
+
+        for (int i = 1; i < gridCount(); i++) {
+            IgniteCache<Integer, String> cache = jcache(i);
+
+            assertNull(cache.localPeek(key, NEAR));
+
+            if (aff.isPrimary(ignite(i).cluster().localNode(), key)) {
+                assertEquals(val, cache.localPeek(key, PRIMARY));
+                assertEquals(val, cache.localPeek(key, ALL));
+                assertNull(cache.localPeek(key, BACKUP));
+                assertNull(cache.localPeek(key, NEAR));
+            }
+            else if (aff.isBackup(ignite(i).cluster().localNode(), key)) {
+                assertEquals(val, cache.localPeek(key, BACKUP));
+                assertEquals(val, cache.localPeek(key, ALL));
+                assertNull(cache.localPeek(key, PRIMARY));
+                assertNull(cache.localPeek(key, NEAR));
+            }
+            else {
+                assertNull(cache.localPeek(key, ALL));
+                assertNull(cache.localPeek(key, PRIMARY));
+                assertNull(cache.localPeek(key, BACKUP));
+                assertNull(cache.localPeek(key, NEAR));
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void checkStorage() throws Exception {
+        IgniteCache<Integer, String> cache0 = jcache(0);
+
+        List<Integer> keys = primaryKeys(cache0, 100, 10_000);
+
+        final String val = "test_value";
+
+        for (Integer key : keys)
+            cache0.put(key, val);
+
+        GridTestSwapSpaceSpi swap = (GridTestSwapSpaceSpi)ignite(0).configuration().getSwapSpaceSpi();
+
+        Set<Integer> swapKeys = new HashSet<>();
+
+        final String spaceName = "gg-swap-cache-dflt";
+
+        IgniteSpiCloseableIterator<Integer> it = swap.keyIterator(spaceName, null);
+
+        assertNotNull(it);
+
+        while (it.hasNext())
+            assertTrue(swapKeys.add(it.next()));
+
+        assertFalse(swapKeys.isEmpty());
+
+        assertTrue(swapKeys.size() + HEAP_ENTRIES < 100);
+
+        List<Integer> offheapKeys = new ArrayList<>(keys);
+
+        for (Integer key : swapKeys) {
+            assertEquals(val, cache0.localPeek(key, SWAP));
+
+            assertNull(cache0.localPeek(key, ONHEAP));
+            assertNull(cache0.localPeek(key, OFFHEAP));
+
+            offheapKeys.remove(key);
+        }
+
+        for (int i = 0; i < HEAP_ENTRIES; i++) {
+            Integer key = keys.get(keys.size() - i - 1);
+
+            assertFalse(swapKeys.contains(key));
+            assertEquals(val, cache0.localPeek(key, ONHEAP));
+
+            assertNull(cache0.localPeek(key, SWAP));
+            assertNull(cache0.localPeek(key, OFFHEAP));
+
+            offheapKeys.remove(key);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6de2cedf/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 cb774d0..50015a4 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
@@ -1994,7 +1994,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             if (cctx.isNear())
                 cctx = cctx.near().dht().context();
 
-            GridCacheSwapEntry e = cctx.swap().read(key);
+            GridCacheSwapEntry e = cctx.swap().read(key, true, true);
 
             return e != null ? e.value() : null;
         }


Mime
View raw message