ehcache / ehcache3

Ehcache 3.x line
http://www.ehcache.org
Apache License 2.0
2.02k stars 580 forks source link

OutOfMemoryError in Persistent Cache #3183

Open FlareBlitzV opened 1 year ago

FlareBlitzV commented 1 year ago

I am trying to dump the data from a heap(in memory) cache to disk cache via iterator, this happens every 30 mins. While trying to do that getting Out of Memory. Not sure if this is due to cache corruption. Once the OutOfMemoryError occurs, the program restarts and while the cache initialized there is no error. But when the data is fetched from the cache OutOfMemoryError is thrown again. Note: Both heap and disk cache are created with ehcache as two separate caches.

Ehcache Version: 3.8.1 OS: Windows 10 JDK: ZuluJDK_8_0_322

Cache Configuration:

persistentCacheManager = (PersistentCacheManager) CacheManagerBuilder.newCacheManagerBuilder() .with(CacheManagerBuilder .persistence(ehCacheData.getDiskStoragePath())) .withCache(ehCacheData.getCacheName(), CacheConfigurationBuilder .newCacheConfigurationBuilder(String.class, ArrayList.class, ResourcePoolsBuilder.newResourcePoolsBuilder() .disk(450L, MemoryUnit.MB, true))) .build(true);

Code Snippet: Iterator<Cache.Entry<String, ArrayList>> iterator = heapCache.iterator(); while (iterator.hasNext()) { Cache.Entry entry = (Cache.Entry)iterator.next(); diskCache.put(entry.getKey(),entry.getValue()); } heapCache.clear();

Exception Stack trace: Failed to allocate direct buffer for FileChannel read. Consider increasing the -XX:MaxDirectMemorySize property to allow enough space for the FileChannel transfer buffers| Failed to allocate direct buffer for FileChannel read. Consider increasing the -XX:MaxDirectMemorySize property to allow enough space for the FileChannel transfer buffers| OutOfMemoryError Occurred::java.lang.OutOfMemoryError: Java heap space| Thread::Thread[AnalyticsCacheDumpThread,5,main]|

Found the below exception later while trying print the data from the disk cache: Ehcache key xxxxxxxxxxxx.xxxxxx-x-x-xx-xxxxxxxxxx-xxxxxxxxx-xxxxxxxxxx-xxxx in possible inconsistent state - Similar messages will be suppressed for 30 seconds| org.ehcache.spi.resilience.StoreAccessException: java.lang.RuntimeException: java.io.EOFException at org.ehcache.core.exceptions.StorePassThroughException.handleException(StorePassThroughException.java:78) at org.ehcache.impl.internal.store.offheap.AbstractOffHeapStore.internalGet(AbstractOffHeapStore.java:211) at org.ehcache.impl.internal.store.offheap.AbstractOffHeapStore.containsKey(AbstractOffHeapStore.java:219) at org.ehcache.core.EhcacheBase.containsKey(EhcacheBase.java:220) XXXXXXXXXXXX...........................................

Caused by: java.lang.RuntimeException: java.io.EOFException at org.ehcache.shadow.org.terracotta.offheapstore.disk.storage.FileBackedStorageEngine$FileChunk.readBuffer(FileBackedStorageEngine.java:601) at org.ehcache.shadow.org.terracotta.offheapstore.disk.storage.FileBackedStorageEngine$FileChunk.readKeyBuffer(FileBackedStorageEngine.java:534) at org.ehcache.shadow.org.terracotta.offheapstore.disk.storage.FileBackedStorageEngine.readKeyBuffer(FileBackedStorageEngine.java:265) at org.ehcache.shadow.org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine.equalsKey(PortabilityBasedStorageEngine.java:125) at org.ehcache.shadow.org.terracotta.offheapstore.OffHeapHashMap.keyEquals(OffHeapHashMap.java:1005) at org.ehcache.shadow.org.terracotta.offheapstore.OffHeapHashMap.computeIfPresentWithMetadata(OffHeapHashMap.java:2101) at org.ehcache.shadow.org.terracotta.offheapstore.AbstractLockedOffHeapHashMap.computeIfPresentWithMetadata(AbstractLockedOffHeapHashMap.java:542) at org.ehcache.shadow.org.terracotta.offheapstore.concurrent.AbstractConcurrentOffHeapMap.computeIfPresentWithMetadata(AbstractConcurrentOffHeapMap.java:781) at org.ehcache.impl.internal.store.disk.EhcachePersistentConcurrentOffHeapClockCache.computeIfPresent(EhcachePersistentConcurrentOffHeapClockCache.java:175) at org.ehcache.impl.internal.store.offheap.AbstractOffHeapStore.internalGet(AbstractOffHeapStore.java:184) ... 11 more Caused by: java.io.EOFException at org.ehcache.shadow.org.terracotta.offheapstore.disk.storage.FileBackedStorageEngine$FileChunk.readBuffer(FileBackedStorageEngine.java:594) ... 20 more

Kindly help me regarding this. Thank you.

FlareBlitzV commented 1 year ago

Is there any chance that the cache was corrupted due to antivirus and is causing the following exception. Can anyone help me regarding this. Thank you