Bug 990587

Summary: [HHH-7959] Hibernate/Infinispan 2nd Level Caches set to transaction-mode=NONE stop functioning after an explicit eviction
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: csams
Component: HibernateAssignee: Brett Meyer <brmeyer>
Status: CLOSED CURRENTRELEASE QA Contact: Zbyněk Roubalík <zroubali>
Severity: high Docs Contact: Russell Dickenson <rdickens>
Priority: unspecified    
Version: 6.0.1CC: lcosti, theute
Target Milestone: ER1   
Target Release: EAP 6.2.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
An Infinispan second-level cache configured with `transaction-mode=NONE` would be invalidated when programmatically forcing an eviction. This invalid state would result in performance degradation, and TRACE level log messages of `Could not invalidate region: null`. This issue was caused by unhandled null values related to attempting to use a TransactionManager in a non-transactional configuration, resulting in NullPointerExceptions. This issue has been fixed in this release of JBoss EAP 6 so that proper null checks now allow the eviction and valid state to occur. As a result, programmatically forcing an eviction on an Infinispan second-level cache configured with `transaction-mode=NONE` will no longer trigger an invalid state and associated performance degradation.
Story Points: ---
Clone Of:
: 990594 (view as bug list) Environment:
Last Closed: 2013-12-15 16:12:47 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 990594, 999686    

Description csams 2013-07-31 13:41:47 UTC
Description of problem:
The caches in the 'infinispan' subsystem configured with <transaction mode="NONE"/> (which results in no transaction used by 2LC) get stuck in state= CLEARING when you perform a programmatic evict() on them to clear the caches. (Using e.g. em.getEntityManagerFactory().getCache().evictAll() or the evict* from the Cache gotten from the SessionFactory)
The problem seem to lie within the class 'org.hibernate.cache.infinispan.impl.BaseRegion, where the 'checkValid' method fails to clear the cache (and set back the state to VALID). The reason it fails is because it calls: cacheAdapter.withinTx(), which in turn tries to get the TransactionManager from the cache (which seems to be null for these non-transactional caches), and then NPEs on the tm.begin(); The NPE is caught and logs out (TRACE in org.hibernate.cache.infinispan.impl.BaseRegion) "Could not invalidate region: null", and never set the state in VALID. So from thereon the caches are in an Invalid state and are not used anymore by Infinispan, thus leading to much performance degradation.

Version-Release number of selected component (if applicable):
EAP 6.0.1 / Hibernate 4.1.3

How reproducible:
Always

Steps to Reproduce:
0. Set org.hibernate.cache logging category to TRACE.
1. Execute a cacheable query with cacheable entities.
2. Execute all of the evict* methods:
		HibernateEntityManagerFactory hEmf = (HibernateEntityManagerFactory)em.getEntityManagerFactory();
		Cache cache = hEmf.getSessionFactory().getCache();
		cache.evictEntityRegions();
		cache.evictCollectionRegions();
		cache.evictDefaultQueryRegion();
		cache.evictQueryRegions();
3. Execute the query again.

Actual results:
See "Could not invalidate region: null" at TRACE level in the logs, and the query cache stops working.

Expected results:
No trace level message

Additional info:

Comment 1 Brett Meyer 2013-08-20 15:19:55 UTC
Fix pushed to http://git.app.eng.bos.redhat.com/?p=hibernate/hibernate-core.git;a=shortlog;h=refs/heads/eap61-cp-updates, but EAP 6.2.0 should have a Hibernate upgrade anyway.

Comment 2 Zbyněk Roubalík 2013-09-23 11:21:11 UTC
EAP 6.2.0.ER1