/** * @param part Partition. * @return Data store for given entry. */ public CacheDataStore dataStore(int part) { return grp.isLocal() ? locCacheDataStore : partDataStores.get(part); }
/** {@inheritDoc} */ @Override public Iterable<CacheDataStore> cacheDataStores() { if (grp.isLocal()) return Collections.singleton(locCacheDataStore); return new Iterable<CacheDataStore>() { @Override public Iterator<CacheDataStore> iterator() { return partDataStores.values().iterator(); } }; }
/** * @param part Partition. * @return Data store for given entry. */ @Override public CacheDataStore dataStore(GridDhtLocalPartition part) { if (grp.isLocal()) return locCacheDataStore; else { assert part != null; return part.dataStore(); } }
/** * Collects non local cache groups. * * @return Collection of non local cache groups. */ private List<CacheGroupContext> nonLocalCacheGroups() { return cctx.cache().cacheGroups().stream() .filter(grp -> !grp.isLocal() && !cacheGroupStopping(grp.groupId())) .collect(Collectors.toList()); }
/** * @param p Partition. * @return Partition data. */ @Nullable private CacheDataStore partitionData(int p) { if (grp.isLocal()) return locCacheDataStore; else { GridDhtLocalPartition part = grp.topology().localPartition(p, AffinityTopologyVersion.NONE, false, true); return part != null ? part.dataStore() : null; } }
/** {@inheritDoc} */ @Override public long cacheEntriesCount( int cacheId, boolean primary, boolean backup, AffinityTopologyVersion topVer ) throws IgniteCheckedException { if (grp.isLocal()) if (primary) return cacheEntriesCount(cacheId, 0); else return 0L; else { long cnt = 0; Iterator<CacheDataStore> it = cacheData(primary, backup, topVer); while (it.hasNext()) cnt += it.next().cacheSize(cacheId); return cnt; } }
/** * @param cctx Cache context. * @param key Key. * @return Data store. */ @Nullable private CacheDataStore dataStore(GridCacheContext cctx, KeyCacheObject key) { if (grp.isLocal()) return locCacheDataStore; GridDhtLocalPartition part = grp.topology().localPartition(cctx.affinity().partition(key), null, false); return part != null ? dataStore(part) : null; }
/** * @return Map of group id -> Set of partitions which can be used as suppliers for WAL rebalance. */ private Map<Integer, Set<Integer>> partitionsApplicableForWalRebalance() { Map<Integer, Set<Integer>> res = new HashMap<>(); for (CacheGroupContext grp : cctx.cache().cacheGroups()) { if (grp.isLocal()) continue; for (GridDhtLocalPartition locPart : grp.topology().currentLocalPartitions()) { if (locPart.state() == GridDhtPartitionState.OWNING && locPart.fullSize() > walRebalanceThreshold) res.computeIfAbsent(grp.groupId(), k -> new HashSet<>()).add(locPart.id()); } } return res; }
/** * Gets filtered group ids. */ private Set<Integer> getCacheGroupIds() { Collection<CacheGroupContext> groups = ignite.context().cache().cacheGroups(); Set<Integer> grpIds = new HashSet<>(); if (F.isEmpty(arg.getExcludeCaches())) { for (CacheGroupContext grp : groups) { if (!grp.systemCache() && !grp.isLocal()) grpIds.add(grp.groupId()); } return grpIds; } for (CacheGroupContext grp : groups) { if (!grp.systemCache() && !grp.isLocal() && !isGrpExcluded(grp)) grpIds.add(grp.groupId()); } return grpIds; }
/** {@inheritDoc} */ @Override @Nullable public CacheDataRow read(GridCacheMapEntry entry) throws IgniteCheckedException { KeyCacheObject key = entry.key(); assert grp.isLocal() || entry.localPartition() != null : entry; return dataStore(entry.localPartition()).find(entry.context(), key); }
/** * Method dumps partitions info see {@link #dumpPartitionsInfo(CacheGroupContext, IgniteLogger)} * for all persistent cache groups. * * @param cctx Shared context. * @param log Logger. * @throws IgniteCheckedException If failed. */ private static void dumpPartitionsInfo(GridCacheSharedContext cctx, IgniteLogger log) throws IgniteCheckedException { for (CacheGroupContext grp : cctx.cache().cacheGroups()) { if (grp.isLocal() || !grp.persistenceEnabled()) continue; dumpPartitionsInfo(grp, log); } }
/** {@inheritDoc} */ @Override public long totalPartitionEntriesCount(int p) { if (grp.isLocal()) return locCacheDataStore.fullSize(); else { GridDhtLocalPartition part = grp.topology().localPartition(p, AffinityTopologyVersion.NONE, false, true); return part != null ? part.dataStore().fullSize() : 0; } }
/** * @param grp Cache group. * @param topNodes Topology nodes. * @return Validation result. */ protected final CacheGroupValidation validateCacheGroup(CacheGroupContext grp, Collection<ClusterNode> topNodes) { Collection<Integer> lostParts = grp.isLocal() ? Collections.<Integer>emptyList() : grp.topology().lostPartitions(); boolean valid = true; if (!grp.systemCache()) { TopologyValidator validator = grp.topologyValidator(); if (validator != null) valid = validator.validate(topNodes); } return new CacheGroupValidation(valid, lostParts); }
/** * */ private void onLeft() { for (CacheGroupContext grp : cctx.cache().cacheGroups()) { if (grp.isLocal()) continue; grp.preloader().unwindUndeploys(); cctx.exchange().exchangerUpdateHeartbeat(); } }
/** * @param cacheNames Cache names. */ private void resetLostPartitions(Collection<String> cacheNames) { assert !exchCtx.mergeExchanges(); synchronized (cctx.exchange().interruptLock()) { if (Thread.currentThread().isInterrupted()) return; for (CacheGroupContext grp : cctx.cache().cacheGroups()) { if (grp.isLocal()) continue; for (String cacheName : cacheNames) { if (grp.hasCache(cacheName)) { grp.topology().resetLostPartitions(initialVersion()); break; } } } } }
/** {@inheritDoc} */ @Override public void preloadPartition(int part) throws IgniteCheckedException { if (grp.isLocal()) { dataStore(part).preload(); return; } GridDhtLocalPartition locPart = grp.topology().localPartition(part, AffinityTopologyVersion.NONE, false, false); assert locPart != null && locPart.reservations() > 0; locPart.dataStore().preload(); }
/** {@inheritDoc} */ @Override public void start(GridCacheSharedContext ctx, CacheGroupContext grp) throws IgniteCheckedException { this.ctx = ctx; this.grp = grp; this.log = ctx.logger(getClass()); updateValSizeThreshold = ctx.database().pageSize() / 2; if (grp.affinityNode()) { ctx.database().checkpointReadLock(); try { initDataStructures(); if (grp.isLocal()) locCacheDataStore = createCacheDataStore(0); } finally { ctx.database().checkpointReadUnlock(); } } }
/** * Detect lost partitions. * * @param resTopVer Result topology version. */ private void detectLostPartitions(AffinityTopologyVersion resTopVer) { boolean detected = false; synchronized (cctx.exchange().interruptLock()) { if (Thread.currentThread().isInterrupted()) return; for (CacheGroupContext grp : cctx.cache().cacheGroups()) { if (!grp.isLocal()) { // Do not trigger lost partition events on start. boolean event = !localJoinExchange() && !activateCluster(); boolean detectedOnGrp = grp.topology().detectLostPartitions(resTopVer, event ? events().lastEvent() : null); detected |= detectedOnGrp; } } } if (detected) { if (log.isDebugEnabled()) log.debug("Partitions have been scheduled to resend [reason=" + "Lost partitions detect on " + resTopVer + "]"); cctx.exchange().scheduleResendPartitions(); } timeBag.finishGlobalStage("Detect lost partitions"); }
/** * */ private abstract class MessageHandler<M> implements IgniteBiInClosure<UUID, M> { /** */ private static final long serialVersionUID = 0L; /** * @param nodeId Sender node ID. * @param msg Message. */ @Override public void apply(UUID nodeId, M msg) { ClusterNode node = cctx.node(nodeId); if (node == null) { if (log.isTraceEnabled()) log.trace("Received message from failed node [node=" + nodeId + ", msg=" + msg + ']'); return; } if (log.isTraceEnabled()) log.trace("Received message from node [node=" + nodeId + ", msg=" + msg + ']'); onMessage(node, msg); } /** * @param node Sender cluster node. * @param msg Message. */ protected abstract void onMessage(ClusterNode node, M msg); }
/** * @throws IgniteCheckedException If failed. */ private void initTopologies() throws IgniteCheckedException { cctx.database().checkpointReadLock(); try { if (crd != null) { for (CacheGroupContext grp : cctx.cache().cacheGroups()) { if (grp.isLocal()) continue; grp.topology().beforeExchange(this, !centralizedAff && !forceAffReassignment, false); cctx.exchange().exchangerUpdateHeartbeat(); } } } finally { cctx.database().checkpointReadUnlock(); } }