Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 44FF919DE1 for ; Thu, 28 Apr 2016 13:01:47 +0000 (UTC) Received: (qmail 75009 invoked by uid 500); 28 Apr 2016 13:01:47 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 74779 invoked by uid 500); 28 Apr 2016 13:01:46 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 74135 invoked by uid 99); 28 Apr 2016 13:01:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Apr 2016 13:01:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 007F9E983B; Thu, 28 Apr 2016 13:01:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Thu, 28 Apr 2016 13:01:59 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [15/35] ignite git commit: IGNITE-2948 - Optimize usage of GridCacheConcurrentMap IGNITE-2948 - Optimize usage of GridCacheConcurrentMap Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3be3d16b Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3be3d16b Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3be3d16b Branch: refs/heads/ignite-db-x-10884 Commit: 3be3d16b0899be7440a60d3eb5c476b789b34bfb Parents: 00f8d65 Author: Yakov Zhdanov Authored: Tue Apr 26 15:07:28 2016 +0300 Committer: Yakov Zhdanov Committed: Tue Apr 26 15:07:28 2016 +0300 ---------------------------------------------------------------------- .../internal/benchmarks/model/IntValue.java | 19 +- .../internal/binary/BinaryObjectImpl.java | 14 + .../processors/cache/GridCacheAdapter.java | 448 ++-- .../cache/GridCacheAffinityManager.java | 10 +- .../cache/GridCacheClearAllRunnable.java | 2 +- .../cache/GridCacheConcurrentMap.java | 1996 +----------------- .../cache/GridCacheConcurrentMapImpl.java | 344 +++ .../processors/cache/GridCacheContext.java | 56 +- .../cache/GridCacheDeploymentManager.java | 2 +- .../processors/cache/GridCacheEntrySet.java | 113 - .../cache/GridCacheEvictionManager.java | 2 +- .../processors/cache/GridCacheKeySet.java | 104 - .../processors/cache/GridCacheMapEntry.java | 22 +- .../processors/cache/GridCacheProcessor.java | 1 - .../processors/cache/GridCacheProxyImpl.java | 2 +- .../processors/cache/GridCacheUtils.java | 1 - .../processors/cache/GridNoStorageCacheMap.java | 107 + .../processors/cache/IgniteInternalCache.java | 2 +- .../processors/cache/KeyCacheObject.java | 11 + .../processors/cache/KeyCacheObjectImpl.java | 32 +- .../binary/CacheObjectBinaryProcessorImpl.java | 24 +- .../GridDistributedCacheAdapter.java | 4 +- .../distributed/GridDistributedLockRequest.java | 19 +- .../GridDistributedTxRemoteAdapter.java | 1 - .../GridDistributedUnlockRequest.java | 16 +- .../dht/GridCachePartitionedConcurrentMap.java | 191 ++ .../dht/GridClientPartitionTopology.java | 7 - .../distributed/dht/GridDhtCacheAdapter.java | 77 +- .../distributed/dht/GridDhtCacheEntry.java | 25 +- .../distributed/dht/GridDhtLocalPartition.java | 152 +- .../distributed/dht/GridDhtLockRequest.java | 16 +- .../dht/GridDhtPartitionTopology.java | 7 - .../dht/GridDhtPartitionTopologyImpl.java | 281 ++- .../distributed/dht/GridDhtUnlockRequest.java | 15 +- .../distributed/dht/GridNoStorageCacheMap.java | 122 -- .../dht/GridPartitionedGetFuture.java | 2 +- .../dht/GridPartitionedSingleGetFuture.java | 2 +- .../dht/atomic/GridDhtAtomicCache.java | 75 +- .../dht/atomic/GridDhtAtomicUpdateRequest.java | 22 +- .../dht/atomic/GridNearAtomicUpdateFuture.java | 6 +- .../dht/atomic/GridNearAtomicUpdateRequest.java | 31 +- .../dht/colocated/GridDhtColocatedCache.java | 13 +- .../dht/preloader/GridDhtPartitionDemander.java | 2 +- .../dht/preloader/GridDhtPartitionSupplier.java | 8 +- .../distributed/near/GridNearCacheAdapter.java | 94 +- .../distributed/near/GridNearGetFuture.java | 2 +- .../distributed/near/GridNearGetRequest.java | 45 +- .../distributed/near/GridNearLockRequest.java | 16 +- .../near/GridNearSingleGetRequest.java | 22 +- .../distributed/near/GridNearUnlockRequest.java | 21 +- .../processors/cache/local/GridLocalCache.java | 7 +- .../local/atomic/GridLocalAtomicCache.java | 24 +- .../cache/transactions/IgniteInternalTx.java | 1 - .../cache/transactions/IgniteTxAdapter.java | 1 - .../cache/transactions/IgniteTxEntry.java | 33 +- .../cacheobject/IgniteCacheObjectProcessor.java | 10 + .../IgniteCacheObjectProcessorImpl.java | 36 +- .../GridCacheAtomicReferenceImpl.java | 2 +- .../internal/util/PartitionedReadOnlySet.java | 71 + .../util/StripedCompositeReadWriteLock.java | 10 + .../ignite/internal/util/lang/GridFunc.java | 3 +- .../ignite/internal/visor/cache/VisorCache.java | 6 +- .../GridCachePreloadingEvictionsSelfTest.java | 4 +- .../cache/GridCacheTtlManagerSelfTest.java | 2 +- ...idCacheValueConsistencyAbstractSelfTest.java | 3 +- .../IgniteDynamicClientCacheStartSelfTest.java | 10 - .../IgniteTxStoreExceptionAbstractSelfTest.java | 8 +- .../GridCacheBinaryObjectsAbstractSelfTest.java | 2 +- ...actQueueFailoverDataConsistencySelfTest.java | 2 +- .../GridCacheQueueCleanupSelfTest.java | 4 +- .../GridCacheSequenceApiSelfAbstractTest.java | 37 - .../GridCacheSetAbstractSelfTest.java | 5 +- .../GridCacheSetFailoverAbstractSelfTest.java | 8 +- .../IgniteDataStructureUniqueNameTest.java | 3 +- .../IgnitePartitionedQueueNoBackupsTest.java | 6 +- .../IgnitePartitionedSetNoBackupsSelfTest.java | 6 +- .../distributed/dht/GridCacheDhtTestUtils.java | 9 +- .../near/GridCacheNearOneNodeSelfTest.java | 4 +- .../processors/igfs/IgfsAbstractSelfTest.java | 10 +- 79 files changed, 1958 insertions(+), 2975 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/3be3d16b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/model/IntValue.java ---------------------------------------------------------------------- diff --git a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/model/IntValue.java b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/model/IntValue.java index 0a97e36..45fbe79 100644 --- a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/model/IntValue.java +++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/model/IntValue.java @@ -85,7 +85,24 @@ public class IntValue implements Externalizable, Binarylizable { } /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + IntValue value = (IntValue)o; + + return val == value.val; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return val; + } + + /** {@inheritDoc} */ @Override public String toString() { return "Value [id=" + val + ']'; } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/3be3d16b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java index 0997d6f..fa10de3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java @@ -72,6 +72,10 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern @GridDirectTransient private boolean detachAllowed; + /** */ + @GridDirectTransient + private int part = -1; + /** * For {@link Externalizable}. */ @@ -94,6 +98,16 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern } /** {@inheritDoc} */ + @Override public int partition() { + return part; + } + + /** {@inheritDoc} */ + @Override public void partition(int part) { + this.part = part; + } + + /** {@inheritDoc} */ @Override public byte cacheObjectType() { return TYPE_BINARY; } http://git-wip-us.apache.org/repos/asf/ignite/blob/3be3d16b/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 d807e26..8c1a750 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 @@ -23,8 +23,8 @@ import java.io.InvalidObjectException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.io.ObjectStreamException; +import java.util.AbstractSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -101,13 +101,11 @@ import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFi import org.apache.ignite.internal.processors.task.GridInternal; import org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException; import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException; -import org.apache.ignite.internal.util.F0; import org.apache.ignite.internal.util.future.GridCompoundFuture; import org.apache.ignite.internal.util.future.GridEmbeddedFuture; import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.lang.GridClosureException; -import org.apache.ignite.internal.util.lang.GridTriple; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.C1; import org.apache.ignite.internal.util.typedef.C2; @@ -132,7 +130,6 @@ import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.lang.IgniteOutClosure; import org.apache.ignite.lang.IgnitePredicate; import org.apache.ignite.lang.IgniteProductVersion; -import org.apache.ignite.lang.IgniteUuid; import org.apache.ignite.mxbean.CacheMetricsMXBean; import org.apache.ignite.plugin.security.SecurityPermission; import org.apache.ignite.resources.IgniteInstanceResource; @@ -146,8 +143,6 @@ import org.jsr166.LongAdder8; import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_KEY_VALIDATION_DISABLED; import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT; -import static org.apache.ignite.events.EventType.EVT_CACHE_ENTRY_CREATED; -import static org.apache.ignite.events.EventType.EVT_CACHE_ENTRY_DESTROYED; import static org.apache.ignite.internal.GridClosureCallMode.BROADCAST; import static org.apache.ignite.internal.processors.dr.GridDrType.DR_LOAD; import static org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE; @@ -304,7 +299,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache ctx, int startSize) { - this(ctx, new GridCacheConcurrentMap(ctx, startSize, null)); + this(ctx, null); } /** @@ -312,7 +307,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache ctx, GridCacheConcurrentMap map) { + protected GridCacheAdapter(final GridCacheContext ctx, @Nullable GridCacheConcurrentMap map) { assert ctx != null; this.ctx = ctx; @@ -393,6 +388,22 @@ public abstract class GridCacheAdapter implements IgniteInternalCache context() { @@ -483,7 +494,6 @@ public abstract class GridCacheAdapter implements IgniteInternalCache((GridCacheContext)ctx, (GridCacheAdapter)this, opCtx); } - /** {@inheritDoc} */ @Nullable @Override public ExpiryPolicy expiry() { return null; @@ -541,13 +551,25 @@ public abstract class GridCacheAdapter implements IgniteInternalCache implements IgniteInternalCache implements IgniteInternalCache t = map.putEntryIfObsoleteOrAbsent( + cur = map.putEntryIfObsoleteOrAbsent( topVer, key, null, - create); - - cur = t.get1(); - - GridCacheEntryEx created = t.get2(); - GridCacheEntryEx doomed = t.get3(); - - if (doomed != null && ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED)) - // Event notification. - ctx.events().addEvent(doomed.partition(), - doomed.key(), - locNodeId, - (IgniteUuid)null, - null, - EVT_CACHE_ENTRY_DESTROYED, - null, - false, - null, - false, - null, - null, - null, - true); - - if (created != null) { - // Event notification. - if (ctx.events().isRecordable(EVT_CACHE_ENTRY_CREATED)) - ctx.events().addEvent(created.partition(), - created.key(), - locNodeId, - (IgniteUuid)null, - null, - EVT_CACHE_ENTRY_CREATED, - null, - false, - null, - false, - null, - null, - null, - true); - - if (touch) - ctx.evicts().touch( - cur, - topVer); - } + create, touch); } return cur; } /** - * @return Set of internal cached entry representations, excluding {@link GridCacheInternal} keys. + * @return Set of internal cached entry representations. */ - public Set entries() { - return map.entries0(); + public Iterable entries() { + return allEntries(); } /** - * @return Set of internal cached entry representations, including {@link GridCacheInternal} keys. + * @return Set of internal cached entry representations. */ - public Set allEntries() { - return map.allEntries0(); + public Iterable allEntries() { + return map.entries(); } /** {@inheritDoc} */ @@ -1022,8 +998,8 @@ public abstract class GridCacheAdapter implements IgniteInternalCache> entrySetx(CacheEntryPredicate... filter) { - return map.entriesx(filter); + @Override public Set> entrySetx(final CacheEntryPredicate... filter) { + return new EntrySet(map.entrySet(filter)); } /** {@inheritDoc} */ @@ -1033,22 +1009,57 @@ public abstract class GridCacheAdapter implements IgniteInternalCache keySet() { - return map.keySet(); + return new KeySet(map.entrySet()); } /** {@inheritDoc} */ @Override public Set keySetx() { - return map.keySetx(); + return keySet(); } /** {@inheritDoc} */ @Override public Set primaryKeySet() { - return map.keySet(CU.cachePrimary(ctx.grid().affinity(ctx.name()), ctx.localNode())); + return new KeySet(map.entrySet(CU.cachePrimary(ctx.grid().affinity(ctx.name()), ctx.localNode()))); } /** {@inheritDoc} */ - @Override public Collection values() { - return map.values(); + @Override public Iterable values() { + return values((CacheEntryPredicate[])null); + } + + /** + * Collection of values cached on this node. You cannot modify this collection. + *

