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