Search in sources :

Example 1 with DiscoCache

use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.

the class CacheAffinitySharedManager method processClientCachesRequests.

/**
 * Process non affinity node cache start/close requests, called from exchange thread.
 *
 * @param msg Change request.
 */
void processClientCachesRequests(ClientCacheChangeDummyDiscoveryMessage msg) {
    // Get ready exchange version.
    AffinityTopologyVersion topVer = cctx.exchange().readyAffinityVersion();
    DiscoCache discoCache = cctx.discovery().discoCache(topVer);
    ClusterNode node = discoCache.oldestAliveServerNode();
    // Resolve coordinator for specific version.
    boolean crd = node != null && node.isLocal();
    Map<Integer, Boolean> startedCaches = null;
    Set<Integer> closedCaches = null;
    // Check and start caches via dummy message.
    if (msg.startRequests() != null)
        startedCaches = processClientCacheStartRequests(crd, msg, topVer, discoCache);
    // Check and close caches via dummy message.
    if (msg.cachesToClose() != null)
        closedCaches = processCacheCloseRequests(msg, topVer);
    // Shedule change message.
    if (startedCaches != null || closedCaches != null)
        scheduleClientChangeMessage(startedCaches, closedCaches);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)

Example 2 with DiscoCache

use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.

the class InitNewCoordinatorFuture method init.

/**
 * @param exchFut Current future.
 * @throws IgniteCheckedException If failed.
 */
public void init(GridDhtPartitionsExchangeFuture exchFut) throws IgniteCheckedException {
    initTopVer = exchFut.initialVersion();
    GridCacheSharedContext cctx = exchFut.sharedContext();
    restoreState = exchangeProtocolVersion(exchFut.context().events().discoveryCache().minimumNodeVersion()) > 1;
    boolean newAff = exchFut.localJoinExchange();
    IgniteInternalFuture<?> fut = cctx.affinity().initCoordinatorCaches(exchFut, newAff);
    if (fut != null)
        add(fut);
    if (restoreState) {
        DiscoCache curDiscoCache = cctx.discovery().discoCache();
        DiscoCache discoCache = exchFut.events().discoveryCache();
        List<ClusterNode> nodes = new ArrayList<>();
        synchronized (this) {
            for (ClusterNode node : discoCache.allNodes()) {
                if (!node.isLocal() && cctx.discovery().alive(node)) {
                    awaited.add(node.id());
                    nodes.add(node);
                } else if (!node.isLocal()) {
                    if (log.isInfoEnabled())
                        log.info("Init new coordinator future will skip remote node: " + node);
                }
            }
            if (exchFut.context().mergeExchanges() && !curDiscoCache.version().equals(discoCache.version())) {
                for (ClusterNode node : curDiscoCache.allNodes()) {
                    if (discoCache.node(node.id()) == null) {
                        if (exchangeProtocolVersion(node.version()) == 1)
                            break;
                        awaited.add(node.id());
                        nodes.add(node);
                        if (joinedNodes == null)
                            joinedNodes = new HashMap<>();
                        GridDhtPartitionExchangeId exchId = new GridDhtPartitionExchangeId(node.id(), EVT_NODE_JOINED, new AffinityTopologyVersion(node.order()));
                        joinedNodes.put(node.id(), exchId);
                    }
                }
            }
            if (joinedNodes == null)
                joinedNodes = Collections.emptyMap();
            if (!awaited.isEmpty()) {
                restoreStateFut = new GridFutureAdapter();
                add(restoreStateFut);
            }
        }
        if (log.isInfoEnabled()) {
            log.info("Try restore exchange result [awaited=" + awaited + ", joined=" + joinedNodes.keySet() + ", nodes=" + U.nodeIds(nodes) + ", discoAllNodes=" + U.nodeIds(discoCache.allNodes()) + ']');
        }
        if (!nodes.isEmpty()) {
            GridDhtPartitionsSingleRequest req = GridDhtPartitionsSingleRequest.restoreStateRequest(exchFut.exchangeId(), exchFut.exchangeId());
            for (ClusterNode node : nodes) {
                try {
                    GridDhtPartitionsSingleRequest sndReq = req;
                    if (joinedNodes.containsKey(node.id())) {
                        sndReq = GridDhtPartitionsSingleRequest.restoreStateRequest(joinedNodes.get(node.id()), exchFut.exchangeId());
                    }
                    cctx.io().send(node, sndReq, GridIoPolicy.SYSTEM_POOL);
                } catch (ClusterTopologyCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to send partitions request, node failed: " + node);
                    onNodeLeft(node.id());
                }
            }
        }
    }
    markInitialized();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) HashMap(java.util.HashMap) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 3 with DiscoCache

