Search in sources :

Example 1 with QueryTypeDescriptorImpl

use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.

the class AbstractSchemaSelfTest method assertIndex.

/**
     * Assert index state on particular node.
     *
     * @param node Node.
     * @param checkNonAffinityNode Whether existence of {@link GridQueryIndexDescriptor} must be checked regardless of
     * whether this node is affinity node or not.
     * @param cacheName Cache name.
     * @param tblName Table name.
     * @param idxName Index name.
     * @param fields Fields.
     */
protected static void assertIndex(Ignite node, boolean checkNonAffinityNode, String cacheName, String tblName, String idxName, IgniteBiTuple<String, Boolean>... fields) {
    IgniteEx node0 = (IgniteEx) node;
    assertIndexDescriptor(node0, cacheName, tblName, idxName, fields);
    if (checkNonAffinityNode || affinityNode(node0, cacheName)) {
        QueryTypeDescriptorImpl typeDesc = typeExisting(node0, cacheName, tblName);
        assertIndex(typeDesc, idxName, fields);
    }
}
Also used : QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 2 with QueryTypeDescriptorImpl

use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.

the class ValidateIndexesClosure method processPartIterator.

/**
 * Process partition iterator.
 *
 * @param grpCtx Cache group context.
 * @param partRes Result object.
 * @param session H2 session.
 * @param it Partition iterator.
 * @throws IgniteCheckedException
 */
private void processPartIterator(CacheGroupContext grpCtx, ValidateIndexesPartitionResult partRes, Session session, GridIterator<CacheDataRow> it) throws IgniteCheckedException {
    boolean enoughIssues = false;
    GridQueryProcessor qryProcessor = ignite.context().query();
    final boolean skipConditions = checkFirst > 0 || checkThrough > 0;
    final boolean bothSkipConditions = checkFirst > 0 && checkThrough > 0;
    long current = 0;
    long processedNumber = 0;
    while (it.hasNextX() && !validateCtx.isCancelled()) {
        if (enoughIssues)
            break;
        CacheDataRow row = it.nextX();
        if (skipConditions) {
            if (bothSkipConditions) {
                if (processedNumber > checkFirst)
                    break;
                else if (current++ % checkThrough > 0)
                    continue;
                else
                    processedNumber++;
            } else {
                if (checkFirst > 0) {
                    if (current++ > checkFirst)
                        break;
                } else {
                    if (current++ % checkThrough > 0)
                        continue;
                }
            }
        }
        int cacheId = row.cacheId() == 0 ? grpCtx.groupId() : row.cacheId();
        GridCacheContext<?, ?> cacheCtx = row.cacheId() == 0 ? grpCtx.singleCacheContext() : grpCtx.shared().cacheContext(row.cacheId());
        if (cacheCtx == null)
            throw new IgniteException("Unknown cacheId of CacheDataRow: " + cacheId);
        if (row.link() == 0L) {
            String errMsg = "Invalid partition row, possibly deleted";
            log.error(errMsg);
            IndexValidationIssue is = new IndexValidationIssue(null, cacheCtx.name(), null, new IgniteCheckedException(errMsg));
            enoughIssues |= partRes.reportIssue(is);
            continue;
        }
        QueryTypeDescriptorImpl res = qryProcessor.typeByValue(cacheCtx.name(), cacheCtx.cacheObjectContext(), row.key(), row.value(), true);
        if (res == null)
            // Tolerate - (k, v) is just not indexed.
            continue;
        IgniteH2Indexing indexing = (IgniteH2Indexing) qryProcessor.getIndexing();
        GridH2Table gridH2Tbl = indexing.schemaManager().dataTable(cacheCtx.name(), res.tableName());
        if (gridH2Tbl == null)
            // Tolerate - (k, v) is just not indexed.
            continue;
        GridH2RowDescriptor gridH2RowDesc = gridH2Tbl.rowDescriptor();
        H2CacheRow h2Row = gridH2RowDesc.createRow(row);
        ArrayList<Index> indexes = gridH2Tbl.getIndexes();
        for (Index idx : indexes) {
            if (validateCtx.isCancelled())
                break;
            if (!(idx instanceof H2TreeIndexBase))
                continue;
            try {
                Cursor cursor = idx.find(session, h2Row, h2Row);
                if (cursor == null || !cursor.next())
                    throw new IgniteCheckedException("Key is present in CacheDataTree, but can't be found in SQL index.");
            } catch (Throwable t) {
                Object o = CacheObjectUtils.unwrapBinaryIfNeeded(grpCtx.cacheObjectContext(), row.key(), true, true);
                IndexValidationIssue is = new IndexValidationIssue(o.toString(), cacheCtx.name(), idx.getName(), t);
                log.error("Failed to lookup key: " + is.toString(), t);
                enoughIssues |= partRes.reportIssue(is);
            }
        }
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) H2TreeIndexBase(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase) Index(org.h2.index.Index) H2CacheRow(org.apache.ignite.internal.processors.query.h2.opt.H2CacheRow) Cursor(org.h2.index.Cursor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) IgniteException(org.apache.ignite.IgniteException) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing)

