Search in sources :

Example 21 with IgniteEx

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

the class IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest method checkCleanState.

/**
 * Validates clean state on all participating nodes after query cancellation.
 */
@SuppressWarnings("unchecked")
private void checkCleanState() throws IgniteCheckedException {
    for (int i = 0; i < GRIDS_CNT; i++) {
        IgniteEx grid = grid(i);
        // Validate everything was cleaned up.
        ConcurrentMap<UUID, ?> map = U.field(((IgniteH2Indexing) U.field((GridProcessor) U.field(grid.context(), "qryProc"), "idx")).mapQueryExecutor(), "qryRess");
        String msg = "Map executor state is not cleared";
        // TODO FIXME Current implementation leaves map entry for each node that's ever executed a query.
        for (Object result : map.values()) {
            Map<Long, ?> m = U.field(result, "res");
            assertEquals(msg, 0, m.size());
        }
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) UUID(java.util.UUID)

Example 22 with IgniteEx

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

the class IgniteCacheQueryNodeRestartSelfTest2 method testRestarts.

/**
 * @throws Exception If failed.
 */
public void testRestarts() throws Exception {
    int duration = 90 * 1000;
    int qryThreadNum = 4;
    // 4 + 2 = 6 nodes
    int restartThreadsNum = 2;
    final int nodeLifeTime = 2 * 1000;
    final int logFreq = 10;
    startGridsMultiThreaded(GRID_CNT);
    final AtomicIntegerArray locks = new AtomicIntegerArray(GRID_CNT);
    fillCaches();
    final List<List<?>> pRes = grid(0).cache("pu").query(new SqlFieldsQuery(PARTITIONED_QRY)).getAll();
    Thread.sleep(3000);
    assertEquals(pRes, grid(0).cache("pu").query(new SqlFieldsQuery(PARTITIONED_QRY)).getAll());
    final List<List<?>> rRes = grid(0).cache("co").query(new SqlFieldsQuery(REPLICATED_QRY)).getAll();
    assertFalse(pRes.isEmpty());
    assertFalse(rRes.isEmpty());
    final AtomicInteger qryCnt = new AtomicInteger();
    final AtomicBoolean qrysDone = new AtomicBoolean();
    IgniteInternalFuture<?> fut1 = multithreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            final GridRandom rnd = new GridRandom();
            while (!qrysDone.get()) {
                int g;
                do {
                    g = rnd.nextInt(locks.length());
                } while (!locks.compareAndSet(g, 0, 1));
                try {
                    final IgniteEx grid = grid(g);
                    if (rnd.nextBoolean()) {
                        // Partitioned query.
                        final IgniteCache<?, ?> cache = grid.cache("pu");
                        final SqlFieldsQuery qry = new SqlFieldsQuery(PARTITIONED_QRY);
                        boolean smallPageSize = rnd.nextBoolean();
                        if (smallPageSize)
                            qry.setPageSize(3);
                        final IgniteCache<Integer, Company> co = grid.cache("co");
                        try {
                            runQuery(grid, new Runnable() {

                                @Override
                                public void run() {
                                    if (rnd.nextBoolean())
                                        // Get lock run test with open transaction.
                                        co.get(rnd.nextInt(COMPANY_CNT));
                                    assertEquals(pRes, cache.query(qry).getAll());
                                }
                            });
                        } catch (CacheException e) {
                            // Interruptions are expected here.
                            if (e.getCause() instanceof IgniteInterruptedCheckedException || e.getCause() instanceof InterruptedException || e.getCause() instanceof ClusterTopologyException || e.getCause() instanceof TransactionTimeoutException || e.getCause() instanceof TransactionException)
                                continue;
                            if (e.getCause() instanceof QueryCancelledException)
                                fail("Retry is expected");
                            if (!smallPageSize)
                                U.error(grid.log(), "On large page size must retry.", e);
                            assertTrue("On large page size must retry.", smallPageSize);
                            boolean failedOnRemoteFetch = false;
                            boolean failedOnInterruption = false;
                            for (Throwable th = e; th != null; th = th.getCause()) {
                                if (th instanceof InterruptedException) {
                                    failedOnInterruption = true;
                                    break;
                                }
                                if (!(th instanceof CacheException))
                                    continue;
                                if (th.getMessage() != null && th.getMessage().startsWith("Failed to fetch data from node:")) {
                                    failedOnRemoteFetch = true;
                                    break;
                                }
                            }
                            // Interruptions are expected here.
                            if (failedOnInterruption)
                                continue;
                            if (!failedOnRemoteFetch) {
                                U.error(grid.log(), "Must fail inside of GridResultPage.fetchNextPage or subclass.", e);
                                fail("Must fail inside of GridResultPage.fetchNextPage or subclass.");
                            }
                        }
                    } else {
                        // Replicated query.
                        IgniteCache<?, ?> cache = grid.cache("co");
                        assertEquals(rRes, cache.query(new SqlFieldsQuery(REPLICATED_QRY)).getAll());
                    }
                } finally {
                    // Clearing lock in final handler to avoid endless loop if exception is thrown.
                    locks.set(g, 0);
                    int c = qryCnt.incrementAndGet();
                    if (c % logFreq == 0)
                        info("Executed queries: " + c);
                }
            }
        }
    }, qryThreadNum, "query-thread");
    final AtomicInteger restartCnt = new AtomicInteger();
    final AtomicBoolean restartsDone = new AtomicBoolean();
    IgniteInternalFuture<?> fut2 = multithreadedAsync(new Callable<Object>() {

        @SuppressWarnings({ "BusyWait" })
        @Override
        public Object call() throws Exception {
            GridRandom rnd = new GridRandom();
            while (!restartsDone.get()) {
                int g;
                do {
                    g = rnd.nextInt(locks.length());
                } while (!locks.compareAndSet(g, 0, -1));
                try {
                    log.info("Stop node: " + g);
                    stopGrid(g);
                    Thread.sleep(rnd.nextInt(nodeLifeTime));
                    log.info("Start node: " + g);
                    startGrid(g);
                    Thread.sleep(rnd.nextInt(nodeLifeTime));
                } finally {
                    locks.set(g, 0);
                    int c = restartCnt.incrementAndGet();
                    if (c % logFreq == 0)
                        info("Node restarts: " + c);
                }
            }
            return true;
        }
    }, restartThreadsNum, "restart-thread");
    Thread.sleep(duration);
    info("Stopping..");
    restartsDone.set(true);
    try {
        fut2.get(20_000);
    } catch (IgniteFutureTimeoutCheckedException e) {
        U.dumpThreads(log);
        fail("Stopping restarts timeout.");
    }
    info("Restarts stopped.");
    qrysDone.set(true);
    // Query thread can stuck in next page waiting loop because all nodes are left.
    try {
        fut1.get(5_000);
    } catch (IgniteFutureTimeoutCheckedException ignored) {
        fut1.cancel();
    }
    info("Queries stopped.");
}
Also used : CacheException(javax.cache.CacheException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridRandom(org.apache.ignite.internal.util.GridRandom) TransactionException(org.apache.ignite.transactions.TransactionException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) List(java.util.List) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) IgniteCache(org.apache.ignite.IgniteCache) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheException(javax.cache.CacheException) TransactionException(org.apache.ignite.transactions.TransactionException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) IgniteEx(org.apache.ignite.internal.IgniteEx) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CAX(org.apache.ignite.internal.util.typedef.CAX) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException)

