Search in sources :

Example 31 with ClusterNode

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

the class GridH2IndexBase method broadcastSegments.

/**
 * @param qctx Query context.
 * @param cctx Cache context.
 * @param isLocalQry Local query flag.
 * @return Collection of nodes for broadcasting.
 */
private List<SegmentKey> broadcastSegments(GridH2QueryContext qctx, GridCacheContext<?, ?> cctx, boolean isLocalQry) {
    Map<UUID, int[]> partMap = qctx.partitionsMap();
    List<ClusterNode> nodes;
    if (isLocalQry) {
        if (partMap != null && !partMap.containsKey(cctx.localNodeId()))
            // Prevent remote index call for local queries.
            return Collections.emptyList();
        nodes = Collections.singletonList(cctx.localNode());
    } else {
        if (partMap == null)
            nodes = new ArrayList<>(CU.affinityNodes(cctx, qctx.topologyVersion()));
        else {
            nodes = new ArrayList<>(partMap.size());
            GridKernalContext ctx = kernalContext();
            for (UUID nodeId : partMap.keySet()) {
                ClusterNode node = ctx.discovery().node(nodeId);
                if (node == null)
                    throw new GridH2RetryException("Failed to find node.");
                nodes.add(node);
            }
        }
        if (F.isEmpty(nodes))
            throw new GridH2RetryException("Failed to collect affinity nodes.");
    }
    int segmentsCount = segmentsCount();
    List<SegmentKey> res = new ArrayList<>(nodes.size() * segmentsCount);
    for (ClusterNode node : nodes) {
        for (int seg = 0; seg < segmentsCount; seg++) res.add(new SegmentKey(node, seg));
    }
    return res;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 32 with ClusterNode

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

the class GridH2IndexBase method rangeSegment.

/**
 * @param cctx Cache context.
 * @param qctx Query context.
 * @param affKeyObj Affinity key.
 * @param isLocalQry Local query flag.
 * @return Segment key for Affinity key.
 */
private SegmentKey rangeSegment(GridCacheContext<?, ?> cctx, GridH2QueryContext qctx, Object affKeyObj, boolean isLocalQry) {
    assert affKeyObj != null && affKeyObj != EXPLICIT_NULL : affKeyObj;
    ClusterNode node;
    int partition = cctx.affinity().partition(affKeyObj);
    if (isLocalQry) {
        if (qctx.partitionsMap() != null) {
            // If we have explicit partitions map, we have to use it to calculate affinity node.
            UUID nodeId = qctx.nodeForPartition(partition, cctx);
            if (!cctx.localNodeId().equals(nodeId))
                // Prevent remote index call for local queries.
                return null;
        }
        if (!cctx.affinity().primaryByKey(cctx.localNode(), partition, qctx.topologyVersion()))
            return null;
        node = cctx.localNode();
    } else {
        if (qctx.partitionsMap() != null) {
            // If we have explicit partitions map, we have to use it to calculate affinity node.
            UUID nodeId = qctx.nodeForPartition(partition, cctx);
            node = cctx.discovery().node(nodeId);
        } else
            // Get primary node for current topology version.
            node = cctx.affinity().primaryByKey(affKeyObj, qctx.topologyVersion());
        if (// Node was not found, probably topology changed and we need to retry the whole query.
        node == null)
            throw new GridH2RetryException("Failed to find node.");
    }
    return new SegmentKey(node, segmentForPartition(partition));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) UUID(java.util.UUID)

Example 33 with ClusterNode

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

the class AgentClusterDemo method tryStart.

/**
 * Start ignite node with cacheEmployee and populate it with data.
 */
public static CountDownLatch tryStart() {
    if (initGuard.compareAndSet(false, true)) {
        log.info("DEMO: Starting embedded nodes for demo...");
        System.setProperty(IGNITE_NO_ASCII, "true");
        System.setProperty(IGNITE_QUIET, "false");
        System.setProperty(IGNITE_UPDATE_NOTIFIER, "false");
        System.setProperty(IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE, "20");
        System.setProperty(IGNITE_PERFORMANCE_SUGGESTIONS_DISABLED, "true");
        final AtomicInteger basePort = new AtomicInteger(60700);
        final AtomicInteger cnt = new AtomicInteger(-1);
        final ScheduledExecutorService execSrv = newScheduledThreadPool(1, "demo-nodes-start");
        execSrv.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                int idx = cnt.incrementAndGet();
                int port = basePort.get();
                boolean first = idx == 0;
                try {
                    IgniteConfiguration cfg = igniteConfiguration(port, idx, false);
                    if (first) {
                        U.delete(Paths.get(cfg.getWorkDirectory()));
                        U.resolveWorkDirectory(cfg.getWorkDirectory(), cfg.getDataStorageConfiguration().getStoragePath(), true);
                    }
                    Ignite ignite = Ignition.start(cfg);
                    if (first) {
                        ClusterNode node = ignite.cluster().localNode();
                        Collection<String> jettyAddrs = node.attribute(ATTR_REST_JETTY_ADDRS);
                        if (jettyAddrs == null) {
                            Ignition.stopAll(true);
                            throw new IgniteException("DEMO: Failed to start Jetty REST server on embedded node");
                        }
                        String jettyHost = jettyAddrs.iterator().next();
                        Integer jettyPort = node.attribute(ATTR_REST_JETTY_PORT);
                        if (F.isEmpty(jettyHost) || jettyPort == null)
                            throw new IgniteException("DEMO: Failed to start Jetty REST handler on embedded node");
                        log.info("DEMO: Started embedded node for demo purpose [TCP binary port={}, Jetty REST port={}]", port, jettyPort);
                        demoUrl = String.format("http://%s:%d", jettyHost, jettyPort);
                        initLatch.countDown();
                    }
                } catch (Throwable e) {
                    if (first) {
                        basePort.getAndAdd(50);
                        log.warn("DEMO: Failed to start embedded node.", e);
                    } else
                        log.error("DEMO: Failed to start embedded node.", e);
                } finally {
                    if (idx == NODE_CNT) {
                        Ignite ignite = Ignition.ignite(SRV_NODE_NAME + 0);
                        if (ignite != null) {
                            ignite.cluster().active(true);
                            deployServices(ignite.services(ignite.cluster().forServers()));
                        }
                        log.info("DEMO: All embedded nodes for demo successfully started");
                        execSrv.shutdown();
                    }
                }
            }
        }, 1, 5, TimeUnit.SECONDS);
    }
    return initLatch;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite)

