/** * @param type Event type. * @return {@code True} if event should be recorded. */ public boolean recordEvent(int type) { if (isReplicated()) { if (type == EVT_CACHE_REBALANCE_STARTED) { if (!rebalanceStartedEvtSent) { rebalanceStartedEvtSent = true; return true; } else return false; } else if (type == EVT_CACHE_REBALANCE_STOPPED) { if (!rebalanceStoppedEvtSent) { rebalanceStoppedEvtSent = true; return true; } else return false; } } return true; }
/** * Check if query may be run locally on all caches mentioned in the query. * * @return {@code true} if query may be run locally on all caches mentioned in the query, i.e. there's no need * to run distributed query. */ public boolean isLocalQuery() { if (selectForUpdate) return false; for (Object o : h2ObjToGridObj.values()) { if (o instanceof GridSqlAlias) o = GridSqlAlias.unwrap((GridSqlAst)o); if (o instanceof GridSqlTable) { GridH2Table tbl = ((GridSqlTable)o).dataTable(); if (tbl != null) { //It's not affinity cache. Can't be local. if (tbl.cacheContext() == null) return false; GridCacheContext cctx = tbl.cacheContext(); if (cctx.mvccEnabled()) return false; if (cctx.isPartitioned()) return false; if (cctx.isReplicated() && !cctx.isReplicatedAffinityNode()) return false; } } } return true; }
/** * @return {@code true} If this is a replicated cache and we are on a data node. */ public boolean isReplicatedAffinityNode() { return isReplicated() && affinityNode(); }
/** * @param loc Enforce local. * @return Local node cluster group. */ private ClusterGroup projection(boolean loc) { GridCacheContext<K, V> ctx = getContextSafe(); if (loc || ctx.isLocal() || ctx.isReplicatedAffinityNode()) return ctx.kernalContext().grid().cluster().forLocal(); if (ctx.isReplicated()) return ctx.kernalContext().grid().cluster().forDataNodes(cacheName).forRandom(); return null; }
/** * @param cacheIds Cache IDs. * @return The first partitioned cache context. */ private GridCacheContext<?,?> findFirstPartitioned(List<Integer> cacheIds) { for (int i = 0; i < cacheIds.size(); i++) { GridCacheContext<?, ?> cctx = cacheContext(cacheIds.get(i)); if (i == 0 && cctx.isLocal()) throw new CacheException("Cache is LOCAL: " + cctx.name()); if (!cctx.isReplicated() && !cctx.isLocal()) return cctx; } throw new IllegalStateException("Failed to find partitioned cache."); }
/** * @param cacheIds Cache IDs. * @return The first partitioned cache context. */ private GridCacheContext<?,?> findFirstPartitioned(List<Integer> cacheIds) { for (int i = 0; i < cacheIds.size(); i++) { GridCacheContext<?, ?> cctx = cacheContext(cacheIds.get(i)); if (i == 0 && cctx.isLocal()) throw new CacheException("Cache is LOCAL: " + cctx.name()); if (!cctx.isReplicated() && !cctx.isLocal()) return cctx; } throw new IllegalStateException("Failed to find partitioned cache."); }
/** * @return {@code True} if need to filter out non-primary keys during processing of set data query. */ private boolean filterKeys() { return !collocated && !(ctx.isLocal() || ctx.isReplicated()) && (CU.isNearEnabled(ctx) || ctx.isPartitioned()); }
/** * @param tx Transaction. * @return {@code True} if should notify continuous query manager. */ public boolean notifyContinuousQueries(@Nullable IgniteInternalTx tx) { return cctx.isLocal() || cctx.isReplicated() || (!cctx.isNear() && !(tx != null && tx.onePhaseCommit() && !tx.local())); }
/** * @param sctx Shared context. * @param cacheIds Cache ids. * @return First partitioned cache or {@code null} in case no partitioned cache ids are in list. */ public static GridCacheContext<?, ?> firstPartitioned(GridCacheSharedContext<?, ?> sctx, int[] cacheIds) { for (int i = 0; i < cacheIds.length; i++) { GridCacheContext<?, ?> cctx = sctx.cacheContext(cacheIds[i]); if (cctx == null) throw new CacheException("Failed to find cache."); if (!cctx.isLocal() && !cctx.isReplicated()) return cctx; } return null; }
/** * @param sctx Shared context. * @param cacheIds Cache ids. * @return First partitioned cache or {@code null} in case no partitioned cache ids are in list. */ public static GridCacheContext<?, ?> firstPartitioned(GridCacheSharedContext<?, ?> sctx, Iterable<Integer> cacheIds) { for (Integer i : cacheIds) { GridCacheContext<?, ?> cctx = sctx.cacheContext(i); if (cctx == null) throw new CacheException("Failed to find cache."); if (!cctx.isLocal() && !cctx.isReplicated()) return cctx; } return null; }
/** */ private boolean isLocalBackup(EnlistOperation op, KeyCacheObject key) { if (!cctx.affinityNode() || op == EnlistOperation.LOCK) return false; else if (cctx.isReplicated()) return true; return cctx.topology().nodes(key.partition(), tx.topologyVersion()).indexOf(cctx.localNode()) > 0; }
/** */ private boolean isLocalBackup(EnlistOperation op, KeyCacheObject key) { if (!cctx.affinityNode() || op == EnlistOperation.LOCK) return false; else if (cctx.isReplicated()) return true; return cctx.topology().nodes(key.partition(), tx.topologyVersion()).contains(cctx.localNode()); }
/** * @param cctx Cache context. * @throws IgniteCheckedException If failed. */ private void startQuery(GridCacheContext cctx) throws IgniteCheckedException { if (!qryIdMap.containsKey(cctx.cacheId())) { synchronized (this) { if (!qryIdMap.containsKey(cctx.cacheId())) { qryIdMap.put(cctx.cacheId(), cctx.continuousQueries().executeInternalQuery( new DataStructuresEntryListener(), new DataStructuresEntryFilter(), cctx.isReplicated() && cctx.affinityNode(), false, false, true )); } } } }
/** * @param topVer Topology version. * @return Nodes where set data request should be sent. * @throws IgniteCheckedException If all cache nodes left grid. */ private Collection<ClusterNode> dataNodes(AffinityTopologyVersion topVer) throws IgniteCheckedException { assert ctx.isPartitioned() || collocated : "Non-collocated mode is supported only for PARTITIONED caches."; if (ctx.isLocal() || (ctx.isReplicated() && ctx.affinityNode())) return Collections.singleton(ctx.localNode()); Collection<ClusterNode> nodes; if (collocated) { List<ClusterNode> nodes0 = ctx.affinity().nodesByPartition(hdrPart, topVer); nodes = !nodes0.isEmpty() ? Collections.singleton(nodes0.contains(ctx.localNode()) ? ctx.localNode() : F.first(nodes0)) : nodes0; } else nodes = CU.affinityNodes(ctx, topVer); if (nodes.isEmpty()) throw new IgniteCheckedException("Failed to get set data, all cache nodes left grid."); return nodes; }
if (cctx.isReplicated()) { for (ClusterNode clusterNode : cctx.affinity().assignment(topVer).nodes()) mapping.put(clusterNode, null);
/** {@inheritDoc} */ @Nullable @Override public IndexingQueryCacheFilter forCache(String cacheName) { final GridCacheAdapter<Object, Object> cache = ctx.cache().internalCache(cacheName); // REPLICATED -> nothing to filter (explicit partitions are not supported). if (cache.context().isReplicated()) return null; // No backups and explicit partitions -> nothing to filter. if (cache.configuration().getBackups() == 0 && parts == null) return null; return new IndexingQueryCacheFilter(cache.context().affinity(), parts, topVer, ctx.discovery().localNode()); } }
/** * Releases the partition that was reserved by a call to * {@link #reserveForFastLocalGet(int, AffinityTopologyVersion)}. * * @param part Partition to release. * @param topVer Topology version. */ public void releaseForFastLocalGet(int part, AffinityTopologyVersion topVer) { assert affinityNode(); if (!isReplicated() || group().persistenceEnabled()) { GridDhtLocalPartition locPart = topology().localPartition(part, topVer, false); assert locPart != null && locPart.state() == OWNING : "partition evicted after reserveForFastLocalGet " + "[part=" + part + ", locPart=" + locPart + ", topVer=" + topVer + ']'; locPart.release(); } }
assert cctx.isReplicated() : cctx.name() + " must be replicated";
/** * Checks if local reads are allowed for the given partition and reserves the partition when needed. If this * method returns {@code true}, then {@link #releaseForFastLocalGet(int, AffinityTopologyVersion)} method * must be called after the read is completed. * * @param part Partition. * @param topVer Topology version. * @return {@code True} if cache 'get' operation is allowed to get entry locally. */ public boolean reserveForFastLocalGet(int part, AffinityTopologyVersion topVer) { boolean result = affinityNode() && rebalanceEnabled() && checkAndReservePartition(part, topVer); // When persistence is enabled, only reading from partitions with OWNING state is allowed. assert !result || !group().persistenceEnabled() || topology().partitionState(localNodeId(), part) == OWNING : "result=" + result + ", persistenceEnabled=" + group().persistenceEnabled() + ", partitionState=" + topology().partitionState(localNodeId(), part) + ", replicated=" + isReplicated() + ", part=" + part; return result; }
if (isReplicated() && !group().persistenceEnabled()) { boolean rebFinished = top.rebalanceFinished(topVer);