Search in sources :

Example 81 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.

the class GridIoManagerBenchmark0 method testVariableLoad.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("deprecation")
public void testVariableLoad() throws Exception {
    final IgniteKernal sndKernal = (IgniteKernal) grid(0);
    final IgniteKernal rcvKernal = (IgniteKernal) grid(1);
    final ClusterNode sndNode = sndKernal.localNode();
    final ClusterNode rcvNode = rcvKernal.localNode();
    final GridIoManager snd = sndKernal.context().io();
    final GridIoManager rcv = rcvKernal.context().io();
    info("Senders: " + THREADS);
    info("Messages: " + CONCUR_MSGS);
    final Semaphore sem = new Semaphore(CONCUR_MSGS);
    final LongAdder8 msgCntr = new LongAdder8();
    final String topic = "test-topic";
    final Map<IgniteUuid, CountDownLatch> latches = new ConcurrentHashMap8<>();
    rcv.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg) {
            try {
                rcv.sendToCustomTopic(sndNode, topic, (Message) msg, PUBLIC_POOL);
            } catch (IgniteCheckedException e) {
                error("Failed to send message.", e);
            }
        }
    });
    snd.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg) {
            msgCntr.increment();
            sem.release();
            CountDownLatch latch = latches.get(((GridTestMessage) msg).id());
            if (latch != null)
                latch.countDown();
        }
    });
    final AtomicBoolean finish = new AtomicBoolean();
    final AtomicReference<CountDownLatch> latchRef = new AtomicReference<>();
    IgniteInternalFuture<?> f = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (!finish.get()) {
                CountDownLatch latch = latchRef.get();
                if (latch != null)
                    U.await(latch);
                IgniteUuid msgId = IgniteUuid.randomUuid();
                sem.acquire();
                snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
            }
            return null;
        }
    }, THREADS, "send-thread");
    IgniteInternalFuture<?> f1 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        private long ts = System.currentTimeMillis();

        @Override
        public Object call() throws Exception {
            try {
                while (!finish.get()) {
                    info(U.nl() + ">>>" + U.nl() + ">>> High load." + U.nl() + ">>>");
                    U.sleep(15 * 1000);
                    reportNumbers();
                    info(U.nl() + ">>>" + U.nl() + ">>> Low load." + U.nl() + ">>>");
                    CountDownLatch latch = new CountDownLatch(1);
                    try {
                        // Here will be a pause.
                        latchRef.set(latch);
                        U.sleep(7 * 1000);
                        reportNumbers();
                    } finally {
                        latch.countDown();
                    }
                }
            } catch (IgniteCheckedException e) {
                X.println("Message send failed", e);
            }
            return null;
        }

        /**
             *
             */
        void reportNumbers() {
            long newTs = System.currentTimeMillis();
            long qrys = msgCntr.sumThenReset();
            long time = newTs - ts;
            X.println("Communication benchmark [qps=" + qrys * 1000 / time + ", executed=" + qrys + ", time=" + time + ']');
            ts = newTs;
        }
    }, 1, "load-dispatcher");
    IgniteInternalFuture<?> f2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (!finish.get()) {
                U.sleep(1000);
                IgniteUuid msgId = IgniteUuid.randomUuid();
                CountDownLatch latch = new CountDownLatch(1);
                latches.put(msgId, latch);
                snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
                long start = System.currentTimeMillis();
                latch.await();
                info("Response time: " + (System.currentTimeMillis() - start));
            }
            return null;
        }
    }, THREADS, "low-loader");
    Thread.sleep(TEST_TIMEOUT);
    finish.set(true);
    sem.release(CONCUR_MSGS * 2);
    f.get();
    f1.get();
    f2.get();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) Message(org.apache.ignite.plugin.extensions.communication.Message) ConcurrentHashMap8(org.jsr166.ConcurrentHashMap8) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) IgniteUuid(org.apache.ignite.lang.IgniteUuid) UUID(java.util.UUID) LongAdder8(org.jsr166.LongAdder8)