use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.

the class VisorTxTask method createVerboseInfo.

/**
 * Constructs detailed transaction info for verbose mode.
 *
 * @param ignite Ignite.
 * @param locTx Local tx.
 */
private static TxVerboseInfo createVerboseInfo(IgniteEx ignite, IgniteInternalTx locTx) {
    TxVerboseInfo res = new TxVerboseInfo();
    res.nearXidVersion(locTx.nearXidVersion());
    Map<Integer, String> usedCaches = new HashMap<>();
    Map<Integer, String> usedCacheGroups = new HashMap<>();
    ClusterNode locNode = ignite.context().discovery().localNode();
    res.localNodeId(locNode.id());
    res.localNodeConsistentId(locNode.consistentId());
    if (locTx instanceof GridNearTxLocal) {
        IgniteTxMappings mappings = ((GridNearTxLocal) locTx).mappings();
        List<IgniteTxEntry> nearOnlyEntries = new ArrayList<>();
        List<IgniteTxEntry> locEntries = new ArrayList<>();
        for (GridDistributedTxMapping mapping : mappings.mappings()) {
            if (F.eqNodes(mapping.primary(), locNode))
                locEntries.addAll(mapping.entries());
            else
                nearOnlyEntries.addAll(mapping.entries());
        }
        res.nearNodeId(locNode.id());
        res.nearNodeConsistentId(locNode.consistentId());
        res.txMappingType(TxMappingType.NEAR);
        List<TxVerboseKey> nearOnlyTxKeys = fetchTxEntriesAndFillUsedCaches(ignite, locTx, usedCaches, usedCacheGroups, nearOnlyEntries, true);
        List<TxVerboseKey> locTxKeys = fetchTxEntriesAndFillUsedCaches(ignite, locTx, usedCaches, usedCacheGroups, locEntries, false);
        res.nearOnlyTxKeys(nearOnlyTxKeys);
        res.localTxKeys(locTxKeys);
    } else if (locTx instanceof GridDhtTxLocal) {
        UUID nearNodeId = locTx.masterNodeIds().iterator().next();
        DiscoCache discoCache = ignite.context().discovery().discoCache(locTx.topologyVersion());
        if (discoCache == null)
            discoCache = ignite.context().discovery().discoCache();
        ClusterNode nearNode = discoCache.node(nearNodeId);
        res.nearNodeId(nearNodeId);
        res.nearNodeConsistentId(nearNode.consistentId());
        res.txMappingType(TxMappingType.DHT);
        res.localTxKeys(fetchTxEntriesAndFillUsedCaches(ignite, locTx, usedCaches, usedCacheGroups, locTx.allEntries(), false));
    } else if (locTx instanceof GridDhtTxRemote) {
        Iterator<UUID> masterNodesIter = locTx.masterNodeIds().iterator();
        UUID nearNodeId = masterNodesIter.next();
        UUID dhtNodeId = masterNodesIter.next();
        DiscoCache discoCache = ignite.context().discovery().discoCache(locTx.topologyVersion());
        if (discoCache == null)
            discoCache = ignite.context().discovery().discoCache();
        ClusterNode nearNode = discoCache.node(nearNodeId);
        ClusterNode dhtNode = discoCache.node(dhtNodeId);
        res.nearNodeId(nearNodeId);
        res.nearNodeConsistentId(nearNode.consistentId());
        res.txMappingType(TxMappingType.REMOTE);
        res.dhtNodeId(dhtNodeId);
        res.dhtNodeConsistentId(dhtNode.consistentId());
        res.localTxKeys(fetchTxEntriesAndFillUsedCaches(ignite, locTx, usedCaches, usedCacheGroups, locTx.allEntries(), false));
    }
    res.usedCaches(usedCaches);
    res.usedCacheGroups(usedCacheGroups);
    return res;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridDhtTxRemote(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxRemote) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) GridDhtTxLocal(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxLocal) HashMap(java.util.HashMap) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping) ArrayList(java.util.ArrayList) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxMappings(org.apache.ignite.internal.processors.cache.distributed.near.IgniteTxMappings) UUID(java.util.UUID)

