EhCache rmi replication issue in WebLogic cluster - java

I am facing the ehcache replication issue while deploying the application into WebLogic 10.3.6.
Application is not starting and throwing the below exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehCacheManager' defined in class path resource [xxxxx.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Problem starting listener for RMICachePeer //xxxx:xxxx/myCache. Initial cause was RemoteException occurred in server thread; nested exception is:
java.rmi.AccessException: Registry.Registry.rebind disallowed; origin /x.x.x.x is non-local host
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
...
Caused by: net.sf.ehcache.CacheException: Problem starting listener for RMICachePeer //xxxx:xxxx/myCache. Initial cause was RemoteException occurred in server thread; nested exception is:
java.rmi.AccessException: Registry.Registry.rebind disallowed; origin /x.x.x.x is non-local host
at net.sf.ehcache.distribution.RMICacheManagerPeerListener.notifyCacheAdded(RMICacheManagerPeerListener.java:538)
at net.sf.ehcache.event.CacheManagerEventListenerRegistry.notifyCacheAdded(CacheManagerEventListenerRegistry.java:159)
at net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:1118)
at net.sf.ehcache.CacheManager.addConfiguredCaches(CacheManager.java:670)
at net.sf.ehcache.CacheManager.init(CacheManager.java:372)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:294)
at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:104)
...
EhCache configuration is as follows:
<diskStore path="java.io.tmpdir/myCache" />
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,rmiUrls=//x.x.x.x:xxxx/myCache" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=x.x.x.x,port=xxxx,socketTimeoutMillis=300000" />
<cache
name="myCache"
maxElementsInMemory="1000"
eternal="false"
overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="1000"
memoryStoreEvictionPolicy="LRU">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicatePuts=true,replicateUpdates=true,replicateRemovals=true,replicateUpdatesViaCopy=true,replicateAsynchronously=true" />
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
</cache>
Appreciate any help.

I am able to make it working by changing my cache discovery strategy to automatic and multicast.
See the working configuration below:
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
multicastGroupPort=4447, timeToLive=32" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="port=xxxx,socketTimeoutMillis=300000" />
<cache
name="myCache"
maxElementsInMemory="1000"
eternal="false"
overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="1000"
memoryStoreEvictionPolicy="LRU">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>
</cache>

Related

Configuration for enabling Ehcache DiskStore

I referred this for configuring disk store for Ehcache.
Below is my configuration. But this does not seem to work. I do to see any file in d:\cache. Am I missing something ?
<diskStore path="d:\\cache" />
<cache name="cache1"
maxEntriesLocalHeap="10"
maxEntriesLocalDisk="10000"
eternal="false"
diskSpoolBufferSizeMB="20"
timeToIdleSeconds="1" timeToLiveSeconds="2"
memoryStoreEvictionPolicy="FIFO"
transactionalMode="off">
<persistence strategy="localTempSwap" />
</cache>

Error in JGROUPs for EhCache, drop message sender not in table

