/** * @return {@code true} if persistence is enabled for at least one data region, {@code false} if not. */ public static boolean isPersistenceEnabled(DataStorageConfiguration cfg) { if (cfg == null) return false; DataRegionConfiguration dfltReg = cfg.getDefaultDataRegionConfiguration(); if (dfltReg == null) return false; if (dfltReg.isPersistenceEnabled()) return true; DataRegionConfiguration[] regCfgs = cfg.getDataRegionConfigurations(); if (regCfgs == null) return false; for (DataRegionConfiguration regCfg : regCfgs) { if (regCfg.isPersistenceEnabled()) return true; } return false; }
/** * @param regCfg DataRegionConfiguration to validate. * @throws IgniteCheckedException If config is invalid. */ private void checkRegionMemoryStorageType(DataRegionConfiguration regCfg) throws IgniteCheckedException { if (regCfg.isPersistenceEnabled() && regCfg.getSwapPath() != null) throw new IgniteCheckedException("DataRegionConfiguration must not have both persistence " + "storage and swap space enabled at the same time (Use DataRegionConfiguration.setSwapPath(null) " + "to disable the swap space usage or DataRegionConfiguration.setPersistenceEnabled(false) " + "to disable the persistence) [name=" + regCfg.getName() + ", swapPath=" + regCfg.getSwapPath() + ", persistenceEnabled=" + regCfg.isPersistenceEnabled() + "]" ); }
/** {@inheritDoc} */ @Override protected IgniteOutClosure<Long> freeSpaceProvider(final DataRegionConfiguration dataRegCfg) { if (!dataRegCfg.isPersistenceEnabled()) return super.freeSpaceProvider(dataRegCfg); final String dataRegName = dataRegCfg.getName(); return new IgniteOutClosure<Long>() { @Override public Long apply() { long freeSpace = 0L; for (CacheGroupContext grpCtx : cctx.cache().cacheGroups()) { if (!grpCtx.dataRegion().config().getName().equals(dataRegName)) continue; assert grpCtx.offheap() instanceof GridCacheOffheapManager; freeSpace += ((GridCacheOffheapManager)grpCtx.offheap()).freeSpace(); } return freeSpace; } }; }
/** * @param regionCfg Region config. */ private void validateDataRegion(DataRegionConfiguration regionCfg) { if (regionCfg.isPersistenceEnabled() && regionCfg.getMaxSize() == DataStorageConfiguration.DFLT_DATA_REGION_MAX_SIZE) throw new AssertionError("Max size of data region should be set explicitly to avoid memory over usage"); }
/** {@inheritDoc} */ @Override protected void checkRegionEvictionProperties(DataRegionConfiguration regCfg, DataStorageConfiguration dbCfg) throws IgniteCheckedException { if (!regCfg.isPersistenceEnabled()) super.checkRegionEvictionProperties(regCfg, dbCfg); else if (regCfg.getPageEvictionMode() != DataPageEvictionMode.DISABLED) { U.warn(log, "Page eviction mode will have no effect because the oldest pages are evicted automatically " + "if Ignite persistence is enabled: " + regCfg.getName()); } }
/** * Releases the checkpoint read lock. */ @Override public void checkpointReadUnlock() { if (checkpointLock.writeLock().isHeldByCurrentThread()) return; checkpointLock.readLock().unlock(); if (checkpointer != null) { Collection<DataRegion> dataRegs = context().database().dataRegions(); if (dataRegs != null) { for (DataRegion dataReg : dataRegs) { if (!dataReg.config().isPersistenceEnabled()) continue; PageMemoryEx mem = (PageMemoryEx)dataReg.pageMemory(); if (mem != null && !mem.safeToUpdate()) { checkpointer.wakeupForCheckpoint(0, "too many dirty pages"); break; } } } } if (ASSERTION_ENABLED) CHECKPOINT_LOCK_HOLD_COUNT.set(CHECKPOINT_LOCK_HOLD_COUNT.get() - 1); }
/** * @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); }
if (dsCfg.getDefaultDataRegionConfiguration().isPersistenceEnabled()) return true; if (drConf.isPersistenceEnabled()) return true; return dsCfg.getDefaultDataRegionConfiguration().isPersistenceEnabled(); return drConf.isPersistenceEnabled();
/** * Get checkpoint buffer size for the given configuration. * * @param regCfg Configuration. * @return Checkpoint buffer size. */ public static long checkpointBufferSize(DataRegionConfiguration regCfg) { if (!regCfg.isPersistenceEnabled()) return 0L; long res = regCfg.getCheckpointPageBufferSize(); if (res == 0L) { if (regCfg.getMaxSize() < GB) res = Math.min(DFLT_MIN_CHECKPOINTING_PAGE_BUFFER_SIZE, regCfg.getMaxSize()); else if (regCfg.getMaxSize() < 8 * GB) res = regCfg.getMaxSize() / 4; else res = DFLT_MAX_CHECKPOINTING_PAGE_BUFFER_SIZE; } return res; }
/** * @param plc data region Configuration. * @param pageMem Page memory. */ protected PageEvictionTracker createPageEvictionTracker(DataRegionConfiguration plc, PageMemory pageMem) { if (plc.getPageEvictionMode() == DataPageEvictionMode.DISABLED || plc.isPersistenceEnabled()) return new NoOpPageEvictionTracker(); assert pageMem instanceof PageMemoryNoStoreImpl : pageMem.getClass(); PageMemoryNoStoreImpl pageMem0 = (PageMemoryNoStoreImpl)pageMem; if (Boolean.getBoolean("override.fair.fifo.page.eviction.tracker")) return new FairFifoPageEvictionTracker(pageMem0, plc, cctx); switch (plc.getPageEvictionMode()) { case RANDOM_LRU: return new RandomLruPageEvictionTracker(pageMem0, plc, cctx); case RANDOM_2_LRU: return new Random2LruPageEvictionTracker(pageMem0, plc, cctx); default: return new NoOpPageEvictionTracker(); } }
/** * @param grp Cache group. * @param freeList Free list. */ public RowStore(CacheGroupContext grp, FreeList freeList) { assert grp != null; assert freeList != null; this.freeList = freeList; ctx = grp.shared(); coctx = grp.cacheObjectContext(); pageMem = grp.dataRegion().pageMemory(); persistenceEnabled = grp.dataRegion().config().isPersistenceEnabled(); }
/** * @return {@code true} if all PageMemory instances are safe to update. */ private boolean safeToUpdatePageMemories() { Collection<DataRegion> memPlcs = context().database().dataRegions(); if (memPlcs == null) return true; for (DataRegion memPlc : memPlcs) { if (!memPlc.config().isPersistenceEnabled()) continue; PageMemoryEx pageMemEx = (PageMemoryEx)memPlc.pageMemory(); if (!pageMemEx.safeToUpdate()) return false; } return true; }
.filter(v -> v.config().isPersistenceEnabled()) .map(v -> v.config().getName().trim()) .collect(Collectors.toSet());
/** * @param memCfg Database config. * @throws IgniteCheckedException If failed to initialize swap path. */ protected void initDataRegions0(DataStorageConfiguration memCfg) throws IgniteCheckedException { DataRegionConfiguration[] dataRegionCfgs = memCfg.getDataRegionConfigurations(); if (dataRegionCfgs != null) { for (DataRegionConfiguration dataRegionCfg : dataRegionCfgs) addDataRegion(memCfg, dataRegionCfg, dataRegionCfg.isPersistenceEnabled()); } addDataRegion( memCfg, memCfg.getDefaultDataRegionConfiguration(), memCfg.getDefaultDataRegionConfiguration().isPersistenceEnabled() ); addDataRegion( memCfg, createSystemDataRegion( memCfg.getSystemRegionInitialSize(), memCfg.getSystemRegionMaxSize(), CU.isPersistenceEnabled(memCfg) ), CU.isPersistenceEnabled(memCfg) ); for (DatabaseLifecycleListener lsnr : getDatabaseListeners(cctx.kernalContext())) lsnr.onInitDataRegions(this); }
grp.groupId(), pageMem, grp.dataRegion().config().isPersistenceEnabled() ? grp.shared().wal() : null, grp.offheap().globalRemoveId(), metaPageId, assert !grp.dataRegion().config().isPersistenceEnabled() || grp.shared().database().checkpointLockIsHeldByThread();
/** * Constructor. * * @param plc Data region configuration. */ public VisorDataRegionConfiguration(DataRegionConfiguration plc) { assert plc != null; name = plc.getName(); initSize = plc.getInitialSize(); maxSize = plc.getMaxSize(); swapPath = plc.getSwapPath(); pageEvictionMode = plc.getPageEvictionMode(); evictionThreshold = plc.getEvictionThreshold(); emptyPagesPoolSize = plc.getEmptyPagesPoolSize(); metricsEnabled = plc.isMetricsEnabled(); metricsSubIntervalCount = plc.getMetricsSubIntervalCount(); metricsRateTimeInterval = plc.getMetricsRateTimeInterval(); persistenceEnabled = plc.isPersistenceEnabled(); checkpointPageBufSize = plc.getCheckpointPageBufferSize(); }
/** * 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) { warnFirstEvict(plcCfg); memPlc.evictionTracker().evictDataPage(); memPlc.memoryMetrics().updateEvictionRate(); } else break; } }
/** * @param regCfg Data region configuration. * @return Data region message. */ private String dataRegionConfigurationMessage(DataRegionConfiguration regCfg) { if (regCfg == null) return null; SB m = new SB(); m.a(" ^-- ").a(regCfg.getName()).a(" ["); m.a("initSize=").a(U.readableSize(regCfg.getInitialSize(), false)); m.a(", maxSize=").a(U.readableSize(regCfg.getMaxSize(), false)); m.a(", persistence=" + regCfg.isPersistenceEnabled()).a(']'); return m.toString(); }
/** {@inheritDoc} */ @Override protected void start0() throws IgniteCheckedException { compressProc = cctx.kernalContext().compress(); CacheConfiguration cfg = cctx.config(); diskPageCompression = cfg.getDiskPageCompression(); if (diskPageCompression != null) { if (!cctx.dataRegion().config().isPersistenceEnabled()) throw new IgniteCheckedException("Disk page compression makes sense only with enabled persistence."); Integer lvl = cfg.getDiskPageCompressionLevel(); diskPageCompressLevel = lvl != null ? checkCompressionLevelBounds(lvl, diskPageCompression) : getDefaultCompressionLevel(diskPageCompression); DataStorageConfiguration dsCfg = cctx.kernalContext().config().getDataStorageConfiguration(); File dbPath = cctx.kernalContext().pdsFolderResolver().resolveFolders().persistentStoreRootPath(); assert dbPath != null; compressProc.checkPageCompressionSupported(dbPath.toPath(), dsCfg.getPageSize()); if (log.isInfoEnabled()) { log.info("Disk page compression is enabled [cache=" + cctx.name() + ", compression=" + diskPageCompression + ", level=" + diskPageCompressLevel + "]"); } } }
/** * Writes the data region configuration. * * @param w Writer. */ private static void writeDataRegionConfiguration(BinaryRawWriter w, DataRegionConfiguration cfg) { assert w != null; assert cfg != null; w.writeString(cfg.getName()); w.writeBoolean(cfg.isPersistenceEnabled()); w.writeLong(cfg.getInitialSize()); w.writeLong(cfg.getMaxSize()); w.writeString(cfg.getSwapPath()); w.writeInt(cfg.getPageEvictionMode().ordinal()); w.writeDouble(cfg.getEvictionThreshold()); w.writeInt(cfg.getEmptyPagesPoolSize()); w.writeBoolean(cfg.isMetricsEnabled()); w.writeInt(cfg.getMetricsSubIntervalCount()); w.writeLong(cfg.getMetricsRateTimeInterval()); w.writeLong(cfg.getCheckpointPageBufferSize()); }