Example 4 with DiscoCache

use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.

the class GridCachePartitionExchangeManager method onKernalStart.

/**
 * @param active Cluster state.
 * @param reconnect Reconnect flag.
 * @return Topology version of local join exchange if cluster is active.
 *         Topology version NONE if cluster is not active or reconnect.
 * @throws IgniteCheckedException If failed.
 */
public AffinityTopologyVersion onKernalStart(boolean active, boolean reconnect) throws IgniteCheckedException {
    for (ClusterNode n : cctx.discovery().remoteNodes()) cctx.versions().onReceived(n.id(), n.metrics().getLastDataVersion());
    DiscoveryLocalJoinData locJoin = cctx.discovery().localJoin();
    GridDhtPartitionsExchangeFuture fut = null;
    if (reconnect)
        reconnectExchangeFut = new GridFutureAdapter<>();
    if (active) {
        DiscoveryEvent discoEvt = locJoin.event();
        DiscoCache discoCache = locJoin.discoCache();
        GridDhtPartitionExchangeId exchId = initialExchangeId();
        fut = exchangeFuture(exchId, reconnect ? null : discoEvt, reconnect ? null : discoCache, null, null);
    } else if (reconnect)
        reconnectExchangeFut.onDone();
    new IgniteThread(cctx.igniteInstanceName(), "exchange-worker", exchWorker).start();
    if (reconnect) {
        if (fut != null) {
            fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

                @Override
                public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
                    try {
                        fut.get();
                        for (CacheGroupContext grp : cctx.cache().cacheGroups()) grp.preloader().onInitialExchangeComplete(null);
                        reconnectExchangeFut.onDone();
                    } catch (IgniteCheckedException e) {
                        for (CacheGroupContext grp : cctx.cache().cacheGroups()) grp.preloader().onInitialExchangeComplete(e);
                        reconnectExchangeFut.onDone(e);
                    }
                }
            });
        }
    } else if (fut != null) {
        if (log.isDebugEnabled())
            log.debug("Beginning to wait on local exchange future: " + fut);
        boolean first = true;
        while (true) {
            try {
                fut.get(cctx.preloadExchangeTimeout());
                break;
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                if (first) {
                    U.warn(log, "Failed to wait for initial partition map exchange. " + "Possible reasons are: " + U.nl() + "  ^-- Transactions in deadlock." + U.nl() + "  ^-- Long running transactions (ignore if this is the case)." + U.nl() + "  ^-- Unreleased explicit locks.");
                    first = false;
                } else
                    U.warn(log, "Still waiting for initial partition map exchange [fut=" + fut + ']');
            } catch (IgniteNeedReconnectException e) {
                throw e;
            } catch (Exception e) {
                if (fut.reconnectOnError(e))
                    throw new IgniteNeedReconnectException(cctx.localNode(), e);
                throw e;
            }
        }
        for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
            if (locJoin.joinTopologyVersion().equals(grp.localStartVersion()))
                grp.preloader().onInitialExchangeComplete(null);
        }
        if (log.isDebugEnabled())
            log.debug("Finished waiting for initial exchange: " + fut.exchangeId());
        return fut.initialVersion();
    }
    return NONE;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteThread(org.apache.ignite.thread.IgniteThread) DiscoveryLocalJoinData(org.apache.ignite.internal.managers.discovery.DiscoveryLocalJoinData) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException)

Example 5 with DiscoCache

use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.

the class IgniteClusterImpl method validateBeforeBaselineChange.

/**
 * Executes validation checks of cluster state and BaselineTopology before changing BaselineTopology to new one.
 */
