Skip to content

Commit 19c14ce

Browse files
rvansagalderz
authored andcommitted
HHH-9868, HHH-9881 Removed references to TransactionManager from PutFromLoadValidator
* Also removed put() instead of PFER() after region invalidation * Relaxed test that required that session.load() after cache.evictAll() in the same transaction cached the loaded entity
1 parent c8ed5e1 commit 19c14ce

File tree

9 files changed

+21
-118
lines changed

9 files changed

+21
-118
lines changed

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

Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ public class PutFromLoadValidator {
9292
private static final Log log = LogFactory.getLog(PutFromLoadValidator.class);
9393
private static final boolean trace = log.isTraceEnabled();
9494

95-
/**
96-
* Used to determine whether the owner of a pending put is a thread or a transaction
97-
*/
98-
private final TransactionManager transactionManager;
99-
10095
/**
10196
* Period after which ongoing invalidation is removed. Value is retrieved from cache configuration.
10297
*/
@@ -130,32 +125,27 @@ public class PutFromLoadValidator {
130125
private int regionInvalidations = 0;
131126

132127
/**
133-
* Transactions that invalidate the region. Entries are removed during next invalidation based on transaction status.
128+
* Allows propagation of current Session to callbacks invoked from interceptors
134129
*/
135-
private final ConcurrentHashSet<Transaction> regionInvalidators = new ConcurrentHashSet<Transaction>();
136-
137130
private final ThreadLocal<SessionImplementor> currentSession = new ThreadLocal<SessionImplementor>();
138131

139-
140132
/**
141133
* Creates a new put from load validator instance.
142134
*
143135
* @param cache Cache instance on which to store pending put information.
144-
* @param transactionManager Transaction manager
145136
*/
146-
public PutFromLoadValidator(AdvancedCache cache, TransactionManager transactionManager) {
147-
this( cache, cache.getCacheManager(), transactionManager);
137+
public PutFromLoadValidator(AdvancedCache cache) {
138+
this( cache, cache.getCacheManager());
148139
}
149140

150141
/**
151142
* Creates a new put from load validator instance.
152143
*
153144
* @param cache Cache instance on which to store pending put information.
154145
* @param cacheManager where to find a cache to store pending put information
155-
* @param tm transaction manager
156146
*/
157147
public PutFromLoadValidator(AdvancedCache cache,
158-
EmbeddedCacheManager cacheManager, TransactionManager tm) {
148+
EmbeddedCacheManager cacheManager) {
159149

160150
Configuration cacheConfiguration = cache.getCacheConfiguration();
161151
Configuration pendingPutsConfiguration = cacheManager.getCacheConfiguration(InfinispanRegionFactory.PENDING_PUTS_CACHE_NAME);
@@ -218,7 +208,6 @@ public PutFromLoadValidator(AdvancedCache cache,
218208

219209
this.cache = cache;
220210
this.pendingPuts = cacheManager.getCache(pendingPutsName);
221-
this.transactionManager = tm;
222211
this.nonTxPutFromLoadInterceptor = nonTxPutFromLoadInterceptor;
223212
}
224213

@@ -422,35 +411,6 @@ public boolean beginInvalidatingRegion() {
422411
regionInvalidationTimestamp = Long.MAX_VALUE;
423412
regionInvalidations++;
424413
}
425-
if (transactionManager != null) {
426-
// cleanup old transactions
427-
for (Iterator<Transaction> it = regionInvalidators.iterator(); it.hasNext(); ) {
428-
Transaction tx = it.next();
429-
try {
430-
switch (tx.getStatus()) {
431-
case Status.STATUS_COMMITTED:
432-
case Status.STATUS_ROLLEDBACK:
433-
case Status.STATUS_UNKNOWN:
434-
case Status.STATUS_NO_TRANSACTION:
435-
it.remove();
436-
}
437-
}
438-
catch (SystemException e) {
439-
log.error("Cannot retrieve transaction status", e);
440-
}
441-
}
442-
// add this transaction
443-
try {
444-
Transaction tx = transactionManager.getTransaction();
445-
if (tx != null) {
446-
regionInvalidators.add(tx);
447-
}
448-
}
449-
catch (SystemException e) {
450-
log.error("TransactionManager failed to provide transaction", e);
451-
return false;
452-
}
453-
}
454414

455415
try {
456416
// Acquire the lock for each entry to ensure any ongoing
@@ -513,29 +473,10 @@ public void endInvalidatingRegion() {
513473
public void registerPendingPut(SessionImplementor session, Object key, long txTimestamp) {
514474
long invalidationTimestamp = this.regionInvalidationTimestamp;
515475
if (txTimestamp <= invalidationTimestamp) {
516-
boolean skip;
517-
if (invalidationTimestamp == Long.MAX_VALUE) {
518-
// there is ongoing invalidation of pending puts
519-
skip = true;
520-
}
521-
else {
522-
Transaction tx = null;
523-
if (transactionManager != null) {
524-
try {
525-
tx = transactionManager.getTransaction();
526-
}
527-
catch (SystemException e) {
528-
log.error("TransactionManager failed to provide transaction", e);
529-
}
530-
}
531-
skip = tx == null || !regionInvalidators.contains(tx);
532-
}
533-
if (skip) {
534-
if (trace) {
535-
log.tracef("registerPendingPut(%s#%s, %d) skipped due to region invalidation (%d)", cache.getName(), key, txTimestamp, invalidationTimestamp);
536-
}
537-
return;
476+
if (trace) {
477+
log.tracef("registerPendingPut(%s#%s, %d) skipped due to region invalidation (%d)", cache.getName(), key, txTimestamp, invalidationTimestamp);
538478
}
479+
return;
539480
}
540481

541482
final PendingPut pendingPut = new PendingPut( session );

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,10 @@ public boolean putFromLoad(SessionImplementor session, Object key, Object value,
124124
return false;
125125
}
126126

127-
putValidator.setCurrentSession(session);
128127
try {
129-
// Conditional put/putForExternalRead. If the region has been
130-
// evicted in the current transaction, do a put instead of a
131-
// putForExternalRead to make it stick, otherwise the current
132-
// transaction won't see it.
133-
if ( region.isRegionInvalidatedInCurrentTx() ) {
134-
writeCache.put( key, value );
135-
}
136-
else {
137-
writeCache.putForExternalRead( key, value );
138-
}
128+
writeCache.putForExternalRead( key, value );
139129
}
140130
finally {
141-
putValidator.resetCurrentSession();
142131
putValidator.releasePutFromLoadLock( key, lock);
143132
}
144133

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType)
5555
}
5656

5757
public PutFromLoadValidator getPutFromLoadValidator() {
58-
return new PutFromLoadValidator( cache, getTransactionManager() );
58+
return new PutFromLoadValidator( cache );
5959
}
6060

6161
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) thr
6363
}
6464

6565
public PutFromLoadValidator getPutFromLoadValidator() {
66-
return new PutFromLoadValidator( cache, getTransactionManager() );
66+
return new PutFromLoadValidator( cache );
6767
}
6868
}

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,7 @@ public void invalidateRegion() {
228228
if (log.isTraceEnabled()) {
229229
log.trace( "Invalidate region: " + name );
230230
}
231-
232-
Transaction tx = getCurrentTransaction();
233-
if ( tx != null ) {
234-
synchronized ( invalidationMutex ) {
235-
invalidateTransaction = tx;
236-
invalidateState.set( InvalidateState.INVALID );
237-
}
238-
}
239-
else {
240-
invalidateState.set( InvalidateState.INVALID );
241-
}
231+
invalidateState.set( InvalidateState.INVALID );
242232
}
243233

244234
public TransactionManager getTransactionManager() {
@@ -255,11 +245,6 @@ public AdvancedCache getCache() {
255245
return cache;
256246
}
257247

258-
public boolean isRegionInvalidatedInCurrentTx() {
259-
Transaction tx = getCurrentTransaction();
260-
return tx != null && tx.equals( invalidateTransaction );
261-
}
262-
263248
private Transaction getCurrentTransaction() {
264249
try {
265250
// Transaction manager could be null

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType)
5757
}
5858

5959
public PutFromLoadValidator getPutFromLoadValidator() {
60-
return new PutFromLoadValidator( cache, getTransactionManager() );
60+
return new PutFromLoadValidator( cache );
6161
}
6262

6363
}

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/access/PutFromLoadValidatorUnitTestCase.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ private void nakedPutTest(final boolean transactional) throws Exception {
9797
withCacheManager(new CacheManagerCallable(createCacheManager()) {
9898
@Override
9999
public void call() {
100-
PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm,
101-
transactional ? tm : null);
100+
PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm);
102101
exec(transactional, new NakedPut(testee, true));
103102
}
104103
});
@@ -117,8 +116,7 @@ private void registeredPutTest(final boolean transactional) throws Exception {
117116
withCacheManager(new CacheManagerCallable(createCacheManager()) {
118117
@Override
119118
public void call() {
120-
PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm,
121-
transactional ? tm : null);
119+
PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm);
122120
exec(transactional, new RegularPut(testee));
123121
}
124122
});
@@ -146,8 +144,7 @@ private void nakedPutAfterRemovalTest(final boolean transactional,
146144
withCacheManager(new CacheManagerCallable(createCacheManager()) {
147145
@Override
148146
public void call() {
149-
PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm,
150-
transactional ? tm : null);
147+
PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache());
151148
Invalidation invalidation = new Invalidation(testee, removeRegion);
152149
// the naked put can succeed because it has txTimestamp after invalidation
153150
NakedPut nakedPut = new NakedPut(testee, true);
@@ -179,8 +176,7 @@ private void registeredPutAfterRemovalTest(final boolean transactional,
179176
withCacheManager(new CacheManagerCallable(createCacheManager()) {
180177
@Override
181178
public void call() {
182-
PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm,
183-
transactional ? tm : null);
179+
PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm);
184180
Invalidation invalidation = new Invalidation(testee, removeRegion);
185181
RegularPut regularPut = new RegularPut(testee);
186182
exec(transactional, invalidation, regularPut);
@@ -211,8 +207,7 @@ private void registeredPutWithInterveningRemovalTest(
211207
withCacheManager(new CacheManagerCallable(createCacheManager()) {
212208
@Override
213209
public void call() {
214-
PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm,
215-
transactional ? tm : null);
210+
PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm);
216211
try {
217212
long txTimestamp = System.currentTimeMillis();
218213
if (transactional) {
@@ -262,8 +257,7 @@ private void multipleRegistrationtest(final boolean transactional) throws Except
262257
withCacheManager(new CacheManagerCallable(createCacheManager()) {
263258
@Override
264259
public void call() {
265-
final PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm,
266-
transactional ? tm : null);
260+
final PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm);
267261

268262
final CountDownLatch registeredLatch = new CountDownLatch(3);
269263
final CountDownLatch finishedLatch = new CountDownLatch(3);
@@ -341,8 +335,7 @@ private void invalidationBlocksForInProgressPutTest(final boolean keyOnly) throw
341335
withCacheManager(new CacheManagerCallable(createCacheManager()) {
342336
@Override
343337
public void call() {
344-
final PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(),
345-
cm, null);
338+
final PutFromLoadValidator testee = new PutFromLoadValidator(cm.getCache().getAdvancedCache(), cm);
346339
final CountDownLatch removeLatch = new CountDownLatch(1);
347340
final CountDownLatch pferLatch = new CountDownLatch(1);
348341
final AtomicReference<Object> cache = new AtomicReference<Object>("INITIAL");

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void testPutFromLoadRemoveDoesNotProduceStaleData() throws Exception {
167167
withCacheManager(new CacheManagerCallable(createCacheManager()) {
168168
@Override
169169
public void call() {
170-
PutFromLoadValidator validator = getPutFromLoadValidator(remoteCollectionRegion.getCache(), cm, remoteTm, removeLatch, pferLatch);
170+
PutFromLoadValidator validator = getPutFromLoadValidator(remoteCollectionRegion.getCache(), cm, removeLatch, pferLatch);
171171

172172
final TransactionalAccessDelegate delegate =
173173
new TransactionalAccessDelegate(localCollectionRegion, validator);
@@ -221,11 +221,10 @@ private static EmbeddedCacheManager createCacheManager() {
221221
}
222222

223223
protected PutFromLoadValidator getPutFromLoadValidator(AdvancedCache cache, EmbeddedCacheManager cm,
224-
TransactionManager tm,
225224
CountDownLatch removeLatch, CountDownLatch pferLatch) {
226225
// remove the interceptor inserted by default PutFromLoadValidator, we're using different one
227226
PutFromLoadValidator.removeFromCache(cache);
228-
return new PutFromLoadValidator(cache, cm, tm) {
227+
return new PutFromLoadValidator(cache, cm) {
229228
@Override
230229
public Lock acquirePutFromLoadLock(SessionImplementor session, Object key, long txTimestamp) {
231230
Lock lock = super.acquirePutFromLoadLock(session, key, txTimestamp);

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,10 +1043,6 @@ public Void call() throws Exception {
10431043
assertNotNull(citizen);
10441044
assertNotNull(citizen.getFirstname()); // proxy gets resolved
10451045
assertEquals(1, slcStats.getMissCount());
1046-
assertEquals(3, slcStats.getPutCount());
1047-
assertEquals(1, slcStats.getElementCountInMemory());
1048-
assertTrue("2lc entity cache is expected to contain Citizen id = " + citizens.get(0).getId(),
1049-
cache.containsEntity(Citizen.class, citizens.get(0).getId()));
10501046

10511047
// cleanup
10521048
tx.rollback();

0 commit comments

Comments
 (0)