Search in sources :

Example 1 with InlineIndexRowHandler

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

the class AbstractInlineLeafIO method storeByOffset.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("ForLoopReplaceableByForEach")
@Override
public final void storeByOffset(long pageAddr, int off, IndexRow row) {
    assert row.link() != 0 : row;
    assertPageType(pageAddr);
    int fieldOff = 0;
    InlineIndexRowHandler rowHnd = ThreadLocalRowHandlerHolder.rowHandler();
    for (int i = 0; i < rowHnd.inlineIndexKeyTypes().size(); i++) {
        try {
            InlineIndexKeyType keyType = rowHnd.inlineIndexKeyTypes().get(i);
            int size = keyType.put(pageAddr, off + fieldOff, row.key(i), inlineSize - fieldOff);
            // Inline size has exceeded.
            if (size == 0)
                break;
            fieldOff += size;
        } catch (Exception e) {
            throw new IgniteException("Failed to store new index row.", e);
        }
    }
    IORowHandler.store(pageAddr, off + inlineSize, row, storeMvccInfo());
}
Also used : InlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType) IgniteException(org.apache.ignite.IgniteException) InlineIndexRowHandler(org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Example 2 with InlineIndexRowHandler

use of org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler 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 3 with InlineIndexRowHandler

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

the class IndexQueryProcessor method alignCriteriaWithIndex.

/**
 * Checks that specified index matches index query criteria.
 */
private IndexRangeQuery alignCriteriaWithIndex(InlineIndexImpl idx, Map<String, RangeIndexQueryCriterion> criteria, IndexDefinition idxDef) {
    // Size of bounds array has to be equal to count of indexed fields.
    IndexKey[] lowerBounds = new IndexKey[idxDef.indexKeyDefinitions().size()];
    IndexKey[] upperBounds = new IndexKey[idxDef.indexKeyDefinitions().size()];
    boolean lowerAllNulls = true;
    boolean upperAllNulls = true;
    IndexRangeQuery qry = new IndexRangeQuery(criteria.size());
    // Checks that users criteria matches a prefix subset of index fields.
    int i = 0;
    for (Map.Entry<String, IndexKeyDefinition> keyDef : idxDef.indexKeyDefinitions().entrySet()) {
        RangeIndexQueryCriterion criterion = criteria.remove(keyDef.getKey());
        if (keyDef.getValue().order().sortOrder() == DESC)
            criterion = criterion.swap();
        qry.criteria[i] = criterion;
        IndexKey l = (IndexKey) criterion.lower();
        IndexKey u = (IndexKey) criterion.upper();
        if (l != null)
            lowerAllNulls = false;
        if (u != null)
            upperAllNulls = false;
        lowerBounds[i] = l;
        upperBounds[i++] = u;
        if (criteria.isEmpty())
            break;
    }
    InlineIndexRowHandler hnd = idx.segment(0).rowHandler();
    qry.lower = lowerAllNulls ? null : new IndexSearchRowImpl(lowerBounds, hnd);
    qry.upper = upperAllNulls ? null : new IndexSearchRowImpl(upperBounds, hnd);
    return qry;
}
Also used : IndexSearchRowImpl(org.apache.ignite.internal.cache.query.index.sorted.IndexSearchRowImpl) IndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) InlineIndexRowHandler(org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler) RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with InlineIndexRowHandler

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

the class AbstractInlineInnerIO method storeByOffset.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("ForLoopReplaceableByForEach")
@Override
public final void storeByOffset(long pageAddr, int off, IndexRow row) {
    assert row.link() != 0 : row;
    assertPageType(pageAddr);
    int fieldOff = 0;
    InlineIndexRowHandler rowHnd = ThreadLocalRowHandlerHolder.rowHandler();
    for (int i = 0; i < rowHnd.inlineIndexKeyTypes().size(); i++) {
        try {
            InlineIndexKeyType keyType = rowHnd.inlineIndexKeyTypes().get(i);
            int size = keyType.put(pageAddr, off + fieldOff, row.key(i), inlineSize - fieldOff);
            // Inline size has exceeded.
            if (size == 0)
                break;
            fieldOff += size;
        } catch (Exception e) {
            throw new IgniteException("Failed to store new index row.", e);
        }
    }
    IORowHandler.store(pageAddr, off + inlineSize, row, storeMvccInfo());
}
Also used : InlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType) IgniteException(org.apache.ignite.IgniteException) InlineIndexRowHandler(org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Example 5 with InlineIndexRowHandler

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

the class InlineIndexTree method inlineObjectSupported.

/**
 * Find whether tree supports inlining objects or not.
 *
 * @param def Index definition.
 * @param metaInfo Metapage info.
 * @return {@code true} if inline object is supported by exists tree.
 */
private boolean inlineObjectSupported(SortedIndexDefinition def, MetaPageInfo metaInfo, InlineIndexRowHandlerFactory rowHndFactory) {
    if (metaInfo.flagsSupported())
        return metaInfo.inlineObjectSupported();
    else {
        try {
            if (InlineObjectBytesDetector.objectMayBeInlined(metaInfo.inlineSize(), def.indexKeyDefinitions().values())) {
                try {
                    InlineObjectBytesDetector inlineObjDetector = new InlineObjectBytesDetector(metaInfo.inlineSize(), def.indexKeyDefinitions().values(), def.idxName(), log);
                    // Create a settings for case where java objects inilned as byte array.
                    IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjSupported(true).inlineObjHash(false);
                    InlineIndexRowHandler rowHnd = rowHndFactory.create(def, keyTypeSettings);
                    ThreadLocalRowHandlerHolder.rowHandler(rowHnd);
                    findFirst(inlineObjDetector);
                    return inlineObjDetector.inlineObjectSupported();
                } finally {
                    ThreadLocalRowHandlerHolder.clearRowHandler();
                }
            } else
                return false;
        } catch (IgniteCheckedException e) {
            throw new IgniteException("Unexpected exception on detect inline object", e);
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) InlineIndexRowHandler(org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)

Aggregations

InlineIndexRowHandler (org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteException (org.apache.ignite.IgniteException)3 InlineIndexKeyType (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 FailureContext (org.apache.ignite.failure.FailureContext)1 RangeIndexQueryCriterion (org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)1 IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)1 IndexKeyTypeSettings (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)1 IndexRow (org.apache.ignite.internal.cache.query.index.sorted.IndexRow)1 IndexSearchRowImpl (org.apache.ignite.internal.cache.query.index.sorted.IndexSearchRowImpl)1 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)1 DefragIndexRowImpl (org.apache.ignite.internal.cache.query.index.sorted.defragmentation.DefragIndexFactory.DefragIndexRowImpl)1 InlineIndex (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndex)1 InlineIndexImpl (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl)1 IndexKey (org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)1 LinkMap (org.apache.ignite.internal.processors.cache.persistence.defragmentation.LinkMap)1