Search in sources :

Example 1 with GridCacheOffheapManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager in project ignite by apache.

the class CachePartitionDefragmentationManager method defragmentOnePartition.

/**
 * Defragment one given partition.
 */
private boolean defragmentOnePartition(CacheGroupContext oldGrpCtx, int grpId, File workDir, GridCacheOffheapManager offheap, FileVersionCheckingFactory pageStoreFactory, GridCompoundFuture<Object, Object> cmpFut, PageMemoryEx oldPageMem, CacheGroupContext newGrpCtx, CacheDataStore oldCacheDataStore) throws IgniteCheckedException {
    TreeIterator treeIter = new TreeIterator(pageSize);
    checkCancellation();
    int partId = oldCacheDataStore.partId();
    PartitionContext partCtx = new PartitionContext(workDir, grpId, partId, partDataRegion, mappingDataRegion, oldGrpCtx, newGrpCtx, oldCacheDataStore, pageStoreFactory);
    if (skipAlreadyDefragmentedPartition(workDir, grpId, partId, log)) {
        partCtx.createPageStore(() -> defragmentedPartMappingFile(workDir, partId).toPath(), partCtx.mappingPagesAllocated, partCtx.mappingPageMemory);
        linkMapByPart.put(partId, partCtx.createLinkMapTree(false));
        return false;
    }
    partCtx.createPageStore(() -> defragmentedPartMappingFile(workDir, partId).toPath(), partCtx.mappingPagesAllocated, partCtx.mappingPageMemory);
    linkMapByPart.put(partId, partCtx.createLinkMapTree(true));
    checkCancellation();
    partCtx.createPageStore(() -> defragmentedPartTmpFile(workDir, partId).toPath(), partCtx.partPagesAllocated, partCtx.partPageMemory);
    partCtx.createNewCacheDataStore(offheap);
    copyPartitionData(partCtx, treeIter);
    DefragmentationPageReadWriteManager pageMgr = (DefragmentationPageReadWriteManager) partCtx.partPageMemory.pageManager();
    PageStore oldPageStore = filePageStoreMgr.getStore(grpId, partId);
    status.onPartitionDefragmented(oldGrpCtx, oldPageStore.size(), // + file header.
    pageSize + partCtx.partPagesAllocated.get() * pageSize);
    // TODO Move inside of defragmentSinglePartition.
    IgniteInClosure<IgniteInternalFuture<?>> cpLsnr = fut -> {
        if (fut.error() == null) {
            if (log.isDebugEnabled()) {
                log.debug(S.toString("Partition defragmented", "grpId", grpId, false, "partId", partId, false, "oldPages", oldPageStore.pages(), false, "newPages", partCtx.partPagesAllocated.get() + 1, false, "mappingPages", partCtx.mappingPagesAllocated.get() + 1, false, "pageSize", pageSize, false, "partFile", defragmentedPartFile(workDir, partId).getName(), false, "workDir", workDir, false));
            }
            oldPageMem.invalidate(grpId, partId);
            partCtx.partPageMemory.invalidate(grpId, partId);
            // Yes, it'll be invalid in a second.
            pageMgr.pageStoreMap().removePageStore(grpId, partId);
            renameTempPartitionFile(workDir, partId);
        }
    };
    GridFutureAdapter<?> cpFut = defragmentationCheckpoint.forceCheckpoint("partition defragmented", null).futureFor(FINISHED);
    cpFut.listen(cpLsnr);
    cmpFut.add((IgniteInternalFuture<Object>) cpFut);
    return true;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Arrays(java.util.Arrays) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) CacheType(org.apache.ignite.internal.processors.cache.CacheType) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) FLAG_DATA(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_DATA) IntMap(org.apache.ignite.internal.util.collection.IntMap) DEFRAGMENTATION_MAPPING_REGION_NAME(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.DEFRAGMENTATION_MAPPING_REGION_NAME) DEFRAGMENTATION_PART_REGION_NAME(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.DEFRAGMENTATION_PART_REGION_NAME) DefragmentationFileUtils.defragmentedPartMappingFile(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.defragmentedPartMappingFile) CacheDataStore(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager.CacheDataStore) CheckpointTimeoutLock(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointTimeoutLock) DefragmentationFileUtils.defragmentedPartFile(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.defragmentedPartFile) LightweightCheckpointManager(org.apache.ignite.internal.processors.cache.persistence.checkpoint.LightweightCheckpointManager) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) Map(java.util.Map) Path(java.nio.file.Path) AbstractFreeList(org.apache.ignite.internal.processors.cache.persistence.freelist.AbstractFreeList) IndexProcessor(org.apache.ignite.internal.cache.query.index.IndexProcessor) DataRow(org.apache.ignite.internal.processors.cache.tree.DataRow) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) DefragmentationFileUtils.skipAlreadyDefragmentedPartition(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.skipAlreadyDefragmentedPartition) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) PendingRow(org.apache.ignite.internal.processors.cache.tree.PendingRow) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) IntRWHashMap(org.apache.ignite.internal.util.collection.IntRWHashMap) List(java.util.List) GridCacheDataStore(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager.GridCacheDataStore) StreamSupport.stream(java.util.stream.StreamSupport.stream) PageIdUtils(org.apache.ignite.internal.pagemem.PageIdUtils) CU(org.apache.ignite.internal.util.typedef.internal.CU) PagePartitionMetaIOV3(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIOV3) IntHashMap(org.apache.ignite.internal.util.collection.IntHashMap) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) GridAtomicLong(org.apache.ignite.internal.util.GridAtomicLong) SimpleDataRow(org.apache.ignite.internal.processors.cache.persistence.freelist.SimpleDataRow) DefragmentationFileUtils.defragmentedIndexTmpFile(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.defragmentedIndexTmpFile) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) DefragmentationFileUtils.renameTempIndexFile(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.renameTempIndexFile) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) CheckpointManager(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointManager) DefragmentationFileUtils.writeDefragmentationCompletionMarker(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.writeDefragmentationCompletionMarker) DefragmentationFileUtils.skipAlreadyDefragmentedCacheGroup(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.skipAlreadyDefragmentedCacheGroup) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) S(org.apache.ignite.internal.util.typedef.internal.S) DefragmentationFileUtils.renameTempPartitionFile(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.renameTempPartitionFile) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) Comparator.comparing(java.util.Comparator.comparing) CacheDataTree(org.apache.ignite.internal.processors.cache.tree.CacheDataTree) AbstractDataLeafIO(org.apache.ignite.internal.processors.cache.tree.AbstractDataLeafIO) FINISHED(org.apache.ignite.internal.processors.cache.persistence.CheckpointState.FINISHED) PendingEntriesTree(org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree) DefragmentationFileUtils.defragmentedPartTmpFile(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.defragmentedPartTmpFile) DefragmentationFileUtils.defragmentedIndexFile(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.defragmentedIndexFile) IoStatisticsHolderNoOp(org.apache.ignite.internal.metric.IoStatisticsHolderNoOp) DataPageEvictionMode(org.apache.ignite.configuration.DataPageEvictionMode) DefragmentationFileUtils.batchRenameDefragmentedCacheGroupPartitions(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils.batchRenameDefragmentedCacheGroupPartitions) FileVersionCheckingFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileVersionCheckingFactory) File(java.io.File) LongConsumer(java.util.function.LongConsumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) TreeMap(java.util.TreeMap) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 2 with GridCacheOffheapManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager in project ignite by apache.

