Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-9868, HHH-9881 Must not write into non-transactional caches durin…
…g transactional write * The write can only invalidate (remove) the entry and block further PFERs of that entry * After successful DB update, if there have not been any concurrent updates the value can be PFERed into the cache
- Loading branch information
Showing
17 changed files
with
423 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...src/main/java/org/hibernate/cache/infinispan/access/NonTxTransactionalAccessDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,86 @@ | |||
/* | |||
* Hibernate, Relational Persistence for Idiomatic Java | |||
* | |||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | |||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | |||
*/ | |||
package org.hibernate.cache.infinispan.access; | |||
|
|||
import org.hibernate.cache.CacheException; | |||
import org.hibernate.cache.infinispan.impl.BaseRegion; | |||
import org.hibernate.engine.spi.SessionImplementor; | |||
import org.hibernate.resource.transaction.TransactionCoordinator; | |||
import org.hibernate.resource.transaction.spi.TransactionStatus; | |||
|
|||
/** | |||
* Delegate for non-transactional caches | |||
* | |||
* @author Radim Vansa <rvansa@redhat.com> | |||
*/ | |||
public class NonTxTransactionalAccessDelegate extends TransactionalAccessDelegate { | |||
public NonTxTransactionalAccessDelegate(BaseRegion region, PutFromLoadValidator validator) { | |||
super(region, validator); | |||
} | |||
|
|||
@Override | |||
@SuppressWarnings("UnusedParameters") | |||
public boolean insert(SessionImplementor session, Object key, Object value, Object version) throws CacheException { | |||
if ( !region.checkValid() ) { | |||
return false; | |||
} | |||
|
|||
// We need to be invalidating even for regular writes; if we were not and the write was followed by eviction | |||
// (or any other invalidation), naked put that was started after the eviction ended but before this insert | |||
// ended could insert the stale entry into the cache (since the entry was removed by eviction). | |||
if ( !putValidator.beginInvalidatingWithPFER(session, key, value)) { | |||
throw new CacheException( | |||
"Failed to invalidate pending putFromLoad calls for key " + key + " from region " + region.getName() | |||
); | |||
} | |||
putValidator.setCurrentSession(session); | |||
try { | |||
writeCache.remove(key); | |||
} | |||
finally { | |||
putValidator.resetCurrentSession(); | |||
} | |||
return true; | |||
} | |||
|
|||
@Override | |||
@SuppressWarnings("UnusedParameters") | |||
public boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) | |||
throws CacheException { | |||
// We update whether or not the region is valid. Other nodes | |||
// may have already restored the region so they need to | |||
// be informed of the change. | |||
|
|||
// We need to be invalidating even for regular writes; if we were not and the write was followed by eviction | |||
// (or any other invalidation), naked put that was started after the eviction ended but before this update | |||
// ended could insert the stale entry into the cache (since the entry was removed by eviction). | |||
if ( !putValidator.beginInvalidatingWithPFER(session, key, value)) { | |||
throw new CacheException( | |||
"Failed to invalidate pending putFromLoad calls for key " + key + " from region " + region.getName() | |||
); | |||
} | |||
putValidator.setCurrentSession(session); | |||
try { | |||
writeCache.remove(key); | |||
} | |||
finally { | |||
putValidator.resetCurrentSession(); | |||
} | |||
return true; | |||
} | |||
|
|||
@Override | |||
public void unlockItem(SessionImplementor session, Object key) throws CacheException { | |||
TransactionCoordinator tc = session.getTransactionCoordinator(); | |||
boolean doPFER = tc != null && tc.getTransactionDriverControl().getStatus() == TransactionStatus.COMMITTED; | |||
if ( !putValidator.endInvalidatingKey(session, key, doPFER) ) { | |||
// TODO: localization | |||
log.warn("Failed to end invalidating pending putFromLoad calls for key " + key + " from region " | |||
+ region.getName() + "; the key won't be cached until invalidation expires."); | |||
} | |||
} | |||
} |
Oops, something went wrong.