Skip to content

Commit 4b2a787

Browse files
rvansagalderz
authored andcommitted
HHH-9868 Infinispan 2LC can store stale data
* invalidation blocks putFromLoads until the transaction with invalidation is committed * rewritten the naked puts support: timestamp is stored in the pendingPutMap and removal of the record relies on pending puts' idle expiration or piggy-backs on release from putFromLoad
1 parent fa8e940 commit 4b2a787

File tree

11 files changed

+562
-377
lines changed

11 files changed

+562
-377
lines changed

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/access/PutFromLoadValidator.java

Lines changed: 207 additions & 223 deletions
Large diffs are not rendered by default.

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/access/TransactionalAccessDelegate.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.hibernate.cache.CacheException;
1010
import org.hibernate.cache.infinispan.impl.BaseRegion;
1111
import org.hibernate.cache.infinispan.util.Caches;
12-
1312
import org.infinispan.AdvancedCache;
1413
import org.infinispan.util.logging.Log;
1514
import org.infinispan.util.logging.LogFactory;
@@ -111,7 +110,8 @@ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object ve
111110
return false;
112111
}
113112

114-
if ( !putValidator.acquirePutFromLoadLock( key ) ) {
113+
PutFromLoadValidator.Lock lock = putValidator.acquirePutFromLoadLock(key);
114+
if ( lock == null) {
115115
if ( TRACE_ENABLED ) {
116116
log.tracef( "Put from load lock not acquired for key %s", key );
117117
}
@@ -131,7 +131,7 @@ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object ve
131131
}
132132
}
133133
finally {
134-
putValidator.releasePutFromLoadLock( key );
134+
putValidator.releasePutFromLoadLock( key, lock);
135135
}
136136

137137
return true;
@@ -185,7 +185,7 @@ public boolean update(Object key, Object value, Object currentVersion, Object pr
185185
* @throws CacheException if removing the cached item fails
186186
*/
187187
public void remove(Object key) throws CacheException {
188-
if ( !putValidator.invalidateKey( key ) ) {
188+
if ( !putValidator.beginInvalidatingKey(key)) {
189189
throw new CacheException(
190190
"Failed to invalidate pending putFromLoad calls for key " + key + " from region " + region.getName()
191191
);
@@ -216,7 +216,7 @@ public void removeAll() throws CacheException {
216216
* @throws CacheException if evicting the item fails
217217
*/
218218
public void evict(Object key) throws CacheException {
219-
if ( !putValidator.invalidateKey( key ) ) {
219+
if ( !putValidator.beginInvalidatingKey(key)) {
220220
throw new CacheException(
221221
"Failed to invalidate pending putFromLoad calls for key " + key + " from region " + region.getName()
222222
);
@@ -240,4 +240,19 @@ public void evictAll() throws CacheException {
240240
Caches.broadcastEvictAll( cache );
241241
}
242242

243+
/**
244+
* Called when we have finished the attempted update/delete (which may or
245+
* may not have been successful), after transaction completion. This method
246+
* is used by "asynchronous" concurrency strategies.
247+
*
248+
* @param key The item key
249+
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
250+
*/
251+
public void unlockItem(Object key) throws CacheException {
252+
if ( !putValidator.endInvalidatingKey(key) ) {
253+
// TODO: localization
254+
log.warn("Failed to end invalidating pending putFromLoad calls for key " + key + " from region "
255+
+ region.getName() + "; the key won't be cached in the future.");
256+
}
257+
}
243258
}

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public SoftLock lockRegion() throws CacheException {
7575
}
7676

7777
public void unlockItem(SessionImplementor session, Object key, SoftLock lock) throws CacheException {
78+
delegate.unlockItem(key);
7879
}
7980

8081
public void unlockRegion(SoftLock lock) throws CacheException {

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public SoftLock lockRegion() throws CacheException {
8484
}
8585

8686
public void unlockItem(SessionImplementor session, Object key, SoftLock lock) throws CacheException {
87+
delegate.unlockItem(key);
8788
}
8889

8990
public void unlockRegion(SoftLock lock) throws CacheException {

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/TransactionalAccess.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public SoftLock lockRegion() throws CacheException {
8989

9090
@Override
9191
public void unlockItem(SessionImplementor session, Object key, SoftLock lock) throws CacheException {
92+
delegate.unlockItem(key);
9293
}
9394

9495
@Override

0 commit comments

Comments
 (0)