HHH-12036 Use cache.clear() for bulk removal on non-tx cache

This commit is contained in:
Radim Vansa 2017-10-18 13:11:42 +02:00 committed by Vlad Mihalcea
parent 4b8cfe0c1f
commit 5d2c353437
3 changed files with 19 additions and 2 deletions

View File

@ -77,4 +77,17 @@ public class NonTxInvalidationCacheAccessDelegate extends InvalidationCacheAcces
// endInvalidatingKeys is called from NonTxInvalidationInterceptor, from the synchronization callback
return false;
}
@Override
public void removeAll() throws CacheException {
try {
if (!putValidator.beginInvalidatingRegion()) {
log.failedInvalidateRegion(region.getName());
}
cache.clear();
}
finally {
putValidator.endInvalidatingRegion();
}
}
}

View File

@ -242,7 +242,7 @@ public abstract class BaseRegion implements Region {
// When we don't have transaction, we can do a clear operation (since we don't
// case about context) and can't do the one-by-one remove: remove() on tx cache
// requires transactional context.
if ( inTransaction ) {
if ( inTransaction && cache.getCacheConfiguration().transaction().transactionMode().isTransactional() ) {
log.tracef( "Transaction, clearing one element at the time" );
Caches.removeAll( localAndSkipLoadCache );
}

View File

@ -45,6 +45,10 @@ import org.hibernate.test.cache.infinispan.util.ExpectingInterceptor;
import org.hibernate.test.cache.infinispan.util.JdbcResourceTransactionMock;
import org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory;
import org.hibernate.test.cache.infinispan.util.TestSynchronization;
import org.infinispan.Cache;
import org.infinispan.commands.write.ClearCommand;
import org.infinispan.test.TestingUtil;
import org.jboss.logging.Logger;
import org.hibernate.test.cache.infinispan.util.TestTimeService;
import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.BeforeClassOnce;
@ -513,7 +517,7 @@ public abstract class AbstractRegionAccessStrategyTest<R extends BaseRegion, S e
});
} else {
ExpectingInterceptor.get(remoteRegion.getCache())
.when((ctx, cmd) -> cmd instanceof InvalidateCommand)
.when((ctx, cmd) -> cmd instanceof InvalidateCommand || cmd instanceof ClearCommand)
.countDown(endInvalidationLatch);
cleanup.add(() -> ExpectingInterceptor.cleanup(remoteRegion.getCache()));
}