Search in sources :

Example 1 with NativeOutOfMemoryError

use of com.hazelcast.memory.NativeOutOfMemoryError 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 NativeOutOfMemoryError

use of com.hazelcast.memory.NativeOutOfMemoryError in project hazelcast by hazelcast.

the class MapOperation method logError.

@Override
public void logError(Throwable e) {
    ILogger logger = getLogger();
    if (e instanceof NativeOutOfMemoryError) {
        Level level = this instanceof BackupOperation ? Level.FINEST : Level.WARNING;
        logger.log(level, "Cannot complete operation! -> " + e.getMessage());
    } else {
        // we need to introduce a proper method to handle operation failures (at the moment
        // this is the only place where we can dispose native memory allocations on failure)
        disposeDeferredBlocks();
        super.logError(e);
    }
}
Also used : NativeOutOfMemoryError(com.hazelcast.memory.NativeOutOfMemoryError) ILogger(com.hazelcast.logging.ILogger) Level(java.util.logging.Level) BackupOperation(com.hazelcast.spi.impl.operationservice.BackupOperation)

Example 3 with NativeOutOfMemoryError

use of com.hazelcast.memory.NativeOutOfMemoryError 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)

Aggregations

ILogger (com.hazelcast.logging.ILogger)3 NativeOutOfMemoryError (com.hazelcast.memory.NativeOutOfMemoryError)3 Evictor (com.hazelcast.map.impl.eviction.Evictor)2 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)2 MapContainer (com.hazelcast.map.impl.MapContainer)1 BackupOperation (com.hazelcast.spi.impl.operationservice.BackupOperation)1 Level (java.util.logging.Level)1