/** * Collects non local cache group descriptors. * * @return Collection of non local cache group descriptors. */ private List<CacheGroupDescriptor> nonLocalCacheGroupDescriptors() { return cctx.affinity().cacheGroups().values().stream() .filter(grpDesc -> grpDesc.config().getCacheMode() != CacheMode.LOCAL) .collect(Collectors.toList()); }
/** {@inheritDoc} */ @Override public boolean onDone(@Nullable GridDhtAffinityAssignmentResponse res, @Nullable Throwable err) { if (super.onDone(res, err)) { ctx.affinity().removeDhtAssignmentFetchFuture(this); return true; } return false; }
/** * @param type Event type. * @param customMsg Custom message instance. * @param node Event node. * @param topVer Topology version. * @param state Cluster state. */ public void onDiscoveryEvent(int type, @Nullable DiscoveryCustomMessage customMsg, ClusterNode node, AffinityTopologyVersion topVer, DiscoveryDataClusterState state) { cachesInfo.onDiscoveryEvent(type, node, topVer); sharedCtx.affinity().onDiscoveryEvent(type, customMsg, node, topVer, state); }
/** * Initializes fetch future. * * @param needPartState {@code True} if also need fetch partitions state. */ public void init(boolean needPartState) { this.needPartState = needPartState; ctx.affinity().addDhtAssignmentFetchFuture(this); requestFromNextNode(); }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> cacheAffinity(String cacheName) { if (cacheName == null) throw new NullPointerException("Null cache name."); DynamicCacheDescriptor cacheDesc = ctx.affinity().caches().get(CU.cacheId(cacheName)); if (cacheDesc == null) throw new IllegalArgumentException("Invalid cache name: " + cacheName); GridAffinityAssignmentCache aff = ctx.affinity().groupAffinity(cacheDesc.groupId()); assert aff != null : cacheName; return aff.readyAssignments(aff.lastVersion()); }
/** * @param crd Coordinator flag. * @throws IgniteCheckedException If failed. * @return Exchange type. */ private ExchangeType onAffinityChangeRequest(boolean crd) throws IgniteCheckedException { assert affChangeMsg != null : this; cctx.affinity().onChangeAffinityMessage(this, crd, affChangeMsg); if (cctx.kernalContext().clientNode()) return ExchangeType.CLIENT; return ExchangeType.ALL; }
/** * @param crd Coordinator flag. * @return Exchange type. */ private ExchangeType onCustomMessageNoAffinityChange(boolean crd) { if (!forceAffReassignment) cctx.affinity().onCustomMessageNoAffinityChange(this, crd, exchActions); return cctx.kernalContext().clientNode() ? ExchangeType.CLIENT : ExchangeType.ALL; }
/** {@inheritDoc} */ @Override public Map<String, CacheConfiguration<?, ?>> startedCaches() { Map<Integer, DynamicCacheDescriptor> cachesMap = ctx.affinity().caches(); Map<String, CacheConfiguration<?, ?>> res = U.newHashMap(cachesMap.size()); for (DynamicCacheDescriptor desc : cachesMap.values()) { if (desc.cacheType().userCache()) res.put(desc.cacheName(), desc.cacheConfiguration()); } return res; }
/** * Finishes recovery for current cache group. * Attaches topology version and initializes I/O. * * @param startVer Cache group start version. * @param originalReceivedFrom UUID of node that was first who initiated cache group creating. * This is needed to decide should node calculate affinity locally or fetch from other nodes. * @param affinityNode Flag indicates, is local node affinity node or not. This may be calculated only after node joined to topology. * @throws IgniteCheckedException If failed. */ public void finishRecovery( AffinityTopologyVersion startVer, UUID originalReceivedFrom, boolean affinityNode ) throws IgniteCheckedException { if (!recoveryMode.compareAndSet(true, false)) return; affNode = affinityNode; rcvdFrom = originalReceivedFrom; locStartVer = startVer; persistGlobalWalState(globalWalEnabled); initializeIO(); ctx.affinity().onCacheGroupCreated(this); }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> cachePartitionOwners(String cacheName) { if (cacheName == null) throw new NullPointerException("Null cache name."); DynamicCacheDescriptor cacheDesc = ctx.affinity().caches().get(CU.cacheId(cacheName)); if (cacheDesc == null) throw new IllegalArgumentException("Invalid cache name: " + cacheName); if (cacheDesc.cacheConfiguration().getCacheMode() == CacheMode.LOCAL) return Collections.emptyList(); CacheGroupContext grp = ctx.cache().cacheGroup(cacheDesc.groupId()); GridDhtPartitionTopology top; if (grp == null) { top = ctx.exchange().clientTopologyIfExists(cacheDesc.groupId()); assert top != null : cacheName; } else top = grp.topology(); return top.allOwners(); }
/** * @param crd Coordinator flag. * @throws IgniteCheckedException If failed. * @return Exchange type. */ private ExchangeType onServerNodeEvent(boolean crd) throws IgniteCheckedException { assert !firstDiscoEvt.eventNode().isClient() : this; if (firstDiscoEvt.type() == EVT_NODE_LEFT || firstDiscoEvt.type() == EVT_NODE_FAILED) { onLeft(); exchCtx.events().warnNoAffinityNodes(cctx); centralizedAff = cctx.affinity().onCentralizedAffinityChange(this, crd); } else cctx.affinity().onServerJoin(this, crd); return cctx.kernalContext().clientNode() ? ExchangeType.CLIENT : ExchangeType.ALL; }
/** * @param grpId Cache group ID. * @param discoCache Discovery data cache. * @return Topology. */ public GridDhtPartitionTopology clientTopology(int grpId, DiscoCache discoCache) { GridClientPartitionTopology top = clientTops.get(grpId); if (top != null) return top; CacheGroupDescriptor grpDesc = cctx.affinity().cacheGroups().get(grpId); assert grpDesc != null : grpId; CacheConfiguration<?, ?> ccfg = grpDesc.config(); AffinityFunction aff = ccfg.getAffinity(); Object affKey = cctx.kernalContext().affinity().similaryAffinityKey(aff, ccfg.getNodeFilter(), ccfg.getBackups(), aff.partitions()); GridClientPartitionTopology old = clientTops.putIfAbsent(grpId, top = new GridClientPartitionTopology(cctx, discoCache, grpId, aff.partitions(), affKey)); return old != null ? old : top; }
/** * @param stoppedCaches Stopped caches. */ private void stopCachesOnClientReconnect(Collection<GridCacheAdapter> stoppedCaches) { assert ctx.discovery().localNode().isClient(); for (GridCacheAdapter cache : stoppedCaches) { CacheGroupContext grp = cache.context().group(); onKernalStop(cache, true); stopCache(cache, true, false); sharedCtx.affinity().stopCacheOnReconnect(cache.context()); if (!grp.hasCaches()) { stopCacheGroup(grp); sharedCtx.affinity().stopCacheGroupOnReconnect(grp); } } }
/** * @param newCrd {@code True} if node become coordinator on this exchange. * @throws IgniteCheckedException If failed. */ private void initCoordinatorCaches(boolean newCrd) throws IgniteCheckedException { if (newCrd) { IgniteInternalFuture<?> fut = cctx.affinity().initCoordinatorCaches(this, false); if (fut != null) { fut.get(); cctx.exchange().exchangerUpdateHeartbeat(); } cctx.exchange().onCoordinatorInitialized(); cctx.exchange().exchangerUpdateHeartbeat(); } }
return new GridFinishedFuture<>(); IgniteInternalFuture<?> res = sharedCtx.affinity().initCachesOnLocalJoin( locJoinCtx.cacheGroupDescriptors(), locJoinCtx.cacheDescriptors());
/** {@inheritDoc} */ @Override public void beforeExchange(GridDhtPartitionsExchangeFuture exchFut, boolean initParts, boolean updateMoving) throws IgniteCheckedException { ClusterNode loc = cctx.localNode(); U.writeLock(lock); try { if (stopping) return; discoCache = exchFut.events().discoveryCache(); beforeExchange0(loc, exchFut); if (updateMoving) { ExchangeDiscoveryEvents evts = exchFut.context().events(); GridAffinityAssignmentCache aff = cctx.affinity().affinity(grpId); assert aff.lastVersion().equals(evts.topologyVersion()); createMovingPartitions(aff.readyAffinity(evts.topologyVersion())); } } finally { lock.writeLock().unlock(); } }
sharedCtx.affinity().clearGroupHoldersAndRegistry();
/** * @param crd Coordinator flag. * @throws IgniteCheckedException If failed. * @return Exchange type. */ private ExchangeType onClientNodeEvent(boolean crd) throws IgniteCheckedException { assert firstDiscoEvt.eventNode().isClient() : this; if (firstDiscoEvt.type() == EVT_NODE_LEFT || firstDiscoEvt.type() == EVT_NODE_FAILED) { onLeft(); assert !firstDiscoEvt.eventNode().isLocal() : firstDiscoEvt; } else assert firstDiscoEvt.type() == EVT_NODE_JOINED || firstDiscoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT : firstDiscoEvt; cctx.affinity().onClientEvent(this, crd); return firstDiscoEvt.eventNode().isLocal() ? ExchangeType.CLIENT : ExchangeType.NONE; }
/** * @param crd Coordinator flag. * @return Exchange type. * @throws IgniteCheckedException If failed. */ private ExchangeType onCacheChangeRequest(boolean crd) throws IgniteCheckedException { assert exchActions != null && !exchActions.empty() : this; assert !exchActions.clientOnlyExchange() : exchActions; cctx.exchange().exchangerBlockingSectionBegin(); try { assert registerCachesFuture == null : "No caches registration should be scheduled before new caches have started."; registerCachesFuture = cctx.affinity().onCacheChangeRequest(this, crd, exchActions); } catch (Exception e) { if (reconnectOnError(e) || !isRollbackSupported()) // This exception will be handled by init() method. throw e; U.error(log, "Failed to initialize cache(s) (will try to rollback) [exchId=" + exchId + ", caches=" + exchActions.cacheGroupsToStart() + ']', e); exchangeLocE = new IgniteCheckedException( "Failed to initialize exchange locally [locNodeId=" + cctx.localNodeId() + "]", e); exchangeGlobalExceptions.put(cctx.localNodeId(), exchangeLocE); } finally { cctx.exchange().exchangerBlockingSectionEnd(); } return cctx.kernalContext().clientNode() ? ExchangeType.CLIENT : ExchangeType.ALL; }
/** * @throws IgniteCheckedException If failed. */ public void start() throws IgniteCheckedException { aff = new GridAffinityAssignmentCache(ctx.kernalContext(), cacheOrGroupName(), grpId, ccfg.getAffinity(), ccfg.getNodeFilter(), ccfg.getBackups(), ccfg.getCacheMode() == LOCAL, persistenceEnabled()); if (ccfg.getCacheMode() != LOCAL) top = new GridDhtPartitionTopologyImpl(ctx, this); try { offheapMgr = persistenceEnabled ? new GridCacheOffheapManager() : new IgniteCacheOffheapManagerImpl(); } catch (Exception e) { throw new IgniteCheckedException("Failed to initialize offheap manager", e); } offheapMgr.start(ctx, this); if (!isRecoveryMode()) { initializeIO(); ctx.affinity().onCacheGroupCreated(this); } }