Search in sources :

Example 6 with DataPageIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO in project ignite by apache.

the class DataPageMvccUpdateNewTxStateHintRecord method applyDelta.

/**
 * {@inheritDoc}
 */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
    DataPageIO io = PageIO.getPageIO(pageAddr);
    io.updateNewTxState(pageAddr, itemId, pageMem.realPageSize(groupId()), txState);
}
Also used : DataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO)

Example 7 with DataPageIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO in project ignite by apache.

the class PageAbstractEvictionTracker method evictDataPage.

/**
 * @param pageIdx Page index.
 * @return true if at least one data row has been evicted
 * @throws IgniteCheckedException If failed.
 */
final boolean evictDataPage(int pageIdx) throws IgniteCheckedException {
    long fakePageId = PageIdUtils.pageId(0, (byte) 0, pageIdx);
    long page = pageMem.acquirePage(0, fakePageId);
    List<CacheDataRowAdapter> rowsToEvict;
    try {
        long pageAddr = pageMem.readLockForce(0, fakePageId, page);
        try {
            if (PageIO.getType(pageAddr) != PageIO.T_DATA)
                // Can't evict: page has been recycled into non-data page.
                return false;
            DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
            long realPageId = PageIO.getPageId(pageAddr);
            if (!checkTouch(realPageId))
                // Can't evict: another thread concurrently invoked forgetPage()
                return false;
            rowsToEvict = io.forAllItems(pageAddr, new DataPageIO.CC<CacheDataRowAdapter>() {

                @Override
                public CacheDataRowAdapter apply(long link) throws IgniteCheckedException {
                    CacheDataRowAdapter row = new CacheDataRowAdapter(link);
                    row.initFromLink(null, sharedCtx, pageMem, CacheDataRowAdapter.RowData.KEY_ONLY, false);
                    assert row.cacheId() != 0 : "Cache ID should be stored in rows of evictable cache";
                    return row;
                }
            });
        } finally {
            pageMem.readUnlock(0, fakePageId, page);
        }
    } finally {
        pageMem.releasePage(0, fakePageId, page);
    }
    boolean evictionDone = false;
    for (CacheDataRowAdapter dataRow : rowsToEvict) {
        GridCacheContext<?, ?> cacheCtx = sharedCtx.cacheContext(dataRow.cacheId());
        if (!cacheCtx.userCache())
            continue;
        GridCacheEntryEx entryEx = cacheCtx.isNear() ? cacheCtx.near().dht().entryEx(dataRow.key()) : cacheCtx.cache().entryEx(dataRow.key());
        evictionDone |= entryEx.evictInternal(GridCacheVersionManager.EVICT_VER, null, true);
    }
    return evictionDone;
}
Also used : DataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) CacheDataRowAdapter(org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter)

Example 8 with DataPageIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO 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 9 with DataPageIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO in project ignite by apache.

the class CacheDataRowAdapter method relatedPageIds.

/**
 * @param grpId Group id.
 * @param link Link.
 * @param pageId PageId.
 * @param pageMem Page memory.
 * @param statHolder Status holder.
 * @return Array of page ids from link to pageId.
 * @throws IgniteCheckedException If failed.
 */
private long[] relatedPageIds(int grpId, long link, long pageId, PageMemory pageMem, IoStatisticsHolder statHolder) throws IgniteCheckedException {
    GridLongList pageIds = new GridLongList();
    long nextLink = link;
    long nextLinkPageId = pageId(nextLink);
    while (nextLinkPageId != pageId) {
        pageIds.add(nextLinkPageId);
        long page = pageMem.acquirePage(grpId, nextLinkPageId, statHolder);
        try {
            long pageAddr = pageMem.readLock(grpId, nextLinkPageId, page);
            try {
                DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
                int itemId = itemId(nextLink);
                DataPagePayload data = io.readPayload(pageAddr, itemId, pageMem.realPageSize(grpId));
                nextLink = data.nextLink();
                nextLinkPageId = pageId(nextLink);
            } finally {
                pageMem.readUnlock(grpId, nextLinkPageId, page);
            }
        } finally {
            pageMem.releasePage(grpId, nextLinkPageId, page);
        }
    }
    pageIds.add(pageId);
    return pageIds.array();
}
Also used : DataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO) GridLongList(org.apache.ignite.internal.util.GridLongList) DataPagePayload(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload)

Example 10 with DataPageIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO in project ignite by apache.

the class CacheDataRowAdapter method doInitFromLink.

/**
 * @param link Link.
 * @param sharedCtx Cache shared context.
 * @param coctx Cache object context.
 * @param pageMem Page memory.
 * @param grpId Cache group Id.
 * @param readCacheId {@code true} If need to read cache ID.
 * @param rowData Required row data.
 * @param incomplete Incomplete object.
 * @param skipVer Whether version read should be skipped.
 * @throws IgniteCheckedException If failed.
 */
private void doInitFromLink(long link, GridCacheSharedContext<?, ?> sharedCtx, CacheObjectContext coctx, PageMemory pageMem, int grpId, IoStatisticsHolder statHolder, boolean readCacheId, RowData rowData, @Nullable IncompleteObject<?> incomplete, boolean skipVer) throws IgniteCheckedException {
    assert link != 0 : "link";
    assert key == null : "key";
    long nextLink = link;
    do {
        final long pageId = pageId(nextLink);
        try {
            final long page = pageMem.acquirePage(grpId, pageId, statHolder);
            try {
                // Non-empty data page must not be recycled.
                long pageAddr = pageMem.readLock(grpId, pageId, page);
                assert pageAddr != 0L : nextLink;
                try {
                    DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
                    int itemId = itemId(nextLink);
                    incomplete = readIncomplete(incomplete, sharedCtx, coctx, pageMem.pageSize(), pageMem.realPageSize(grpId), pageAddr, itemId, io, rowData, readCacheId, skipVer);
                    if (incomplete == null || (rowData == KEY_ONLY && key != null))
                        return;
                    nextLink = incomplete.getNextLink();
                } finally {
                    pageMem.readUnlock(grpId, pageId, page);
                }
            } finally {
                pageMem.releasePage(grpId, pageId, page);
            }
        } catch (RuntimeException | AssertionError e) {
            // Collect all pages from first link to pageId.
            long[] pageIds;
            try {
                pageIds = relatedPageIds(grpId, link, pageId, pageMem, statHolder);
            } catch (IgniteCheckedException e0) {
                // Ignore exception if failed to resolve related page ids.
                pageIds = new long[] { pageId };
            }
            throw new BPlusTreeRuntimeException(e, grpId, pageIds);
        }
    } while (nextLink != 0);
    assert isReady() : "ready";
}
Also used : DataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO) BPlusTreeRuntimeException(org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTreeRuntimeException) BPlusTreeRuntimeException(org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTreeRuntimeException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Aggregations

DataPageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO)11 DataPagePayload (org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload)3 ByteBuffer (java.nio.ByteBuffer)2 CacheDataRowAdapter (org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter)2 File (java.io.File)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 OpenOption (java.nio.file.OpenOption)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Pattern (java.util.regex.Pattern)1 FileUtils (org.apache.commons.io.FileUtils)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 ClusterState (org.apache.ignite.cluster.ClusterState)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1