Search in sources :

Example 6 with IndexRow

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

the class InlineIndexImpl method putx.

/**
 */
private boolean putx(IndexRowImpl idxRow, int segment, boolean flag) throws IgniteCheckedException {
    try {
        boolean replaced;
        if (flag)
            replaced = segments[segment].putx(idxRow);
        else {
            IndexRow prevRow0 = segments[segment].put(idxRow);
            replaced = prevRow0 != null;
        }
        return replaced;
    } catch (Throwable t) {
        cctx.kernalContext().failure().process(new FailureContext(CRITICAL_ERROR, t));
        throw t;
    }
}
Also used : IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) FailureContext(org.apache.ignite.failure.FailureContext)

Example 7 with IndexRow

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

the class InlineObjectBytesDetector method apply.

/**
 * {@inheritDoc}
 */
@Override
public boolean apply(BPlusTree<IndexRow, IndexRow> tree, BPlusIO<IndexRow> io, long pageAddr, int idx) throws IgniteCheckedException {
    IndexRow r = tree.getRow(io, pageAddr, idx);
    int off = io.offset(idx);
    int fieldOff = 0;
    boolean varLenPresents = false;
    IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings();
    Iterator<IndexKeyDefinition> it = keyDefs.iterator();
    for (int i = 0; i < keyDefs.size(); ++i) {
        IndexKeyDefinition keyDef = it.next();
        if (fieldOff >= inlineSize)
            return false;
        if (keyDef.idxType() != IndexKeyTypes.JAVA_OBJECT) {
            InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(keyDef.idxType(), keyTypeSettings);
            if (keyType.inlineSize() < 0)
                varLenPresents = true;
            fieldOff += keyType.inlineSize(pageAddr, off + fieldOff);
            continue;
        }
        IndexKey key = r.key(i);
        if (key == NullIndexKey.INSTANCE)
            return false;
        int type = PageUtils.getByte(pageAddr, off + fieldOff);
        // We can have garbage in memory and need to compare data.
        if (type == IndexKeyTypes.JAVA_OBJECT) {
            int len = PageUtils.getShort(pageAddr, off + fieldOff + 1);
            len &= 0x7FFF;
            byte[] originalObjBytes = ((JavaObjectIndexKey) key).bytesNoCopy();
            // Read size more then available space or more then origin length.
            if (len > inlineSize - fieldOff - 3 || len > originalObjBytes.length) {
                inlineObjectSupportedDecision(false, "length is big " + len);
                return true;
            }
            // Try compare byte by byte for fully or partial inlined object.
            byte[] inlineBytes = PageUtils.getBytes(pageAddr, off + fieldOff + 3, len);
            if (!Arrays.equals(inlineBytes, originalObjBytes)) {
                inlineObjectSupportedDecision(false, "byte compare");
                return true;
            }
            inlineObjectSupportedDecision(true, len + " bytes compared");
            return true;
        }
        if (type == IndexKeyTypes.UNKNOWN && varLenPresents) {
            // 2: short string, inlined java object
            return false;
        }
        inlineObjectSupportedDecision(false, "inline type " + type);
        return true;
    }
    inlineObjectSupportedDecision(true, "no java objects for inlining");
    return true;
}
Also used : JavaObjectIndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.JavaObjectIndexKey) IndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey) NullIndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.NullIndexKey) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) JavaObjectIndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.JavaObjectIndexKey) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)

Example 8 with IndexRow

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

the class H2TreeIndex method findFirstOrLast.

/**
 * {@inheritDoc}
 */
@Override
public Cursor findFirstOrLast(Session ses, boolean b) {
    try {
        QueryContext qctx = H2Utils.context(ses);
        IndexQueryContext qryCtx = idxQryContext(qctx);
        GridCursor<IndexRow> cursor = b ? queryIndex.findFirst(segment(qctx), qryCtx) : queryIndex.findLast(segment(qctx), qryCtx);
        return new H2Cursor(new IndexValueCursor<>(cursor, this::mapIndexRow));
    } catch (IgniteCheckedException e) {
        throw DbException.convert(e);
    }
}
Also used : IndexQueryContext(org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) H2Cursor(org.apache.ignite.internal.processors.query.h2.H2Cursor) IndexQueryContext(org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext) QueryContext(org.apache.ignite.internal.processors.query.h2.opt.QueryContext)

