use of com.hazelcast.map.impl.eviction.Evictor in project hazelcast by hazelcast.
the class MultipleRecordStoreForcedEviction method forceEvictAndRun.
@Override
public boolean forceEvictAndRun(MapOperation mapOperation, double evictionPercentage) {
assert evictionPercentage > 0 && evictionPercentage <= 1;
int partitionCount = numberOfPartitions(mapOperation);
int threadCount = threadCount(mapOperation);
int mod = mod(mapOperation, threadCount);
ILogger logger = mapOperation.logger();
int evictionRetryTimes = retryCount(evictionPercentage);
for (int i = 0; i < evictionRetryTimes; i++) {
try {
for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
if ((partitionId % threadCount) != mod) {
continue;
}
Collection<RecordStore> recordStores = partitionMaps(mapOperation, partitionId).values();
for (RecordStore recordStore : recordStores) {
// used for logging
int sizeBeforeEviction = recordStore.size();
MapContainer mapContainer = recordStore.getMapContainer();
Evictor evictor = mapContainer.getEvictor();
evictor.forceEvictByPercentage(recordStore, evictionPercentage);
if (logger.isFineEnabled()) {
logForcedEviction(logger, mapOperation, recordStore, evictionPercentage, (i + 1), sizeBeforeEviction);
}
}
}
mapOperation.runInternal();
return true;
} catch (NativeOutOfMemoryError e) {
// see #retryCount javaDoc
if (evictionPercentage == 1D) {
throw e;
} else {
ignore(e);
}
}
}
return false;
}
use of com.hazelcast.map.impl.eviction.Evictor in project hazelcast by hazelcast.
the class SingleRecordStoreForcedEviction method forceEvictAndRun.
@Override
public boolean forceEvictAndRun(MapOperation mapOperation, double evictionPercentage) {
assert evictionPercentage > 0 && evictionPercentage <= 1;
RecordStore recordStore = mapOperation.recordStore;
if (!ForcedEviction.isValid(recordStore)) {
return false;
}
ILogger logger = mapOperation.logger();
int retryCount = retryCount(evictionPercentage);
for (int i = 0; i < retryCount; i++) {
if (logger.isFineEnabled()) {
if (logger.isFineEnabled()) {
String msg = "Single record store forced eviction [attemptNumber: %d, mapName: %s, " + "evictionPercentage:%.2f, partitionId: %d]";
logger.fine(format(msg, (i + 1), mapOperation.getName(), evictionPercentage, mapOperation.getPartitionId()));
}
}
try {
Evictor evictor = recordStore.getMapContainer().getEvictor();
evictor.forceEvictByPercentage(recordStore, evictionPercentage);
mapOperation.runInternal();
return true;
} catch (NativeOutOfMemoryError e) {
ignore(e);
}
}
return false;
}
use of com.hazelcast.map.impl.eviction.Evictor in project hazelcast by hazelcast.
the class EvictionMaxSizePolicyTest method setMockRuntimeMemoryInfoAccessor.
public static void setMockRuntimeMemoryInfoAccessor(IMap map, final long totalMemoryMB, final long freeMemoryMB, final long maxMemoryMB) {
final MapProxyImpl mapProxy = (MapProxyImpl) map;
final MapService mapService = (MapService) mapProxy.getService();
final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
MemoryInfoAccessor memoryInfoAccessor = new MemoryInfoAccessor() {
@Override
public long getTotalMemory() {
return MEGABYTES.toBytes(totalMemoryMB);
}
@Override
public long getFreeMemory() {
return MEGABYTES.toBytes(freeMemoryMB);
}
@Override
public long getMaxMemory() {
return MEGABYTES.toBytes(maxMemoryMB);
}
};
MapContainer mapContainer = mapServiceContext.getMapContainer(map.getName());
EvictionChecker evictionChecker = new EvictionChecker(memoryInfoAccessor, mapServiceContext);
IPartitionService partitionService = mapServiceContext.getNodeEngine().getPartitionService();
Evictor evictor = new TestEvictor(LRUEvictionPolicyComparator.INSTANCE, evictionChecker, partitionService);
mapContainer.setEvictor(evictor);
}
Aggregations