Search in sources :

Example 1 with MaxSizePolicy

use of com.hazelcast.config.MaxSizePolicy in project hazelcast by hazelcast.

the class CachePartitionIteratorBouncingTest method getConfig.

@Override
protected Config getConfig() {
    Config config = smallInstanceConfig();
    MaxSizePolicy maxSizePolicy = getInMemoryFormat() == InMemoryFormat.NATIVE ? USED_NATIVE_MEMORY_SIZE : DEFAULT_MAX_SIZE_POLICY;
    config.getCacheConfig(TEST_CACHE_NAME).setInMemoryFormat(getInMemoryFormat()).getEvictionConfig().setMaxSizePolicy(maxSizePolicy).setSize(Integer.MAX_VALUE);
    return config;
}
Also used : MaxSizePolicy(com.hazelcast.config.MaxSizePolicy) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) Config(com.hazelcast.config.Config)

Example 2 with MaxSizePolicy

use of com.hazelcast.config.MaxSizePolicy in project hazelcast by hazelcast.

the class CacheEventJournalBasicTest method getConfig.

@Override
protected Config getConfig() {
    Config config = super.getConfig();
    CacheSimpleConfig nonEvictingCache = config.getCacheConfig(NON_EVICTING_CACHE).setInMemoryFormat(getInMemoryFormat());
    MaxSizePolicy maxSizePolicy = getInMemoryFormat() == InMemoryFormat.NATIVE ? USED_NATIVE_MEMORY_SIZE : DEFAULT_MAX_SIZE_POLICY;
    nonEvictingCache.getEvictionConfig().setMaxSizePolicy(maxSizePolicy).setSize(Integer.MAX_VALUE);
    final CacheSimpleConfig evictingCache = config.getCacheConfig(EVICTING_CACHE).setInMemoryFormat(getInMemoryFormat());
    evictingCache.getEvictionConfig().setMaxSizePolicy(maxSizePolicy);
    return config;
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) MaxSizePolicy(com.hazelcast.config.MaxSizePolicy) Config(com.hazelcast.config.Config) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig)

Example 3 with MaxSizePolicy

use of com.hazelcast.config.MaxSizePolicy in project hazelcast by hazelcast.

the class EvictionChecker method checkEvictable.

public boolean checkEvictable(RecordStore recordStore) {
    if (recordStore.size() == 0) {
        return false;
    }
    String mapName = recordStore.getName();
    MapContainer mapContainer = recordStore.getMapContainer();
    EvictionConfig evictionConfig = mapContainer.getMapConfig().getEvictionConfig();
    MaxSizePolicy maximumSizePolicy = evictionConfig.getMaxSizePolicy();
    int maxConfiguredSize = evictionConfig.getSize();
    switch(maximumSizePolicy) {
        case PER_NODE:
            return recordStore.size() > toPerPartitionMaxSize(maxConfiguredSize, mapName);
        case PER_PARTITION:
            return recordStore.size() > maxConfiguredSize;
        case USED_HEAP_SIZE:
            return usedHeapInBytes(mapName) > MEGABYTES.toBytes(maxConfiguredSize);
        case FREE_HEAP_SIZE:
            return availableMemoryInBytes() < MEGABYTES.toBytes(maxConfiguredSize);
        case USED_HEAP_PERCENTAGE:
            return (usedHeapInBytes(mapName) * ONE_HUNDRED / Math.max(maxMemoryInBytes(), 1)) > maxConfiguredSize;
        case FREE_HEAP_PERCENTAGE:
            return (availableMemoryInBytes() * ONE_HUNDRED / Math.max(maxMemoryInBytes(), 1)) < maxConfiguredSize;
        default:
            throw new IllegalArgumentException("Not an appropriate max size policy [" + maximumSizePolicy + ']');
    }
}
Also used : MaxSizePolicy(com.hazelcast.config.MaxSizePolicy) EvictionConfig(com.hazelcast.config.EvictionConfig) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 4 with MaxSizePolicy

use of com.hazelcast.config.MaxSizePolicy in project hazelcast by hazelcast.

the class AbstractInternalQueryCache method reachedMaxCapacity.

@Override
public boolean reachedMaxCapacity() {
    EvictionConfig evictionConfig = queryCacheConfig.getEvictionConfig();
    MaxSizePolicy maximumSizePolicy = evictionConfig.getMaxSizePolicy();
    return maximumSizePolicy == MaxSizePolicy.ENTRY_COUNT && size() == evictionConfig.getSize();
}
Also used : MaxSizePolicy(com.hazelcast.config.MaxSizePolicy) EvictionConfig(com.hazelcast.config.EvictionConfig)

Example 5 with MaxSizePolicy

use of com.hazelcast.config.MaxSizePolicy in project hazelcast by hazelcast.

the class ConfigValidator method checkOnHeapNearCacheMaxSizePolicy.

private static void checkOnHeapNearCacheMaxSizePolicy(NearCacheConfig nearCacheConfig) {
    InMemoryFormat inMemoryFormat = nearCacheConfig.getInMemoryFormat();
    if (inMemoryFormat == NATIVE) {
        return;
    }
    MaxSizePolicy maxSizePolicy = nearCacheConfig.getEvictionConfig().getMaxSizePolicy();
    if (!NEAR_CACHE_SUPPORTED_ON_HEAP_MAX_SIZE_POLICIES.contains(maxSizePolicy)) {
        throw new InvalidConfigurationException(format("Near Cache maximum size policy %s cannot be used with %s storage." + " Supported maximum size policies are: %s", maxSizePolicy, inMemoryFormat, NEAR_CACHE_SUPPORTED_ON_HEAP_MAX_SIZE_POLICIES));
    }
}
Also used : MaxSizePolicy(com.hazelcast.config.MaxSizePolicy) InMemoryFormat(com.hazelcast.config.InMemoryFormat) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Aggregations

MaxSizePolicy (com.hazelcast.config.MaxSizePolicy)7 EvictionConfig (com.hazelcast.config.EvictionConfig)3 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)2 Config (com.hazelcast.config.Config)2 InMemoryFormat (com.hazelcast.config.InMemoryFormat)2 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)2 EvictionPolicy (com.hazelcast.config.EvictionPolicy)1 ConfigValidator.checkEvictionConfig (com.hazelcast.internal.config.ConfigValidator.checkEvictionConfig)1 ConfigValidator.checkMapEvictionConfig (com.hazelcast.internal.config.ConfigValidator.checkMapEvictionConfig)1 ConfigValidator.checkNearCacheEvictionConfig (com.hazelcast.internal.config.ConfigValidator.checkNearCacheEvictionConfig)1 MapContainer (com.hazelcast.map.impl.MapContainer)1