Example 23 with IgniteEx

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

the class IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest method checkCleanState.

/**
 * Validates clean state on all participating nodes after query cancellation.
 */
@SuppressWarnings("unchecked")
private void checkCleanState() throws IgniteCheckedException {
    for (int i = 0; i < GRID_CNT; i++) {
        IgniteEx grid = grid(i);
        // Validate everything was cleaned up.
        ConcurrentMap<UUID, ?> map = U.field(((IgniteH2Indexing) U.field((GridProcessor) U.field(grid.context(), "qryProc"), "idx")).mapQueryExecutor(), "qryRess");
        String msg = "Map executor state is not cleared";
        // TODO FIXME Current implementation leaves map entry for each node that's ever executed a query.
        for (Object result : map.values()) {
            Map<Long, ?> m = U.field(result, "res");
            assertEquals(msg, 0, m.size());
        }
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) UUID(java.util.UUID)

Example 24 with IgniteEx

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

the class AbstractSchemaSelfTest method assertIndex.

/**
 * Assert index state on particular node.
 *
 * @param node Node.
 * @param cacheName Cache name.
 * @param tblName Table name.
 * @param idxName Index name.
 * @param inlineSize Inline size.
 * @param fields Fields.
 */
static void assertIndex(Ignite node, String cacheName, String tblName, String idxName, int inlineSize, IgniteBiTuple<String, Boolean>... fields) {
    awaitCompletion();
    node.cache(cacheName);
    IgniteEx node0 = (IgniteEx) node;
    ArrayList<IgniteBiTuple<String, Boolean>> res = new ArrayList<>();
    try {
        try (Connection c = connect(node0)) {
            try (ResultSet rs = c.getMetaData().getIndexInfo(null, cacheName, tblName, false, false)) {
                while (rs.next()) {
                    if (F.eq(idxName, rs.getString("INDEX_NAME")))
                        res.add(new T2<>(rs.getString("COLUMN_NAME"), F.eq("A", rs.getString("ASC_OR_DESC"))));
                }
            }
        }
        assertTrue("Index not found: " + idxName, res.size() > 0);
        assertEquals(Arrays.asList(fields), res);
    } catch (SQLException e) {
        throw new AssertionError(e);
    }
    // Also, let's check internal stuff not visible via JDBC - like inline size.
    QueryTypeDescriptorImpl typeDesc = typeExisting(node0, cacheName, tblName);
    assertInternalIndexParams(typeDesc, idxName, inlineSize);
}
Also used : QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) SQLException(java.sql.SQLException) IgniteEx(org.apache.ignite.internal.IgniteEx) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) T2(org.apache.ignite.internal.util.typedef.T2)

