Search in sources :

Example 11 with PageMemoryEx

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

the class GridCacheDatabaseSharedManager method restoreMemory.

/**
 * @param status Checkpoint status.
 * @param storeOnly If {@code True} restores Metastorage only.
 */
private WALPointer restoreMemory(CheckpointStatus status, boolean storeOnly, PageMemoryEx storePageMem) throws IgniteCheckedException {
    assert !storeOnly || storePageMem != null;
    if (log.isInfoEnabled())
        log.info("Checking memory state [lastValidPos=" + status.endPtr + ", lastMarked=" + status.startPtr + ", lastCheckpointId=" + status.cpStartId + ']');
    boolean apply = status.needRestoreMemory();
    if (apply) {
        U.quietAndWarn(log, "Ignite node stopped in the middle of checkpoint. Will restore memory state and " + "finish checkpoint on node start.");
        cctx.pageStore().beginRecover();
    } else
        cctx.wal().allowCompressionUntil(status.startPtr);
    long start = U.currentTimeMillis();
    int applied = 0;
    WALPointer lastRead = null;
    Collection<Integer> ignoreGrps = storeOnly ? Collections.emptySet() : initiallyWalDisabledGrps;
    try (WALIterator it = cctx.wal().replay(status.endPtr)) {
        while (it.hasNextX()) {
            IgniteBiTuple<WALPointer, WALRecord> tup = it.nextX();
            WALRecord rec = tup.get2();
            lastRead = tup.get1();
            switch(rec.type()) {
                case CHECKPOINT_RECORD:
                    CheckpointRecord cpRec = (CheckpointRecord) rec;
                    // We roll memory up until we find a checkpoint start record registered in the status.
                    if (F.eq(cpRec.checkpointId(), status.cpStartId)) {
                        log.info("Found last checkpoint marker [cpId=" + cpRec.checkpointId() + ", pos=" + tup.get1() + ']');
                        apply = false;
                    } else if (!F.eq(cpRec.checkpointId(), status.cpEndId))
                        U.warn(log, "Found unexpected checkpoint marker, skipping [cpId=" + cpRec.checkpointId() + ", expCpId=" + status.cpStartId + ", pos=" + tup.get1() + ']');
                    break;
                case PAGE_RECORD:
                    if (apply) {
                        PageSnapshot pageRec = (PageSnapshot) rec;
                        // Here we do not require tag check because we may be applying memory changes after
                        // several repetitive restarts and the same pages may have changed several times.
                        int grpId = pageRec.fullPageId().groupId();
                        if (storeOnly && grpId != METASTORAGE_CACHE_ID)
                            continue;
                        if (!ignoreGrps.contains(grpId)) {
                            long pageId = pageRec.fullPageId().pageId();
                            PageMemoryEx pageMem = grpId == METASTORAGE_CACHE_ID ? storePageMem : getPageMemoryForCacheGroup(grpId);
                            long page = pageMem.acquirePage(grpId, pageId, true);
                            try {
                                long pageAddr = pageMem.writeLock(grpId, pageId, page);
                                try {
                                    PageUtils.putBytes(pageAddr, 0, pageRec.pageData());
                                } finally {
                                    pageMem.writeUnlock(grpId, pageId, page, null, true, true);
                                }
                            } finally {
                                pageMem.releasePage(grpId, pageId, page);
                            }
                            applied++;
                        }
                    }
                    break;
                case PARTITION_DESTROY:
                    PartitionDestroyRecord destroyRec = (PartitionDestroyRecord) rec;
                    final int gId = destroyRec.groupId();
                    if (storeOnly && gId != METASTORAGE_CACHE_ID)
                        continue;
                    if (!ignoreGrps.contains(gId)) {
                        final int pId = destroyRec.partitionId();
                        PageMemoryEx pageMem = gId == METASTORAGE_CACHE_ID ? storePageMem : getPageMemoryForCacheGroup(gId);
                        pageMem.clearAsync((grpId, pageId) -> grpId == gId && PageIdUtils.partId(pageId) == pId, true).get();
                    }
                    break;
                default:
                    if (apply && rec instanceof PageDeltaRecord) {
                        PageDeltaRecord r = (PageDeltaRecord) rec;
                        int grpId = r.groupId();
                        if (storeOnly && grpId != METASTORAGE_CACHE_ID)
                            continue;
                        if (!ignoreGrps.contains(grpId)) {
                            long pageId = r.pageId();
                            PageMemoryEx pageMem = grpId == METASTORAGE_CACHE_ID ? storePageMem : getPageMemoryForCacheGroup(grpId);
                            // Here we do not require tag check because we may be applying memory changes after
                            // several repetitive restarts and the same pages may have changed several times.
                            long page = pageMem.acquirePage(grpId, pageId, true);
                            try {
                                long pageAddr = pageMem.writeLock(grpId, pageId, page);
                                try {
                                    r.applyDelta(pageMem, pageAddr);
                                } finally {
                                    pageMem.writeUnlock(grpId, pageId, page, null, true, true);
                                }
                            } finally {
                                pageMem.releasePage(grpId, pageId, page);
                            }
                            applied++;
                        }
                    }
            }
        }
    }
    if (storeOnly)
        return null;
    if (status.needRestoreMemory()) {
        if (apply)
            throw new IgniteCheckedException("Failed to restore memory state (checkpoint marker is present " + "on disk, but checkpoint record is missed in WAL) " + "[cpStatus=" + status + ", lastRead=" + lastRead + "]");
        log.info("Finished applying memory changes [changesApplied=" + applied + ", time=" + (U.currentTimeMillis() - start) + "ms]");
        if (applied > 0)
            finalizeCheckpointOnRecovery(status.cpStartTs, status.cpStartId, status.startPtr);
    }
    checkpointHist.loadHistory(cpDir);
    return lastRead == null ? null : lastRead.next();
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) RandomAccessFile(java.io.RandomAccessFile) OverlappingFileLockException(java.nio.channels.OverlappingFileLockException) Arrays(java.util.Arrays) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) MetastorageLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetastorageLifecycleListener) CheckpointWriteOrder(org.apache.ignite.configuration.CheckpointWriteOrder) IGNITE_PDS_SKIP_CRC(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) GridPortRecord(org.apache.ignite.internal.processors.port.GridPortRecord) Matcher(java.util.regex.Matcher) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) METASTORAGE_CACHE_ID(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_ID) Map(java.util.Map) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) Path(java.nio.file.Path) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheGroupDescriptor(org.apache.ignite.internal.processors.cache.CacheGroupDescriptor) Set(java.util.Set) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE) ByteOrder(java.nio.ByteOrder) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) PageIdUtils(org.apache.ignite.internal.pagemem.PageIdUtils) MappedFileMemoryProvider(org.apache.ignite.internal.mem.file.MappedFileMemoryProvider) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) AtomicIntegerFieldUpdater(java.util.concurrent.atomic.AtomicIntegerFieldUpdater) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) IgniteThread(org.apache.ignite.thread.IgniteThread) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) READ(java.nio.file.StandardOpenOption.READ) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) S(org.apache.ignite.internal.util.typedef.internal.S) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) SoftReference(java.lang.ref.SoftReference) DataStorageMetrics(org.apache.ignite.DataStorageMetrics) Files(java.nio.file.Files) GridUnsafe(org.apache.ignite.internal.util.GridUnsafe) IOException(java.io.IOException) IGNITE_PDS_WAL_REBALANCE_THRESHOLD(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD) File(java.io.File) T2(org.apache.ignite.internal.util.typedef.T2) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) FileFilter(java.io.FileFilter) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) Paths(java.nio.file.Paths) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteCacheSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteCacheSnapshotManager) GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) PartitionDestroyRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) CheckpointMetricsTracker(org.apache.ignite.internal.processors.cache.persistence.pagemem.CheckpointMetricsTracker) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) ByteBuffer(java.nio.ByteBuffer) FileLock(java.nio.channels.FileLock) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) SB(org.apache.ignite.internal.util.typedef.internal.SB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PureJavaCrc32(org.apache.ignite.internal.processors.cache.persistence.wal.crc.PureJavaCrc32) DataStorageMetricsMXBean(org.apache.ignite.mxbean.DataStorageMetricsMXBean) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) IgniteFuture(org.apache.ignite.lang.IgniteFuture) CacheState(org.apache.ignite.internal.pagemem.wal.record.CacheState) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) EventType(org.apache.ignite.events.EventType) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) StandardOpenOption(java.nio.file.StandardOpenOption) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StorageException(org.apache.ignite.internal.pagemem.wal.StorageException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) UUID(java.util.UUID) ObjectName(javax.management.ObjectName) NavigableMap(java.util.NavigableMap) NodeInvalidator(org.apache.ignite.internal.NodeInvalidator) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) PageDeltaRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord) ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CU(org.apache.ignite.internal.util.typedef.internal.CU) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) LongAdder(java.util.concurrent.atomic.LongAdder) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridMultiCollectionWrapper(org.apache.ignite.internal.util.GridMultiCollectionWrapper) HashMap(java.util.HashMap) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) LT(org.apache.ignite.internal.util.typedef.internal.LT) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) MemoryRecoveryRecord(org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord) ExecutorService(java.util.concurrent.ExecutorService) SnapshotOperation(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotOperation) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) PartitionAllocationMap(org.apache.ignite.internal.processors.cache.persistence.partstate.PartitionAllocationMap) F(org.apache.ignite.internal.util.typedef.F) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) Iterator(java.util.Iterator) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) CountDownFuture(org.apache.ignite.internal.util.future.CountDownFuture) DataPageEvictionMode(org.apache.ignite.configuration.DataPageEvictionMode) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) GridToStringInclude(org.apache.ignite.internal.util.tostring.GridToStringInclude) TimeUnit(java.util.concurrent.TimeUnit) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) Comparator(java.util.Comparator) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) PageDeltaRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) PartitionDestroyRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)

