Search in sources :

Example 1 with InlineIndexImpl

use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl in project ignite by apache.

the class IndexingDefragmentation method defragmentTable.

/**
 * Defragment one given table.
 */
private boolean defragmentTable(CacheGroupContext newCtx, IntMap<LinkMap> mappingByPartition, CheckpointTimeoutLock cpLock, Runnable cancellationChecker, int pageSize, PageMemoryEx oldCachePageMem, PageMemory newCachePageMemory, long cpLockThreshold, AtomicLong lastCpLockTs, TableIndexes indexes) throws IgniteCheckedException {
    cpLock.checkpointReadLock();
    try {
        TreeIterator treeIterator = new TreeIterator(pageSize);
        GridCacheContext<?, ?> cctx = indexes.cctx;
        cancellationChecker.run();
        for (InlineIndex oldIdx : indexes.idxs) {
            InlineIndexRowHandler oldRowHnd = oldIdx.segment(0).rowHandler();
            SortedIndexDefinition idxDef = (SortedIndexDefinition) indexing.indexDefinition(oldIdx.id());
            InlineIndexImpl newIdx = new DefragIndexFactory(newCtx.offheap(), newCachePageMemory, oldIdx).createIndex(cctx, idxDef).unwrap(InlineIndexImpl.class);
            int segments = oldIdx.segmentsCount();
            for (int i = 0; i < segments; ++i) {
                treeIterator.iterate(oldIdx.segment(i), oldCachePageMem, (theTree, io, pageAddr, idx) -> {
                    cancellationChecker.run();
                    if (System.currentTimeMillis() - lastCpLockTs.get() >= cpLockThreshold) {
                        cpLock.checkpointReadUnlock();
                        cpLock.checkpointReadLock();
                        lastCpLockTs.set(System.currentTimeMillis());
                    }
                    assert 1 == io.getVersion() : "IO version " + io.getVersion() + " is not supported by current defragmentation algorithm." + " Please implement copying of tree in a new format.";
                    BPlusIO<IndexRow> h2IO = DefragIndexFactory.wrap(io, oldRowHnd);
                    IndexRow row = theTree.getRow(h2IO, pageAddr, idx);
                    if (row instanceof DefragIndexRowImpl) {
                        DefragIndexRowImpl r = (DefragIndexRowImpl) row;
                        CacheDataRow cacheDataRow = r.cacheDataRow();
                        int partition = cacheDataRow.partition();
                        long link = r.link();
                        LinkMap map = mappingByPartition.get(partition);
                        long newLink = map.get(link);
                        // Use old row handler, as MetaInfo is copied from old tree.
                        DefragIndexRowImpl newRow = DefragIndexRowImpl.create(oldRowHnd, newLink, r, ((MvccIO) io).storeMvccInfo());
                        newIdx.putIndexRow(newRow);
                    }
                    return true;
                });
            }
        }
        return true;
    } catch (Throwable t) {
        newCtx.cacheObjectContext().kernalContext().failure().process(new FailureContext(CRITICAL_ERROR, t));
        throw t;
    } finally {
        cpLock.checkpointReadUnlock();
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) LinkMap(org.apache.ignite.internal.processors.cache.persistence.defragmentation.LinkMap) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) InlineIndex(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndex) DefragIndexRowImpl(org.apache.ignite.internal.cache.query.index.sorted.defragmentation.DefragIndexFactory.DefragIndexRowImpl) InlineIndexRowHandler(org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler) InlineIndexImpl(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl) FailureContext(org.apache.ignite.failure.FailureContext) TreeIterator(org.apache.ignite.internal.processors.cache.persistence.defragmentation.TreeIterator)

Example 2 with InlineIndexImpl

use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl in project ignite by apache.

the class IgniteH2Indexing method createSortedIndex.

/**
 * Create sorted index.
 *
 * @param name Index name,
 * @param tbl Table.
 * @param pk Primary key flag.
 * @param affinityKey Affinity key flag.
 * @param unwrappedCols Unwrapped index columns for complex types.
 * @param wrappedCols Index columns as is complex types.
 * @param inlineSize Index inline size.
 * @param cacheVisitor whether index created with new cache or on existing one.
 * @return Index.
 */