Example 82 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.

the class TcpDiscoverySelfTest method testGridStartTime.

/**
     * @throws Exception If any error occurs.
     */
public void testGridStartTime() throws Exception {
    try {
        startGridsMultiThreaded(5);
        Long startTime = null;
        IgniteKernal firstGrid = null;
        Collection<IgniteKernal> grids = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            IgniteKernal grid = (IgniteKernal) grid(i);
            assertTrue(grid.context().discovery().gridStartTime() > 0);
            if (i > 0)
                assertEquals(startTime, (Long) grid.context().discovery().gridStartTime());
            else
                startTime = grid.context().discovery().gridStartTime();
            if (grid.localNode().order() == 1)
                firstGrid = grid;
            else
                grids.add(grid);
        }
        assertNotNull(firstGrid);
        stopGrid(firstGrid.name());
        for (IgniteKernal grid : grids) assertEquals(startTime, (Long) grid.context().discovery().gridStartTime());
        grids.add((IgniteKernal) startGrid(5));
        for (IgniteKernal grid : grids) assertEquals(startTime, (Long) grid.context().discovery().gridStartTime());
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) ArrayList(java.util.ArrayList)

Example 83 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.

the class HibernateAccessStrategyFactory method start.

/**
     * @param props Properties.
     */
public void start(Properties props) {
    String gridCfg = props.getProperty(GRID_CONFIG_PROPERTY);
    String igniteInstanceName = props.getProperty(IGNITE_INSTANCE_NAME_PROPERTY);
    if (igniteInstanceName == null)
        igniteInstanceName = props.getProperty(GRID_NAME_PROPERTY);
    if (gridCfg != null) {
        try {
            ignite = G.start(gridCfg);
        } catch (IgniteException e) {
            throw eConverter.convert(e);
        }
    } else
        ignite = Ignition.ignite(igniteInstanceName);
    for (Map.Entry<Object, Object> prop : props.entrySet()) {
        String key = prop.getKey().toString();
        if (key.startsWith(REGION_CACHE_PROPERTY)) {
            String regionName = key.substring(REGION_CACHE_PROPERTY.length());
            String cacheName = prop.getValue().toString();
            if (((IgniteKernal) ignite).getCache(cacheName) == null)
                throw new IllegalArgumentException("Cache '" + cacheName + "' specified for region '" + regionName + "' " + "is not configured.");
            regionCaches.put(regionName, cacheName);
        }
    }
    String dfltCacheName = props.getProperty(DFLT_CACHE_NAME_PROPERTY);
    if (dfltCacheName != null) {
        IgniteInternalCache<Object, Object> dfltCache = ((IgniteKernal) ignite).getCache(dfltCacheName);
        if (dfltCache == null)
            throw new IllegalArgumentException("Cache specified as default is not configured: " + dfltCacheName);
        this.dfltCache = new HibernateCacheProxy(dfltCache, keyTransformer);
    }
    IgniteLogger log = ignite.log().getLogger(getClass());
    if (log.isDebugEnabled())
        log.debug("HibernateRegionFactory started [igniteInstanceName=" + igniteInstanceName + ']');
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteException(org.apache.ignite.IgniteException) IgniteLogger(org.apache.ignite.IgniteLogger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 84 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.

the class GridCacheCrossCacheQuerySelfTest method testTwoStepGroupAndAggregates.

/**
     * @throws Exception If failed.
     */
public void testTwoStepGroupAndAggregates() throws Exception {
    IgniteInternalCache<Integer, FactPurchase> cache = ((IgniteKernal) ignite).getCache("partitioned");
    GridQueryProcessor qryProc = ((IgniteKernal) ignite).context().query();
    Set<Integer> set1 = new HashSet<>();
    X.println("___ simple");
    SqlFieldsQuery qry = new SqlFieldsQuery("select f.productId, p.name, f.price " + "from FactPurchase f, \"replicated-prod\".DimProduct p where p.id = f.productId ");
    for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
        X.println("___ -> " + o);
        set1.add((Integer) o.get(0));
    }
    assertFalse(set1.isEmpty());
    Set<Integer> set0 = new HashSet<>();
    X.println("___ GROUP BY");
    qry = new SqlFieldsQuery("select productId from FactPurchase group by productId");
    for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
        X.println("___ -> " + o);
        assertTrue(set0.add((Integer) o.get(0)));
    }
    assertEquals(set0, set1);
    X.println("___ GROUP BY AVG MIN MAX SUM COUNT(*) COUNT(x) (MAX - MIN) * 2 as");
    Set<String> names = new HashSet<>();
    qry = new SqlFieldsQuery("select p.name, avg(f.price), min(f.price), max(f.price), sum(f.price), count(*), " + "count(nullif(f.price, 5)), (max(f.price) - min(f.price)) * 3 as nn " + ", CAST(max(f.price) + 7 AS VARCHAR) " + "from FactPurchase f, \"replicated-prod\".DimProduct p " + "where p.id = f.productId " + "group by f.productId, p.name");
    for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
        X.println("___ -> " + o);
        assertTrue(names.add((String) o.get(0)));
        assertEquals(i(o, 4), i(o, 2) + i(o, 3));
        assertEquals(i(o, 7), (i(o, 3) - i(o, 2)) * 3);
        assertEquals(o.get(8), Integer.toString(i(o, 3) + 7));
    }
    X.println("___ SUM HAVING");
    qry = new SqlFieldsQuery("select p.name, sum(f.price) s " + "from FactPurchase f, \"replicated-prod\".DimProduct p " + "where p.id = f.productId " + "group by f.productId, p.name " + "having s >= 15");
    for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
        X.println("___ -> " + o);
        assertTrue(i(o, 1) >= 15);
    }
    X.println("___ DISTINCT ORDER BY TOP");
    int top = 6;
    qry = new SqlFieldsQuery("select top 3 distinct productId " + "from FactPurchase f order by productId desc ");
    for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
        X.println("___ -> " + o);
        assertEquals(top--, o.get(0));
    }
    X.println("___ DISTINCT ORDER BY OFFSET LIMIT");
    top = 5;
    qry = new SqlFieldsQuery("select distinct productId " + "from FactPurchase f order by productId desc limit 2 offset 1");
    for (List<?> o : qryProc.querySqlFields(cache.context(), qry, false).getAll()) {
        X.println("___ -> " + o);
        assertEquals(top--, o.get(0));
    }
    assertEquals(3, top);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) HashSet(java.util.HashSet)

