Search in sources :

Example 1 with CacheDataRowAdapter

use of org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter 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);
                    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.database.tree.io.DataPageIO) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) CacheDataRowAdapter(org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter)

Aggregations

GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)1 CacheDataRowAdapter (org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter)1 DataPageIO (org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO)1