Repository: incubator-ignite Updated Branches: refs/heads/ignite-784 [created] c7c3ffed8
#ignite-784: Need to check for null result of 'ClusterNode GridCacheAffinityManager.primary()' Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/c7c3ffed Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/c7c3ffed Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/c7c3ffed Branch: refs/heads/ignite-784 Commit: c7c3ffed8631f54d2f2a6b4dd83e861943baad62 Parents: 4a7479f Author: ivasilinets <ivasilin...@gridgain.com> Authored: Wed Apr 22 17:45:02 2015 +0300 Committer: ivasilinets <ivasilin...@gridgain.com> Committed: Wed Apr 22 17:45:02 2015 +0300 ---------------------------------------------------------------------- .../processors/cache/GridCacheUtils.java | 41 -------------------- .../dht/GridPartitionedGetFuture.java | 3 ++ .../dht/atomic/GridNearAtomicUpdateFuture.java | 6 +++ .../dht/colocated/GridDhtColocatedCache.java | 11 ++++++ .../colocated/GridDhtColocatedLockFuture.java | 2 +- .../distributed/near/GridNearCacheEntry.java | 5 +++ .../distributed/near/GridNearGetFuture.java | 12 ++++-- .../distributed/near/GridNearLockFuture.java | 2 +- .../near/GridNearTransactionalCache.java | 13 +++++++ .../cache/query/GridCacheQueryManager.java | 8 +++- 10 files changed, 55 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7c3ffed/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 9bc7574..848cf17 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 @@ -1022,45 +1022,6 @@ public class GridCacheUtils { } /** - * @param ctx Context. - * @param keys Keys. - * @return Mapped keys. - */ - @SuppressWarnings( {"unchecked", "MismatchedQueryAndUpdateOfCollection"}) - public static <K> Map<ClusterNode, Collection<K>> mapKeysToNodes(GridCacheContext<K, ?> ctx, - Collection<? extends K> keys) { - if (keys == null || keys.isEmpty()) - return Collections.emptyMap(); - - // Map all keys to local node for local caches. - if (ctx.config().getCacheMode() == LOCAL) - return F.asMap(ctx.localNode(), (Collection<K>)keys); - - AffinityTopologyVersion topVer = new AffinityTopologyVersion(ctx.discovery().topologyVersion()); - - if (CU.affinityNodes(ctx, topVer).isEmpty()) - return Collections.emptyMap(); - - if (keys.size() == 1) - return Collections.singletonMap(ctx.affinity().primary(F.first(keys), topVer), (Collection<K>)keys); - - Map<ClusterNode, Collection<K>> map = new GridLeanMap<>(5); - - for (K k : keys) { - ClusterNode primary = ctx.affinity().primary(k, topVer); - - Collection<K> mapped = map.get(primary); - - if (mapped == null) - map.put(primary, mapped = new LinkedList<>()); - - mapped.add(k); - } - - return map; - } - - /** * @param t Exception to check. * @return {@code true} if caused by lock timeout. */ @@ -1228,8 +1189,6 @@ public class GridCacheUtils { ClusterNode primary = ctx.affinity().primary(key, ctx.affinity().affinityTopologyVersion()); - assert primary != null; - return primary; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7c3ffed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java index f37daf8..efeaca6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java @@ -462,6 +462,9 @@ public class GridPartitionedGetFuture<K, V> extends GridCompoundIdentityFuture<M ClusterNode node = cctx.affinity().primary(key, topVer); + if (node == null) + onDone(new ClusterTopologyCheckedException("Cannot find primary node for key " + key + ".")); + remote = !node.isLocal(); LinkedHashMap<KeyCacheObject, Boolean> keys = mapped.get(node); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7c3ffed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java index 974a197..f890a15 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java @@ -557,6 +557,9 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object> ClusterNode primary = F.first(primaryNodes); + if (primary == null) + onDone(new ClusterTopologyCheckedException("Cannot find primary node for the key " + key + ".")); + GridNearAtomicUpdateRequest req = new GridNearAtomicUpdateRequest( cctx.cacheId(), primary.id(), @@ -674,6 +677,9 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object> int i = 0; for (ClusterNode affNode : affNodes) { + if (affNode == null) + onDone(new ClusterTopologyCheckedException("Cannot find primary node for the key " + key + ".")); + UUID nodeId = affNode.id(); GridNearAtomicUpdateRequest mapped = pendingMappings.get(nodeId); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7c3ffed/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 9c59354..3ca7643 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 @@ -425,6 +425,10 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte // Send request to remove from remote nodes. ClusterNode primary = ctx.affinity().primary(key, topVer); + if (primary == null) + throw new ClusterTopologyCheckedException("Failed to unlock key " + key + + ". Cannot find primary node for the key."); + if (!lock.reentry()) { if (!ver.equals(lock.version())) throw new IgniteCheckedException("Failed to unlock (if keys were locked separately, " + @@ -524,6 +528,13 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte ClusterNode primary = ctx.affinity().primary(key, topVer); + if (primary == null) { + log.debug("Filed to unlock key " + key + + ". Cannot find primary node for the key."); + + continue; + } + if (!primary.isLocal()) { // Send request to remove from remote nodes. GridNearUnlockRequest req = map.get(primary); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7c3ffed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java index 7b05065..61d2e7d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java @@ -1052,7 +1052,7 @@ public final class GridDhtColocatedLockFuture<K, V> extends GridCompoundIdentity ClusterNode primary = cctx.affinity().primary(key, topVer); - if (cctx.discovery().node(primary.id()) == null) + if (primary == null || cctx.discovery().node(primary.id()) == null) // If primary node left the grid before lock acquisition, fail the whole future. throw newTopologyException(null, primary.id()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7c3ffed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java index 1e8e3f2..819024c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java @@ -168,6 +168,11 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry { } } + ClusterNode primaryNode = cctx.affinity().primary(key, topVer); + + if (primaryNode == null) + return false; + recordNodeId(cctx.affinity().primary(key, topVer).id(), topVer); dhtVer = e.isNew() || e.isDeleted() ? null : e.version(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7c3ffed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java index e75c49e..13836d3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java @@ -472,7 +472,8 @@ public final class GridNearGetFuture<K, V> extends GridCompoundIdentityFuture<Ma else { primary = cctx.affinity().primary(key, topVer); - if (!primary.isLocal() && cctx.cache().configuration().isStatisticsEnabled() && !skipVals) + if (primary == null || !primary.isLocal() && + cctx.cache().configuration().isStatisticsEnabled() && !skipVals) near.metrics0().onRead(false); } } @@ -510,13 +511,18 @@ public final class GridNearGetFuture<K, V> extends GridCompoundIdentityFuture<Ma savedVers.put(key, nearEntry == null ? null : nearEntry.dhtVersion()); - LinkedHashMap<KeyCacheObject, Boolean> keys = mapped.get(primary); + LinkedHashMap<KeyCacheObject, Boolean> keys = null; + + if (primary != null) + mapped.get(primary); if (keys != null && keys.containsKey(key)) { if (remapCnt.incrementAndGet() > MAX_REMAP_CNT) { onDone(new ClusterTopologyCheckedException("Failed to remap key to a new node after " + MAX_REMAP_CNT + " attempts (key got remapped to the same node) " + - "[key=" + key + ", node=" + U.toShortString(primary) + ", mappings=" + mapped + ']')); + "[key=" + key + + primary != null ? ", node=" + U.toShortString(primary) : ", no primary node for the key " + + ", mappings=" + mapped + ']')); return savedVers; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7c3ffed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java index 789fd93..7bbf7c3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java @@ -1153,7 +1153,7 @@ public final class GridNearLockFuture<K, V> extends GridCompoundIdentityFuture<B ClusterNode primary = cctx.affinity().primary(key, topVer); - if (cctx.discovery().node(primary.id()) == null) + if (primary == null || cctx.discovery().node(primary.id()) == null) // If primary node left the grid before lock acquisition, fail the whole future. throw newTopologyException(null, primary.id()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7c3ffed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java index a0197c7..3d76715 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java @@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.cache.distributed.near; import org.apache.ignite.*; import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; +import org.apache.ignite.internal.cluster.*; import org.apache.ignite.internal.processors.affinity.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.distributed.*; @@ -512,6 +513,10 @@ public class GridNearTransactionalCache<K, V> extends GridNearCacheAdapter<K, V> // Send request to remove from remote nodes. ClusterNode primary = ctx.affinity().primary(key, topVer); + if (primary == null) + throw new ClusterTopologyCheckedException("Filed to unlock key " + key + + ". Cannot find primary node for the key " + key + "."); + GridNearUnlockRequest req = map.get(primary); if (req == null) { @@ -626,6 +631,14 @@ public class GridNearTransactionalCache<K, V> extends GridNearCacheAdapter<K, V> ClusterNode primary = ctx.affinity().primary(key, cand.topologyVersion()); + if (primary == null) { + if (log.isDebugEnabled()) + log.debug("Cannot remove lock for key " + key + + ". Cannot find primary node for the key " + key + "."); + + break; + } + if (!primary.isLocal()) { req = map.get(primary); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7c3ffed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java index 16063af..2d422a1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java @@ -1297,10 +1297,14 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte V val = row.getValue(); - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { + ClusterNode primaryNode = CU.primaryNode(cctx, key); + log.debug("Record [key=" + key + ", val=" + val + ", incBackups=" + - incBackups + "priNode=" + U.id8(CU.primaryNode(cctx, key).id()) + + incBackups + + primaryNode != null ? "priNode=" + U.id8(primaryNode.id()) : "no primary node" + ", node=" + U.id8(cctx.localNode().id()) + ']'); + } if (val == null) { if (log.isDebugEnabled())