the class Checkpointer method destroyEvictedPartitions.

/**
 * Processes all evicted partitions scheduled for destroy.
 *
 * @return The number of destroyed partition files.
 * @throws IgniteCheckedException If failed.
 */
private int destroyEvictedPartitions() throws IgniteCheckedException {
    PartitionDestroyQueue destroyQueue = curCpProgress.getDestroyQueue();
    if (destroyQueue.pendingReqs().isEmpty())
        return 0;
    List<PartitionDestroyRequest> reqs = null;
    for (final PartitionDestroyRequest req : destroyQueue.pendingReqs().values()) {
        if (!req.beginDestroy())
            continue;
        final int grpId = req.groupId();
        final int partId = req.partitionId();
        CacheGroupContext grp = cacheProcessor.cacheGroup(grpId);
        assert grp != null : "Cache group is not initialized [grpId=" + grpId + "]";
        assert grp.offheap() instanceof GridCacheOffheapManager : "Destroying partition files when persistence is off " + grp.offheap();
        final GridCacheOffheapManager offheap = (GridCacheOffheapManager) grp.offheap();
        Runnable destroyPartTask = () -> {
            try {
                offheap.destroyPartitionStore(partId);
                req.onDone(null);
                grp.metrics().decrementInitializedLocalPartitions();
                if (log.isDebugEnabled())
                    log.debug("Partition file has destroyed [grpId=" + grpId + ", partId=" + partId + "]");
            } catch (Exception e) {
                req.onDone(new IgniteCheckedException("Partition file destroy has failed [grpId=" + grpId + ", partId=" + partId + "]", e));
            }
        };
        IgniteThreadPoolExecutor pool = checkpointWritePagesPool;
        if (pool != null) {
            try {
                pool.execute(destroyPartTask);
            } catch (RejectedExecutionException ignore) {
                // Run the task synchronously.
                destroyPartTask.run();
            }
        } else
            destroyPartTask.run();
        if (reqs == null)
            reqs = new ArrayList<>();
        reqs.add(req);
    }
    if (reqs != null)
        for (PartitionDestroyRequest req : reqs) req.waitCompleted();
    destroyQueue.pendingReqs().clear();
    return reqs != null ? reqs.size() : 0;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) ArrayList(java.util.ArrayList) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 3 with GridCacheOffheapManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager in project ignite by apache.

the class ReleaseSegmentOnHistoricalRebalanceTest method testReleaseBeforeRebalanceIterator.

/**
 * Checks that if release the segment before {@link IgniteCacheOffheapManagerImpl#rebalanceIterator},
 * there will be no errors and the rebalance will be completed.
 *
 * @throws Exception If failed.
 */
