Search in sources :

Example 1 with DefragmentationPageReadWriteManager

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

the class GridCacheDatabaseSharedManager method configureDataRegionForDefragmentation.

/**
 * Configure data regions:
 * <p> Size of configured cache data regions will be decreased in order of freeing space for</p>
 * <p>defragmentation needs. * New defragmentation regions will be created which size would be based on freed space
 * from previous step.</p>
 *
 * @param memCfg Data storage configuration with data region configurations.
 * @return New data storage configuration which contains data regions with changed size.
 * @throws IgniteCheckedException If fail.
 */
private DataStorageConfiguration configureDataRegionForDefragmentation(DataStorageConfiguration memCfg) throws IgniteCheckedException {
    List<DataRegionConfiguration> regionConfs = new ArrayList<>();
    // not do the changes in-place it's better to make the copy of memCfg.
    DataStorageConfiguration dataConf = memCfg;
    regionConfs.add(dataConf.getDefaultDataRegionConfiguration());
    if (dataConf.getDataRegionConfigurations() != null)
        regionConfs.addAll(Arrays.asList(dataConf.getDataRegionConfigurations()));
    long totalDefrRegionSize = 0;
    long totalRegionsSize = 0;
    for (DataRegionConfiguration regionCfg : regionConfs) {
        totalDefrRegionSize = Math.max(totalDefrRegionSize, (long) (regionCfg.getMaxSize() * 0.01 * defragmentationRegionSizePercentageOfConfiguredSize));
        totalRegionsSize += regionCfg.getMaxSize();
    }
    double shrinkPercentage = 1d * (totalRegionsSize - totalDefrRegionSize) / totalRegionsSize;
    for (DataRegionConfiguration region : regionConfs) {
        long newSize = (long) (region.getMaxSize() * shrinkPercentage);
        long newInitSize = Math.min(region.getInitialSize(), newSize);
        if (log.isInfoEnabled()) {
            log.info("Region size was reassigned by defragmentation reason: " + "region = '" + region.getName() + "', " + "oldInitialSize = '" + region.getInitialSize() + "', " + "newInitialSize = '" + newInitSize + "', " + "oldMaxSize = '" + region.getMaxSize() + "', " + "newMaxSize = '" + newSize);
        }
        region.setMaxSize(newSize);
        region.setInitialSize(newInitSize);
        region.setCheckpointPageBufferSize(0);
    }
    long mappingRegionSize = Math.min(GB, (long) (totalDefrRegionSize * 0.1));
    checkpointedDataRegions.remove(addDataRegion(memCfg, createDefragmentationDataRegionConfig(totalDefrRegionSize - mappingRegionSize), true, new DefragmentationPageReadWriteManager(cctx.kernalContext(), "defrgPartitionsStore")));
    checkpointedDataRegions.remove(addDataRegion(memCfg, createDefragmentationMappingRegionConfig(mappingRegionSize), true, new DefragmentationPageReadWriteManager(cctx.kernalContext(), "defrgLinkMappingStore")));
    return dataConf;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ArrayList(java.util.ArrayList) DefragmentationPageReadWriteManager(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationPageReadWriteManager)

Aggregations

ArrayList (java.util.ArrayList)1 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 DefragmentationPageReadWriteManager (org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationPageReadWriteManager)1