Search in sources :

Example 51 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridClientPartitionTopology method nodes.

/**
 * {@inheritDoc}
 */
@Override
public List<ClusterNode> nodes(int p, AffinityTopologyVersion topVer) {
    lock.readLock().lock();
    try {
        assert node2part != null && node2part.valid() : "Invalid node-to-partitions map [topVer=" + topVer + ", node2part=" + node2part + ']';
        List<ClusterNode> nodes = null;
        Collection<UUID> nodeIds = part2node.get(p);
        if (!F.isEmpty(nodeIds)) {
            for (UUID nodeId : nodeIds) {
                ClusterNode n = discoCache.node(nodeId);
                if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) {
                    if (nodes == null)
                        nodes = new ArrayList<>(nodeIds.size());
                    nodes.add(n);
                }
            }
        }
        return nodes;
    } finally {
        lock.readLock().unlock();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 52 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridClientPartitionTopology method nodes.

/**
 * @param p Partition.
 * @param topVer Topology version ({@code -1} for all nodes).
 * @param state Partition state.
 * @param states Additional partition states.
 * @return List of nodes for the partition.
 */
private List<ClusterNode> nodes(int p, AffinityTopologyVersion topVer, GridDhtPartitionState state, GridDhtPartitionState... states) {
    Collection<UUID> allIds = F.nodeIds(discoCache.cacheGroupAffinityNodes(grpId));
    lock.readLock().lock();
    try {
        assert node2part != null && node2part.valid() : "Invalid node-to-partitions map [topVer=" + topVer + ", allIds=" + allIds + ", node2part=" + node2part + ']';
        Collection<UUID> nodeIds = part2node.get(p);
        // Node IDs can be null if both, primary and backup, nodes disappear.
        int size = nodeIds == null ? 0 : nodeIds.size();
        if (size == 0)
            return Collections.emptyList();
        List<ClusterNode> nodes = new ArrayList<>(size);
        for (UUID id : nodeIds) {
            if (topVer.topologyVersion() > 0 && !F.contains(allIds, id))
                continue;
            if (hasState(p, id, state, states)) {
                ClusterNode n = discoCache.node(id);
                if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion()))
                    nodes.add(n);
            }
        }
        return nodes;
    } finally {
        lock.readLock().unlock();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 53 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridServiceProcessorProxySelfTest method testRemoteStickyProxyInvocation.

/**
 * @throws Exception If failed.
 */
public void testRemoteStickyProxyInvocation() throws Exception {
    final String name = "testRemoteStickyProxyInvocation";
    final Ignite ignite = grid(0);
    ignite.services().deployNodeSingleton(name, new MapServiceImpl<String, Integer>());
    // Get remote proxy.
    MapService<Integer, String> svc = ignite.services(ignite.cluster().forRemotes()).serviceProxy(name, MapService.class, true);
    // Make sure service is a local instance.
    assertFalse(svc instanceof Service);
    for (int i = 0; i < nodeCount(); i++) svc.put(i, Integer.toString(i));
    int size = 0;
    for (ClusterNode n : ignite.cluster().forRemotes().nodes()) {
        MapService<Integer, String> map = ignite.services(ignite.cluster().forNode(n)).serviceProxy(name, MapService.class, false);
        // Make sure service is a local instance.
        assertFalse(map instanceof Service);
        if (map.size() != 0)
            size += map.size();
    }
    assertEquals(nodeCount(), size);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Service(org.apache.ignite.services.Service) Ignite(org.apache.ignite.Ignite)

Example 54 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridServiceProcessorBatchDeploySelfTest method _testDeployAllTopologyChangeFail.

/**
 * TODO: enable when IGNITE-6259 is fixed.
 *
 * @throws Exception If failed.
 */
public void _testDeployAllTopologyChangeFail() throws Exception {
    final Ignite client = grid(CLIENT_NODE_NAME);
    final AtomicBoolean finished = new AtomicBoolean();
    IgniteInternalFuture<Object> topChangeFut = runTopChanger(finished);
    try {
        int numServices = 500;
        int batchSize = 5;
        CountDownLatch latch = new CountDownLatch(numServices);
        IgnitePredicate<ClusterNode> depPred = client.cluster().forServers().forPredicate(new IgnitePredicate<ClusterNode>() {

            @Override
            public boolean apply(ClusterNode node) {
                String gridName = node.attribute(IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME);
                assert gridName != null;
                return gridName.startsWith(getTestIgniteInstanceName());
            }
        }).predicate();
        List<ServiceConfiguration> cfgs = getConfigs(depPred, numServices);
        List<ServiceConfiguration> failingCfgs = new ArrayList<>();
        subscribeExeLatch(cfgs, latch);
        int from = 0;
        while (from < numServices) {
            int to = Math.min(numServices, from + batchSize);
            List<ServiceConfiguration> cfgsBatch = cfgs.subList(from, to);
            ServiceConfiguration failingCfg = cfgsBatch.get(0);
            failingCfg.setName(null);
            failingCfgs.add(failingCfg);
            try {
                client.services().deployAllAsync(cfgsBatch).get(5000);
                fail("Should never reach here.");
            } catch (ServiceDeploymentException e) {
                assertEquals(1, e.getFailedConfigurations().size());
                ServiceConfiguration actFailedCfg = copyService(e.getFailedConfigurations().iterator().next());
                assertEquals(failingCfg, actFailedCfg);
                latch.countDown();
            }
            from = to;
        }
        assertTrue(latch.await(30, TimeUnit.SECONDS));
        cfgs.removeAll(failingCfgs);
        assertDeployedServices(client, cfgs);
    } finally {
        finished.set(true);
    }
    topChangeFut.get();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ArrayList(java.util.ArrayList) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Ignite(org.apache.ignite.Ignite)

Example 55 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridDhtAtomicAbstractUpdateFuture method addWriteEntry.

/**
 * @param affAssignment Affinity assignment.
 * @param entry Entry to map.
 * @param val Value to write.
 * @param entryProcessor Entry processor.
 * @param ttl TTL (optional).
 * @param conflictExpireTime Conflict expire time (optional).
 * @param conflictVer Conflict version (optional).
 * @param addPrevVal If {@code true} sends previous value to backups.
 * @param prevVal Previous value.
 * @param updateCntr Partition update counter.
 */
@SuppressWarnings("ForLoopReplaceableByForEach")
final void addWriteEntry(AffinityAssignment affAssignment, GridDhtCacheEntry entry, @Nullable CacheObject val, EntryProcessor<Object, Object, Object> entryProcessor, long ttl, long conflictExpireTime, @Nullable GridCacheVersion conflictVer, boolean addPrevVal, @Nullable CacheObject prevVal, long updateCntr) {
    AffinityTopologyVersion topVer = updateReq.topologyVersion();
    List<ClusterNode> affNodes = affAssignment.get(entry.partition());
    // Client has seen that rebalancing finished, it is safe to use affinity mapping.
    List<ClusterNode> dhtNodes = updateReq.affinityMapping() ? affNodes : cctx.dht().topology().nodes(entry.partition(), affAssignment, affNodes);
    if (dhtNodes == null)
        dhtNodes = affNodes;
    if (log.isDebugEnabled())
        log.debug("Mapping entry to DHT nodes [nodes=" + U.nodeIds(dhtNodes) + ", entry=" + entry + ']');
    CacheWriteSynchronizationMode syncMode = updateReq.writeSynchronizationMode();
    addDhtKey(entry.key(), dhtNodes);
    for (int i = 0; i < dhtNodes.size(); i++) {
        ClusterNode node = dhtNodes.get(i);
        UUID nodeId = node.id();
        if (!nodeId.equals(cctx.localNodeId())) {
            GridDhtAtomicAbstractUpdateRequest updateReq = mappings.get(nodeId);
            if (updateReq == null) {
                updateReq = createRequest(node.id(), futId, writeVer, syncMode, topVer, ttl, conflictExpireTime, conflictVer);
                mappings.put(nodeId, updateReq);
            }
            updateReq.addWriteValue(entry.key(), val, entryProcessor, ttl, conflictExpireTime, conflictVer, addPrevVal, prevVal, updateCntr);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) UUID(java.util.UUID)

Aggregations

ClusterNode (org.apache.ignite.cluster.ClusterNode)1104 UUID (java.util.UUID)281 ArrayList (java.util.ArrayList)280 Test (org.junit.Test)276 Ignite (org.apache.ignite.Ignite)239 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)239 HashMap (java.util.HashMap)184 Map (java.util.Map)182 List (java.util.List)165 IgniteException (org.apache.ignite.IgniteException)147 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)147 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)143 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)126 Collection (java.util.Collection)113 Message (org.apache.ignite.plugin.extensions.communication.Message)106 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)87 HashSet (java.util.HashSet)85 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)82 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)81 IgniteEx (org.apache.ignite.internal.IgniteEx)81