Ehcache初始表分配失败

时间:2018-03-12 09:16:03

标签: java ehcache

我们的一个Web应用程序在Tomcat 7中运行,它部署在AS400服务器上,它使用Ehcache作为缓存组件交换数据到磁盘并减少内存使用。

几周前,当我们尝试为我们的某个客户部署此应用程序时,它在启动时失败。日志显示:

Caused by: java.lang.IllegalStateException: Cache 'data' creation in EhcacheManager failed.        
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:288)                           
at org.ehcache.core.EhcacheManager.init(EhcacheManager.java:567)                                                            
... 7 more                                                                                                                  
Caused by: org.ehcache.StateTransitionException: Initial table allocation failed.                                            
Initial Table Size (slots) : 64                                                                                              
Allocation Will Require    : 1KB                                                                                             
Table Page Source        : org.terracotta.offheapstore.disk.paging.MappedPageSource@bc8a4ca2                                 
at org.ehcache.core.StatusTransitioner$Transition.succeeded(StatusTransitioner.java:209)                                    
at org.ehcache.core.Ehcache.init(Ehcache.java:567)                                                                          
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:261)                                                     
... 8 more    
Caused by: java.lang.IllegalArgumentException: Initial table allocation failed.                                              
Initial Table Size (slots) : 64                                                                                              
Allocation Will Require    : 1KB                                                                                             
Table Page Source        : org.terracotta.offheapstore.disk.paging.MappedPageSource@bc8a4ca2                                 
at org.terracotta.offheapstore.OffHeapHashMap.<init>(OffHeapHashMap.java:219)                                               
at org.terracotta.offheapstore.AbstractLockedOffHeapHashMap.<init>(AbstractLockedOffHeapHashMap.java:71)                    
at org.terracotta.offheapstore.AbstractOffHeapClockCache.<init>(AbstractOffHeapClockCache.java:76)                          
at org.terracotta.offheapstore.disk.persistent.AbstractPersistentOffHeapCache.<init>(AbstractPersistentOffHeapCache.java:43)
at org.terracotta.offheapstore.disk.persistent.PersistentReadWriteLockedOffHeapClockCache.<init>(PersistentReadWriteLockedOffHeapClockCache.java:36)
at org.ehcache.impl.internal.store.disk.factories.EhcachePersistentSegmentFactory$EhcachePersistentSegment.<init>(EhcachePersistentSegmentFactory.java:73)
at org.ehcache.impl.internal.store.disk.factories.EhcachePersistentSegmentFactory.newInstance(EhcachePersistentSegmentFactory.java:60)
at org.ehcache.impl.internal.store.disk.factories.EhcachePersistentSegmentFactory.newInstance(EhcachePersistentSegmentFactory.java:37)
at org.terracotta.offheapstore.concurrent.AbstractConcurrentOffHeapMap.<init>(AbstractConcurrentOffHeapMap.java:106)               
at org.terracotta.offheapstore.concurrent.AbstractConcurrentOffHeapCache.<init>(AbstractConcurrentOffHeapCache.java:48)            
at org.terracotta.offheapstore.disk.persistent.AbstractPersistentConcurrentOffHeapCache.<init>(AbstractPersistentConcurrentOffHeapCache.java:52) 
at org.ehcache.impl.internal.store.disk.EhcachePersistentConcurrentOffHeapClockCache.<init>(EhcachePersistentConcurrentOffHeapClockCache.java:52)
at org.ehcache.impl.internal.store.disk.OffHeapDiskStore.createBackingMap(OffHeapDiskStore.java:279)                               
at org.ehcache.impl.internal.store.disk.OffHeapDiskStore.getBackingMap(OffHeapDiskStore.java:167)                                  
at org.ehcache.impl.internal.store.disk.OffHeapDiskStore.access$600(OffHeapDiskStore.java:95)                                      
at org.ehcache.impl.internal.store.disk.OffHeapDiskStore$Provider.init(OffHeapDiskStore.java:460)                                  
at org.ehcache.impl.internal.store.disk.OffHeapDiskStore$Provider.initStore(OffHeapDiskStore.java:456)                             
at org.ehcache.impl.internal.store.disk.OffHeapDiskStore$Provider.initAuthoritativeTier(OffHeapDiskStore.java:507)                 
at org.ehcache.impl.internal.store.tiering.TieredStore$Provider.initStore(TieredStore.java:472)                                    
at org.ehcache.core.EhcacheManager$8.init(EhcacheManager.java:499)                                                                 
at org.ehcache.core.StatusTransitioner.runInitHooks(StatusTransitioner.java:135)                                                   
at org.ehcache.core.StatusTransitioner.access$000(StatusTransitioner.java:33)                                                      
at org.ehcache.core.StatusTransitioner$Transition.succeeded(StatusTransitioner.java:194) 

这个代码触发了这个:

CacheConfiguration<String, String[]> dconf = CacheConfigurationBuilder
      .newCacheConfigurationBuilder(String.class, String[].class, ResourcePoolsBuilder.heap(11) 
      .disk(3, MemoryUnit.GB, false))
      .withExpiry(Expirations.timeToLiveExpiration(Duration.of(30, TimeUnit.MINUTES)))
      .build();
dataCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
      .with(CacheManagerBuilder.persistence(new File(cacheFolder, "requestdata"))) //$NON-NLS-1$
      .withCache(CACHE_NAME_DATA,dconf)
      .build(true); 

让我们感到惊讶,因为它以前从未发生过,我们已经将它部署到其他客户的服务器(Windows,As400,linux),但没有一个有这个问题。

这真是令人头痛,我们花了几周的时间试图弄明白,阅读源代码,调整jvm参数,谷歌搜索...,除了一个未答复的帖子之外什么都没有:https://groups.google.com/forum/#!topic/ehcache-users/ApFAe5nYxuA

有人可以帮我们一个吗?谢谢你!

1 个答案:

答案 0 :(得分:0)

Ehcache 3磁盘存储使用java.nio.MappedByteBuffer,需要访问直接内存。

Java中没有记录的默认MaxDirectMemorySize,不同操作系统上的相同JVM可能表现不同。

如果您在启动应用程序时尚未设置标记-XX:MaxDirectMemorySize=3G,则可能是您看到该异常的原因。