Search in sources :

Example 6 with PageStore

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

the class MetaStorage method init.

/**
 */
public void init(GridCacheDatabaseSharedManager db) throws IgniteCheckedException {
    dataRegion.metrics().clear();
    initInternal(db);
    if (!PRESERVE_LEGACY_METASTORAGE_PARTITION_ID) {
        if (partId == OLD_METASTORE_PARTITION)
            db.temporaryMetaStorage(copyDataToTmpStorage());
        else if (db.temporaryMetaStorage() != null) {
            restoreDataFromTmpStorage(db.temporaryMetaStorage());
            db.temporaryMetaStorage(null);
            db.addCheckpointListener(new CheckpointListener() {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public void onMarkCheckpointBegin(Context ctx) {
                }

                /**
                 * {@inheritDoc}
                 */
                @Override
                public void onCheckpointBegin(Context ctx) throws IgniteCheckedException {
                    assert cctx.pageStore() != null;
                    int partTag = ((PageMemoryEx) dataRegion.pageMemory()).invalidate(METASTORAGE_CACHE_ID, OLD_METASTORE_PARTITION);
                    cctx.pageStore().truncate(METASTORAGE_CACHE_ID, OLD_METASTORE_PARTITION, partTag);
                    int idxTag = ((PageMemoryEx) dataRegion.pageMemory()).invalidate(METASTORAGE_CACHE_ID, PageIdAllocator.INDEX_PARTITION);
                    PageStore store = ((FilePageStoreManager) cctx.pageStore()).getStore(METASTORAGE_CACHE_ID, PageIdAllocator.INDEX_PARTITION);
                    store.truncate(idxTag);
                    db.removeCheckpointListener(this);
                }

                /**
                 * {@inheritDoc}
                 */
                @Override
                public void beforeCheckpointBegin(Context ctx) {
                }
            }, dataRegion);
        }
    }
}
Also used : GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)

Example 7 with PageStore

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

the class PageReadWriteManagerImpl method write.

/**
 * {@inheritDoc}
 */
@Override
public PageStore write(int grpId, long pageId, ByteBuffer pageBuf, int tag, boolean calculateCrc) throws IgniteCheckedException {
    int partId = PageIdUtils.partId(pageId);
    PageStore store = pageStores.getStore(grpId, partId);
    try {
        int pageSize = store.getPageSize();
        int compressedPageSize = pageSize;
        GridCacheContext<?, ?> cctx0 = ctx.cache().context().cacheContext(grpId);
        if (cctx0 != null) {
            assert pageBuf.position() == 0 && pageBuf.limit() == pageSize : pageBuf;
            ByteBuffer compressedPageBuf = cctx0.compress().compressPage(pageBuf, store);
            if (compressedPageBuf != pageBuf) {
                compressedPageSize = PageIO.getCompressedSize(compressedPageBuf);
                if (!calculateCrc) {
                    calculateCrc = true;
                    // It will be recalculated over compressed data further.
                    PageIO.setCrc(compressedPageBuf, 0);
                }
                // It is expected to be reset to 0 after each write.
                PageIO.setCrc(pageBuf, 0);
                pageBuf = compressedPageBuf;
            }
        }
        store.write(pageId, pageBuf, tag, calculateCrc);
        if (pageSize > compressedPageSize)
            // TODO maybe add async punch mode?
            store.punchHole(pageId, compressedPageSize);
    } catch (StorageException e) {
        ctx.failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
        throw e;
    }
    return store;
}
Also used : FailureContext(org.apache.ignite.failure.FailureContext) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) ByteBuffer(java.nio.ByteBuffer) StorageException(org.apache.ignite.internal.processors.cache.persistence.StorageException)

Example 8 with PageStore

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

the class PageReadWriteManagerImpl method read.

/**
 * {@inheritDoc}
 */
@Override
public void read(int grpId, long pageId, ByteBuffer pageBuf, boolean keepCrc) throws IgniteCheckedException {
    PageStore store = pageStores.getStore(grpId, PageIdUtils.partId(pageId));
    try {
        store.read(pageId, pageBuf, keepCrc);
        ctx.compress().decompressPage(pageBuf, store.getPageSize());
    } catch (StorageException e) {
        ctx.failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
        throw e;
    }
}
Also used : FailureContext(org.apache.ignite.failure.FailureContext) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) StorageException(org.apache.ignite.internal.processors.cache.persistence.StorageException)