Example 85 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.

the class TcpDiscoveryMultiThreadedTest method testTopologyVersion.

/**
     * @throws Exception If any error occurs.
     */
public void testTopologyVersion() throws Exception {
    clientFlagGlobal = false;
    startGridsMultiThreaded(GRID_CNT);
    long prev = 0;
    for (Ignite g : G.allGrids()) {
        IgniteKernal kernal = (IgniteKernal) g;
        long ver = kernal.context().discovery().topologyVersion();
        info("Top ver: " + ver);
        if (prev == 0)
            prev = ver;
    }
    info("Test finished.");
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) Ignite(org.apache.ignite.Ignite)

Aggregations

IgniteKernal (org.apache.ignite.internal.IgniteKernal)164 Ignite (org.apache.ignite.Ignite)72 ClusterNode (org.apache.ignite.cluster.ClusterNode)30 Transaction (org.apache.ignite.transactions.Transaction)29 ArrayList (java.util.ArrayList)27 Map (java.util.Map)26 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)24 IgniteCache (org.apache.ignite.IgniteCache)24 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)22 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)22 UUID (java.util.UUID)21 IgniteException (org.apache.ignite.IgniteException)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 IgniteEx (org.apache.ignite.internal.IgniteEx)14 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)14 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)14 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)13 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)13 CacheException (javax.cache.CacheException)12 Collection (java.util.Collection)10