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;
}
}
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;
}
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();
}
};
}
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);
}
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;
}
Aggregations