@SuppressWarnings("ConstantConditions")
GridH2IndexBase createSortedIndex(String name, GridH2Table tbl, boolean pk, boolean affinityKey, List<IndexColumn> unwrappedCols, List<IndexColumn> wrappedCols, int inlineSize, @Nullable SchemaIndexCacheVisitor cacheVisitor) {
    GridCacheContextInfo cacheInfo = tbl.cacheInfo();
    if (log.isDebugEnabled())
        log.debug("Creating cache index [cacheId=" + cacheInfo.cacheId() + ", idxName=" + name + ']');
    if (cacheInfo.affinityNode()) {
        QueryIndexDefinition idxDef = new QueryIndexDefinition(tbl, name, ctx.indexProcessor().rowCacheCleaner(cacheInfo.groupId()), pk, affinityKey, unwrappedCols, wrappedCols, inlineSize);
        org.apache.ignite.internal.cache.query.index.Index index;
        if (cacheVisitor != null)
            index = ctx.indexProcessor().createIndexDynamically(tbl.cacheContext(), idxFactory, idxDef, cacheVisitor);
        else
            index = ctx.indexProcessor().createIndex(tbl.cacheContext(), idxFactory, idxDef);
        InlineIndexImpl queryIndex = index.unwrap(InlineIndexImpl.class);
        return new H2TreeIndex(queryIndex, tbl, unwrappedCols.toArray(new IndexColumn[0]), pk, log);
    } else {
        ClientIndexDefinition d = new ClientIndexDefinition(tbl, new IndexName(tbl.cacheName(), tbl.getSchema().getName(), tbl.getName(), name), unwrappedCols, inlineSize, tbl.cacheInfo().config().getSqlIndexMaxInlineSize());
        org.apache.ignite.internal.cache.query.index.Index index = ctx.indexProcessor().createIndex(tbl.cacheContext(), ClientIndexFactory.INSTANCE, d);
        InlineIndex idx = index.unwrap(InlineIndex.class);
        IndexType idxType = pk ? IndexType.createPrimaryKey(false, false) : IndexType.createNonUnique(false, false, false);
        return new H2TreeClientIndex(idx, tbl, name, unwrappedCols.toArray(new IndexColumn[0]), idxType);
    }
}
Also used : H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) InlineIndex(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndex) IndexColumn(org.h2.table.IndexColumn) IndexName(org.apache.ignite.internal.cache.query.index.IndexName) InlineIndexImpl(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl) QueryIndexDefinition(org.apache.ignite.internal.processors.query.h2.index.QueryIndexDefinition) GridCacheContextInfo(org.apache.ignite.internal.processors.cache.GridCacheContextInfo) H2TreeClientIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeClientIndex) ClientIndexDefinition(org.apache.ignite.internal.processors.query.h2.index.client.ClientIndexDefinition) IndexType(org.h2.index.IndexType)

Example 3 with InlineIndexImpl

use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl in project ignite by apache.

the class IndexQueryProcessor method prepareQuery.

/**
 * Prepare index query.
 *
 * @return Prepared query for index range.
 */
private IndexRangeQuery prepareQuery(SortedSegmentedIndex idx, IndexQueryDesc idxQryDesc) throws IgniteCheckedException {
    SortedIndexDefinition idxDef = (SortedIndexDefinition) idxProc.indexDefinition(idx.id());
    // For PK indexes will serialize _KEY column.
    if (F.isEmpty(idxQryDesc.criteria()))
        return new IndexRangeQuery(1);
    InlineIndexImpl sortedIdx = (InlineIndexImpl) idx;
    Map<String, RangeIndexQueryCriterion> merged = mergeIndexQueryCriteria(sortedIdx, idxDef, idxQryDesc);
    return alignCriteriaWithIndex(sortedIdx, merged, idxDef);
}
Also used : InlineIndexImpl(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)

Example 4 with InlineIndexImpl

use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl in project ignite by apache.

the class ComputeInlineSizeTest method checkIdxsInlineSizes.

/**
 */
private void checkIdxsInlineSizes() {
    Collection<Index> idx = ignite.context().indexProcessor().indexes(context());
    Map<String, Integer> expInlineSize = new HashMap<String, Integer>() {

        {
            // 9 is inline for _KEY (LongIndexKeyType).
            put("PERSON_STR_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE);
            put("PERSON_STRPRECBIG_IDX", InlineIndexTree.IGNITE_MAX_INDEX_PAYLOAD_SIZE_DEFAULT);
            // 3 is for storing info (type, length) of inlined key.
            put("PERSON_STRPREC_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE + 10 + 3);
            put("PERSON_BYTES_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE);
            put("PERSON_BYTESPREC_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE + 20 + 3);
        }
    };
    for (Index i : idx) {
        InlineIndexImpl impl = (InlineIndexImpl) i;
        if (expInlineSize.containsKey(impl.name())) {
            int inlineSize = expInlineSize.remove(impl.name());
            assertEquals(inlineSize, impl.inlineSize());
        }
    }
    assertTrue(expInlineSize.isEmpty());
}
Also used : InlineIndexImpl(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl) HashMap(java.util.HashMap) Index(org.apache.ignite.internal.cache.query.index.Index)

Aggregations

InlineIndexImpl (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl)4 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)2 InlineIndex (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndex)2 HashMap (java.util.HashMap)1 FailureContext (org.apache.ignite.failure.FailureContext)1 RangeIndexQueryCriterion (org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)1 Index (org.apache.ignite.internal.cache.query.index.Index)1 IndexName (org.apache.ignite.internal.cache.query.index.IndexName)1 IndexRow (org.apache.ignite.internal.cache.query.index.sorted.IndexRow)1 InlineIndexRowHandler (org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler)1 DefragIndexRowImpl (org.apache.ignite.internal.cache.query.index.sorted.defragmentation.DefragIndexFactory.DefragIndexRowImpl)1 GridCacheContextInfo (org.apache.ignite.internal.processors.cache.GridCacheContextInfo)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)1 LinkMap (org.apache.ignite.internal.processors.cache.persistence.defragmentation.LinkMap)1 TreeIterator (org.apache.ignite.internal.processors.cache.persistence.defragmentation.TreeIterator)1 H2TreeClientIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeClientIndex)1 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)1 QueryIndexDefinition (org.apache.ignite.internal.processors.query.h2.index.QueryIndexDefinition)1 ClientIndexDefinition (org.apache.ignite.internal.processors.query.h2.index.client.ClientIndexDefinition)1 IndexType (org.h2.index.IndexType)1