Search in sources :

Example 26 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class DynamicIndexAbstractConcurrentSelfTest method testConcurrentOperationsAndCacheStartStopMultithreaded.

/**
     * Multithreaded cache start/stop along with index operations. Nothing should hang.
     *
     * @throws Exception If failed.
     */
public void testConcurrentOperationsAndCacheStartStopMultithreaded() throws Exception {
    // Start complex topology.
    Ignition.start(serverConfiguration(1));
    Ignition.start(serverConfiguration(2));
    Ignition.start(serverConfiguration(3, true));
    Ignite cli = Ignition.start(clientConfiguration(4));
    final AtomicBoolean stopped = new AtomicBoolean();
    // Start cache create/destroy worker.
    IgniteInternalFuture startStopFut = multithreadedAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            boolean exists = false;
            while (!stopped.get()) {
                Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
                if (exists) {
                    destroySqlCache(node);
                    exists = false;
                } else {
                    createSqlCache(node);
                    exists = true;
                }
                Thread.sleep(ThreadLocalRandom.current().nextLong(200L, 400L));
            }
            return null;
        }
    }, 1);
    // Start several threads which will mess around indexes.
    final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
    IgniteInternalFuture idxFut = multithreadedAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            boolean exists = false;
            while (!stopped.get()) {
                Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
                IgniteInternalFuture fut;
                if (exists) {
                    fut = queryProcessor(node).dynamicIndexDrop(CACHE_NAME, CACHE_NAME, IDX_NAME_1, true);
                    exists = false;
                } else {
                    fut = queryProcessor(node).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, true);
                    exists = true;
                }
                try {
                    fut.get();
                } catch (SchemaOperationException e) {
                // No-op.
                } catch (Exception e) {
                    fail("Unexpected exception: " + e);
                }
            }
            return null;
        }
    }, 8);
    Thread.sleep(TEST_DUR);
    stopped.set(true);
    // Make sure nothing hanged.
    startStopFut.get();
    idxFut.get();
    // Make sure cache is operational at this point.
    createSqlCache(cli);
    queryProcessor(cli).dynamicIndexDrop(CACHE_NAME, CACHE_NAME, IDX_NAME_1, true).get();
    queryProcessor(cli).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, true).get();
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1));
    put(cli, 0, KEY_AFTER);
    assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
    assertSqlSimpleData(SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException)

Example 27 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class DynamicIndexAbstractBasicSelfTest method checkCreateComposite.

/**
     * Check composite index creation.
     *
     * @param mode Mode.
     * @param atomicityMode Atomicity mode.
     * @param near Near flag.
     * @throws Exception If failed.
     */
private void checkCreateComposite(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
    initialize(mode, atomicityMode, near);
    final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED), field(alias(FIELD_NAME_2_ESCAPED)));
    dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1_ESCAPED), field(alias(FIELD_NAME_2_ESCAPED)));
    assertCompositeIndexOperations(SQL_COMPOSITE);
    assertIndexUsed(IDX_NAME_1, SQL_COMPOSITE, SQL_ARG_1, SQL_ARG_2);
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex)

Example 28 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class DynamicIndexAbstractBasicSelfTest method testFailOnLocalCache.

/**
     * Test that operations fail on LOCAL cache.
     *
     * @throws Exception If failed.
     */
public void testFailOnLocalCache() throws Exception {
    for (Ignite node : Ignition.allGrids()) {
        if (!node.configuration().isClientMode())
            createSqlCache(node, cacheConfiguration().setCacheMode(LOCAL));
    }
    final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
    assertSchemaException(new RunnableX() {

        @Override
        public void run() throws Exception {
            dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true);
        }
    }, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
    assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
    assertSchemaException(new RunnableX() {

        @Override
        public void run() throws Exception {
            dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true);
        }
    }, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) CacheException(javax.cache.CacheException)

Example 29 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class DynamicIndexAbstractBasicSelfTest method checkCreate.

/**
     * Check normal create operation.
     *
     * @param mode Mode.
     * @param atomicityMode Atomicity mode.
     * @param near Near flag.
     * @throws Exception If failed.
     */
private void checkCreate(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
    initialize(mode, atomicityMode, near);
    final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
    dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
    assertSchemaException(new RunnableX() {

        @Override
        public void run() throws Exception {
            dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
        }
    }, IgniteQueryErrorCode.INDEX_ALREADY_EXISTS);
    dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true);
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
    assertSimpleIndexOperations(SQL_SIMPLE_FIELD_1);
    assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) CacheException(javax.cache.CacheException)

Example 30 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class DynamicIndexAbstractBasicSelfTest method checkCreateNoColumn.

/**
     * Check create when table doesn't exist.
     *
     * @param mode Mode.
     * @param atomicityMode Atomicity mode.
     * @param near Near flag.
     * @throws Exception If failed.
     */
private void checkCreateNoColumn(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
    initialize(mode, atomicityMode, near);
    final QueryIndex idx = index(IDX_NAME_1, field(randomString()));
    assertSchemaException(new RunnableX() {

        @Override
        public void run() throws Exception {
            dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
        }
    }, IgniteQueryErrorCode.COLUMN_NOT_FOUND);
    assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) CacheException(javax.cache.CacheException)

Aggregations

QueryIndex (org.apache.ignite.cache.QueryIndex)69 QueryEntity (org.apache.ignite.cache.QueryEntity)35 LinkedHashMap (java.util.LinkedHashMap)25 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)21 ArrayList (java.util.ArrayList)18 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)16 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)13 IgniteException (org.apache.ignite.IgniteException)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)8 HashMap (java.util.HashMap)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 CacheException (javax.cache.CacheException)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4