Example 9 with PageStore

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

the class Checkpointer method writePages.

/**
 * @param workProgressDispatcher Work progress dispatcher.
 * @param tracker Checkpoint metrics tracker.
 * @param cpPages List of pages to write.
 * @param curCpProgress Current checkpoint data.
 * @param shutdownNow Checker of stop operation.
 */
boolean writePages(CheckpointMetricsTracker tracker, GridConcurrentMultiPairQueue<PageMemoryEx, FullPageId> cpPages, CheckpointProgressImpl curCpProgress, WorkProgressDispatcher workProgressDispatcher, BooleanSupplier shutdownNow) throws IgniteCheckedException {
    IgniteThreadPoolExecutor pageWritePool = checkpointWritePagesPool;
    int checkpointWritePageThreads = pageWritePool == null ? 1 : pageWritePool.getMaximumPoolSize();
    // Identity stores set.
    ConcurrentLinkedHashMap<PageStore, LongAdder> updStores = new ConcurrentLinkedHashMap<>();
    CountDownFuture doneWriteFut = new CountDownFuture(checkpointWritePageThreads);
    tracker.onPagesWriteStart();
    for (int i = 0; i < checkpointWritePageThreads; i++) {
        Runnable write = checkpointPagesWriterFactory.build(tracker, cpPages, updStores, doneWriteFut, workProgressDispatcher::updateHeartbeat, curCpProgress, shutdownNow);
        if (pageWritePool == null)
            write.run();
        else {
            try {
                pageWritePool.execute(write);
            } catch (RejectedExecutionException ignore) {
                // Run the task synchronously.
                write.run();
            }
        }
    }
    workProgressDispatcher.updateHeartbeat();
    // Wait and check for errors.
    doneWriteFut.get();
    // If so, we should not put finish checkpoint mark.
    if (shutdownNow.getAsBoolean()) {
        curCpProgress.fail(new NodeStoppingException("Node is stopping."));
        return false;
    }
    tracker.onFsyncStart();
    if (!skipSync) {
        for (Map.Entry<PageStore, LongAdder> updStoreEntry : updStores.entrySet()) {
            if (shutdownNow.getAsBoolean()) {
                curCpProgress.fail(new NodeStoppingException("Node is stopping."));
                return false;
            }
            workProgressDispatcher.blockingSectionBegin();
            try {
                updStoreEntry.getKey().sync();
            } finally {
                workProgressDispatcher.blockingSectionEnd();
            }
            curCpProgress.updateSyncedPages(updStoreEntry.getValue().intValue());
        }
    }
    return true;
}
Also used : CountDownFuture(org.apache.ignite.internal.util.future.CountDownFuture) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) LongAdder(java.util.concurrent.atomic.LongAdder) Map(java.util.Map) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap)

Example 10 with PageStore

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

the class CachePartitionDefragmentationManager method createIndexPageStore.

/**
 */
public void createIndexPageStore(int grpId, File workDir, FileVersionCheckingFactory pageStoreFactory, DataRegion partRegion, LongConsumer allocatedTracker) throws IgniteCheckedException {
    // Index partition file has to be deleted before we begin, otherwise there's a chance of reading corrupted file.
    // There is a time period when index is already defragmented but marker file is not created yet. If node is
    // failed in that time window then index will be deframented once again. That's fine, situation is rare but code
    // to fix that would add unnecessary complications.
    U.delete(defragmentedIndexTmpFile(workDir));
    PageStore idxPageStore;
    defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
    try {
        idxPageStore = pageStoreFactory.createPageStore(FLAG_IDX, () -> defragmentedIndexTmpFile(workDir).toPath(), allocatedTracker);
    } finally {
        defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
    }
    idxPageStore.sync();
    PageMemoryEx partPageMem = (PageMemoryEx) partRegion.pageMemory();
    DefragmentationPageReadWriteManager partMgr = (DefragmentationPageReadWriteManager) partPageMem.pageManager();
    partMgr.pageStoreMap().addPageStore(grpId, INDEX_PARTITION, idxPageStore);
}
Also used : PageStore(org.apache.ignite.internal.pagemem.store.PageStore) 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