Skip to content

Commit

Permalink
ISPN-8570 Partially fix version dependant compatibility
Browse files Browse the repository at this point in the history
* Mostly focused around the imcompatibilities between
SessionImplementor (5.1) and SharedSessionContractImplementor (5.2).
* Also focused on the TransactionCoordinator and related package
refactoring from org.hibernate.resource.transaction to
org.hibernate.resource.transaction.spi
  • Loading branch information
galderz committed Jan 8, 2018
1 parent 0d78972 commit 109e7b7
Show file tree
Hide file tree
Showing 60 changed files with 1,206 additions and 383 deletions.
Expand Up @@ -14,6 +14,7 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.ServiceLoader;
import java.util.function.Consumer; import java.util.function.Consumer;


import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
Expand Down Expand Up @@ -43,17 +44,11 @@
import org.infinispan.commons.util.Util; import org.infinispan.commons.util.Util;
import org.infinispan.configuration.cache.Configuration; import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.cache.StorageType;
import org.infinispan.configuration.cache.TransactionConfiguration; import org.infinispan.configuration.cache.TransactionConfiguration;
import org.infinispan.configuration.parsing.ConfigurationBuilderHolder; import org.infinispan.configuration.parsing.ConfigurationBuilderHolder;
import org.infinispan.configuration.parsing.ParserRegistry; import org.infinispan.configuration.parsing.ParserRegistry;
import org.infinispan.eviction.EvictionType;
import org.infinispan.factories.GlobalComponentRegistry; import org.infinispan.factories.GlobalComponentRegistry;
import org.infinispan.hibernate.cache.commons.collection.CollectionRegionImpl;
import org.infinispan.hibernate.cache.commons.entity.EntityRegionImpl;
import org.infinispan.hibernate.cache.commons.impl.BaseRegion; import org.infinispan.hibernate.cache.commons.impl.BaseRegion;
import org.infinispan.hibernate.cache.commons.naturalid.NaturalIdRegionImpl;
import org.infinispan.hibernate.cache.commons.query.QueryResultsRegionImpl;
import org.infinispan.hibernate.cache.commons.timestamp.ClusteredTimestampsRegionImpl; import org.infinispan.hibernate.cache.commons.timestamp.ClusteredTimestampsRegionImpl;
import org.infinispan.hibernate.cache.commons.timestamp.TimestampsRegionImpl; import org.infinispan.hibernate.cache.commons.timestamp.TimestampsRegionImpl;
import org.infinispan.hibernate.cache.commons.tm.HibernateTransactionManagerLookup; import org.infinispan.hibernate.cache.commons.tm.HibernateTransactionManagerLookup;
Expand Down Expand Up @@ -289,11 +284,19 @@ public void validate(Configuration configuration) {


private Boolean globalStats; private Boolean globalStats;


private final InternalRegionFactory internalRegionFactory;

/** /**
* Create a new instance using the default configuration. * Create a new instance using the default configuration.
*/ */
public InfinispanRegionFactory() { public InfinispanRegionFactory() {
} internalRegionFactory = findInternalRegionFactory();
}

private InternalRegionFactory findInternalRegionFactory() {
ServiceLoader<InternalRegionFactory> loader = ServiceLoader.load(InternalRegionFactory.class);
return loader.iterator().next();
}


/** /**
* Create a new instance using conifguration properties in <code>props</code>. * Create a new instance using conifguration properties in <code>props</code>.
Expand All @@ -302,6 +305,7 @@ public InfinispanRegionFactory() {
*/ */
@SuppressWarnings("UnusedParameters") @SuppressWarnings("UnusedParameters")
public InfinispanRegionFactory(Properties props) { public InfinispanRegionFactory(Properties props) {
this();
} }


@Override @Override
Expand All @@ -310,8 +314,8 @@ public CollectionRegion buildCollectionRegion(String regionName, Properties prop
log.debug( "Building collection cache region [" + regionName + "]" ); log.debug( "Building collection cache region [" + regionName + "]" );
} }
final AdvancedCache cache = getCache( regionName, DataType.COLLECTION, metadata); final AdvancedCache cache = getCache( regionName, DataType.COLLECTION, metadata);
final CollectionRegionImpl region = new CollectionRegionImpl( cache, regionName, transactionManager, metadata, this, getCacheKeysFactory() ); final CollectionRegion region = internalRegionFactory.createCollectionRegion( cache, regionName, transactionManager, metadata, this, getCacheKeysFactory() );
startRegion( region ); startRegion((BaseRegion) region);
return region; return region;
} }