private void validateBeforeBaselineChange(Collection<? extends BaselineNode> baselineTop) {
    verifyBaselineTopologySupport(ctx.discovery().discoCache());
    if (!ctx.state().clusterState().active())
        throw new IgniteException("Changing BaselineTopology on inactive cluster is not allowed.");
    if (baselineTop != null) {
        if (baselineTop.isEmpty())
            throw new IgniteException("BaselineTopology must contain at least one node.");
        List<BaselineNode> currBlT = Optional.ofNullable(ctx.state().clusterState().baselineTopology()).map(BaselineTopology::currentBaseline).orElse(Collections.emptyList());
        Collection<ClusterNode> srvrs = ctx.cluster().get().forServers().nodes();
        for (BaselineNode node : baselineTop) {
            Object consistentId = node.consistentId();
            if (currBlT.stream().noneMatch(currBlTNode -> Objects.equals(currBlTNode.consistentId(), consistentId)) && srvrs.stream().noneMatch(currServersNode -> Objects.equals(currServersNode.consistentId(), consistentId)))
                throw new IgniteException("Check arguments. Node with consistent ID [" + consistentId + "] not found in server nodes.");
        }
        Collection<Object> onlineNodes = onlineBaselineNodesRequestedForRemoval(baselineTop);
        if (onlineNodes != null) {
            if (!onlineNodes.isEmpty())
                throw new IgniteException("Removing online nodes from BaselineTopology is not supported: " + onlineNodes);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) ATTR_MACS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS) ObjectOutput(java.io.ObjectOutput) InetAddress(java.net.InetAddress) SB(org.apache.ignite.internal.util.typedef.internal.SB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCluster(org.apache.ignite.IgniteCluster) Map(java.util.Map) BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) StartNodeCallable(org.apache.ignite.internal.util.nodestart.StartNodeCallable) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteFuture(org.apache.ignite.lang.IgniteFuture) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) IgniteNodeStartUtils.parseFile(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.parseFile) Externalizable(java.io.Externalizable) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) UUID(java.util.UUID) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BaselineAutoAdjustStatus(org.apache.ignite.internal.processors.cluster.baseline.autoadjust.BaselineAutoAdjustStatus) CU(org.apache.ignite.internal.util.typedef.internal.CU) Optional(java.util.Optional) ObjectInput(java.io.ObjectInput) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) ShutdownPolicy(org.apache.ignite.ShutdownPolicy) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) DistributedEnumProperty(org.apache.ignite.internal.processors.configuration.distributed.DistributedEnumProperty) ClusterState(org.apache.ignite.cluster.ClusterState) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteComponentType(org.apache.ignite.internal.IgniteComponentType) ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) ATTR_IPS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_IPS) A(org.apache.ignite.internal.util.typedef.internal.A) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) BaselineNode(org.apache.ignite.cluster.BaselineNode) File(java.io.File) ObjectStreamException(java.io.ObjectStreamException) IgniteSshHelper(org.apache.ignite.internal.util.nodestart.IgniteSshHelper) IgniteRemoteStartSpecification(org.apache.ignite.internal.util.nodestart.IgniteRemoteStartSpecification) Collections(java.util.Collections) IgniteNodeStartUtils.specifications(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.specifications) IgniteException(org.apache.ignite.IgniteException) BaselineNode(org.apache.ignite.cluster.BaselineNode)

Aggregations

DiscoCache (org.apache.ignite.internal.managers.discovery.DiscoCache)18 ClusterNode (org.apache.ignite.cluster.ClusterNode)12 UUID (java.util.UUID)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 HashMap (java.util.HashMap)9 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)9 ArrayList (java.util.ArrayList)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)8 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)8 Map (java.util.Map)7 IgniteException (org.apache.ignite.IgniteException)7 Collection (java.util.Collection)6 Collections (java.util.Collections)6 List (java.util.List)6 Set (java.util.Set)6 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)6 F (org.apache.ignite.internal.util.typedef.F)6 CU (org.apache.ignite.internal.util.typedef.internal.CU)6 U (org.apache.ignite.internal.util.typedef.internal.U)6