Example 12 with PageMemoryEx

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

the class GridCacheDatabaseSharedManager method createPageMemory.

/**
 * {@inheritDoc}
 */
@Override
protected PageMemory createPageMemory(DirectMemoryProvider memProvider, DataStorageConfiguration memCfg, DataRegionConfiguration plcCfg, DataRegionMetricsImpl memMetrics, final boolean trackable) {
    if (!plcCfg.isPersistenceEnabled())
        return super.createPageMemory(memProvider, memCfg, plcCfg, memMetrics, trackable);
    memMetrics.persistenceEnabled(true);
    long cacheSize = plcCfg.getMaxSize();
    // Checkpoint buffer size can not be greater than cache size, it does not make sense.
    long chpBufSize = checkpointBufferSize(plcCfg);
    if (chpBufSize > cacheSize) {
        U.quietAndInfo(log, "Configured checkpoint page buffer size is too big, setting to the max region size [size=" + U.readableSize(cacheSize, false) + ",  memPlc=" + plcCfg.getName() + ']');
        chpBufSize = cacheSize;
    }
    GridInClosure3X<Long, FullPageId, PageMemoryEx> changeTracker;
    if (trackable)
        changeTracker = new GridInClosure3X<Long, FullPageId, PageMemoryEx>() {

            @Override
            public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) throws IgniteCheckedException {
                if (trackable)
                    snapshotMgr.onChangeTrackerPage(page, fullId, pageMem);
            }
        };
    else
        changeTracker = null;
    PageMemoryImpl pageMem = new PageMemoryImpl(memProvider, calculateFragmentSizes(memCfg.getConcurrencyLevel(), cacheSize, chpBufSize), cctx, memCfg.getPageSize(), (fullId, pageBuf, tag) -> {
        // First of all, write page to disk.
        storeMgr.write(fullId.groupId(), fullId.pageId(), pageBuf, tag);
        // Only after write we can write page into snapshot.
        snapshotMgr.flushDirtyPageHandler(fullId, pageBuf, tag);
        AtomicInteger cntr = evictedPagesCntr;
        if (cntr != null)
            cntr.incrementAndGet();
    }, changeTracker, this, memMetrics, resolveThrottlingPolicy(), this);
    memMetrics.pageMemory(pageMem);
    return pageMem;
}
Also used : GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 13 with PageMemoryEx

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

