Search in sources :

Example 6 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 cacheName Cache name.
 * @param tblName Table name.
 * @param idxName Index name.
 * @param inlineSize Inline size.
 * @param fields Fields.
 */
static void assertIndex(Ignite node, String cacheName, String tblName, String idxName, int inlineSize, IgniteBiTuple<String, Boolean>... fields) {
    awaitCompletion();
    node.cache(cacheName);
    IgniteEx node0 = (IgniteEx) node;
    ArrayList<IgniteBiTuple<String, Boolean>> res = new ArrayList<>();
    try {
        try (Connection c = connect(node0)) {
            try (ResultSet rs = c.getMetaData().getIndexInfo(null, cacheName, tblName, false, false)) {
                while (rs.next()) {
                    if (F.eq(idxName, rs.getString("INDEX_NAME")))
                        res.add(new T2<>(rs.getString("COLUMN_NAME"), F.eq("A", rs.getString("ASC_OR_DESC"))));
                }
            }
        }
        assertTrue("Index not found: " + idxName, res.size() > 0);
        assertEquals(Arrays.asList(fields), res);
    } catch (SQLException e) {
        throw new AssertionError(e);
    }
    // Also, let's check internal stuff not visible via JDBC - like inline size.
    QueryTypeDescriptorImpl typeDesc = typeExisting(node0, cacheName, tblName);
    assertInternalIndexParams(typeDesc, idxName, inlineSize);
}
Also used : QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteEx(org.apache.ignite.internal.IgniteEx) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) T2(org.apache.ignite.internal.util.typedef.T2)

Example 7 with QueryTypeDescriptorImpl

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

the class AbstractSchemaSelfTest method types.

/**
 * Get available types on the given node for the given cache.
 *
 * @param node Node.
 * @param cacheName Cache name.
 * @return Map from table name to type.
 */
protected static Map<String, QueryTypeDescriptorImpl> types(IgniteEx node, String cacheName) {
    Map<String, QueryTypeDescriptorImpl> res = new HashMap<>();
    Collection<GridQueryTypeDescriptor> descs = node.context().query().types(cacheName);
    for (GridQueryTypeDescriptor desc : descs) {
        QueryTypeDescriptorImpl desc0 = (QueryTypeDescriptorImpl) desc;
        res.put(desc0.tableName(), desc0);
    }
    return res;
}
Also used : QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)

Example 8 with QueryTypeDescriptorImpl

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

the class H2DynamicTableSelfTest method doTestCreateTable.

/**
     * Test that {@code CREATE TABLE} with given template cache name actually creates new cache,
     * H2 table and type descriptor on all nodes, optionally with cache type check.
     * @param tplCacheName Template cache name.
     * @param mode Expected cache mode, or {@code null} if no check is needed.
     */
private void doTestCreateTable(String tplCacheName, CacheMode mode) {
    executeDdl("CREATE TABLE \"Person\" (\"id\" int, \"city\" varchar," + " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH " + (F.isEmpty(tplCacheName) ? "" : "\"template=" + tplCacheName + "\",") + "\"backups=10,atomicity=atomic\"");
    for (int i = 0; i < 4; i++) {
        IgniteEx node = grid(i);
        assertNotNull(node.cache("Person"));
        DynamicCacheDescriptor cacheDesc = node.context().cache().cacheDescriptor("Person");
        assertNotNull(cacheDesc);
        if (mode == CacheMode.REPLICATED)
            assertEquals(Integer.MAX_VALUE, cacheDesc.cacheConfiguration().getBackups());
        else
            assertEquals(10, cacheDesc.cacheConfiguration().getBackups());
        assertEquals(CacheAtomicityMode.ATOMIC, cacheDesc.cacheConfiguration().getAtomicityMode());
        assertTrue(cacheDesc.sql());
        if (mode != null)
            assertEquals(mode, cacheDesc.cacheConfiguration().getCacheMode());
        QueryTypeDescriptorImpl desc = typeExisting(node, "Person", "Person");
        assertEquals(Object.class, desc.keyClass());
        assertEquals("PersonKey", desc.keyTypeName());
        assertEquals(Object.class, desc.valueClass());
        assertEquals("Person", desc.valueTypeName());
        assertEquals(F.asList("id", "city", "name", "surname", "age"), new ArrayList<>(desc.fields().keySet()));
        assertProperty(desc, "id", Integer.class, true);
        assertProperty(desc, "city", String.class, true);
        assertProperty(desc, "name", String.class, false);
        assertProperty(desc, "surname", String.class, false);
        assertProperty(desc, "age", Integer.class, false);
        GridH2Table tbl = ((IgniteH2Indexing) node.context().query().getIndexing()).dataTable("PUBLIC", "Person");
        assertNotNull(tbl);
    }
}
Also used : QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) IgniteEx(org.apache.ignite.internal.IgniteEx) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing)

