Search in sources :

Example 1 with MvccDataRow

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

the class DefragIndexFactory method lookupRow.

/**
 */
private static <T extends BPlusIO<IndexRow> & InlineIO> IndexRow lookupRow(InlineIndexRowHandler rowHnd, long pageAddr, int idx, T io) {
    long link = io.link(pageAddr, idx);
    int off = io.offset(idx);
    int inlineSize = io.inlineSize();
    byte[] values;
    if (rowHnd.inlineIndexKeyTypes().isEmpty())
        values = EMPTY_BYTES;
    else
        values = PageUtils.getBytes(pageAddr, off, inlineSize);
    if (io.storeMvccInfo()) {
        long mvccCrdVer = io.mvccCoordinatorVersion(pageAddr, idx);
        long mvccCntr = io.mvccCounter(pageAddr, idx);
        int mvccOpCntr = io.mvccOperationCounter(pageAddr, idx);
        MvccDataRow row = new MvccDataRow(null, 0, link, PageIdUtils.partId(PageIdUtils.pageId(link)), CacheDataRowAdapter.RowData.LINK_ONLY, mvccCrdVer, mvccCntr, mvccOpCntr, true);
        return new DefragIndexRowImpl(rowHnd, row, values);
    }
    return new DefragIndexRowImpl(rowHnd, new CacheDataRowAdapter(link), values);
}
Also used : MvccDataRow(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow) CacheDataRowAdapter(org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter)

Example 2 with MvccDataRow

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

the class CacheDataTree method scanDataPages.

/**
 * @param rowData Required row data.
 * @param c Optional MVCC closure.
 * @return Cache row cursor.
 * @throws IgniteCheckedException If failed.
 */
private GridCursor<CacheDataRow> scanDataPages(CacheDataRowAdapter.RowData rowData, MvccDataPageClosure c) throws IgniteCheckedException {
    lastFindWithDataPageScan = TRUE;
    checkDestroyed();
    assert rowData != null;
    assert grp.persistenceEnabled();
    int partId = rowStore.getPartitionId();
    GridCacheSharedContext shared = grp.shared();
    GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) shared.database();
    PageStore pageStore = db.getPageStore(grpId, partId);
    boolean mvccEnabled = grp.mvccEnabled();
    int pageSize = pageSize();
    long startPageId = ((PageMemoryEx) pageMem).partitionMetaPageId(grp.groupId(), partId);
    /**
     */
    final class DataPageScanCursor implements GridCursor<CacheDataRow> {

        /**
         */
        int pagesCnt = pageStore.pages();

        /**
         */
        int curPage = -1;

        /**
         */
        CacheDataRow[] rows = EMPTY_ROWS;

        /**
         */
        int curRow = -1;

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean next() throws IgniteCheckedException {
            if (rows == null)
                return false;
            if (++curRow < rows.length && rows[curRow] != null)
                return true;
            return readNextDataPage();
        }

        /**
         * @return {@code true} If new rows were fetched.
         * @throws IgniteCheckedException If failed.
         */
        private boolean readNextDataPage() throws IgniteCheckedException {
            checkDestroyed();
            for (; ; ) {
                if (++curPage >= pagesCnt) {
                    // Reread number of pages when we reach it (it may grow).
                    int newPagesCnt = pageStore.pages();
                    if (newPagesCnt <= pagesCnt) {
                        rows = null;
                        return false;
                    }
                    pagesCnt = newPagesCnt;
                }
                long pageId = startPageId + curPage;
                long page = pageMem.acquirePage(grpId, pageId);
                try {
                    boolean skipVer = CacheDataRowStore.getSkipVersion();
                    long pageAddr = ((PageMemoryEx) pageMem).readLock(page, pageId, true, false);
                    try {
                        // Here we should also exclude fragmented pages that don't contain the head of the entry.
                        if (PageIO.getType(pageAddr) != T_DATA)
                            // Not a data page.
                            continue;
                        DataPageIO io = PageIO.getPageIO(T_DATA, PageIO.getVersion(pageAddr));
                        int rowsCnt = io.getRowsCount(pageAddr);
                        if (rowsCnt == 0)
                            // Empty page.
                            continue;
                        if (rowsCnt > rows.length)
                            rows = new CacheDataRow[rowsCnt];
                        else
                            clearTail(rows, rowsCnt);
                        int r = 0;
                        for (int i = 0; i < rowsCnt; i++) {
                            if (c == null || c.applyMvcc(io, pageAddr, i, pageSize)) {
                                DataRow row = mvccEnabled ? new MvccDataRow() : new DataRow();
                                row.initFromDataPage(io, pageAddr, i, grp, shared, pageMem, rowData, skipVer);
                                rows[r++] = row;
                            }
                        }
                        if (r == 0)
                            // No rows fetched in this page.
                            continue;
                        curRow = 0;
                        return true;
                    } finally {
                        pageMem.readUnlock(grpId, pageId, page);
                    }
                } finally {
                    pageMem.releasePage(grpId, pageId, page);
                }
            }
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public CacheDataRow get() {
            return rows[curRow];
        }
    }
    return new DataPageScanCursor();
}
Also used : DataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridCursor(org.apache.ignite.internal.util.lang.GridCursor) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) MvccDataRow(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) MvccDataRow(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)