the class GridCacheDatabaseSharedManager method restorePartitionState.

/**
 * @param partStates Partition states.
 * @throws IgniteCheckedException If failed to restore.
 */
private void restorePartitionState(Map<T2<Integer, Integer>, T2<Integer, Long>> partStates, Collection<Integer> ignoreGrps) throws IgniteCheckedException {
    for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
        if (grp.isLocal() || !grp.affinityNode() || ignoreGrps.contains(grp.groupId())) {
            // Local cache has no partitions and its states.
            continue;
        }
        if (!grp.dataRegion().config().isPersistenceEnabled())
            continue;
        int grpId = grp.groupId();
        PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
        for (int i = 0; i < grp.affinity().partitions(); i++) {
            T2<Integer, Long> restore = partStates.get(new T2<>(grpId, i));
            if (storeMgr.exists(grpId, i)) {
                storeMgr.ensure(grpId, i);
                if (storeMgr.pages(grpId, i) <= 1)
                    continue;
                GridDhtLocalPartition part = grp.topology().forceCreatePartition(i);
                assert part != null;
                // TODO: https://issues.apache.org/jira/browse/IGNITE-6097
                grp.offheap().onPartitionInitialCounterUpdated(i, 0);
                checkpointReadLock();
                try {
                    long partMetaId = pageMem.partitionMetaPageId(grpId, i);
                    long partMetaPage = pageMem.acquirePage(grpId, partMetaId);
                    try {
                        long pageAddr = pageMem.writeLock(grpId, partMetaId, partMetaPage);
                        boolean changed = false;
                        try {
                            PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.forPage(pageAddr);
                            if (restore != null) {
                                int stateId = restore.get1();
                                io.setPartitionState(pageAddr, (byte) stateId);
                                changed = updateState(part, stateId);
                                if (stateId == GridDhtPartitionState.OWNING.ordinal() || (stateId == GridDhtPartitionState.MOVING.ordinal() && part.initialUpdateCounter() < restore.get2())) {
                                    part.initialUpdateCounter(restore.get2());
                                    changed = true;
                                }
                            } else
                                updateState(part, (int) io.getPartitionState(pageAddr));
                        } finally {
                            pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, changed);
                        }
                    } finally {
                        pageMem.releasePage(grpId, partMetaId, partMetaPage);
                    }
                } finally {
                    checkpointReadUnlock();
                }
            } else if (restore != null) {
                GridDhtLocalPartition part = grp.topology().forceCreatePartition(i);
                assert part != null;
                // TODO: https://issues.apache.org/jira/browse/IGNITE-6097
                grp.offheap().onPartitionInitialCounterUpdated(i, 0);
                updateState(part, restore.get1());
            }
        }
        // After partition states are restored, it is necessary to update internal data structures in topology.
        grp.topology().afterStateRestored(grp.topology().lastTopologyChangeVersion());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 14 with PageMemoryEx

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

