Search in sources :

Example 11 with QueryField

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()));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryField(org.apache.ignite.internal.processors.query.QueryField) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with QueryField

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.
    }
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) QueryField(org.apache.ignite.internal.processors.query.QueryField) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 13 with QueryField

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;
}
Also used : QueryField(org.apache.ignite.internal.processors.query.QueryField) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 14 with QueryField

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);
}
Also used : QueryField(org.apache.ignite.internal.processors.query.QueryField)

Example 15 with QueryField

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);
}
Also used : QueryField(org.apache.ignite.internal.processors.query.QueryField)

Aggregations

QueryField (org.apache.ignite.internal.processors.query.QueryField)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 Ignite (org.apache.ignite.Ignite)4 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)4 List (java.util.List)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 BinaryObject (org.apache.ignite.binary.BinaryObject)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 IgniteException (org.apache.ignite.IgniteException)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1