+ * Iterator over this collection will not fail if collection was + * concurrently updated by another thread. This means that iterator may or + * may not return latest values depending on whether they were added before + * or after current iterator position. + *

+ * NOTE: this operation is not distributed and returns only the values cached on this node. + * + * @param filter Filters. + * @return Collection of cached values. + */ + public Iterable values(final CacheEntryPredicate... filter) { + return new Iterable() { + @Override public Iterator iterator() { + return new Iterator() { + private final Iterator it = entries().iterator(); + + @Override public boolean hasNext() { + return it.hasNext(); + } + + @Override public V next() { + return (V) it.next().wrap().getValue(); + } + + @Override public void remove() { + throw new UnsupportedOperationException("remove"); + } + }; + } + }; } /** @@ -1058,21 +1069,10 @@ public abstract class GridCacheAdapter implements IgniteInternalCache implements IgniteInternalCache implements IgniteInternalCache implements IgniteInternalCache t = (T2)get(key, !ctx.keepBinary(), true); - CacheEntry val = t != null ? new CacheEntryImplEx<>(key, t.get1(), t.get2()): null; + CacheEntry val = t != null ? new CacheEntryImplEx<>(key, t.get1(), t.get2()) : null; if (ctx.config().getInterceptor() != null) { V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null); @@ -1424,7 +1431,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache fut = getAsync(key, !ctx.keepBinary(), false); if (ctx.config().getInterceptor() != null) - fut = fut.chain(new CX1, V>() { + fut = fut.chain(new CX1, V>() { @Override public V applyx(IgniteInternalFuture f) throws IgniteCheckedException { return (V)ctx.config().getInterceptor().onGet(key, f.get()); } @@ -1451,20 +1458,20 @@ public abstract class GridCacheAdapter implements IgniteInternalCache> fr = fut.chain( new CX1>, CacheEntry>() { - @Override public CacheEntry applyx(IgniteInternalFuture> f) - throws IgniteCheckedException { - T2 t = f.get(); + @Override public CacheEntry applyx(IgniteInternalFuture> f) + throws IgniteCheckedException { + T2 t = f.get(); - CacheEntry val = t != null ? new CacheEntryImplEx<>(key, t.get1(), t.get2()) : null; - if (intercept) { - V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null); + CacheEntry val = t != null ? new CacheEntryImplEx<>(key, t.get1(), t.get2()) : null; + if (intercept) { + V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null); - return new CacheEntryImplEx<>(key, val0, t != null ? t.get2() : null); + return new CacheEntryImplEx<>(key, val0, t != null ? t.get2() : null); + } + else + return val; } - else - return val; - } - }); + }); if (statsEnabled) fut.listen(new UpdateGetTimeStatClosure>(metrics0(), start)); @@ -1516,7 +1523,6 @@ public abstract class GridCacheAdapter implements IgniteInternalCache> getAllAsync(@Nullable final Collection keys) { A.notNull(keys, "keys"); @@ -1541,7 +1547,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache>> getEntriesAsync( + @Override public IgniteInternalFuture>> getEntriesAsync( @Nullable final Collection keys) { A.notNull(keys, "keys"); @@ -1850,7 +1856,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache implements IgniteInternalCache implements IgniteInternalCache fut = asyncOp(new AsyncOp() { @Override public IgniteInternalFuture op(IgniteTxLocalAdapter tx, AffinityTopologyVersion readyTopVer) { Map> invokeMap = - Collections.singletonMap(key, (EntryProcessor) entryProcessor); + Collections.singletonMap(key, (EntryProcessor)entryProcessor); return tx.invokeAsync(ctx, readyTopVer, invokeMap, args); } @@ -2578,7 +2583,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache(metrics0(), start)); return fut; @@ -2912,11 +2917,11 @@ public abstract class GridCacheAdapter implements IgniteInternalCache it = ctx.swap().offHeapKeyIterator(true, true, AffinityTopologyVersion.NONE); - it.hasNext(); ) + it.hasNext(); ) remove((K)it.next()); for (Iterator it = ctx.swap().swapKeyIterator(true, true, AffinityTopologyVersion.NONE); - it.hasNext(); ) + it.hasNext(); ) remove((K)it.next()); removeAll(keySet()); @@ -3436,7 +3441,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache) p, topVer, replicate, ttl); + loadEntry(key, val, ver0, (IgniteBiPredicate)p, topVer, replicate, ttl); } }, args); } @@ -3490,8 +3495,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache localLoadCacheAsync(final IgniteBiPredicate p, - final Object[] args) - { + final Object[] args) { return ctx.closures().callLocalSafe( ctx.projectSafe(new Callable() { @Nullable @Override public Object call() throws IgniteCheckedException { @@ -3596,8 +3600,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache keys, @Nullable ExpiryPolicy plc) - throws IgniteCheckedException - { + throws IgniteCheckedException { final boolean replicate = ctx.isDrEnabled(); final AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion(); @@ -4574,14 +4577,14 @@ public abstract class GridCacheAdapter implements IgniteInternalCache> entrySet(@Nullable CacheEntryPredicate... filter) { - return map.entries(filter); + return entrySetx(filter); } /** * @return Primary entry set. */ public Set> primaryEntrySet() { - return map.entries(CU.cachePrimary(ctx.grid().affinity(ctx.name()), ctx.localNode())); + return new EntrySet(map.entrySet(CU.cachePrimary(ctx.grid().affinity(ctx.name()), ctx.localNode()))); } /** @@ -4612,15 +4615,23 @@ public abstract class GridCacheAdapter implements IgniteInternalCache implements IgniteInternalCache> iterator(final Iterator it, + protected Iterator> iterator(final Iterator it, final boolean deserializeBinary) { return new Iterator>() { { @@ -4807,8 +4818,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache toCacheEntry(GridCacheEntryEx entry, boolean deserializeBinary) - throws IgniteCheckedException, GridCacheEntryRemovedException - { + throws IgniteCheckedException, GridCacheEntryRemovedException { CacheObject val = entry.innerGet( null, null, @@ -5497,7 +5507,8 @@ public abstract class GridCacheAdapter implements IgniteInternalCache p, Object[] loadArgs, + private LoadCacheJob(String cacheName, AffinityTopologyVersion topVer, IgniteBiPredicate p, + Object[] loadArgs, ExpiryPolicy plc) { super(cacheName, topVer); @@ -5710,7 +5721,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache implements IgniteCallable, Externalizable{ + static class LoadKeysCallable implements IgniteCallable, Externalizable { /** */ private static final long serialVersionUID = 0L; @@ -5831,8 +5842,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCachevalue(ctx.cacheObjectContext(), false), (V)val)) @@ -5914,8 +5924,7 @@ public abstract class GridCacheAdapter implements IgniteInternalCache p, Object[] args, - @Nullable ExpiryPolicy plc) - { + @Nullable ExpiryPolicy plc) { this.cacheName = cacheName; this.p = p; this.args = args; @@ -6380,4 +6389,173 @@ public abstract class GridCacheAdapter implements IgniteInternalCache { + /** Internal map entry iterator. */ + private final Iterator internalIterator; + + /** Keep binary flag. */ + private final boolean keepBinary; + + /** Current entry. */ + private GridCacheMapEntry current; + + /** + * Constructor. + * @param internalIterator Internal iterator. + * @param keepBinary Keep binary flag. + */ + private KeySetIterator(Iterator internalIterator, boolean keepBinary) { + this.internalIterator = internalIterator; + this.keepBinary = keepBinary; + } + + /** {@inheritDoc} */ + @Override public boolean hasNext() { + return internalIterator.hasNext(); + } + + /** {@inheritDoc} */ + @Override public K next() { + current = internalIterator.next(); + + return (K)ctx.unwrapBinaryIfNeeded(current.key(), keepBinary, true); + } + + /** {@inheritDoc} */ + @Override public void remove() { + if (current == null) + throw new IllegalStateException(); + + try { + GridCacheAdapter.this.getAndRemove((K)current.key()); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + + current = null; + } + } + + /** + * A wrapper over internal map that provides set semantics and constant-time contains() check. + */ + private final class KeySet extends AbstractSet { + /** Internal entry set. */ + private final Set internalSet; + + /** Keep binary flag. */ + private final boolean keepBinary; + + /** + * Constructor + * @param internalSet Internal set. + */ + private KeySet(Set internalSet) { + this.internalSet = internalSet; + + CacheOperationContext opCtx = ctx.operationContextPerCall(); + + keepBinary = opCtx != null && opCtx.isKeepBinary(); + } + + /** {@inheritDoc} */ + @Override public Iterator iterator() { + return new KeySetIterator(internalSet.iterator(), keepBinary); + } + + /** {@inheritDoc} */ + @Override public int size() { + return F.size(iterator()); + } + + /** {@inheritDoc} */ + @Override public boolean contains(Object o) { + GridCacheMapEntry entry = map.getEntry(ctx.toCacheKeyObject(o)); + + return entry != null && internalSet.contains(entry); + } + } + + /** + * Iterator implementation for EntrySet. + */ + private final class EntryIterator implements Iterator> { + + /** Internal iterator. */ + private final Iterator internalIterator; + + /** Current entry. */ + private GridCacheMapEntry current; + + /** + * Constructor. + * @param internalIterator Internal iterator. + */ + private EntryIterator(Iterator internalIterator) { + this.internalIterator = internalIterator; + } + + /** {@inheritDoc} */ + @Override public boolean hasNext() { + return internalIterator.hasNext(); + } + + /** {@inheritDoc} */ + @Override public Cache.Entry next() { + current = internalIterator.next(); + + return current.wrapLazyValue(); + } + + /** {@inheritDoc} */ + @Override public void remove() { + if (current == null) + throw new IllegalStateException(); + + try { + GridCacheAdapter.this.getAndRemove((K)current.wrapLazyValue().getKey()); + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } + + current = null; + } + } + + /** + * A wrapper over internal map that provides set semantics and constant-time contains() check. + */ + private final class EntrySet extends AbstractSet> { + + /** Internal set. */ + private final Set internalSet; + + /** Constructor. */ + private EntrySet(Set internalSet) { + this.internalSet = internalSet; + } + + /** {@inheritDoc} */ + @Override public Iterator> iterator() { + return new EntryIterator(internalSet.iterator()); + } + + /** {@inheritDoc} */ + @Override public int size() { + return F.size(iterator()); + } + + /** {@inheritDoc} */ + @Override public boolean contains(Object o) { + GridCacheMapEntry entry = map.getEntry(ctx.toCacheKeyObject(o)); + + return entry != null && internalSet.contains(entry); + } + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/3be3d16b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java index f1767e0..5e843dc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java @@ -197,10 +197,18 @@ public class GridCacheAffinityManager extends GridCacheManagerAdapter { public int partition(Object key) { GridAffinityAssignmentCache aff0 = aff; + if (key instanceof KeyCacheObject && ((KeyCacheObject)key).partition() != -1) + return ((KeyCacheObject)key).partition(); + if (aff0 == null) throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name()); - return affFunction.partition(affinityKey(key)); + int p = affFunction.partition(affinityKey(key)); + + if (key instanceof KeyCacheObject) + ((KeyCacheObject)key).partition(p); + + return p; } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/3be3d16b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java index ffce82d..4f97e7b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java @@ -79,7 +79,7 @@ public class GridCacheClearAllRunnable implements Runnable { /** {@inheritDoc} */ @Override public void run() { - Iterator iter = cache.map().stripedEntryIterator(id, totalCnt); + Iterator iter = cache.entries().iterator(); while (iter.hasNext()) clearEntry(iter.next());