the class GridCacheOffheapManager method getOrAllocateCacheMetas.

/**
 * @return Meta root pages info.
 * @throws IgniteCheckedException If failed.
 */
private Metas getOrAllocateCacheMetas() throws IgniteCheckedException {
    PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
    IgniteWriteAheadLogManager wal = ctx.wal();
    int grpId = grp.groupId();
    long metaId = pageMem.metaPageId(grpId);
    long metaPage = pageMem.acquirePage(grpId, metaId);
    try {
        final long pageAddr = pageMem.writeLock(grpId, metaId, metaPage);
        boolean allocated = false;
        try {
            long metastoreRoot, reuseListRoot;
            if (PageIO.getType(pageAddr) != PageIO.T_META) {
                PageMetaIO pageIO = PageMetaIO.VERSIONS.latest();
                pageIO.initNewPage(pageAddr, metaId, pageMem.pageSize());
                metastoreRoot = pageMem.allocatePage(grpId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX);
                reuseListRoot = pageMem.allocatePage(grpId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX);
                pageIO.setTreeRoot(pageAddr, metastoreRoot);
                pageIO.setReuseListRoot(pageAddr, reuseListRoot);
                if (PageHandler.isWalDeltaRecordNeeded(pageMem, grpId, metaId, metaPage, wal, null))
                    wal.log(new MetaPageInitRecord(grpId, metaId, pageIO.getType(), pageIO.getVersion(), metastoreRoot, reuseListRoot));
                allocated = true;
            } else {
                PageMetaIO pageIO = PageIO.getPageIO(pageAddr);
                metastoreRoot = pageIO.getTreeRoot(pageAddr);
                reuseListRoot = pageIO.getReuseListRoot(pageAddr);
                assert reuseListRoot != 0L;
            }
            return new Metas(new RootPage(new FullPageId(metastoreRoot, grpId), allocated), new RootPage(new FullPageId(reuseListRoot, grpId), allocated));
        } finally {
            pageMem.writeUnlock(grpId, metaId, metaPage, null, allocated);
        }
    } finally {
        pageMem.releasePage(grpId, metaId, metaPage);
    }
}
Also used : PageMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) MetaPageInitRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 15 with PageMemoryEx

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