Example 9 with QueryTypeDescriptorImpl

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

the class SchemaIndexCacheVisitorImpl method indexStatStr.

/**
 * Prints index cache stats to log.
 *
 * @param stat Index cache stats.
 * @throws IgniteCheckedException if failed to get index size.
 */
private String indexStatStr(SchemaIndexCacheStat stat) throws IgniteCheckedException {
    SB res = new SB();
    res.a("Details for cache rebuilding [name=" + cctx.cache().name() + ", grpName=" + cctx.group().name() + ']');
    res.a(U.nl());
    res.a("   Scanned rows " + stat.scannedKeys() + ", visited types " + stat.typeNames());
    res.a(U.nl());
    final GridQueryIndexing idx = cctx.kernalContext().query().getIndexing();
    for (QueryTypeDescriptorImpl type : stat.types()) {
        res.a("        Type name=" + type.name());
        res.a(U.nl());
        String pk = QueryUtils.PRIMARY_KEY_INDEX;
        String tblName = type.tableName();
        res.a("            Index: name=" + pk + ", size=" + idx.indexSize(type.schemaName(), tblName, pk));
        res.a(U.nl());
        for (GridQueryIndexDescriptor descriptor : type.indexes().values()) {
            long size = idx.indexSize(type.schemaName(), tblName, descriptor.name());
            res.a("            Index: name=" + descriptor.name() + ", size=" + size);
            res.a(U.nl());
        }
    }
    return res.toString();
}
Also used : QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) GridQueryIndexDescriptor(org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor) GridQueryIndexing(org.apache.ignite.internal.processors.query.GridQueryIndexing) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 10 with QueryTypeDescriptorImpl

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

the class ValidateIndexesClosure method calcCacheSize.

/**
 * Calculation of caches size with divided by tables.
 *
 * @param grpCtx Cache group context.
 * @param locPart Local partition.
 * @return Cache size representation object.
 */
