# 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/78c88cbc Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/78c88cbc Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/78c88cbc Branch: refs/heads/ignite-58 Commit: 78c88cbc1b3db6b4232a08273d3c908cb691078b Parents: fde5a48 Author: sboikov <sboi...@gridgain.com> Authored: Thu Feb 5 10:00:39 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Thu Feb 5 10:39:31 2015 +0300 ---------------------------------------------------------------------- .../java/org/apache/ignite/IgniteCache.java | 4 +- .../org/apache/ignite/cache/CacheEntry.java | 1 + .../org/apache/ignite/cache/CachePeekMode.java | 12 +- .../apache/ignite/cache/GridCachePeekMode.java | 85 ------- .../eviction/fifo/CacheFifoEvictionPolicy.java | 1 + .../random/CacheRandomEvictionPolicy.java | 1 + .../processors/cache/GridCacheAdapter.java | 134 +++++++---- .../processors/cache/GridCacheEntryEx.java | 2 + .../processors/cache/GridCacheEntryImpl.java | 2 +- .../cache/GridCacheEvictionEntry.java | 2 +- .../cache/GridCacheFilterEvaluationEntry.java | 2 +- .../processors/cache/GridCachePeekMode.java | 85 +++++++ .../processors/cache/GridCacheUtils.java | 2 +- .../GridPartitionedCacheEntryImpl.java | 2 +- .../distributed/dht/GridDhtCacheEntryImpl.java | 2 +- .../dht/atomic/GridDhtAtomicCache.java | 3 +- .../dht/colocated/GridDhtColocatedCache.java | 2 +- .../distributed/near/GridNearCacheAdapter.java | 2 +- .../distributed/near/GridNearTxRemote.java | 2 +- .../cache/GridCacheAbstractFullApiSelfTest.java | 2 +- .../cache/GridCacheOffHeapSelfTest.java | 2 +- .../cache/IgniteCacheAtomicLocalPeekTest.java | 43 ++++ .../IgniteCacheAtomicReplicatedPeekTest.java | 32 +++ .../cache/IgniteCachePeekAbstractTest.java | 234 +++++++++++++------ .../cache/IgniteCacheTxLocalPeekTest.java | 43 ++++ .../processors/cache/IgniteCacheTxPeekTest.java | 49 ++++ .../cache/IgniteCacheTxReplicatedPeekTest.java | 32 +++ .../dht/GridCacheDhtInternalEntrySelfTest.java | 2 +- .../near/GridCacheNearMultiNodeSelfTest.java | 2 +- ...achePartitionedMultiNodeFullApiSelfTest.java | 2 +- .../cache/eviction/GridCacheMockEntry.java | 1 + .../ignite/testsuites/IgniteCacheTestSuite.java | 7 + .../cache/GridCacheOffHeapAndSwapSelfTest.java | 2 +- .../processors/cache/GridCacheSwapSelfTest.java | 2 +- 34 files changed, 570 insertions(+), 231 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/IgniteCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java index 8430ec4..a120515 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java @@ -234,13 +234,13 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS public void localEvict(Collection<? extends K> keys); /** - * Peeks at in-memory cached value using default {@link org.apache.ignite.cache.GridCachePeekMode#SMART} + * Peeks at in-memory cached value using default {@link org.apache.ignite.internal.processors.cache.GridCachePeekMode#SMART} * peek mode. * <p> * This method will not load value from any persistent store or from a remote node. * <h2 class="header">Transactions</h2> * This method does not participate in any transactions, however, it will - * peek at transactional value according to the {@link org.apache.ignite.cache.GridCachePeekMode#SMART} mode + * peek at transactional value according to the {@link org.apache.ignite.internal.processors.cache.GridCachePeekMode#SMART} mode * semantics. If you need to look at global cached value even from within transaction, * you can use {@link org.apache.ignite.cache.GridCache#peek(Object, Collection)} method. * http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/cache/CacheEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheEntry.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheEntry.java index 8033236..c9f8085 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/CacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheEntry.java @@ -19,6 +19,7 @@ package org.apache.ignite.cache; import org.apache.ignite.*; import org.apache.ignite.internal.*; +import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.lang.*; import org.apache.ignite.transactions.*; import org.jetbrains.annotations.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/cache/CachePeekMode.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CachePeekMode.java b/modules/core/src/main/java/org/apache/ignite/cache/CachePeekMode.java index 0fffb38..ea7037e 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/CachePeekMode.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/CachePeekMode.java @@ -17,13 +17,15 @@ package org.apache.ignite.cache; +import org.apache.ignite.*; import org.jetbrains.annotations.*; /** - * Enumeration of all supported cache peek modes. Peek modes can be passed into various - * {@code 'CacheProjection.peek(..)'} and {@code CacheEntry.peek(..)} methods, - * such as {@link CacheProjection#peek(Object, java.util.Collection)}, - * {@link CacheEntry#peek()}, and others. + * Enumeration of all supported cache peek modes. Peek modes can be passed + * into {@link IgniteCache#localPeek(Object, CachePeekMode...)}, + * {@link IgniteCache#localEntries(CachePeekMode...)}, + * {@link IgniteCache#localSize(CachePeekMode...)} and + * {@link IgniteCache#size(CachePeekMode...)} methods. * <p> * The following modes are supported: * <ul> @@ -48,11 +50,13 @@ public enum CachePeekMode { /** * Peek value from primary copy of partitioned cache only (skip near cache). + * In case of {@link CacheMode#LOCAL} cache, behaves as {@link #ALL} mode. */ PRIMARY, /** * Peek value from backup copies of partitioned cache only (skip near cache). + * In case of {@link CacheMode#LOCAL} cache, behaves as {@link #ALL} mode. */ BACKUP, http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/cache/GridCachePeekMode.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/GridCachePeekMode.java b/modules/core/src/main/java/org/apache/ignite/cache/GridCachePeekMode.java deleted file mode 100644 index e08d091..0000000 --- a/modules/core/src/main/java/org/apache/ignite/cache/GridCachePeekMode.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.cache; - -import org.jetbrains.annotations.*; - -import java.util.*; - -/** - * Enumeration of all supported cache peek modes. Peek modes can be passed into various - * {@code 'CacheProjection.peek(..)'} and {@code CacheEntry.peek(..)} methods, - * such as {@link CacheProjection#peek(Object, Collection)}, - * {@link CacheEntry#peek()}, and others. - * <p> - * The following modes are supported: - * <ul> - * <li>{@link #TX}</li> - * <li>{@link #GLOBAL}</li> - * <li>{@link #SMART}</li> - * <li>{@link #SWAP}</li> - * <li>{@link #DB}</li> - * </ul> - */ -public enum GridCachePeekMode { - /** Peeks value only from in-transaction memory of an ongoing transaction, if any. */ - TX, - - /** Peeks at cache global (not in-transaction) memory. */ - GLOBAL, - - /** - * In this mode value is peeked from in-transaction memory first using {@link #TX} - * mode and then, if it has not been found there, {@link #GLOBAL} mode is used to - * search in committed cached values. - */ - SMART, - - /** Peeks value only from off-heap or cache swap storage without loading swapped value into cache. */ - SWAP, - - /** Peek value from the underlying persistent storage without loading this value into cache. */ - DB, - - /** - * Peek value from near cache only (don't peek from partitioned cache). - * In case of {@link CacheMode#LOCAL} or {@link CacheMode#REPLICATED} cache, - * behaves as {@link #GLOBAL} mode. - */ - NEAR_ONLY, - - /** - * Peek value from partitioned cache only (skip near cache). - * In case of {@link CacheMode#LOCAL} or {@link CacheMode#REPLICATED} cache, - * behaves as {@link #GLOBAL} mode. - */ - PARTITIONED_ONLY; - - /** Enumerated values. */ - private static final GridCachePeekMode[] VALS = values(); - - /** - * Efficiently gets enumerated value from its ordinal. - * - * @param ord Ordinal value. - * @return Enumerated value or {@code null} if ordinal out of range. - */ - @Nullable public static GridCachePeekMode fromOrdinal(byte ord) { - return ord >= 0 && ord < VALS.length ? VALS[ord] : null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicy.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicy.java index a8aaef8..d0f74b4 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicy.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicy.java @@ -20,6 +20,7 @@ package org.apache.ignite.cache.eviction.fifo; import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.cache.eviction.*; +import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.jdk8.backport.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java index afb582c..9fa6941 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java @@ -20,6 +20,7 @@ package org.apache.ignite.cache.eviction.random; import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.cache.eviction.*; +import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/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 2cd1737..dd55284 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 @@ -64,7 +64,7 @@ import java.util.concurrent.locks.*; import static java.util.Collections.*; import static org.apache.ignite.IgniteSystemProperties.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.events.IgniteEventType.*; import static org.apache.ignite.internal.GridClosureCallMode.*; import static org.apache.ignite.internal.processors.cache.CacheFlag.*; @@ -703,6 +703,14 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>, switch (peekMode) { case ALL: + near = true; + primary = true; + backup = true; + + heap = true; + offheap = true; + swap = true; + break; case BACKUP: @@ -760,76 +768,80 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>, if (ctx.portableEnabled()) key = (K)ctx.marshalToPortable(key); - long topVer = ctx.affinity().affinityTopologyVersion(); + V val = null; - int part = ctx.affinity().partition(key); + if (!ctx.isLocal()) { + long topVer = ctx.affinity().affinityTopologyVersion(); - boolean nearKey; + int part = ctx.affinity().partition(key); - if (!(near && primary && backup)) { - boolean keyPrimary = ctx.affinity().primary(ctx.localNode(), part, topVer); + boolean nearKey; - if (keyPrimary) { - if (!primary) - return null; + if (!(near && primary && backup)) { + boolean keyPrimary = ctx.affinity().primary(ctx.localNode(), part, topVer); - nearKey = false; - } - else { - boolean keyBackup = ctx.affinity().belongs(ctx.localNode(), part, topVer); - - if (keyBackup) { - if (!backup) + if (keyPrimary) { + if (!primary) return null; nearKey = false; } else { - if (!near) - return null; + boolean keyBackup = ctx.affinity().belongs(ctx.localNode(), part, topVer); - nearKey = true; + 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; } } - } - 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 (nearKey && !ctx.isNear()) + return null; - if (heap) { - GridCacheEntryEx<K, V> e = nearKey ? peekEx(key) : - (ctx.isNear() ? ctx.near().dht().peekEx(key) : peekEx(key)); + if (heap) { + GridCacheEntryEx<K, V> e = nearKey ? peekEx(key) : + (ctx.isNear() ? ctx.near().dht().peekEx(key) : peekEx(key)); - if (e != null) { - val = e.peek(heap, offheap, swap, topVer); + if (e != null) { + val = e.peek(heap, offheap, swap, topVer); - offheap = false; - swap = false; + offheap = false; + swap = false; + } } - } - if (offheap || swap) { - GridCacheSwapManager<K, V> swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap(); + if (offheap || swap) { + GridCacheSwapManager<K, V> swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap(); - GridCacheSwapEntry<V> swapEntry = swapMgr.read(key, offheap, swap); + GridCacheSwapEntry<V> swapEntry = swapMgr.read(key, offheap, swap); - val = swapEntry != null ? swapEntry.value() : null; + val = swapEntry != null ? swapEntry.value() : null; + } } + else + val = localCachePeek0(key, heap, offheap, swap); if (ctx.portableEnabled()) val = (V)ctx.unwrapPortableIfNeeded(val, ctx.keepPortable()); @@ -844,6 +856,38 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>, } } + /** + * @param key Key. + * @param heap Read heap flag. + * @param offheap Read offheap flag. + * @param swap Read swap flag. + * @return Value. + * @throws GridCacheEntryRemovedException If entry removed. + * @throws IgniteCheckedException If failed. + */ + @Nullable private V localCachePeek0(K key, boolean heap, boolean offheap, boolean swap) + throws GridCacheEntryRemovedException, IgniteCheckedException { + assert ctx.isLocal(); + assert heap || offheap || swap; + + if (heap) { + GridCacheEntryEx<K, V> e = peekEx(key); + + if (e != null) + return e.peek(heap, offheap, swap, -1); + } + + if (offheap || swap) { + GridCacheSwapManager<K, V> swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap(); + + GridCacheSwapEntry<V> swapEntry = swapMgr.read(key, offheap, swap); + + return swapEntry != null ? swapEntry.value() : null; + } + + return null; + } + /** {@inheritDoc} */ @Override public V peek(K key) { return peek(key, (IgnitePredicate<CacheEntry<K, V>>)null); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/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 808336a..6df49e5 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 @@ -593,8 +593,10 @@ public interface GridCacheEntryEx<K, V> { * @param heap Read from heap flag. * @param offheap Read from offheap flag. * @param swap Read from swap flag. + * @param topVer Topology version.. * @return Value. * @throws GridCacheEntryRemovedException If entry has been removed. + * @throws IgniteCheckedException If failed. */ @Nullable public V peek(boolean heap, boolean offheap, boolean swap, long topVer) throws GridCacheEntryRemovedException, IgniteCheckedException; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryImpl.java index 5b0e9c5..b27dd2a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryImpl.java @@ -34,7 +34,7 @@ import java.util.*; import java.util.concurrent.*; import static org.apache.ignite.cache.CacheMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.internal.processors.cache.GridCacheUtils.*; /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionEntry.java index 67f48a8..91fc7ef 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionEntry.java @@ -34,7 +34,7 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; import static org.apache.ignite.cache.CacheMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; /** * Entry wrapper that never obscures obsolete entries from user. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheFilterEvaluationEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheFilterEvaluationEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheFilterEvaluationEntry.java index 32bbdca..9e4c684 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheFilterEvaluationEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheFilterEvaluationEntry.java @@ -27,7 +27,7 @@ import org.jetbrains.annotations.*; import java.util.*; import java.util.concurrent.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; /** * Entry implementation for passing raw cache map entries through filters. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePeekMode.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePeekMode.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePeekMode.java new file mode 100644 index 0000000..b50dd18 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePeekMode.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import org.jetbrains.annotations.*; + +import java.util.*; + +/** + * Enumeration of all supported cache peek modes. Peek modes can be passed into various + * {@code 'CacheProjection.peek(..)'} and {@code CacheEntry.peek(..)} methods, + * such as {@link org.apache.ignite.cache.CacheProjection#peek(Object, Collection)}, + * {@link org.apache.ignite.cache.CacheEntry#peek()}, and others. + * <p> + * The following modes are supported: + * <ul> + * <li>{@link #TX}</li> + * <li>{@link #GLOBAL}</li> + * <li>{@link #SMART}</li> + * <li>{@link #SWAP}</li> + * <li>{@link #DB}</li> + * </ul> + */ +public enum GridCachePeekMode { + /** Peeks value only from in-transaction memory of an ongoing transaction, if any. */ + TX, + + /** Peeks at cache global (not in-transaction) memory. */ + GLOBAL, + + /** + * In this mode value is peeked from in-transaction memory first using {@link #TX} + * mode and then, if it has not been found there, {@link #GLOBAL} mode is used to + * search in committed cached values. + */ + SMART, + + /** Peeks value only from off-heap or cache swap storage without loading swapped value into cache. */ + SWAP, + + /** Peek value from the underlying persistent storage without loading this value into cache. */ + DB, + + /** + * Peek value from near cache only (don't peek from partitioned cache). + * In case of {@link org.apache.ignite.cache.CacheMode#LOCAL} or {@link org.apache.ignite.cache.CacheMode#REPLICATED} cache, + * behaves as {@link #GLOBAL} mode. + */ + NEAR_ONLY, + + /** + * Peek value from partitioned cache only (skip near cache). + * In case of {@link org.apache.ignite.cache.CacheMode#LOCAL} or {@link org.apache.ignite.cache.CacheMode#REPLICATED} cache, + * behaves as {@link #GLOBAL} mode. + */ + PARTITIONED_ONLY; + + /** Enumerated values. */ + private static final GridCachePeekMode[] VALS = values(); + + /** + * Efficiently gets enumerated value from its ordinal. + * + * @param ord Ordinal value. + * @return Enumerated value or {@code null} if ordinal out of range. + */ + @Nullable public static GridCachePeekMode fromOrdinal(byte ord) { + return ord >= 0 && ord < VALS.length ? VALS[ord] : null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java index 5fac8f0..d3d43c0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java @@ -49,7 +49,7 @@ import static org.apache.ignite.cache.CacheDistributionMode.*; import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CachePreloadMode.*; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.internal.GridNodeAttributes.*; import static org.apache.ignite.internal.GridTopic.*; import static org.apache.ignite.internal.processors.cache.GridCacheOperation.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridPartitionedCacheEntryImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridPartitionedCacheEntryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridPartitionedCacheEntryImpl.java index 7610bd2..2fc3a93 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridPartitionedCacheEntryImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridPartitionedCacheEntryImpl.java @@ -34,7 +34,7 @@ import java.io.*; import java.util.*; import java.util.concurrent.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; /** * Partitioned cache entry public API. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntryImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntryImpl.java index 066002c..4984624 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntryImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntryImpl.java @@ -28,7 +28,7 @@ import org.jetbrains.annotations.*; import java.io.*; import java.util.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.internal.processors.cache.GridCacheUtils.*; /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index 414d64b..b7fa3ef 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -19,7 +19,6 @@ package org.apache.ignite.internal.processors.cache.distributed.dht.atomic; import org.apache.ignite.*; import org.apache.ignite.cache.CacheEntry; -import org.apache.ignite.cache.*; import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.cluster.*; @@ -56,7 +55,7 @@ import java.util.concurrent.locks.*; import static org.apache.ignite.IgniteSystemProperties.*; import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.internal.processors.cache.GridCacheOperation.*; import static org.apache.ignite.internal.processors.cache.GridCacheUtils.*; import static org.apache.ignite.internal.processors.dr.GridDrType.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java index 83fddb0..b64911a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java @@ -39,7 +39,7 @@ import org.jetbrains.annotations.*; import java.io.*; import java.util.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.internal.processors.cache.CacheFlag.*; /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java index 4780429..a235259 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java @@ -36,7 +36,7 @@ import javax.cache.expiry.*; import java.io.*; import java.util.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.internal.processors.cache.CacheFlag.*; import static org.apache.ignite.internal.processors.cache.GridCacheUtils.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java index 81b4624..5a9fdb1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java @@ -32,7 +32,7 @@ import org.jetbrains.annotations.*; import java.io.*; import java.util.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; /** * Transaction created by system implicitly on remote nodes. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java index a4d7c3a..e91ae91 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java @@ -45,7 +45,7 @@ import java.util.concurrent.locks.*; import static java.util.concurrent.TimeUnit.*; import static org.apache.ignite.cache.CacheMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.events.IgniteEventType.*; import static org.apache.ignite.testframework.GridTestUtils.*; import static org.apache.ignite.transactions.IgniteTxConcurrency.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapSelfTest.java index bb8ae3c..0fb3d7d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapSelfTest.java @@ -39,7 +39,7 @@ import java.util.concurrent.atomic.*; import static java.util.concurrent.TimeUnit.*; import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.configuration.IgniteDeploymentMode.*; import static org.apache.ignite.events.IgniteEventType.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalPeekTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalPeekTest.java new file mode 100644 index 0000000..4c3eb6a --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalPeekTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.cache.*; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheMode.*; + +/** + * + */ +public class IgniteCacheAtomicLocalPeekTest extends IgniteCachePeekAbstractTest { + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return ATOMIC; + } + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 1; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return LOCAL; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedPeekTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedPeekTest.java new file mode 100644 index 0000000..4d34827 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedPeekTest.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.cache.*; + +import static org.apache.ignite.cache.CacheMode.*; + +/** + * + */ +public class IgniteCacheAtomicReplicatedPeekTest extends IgniteCacheAtomicPeekTest { + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return REPLICATED; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/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 index cd97c75..33e4cd6 100644 --- 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 @@ -29,6 +29,7 @@ import org.apache.ignite.spi.swapspace.inmemory.*; import java.util.*; import static org.apache.ignite.cache.CacheDistributionMode.*; +import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CachePeekMode.*; /** @@ -79,137 +80,216 @@ public abstract class IgniteCachePeekAbstractTest extends IgniteCacheAbstractTes * @throws Exception If failed. */ public void testLocalPeek() throws Exception { - checkAffinity(); + if (cacheMode() == LOCAL) { + checkAffinityLocalCache(); - checkStorage(); + checkStorage(0); + } + else { + checkAffinityPeek(0); + + checkAffinityPeek(1); + + checkStorage(0); + + checkStorage(1); + } } /** * @throws Exception If failed. */ - private void checkAffinity() throws Exception { + private void checkAffinityLocalCache() throws Exception { IgniteCache<Integer, String> cache0 = jcache(0); - Integer key = nearKey(cache0); - final String val = "1"; - cache0.put(key, val); + for (int i = 0; i < HEAP_ENTRIES; i++) + cache0.put(i, val); + + try { + for (int i = 0; i < HEAP_ENTRIES; i++) { + assertEquals(val, cache0.localPeek(i)); + assertEquals(val, cache0.localPeek(i, ALL)); + assertEquals(val, cache0.localPeek(i, PRIMARY)); + assertEquals(val, cache0.localPeek(i, BACKUP)); + assertEquals(val, cache0.localPeek(i, NEAR)); + } + } + finally { + for (int i = 0; i < HEAP_ENTRIES; i++) + cache0.remove(i); + } + } + + /** + * @param nodeIdx Node index. + * @throws Exception If failed. + */ + private void checkAffinityPeek(int nodeIdx) throws Exception { + IgniteCache<Integer, String> cache0 = jcache(nodeIdx); - 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)); + final String val = "1"; - CacheAffinity<Integer> aff = ignite(0).affinity(null); + Integer key = null; - for (int i = 1; i < gridCount(); i++) { - IgniteCache<Integer, String> cache = jcache(i); + try { + if (cacheMode() == REPLICATED) { + key = backupKey(cache0); - assertNull(cache.localPeek(key, NEAR)); + cache0.put(key, val); - 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)); + assertEquals(val, cache0.localPeek(key, ALL)); + assertEquals(val, cache0.localPeek(key, BACKUP)); + assertNull(cache0.localPeek(key, NEAR)); + assertNull(cache0.localPeek(key, PRIMARY)); } else { - assertNull(cache.localPeek(key, ALL)); - assertNull(cache.localPeek(key, PRIMARY)); - assertNull(cache.localPeek(key, BACKUP)); + key = nearKey(cache0); + + cache0.put(key, val); + + boolean hasNearCache = nodeIdx == 0 ; + + if (hasNearCache) { + assertEquals(val, cache0.localPeek(key, NEAR)); + assertEquals(val, cache0.localPeek(key, ALL)); + } + else { + assertNull(cache0.localPeek(key, NEAR)); + assertNull(cache0.localPeek(key, ALL)); + } + + assertNull(cache0.localPeek(key, PRIMARY)); + assertNull(cache0.localPeek(key, BACKUP)); + } + + CacheAffinity<Integer> aff = ignite(0).affinity(null); + + for (int i = 0; i < gridCount(); i++) { + if (i == nodeIdx) + continue; + + 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)); + } } } + finally { + if (key != null) + cache0.remove(key); + } } /** + * @param nodeIdx Node index. * @throws Exception If failed. */ - private void checkStorage() throws Exception { - IgniteCache<Integer, String> cache0 = jcache(0); + private void checkStorage(int nodeIdx) throws Exception { + IgniteCache<Integer, String> cache0 = jcache(nodeIdx); List<Integer> keys = primaryKeys(cache0, 100, 10_000); - final String val = "test_value"; + try { + final String val = "test_value"; - for (Integer key : keys) - cache0.put(key, val); + for (Integer key : keys) + cache0.put(key, val); - GridTestSwapSpaceSpi swap = (GridTestSwapSpaceSpi)ignite(0).configuration().getSwapSpaceSpi(); + GridTestSwapSpaceSpi swap = (GridTestSwapSpaceSpi)ignite(nodeIdx).configuration().getSwapSpaceSpi(); - Set<Integer> swapKeys = new HashSet<>(); + Set<Integer> swapKeys = new HashSet<>(); - final String spaceName = "gg-swap-cache-dflt"; + final String spaceName = "gg-swap-cache-dflt"; - IgniteSpiCloseableIterator<Integer> it = swap.keyIterator(spaceName, null); + IgniteSpiCloseableIterator<Integer> it = swap.keyIterator(spaceName, null); - assertNotNull(it); + assertNotNull(it); - while (it.hasNext()) - assertTrue(swapKeys.add(it.next())); + while (it.hasNext()) + assertTrue(swapKeys.add(it.next())); - assertFalse(swapKeys.isEmpty()); + assertFalse(swapKeys.isEmpty()); - assertTrue(swapKeys.size() + HEAP_ENTRIES < 100); + assertTrue(swapKeys.size() + HEAP_ENTRIES < 100); - Set<Integer> offheapKeys = new HashSet<>(); + Set<Integer> offheapKeys = new HashSet<>(); - GridCacheAdapter<Integer, String> internalCache = - ((IgniteKernal)ignite(0)).context().cache().<Integer, String>internalCache(); + GridCacheAdapter<Integer, String> internalCache = + ((IgniteKernal)ignite(nodeIdx)).context().cache().internalCache(); - Iterator<Map.Entry<Integer, String>> offheapIt = - internalCache.context().near().dht().context().swap().lazyOffHeapIterator(); + Iterator<Map.Entry<Integer, String>> offheapIt; - while (offheapIt.hasNext()) { - Map.Entry<Integer, String> e = offheapIt.next(); + if (internalCache.context().isNear()) + offheapIt = internalCache.context().near().dht().context().swap().lazyOffHeapIterator(); + else + offheapIt = internalCache.context().swap().lazyOffHeapIterator(); - assertTrue(offheapKeys.add(e.getKey())); + while (offheapIt.hasNext()) { + Map.Entry<Integer, String> e = offheapIt.next(); - assertFalse(swapKeys.contains(e.getKey())); - } + assertTrue(offheapKeys.add(e.getKey())); - assertFalse(offheapKeys.isEmpty()); + assertFalse(swapKeys.contains(e.getKey())); + } - Set<Integer> heapKeys = new HashSet<>(keys); + assertFalse(offheapKeys.isEmpty()); - heapKeys.removeAll(offheapKeys); - heapKeys.removeAll(swapKeys); + Set<Integer> heapKeys = new HashSet<>(keys); - assertFalse(heapKeys.isEmpty()); + heapKeys.removeAll(offheapKeys); + heapKeys.removeAll(swapKeys); - log.info("Keys [swap=" + swapKeys.size() + - ", offheap=" + offheapKeys.size() + - ", heap=" + heapKeys.size() + ']'); + assertFalse(heapKeys.isEmpty()); - assertEquals(100, swapKeys.size() + offheapKeys.size() + heapKeys.size()); + log.info("Keys [swap=" + swapKeys.size() + + ", offheap=" + offheapKeys.size() + + ", heap=" + heapKeys.size() + ']'); - for (Integer key : swapKeys) { - assertEquals(val, cache0.localPeek(key, SWAP)); + assertEquals(100, swapKeys.size() + offheapKeys.size() + heapKeys.size()); - assertNull(cache0.localPeek(key, ONHEAP)); - assertNull(cache0.localPeek(key, OFFHEAP)); - } + for (Integer key : swapKeys) { + assertEquals(val, cache0.localPeek(key, SWAP)); + + assertNull(cache0.localPeek(key, ONHEAP)); + assertNull(cache0.localPeek(key, OFFHEAP)); + } - for (Integer key : offheapKeys) { - assertEquals(val, cache0.localPeek(key, OFFHEAP)); + for (Integer key : offheapKeys) { + assertEquals(val, cache0.localPeek(key, OFFHEAP)); - assertNull(cache0.localPeek(key, ONHEAP)); - assertNull(cache0.localPeek(key, SWAP)); - } + assertNull(cache0.localPeek(key, ONHEAP)); + assertNull(cache0.localPeek(key, SWAP)); + } - for (Integer key : heapKeys) { - assertEquals(val, cache0.localPeek(key, ONHEAP)); + for (Integer key : heapKeys) { + assertEquals(val, cache0.localPeek(key, ONHEAP)); - assertNull(cache0.localPeek(key, SWAP)); - assertNull(cache0.localPeek(key, OFFHEAP)); + assertNull(cache0.localPeek(key, SWAP)); + assertNull(cache0.localPeek(key, OFFHEAP)); + } + } + finally { + cache0.removeAll(new HashSet<>(keys)); } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalPeekTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalPeekTest.java new file mode 100644 index 0000000..f4b70cf --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalPeekTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.cache.*; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheMode.*; + +/** + * + */ +public class IgniteCacheTxLocalPeekTest extends IgniteCachePeekAbstractTest { + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return TRANSACTIONAL; + } + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 1; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return LOCAL; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxPeekTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxPeekTest.java new file mode 100644 index 0000000..0ddeaaf --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxPeekTest.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 IgniteCacheTxPeekTest extends IgniteCachePeekAbstractTest { + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 4; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return TRANSACTIONAL; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() { + return PRIMARY; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedPeekTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedPeekTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedPeekTest.java new file mode 100644 index 0000000..3b0f0f6 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedPeekTest.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.cache.*; + +import static org.apache.ignite.cache.CacheMode.*; + +/** + * + */ +public class IgniteCacheTxReplicatedPeekTest extends IgniteCacheTxPeekTest { + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return REPLICATED; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtInternalEntrySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtInternalEntrySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtInternalEntrySelfTest.java index cb554ea..388f3ec 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtInternalEntrySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtInternalEntrySelfTest.java @@ -38,7 +38,7 @@ import java.util.*; import static org.apache.ignite.cache.CacheAtomicityMode.*; import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CachePreloadMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; /** * Tests for internal DHT entry. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMultiNodeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMultiNodeSelfTest.java index d03f841..9fb06d7 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMultiNodeSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMultiNodeSelfTest.java @@ -44,7 +44,7 @@ import java.util.concurrent.locks.*; import static org.apache.ignite.cache.CacheAtomicityMode.*; import static org.apache.ignite.cache.CacheDistributionMode.*; import static org.apache.ignite.cache.CacheMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.transactions.IgniteTxConcurrency.*; import static org.apache.ignite.transactions.IgniteTxIsolation.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java index 6b6e1bb..c176c43 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.*; import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CachePreloadMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.events.IgniteEventType.*; /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheMockEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheMockEntry.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheMockEntry.java index e09fc75..53bf2e9 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheMockEntry.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheMockEntry.java @@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.cache.eviction; import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.internal.*; +import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.util.future.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.tostring.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java index f6e1e11..eb4e7ea 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java @@ -367,6 +367,13 @@ public class IgniteCacheTestSuite extends TestSuite { suite.addTestSuite(IgniteCacheTxNearEnabledNoWriteThroughTest.class); suite.addTestSuite(IgniteCacheTxLocalNoWriteThroughTest.class); + suite.addTestSuite(IgniteCacheAtomicPeekTest.class); + suite.addTestSuite(IgniteCacheAtomicReplicatedPeekTest.class); + suite.addTestSuite(IgniteCacheAtomicLocalPeekTest.class); + suite.addTestSuite(IgniteCacheTxPeekTest.class); + suite.addTestSuite(IgniteCacheTxLocalPeekTest.class); + suite.addTestSuite(IgniteCacheTxReplicatedPeekTest.class); + // TODO: IGNITE-114. // suite.addTestSuite(IgniteCacheInvokeReadThroughTest.class); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapAndSwapSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapAndSwapSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapAndSwapSelfTest.java index 60281b7..6823032 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapAndSwapSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapAndSwapSelfTest.java @@ -39,7 +39,7 @@ import java.util.concurrent.atomic.*; import static org.apache.ignite.cache.CacheAtomicityMode.*; import static org.apache.ignite.cache.CacheDistributionMode.*; import static org.apache.ignite.cache.CacheMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.configuration.IgniteDeploymentMode.*; import static org.apache.ignite.events.IgniteEventType.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/78c88cbc/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapSelfTest.java index 7972eed..21bd192 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapSelfTest.java @@ -39,7 +39,7 @@ import java.util.concurrent.atomic.*; import static java.util.concurrent.TimeUnit.*; import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; -import static org.apache.ignite.cache.GridCachePeekMode.*; +import static org.apache.ignite.internal.processors.cache.GridCachePeekMode.*; import static org.apache.ignite.configuration.IgniteDeploymentMode.*; import static org.apache.ignite.events.IgniteEventType.*;