Search in sources :

Example 6 with MvccDataRow

use of org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow in project ignite by apache.

the class CacheDataTree method compareKeys.

/**
 * @param key Key.
 * @param link Link.
 * @return Compare result.
 * @throws IgniteCheckedException If failed.
 */
private int compareKeys(KeyCacheObject key, final long link) throws IgniteCheckedException {
    byte[] bytes = key.valueBytes(grp.cacheObjectContext());
    final long pageId = pageId(link);
    final long page = acquirePage(pageId);
    try {
        // Non-empty data page must not be recycled.
        long pageAddr = readLock(pageId, page);
        assert pageAddr != 0L : link;
        try {
            DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
            DataPagePayload data = io.readPayload(pageAddr, itemId(link), pageSize());
            if (data.nextLink() == 0) {
                long addr = pageAddr + data.offset();
                if (grp.mvccEnabled())
                    // Skip MVCC info.
                    addr += MVCC_INFO_SIZE;
                if (grp.storeCacheIdInDataPage())
                    // Skip cache id.
                    addr += 4;
                final int len = PageUtils.getInt(addr, 0);
                int lenCmp = Integer.compare(len, bytes.length);
                if (lenCmp != 0)
                    return lenCmp;
                // Skip length and type byte.
                addr += 5;
                final int words = len / 8;
                for (int i = 0; i < words; i++) {
                    int off = i * 8;
                    long b1 = PageUtils.getLong(addr, off);
                    long b2 = GridUnsafe.getLong(bytes, GridUnsafe.BYTE_ARR_OFF + off);
                    int cmp = Long.compare(b1, b2);
                    if (cmp != 0)
                        return cmp;
                }
                for (int i = words * 8; i < len; i++) {
                    byte b1 = PageUtils.getByte(addr, i);
                    byte b2 = bytes[i];
                    if (b1 != b2)
                        return b1 > b2 ? 1 : -1;
                }
                return 0;
            }
        } finally {
            readUnlock(pageId, page, pageAddr);
        }
    } finally {
        releasePage(pageId, page);
    }
    // TODO GG-11768.
    CacheDataRowAdapter other = grp.mvccEnabled() ? new MvccDataRow(link) : new CacheDataRowAdapter(link);
    other.initFromLink(grp, CacheDataRowAdapter.RowData.KEY_ONLY);
    byte[] bytes1 = other.key().valueBytes(grp.cacheObjectContext());
    byte[] bytes2 = key.valueBytes(grp.cacheObjectContext());
    int lenCmp = Integer.compare(bytes1.length, bytes2.length);
    if (lenCmp != 0)
        return lenCmp;
    final int len = bytes1.length;
    final int words = len / 8;
    for (int i = 0; i < words; i++) {
        int off = GridUnsafe.BYTE_ARR_INT_OFF + i * 8;
        long b1 = GridUnsafe.getLong(bytes1, off);
        long b2 = GridUnsafe.getLong(bytes2, off);
        int cmp = Long.compare(b1, b2);
        if (cmp != 0)
            return cmp;
    }
    for (int i = words * 8; i < len; i++) {
        byte b1 = bytes1[i];
        byte b2 = bytes2[i];
        if (b1 != b2)
            return b1 > b2 ? 1 : -1;
    }
    return 0;
}
Also used : DataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO) DataPagePayload(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload) CacheDataRowAdapter(org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter) MvccDataRow(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow)

Example 7 with MvccDataRow

use of org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow in project ignite by apache.

the class InlineIndexTree method createMvccIndexRow.

/**
 * Creates an mvcc index row for this tree.
 */
public IndexRowImpl createMvccIndexRow(long link, long mvccCrdVer, long mvccCntr, int mvccOpCntr) throws IgniteCheckedException {
    IndexRowImpl cachedRow = idxRowCache == null ? null : idxRowCache.get(link);
    if (cachedRow != null)
        return cachedRow;
    int partId = PageIdUtils.partId(PageIdUtils.pageId(link));
    MvccDataRow row = new MvccDataRow(cacheGroupContext(), 0, link, partId, null, mvccCrdVer, mvccCntr, mvccOpCntr, true);
    IndexRowImpl r = new IndexRowImpl(rowHandler(), row);
    if (idxRowCache != null)
        idxRowCache.put(r);
    return r;
}
Also used : IndexRowImpl(org.apache.ignite.internal.cache.query.index.sorted.IndexRowImpl) MvccDataRow(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow)

Aggregations

MvccDataRow (org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow)7 CacheDataRowAdapter (org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter)3 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)2 DataPageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO)2 ArrayList (java.util.ArrayList)1 IndexRowImpl (org.apache.ignite.internal.cache.query.index.sorted.IndexRowImpl)1 PageStore (org.apache.ignite.internal.pagemem.store.PageStore)1 CacheEntryInfoCollection (org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection)1 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)1 GridCacheMvccEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo)1 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)1 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)1 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)1 DataPagePayload (org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload)1 MvccLinkAwareSearchRow (org.apache.ignite.internal.processors.cache.tree.mvcc.search.MvccLinkAwareSearchRow)1 GridCursor (org.apache.ignite.internal.util.lang.GridCursor)1