I have four nodes in a cluster, and I need synchronize them. When node BRJGSD309173 tried send a messages through JGROUPs to BRJGSD333007, the server BRJGSD333007 informed the message below:
11:34:07,759 WARN [org.jgroups.protocols.pbcast.NAKACK] (Incoming-2,maestroCacheManager,BRJGSD333007-24075) BRJGSD333007-24075: dropped message 4787 from BRJGSD309173-7667 (sender not in table [BRJGSD333007-24075]), view=[BRJGSD333007-24075|0] [BRJGSD333007-24075]
The follow configuration of eh jgroups_tcp.xml
<?xml version='1.0'?>
<config>
<TCP bind_port="7800"
max_bundle_size="5M" />
<TCPPING timeout="3000"
initial_hosts="brjgsm10.weg.net[7800],brjgsm11.weg.net[7800],brjgsd309173.weg.net[7800],brjgsd333007.weg.net[7800]"
port_range="10"
num_initial_members="5"/>
<VERIFY_SUSPECT timeout="1500" />
<pbcast.NAKACK use_mcast_xmit="false"
retransmit_timeout="300,600,1200,2400,4800"
discard_delivered_msgs="true"/>
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000" max_bytes="400000"/>
<pbcast.GMS print_local_addr="true" join_timeout="5000" view_bundling="true"/>
</config>
And a fragment of ehcache.xml
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
updateCheck="false" xsi:noNamespaceSchemaLocation="ehcache.xsd" name="maestroCacheManager">
...
<cache
name="objectServiceExecute"
maxEntriesLocalHeap="100000"
eternal="false" >
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" />
</cache>
<diskStore
path="java.io.tmpdir/ehcache" />
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
properties="file=jgroups_tcp.xml"
propertySeparator=";"
/>
<cache
name="org.hibernate.cache.internal.StandardQueryCache"
maxElementsInMemory="10000000"
eternal="true"
memoryStoreEvictionPolicy="LRU" />
<defaultCache
maxElementsInMemory="10000000"
eternal="true"
memoryStoreEvictionPolicy="LRU" >
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" />
</defaultCache>
</ehcache>
This is a very stange JGroups configuration! You're missing failure detection protocols, UNICAST3 and MERFGE3 etc!
The error above means that you received a message from a member not in the cluster, so it was consequently dropped. Why the member was not in the cluster is unclear, perhaps it didn't join correctly. Since you don't have any failure detection protocols, it can't have been suspected and expelled.
I suggest copy tcp.xml shipped with JGroups and replace TCPPING with your TCPPING config. Also make sure you set bind_addr in TCP, to make sure JGroups binds to the correct interface.
Hope this helps,
Cheers

UpdateTimestampsCache not appearing in Terracotta Dev Console

I have configured ehcache for hibernate 2nd level cache to use a Terracotta server. Everything is working fine, except the UpdateTimestampsCache for the query cache is just not showing up in the Dev Console. We are using Hibernate 3.6.10 and ehcache 2.6.0.
I am seeing all entity, collection, query and the StandardQueryCache, but not org.hibernate.cache.UpdateTimestampsCache. I know the timestamp cache exists and is being used because I can see the stats on it using the the metrics lib instrumented in.
Any ideas?
Thanks!
Here's my ehcache.xml config
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false"
name="Hibernate-CacheManager"
monitoring="autodetect"
dynamicConfig="true">
<terracottaConfig url="localhost:9510" />
<defaultCache
eternal="false"
overflowToDisk="false"
maxElementsInMemory="50000"
timeToIdleSeconds="7200"
timeToLiveSeconds="0">
<cacheDecoratorFactory
class="com.yammer.metrics.ehcache.InstrumentedEhcacheFactory" />
<terracotta/>
</defaultCache>
<cache
name="org.hibernate.cache.UpdateTimestampsCache"
eternal="false"
overflowToDisk="false"
maxElementsInMemory="500"
timeToIdleSeconds="7200"
timeToLiveSeconds="0">
<cacheDecoratorFactory
class="com.yammer.metrics.ehcache.InstrumentedEhcacheFactory" />
<terracotta/>
</cache>
<cache
name="org.hibernate.cache.StandardQueryCache"
eternal="false"
overflowToDisk="false"
maxElementsInMemory="50000"
timeToIdleSeconds="7200"
timeToLiveSeconds="0">
<cacheDecoratorFactory
class="com.yammer.metrics.ehcache.InstrumentedEhcacheFactory" />
<terracotta/>
</cache>
</ehcache>
Recopying answer from: http://forums.terracotta.org/forums/posts/list/0/7554.page#36815
Hibernate does not maintain statistics for the UpdateTimestampsCache cache up to Hibernate 4.0.0. This explains why the cache does not show up in the terracotta dev console.
This is filed as bug https://hibernate.onjira.com/browse/HHH-5326

ehcache RMI config to spring

