Search in sources :

Example 1 with CacheFreeListImpl

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

the class IgniteCacheDatabaseSharedManager method ensureFreeSpace.

/**
 * See {@link GridCacheMapEntry#ensureFreeSpace()}
 *
 * @param memPlc data region.
 */
public void ensureFreeSpace(DataRegion memPlc) throws IgniteCheckedException {
    if (memPlc == null)
        return;
    DataRegionConfiguration plcCfg = memPlc.config();
    if (plcCfg.getPageEvictionMode() == DataPageEvictionMode.DISABLED || plcCfg.isPersistenceEnabled())
        return;
    long memorySize = plcCfg.getMaxSize();
    PageMemory pageMem = memPlc.pageMemory();
    int sysPageSize = pageMem.systemPageSize();
    CacheFreeListImpl freeListImpl = freeListMap.get(plcCfg.getName());
    for (; ; ) {
        long allocatedPagesCnt = pageMem.loadedPages();
        int emptyDataPagesCnt = freeListImpl.emptyDataPages();
        boolean shouldEvict = allocatedPagesCnt > (memorySize / sysPageSize * plcCfg.getEvictionThreshold()) && emptyDataPagesCnt < plcCfg.getEmptyPagesPoolSize();
        if (shouldEvict) {
            memPlc.evictionTracker().evictDataPage();
            memPlc.memoryMetrics().updateEvictionRate();
        } else
            break;
    }
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheFreeListImpl(org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeListImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory)

Example 2 with CacheFreeListImpl

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

the class GridCacheOffheapManager method saveStoreMetadata.

/**
 * @param store Store to save metadata.
 * @throws IgniteCheckedException If failed.
 */
private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean saveMeta, boolean beforeDestroy) throws IgniteCheckedException {
    RowStore rowStore0 = store.rowStore();
    boolean needSnapshot = ctx != null && ctx.nextSnapshot() && ctx.needToSnapshot(grp.cacheOrGroupName());
    boolean wasSaveToMeta = false;
    if (rowStore0 != null) {
        CacheFreeListImpl freeList = (CacheFreeListImpl) rowStore0.freeList();
        freeList.saveMetadata();
        long updCntr = store.updateCounter();
        int size = store.fullSize();
        long rmvId = globalRemoveId().get();
        PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
        IgniteWriteAheadLogManager wal = this.ctx.wal();
        if (size > 0 || updCntr > 0) {
            GridDhtPartitionState state = null;
            // localPartition will not acquire writeLock here because create=false.
            GridDhtLocalPartition part = null;
            if (!grp.isLocal()) {
                if (beforeDestroy)
                    state = GridDhtPartitionState.EVICTED;
                else {
                    part = getPartition(store);
                    if (part != null && part.state() != GridDhtPartitionState.EVICTED)
                        state = part.state();
                }
                // Do not save meta for evicted partitions on next checkpoints.
                if (state == null)
                    return false;
            }
            int grpId = grp.groupId();
            long partMetaId = pageMem.partitionMetaPageId(grpId, store.partId());
            long partMetaPage = pageMem.acquirePage(grpId, partMetaId);
            try {
                long partMetaPageAddr = pageMem.writeLock(grpId, partMetaId, partMetaPage);
                if (partMetaPageAddr == 0L) {
                    U.warn(log, "Failed to acquire write lock for meta page [metaPage=" + partMetaPage + ", saveMeta=" + saveMeta + ", beforeDestroy=" + beforeDestroy + ", size=" + size + ", updCntr=" + updCntr + ", state=" + state + ']');
                    return false;
                }
                boolean changed = false;
                try {
                    PagePartitionMetaIO io = PageIO.getPageIO(partMetaPageAddr);
                    changed |= io.setUpdateCounter(partMetaPageAddr, updCntr);
                    changed |= io.setGlobalRemoveId(partMetaPageAddr, rmvId);
                    changed |= io.setSize(partMetaPageAddr, size);
                    if (state != null)
                        changed |= io.setPartitionState(partMetaPageAddr, (byte) state.ordinal());
                    else
                        assert grp.isLocal() : grp.cacheOrGroupName();
                    long cntrsPageId;
                    if (grp.sharedGroup()) {
                        long initCntrPageId = io.getCountersPageId(partMetaPageAddr);
                        Map<Integer, Long> newSizes = store.cacheSizes();
                        Map<Integer, Long> prevSizes = readSharedGroupCacheSizes(pageMem, grpId, initCntrPageId);
                        if (prevSizes != null && prevSizes.equals(newSizes))
                            // Preventing modification of sizes pages for store
                            cntrsPageId = initCntrPageId;
                        else {
                            cntrsPageId = writeSharedGroupCacheSizes(pageMem, grpId, initCntrPageId, store.partId(), newSizes);
                            if (initCntrPageId == 0 && cntrsPageId != 0) {
                                io.setCountersPageId(partMetaPageAddr, cntrsPageId);
                                changed = true;
                            }
                        }
                    } else
                        cntrsPageId = 0L;
                    int pageCnt;
                    if (needSnapshot) {
                        pageCnt = this.ctx.pageStore().pages(grpId, store.partId());
                        io.setCandidatePageCount(partMetaPageAddr, size == 0 ? 0 : pageCnt);
                        if (saveMeta) {
                            saveMeta(ctx);
                            wasSaveToMeta = true;
                        }
                        if (state == OWNING) {
                            assert part != null;
                            if (!addPartition(part, ctx.partitionStatMap(), partMetaPageAddr, io, grpId, store.partId(), this.ctx.pageStore().pages(grpId, store.partId()), store.fullSize()))
                                U.warn(log, "Partition was concurrently evicted grpId=" + grpId + ", partitionId=" + part.id());
                        } else if (state == MOVING || state == RENTING) {
                            if (ctx.partitionStatMap().forceSkipIndexPartition(grpId)) {
                                if (log.isInfoEnabled())
                                    log.info("Will not include SQL indexes to snapshot because there is " + "a partition not in " + OWNING + " state [grp=" + grp.cacheOrGroupName() + ", partId=" + store.partId() + ", state=" + state + ']');
                            }
                        }
                        changed = true;
                    } else
                        pageCnt = io.getCandidatePageCount(partMetaPageAddr);
                    if (PageHandler.isWalDeltaRecordNeeded(pageMem, grpId, partMetaId, partMetaPage, wal, null))
                        wal.log(new MetaPageUpdatePartitionDataRecord(grpId, partMetaId, updCntr, rmvId, size, cntrsPageId, state == null ? -1 : (byte) state.ordinal(), pageCnt));
                } finally {
                    pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, changed);
                }
            } finally {
                pageMem.releasePage(grpId, partMetaId, partMetaPage);
            }
        } else if (needSnapshot)
            tryAddEmptyPartitionToSnapshot(store, ctx);
        ;
    } else if (needSnapshot)
        tryAddEmptyPartitionToSnapshot(store, ctx);
    return wasSaveToMeta;
}
Also used : CacheFreeListImpl(org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeListImpl) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) CacheDataRowStore(org.apache.ignite.internal.processors.cache.tree.CacheDataRowStore) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState) MetaPageUpdatePartitionDataRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord) 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)