private CacheSize calcCacheSize(CacheGroupContext grpCtx, GridDhtLocalPartition locPart) {
    try {
        if (validateCtx.isCancelled())
            return new CacheSize(null, emptyMap());
        @Nullable PartitionUpdateCounter updCntr = locPart.dataStore().partUpdateCounter();
        PartitionUpdateCounter updateCntrBefore = updCntr == null ? updCntr : updCntr.copy();
        int grpId = grpCtx.groupId();
        if (failCalcCacheSizeGrpIds.contains(grpId))
            return new CacheSize(null, null);
        boolean reserve = false;
        int partId = locPart.id();
        try {
            if (!(reserve = locPart.reserve()))
                throw new IgniteException("Can't reserve partition");
            if (locPart.state() != OWNING)
                throw new IgniteException("Partition not in state " + OWNING);
            Map<Integer, Map<String, AtomicLong>> cacheSizeByTbl = new HashMap<>();
            GridIterator<CacheDataRow> partIter = grpCtx.offheap().partitionIterator(partId);
            GridQueryProcessor qryProcessor = ignite.context().query();
            IgniteH2Indexing h2Indexing = (IgniteH2Indexing) qryProcessor.getIndexing();
            while (partIter.hasNextX() && !failCalcCacheSizeGrpIds.contains(grpId)) {
                CacheDataRow cacheDataRow = partIter.nextX();
                int cacheId = cacheDataRow.cacheId();
                GridCacheContext cacheCtx = cacheId == 0 ? grpCtx.singleCacheContext() : grpCtx.shared().cacheContext(cacheId);
                if (cacheCtx == null)
                    throw new IgniteException("Unknown cacheId of CacheDataRow: " + cacheId);
                if (cacheDataRow.link() == 0L)
                    throw new IgniteException("Contains invalid partition row, possibly deleted");
                String cacheName = cacheCtx.name();
                QueryTypeDescriptorImpl qryTypeDesc = qryProcessor.typeByValue(cacheName, cacheCtx.cacheObjectContext(), cacheDataRow.key(), cacheDataRow.value(), true);
                if (isNull(qryTypeDesc))
                    // Tolerate - (k, v) is just not indexed.
                    continue;
                String tableName = qryTypeDesc.tableName();
                GridH2Table gridH2Tbl = h2Indexing.schemaManager().dataTable(cacheName, tableName);
                if (isNull(gridH2Tbl))
                    // Tolerate - (k, v) is just not indexed.
                    continue;
                cacheSizeByTbl.computeIfAbsent(cacheCtx.cacheId(), i -> new HashMap<>()).computeIfAbsent(tableName, s -> new AtomicLong()).incrementAndGet();
            }
            PartitionUpdateCounter updateCntrAfter = locPart.dataStore().partUpdateCounter();
            if (updateCntrAfter != null && !updateCntrAfter.equals(updateCntrBefore)) {
                throw new GridNotIdleException(GRID_NOT_IDLE_MSG + "[grpName=" + grpCtx.cacheOrGroupName() + ", grpId=" + grpCtx.groupId() + ", partId=" + locPart.id() + "] changed during size " + "calculation [updCntrBefore=" + updateCntrBefore + ", updCntrAfter=" + updateCntrAfter + "]");
            }
            return new CacheSize(null, cacheSizeByTbl);
        } catch (Throwable t) {
            IgniteException cacheSizeErr = new IgniteException("Cache size calculation error [" + cacheGrpInfo(grpCtx) + ", locParId=" + partId + ", err=" + t.getMessage() + "]", t);
            error(log, cacheSizeErr);
            failCalcCacheSizeGrpIds.add(grpId);
            return new CacheSize(cacheSizeErr, null);
        } finally {
            if (reserve)
                locPart.release();
        }
    } finally {
        processedCacheSizePartitions.incrementAndGet();
        printProgressOfIndexValidationIfNeeded();
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Collections.shuffle(java.util.Collections.shuffle) IgniteEx(org.apache.ignite.internal.IgniteEx) DbException(org.h2.message.DbException) H2Utils(org.apache.ignite.internal.processors.query.h2.H2Utils) Index(org.h2.index.Index) IdleVerifyUtility.checkPartitionsPageCrcSum(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.checkPartitionsPageCrcSum) ConnectionManager(org.apache.ignite.internal.processors.query.h2.ConnectionManager) Future(java.util.concurrent.Future) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) BPlusTree(org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree) JdbcConnection(org.h2.jdbc.JdbcConnection) Objects.isNull(java.util.Objects.isNull) LoggerResource(org.apache.ignite.resources.LoggerResource) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridNotIdleException(org.apache.ignite.internal.processors.cache.verify.GridNotIdleException) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Executors(java.util.concurrent.Executors) GRID_NOT_IDLE_MSG(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.GRID_NOT_IDLE_MSG) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) Cursor(org.h2.index.Cursor) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Entry(java.util.Map.Entry) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Objects.nonNull(java.util.Objects.nonNull) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) CacheObjectUtils(org.apache.ignite.internal.processors.cache.CacheObjectUtils) PartitionKey(org.apache.ignite.internal.processors.cache.verify.PartitionKey) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) IgniteLogger(org.apache.ignite.IgniteLogger) CorruptedTreeException(org.apache.ignite.internal.processors.cache.persistence.tree.CorruptedTreeException) Supplier(java.util.function.Supplier) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteCallable(org.apache.ignite.lang.IgniteCallable) HashSet(java.util.HashSet) IdleVerifyUtility.formatUpdateCountersDiff(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.formatUpdateCountersDiff) Session(org.h2.engine.Session) Collections.newSetFromMap(java.util.Collections.newSetFromMap) IdleVerifyUtility.compareUpdateCounters(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.compareUpdateCounters) MvccUtils(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IdleVerifyUtility.getUpdateCountersSnapshot(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.getUpdateCountersSnapshot) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) IdleVerifyUtility(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility) ExecutorService(java.util.concurrent.ExecutorService) F(org.apache.ignite.internal.util.typedef.F) Collections.emptyMap(java.util.Collections.emptyMap) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) H2TreeIndexBase(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) T3(org.apache.ignite.internal.util.typedef.T3) GridIterator(org.apache.ignite.internal.util.lang.GridIterator) T2(org.apache.ignite.internal.util.typedef.T2) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) MvccSnapshot(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot) H2CacheRow(org.apache.ignite.internal.processors.query.h2.opt.H2CacheRow) Collections(java.util.Collections) MvccQueryTracker(org.apache.ignite.internal.processors.cache.mvcc.MvccQueryTracker) QueryContext(org.apache.ignite.internal.processors.query.h2.opt.QueryContext) IgniteUtils.error(org.apache.ignite.internal.util.IgniteUtils.error) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridNotIdleException(org.apache.ignite.internal.processors.cache.verify.GridNotIdleException) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteException(org.apache.ignite.IgniteException) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Collections.newSetFromMap(java.util.Collections.newSetFromMap) Collections.emptyMap(java.util.Collections.emptyMap) Nullable(org.jetbrains.annotations.Nullable)

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