Expand All @@ -326,8 +330,8 @@ public EntityRegion buildEntityRegion(String regionName, Properties properties,
); );
} }
final AdvancedCache cache = getCache( regionName, metadata.isMutable() ? DataType.ENTITY : DataType.IMMUTABLE_ENTITY, metadata ); final AdvancedCache cache = getCache( regionName, metadata.isMutable() ? DataType.ENTITY : DataType.IMMUTABLE_ENTITY, metadata );
final EntityRegionImpl region = new EntityRegionImpl( cache, regionName, transactionManager, metadata, this, getCacheKeysFactory() ); final EntityRegion region = internalRegionFactory.createEntityRegion( cache, regionName, transactionManager, metadata, this, getCacheKeysFactory() );
startRegion( region ); startRegion((BaseRegion) region);
return region; return region;
} }


Expand All @@ -337,8 +341,8 @@ public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties proper
log.debug("Building natural id cache region [" + regionName + "]"); log.debug("Building natural id cache region [" + regionName + "]");
} }
final AdvancedCache cache = getCache( regionName, DataType.NATURAL_ID, metadata); final AdvancedCache cache = getCache( regionName, DataType.NATURAL_ID, metadata);
final NaturalIdRegionImpl region = new NaturalIdRegionImpl( cache, regionName, transactionManager, metadata, this, getCacheKeysFactory()); NaturalIdRegion region = internalRegionFactory.createNaturalIdRegion( cache, regionName, transactionManager, metadata, this, getCacheKeysFactory());
startRegion( region ); startRegion((BaseRegion) region);
return region; return region;
} }


Expand All @@ -349,8 +353,8 @@ public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties
} }


final AdvancedCache cache = getCache( regionName, DataType.QUERY, null); final AdvancedCache cache = getCache( regionName, DataType.QUERY, null);
final QueryResultsRegionImpl region = new QueryResultsRegionImpl( cache, regionName, transactionManager, this ); final QueryResultsRegion region = internalRegionFactory.createQueryResultsRegion( cache, regionName, transactionManager, this );
startRegion( region ); startRegion((BaseRegion) region);
return region; return region;
} }


Expand Down Expand Up @@ -379,7 +383,7 @@ public Configuration getPendingPutsCacheConfiguration() {
return dataTypeConfigurations.get(DataType.PENDING_PUTS); return dataTypeConfigurations.get(DataType.PENDING_PUTS);
} }


private CacheKeysFactory getCacheKeysFactory() { protected CacheKeysFactory getCacheKeysFactory() {
return cacheKeysFactory; return cacheKeysFactory;
} }


Expand Down
@@ -0,0 +1,35 @@
package org.infinispan.hibernate.cache.commons;

import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.CacheKeysFactory;
import org.hibernate.cache.spi.CollectionRegion;
import org.hibernate.cache.spi.EntityRegion;
import org.hibernate.cache.spi.NaturalIdRegion;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.infinispan.AdvancedCache;
import org.infinispan.hibernate.cache.commons.impl.BaseRegion;

import javax.transaction.TransactionManager;

