Search in sources :

Example 1 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class FilePageStoreManager method onPartitionDestroyed.

/**
 * {@inheritDoc}
 */
@Override
public void onPartitionDestroyed(int grpId, int partId, int tag) throws IgniteCheckedException {
    assert partId <= PageIdAllocator.MAX_PARTITION_ID;
    PageStore store = getStore(grpId, partId);
    assert store instanceof FilePageStore : store;
    ((FilePageStore) store).truncate(tag);
}
Also used : PageStore(org.apache.ignite.internal.pagemem.store.PageStore)

Example 2 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class GridCacheDatabaseSharedManager method finalizeCheckpointOnRecovery.

/**
 * @throws IgniteCheckedException If failed.
 */
private void finalizeCheckpointOnRecovery(long cpTs, UUID cpId, WALPointer walPtr) throws IgniteCheckedException {
    assert cpTs != 0;
    ByteBuffer tmpWriteBuf = ByteBuffer.allocateDirect(pageSize());
    long start = System.currentTimeMillis();
    Collection<DataRegion> memPolicies = context().database().dataRegions();
    List<IgniteBiTuple<PageMemory, Collection<FullPageId>>> cpEntities = new ArrayList<>(memPolicies.size());
    for (DataRegion memPlc : memPolicies) {
        if (memPlc.config().isPersistenceEnabled()) {
            PageMemoryEx pageMem = (PageMemoryEx) memPlc.pageMemory();
            cpEntities.add(new IgniteBiTuple<PageMemory, Collection<FullPageId>>(pageMem, (pageMem).beginCheckpoint()));
        }
    }
    tmpWriteBuf.order(ByteOrder.nativeOrder());
    // Identity stores set.
    Collection<PageStore> updStores = new HashSet<>();
    int cpPagesCnt = 0;
    for (IgniteBiTuple<PageMemory, Collection<FullPageId>> e : cpEntities) {
        PageMemoryEx pageMem = (PageMemoryEx) e.get1();
        Collection<FullPageId> cpPages = e.get2();
        cpPagesCnt += cpPages.size();
        for (FullPageId fullId : cpPages) {
            tmpWriteBuf.rewind();
            Integer tag = pageMem.getForCheckpoint(fullId, tmpWriteBuf, null);
            if (tag != null) {
                tmpWriteBuf.rewind();
                PageStore store = storeMgr.writeInternal(fullId.groupId(), fullId.pageId(), tmpWriteBuf, tag, true);
                tmpWriteBuf.rewind();
                updStores.add(store);
            }
        }
    }
    long written = U.currentTimeMillis();
    for (PageStore updStore : updStores) updStore.sync();
    long fsync = U.currentTimeMillis();
    for (IgniteBiTuple<PageMemory, Collection<FullPageId>> e : cpEntities) ((PageMemoryEx) e.get1()).finishCheckpoint();
    writeCheckpointEntry(tmpWriteBuf, cpTs, cpId, walPtr, null, CheckpointEntryType.END);
    cctx.pageStore().finishRecover();
    if (log.isInfoEnabled())
        log.info(String.format("Checkpoint finished [cpId=%s, pages=%d, markPos=%s, " + "pagesWrite=%dms, fsync=%dms, total=%dms]", cpId, cpPagesCnt, walPtr, written - start, fsync - written, fsync - start));
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) ByteBuffer(java.nio.ByteBuffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) HashSet(java.util.HashSet)

Example 3 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class GridCacheDatabaseSharedManager method forGroupPageStores.

/**
 * @param gctx Group context.
 * @param f Consumer.
 * @return Accumulated result for all page stores.
 */
public long forGroupPageStores(CacheGroupContext gctx, ToLongFunction<PageStore> f) {
    int groupId = gctx.groupId();
    long res = 0;
    try {
        Collection<PageStore> stores = storeMgr.getStores(groupId);
        if (stores != null) {
            for (PageStore store : stores) res += f.applyAsLong(store);
        }
    } catch (IgniteCheckedException e) {
        throw new IgniteException(e);
    }
    return res;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore)

Example 4 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class GridCacheOffheapManager method forGroupPageStores.

/**
 * @param gctx Group context.
 * @param f Consumer.
 * @return Accumulated result for all page stores.
 */
private long forGroupPageStores(CacheGroupContext gctx, ToLongFunction<PageStore> f) {
    int groupId = gctx.groupId();
    long res = 0;
    try {
        Collection<PageStore> stores = ((FilePageStoreManager) ctx.cache().context().pageStore()).getStores(groupId);
        if (stores != null) {
            for (PageStore store : stores) res += f.applyAsLong(store);
        }
    } catch (IgniteCheckedException e) {
        throw new IgniteException(e);
    }
    return res;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)

Example 5 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore 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)

Aggregations

PageStore (org.apache.ignite.internal.pagemem.store.PageStore)27 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 FilePageStoreManager (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)9 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 IgniteException (org.apache.ignite.IgniteException)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)5 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)5 PageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)5 File (java.io.File)4 ByteBuffer (java.nio.ByteBuffer)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 FailureContext (org.apache.ignite.failure.FailureContext)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)4