Example 3 with CacheFreeListImpl

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

the class IgniteCacheDatabaseSharedManager method freeSpaceProvider.

/**
 * Closure that can be used to compute fill factor for provided data region.
 *
 * @param dataRegCfg Data region configuration.
 * @return Closure.
 */
protected IgniteOutClosure<Long> freeSpaceProvider(final DataRegionConfiguration dataRegCfg) {
    final String dataRegName = dataRegCfg.getName();
    return new IgniteOutClosure<Long>() {

        private CacheFreeListImpl freeList;

        @Override
        public Long apply() {
            if (freeList == null) {
                CacheFreeListImpl freeList0 = freeListMap.get(dataRegName);
                if (freeList0 == null)
                    return 0L;
                freeList = freeList0;
            }
            return freeList.freeSpace();
        }
    };
}
Also used : CacheFreeListImpl(org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeListImpl) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure)

Example 4 with CacheFreeListImpl

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

the class IgniteCacheDatabaseSharedManager method initPageMemoryDataStructures.

/**
 * @param dbCfg Database config.
 * @throws IgniteCheckedException If failed.
 */
protected void initPageMemoryDataStructures(DataStorageConfiguration dbCfg) throws IgniteCheckedException {
    freeListMap = U.newHashMap(dataRegionMap.size());
    String dfltMemPlcName = dbCfg.getDefaultDataRegionConfiguration().getName();
    for (DataRegion memPlc : dataRegionMap.values()) {
        DataRegionConfiguration memPlcCfg = memPlc.config();
        DataRegionMetricsImpl memMetrics = (DataRegionMetricsImpl) memMetricsMap.get(memPlcCfg.getName());
        boolean persistenceEnabled = memPlcCfg.isPersistenceEnabled();
        CacheFreeListImpl freeList = new CacheFreeListImpl(0, cctx.igniteInstanceName(), memMetrics, memPlc, null, persistenceEnabled ? cctx.wal() : null, 0L, true);
        freeListMap.put(memPlcCfg.getName(), freeList);
    }
    dfltFreeList = freeListMap.get(dfltMemPlcName);
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheFreeListImpl(org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeListImpl)

Example 5 with CacheFreeListImpl

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

the class GridCacheOffheapManager method freeSpace.

/**
 * Calculates free space of all partition data stores - number of bytes available for use in allocated pages.
 *
 * @return Tuple (numenator, denominator).
 */
long freeSpace() {
    long freeSpace = 0;
    for (CacheDataStore store : partDataStores.values()) {
        assert store instanceof GridCacheDataStore;
        CacheFreeListImpl freeList = ((GridCacheDataStore) store).freeList;
        if (freeList == null)
            continue;
        freeSpace += freeList.freeSpace();
    }
    return freeSpace;
}
Also used : CacheFreeListImpl(org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeListImpl)

Aggregations

CacheFreeListImpl (org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeListImpl)7 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)3 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)2 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)1 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)1 MetaPageUpdatePartitionDataRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState)1 DataRegion (org.apache.ignite.internal.processors.cache.persistence.DataRegion)1 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)1 NoOpPageEvictionTracker (org.apache.ignite.internal.processors.cache.persistence.evict.NoOpPageEvictionTracker)1 PagesList (org.apache.ignite.internal.processors.cache.persistence.freelist.PagesList)1 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)1 PagePartitionMetaIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)1 CacheDataRowStore (org.apache.ignite.internal.processors.cache.tree.CacheDataRowStore)1 T2 (org.apache.ignite.internal.util.typedef.T2)1 IgniteOutClosure (org.apache.ignite.lang.IgniteOutClosure)1