Example 3 with QueryTypeDescriptorImpl

use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.

the class H2DynamicTableSelfTest method testDropTableFromClient.

/**
 * Test that {@code DROP TABLE} executed at client node actually removes specified cache and type descriptor on all nodes.
 * @throws Exception if failed.
 */
@Test
public void testDropTableFromClient() throws Exception {
    execute(grid(0), "CREATE TABLE IF NOT EXISTS \"Person\" (\"id\" int, \"city\" varchar," + " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH " + "\"template=cache\"");
    execute(client(), "DROP TABLE \"Person\"");
    for (int i = 0; i < 4; i++) {
        IgniteEx node = grid(i);
        assertNull(node.cache("Person"));
        QueryTypeDescriptorImpl desc = type(node, "Person", "Person");
        assertNull(desc);
    }
}
Also used : QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test)

Example 4 with QueryTypeDescriptorImpl

use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.

the class H2DynamicTableSelfTest method testDropTable.

/**
 * Test that {@code DROP TABLE} actually removes specified cache and type descriptor on all nodes.
 * @throws Exception if failed.
 */
@Test
public void testDropTable() throws Exception {
    execute("CREATE TABLE IF NOT EXISTS \"Person\" (\"id\" int, \"city\" varchar," + " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH " + "\"template=cache\"");
    execute("DROP TABLE \"Person\"");
    for (int i = 0; i < 4; i++) {
        IgniteEx node = grid(i);
        assertNull(node.cache("Person"));
        QueryTypeDescriptorImpl desc = type(node, "Person", "Person");
        assertNull(desc);
    }
}
Also used : QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test)

Example 5 with QueryTypeDescriptorImpl

use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.

the class H2DynamicTableSelfTest method testTableEnabledDynamicallyNotExistsIfCacheDestroyed.

/**
 * Tests that after destroying cache with table enabled dynamically that table also is removed.
 *
 * @throws Exception If failed.
 */
@Test
public void testTableEnabledDynamicallyNotExistsIfCacheDestroyed() throws Exception {
    String cacheName = "new";
    String tableName = "NewTable";
    String createSql = "CREATE TABLE \"" + tableName + "\" (id int primary key, x varchar) WITH " + "\"wrap_key,wrap_value,cache_name=" + cacheName + "\"";
    client().getOrCreateCache(cacheName);
    execute(client(), createSql);
    client().destroyCache(cacheName);
    for (Ignite g : G.allGrids()) {
        IgniteEx node = (IgniteEx) g;
        QueryTypeDescriptorImpl desc = type(node, cacheName, tableName);
        assertNull(desc);
        assertTrue(execute(g, "SELECT * FROM SYS.TABLES WHERE table_name = '" + tableName + "'").isEmpty());
    }
}
Also used : QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Aggregations

QueryTypeDescriptorImpl (org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl)11 IgniteEx (org.apache.ignite.internal.IgniteEx)7 IgniteH2Indexing (org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing)3 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.newSetFromMap (java.util.Collections.newSetFromMap)1 Collections.shuffle (java.util.Collections.shuffle)1 HashSet (java.util.HashSet)1