/** * @param cctx Cache context. * @param p Partition ID. * @return Partition. */ private GridDhtLocalPartition partition(GridCacheContext<?, ?> cctx, int p) { return cctx.topology().localPartition(p, NONE, false); }
/** * @param part Partition. * @return Backup nodes for the given partition. */ @NotNull private List<ClusterNode> backupNodes(int part) { List<ClusterNode> nodes = cctx.topology().nodes(part, tx.topologyVersion()); assert !nodes.isEmpty() && nodes.get(0).isLocal(); return nodes.subList(1, nodes.size()); }
/** {@inheritDoc} */ @Override public Collection<Integer> lostPartitions() { if (isLocal()) return Collections.emptyList(); return ctx.topology().lostPartitions(); }
/** {@inheritDoc} */ @Override public void topologyReadUnlock(GridCacheSharedContext cctx) { if (cacheCtx == null || cacheCtx.isLocal()) return; cacheCtx.topology().readUnlock(); }
/** {@inheritDoc} */ @Override public void onMarkedObsolete() { assert !lockedByCurrentThread(); // Remove this entry from partition mapping. cctx.topology().onRemoved(this); }
/** * @param part Partition. * @return {@code True} if partition is in owned state. */ private boolean partitionOwned(int part) { return cctx.topology().partitionState(cctx.localNodeId(), part) == OWNING; }
/** * @param part Partition. * @return {@code True} if partition is in owned state. */ protected final boolean partitionOwned(int part) { return cctx.topology().partitionState(cctx.localNodeId(), part) == OWNING; }
/** {@inheritDoc} */ @Override public boolean onDone(GridCacheEntryInfo res, Throwable err) { if (super.onDone(res, err)) { // Release all partitions reserved by this future. if (part != -1) cctx.topology().releasePartitions(part); return true; } return false; }
/** * @param cctx Cache context. * @return {@code True} If cache has partitions in {@link GridDhtPartitionState#MOVING} state. */ private static boolean hasMovingPartitions(GridCacheContext<?, ?> cctx) { assert cctx != null; return !cctx.isLocal() && cctx.topology().hasMovingPartitions(); }
/** * @param node Cluster node. * @param part Partition. * @return {@code true} if the given partition is rebalancing to the given node. */ private boolean isMoving(ClusterNode node, int part) { return cctx.topology().partitionState(node.id(), part) == GridDhtPartitionState.MOVING; }
/** {@inheritDoc} */ @Override public boolean onDone(Collection<GridCacheEntryInfo> res, Throwable err) { if (super.onDone(res, err)) { // Release all partitions reserved by this future. if (parts != null) cctx.topology().releasePartitions(parts); return true; } return false; }
/** {@inheritDoc} */ @Override protected VisorCacheLostPartitionsTaskResult run(VisorCacheLostPartitionsTaskArg arg) { Map<String, List<Integer>> res = new HashMap<>(); for (String cacheName: arg.getCacheNames()) { IgniteInternalCache cache = ignite.cachex(cacheName); if (cache != null) { GridDhtPartitionTopology top = cache.context().topology(); List<Integer> lostPartitions = new ArrayList<>(top.lostPartitions()); if (!lostPartitions.isEmpty()) res.put(cacheName, lostPartitions); } } return new VisorCacheLostPartitionsTaskResult(res); }
/** * @return Topology version future. */ public GridDhtTopologyFuture topologyVersionFuture() { GridCacheAdapter<K, V> cache = this.cache; if (cache == null) throw new IllegalStateException("Cache stopped: " + cacheName); assert cache.isNear() || cache.isDht() || cache.isColocated() || cache.isDhtAtomic() : cache; return topology(cache).topologyVersionFuture(); }
/** */ 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()); }
/** {@inheritDoc} */ @Override public GridDhtTopologyFuture topologyReadLock(GridCacheSharedContext cctx, GridFutureAdapter<?> fut) { if (cacheCtx == null || cacheCtx.isLocal()) return cctx.exchange().lastTopologyFuture(); cacheCtx.topology().readLock(); if (cacheCtx.topology().stopping()) { fut.onDone( cctx.cache().isCacheRestarting(cacheCtx.name())? new IgniteCacheRestartingException(cacheCtx.name()): new CacheStoppedException(cacheCtx.name())); return null; } return cacheCtx.topology().topologyVersionFuture(); }
/** * @param cctx Cctx. * @return Local partition. */ private static int anyLocalPartition(GridCacheContext<?, ?> cctx) { return F.first(cctx.topology().localPartitions()).id(); }
@Override public void onMessage(UUID nodeId, Object msg) { if (GridH2QueryRequest.class.isAssignableFrom(msg.getClass())) { GridH2QueryRequest qryReq = (GridH2QueryRequest)msg; GridCacheContext<?, ?> cctx = ctx.cache().context().cacheContext(qryReq.caches().get(0)); GridDhtLocalPartition part = cctx.topology().localPartition(0, NONE, false); AtomicLong aState = GridTestUtils.getFieldValue(part, GridDhtLocalPartition.class, "state"); long stateVal = aState.getAndSet(2); startedExecutor.onMessage(nodeId, msg); aState.getAndSet(stateVal); } else startedExecutor.onMessage(nodeId, msg); } }.insertRealExecutor(mapQryExec));
/** * @param ignite Ignite instance. * @param orgId Organization ID. * @return {@code true} if partition for the given organization ID is primary on the given node. */ private static boolean primaryPartition(IgniteEx ignite, int orgId) { int part = ignite.affinity(Organization.class.getSimpleName()).partition(orgId); GridCacheAdapter<?, ?> cacheAdapterPers = ignite.context().cache() .internalCache(Person.class.getSimpleName()); GridDhtLocalPartition pPers = cacheAdapterPers.context().topology() .localPartition(part, AffinityTopologyVersion.NONE, false); return pPers.primary(AffinityTopologyVersion.NONE); }
@Override public boolean apply() { for (int i = 0; i < NODES; i++) { final GridDhtPartitionTopology top = ((IgniteKernal)ignite(i)).context().cache().cache(DEFAULT_CACHE_NAME).context().topology(); for (GridDhtLocalPartition p : top.currentLocalPartitions()) { Collection<Object> rmvQueue = GridTestUtils.getFieldValue(p, "rmvQueue"); if (!rmvQueue.isEmpty() || p.dataStore().fullSize() != 0) return false; } } return true; } }, 5000);