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"));
}
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());
}
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 + ']');
}
}
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);
}
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);
}
Aggregations