Example 25 with IgniteEx

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

the class DynamicColumnsAbstractConcurrentSelfTest method checkNodeJoinOnPendingOperation.

/**
 * Check node join on pending operation.
 *
 * @param addOrRemove Pass {@code true} to check add column. Otherwise, drop column is checked.
 * @throws Exception If failed.
 */
private void checkNodeJoinOnPendingOperation(boolean addOrRemove) throws Exception {
    CountDownLatch finishLatch = new CountDownLatch(4);
    IgniteEx srv1 = ignitionStart(serverConfiguration(1), finishLatch);
    createSqlCache(srv1);
    run(srv1, addOrRemove ? createSql : createSql4Cols);
    CountDownLatch idxLatch = blockIndexing(srv1);
    QueryField c = c("AGE", Integer.class.getName());
    IgniteInternalFuture<?> idxFut = addOrRemove ? addCols(srv1, QueryUtils.DFLT_SCHEMA, c) : dropCols(srv1, QueryUtils.DFLT_SCHEMA, "CITY");
    U.await(idxLatch);
    ignitionStart(serverConfiguration(2), finishLatch);
    ignitionStart(serverConfiguration(3, true), finishLatch);
    ignitionStart(clientConfiguration(4), finishLatch);
    assertFalse(idxFut.isDone());
    unblockIndexing(srv1);
    idxFut.get();
    U.await(finishLatch);
    checkTableState(srv1, QueryUtils.DFLT_SCHEMA, TBL_NAME, c);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryField(org.apache.ignite.internal.processors.query.QueryField) IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)396 Ignite (org.apache.ignite.Ignite)85 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)64 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)60 IgniteException (org.apache.ignite.IgniteException)46 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)37 Transaction (org.apache.ignite.transactions.Transaction)34 ArrayList (java.util.ArrayList)31 HashMap (java.util.HashMap)31 CountDownLatch (java.util.concurrent.CountDownLatch)28 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)27 IgniteCache (org.apache.ignite.IgniteCache)25 Map (java.util.Map)24 ClusterNode (org.apache.ignite.cluster.ClusterNode)20 CacheException (javax.cache.CacheException)19 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)19 UUID (java.util.UUID)18 Callable (java.util.concurrent.Callable)17 List (java.util.List)16 Random (java.util.Random)16