Example 3 with MvccDataRow

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

the class PendingRow method initKey.

/**
 * @param grp Cache group.
 * @return Row.
 * @throws IgniteCheckedException If failed.
 */
PendingRow initKey(CacheGroupContext grp) throws IgniteCheckedException {
    CacheDataRowAdapter rowData = grp.mvccEnabled() ? new MvccDataRow(link) : new CacheDataRowAdapter(link);
    rowData.initFromLink(grp, CacheDataRowAdapter.RowData.KEY_ONLY);
    key = rowData.key();
    return this;
}
Also used : CacheDataRowAdapter(org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter) MvccDataRow(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow)

Example 4 with MvccDataRow

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

the class CacheMvccBackupsAbstractTest method assertKeyVersionsEquals.

/**
 * @param leftRows Left rows.
 * @param rightRows Right rows.
 * @throws IgniteCheckedException If failed.
 */
private void assertKeyVersionsEquals(List<CacheDataRow> leftRows, List<CacheDataRow> rightRows) throws IgniteCheckedException {
    assertNotNull(leftRows);
    assertNotNull(rightRows);
    assertEquals("leftRows=" + leftRows + ", rightRows=" + rightRows, leftRows.size(), rightRows.size());
    for (int i = 0; i < leftRows.size(); i++) {
        CacheDataRow leftRow = leftRows.get(i);
        CacheDataRow rightRow = rightRows.get(i);
        assertNotNull(leftRow);
        assertNotNull(rightRow);
        assertTrue(leftRow instanceof MvccDataRow);
        assertTrue(rightRow instanceof MvccDataRow);
        leftRow.key().valueBytes(null);
        assertEquals(leftRow.expireTime(), rightRow.expireTime());
        assertEquals(leftRow.partition(), rightRow.partition());
        assertArrayEquals(leftRow.value().valueBytes(null), rightRow.value().valueBytes(null));
        assertEquals(leftRow.version(), rightRow.version());
        assertEquals(leftRow.cacheId(), rightRow.cacheId());
        assertEquals(leftRow.hash(), rightRow.hash());
        assertEquals(leftRow.key(), rightRow.key());
        assertTrue(MvccUtils.compare(leftRow, rightRow.mvccVersion()) == 0);
        assertTrue(MvccUtils.compareNewVersion(leftRow, rightRow.newMvccVersion()) == 0);
        assertEquals(leftRow.newMvccCoordinatorVersion(), rightRow.newMvccCoordinatorVersion());
        assertEquals(leftRow.newMvccCounter(), rightRow.newMvccCounter());
        assertEquals(leftRow.newMvccOperationCounter(), rightRow.newMvccOperationCounter());
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) MvccDataRow(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow)

Example 5 with MvccDataRow

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

the class GridDhtTxAbstractEnlistFuture method fetchHistoryInfo.

/**
 * @param key Key.
 * @param hist History rows.
 * @return History entries.
 * @throws IgniteCheckedException, if failed.
 */
private CacheEntryInfoCollection fetchHistoryInfo(KeyCacheObject key, List<MvccLinkAwareSearchRow> hist) {
    List<GridCacheEntryInfo> res = new ArrayList<>();
    for (int i = 0; i < hist.size(); i++) {
        MvccLinkAwareSearchRow row0 = hist.get(i);
        MvccDataRow row = new MvccDataRow(cctx.group(), row0.hash(), row0.link(), key.partition(), CacheDataRowAdapter.RowData.NO_KEY_WITH_HINTS, row0.mvccCoordinatorVersion(), row0.mvccCounter(), row0.mvccOperationCounter(), false);
        GridCacheMvccEntryInfo entry = new GridCacheMvccEntryInfo();
        entry.cacheId(cctx.cacheId());
        entry.version(row.version());
        entry.value(row.value());
        entry.expireTime(row.expireTime());
        // Row should be retrieved with actual hints.
        entry.mvccVersion(row);
        entry.newMvccVersion(row);
        if (MvccUtils.compare(mvccSnapshot, row.mvccCoordinatorVersion(), row.mvccCounter()) != 0)
            entry.mvccTxState(row.mvccTxState());
        if (row.newMvccCoordinatorVersion() != MvccUtils.MVCC_CRD_COUNTER_NA && MvccUtils.compare(mvccSnapshot, row.newMvccCoordinatorVersion(), row.newMvccCounter()) != 0)
            entry.newMvccTxState(row.newMvccTxState());
        assert mvccSnapshot.coordinatorVersion() != MvccUtils.MVCC_CRD_COUNTER_NA;
        res.add(entry);
    }
    return new CacheEntryInfoCollection(res);
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridCacheMvccEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo) CacheEntryInfoCollection(org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection) ArrayList(java.util.ArrayList) MvccDataRow(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow) MvccLinkAwareSearchRow(org.apache.ignite.internal.processors.cache.tree.mvcc.search.MvccLinkAwareSearchRow)

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