I'm trying to move the creation of Cache that uses RMI from ehcache.xml file to a Spring xml.
It wasn't a problem to just create a EhCacheFactoryBean but how does RMICacheReplicatorFactory definition suppose to/can be implemented?
Here is how it looks in ehcache.xml file.
Many thanks,
Idan
<cache name="MyCache1"
maxElementsInMemory="1000"
eternal="false"
overflowToDisk="true"
diskSpoolBufferSizeMB="20"
timeToLiveSeconds="3000"
timeToIdleSeconds="3000"
memoryStoreEvictionPolicy="LFU">
<!-- RMI replication listener -->
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true,
replicatePuts=true,
replicatePutsViaCopy=true,
replicateUpdates=true,
replicateUpdatesViaCopy=true,
replicateRemovals=true" />
<!-- RMI Cache bootstrap -->
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"
propertySeparator="," />
</cache>
When using Spring 3 there is a cacheEventListeners property of type Set<CacheEventListener> for the EhCacheFactoryBean (see https://jira.springsource.org/browse/SPR-6234). When using 2.5 you could extend EhCacheFactoryBean yourself like shown here.

Adding JMS Info breaks EhCache

I want to distribute my EhCache via a JMS Topic. This is documented here on EhCache's site
I'm using:
ehcache-1.6.0-beta3
ehcache-jmsreplication-0.3
spring-2.5
spring-modules-0.9
My Spring config looks like this:
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
</bean>
<bean id="cacheProvider"
class="org.springmodules.cache.provider.ehcache.EhCacheFacade">
<property name="cacheManager" ref="cacheManager" />
</bean>
<ehcache:proxy id="pocDaoCache" refId="pocDao">
<ehcache:caching methodName="fetch" cacheName="pocCache" />
</ehcache:proxy>
And, pre-JMS config, my ehcache.xml looks like this:
<diskStore path="c:/projects/cache/demo" />
<defaultCache maxElementsInMemory="50" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" />
<cache name="pocCache"
maxElementsInMemory="10000"
maxElementsOnDisk="1000"
eternal="false"
overflowToDisk="true"
diskSpoolBufferSizeMB="20"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
/ >
And this works fine. So I add my Topic information:
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory"
properties="initialContextFactoryName=JmsInitialContextFactory,
userName=myuser,password=mypass,
providerURL=tcp://jmsdev1-jndi,tcp://jmsdev2-jndi
topicConnectionFactoryBindingName=TCF-00,
topicBindingName=MyTopiceName"
propertySeparator=","
/>
And I get a NullPointer when I get an application context. Here is the stack trace:
org.springframework.beans.factory.BeanCreationException:
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'cacheManager' defined in class path resource [cache-context.xml]:
Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:217)
[snip]
Any ideas from anyone?
The real problem is that Ehcache's documentation isn't right -- not even close -- to how it is really implemented. Through logging and looking through the code in the jmsreplication module, I was able to get it working.
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory"
properties="initialContextFactoryName=com.InitialContextFactory;
userName=uname;password=passwd;
replicationTopicConnectionFactoryBindingName=TCF;
replicationTopicBindingName=CACHE;
providerURL=tcp://server1:7222,tcp://server2:7222;
getQueueConnectionFactoryBindingName=QCF;
getQueueBindingName=CACHE_LOAD
"
propertySeparator=";"
/>
Another thing that tripped me up was simple, once I realized it -- you have to implement your own key generator to ensure that Ehcache saves the objects with the same keys on each JVM. That makes perfect sense, when you think about it.
Yes, you have to put in the loader queue information into the cacheManagerPeerProviderFactory. That is because, if you start up a process after one has been running, the new process can pre-load the cache from the existing process.
You configure the loader requester (cacheLoaderFactory) with the exact same settings:
<cacheLoaderFactory
class="net.sf.ehcache.distribution.jms.JMSCacheLoaderFactory"
properties="initialContextFactoryName=com.InitialContextFactory;
userName=uname;password=passwd;
replicationTopicConnectionFactoryBindingName=TCF;
replicationTopicBindingName=CACHE;
providerURL=tcp://server1:7222,tcp://server2:7222;
getQueueConnectionFactoryBindingName=QCF;
getQueueBindingName=CACHE_LOAD
"
propertySeparator=";"
/>
Regarding the key generation issue, it's actually a known problem - MOD-255. We are going to be patching that into the Spring Modules Fork shortly.

Categories

Resources