Example 34 with ClusterNode

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

the class IgniteCacheAbstractBenchmark method setUp.

/**
 * {@inheritDoc}
 */
@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
    super.setUp(cfg);
    cache = cache();
    CacheConfiguration<?, ?> ccfg = cache.getConfiguration(CacheConfiguration.class);
    String grpName = ccfg.getGroupName();
    BenchmarkUtils.println(cfg, "Benchmark setUp [name=" + getClass().getSimpleName() + ", cacheName=" + cache.getName() + ", cacheGroup=" + grpName + ", cacheCfg=" + cache.getConfiguration(CacheConfiguration.class) + ']');
    caches = args.cachesCount();
    if (caches > 1) {
        List<CacheConfiguration> toCreate = new ArrayList<>();
        for (int i = 0; i < caches - 1; i++) {
            JdkMarshaller marsh = new JdkMarshaller();
            CacheConfiguration ccfg0 = marsh.unmarshal(marsh.marshal(ccfg), null);
            ccfg0.setName(cache.getName() + "-" + i);
            toCreate.add(ccfg0);
        }
        Collection<IgniteCache> caches = ignite().getOrCreateCaches(toCreate);
        testCaches = new ArrayList<>(caches);
        testCaches.add(cache);
        BenchmarkUtils.println(cfg, "Created additional caches [caches=" + testCaches.size() + ", grp=" + grpName + ']');
    }
    if (args.printPartitionStatistics()) {
        Map<ClusterNode, T2<List<Integer>, List<Integer>>> parts = new HashMap<>();
        for (ClusterNode node : ignite().cluster().nodes()) parts.put(node, new T2<List<Integer>, List<Integer>>(new ArrayList<Integer>(), new ArrayList<Integer>()));
        U.sleep(5000);
        Affinity<Object> aff = ignite().affinity(cache.getName());
        for (int p = 0; p < aff.partitions(); p++) {
            Collection<ClusterNode> nodes = aff.mapPartitionToPrimaryAndBackups(p);
            boolean primary = true;
            for (ClusterNode node : nodes) {
                if (primary) {
                    parts.get(node).get1().add(p);
                    primary = false;
                } else
                    parts.get(node).get2().add(p);
            }
        }
        BenchmarkUtils.println(cfg, "Partition stats. [cacheName: " + cache.getName() + ", topVer: " + ignite().cluster().topologyVersion() + "]");
        BenchmarkUtils.println(cfg, "(Node id,  Number of Primary, Percent, Number of Backup, Percent, Total, Percent)");
        for (Map.Entry<ClusterNode, T2<List<Integer>, List<Integer>>> e : parts.entrySet()) {
            List<Integer> primary = e.getValue().get1();
            List<Integer> backup = e.getValue().get2();
            BenchmarkUtils.println(cfg, e.getKey().id() + "  " + primary.size() + "  " + primary.size() * 1. / aff.partitions() + "  " + backup.size() + "  " + backup.size() * 1. / (aff.partitions() * (args.backups() == 0 ? 1 : args.backups())) + "  " + (primary.size() + backup.size()) + "  " + (primary.size() + backup.size() * 1.) / (aff.partitions() * args.backups() + aff.partitions()));
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IgniteCache(org.apache.ignite.IgniteCache) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JdkMarshaller(org.apache.ignite.marshaller.jdk.JdkMarshaller) HashMap(java.util.HashMap) Map(java.util.Map) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) T2(org.apache.ignite.internal.util.typedef.T2)

Example 35 with ClusterNode

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

the class IgniteIoTestAbstractBenchmark method setUp.

/**
 * {@inheritDoc}
 */
@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
    super.setUp(cfg);
    ignite = (IgniteKernal) ignite();
    ClusterNode loc = ignite().cluster().localNode();
    Collection<ClusterNode> nodes = ignite().cluster().forServers().nodes();
    for (ClusterNode node : nodes) {
        if (!loc.equals(node))
            targetNodes.add(node);
    }
    if (targetNodes.isEmpty())
        throw new IgniteException("Failed to find remote server nodes [nodes=" + nodes + ']');
    BenchmarkUtils.println(cfg, "Initialized target nodes: " + F.nodeIds(targetNodes) + ']');
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteException(org.apache.ignite.IgniteException)

Aggregations

ClusterNode (org.apache.ignite.cluster.ClusterNode)738 UUID (java.util.UUID)185 ArrayList (java.util.ArrayList)180 Ignite (org.apache.ignite.Ignite)151 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)150 HashMap (java.util.HashMap)104 Map (java.util.Map)89 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)86 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)80 List (java.util.List)79 IgniteException (org.apache.ignite.IgniteException)68 Collection (java.util.Collection)67 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)58 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)52 HashSet (java.util.HashSet)39 CountDownLatch (java.util.concurrent.CountDownLatch)38 Event (org.apache.ignite.events.Event)38 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)36 IgniteKernal (org.apache.ignite.internal.IgniteKernal)35 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)34