use of org.apache.ignite.internal.processors.query.QueryField in project ignite by apache.
the class DynamicColumnsAbstractConcurrentSelfTest method checkConcurrentRebalance.
/**
* Check index consistency on re-balance.
*
* @param addOrRemove Pass {@code true} to check add column. Otherwise, drop column is checked.
* @throws Exception If failed.
*/
public void checkConcurrentRebalance(boolean addOrRemove) throws Exception {
// Start cache and populate it with data.
IgniteEx srv1 = ignitionStart(serverConfiguration(1));
Ignite srv2 = ignitionStart(serverConfiguration(2));
createSqlCache(srv1);
run(srv1, createSql);
awaitPartitionMapExchange();
put(srv1, 0, LARGE_CACHE_SIZE);
// Start index operation in blocked state.
CountDownLatch idxLatch1 = blockIndexing(srv1);
CountDownLatch idxLatch2 = blockIndexing(srv2);
QueryField c = c("salary", Double.class.getName());
final IgniteInternalFuture<?> idxFut = addOrRemove ? addCols(srv1, QueryUtils.DFLT_SCHEMA, c) : dropCols(srv1, QueryUtils.DFLT_SCHEMA, "NAME");
U.await(idxLatch1);
U.await(idxLatch2);
// 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();
checkTableState(srv1, QueryUtils.DFLT_SCHEMA, TBL_NAME, addOrRemove ? c : c("ID", Integer.class.getName()));
}
use of org.apache.ignite.internal.processors.query.QueryField in project ignite by apache.
the class DynamicColumnsAbstractConcurrentSelfTest method checkConcurrentCacheDestroy.
/**
* Check what happens in case cache is destroyed before operation is started.
*
* @param addOrRemove Pass {@code true} to check add column. Otherwise, drop column is checked.
* @throws Exception If failed.
*/
private void checkConcurrentCacheDestroy(boolean addOrRemove) throws Exception {
// Start complex topology.
Ignite srv1 = ignitionStart(serverConfiguration(1));
ignitionStart(serverConfiguration(2));
ignitionStart(serverConfiguration(3, true));
Ignite cli = ignitionStart(clientConfiguration(4));
waitForDiscovery(srv1, grid(2), grid(3), cli);
// Start cache and populate it with data.
createSqlCache(cli);
run(cli, createSql);
put(cli, 0, LARGE_CACHE_SIZE);
// Start index operation and block it on coordinator.
CountDownLatch idxLatch = blockIndexing(srv1);
QueryField c = c("city", String.class.getName());
final IgniteInternalFuture<?> idxFut = addOrRemove ? addCols(srv1, QueryUtils.DFLT_SCHEMA, c) : dropCols(srv1, QueryUtils.DFLT_SCHEMA, "NAME");
idxLatch.await();
// Destroy cache (drop table).
run(cli, DROP_SQL);
// 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.internal.processors.query.QueryField in project ignite by apache.
the class DynamicColumnsAbstractTest method checkTableState.
/**
* Check that given columns are seen by client.
* @param node Node to check.
* @param schemaName Schema name to look for the table in.
* @param tblName Table name to check.
* @param cols Columns whose presence must be checked.
* @return Number of other columns.
*/
static int checkTableState(IgniteEx node, String schemaName, String tblName, QueryField... cols) throws SQLException {
List<QueryField> flds = new ArrayList<>();
try (Connection c = connect(node)) {
try (ResultSet rs = c.getMetaData().getColumns(null, schemaName, tblName, "%")) {
while (rs.next()) {
String name = rs.getString("COLUMN_NAME");
short type = rs.getShort("DATA_TYPE");
String typeClsName = DataType.getTypeClassName(DataType.convertSQLTypeToValueType(type));
short nullable = rs.getShort("NULLABLE");
flds.add(new QueryField(name, typeClsName, nullable == 1));
}
}
}
Iterator<QueryField> it = flds.iterator();
for (int i = flds.size() - cols.length; i > 0 && it.hasNext(); i--) it.next();
for (QueryField exp : cols) {
assertTrue("New column not found in metadata: " + exp.name(), it.hasNext());
QueryField act = it.next();
assertEquals(exp.name(), act.name());
assertEquals(exp.typeName(), act.typeName());
assertEquals(exp.isNullable(), act.isNullable());
}
return flds.size() - cols.length;
}
use of org.apache.ignite.internal.processors.query.QueryField in project ignite by apache.
the class H2DynamicColumnsAbstractBasicSelfTest method testAddNotNullColumn.
/**
* Test addition of column with not null constraint.
*/
public void testAddNotNullColumn() throws SQLException {
run("ALTER TABLE Person ADD COLUMN age int NOT NULL");
doSleep(500);
QueryField c = new QueryField("AGE", Integer.class.getName(), false);
checkTableState(QueryUtils.DFLT_SCHEMA, "PERSON", c);
}
use of org.apache.ignite.internal.processors.query.QueryField in project ignite by apache.
the class H2DynamicColumnsAbstractBasicSelfTest method testAddColumnSimple.
/**
* Test column addition to the end of the columns list.
*/
public void testAddColumnSimple() throws SQLException {
run("ALTER TABLE Person ADD COLUMN age int");
doSleep(500);
QueryField c = c("AGE", Integer.class.getName());
checkTableState(QueryUtils.DFLT_SCHEMA, "PERSON", c);
}
Aggregations