@Test
public void testReleaseBeforeRebalanceIterator() throws Exception {
    checkHistoricalRebalance(n -> {
        IgniteInternalCache<?, ?> cachex = n.cachex(DEFAULT_CACHE_NAME);
        GridCacheOffheapManager spy = spy(offheapManager(cachex));
        doAnswer(m -> {
            CheckpointHistory cpHist = dbMgr(n).checkpointHistory();
            for (Long cp : cpHist.checkpoints()) release(n, entry(cpHist, cp).checkpointMark());
            return m.callRealMethod();
        }).when(spy).rebalanceIterator(any(), any());
        offheapManager(cachex, spy);
    });
}
Also used : GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Test(org.junit.Test)

Example 4 with GridCacheOffheapManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager in project ignite by apache.

the class CheckpointFreeListTest method testFreeListRestoredCorrectly.

/**
 * @throws Exception if fail.
 */
@Test
public void testFreeListRestoredCorrectly() throws Exception {
    IgniteEx ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    IgniteEx igniteClient = startClientGrid(getClientConfiguration("client"));
    Random random = new Random();
    IgniteCache<Integer, Object> cache = igniteClient.cache(CACHE_NAME);
    for (int j = 0; j < CACHE_SIZE; j++) {
        cache.put(j, new byte[random.nextInt(SF.apply(3072))]);
        if (random.nextBoolean())
            cache.remove(j);
    }
    GridCacheOffheapManager offheap = cacheOffheapManager();
    HashMap<Integer, AtomicReferenceArray<PagesList.Stripe[]>> bucketsStorage = new HashMap<>();
    offheap.cacheDataStores().forEach(cacheData -> bucketsStorage.put(cacheData.partId(), U.field(cacheData.rowStore().freeList(), "buckets")));
    forceCheckpoint();
    stopGrid(0);
    ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    GridCacheOffheapManager offheap2 = cacheOffheapManager();
    offheap2.cacheDataStores().forEach(cacheData -> {
        AtomicReferenceArray<PagesList.Stripe[]> restoredBuckets = U.field(cacheData.rowStore().freeList(), "buckets");
        AtomicReferenceArray<PagesList.Stripe[]> savedBuckets = bucketsStorage.get(cacheData.partId());
        if (savedBuckets != null && restoredBuckets != null) {
            assertEquals(restoredBuckets.length(), savedBuckets.length());
            for (int i = 0; i < restoredBuckets.length(); i++) assertTrue(Objects.deepEquals(restoredBuckets.get(i), savedBuckets.get(i)));
        } else
            assertTrue(savedBuckets == null && restoredBuckets == null);
    });
}
Also used : HashMap(java.util.HashMap) GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) PagesList(org.apache.ignite.internal.processors.cache.persistence.freelist.PagesList) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with GridCacheOffheapManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager in project ignite by apache.

the class UpgradePendingTreeToPerPartitionTask method processCacheGroup.

/**
 * Converts CacheGroup pending tree to per-partition basis.
 *
 * @param grp Cache group.
 * @throws IgniteCheckedException If error occurs.
 */
private void processCacheGroup(CacheGroupContext grp) throws IgniteCheckedException {
    assert grp.offheap() instanceof GridCacheOffheapManager;
    PendingEntriesTree oldPendingTree;
    final IgniteCacheDatabaseSharedManager db = grp.shared().database();
    db.checkpointReadLock();
    try {
        IndexStorage indexStorage = ((GridCacheOffheapManager) grp.offheap()).getIndexStorage();
        // TODO: IGNITE-5874: replace with some check-method to avoid unnecessary page allocation.
        RootPage pendingRootPage = indexStorage.allocateIndex(PENDING_ENTRIES_TREE_NAME);
        if (pendingRootPage.isAllocated()) {
            log.info("No pending tree found for cache group: [grpId=" + grp.groupId() + ", grpName=" + grp.name() + ']');
            // Nothing to do here as just allocated tree is obviously empty.
            indexStorage.dropIndex(PENDING_ENTRIES_TREE_NAME);
            return;
        }
        oldPendingTree = new PendingEntriesTree(grp, PENDING_ENTRIES_TREE_NAME, grp.dataRegion().pageMemory(), pendingRootPage.pageId().pageId(), ((GridCacheOffheapManager) grp.offheap()).reuseListForIndex(null), false, grp.shared().diagnostic().pageLockTracker(), PageIdAllocator.FLAG_IDX);
    } finally {
        db.checkpointReadUnlock();
    }
    processPendingTree(grp, oldPendingTree);
    if (Thread.currentThread().isInterrupted())
        return;
    db.checkpointReadLock();
    try {
        oldPendingTree.destroy();
    } finally {
        db.checkpointReadUnlock();
    }
}
Also used : GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) IndexStorage(org.apache.ignite.internal.processors.cache.persistence.IndexStorage) PendingEntriesTree(org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Aggregations

GridCacheOffheapManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager)13 HashMap (java.util.HashMap)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)5 Test (org.junit.Test)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)4 List (java.util.List)3 Map (java.util.Map)3 IgniteException (org.apache.ignite.IgniteException)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 File (java.io.File)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Comparator.comparing (java.util.Comparator.comparing)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2