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);
}
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);
}
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.
}
}
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);
}
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);
}
Aggregations