Search in sources :

Example 1 with Evictor

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;
}
Also used : NativeOutOfMemoryError(com.hazelcast.memory.NativeOutOfMemoryError) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) ILogger(com.hazelcast.logging.ILogger) Evictor(com.hazelcast.map.impl.eviction.Evictor) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 2 with Evictor

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;
}
Also used : NativeOutOfMemoryError(com.hazelcast.memory.NativeOutOfMemoryError) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) ILogger(com.hazelcast.logging.ILogger) Evictor(com.hazelcast.map.impl.eviction.Evictor)

Example 3 with Evictor

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);
}
Also used : EvictionChecker(com.hazelcast.map.impl.eviction.EvictionChecker) IPartitionService(com.hazelcast.internal.partition.IPartitionService) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) MemoryInfoAccessor(com.hazelcast.internal.util.MemoryInfoAccessor) MapService(com.hazelcast.map.impl.MapService) Evictor(com.hazelcast.map.impl.eviction.Evictor) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer)

Aggregations

Evictor (com.hazelcast.map.impl.eviction.Evictor)3 ILogger (com.hazelcast.logging.ILogger)2 MapContainer (com.hazelcast.map.impl.MapContainer)2 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)2 NativeOutOfMemoryError (com.hazelcast.memory.NativeOutOfMemoryError)2 IPartitionService (com.hazelcast.internal.partition.IPartitionService)1 MemoryInfoAccessor (com.hazelcast.internal.util.MemoryInfoAccessor)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1 EvictionChecker (com.hazelcast.map.impl.eviction.EvictionChecker)1 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)1