Infinispan not evicting entities from named cache
_rob_jboss Nov 10, 2011 6:28 AMI have recently migrated from JBoss 4.2 to 6 and as a result from JBoss Cache to Infinispan. I followed this article - https://docs.jboss.org/author/display/ISPN/Using+Infinispan+as+JPA-Hibernate+Second+Level+Cache+Provider to set caching up.
I'm getting problems when it comes to infinispan evicting/updating cached entities. This is best described in steps:
1) Request is made for all incident entities
2) Incidents are placed into the entity-repeatable cache (NumberOfEntries=17 in the JMX infinispan stats)
3) One query is placed into the local-query cache (NumberOfEntries=1 in the JMX infinispan stats)
4) Another request is made for all incident entities (which are retrived from the cache)
5) 5 seconds pass and the entities are still in the cache (according to the JMX infinispan stats)
6) 10 seconds pass and the query is removed from the cache (according to the JMX infinispan stats)
7) All incidents are updated within the database
8) Another request is made for all incident entities
9) New incidents are returned.
10) Another request is _immediately_ made and the old incidents are returned. (Hits=17 in the JMX infinispan stats)
The new incidents are only returned after the cached query is evicted and therefore a call is made to the database.
No matter what value I define for the expiration life span (under the named cache entity-repeatable), the entities are never evicted. At the same time the named cache local-query evicts queries as expected. Weirdly, if I place the entities in the local-query cache, neither the entities nor the queries are evicted!
I'm using:
Java 1.6
JBoss-6.0.0.Final
Hibernate 3.6.0.Final
Hibernate Commons Annotations 3.2.0.Final
Infinispan 4.2.0.FINAL
Single JBoss node running on Windows XP Pro
My questions are:
1) Why aren't the entitles being evicted/updated?
2) Is it possible to turn on extra infinispan logging to see what evictions are taking place, if any?
Any help in resolving this would be very much appreciated.
Thanks,
Rob.
Persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="PersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/MSSQLDS</jta-data-source>
<jar-file>Project6-ejb.jar</jar-file>
<properties>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"/>
<property name="hibernate.cache.infinispan.cachemanager" value="java:CacheManager/entity"/>
<property name="hibernate.cache.region_prefix" value="Project6"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"/>
<property name="hibernate.cache.infinispan.statistics" value="true"/>
</properties>
</persistence-unit>
</persistence>
Entity example with cache region references
@Entity
@Table(name = "Incident")
@NamedQueries({
@NamedQuery(name = "Incident.findAll",
query = "SELECT i FROM Incident i",
hints = {
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
@QueryHint(name = "org.hibernate.cacheRegion", value = "local-query")})
})
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "entity-repeatable")
public class Incident implements Serializable {
// usual entity code here
}
infinispan-config.xml (hibernate part only)
<!-- Hibernate second-level cache -->
<infinispan-config name="hibernate" jndi-name="java:CacheManager/entity">
<infinispan xmlns="urn:infinispan:config:4.2">
<global>
<transport clusterName="${jboss.partition.name:DefaultPartition}-Hibernate" distributedSyncTimeout="17500">
<properties>
<property name="stack" value="${jboss.default.jgroups.stack:udp}"/>
</properties>
</transport>
<globalJmxStatistics enabled="true"/>
<shutdown hookBehavior="DONT_REGISTER"/>
</global>
<default>
<!-- Used to register JMX statistics in any available MBean server -->
<jmxStatistics enabled="true"/>
<!--transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.JBossTransactionManagerLookup"/-->
</default>
<!-- Default configuration is appropriate for entity/collection caching. -->
<namedCache name="entity-repeatable">
<clustering mode="invalidation">
<stateRetrieval fetchInMemoryState="false" timeout="20000"/>
<sync replTimeout="20000"/>
</clustering>
<!-- Note: REPEATABLE_READ is only useful if the application evicts/clears entities
from the Hibernate Session and then expects to repeatably re-read them in
the same transaction. Otherwise, the Session's internal cache provides a
repeatable-read semantic. Before choosing this config, carefully read the docs
and make sure you really need REPEATABLE_READ.
-->
<locking isolationLevel="REPEATABLE_READ" concurrencyLevel="1000"
lockAcquisitionTimeout="15000" useLockStriping="false"/>
<!-- Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds.
0 means the eviction thread will never run. A separate executor is used for eviction in each cache. -->
<eviction wakeUpInterval="1000" maxEntries="10000" strategy="FIFO"/>
<expiration maxIdle="-1" lifespan="5000"/>
<lazyDeserialization enabled="true"/>
</namedCache>
<!-- A config appropriate for query caching. Does not replicate queries. -->
<namedCache name="local-query"><!-- Non-replicating query cache -->
<locking isolationLevel="READ_COMMITTED" concurrencyLevel="1000"
lockAcquisitionTimeout="15000" useLockStriping="false"/>
<!--Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds. 0 means
the eviction thread will never run. A separate executor is used for eviction in each cache. -->
<eviction wakeUpInterval="1000" maxEntries="10000" strategy="FIFO"/>
<expiration maxIdle="-1" lifespan="10000"/>
</namedCache>
<!-- Optimized for timestamp caching. -->
<!-- A clustered timestamp cache is required if query caching is used, even if the query cache itself is configured with CacheMode=LOCAL. -->
<namedCache name="timestamps">
<clustering mode="replication">
<stateRetrieval fetchInMemoryState="true" timeout="20000"/>
<async/>
</clustering>
<locking isolationLevel="READ_COMMITTED" concurrencyLevel="1000"
lockAcquisitionTimeout="15000" useLockStriping="false"/>
<!-- Don't ever evict modification timestamps -->
<eviction wakeUpInterval="0" strategy="NONE"/>
<lazyDeserialization enabled="true"/>
</namedCache>
</infinispan>
</infinispan-config>