the class GridCacheOffheapManager method saveMeta.

/**
 * @param ctx Context.
 */
private void saveMeta(Context ctx) throws IgniteCheckedException {
    int grpId = grp.groupId();
    PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
    IgniteWriteAheadLogManager wal = this.ctx.wal();
    long metaPageId = pageMem.metaPageId(grpId);
    long metaPage = pageMem.acquirePage(grpId, metaPageId);
    try {
        long metaPageAddr = pageMem.writeLock(grpId, metaPageId, metaPage);
        try {
            PageMetaIO metaIo = PageMetaIO.getPageIO(metaPageAddr);
            long nextSnapshotTag = metaIo.getNextSnapshotTag(metaPageAddr);
            metaIo.setNextSnapshotTag(metaPageAddr, nextSnapshotTag + 1);
            if (log != null && log.isDebugEnabled())
                log.debug("Save next snapshot before checkpoint start for grId = " + grpId + ", nextSnapshotTag = " + nextSnapshotTag);
            if (PageHandler.isWalDeltaRecordNeeded(pageMem, grpId, metaPageId, metaPage, wal, null))
                wal.log(new MetaPageUpdateNextSnapshotId(grpId, metaPageId, nextSnapshotTag + 1));
            addPartition(null, ctx.partitionStatMap(), metaPageAddr, metaIo, grpId, PageIdAllocator.INDEX_PARTITION, this.ctx.pageStore().pages(grpId, PageIdAllocator.INDEX_PARTITION), -1);
        } finally {
            pageMem.writeUnlock(grpId, metaPageId, metaPage, null, true);
        }
    } finally {
        pageMem.releasePage(grpId, metaPageId, metaPage);
    }
}
Also used : PageMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) MetaPageUpdateNextSnapshotId(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateNextSnapshotId)

Aggregations

PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)18 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)8 PagePartitionMetaIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ByteBuffer (java.nio.ByteBuffer)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 HashMap (java.util.HashMap)4 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)4 WALPointer (org.apache.ignite.internal.pagemem.wal.WALPointer)4 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)4 PageDeltaRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord)4 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)4 GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState)4 File (java.io.File)3 RandomAccessFile (java.io.RandomAccessFile)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)3 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)3 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)3