We were using Ignite 2.4 (update pending). Ignite 2.5 and later seens to
treat OOM as a critical error by default and stops the node. The reproducer
below uses a failure handler to stop this from happening. It allocates a
100MB (configurable - 100MB is quite small) region and fills it up with
data. Afterwards, it attempts to clear data from the cache. Every cache
operation (even data removal) results in OOM errors.

package mytest;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.DataRegionConfiguration;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.failure.NoOpFailureHandler;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.junit.Test;

import javax.cache.CacheException;

public class MemoryTest {

    private static final String CACHE_NAME = "cache";
    private static final Logger logger =
LogManager.getLogger(MemoryTest.class);
    private static final String DEFAULT_MEMORY_REGION = "Default_Region";

    private static final String I1_NAME = "IgniteMemoryMonitorTest1";

    private static final long MEM_SIZE = 100L * 1024 * 1024;



    @Test
    public void testOOM() {
        try (Ignite ignite = startIgnite(I1_NAME)) {
            fillDataRegion(ignite);
            IgniteCache<Object, Object> cache =
ignite.getOrCreateCache(CACHE_NAME);

            // Clear all entries from the cache to free up memory
            cache.clear();      // Fails here
            cache.put("Key", "Value");
        }
    }


    private Ignite startIgnite(String instanceName) {
        IgniteConfiguration cfg = new IgniteConfiguration();
        cfg.setIgniteInstanceName(instanceName);
        cfg.setDataStorageConfiguration(createDataStorageConfiguration());
        cfg.setFailureHandler(new NoOpFailureHandler());
        return Ignition.start(cfg);
    }

    private DataStorageConfiguration createDataStorageConfiguration() {
        return new DataStorageConfiguration()
                .setDefaultDataRegionConfiguration(
                        new DataRegionConfiguration()
                                .setName(DEFAULT_MEMORY_REGION)
                                .setInitialSize(MEM_SIZE)
                                .setMaxSize(MEM_SIZE)
                                .setMetricsEnabled(true));
    }



    private void fillDataRegion(Ignite ignite) {
        byte[] megabyte = new byte[1024 * 1024];

        int storedDataMB = 0;
        try {
            IgniteCache<Object, Object> cache =
ignite.getOrCreateCache(CACHE_NAME);
            for (int i = 0; i < 200; i++) {
                cache.put(i, megabyte);
                storedDataMB++;
            }
        } catch (CacheException e) {
            logger.info("Out of memory: " + e.getClass().getSimpleName() + "
after " + storedDataMB + "MB", e);
        }
    }
}




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Reply via email to