Search in sources :

Example 1 with MaxSizeConfig

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

the class MapConfigDTO method fromJson.

@Override
public void fromJson(JsonObject json) {
    config = new MapConfig();
    config.setName(getString(json, "name"));
    config.setInMemoryFormat(InMemoryFormat.valueOf(getString(json, "memoryFormat")));
    config.setBackupCount(getInt(json, "backupCount"));
    config.setAsyncBackupCount(getInt(json, "asyncBackupCount"));
    config.setEvictionPercentage(getInt(json, "evictionPercentage"));
    config.setMinEvictionCheckMillis(getLong(json, "minEvictionCheckMillis"));
    config.setTimeToLiveSeconds(getInt(json, "ttl"));
    config.setMaxIdleSeconds(getInt(json, "maxIdle"));
    config.setMaxSizeConfig(new MaxSizeConfig().setSize(getInt(json, "maxSize")).setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.valueOf(getString(json, "maxSizePolicy"))));
    config.setReadBackupData(getBoolean(json, "readBackupData"));
    config.setEvictionPolicy(EvictionPolicy.valueOf(getString(json, "evictionPolicy")));
    config.setMergePolicy(getString(json, "mergePolicy"));
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 2 with MaxSizeConfig

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

the class MapConfigDTO method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    config = new MapConfig();
    config.setName(in.readUTF());
    config.setInMemoryFormat(InMemoryFormat.valueOf(in.readUTF()));
    config.setBackupCount(in.readInt());
    config.setAsyncBackupCount(in.readInt());
    config.setEvictionPercentage(in.readInt());
    config.setMinEvictionCheckMillis(in.readLong());
    config.setTimeToLiveSeconds(in.readInt());
    config.setMaxIdleSeconds(in.readInt());
    config.setMaxSizeConfig(new MaxSizeConfig().setSize(in.readInt()).setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.valueOf(in.readUTF())));
    config.setReadBackupData(in.readBoolean());
    config.setEvictionPolicy(EvictionPolicy.valueOf(in.readUTF()));
    config.setMergePolicy(in.readUTF());
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 3 with MaxSizeConfig

use of com.hazelcast.config.MaxSizeConfig 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();
    MaxSizeConfig maxSizeConfig = mapContainer.getMapConfig().getMaxSizeConfig();
    MaxSizeConfig.MaxSizePolicy maxSizePolicy = maxSizeConfig.getMaxSizePolicy();
    switch(maxSizePolicy) {
        case PER_NODE:
            return checkPerNodeEviction(recordStore);
        case PER_PARTITION:
            int partitionId = recordStore.getPartitionId();
            return checkPerPartitionEviction(mapName, maxSizeConfig, partitionId);
        case USED_HEAP_PERCENTAGE:
            return checkHeapPercentageEviction(mapName, maxSizeConfig);
        case USED_HEAP_SIZE:
            return checkHeapSizeEviction(mapName, maxSizeConfig);
        case FREE_HEAP_PERCENTAGE:
            return checkFreeHeapPercentageEviction(maxSizeConfig);
        case FREE_HEAP_SIZE:
            return checkFreeHeapSizeEviction(maxSizeConfig);
        default:
            throw new IllegalArgumentException("Not an appropriate max size policy [" + maxSizePolicy + ']');
    }
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MemorySize.toPrettyString(com.hazelcast.memory.MemorySize.toPrettyString) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 4 with MaxSizeConfig

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

the class EvictionChecker method calculatePerNodeMaxRecordStoreSize.

/**
     * Calculates and returns the expected maximum size of an evicted record-store
     * when {@link com.hazelcast.config.MaxSizeConfig.MaxSizePolicy#PER_NODE PER_NODE} max-size-policy is used.
     */
public double calculatePerNodeMaxRecordStoreSize(RecordStore recordStore) {
    MapConfig mapConfig = recordStore.getMapContainer().getMapConfig();
    MaxSizeConfig maxSizeConfig = mapConfig.getMaxSizeConfig();
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    int configuredMaxSize = maxSizeConfig.getSize();
    int memberCount = nodeEngine.getClusterService().getSize(DATA_MEMBER_SELECTOR);
    int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
    return (1D * configuredMaxSize * memberCount / partitionCount);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 5 with MaxSizeConfig

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

the class EvictionTest method testEvictionPerPartition.

@Test
public void testEvictionPerPartition() throws InterruptedException {
    final int k = 2;
    final int size = 10;
    final String mapName = "testEvictionPerPartition";
    Config cfg = getConfig();
    cfg.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    final MapConfig mc = cfg.getMapConfig(mapName);
    mc.setEvictionPolicy(EvictionPolicy.LRU);
    mc.setEvictionPercentage(50);
    mc.setMinEvictionCheckMillis(0);
    final MaxSizeConfig msc = new MaxSizeConfig();
    msc.setMaxSizePolicy(PER_PARTITION);
    msc.setSize(size);
    mc.setMaxSizeConfig(msc);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
    final HazelcastInstance[] instances = factory.newInstances(cfg);
    final int pNum = instances[0].getPartitionService().getPartitions().size();
    int insertCount = size * pNum * 2;
    final Map<Integer, Integer> map = instances[0].getMap(mapName);
    for (int i = 0; i < insertCount; i++) {
        map.put(i, i);
    }
    int mapSize = map.size();
    String message = format("mapSize : %d should be <= max-size : %d ", mapSize, size);
    assertTrue(message, mapSize <= size);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)26 MapConfig (com.hazelcast.config.MapConfig)18 QuickTest (com.hazelcast.test.annotation.QuickTest)15 Test (org.junit.Test)15 Config (com.hazelcast.config.Config)13 ParallelTest (com.hazelcast.test.annotation.ParallelTest)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)7 NearCacheConfig (com.hazelcast.config.NearCacheConfig)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 NightlyTest (com.hazelcast.test.annotation.NightlyTest)5 IMap (com.hazelcast.core.IMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 EvictionPolicy (com.hazelcast.config.EvictionPolicy)1 GroupConfig (com.hazelcast.config.GroupConfig)1 MapIndexConfig (com.hazelcast.config.MapIndexConfig)1 MultiMapConfig (com.hazelcast.config.MultiMapConfig)1