This is an automated email from the ASF dual-hosted git repository. ptupitsyn pushed a commit to branch ignite-14067 in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 66ef7decf714a845d85b892e49ce42d3a6357702 Author: Pavel Tupitsyn <[email protected]> AuthorDate: Thu Jan 28 12:52:15 2021 +0300 Improve IgniteTxStateImpl.validateTopology for single cache scenario --- .../cache/transactions/IgniteTxStateImpl.java | 46 +++++++++++++++------- .../processors/cache/GridCacheTestEntryEx.java | 6 +++ 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java index 00d4817..b331a71 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxStateImpl.java @@ -30,6 +30,7 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.cache.CacheInterceptor; import org.apache.ignite.cache.CacheWriteSynchronizationMode; import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheInvalidStateException; import org.apache.ignite.internal.processors.cache.CacheStoppedException; import org.apache.ignite.internal.processors.cache.GridCacheContext; @@ -138,36 +139,53 @@ public class IgniteTxStateImpl extends IgniteTxLocalStateAdapter { boolean read, GridDhtTopologyFuture topFut ) { - Map<Integer, Set<KeyCacheObject>> keysByCacheId = new HashMap<>(); + if (activeCacheIds.size() == 1) { + IgniteTxKey anyKey = txMap.keySet().iterator().next(); + + int cacheId = anyKey.cacheId(); + GridCacheContext ctx = cctx.cacheContext(cacheId); - for (IgniteTxKey key : txMap.keySet()) { - Set<KeyCacheObject> set = keysByCacheId.get(key.cacheId()); + assert ctx != null : cacheId; - if (set == null) - keysByCacheId.put(key.cacheId(), set = new HashSet<>()); + CacheInvalidStateException err = topFut.validateCache(ctx, recovery(), read, null, txMap.keySet()); - set.add(key.key()); + if (err != null) + return err; } + else { + Map<Integer, Set<KeyCacheObject>> keysByCacheId = new HashMap<>(); - for (Map.Entry<Integer, Set<KeyCacheObject>> e : keysByCacheId.entrySet()) { - int cacheId = e.getKey(); + for (IgniteTxKey key : txMap.keySet()) { + Set<KeyCacheObject> set = keysByCacheId.get(key.cacheId()); - GridCacheContext ctx = cctx.cacheContext(cacheId); + if (set == null) + keysByCacheId.put(key.cacheId(), set = new HashSet<>()); - assert ctx != null : cacheId; + set.add(key.key()); + } - CacheInvalidStateException err = topFut.validateCache(ctx, recovery(), read, null, e.getValue()); + for (Map.Entry<Integer, Set<KeyCacheObject>> e : keysByCacheId.entrySet()) { + int cacheId = e.getKey(); - if (err != null) - return err; + GridCacheContext ctx = cctx.cacheContext(cacheId); + + assert ctx != null : cacheId; + + CacheInvalidStateException err = topFut.validateCache(ctx, recovery(), read, null, e.getValue()); + + if (err != null) + return err; + } } + AffinityTopologyVersion topVer = topFut.topologyVersion(); + for (int i = 0; i < activeCacheIds.size(); i++) { int cacheId = activeCacheIds.get(i); GridCacheContext<?, ?> cacheCtx = cctx.cacheContext(cacheId); - if (CU.affinityNodes(cacheCtx, topFut.topologyVersion()).isEmpty()) { + if (CU.affinityNodes(cacheCtx, topVer).isEmpty()) { return new ClusterTopologyServerNotFoundException("Failed to map keys for cache (all " + "partition nodes left the grid): " + cacheCtx.name()); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java index c406054..f024c16 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java @@ -800,6 +800,12 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr return mvcc.localCandidates(exclude); } + @Override + public Collection<GridCacheMvccCandidate> localCandidatesMax(GridCacheVersion maxVer) throws GridCacheEntryRemovedException { + // TODO + return null; + } + /** @inheritDoc */ Collection<GridCacheMvccCandidate> localCandidates(boolean reentries, GridCacheVersion... exclude) { return mvcc.localCandidates(reentries, exclude);
