Search in sources :

Example 71 with QueryIndex

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

the class DynamicIndexAbstractConcurrentSelfTest method testNodeJoinOnPendingOperation.

/**
 * Test node join on pending operation.
 *
 * @throws Exception If failed.
 */
public void testNodeJoinOnPendingOperation() throws Exception {
    Ignite srv1 = ignitionStart(serverConfiguration(1));
    createSqlCache(srv1);
    CountDownLatch idxLatch = blockIndexing(srv1);
    QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
    IgniteInternalFuture<?> idxFut = queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, false, 0);
    ignitionStart(serverConfiguration(2));
    ignitionStart(serverConfiguration(3, true));
    ignitionStart(clientConfiguration(4));
    assert !idxFut.isDone();
    unblockIndexing(srv1);
    idxFut.get();
    idxLatch.countDown();
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, QueryIndex.DFLT_INLINE_SIZE, field(FIELD_NAME_1));
    put(srv1, 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 : QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 72 with QueryIndex

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

the class DynamicIndexAbstractConcurrentSelfTest method testOperationChaining.

/**
 * Test operations join.
 *
 * @throws Exception If failed.
 */
public void testOperationChaining() throws Exception {
    Ignite srv1 = ignitionStart(serverConfiguration(1));
    ignitionStart(serverConfiguration(2));
    ignitionStart(serverConfiguration(3, true));
    ignitionStart(clientConfiguration(4));
    createSqlCache(srv1);
    CountDownLatch idxLatch = blockIndexing(srv1);
    QueryIndex idx1 = index(IDX_NAME_1, field(FIELD_NAME_1));
    QueryIndex idx2 = index(IDX_NAME_2, field(aliasUnescaped(FIELD_NAME_2)));
    IgniteInternalFuture<?> idxFut1 = queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx1, false, 0);
    IgniteInternalFuture<?> idxFut2 = queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx2, false, 0);
    // Start even more nodes of different flavors
    ignitionStart(serverConfiguration(5));
    ignitionStart(serverConfiguration(6, true));
    ignitionStart(clientConfiguration(7));
    assert !idxFut1.isDone();
    assert !idxFut2.isDone();
    unblockIndexing(srv1);
    idxFut1.get();
    idxFut2.get();
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, QueryIndex.DFLT_INLINE_SIZE, field(FIELD_NAME_1));
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, QueryIndex.DFLT_INLINE_SIZE, field(aliasUnescaped(FIELD_NAME_2)));
    idxLatch.countDown();
    put(srv1, 0, KEY_AFTER);
    assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
    assertIndexUsed(IDX_NAME_2, SQL_SIMPLE_FIELD_2, SQL_ARG_1);
    assertSqlSimpleData(SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
    assertSqlSimpleData(SQL_SIMPLE_FIELD_2, KEY_AFTER - SQL_ARG_1);
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 73 with QueryIndex

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

the class DynamicIndexAbstractConcurrentSelfTest method testConcurrentCacheDestroy.

/**
 * Check what happen in case cache is destroyed before operation is started.
 *
 * @throws Exception If failed.
 */
public void testConcurrentCacheDestroy() throws Exception {
    // Start complex topology.
    Ignite srv1 = ignitionStart(serverConfiguration(1));
    ignitionStart(serverConfiguration(2));
    ignitionStart(serverConfiguration(3, true));
    Ignite cli = ignitionStart(clientConfiguration(4));
    // Start cache and populate it with data.
    createSqlCache(cli);
    put(cli, KEY_AFTER);
    // Start index operation and block it on coordinator.
    CountDownLatch idxLatch = blockIndexing(srv1);
    QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
    final IgniteInternalFuture<?> idxFut = queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, false, 0);
    idxLatch.countDown();
    // Destroy cache (drop table).
    destroySqlCache(cli);
    // Unblock indexing and see what happens.
    unblockIndexing(srv1);
    try {
        idxFut.get();
        fail("Exception has not been thrown.");
    } catch (SchemaOperationException e) {
    // No-op.
    }
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 74 with QueryIndex

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

the class DynamicIndexAbstractConcurrentSelfTest method testConcurrentOperationsMultithreaded.

/**
 * Make sure that contended operations on the same index from different nodes do not hang.
 *
 * @throws Exception If failed.
 */
public void testConcurrentOperationsMultithreaded() throws Exception {
    // Start complex topology.
    ignitionStart(serverConfiguration(1));
    ignitionStart(serverConfiguration(2));
    ignitionStart(serverConfiguration(3, true));
    Ignite cli = ignitionStart(clientConfiguration(4));
    createSqlCache(cli);
    final AtomicBoolean stopped = new AtomicBoolean();
    // 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, 0);
                    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.
    idxFut.get();
    queryProcessor(cli).dynamicIndexDrop(CACHE_NAME, CACHE_NAME, IDX_NAME_1, true).get();
    queryProcessor(cli).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, true, 0).get();
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, QueryIndex.DFLT_INLINE_SIZE, 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 75 with QueryIndex

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

the class DynamicIndexAbstractConcurrentSelfTest method testConcurrentRebalance.

/**
 * Test index consistency on re-balance.
 *
 * @throws Exception If failed.
 */
public void testConcurrentRebalance() throws Exception {
    // Start cache and populate it with data.
    Ignite srv1 = ignitionStart(serverConfiguration(1));
    Ignite srv2 = ignitionStart(serverConfiguration(2));
    createSqlCache(srv1);
    awaitPartitionMapExchange();
    put(srv1, 0, LARGE_CACHE_SIZE);
    // Start index operation in blocked state.
    CountDownLatch idxLatch1 = blockIndexing(srv1);
    CountDownLatch idxLatch2 = blockIndexing(srv2);
    QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
    final IgniteInternalFuture<?> idxFut = queryProcessor(srv1).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, false, 0);
    idxLatch1.countDown();
    idxLatch2.countDown();
    // Start two more nodes and unblock index operation in the middle.
    ignitionStart(serverConfiguration(3));
    unblockIndexing(srv1);
    unblockIndexing(srv2);
    ignitionStart(serverConfiguration(4));
    awaitPartitionMapExchange();
    // Validate index state.
    idxFut.get();
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, QueryIndex.DFLT_INLINE_SIZE, field(FIELD_NAME_1));
    assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
    assertSqlSimpleData(SQL_SIMPLE_FIELD_1, LARGE_CACHE_SIZE - SQL_ARG_1);
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

QueryIndex (org.apache.ignite.cache.QueryIndex)89 QueryEntity (org.apache.ignite.cache.QueryEntity)46 LinkedHashMap (java.util.LinkedHashMap)35 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)26 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)24 ArrayList (java.util.ArrayList)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)20 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)14 Ignite (org.apache.ignite.Ignite)13 CacheException (javax.cache.CacheException)10 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)10 IgniteException (org.apache.ignite.IgniteException)9 HashMap (java.util.HashMap)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)8 Map (java.util.Map)7 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)7 HashSet (java.util.HashSet)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 BinaryObject (org.apache.ignite.binary.BinaryObject)5 CountDownLatch (java.util.concurrent.CountDownLatch)4