use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException 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.internal.processors.query.schema.SchemaOperationException in project ignite by apache.
the class DdlStatementsProcessor method runDdlStatement.
/**
* Execute DDL statement.
*
* @param sql SQL.
* @param stmt H2 statement to parse and execute.
*/
@SuppressWarnings("unchecked")
public FieldsQueryCursor<List<?>> runDdlStatement(String sql, PreparedStatement stmt) throws IgniteCheckedException {
assert stmt instanceof JdbcPreparedStatement;
IgniteInternalFuture fut = null;
try {
GridSqlStatement stmt0 = new GridSqlQueryParser(false).parse(GridSqlQueryParser.prepared(stmt));
if (stmt0 instanceof GridSqlCreateIndex) {
GridSqlCreateIndex cmd = (GridSqlCreateIndex) stmt0;
GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
if (tbl == null)
throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, cmd.tableName());
assert tbl.rowDescriptor() != null;
QueryIndex newIdx = new QueryIndex();
newIdx.setName(cmd.index().getName());
newIdx.setIndexType(cmd.index().getIndexType());
LinkedHashMap<String, Boolean> flds = new LinkedHashMap<>();
// Let's replace H2's table and property names by those operated by GridQueryProcessor.
GridQueryTypeDescriptor typeDesc = tbl.rowDescriptor().type();
for (Map.Entry<String, Boolean> e : cmd.index().getFields().entrySet()) {
GridQueryProperty prop = typeDesc.property(e.getKey());
if (prop == null)
throw new SchemaOperationException(SchemaOperationException.CODE_COLUMN_NOT_FOUND, e.getKey());
flds.put(prop.name(), e.getValue());
}
newIdx.setFields(flds);
fut = ctx.query().dynamicIndexCreate(tbl.cacheName(), cmd.schemaName(), typeDesc.tableName(), newIdx, cmd.ifNotExists());
} else if (stmt0 instanceof GridSqlDropIndex) {
GridSqlDropIndex cmd = (GridSqlDropIndex) stmt0;
GridH2Table tbl = idx.dataTableForIndex(cmd.schemaName(), cmd.indexName());
if (tbl != null) {
fut = ctx.query().dynamicIndexDrop(tbl.cacheName(), cmd.schemaName(), cmd.indexName(), cmd.ifExists());
} else {
if (cmd.ifExists())
fut = new GridFinishedFuture();
else
throw new SchemaOperationException(SchemaOperationException.CODE_INDEX_NOT_FOUND, cmd.indexName());
}
} else if (stmt0 instanceof GridSqlCreateTable) {
GridSqlCreateTable cmd = (GridSqlCreateTable) stmt0;
if (!F.eq(QueryUtils.DFLT_SCHEMA, cmd.schemaName()))
throw new SchemaOperationException("CREATE TABLE can only be executed on " + QueryUtils.DFLT_SCHEMA + " schema.");
GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
if (tbl != null) {
if (!cmd.ifNotExists())
throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_EXISTS, cmd.tableName());
} else {
ctx.query().dynamicTableCreate(cmd.schemaName(), toQueryEntity(cmd), cmd.templateName(), cmd.atomicityMode(), cmd.backups(), cmd.ifNotExists());
}
} else if (stmt0 instanceof GridSqlDropTable) {
GridSqlDropTable cmd = (GridSqlDropTable) stmt0;
if (!F.eq(QueryUtils.DFLT_SCHEMA, cmd.schemaName()))
throw new SchemaOperationException("DROP TABLE can only be executed on " + QueryUtils.DFLT_SCHEMA + " schema.");
GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
if (tbl == null) {
if (!cmd.ifExists())
throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, cmd.tableName());
} else
ctx.query().dynamicTableDrop(tbl.cacheName(), cmd.tableName(), cmd.ifExists());
} else
throw new IgniteSQLException("Unsupported DDL operation: " + sql, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
if (fut != null)
fut.get();
QueryCursorImpl<List<?>> resCur = (QueryCursorImpl<List<?>>) new QueryCursorImpl(Collections.singletonList(Collections.singletonList(0L)), null, false);
resCur.fieldsMeta(UPDATE_RESULT_META);
return resCur;
} catch (SchemaOperationException e) {
throw convert(e);
} catch (IgniteSQLException e) {
throw e;
} catch (Exception e) {
throw new IgniteSQLException("Unexpected DLL operation failure: " + e.getMessage(), e);
}
}
use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.
the class DynamicIndexAbstractConcurrentSelfTest method testQueryConsistencyMultithreaded.
/**
* Make sure that contended operations on the same index from different nodes do not hang when we issue both
* CREATE/DROP and SELECT statements.
*
* @throws Exception If failed.
*/
public void testQueryConsistencyMultithreaded() throws Exception {
// Start complex topology.
Ignition.start(serverConfiguration(1));
Ignition.start(serverConfiguration(2));
Ignition.start(serverConfiguration(3, true));
Ignite cli = Ignition.start(clientConfiguration(4));
createSqlCache(cli);
put(cli, 0, KEY_AFTER);
final AtomicBoolean stopped = new AtomicBoolean();
// Thread 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;
}
}, 1);
IgniteInternalFuture qryFut = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!stopped.get()) {
Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
assertSqlSimpleData(node, SQL_SIMPLE_FIELD_1, KEY_AFTER - SQL_ARG_1);
}
return null;
}
}, 8);
Thread.sleep(TEST_DUR);
stopped.set(true);
// Make sure nothing hanged.
idxFut.get();
qryFut.get();
}
use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.
the class DynamicIndexAbstractBasicSelfTest method checkCreateNotCache.
/**
* Check create when cache doesn't exist.
*
* @param mode Mode.
* @param atomicityMode Atomicity mode.
* @param near Near flag.
* @throws Exception If failed.
*/
private void checkCreateNotCache(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
initialize(mode, atomicityMode, near);
final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
try {
String cacheName = randomString();
queryProcessor(node()).dynamicIndexCreate(cacheName, cacheName, TBL_NAME, idx, false).get();
} catch (SchemaOperationException e) {
assertEquals(SchemaOperationException.CODE_CACHE_NOT_FOUND, e.code());
assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
return;
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
fail(SchemaOperationException.class.getSimpleName() + " is not thrown.");
}
use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.
the class DynamicIndexAbstractConcurrentSelfTest method testConcurrentOperationsAndNodeStartStopMultithreaded.
/**
* Test concurrent node start/stop along with index operations. Nothing should hang.
*
* @throws Exception If failed.
*/
public void testConcurrentOperationsAndNodeStartStopMultithreaded() throws Exception {
// Start several stable nodes.
Ignition.start(serverConfiguration(1));
Ignition.start(serverConfiguration(2));
Ignition.start(serverConfiguration(3, true));
final Ignite cli = Ignition.start(clientConfiguration(4));
createSqlCache(cli);
final AtomicBoolean stopped = new AtomicBoolean();
// Start node start/stop worker.
final AtomicInteger nodeIdx = new AtomicInteger(4);
IgniteInternalFuture startStopFut = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
boolean exists = false;
int lastIdx = 0;
while (!stopped.get()) {
if (exists) {
stopGrid(lastIdx);
exists = false;
} else {
lastIdx = nodeIdx.incrementAndGet();
IgniteConfiguration cfg;
switch(ThreadLocalRandom.current().nextInt(0, 3)) {
case 1:
cfg = serverConfiguration(lastIdx, false);
break;
case 2:
cfg = serverConfiguration(lastIdx, true);
break;
default:
cfg = clientConfiguration(lastIdx);
}
Ignition.start(cfg);
exists = true;
}
Thread.sleep(ThreadLocalRandom.current().nextLong(500L, 1500L));
}
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;
}
}, 1);
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);
}
Aggregations