public interface InternalRegionFactory {

<T extends BaseRegion & CollectionRegion> T createCollectionRegion(
AdvancedCache cache, String regionName, TransactionManager transactionManager,
CacheDataDescription metadata, InfinispanRegionFactory regionFactory,
CacheKeysFactory cacheKeysFactory);

<T extends BaseRegion & EntityRegion> T createEntityRegion(
AdvancedCache cache, String regionName, TransactionManager transactionManager,
CacheDataDescription metadata, InfinispanRegionFactory regionFactory,
CacheKeysFactory cacheKeysFactory);

<T extends BaseRegion & NaturalIdRegion> T createNaturalIdRegion(
AdvancedCache cache, String regionName, TransactionManager transactionManager,
CacheDataDescription metadata, InfinispanRegionFactory regionFactory,
CacheKeysFactory cacheKeysFactory);

<T extends BaseRegion & QueryResultsRegion> T createQueryResultsRegion(
AdvancedCache cache, String regionName, TransactionManager transactionManager,
InfinispanRegionFactory regionFactory);

}
Expand Up @@ -20,7 +20,7 @@
* @author Radim Vansa &lt;rvansa@redhat.com&gt; * @author Radim Vansa &lt;rvansa@redhat.com&gt;
*/ */
public interface AccessDelegate { public interface AccessDelegate {
Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException; Object get(Object session, Object key, long txTimestamp) throws CacheException;


/** /**
* Attempt to cache an object, after loading from the database. * Attempt to cache an object, after loading from the database.
Expand All @@ -32,7 +32,7 @@ public interface AccessDelegate {
* @param version the item version number * @param version the item version number
* @return <tt>true</tt> if the object was successfully cached * @return <tt>true</tt> if the object was successfully cached
*/ */
boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version); boolean putFromLoad(Object session, Object key, Object value, long txTimestamp, Object version);


/** /**
* Attempt to cache an object, after loading from the database, explicitly * Attempt to cache an object, after loading from the database, explicitly
Expand All @@ -47,7 +47,7 @@ public interface AccessDelegate {
* @return <tt>true</tt> if the object was successfully cached * @return <tt>true</tt> if the object was successfully cached
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
*/ */
boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) boolean putFromLoad(Object session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException; throws CacheException;


/** /**
Expand All @@ -61,7 +61,7 @@ boolean putFromLoad(SessionImplementor session, Object key, Object value, long t
* @return Were the contents of the cache actual changed by this operation? * @return Were the contents of the cache actual changed by this operation?
* @throws CacheException if the insert fails * @throws CacheException if the insert fails
*/ */
boolean insert(SessionImplementor session, Object key, Object value, Object version) throws CacheException; boolean insert(Object session, Object key, Object value, Object version) throws CacheException;


/** /**
* Called after an item has been updated (before the transaction completes), * Called after an item has been updated (before the transaction completes),
Expand All @@ -75,7 +75,7 @@ boolean putFromLoad(SessionImplementor session, Object key, Object value, long t
* @return Whether the contents of the cache actual changed by this operation * @return Whether the contents of the cache actual changed by this operation
* @throws CacheException if the update fails * @throws CacheException if the update fails
*/ */
boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) boolean update(Object session, Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException; throws CacheException;


/** /**
Expand All @@ -85,7 +85,7 @@ boolean update(SessionImplementor session, Object key, Object value, Object curr
* @param key The key of the item to remove * @param key The key of the item to remove
* @throws CacheException if removing the cached item fails * @throws CacheException if removing the cached item fails
*/ */
void remove(SessionImplementor session, Object key) throws CacheException; void remove(Object session, Object key) throws CacheException;


/** /**
* Called to evict data from the entire region * Called to evict data from the entire region
Expand Down Expand Up @@ -121,7 +121,7 @@ boolean update(SessionImplementor session, Object key, Object value, Object curr
* @param key The item key * @param key The item key
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
*/ */
void unlockItem(SessionImplementor session, Object key) throws CacheException; void unlockItem(Object session, Object key) throws CacheException;


/** /**
* Called after an item has been inserted (after the transaction completes), * Called after an item has been inserted (after the transaction completes),
Expand All @@ -136,7 +136,7 @@ boolean update(SessionImplementor session, Object key, Object value, Object curr
* @return Were the contents of the cache actual changed by this operation? * @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region} * @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/ */
boolean afterInsert(SessionImplementor session, Object key, Object value, Object version); boolean afterInsert(Object session, Object key, Object value, Object version);


/** /**
* Called after an item has been updated (after the transaction completes), * Called after an item has been updated (after the transaction completes),
Expand All @@ -153,5 +153,5 @@ boolean update(SessionImplementor session, Object key, Object value, Object curr
* @return Were the contents of the cache actual changed by this operation? * @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region} * @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/ */
boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock); boolean afterUpdate(Object session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock);
} }
Expand Up @@ -8,11 +8,11 @@


import java.util.UUID; import java.util.UUID;


import org.infinispan.hibernate.cache.commons.access.SessionAccess.TransactionCoordinatorAccess;
import org.infinispan.hibernate.cache.commons.impl.BaseTransactionalDataRegion; import org.infinispan.hibernate.cache.commons.impl.BaseTransactionalDataRegion;
import org.infinispan.hibernate.cache.commons.util.FutureUpdate; import org.infinispan.hibernate.cache.commons.util.FutureUpdate;
import org.infinispan.hibernate.cache.commons.util.InfinispanMessageLogger; import org.infinispan.hibernate.cache.commons.util.InfinispanMessageLogger;
import org.infinispan.hibernate.cache.commons.util.InvocationAfterCompletion; import org.infinispan.hibernate.cache.commons.util.InvocationAfterCompletion;
import org.hibernate.resource.transaction.TransactionCoordinator;