Example 9 with IndexRow

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

the class GeoSpatialIndexImpl method put.

/**
 */
private boolean put(CacheDataRow row) {
    checkClosed();
    Object key = def.rowHandler().key(row);
    assert key != null;
    final int seg = segmentForRow(row);
    Long rowId = keyToId.get(key);
    if (rowId != null) {
        Long oldRowId = segments[seg].remove(getEnvelope(idToRow.get(rowId).cacheDataRow(), rowId));
        assert rowId.equals(oldRowId);
    } else {
        rowId = ++rowIds;
        keyToId.put(key, rowId);
    }
    IndexRow old = idToRow.put(rowId, new IndexRowImpl(def.rowHandler(), row));
    segments[seg].put(getEnvelope(row, rowId), rowId);
    if (old == null)
        // No replace.
        rowCnt++;
    return old != null;
}
Also used : IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) IndexRowImpl(org.apache.ignite.internal.cache.query.index.sorted.IndexRowImpl)

Example 10 with IndexRow

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

the class IndexQueryProcessor method querySortedIndex.

/**
 * Runs an index query.
 *
 * @return Result cursor.
 */
private GridCursor<IndexRow> querySortedIndex(GridCacheContext<?, ?> cctx, SortedSegmentedIndex idx, IndexingQueryFilter cacheFilter, IndexRangeQuery qry) throws IgniteCheckedException {
    int segmentsCnt = cctx.isPartitioned() ? cctx.config().getQueryParallelism() : 1;
    BPlusTree.TreeRowClosure<IndexRow, IndexRow> treeFilter = null;
    // Also skips filtering if the current search is unbounded (both boundaries equal to null).
    if (qry.criteria.length > 1 && !(qry.lower == null && qry.upper == null)) {
        LinkedHashMap<String, IndexKeyDefinition> idxDef = idxProc.indexDefinition(idx.id()).indexKeyDefinitions();
        treeFilter = new IndexQueryCriteriaClosure(qry, idxDef, ((SortedIndexDefinition) idxProc.indexDefinition(idx.id())).rowComparator());
    }
    IndexQueryContext qryCtx = new IndexQueryContext(cacheFilter, treeFilter, null);
    if (segmentsCnt == 1)
        return treeIndexRange(idx, 0, qry, qryCtx);
    final GridCursor<IndexRow>[] segmentCursors = new GridCursor[segmentsCnt];
    // Actually it just traverses BPlusTree to find boundaries. It's too fast to parallelize this.
    for (int i = 0; i < segmentsCnt; i++) segmentCursors[i] = treeIndexRange(idx, i, qry, qryCtx);
    return new SegmentedIndexCursor(segmentCursors, (SortedIndexDefinition) idxProc.indexDefinition(idx.id()));
}
Also used : GridCursor(org.apache.ignite.internal.util.lang.GridCursor) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IndexQueryContext(org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext) BPlusTree(org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree)

Aggregations

IndexRow (org.apache.ignite.internal.cache.query.index.sorted.IndexRow)17 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 H2Cursor (org.apache.ignite.internal.processors.query.h2.H2Cursor)4 SingleCursor (org.apache.ignite.internal.cache.query.index.SingleCursor)3 IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)3 IndexValueCursor (org.apache.ignite.internal.cache.query.index.sorted.IndexValueCursor)3 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)3 IndexQueryContext (org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext)3 FailureContext (org.apache.ignite.failure.FailureContext)2 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)2 H2Row (org.apache.ignite.internal.processors.query.h2.opt.H2Row)2 QueryContext (org.apache.ignite.internal.processors.query.h2.opt.QueryContext)2 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 IgniteException (org.apache.ignite.IgniteException)1 IndexKeyTypeSettings (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)1 IndexRowImpl (org.apache.ignite.internal.cache.query.index.sorted.IndexRowImpl)1