import org.infinispan.AdvancedCache; import org.infinispan.AdvancedCache;


Expand All @@ -29,7 +29,7 @@ public class FutureUpdateSynchronization extends InvocationAfterCompletion {
private final long sessionTimestamp; private final long sessionTimestamp;
private final AdvancedCache cache; private final AdvancedCache cache;


public FutureUpdateSynchronization(TransactionCoordinator tc, AdvancedCache cache, boolean requiresTransaction, public FutureUpdateSynchronization(TransactionCoordinatorAccess tc, AdvancedCache cache, boolean requiresTransaction,
Object key, Object value, BaseTransactionalDataRegion region, long sessionTimestamp) { Object key, Object value, BaseTransactionalDataRegion region, long sessionTimestamp) {


super(tc, requiresTransaction); super(tc, requiresTransaction);
Expand Down
Expand Up @@ -54,7 +54,7 @@ protected InvalidationCacheAccessDelegate(BaseRegion region, PutFromLoadValidato
*/ */
@Override @Override
@SuppressWarnings("UnusedParameters") @SuppressWarnings("UnusedParameters")
public Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException { public Object get(Object session, Object key, long txTimestamp) throws CacheException {
if ( !region.checkValid() ) { if ( !region.checkValid() ) {
return null; return null;
} }
Expand All @@ -66,7 +66,7 @@ public Object get(SessionImplementor session, Object key, long txTimestamp) thro
} }


@Override @Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version) { public boolean putFromLoad(Object session, Object key, Object value, long txTimestamp, Object version) {
return putFromLoad(session, key, value, txTimestamp, version, false ); return putFromLoad(session, key, value, txTimestamp, version, false );
} }


Expand All @@ -85,7 +85,7 @@ public boolean putFromLoad(SessionImplementor session, Object key, Object value,
*/ */
@Override @Override
@SuppressWarnings("UnusedParameters") @SuppressWarnings("UnusedParameters")
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public boolean putFromLoad(Object session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException { throws CacheException {
if ( !region.checkValid() ) { if ( !region.checkValid() ) {
if ( TRACE_ENABLED ) { if ( TRACE_ENABLED ) {
Expand Down Expand Up @@ -122,7 +122,7 @@ public boolean putFromLoad(SessionImplementor session, Object key, Object value,
} }


@Override @Override
public void remove(SessionImplementor session, Object key) throws CacheException { public void remove(Object session, Object key) throws CacheException {
putValidator.setCurrentSession(session); putValidator.setCurrentSession(session);
try { try {
// We update whether or not the region is valid. Other nodes // We update whether or not the region is valid. Other nodes
Expand Down Expand Up @@ -170,6 +170,6 @@ public void evictAll() throws CacheException {
} }


@Override @Override
public void unlockItem(SessionImplementor session, Object key) throws CacheException { public void unlockItem(Object session, Object key) throws CacheException {
} }
} }
Expand Up @@ -9,14 +9,13 @@
import java.util.Comparator; import java.util.Comparator;


import org.hibernate.cache.CacheException; import org.hibernate.cache.CacheException;
import org.infinispan.hibernate.cache.commons.access.SessionAccess.TransactionCoordinatorAccess;
import org.infinispan.hibernate.cache.commons.impl.BaseTransactionalDataRegion; import org.infinispan.hibernate.cache.commons.impl.BaseTransactionalDataRegion;
import org.infinispan.hibernate.cache.commons.util.Caches; import org.infinispan.hibernate.cache.commons.util.Caches;
import org.infinispan.hibernate.cache.commons.util.InfinispanMessageLogger; import org.infinispan.hibernate.cache.commons.util.InfinispanMessageLogger;
import org.infinispan.hibernate.cache.commons.util.VersionedEntry; import org.infinispan.hibernate.cache.commons.util.VersionedEntry;
import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.cache.spi.entry.CacheEntry; import org.hibernate.cache.spi.entry.CacheEntry;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.resource.transaction.TransactionCoordinator;


import org.infinispan.AdvancedCache; import org.infinispan.AdvancedCache;
import org.infinispan.configuration.cache.Configuration; import org.infinispan.configuration.cache.Configuration;
Expand Down Expand Up @@ -60,7 +59,7 @@ public NonStrictAccessDelegate(BaseTransactionalDataRegion region) {
} }


@Override @Override
public Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException { public Object get(Object session, Object key, long txTimestamp) throws CacheException {
if (txTimestamp < region.getLastRegionInvalidation() ) { if (txTimestamp < region.getLastRegionInvalidation() ) {
return null; return null;
} }
Expand All @@ -72,12 +71,12 @@ public Object get(SessionImplementor session, Object key, long txTimestamp) thro
} }


@Override @Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version) { public boolean putFromLoad(Object session, Object key, Object value, long txTimestamp, Object version) {
return putFromLoad(session, key, value, txTimestamp, version, false); return putFromLoad(session, key, value, txTimestamp, version, false);
} }


@Override @Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { public boolean putFromLoad(Object session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException {
long lastRegionInvalidation = region.getLastRegionInvalidation(); long lastRegionInvalidation = region.getLastRegionInvalidation();
if (txTimestamp < lastRegionInvalidation) { if (txTimestamp < lastRegionInvalidation) {
log.tracef("putFromLoad not executed since tx started at %d, before last region invalidation finished = %d", txTimestamp, lastRegionInvalidation); log.tracef("putFromLoad not executed since tx started at %d, before last region invalidation finished = %d", txTimestamp, lastRegionInvalidation);
Expand Down Expand Up @@ -115,25 +114,25 @@ else if (prev instanceof VersionedEntry && txTimestamp <= ((VersionedEntry) prev
} }


@Override @Override
public boolean insert(SessionImplementor session, Object key, Object value, Object version) throws CacheException { public boolean insert(Object session, Object key, Object value, Object version) throws CacheException {
return false; return false;
} }


@Override @Override
public boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { public boolean update(Object session, Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
return false; return false;
} }


@Override @Override
public void remove(SessionImplementor session, Object key) throws CacheException { public void remove(Object session, Object key) throws CacheException {
// there's no 'afterRemove', so we have to use our own synchronization // there's no 'afterRemove', so we have to use our own synchronization
// the API does not provide version of removed item but we can't load it from the cache // the API does not provide version of removed item but we can't load it from the cache
// as that would be prone to race conditions - if the entry was updated in the meantime // as that would be prone to race conditions - if the entry was updated in the meantime
// the remove could be discarded and we would end up with stale record // the remove could be discarded and we would end up with stale record
// See VersionedTest#testCollectionUpdate for such situation // See VersionedTest#testCollectionUpdate for such situation
TransactionCoordinator transactionCoordinator = session.getTransactionCoordinator(); TransactionCoordinatorAccess transactionCoordinator = region.sessionAccess.getTransactionCoordinator(session);
RemovalSynchronization sync = new RemovalSynchronization(transactionCoordinator, writeCache, false, region, key); RemovalSynchronization sync = new RemovalSynchronization(transactionCoordinator, writeCache, false, region, key);
transactionCoordinator.getLocalSynchronizations().registerSynchronization(sync); transactionCoordinator.registerLocalSynchronization(sync);
} }


@Override @Override
Expand Down Expand Up @@ -164,18 +163,18 @@ public void evictAll() throws CacheException {
} }


@Override @Override
public void unlockItem(SessionImplementor session, Object key) throws CacheException { public void unlockItem(Object session, Object key) throws CacheException {
} }


@Override @Override
public boolean afterInsert(SessionImplementor session, Object key, Object value, Object version) { public boolean afterInsert(Object session, Object key, Object value, Object version) {
writeCache.put(key, getVersioned(value, version, session.getTimestamp())); writeCache.put(key, getVersioned(value, version, region.sessionAccess.getTimestamp(session)));
return true; return true;
} }


@Override @Override
public boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) { public boolean afterUpdate(Object session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) {
writeCache.put(key, getVersioned(value, currentVersion, session.getTimestamp())); writeCache.put(key, getVersioned(value, currentVersion, region.sessionAccess.getTimestamp(session)));
return true; return true;
} }


Expand Down

0 comments on commit 109e7b7

Please sign in to comment.