Skip to content

Commit 9372803

Browse files
rvansasebersole
authored andcommitted
HHH-10215 Upgrade to Infinispan 8.0
1 parent 63b4f69 commit 9372803

File tree

13 files changed

+41
-111
lines changed

13 files changed

+41
-111
lines changed

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/ClusteredTimestampsRegionImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
import org.hibernate.engine.spi.SessionImplementor;
1818
import org.infinispan.AdvancedCache;
19+
import org.infinispan.CacheSet;
1920
import org.infinispan.commons.util.CloseableIterable;
21+
import org.infinispan.commons.util.CloseableIterator;
2022
import org.infinispan.container.entries.CacheEntry;
2123
import org.infinispan.context.Flag;
2224
import org.infinispan.notifications.Listener;
@@ -109,14 +111,14 @@ public void destroy() throws CacheException {
109111
* Brings all data from the distributed cache into our local cache.
110112
*/
111113
private void populateLocalCache() {
112-
CloseableIterable<Object> iterable = Caches.keys(cache);
114+
CloseableIterator iterator = cache.keySet().iterator();
113115
try {
114-
for (Object key : iterable) {
115-
get(null, key);
116+
while (iterator.hasNext()) {
117+
get(null, iterator.next());
116118
}
117119
}
118120
finally {
119-
iterable.close();
121+
iterator.close();
120122
}
121123
}
122124

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/BeginInvalidationCommand.java

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
package org.hibernate.cache.infinispan.util;
88

99
import org.hibernate.internal.util.compare.EqualsHelper;
10+
import org.infinispan.commands.CommandInvocationId;
1011
import org.infinispan.commands.write.AbstractDataWriteCommand;
1112
import org.infinispan.commands.write.InvalidateCommand;
1213
import org.infinispan.context.Flag;
1314
import org.infinispan.notifications.cachelistener.CacheNotifier;
1415
import org.infinispan.remoting.transport.Address;
1516

1617
import java.lang.reflect.Field;
17-
import java.lang.reflect.InvocationTargetException;
1818
import java.lang.reflect.Method;
1919
import java.util.Arrays;
2020
import java.util.Set;
@@ -23,56 +23,14 @@
2323
* @author Radim Vansa &lt;[email protected]&gt;
2424
*/
2525
public class BeginInvalidationCommand extends InvalidateCommand {
26-
// this is a hack to keep compatibility with both Infinispan 7 and 8
27-
// TODO: remove this when rebasing on Infinispan 8
28-
private static final Field commandInvocationIdField;
29-
private static final Method generateIdMethod;
30-
31-
static {
32-
Field commandInvocationId = null;
33-
Method generateId = null;
34-
try {
35-
commandInvocationId = AbstractDataWriteCommand.class.getDeclaredField("commandInvocationId");
36-
commandInvocationId.setAccessible(true);
37-
Class commandInvocationIdClass = Class.forName("org.infinispan.commands.CommandInvocationId");
38-
generateId = commandInvocationIdClass.getMethod("generateId", Address.class);
39-
}
40-
catch (NoSuchFieldException e) {
41-
}
42-
catch (ClassNotFoundException e) {
43-
// already found field and not the class?
44-
throw new IllegalStateException(e);
45-
}
46-
catch (NoSuchMethodException e) {
47-
// already found field and not the method?
48-
throw new IllegalStateException(e);
49-
}
50-
commandInvocationIdField = commandInvocationId;
51-
generateIdMethod = generateId;
52-
}
53-
5426
private Object sessionTransactionId;
5527

5628
public BeginInvalidationCommand() {
5729
}
5830

59-
public BeginInvalidationCommand(CacheNotifier notifier, Set<Flag> flags, Object[] keys, Address address, Object sessionTransactionId) {
60-
super();
61-
this.notifier = notifier;
62-
this.flags = flags;
63-
this.keys = keys;
31+
public BeginInvalidationCommand(CacheNotifier notifier, Set<Flag> flags, CommandInvocationId commandInvocationId, Object[] keys, Object sessionTransactionId) {
32+
super(notifier, flags, commandInvocationId, keys);
6433
this.sessionTransactionId = sessionTransactionId;
65-
if (commandInvocationIdField != null) {
66-
try {
67-
commandInvocationIdField.set(this, generateIdMethod.invoke(null, address));
68-
}
69-
catch (IllegalAccessException e) {
70-
throw new IllegalStateException(e);
71-
}
72-
catch (InvocationTargetException e) {
73-
throw new IllegalStateException(e);
74-
}
75-
}
7634
}
7735

7836
public Object getSessionTransactionId() {
@@ -81,15 +39,6 @@ public Object getSessionTransactionId() {
8139

8240
@Override
8341
public Object[] getParameters() {
84-
Object commandInvocationId = null;
85-
if (commandInvocationIdField != null) {
86-
try {
87-
commandInvocationId = commandInvocationIdField.get(this);
88-
}
89-
catch (IllegalAccessException e) {
90-
throw new IllegalStateException(e);
91-
}
92-
}
9342
if (keys == null || keys.length == 0) {
9443
return new Object[]{flags, sessionTransactionId, commandInvocationId, 0};
9544
}
@@ -112,15 +61,7 @@ public void setParameters(int commandId, Object[] args) {
11261
}
11362
flags = (Set<Flag>) args[0];
11463
sessionTransactionId = args[1];
115-
Object commandInvocationId = args[2];
116-
if (commandInvocationIdField != null) {
117-
try {
118-
commandInvocationIdField.set(this, commandInvocationId);
119-
}
120-
catch (IllegalAccessException e) {
121-
throw new IllegalStateException(e);
122-
}
123-
}
64+
commandInvocationId = (CommandInvocationId) args[2];
12465
int size = (Integer) args[3];
12566
keys = new Object[size];
12667
if (size == 1) {

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.hibernate.cache.infinispan.util;
88

99
import org.hibernate.cache.infinispan.access.PutFromLoadValidator;
10+
import org.infinispan.commands.CommandInvocationId;
1011
import org.infinispan.commands.ReplicableCommand;
1112
import org.infinispan.commands.module.ModuleCommandInitializer;
1213
import org.infinispan.configuration.cache.Configuration;
@@ -66,7 +67,7 @@ public EvictAllCommand buildEvictAllCommand(String regionName) {
6667
}
6768

6869
public BeginInvalidationCommand buildBeginInvalidationCommand(Set<Flag> flags, Object[] keys, Object sessionTransactionId) {
69-
return new BeginInvalidationCommand(notifier, flags, keys, clusteringDependentLogic.getAddress(), sessionTransactionId);
70+
return new BeginInvalidationCommand(notifier, flags, CommandInvocationId.generateId(clusteringDependentLogic.getAddress()), keys, sessionTransactionId);
7071
}
7172

7273
public EndInvalidationCommand buildEndInvalidationCommand(String cacheName, Object[] keys, Object sessionTransactionId) {

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/Caches.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public static boolean isTransactionalCache(AdvancedCache cache) {
278278

279279

280280
public static void removeAll(AdvancedCache cache) {
281-
CloseableIterator it = keys(cache).iterator();
281+
CloseableIterator it = cache.keySet().iterator();
282282
try {
283283
while (it.hasNext()) {
284284
// Cannot use it.next(); it.remove() due to ISPN-5653
@@ -301,26 +301,14 @@ public interface MapCollectableCloseableIterable<K, V> extends CloseableIterable
301301
Map<K, V> toMap();
302302
}
303303

304-
public static <K, V> CollectableCloseableIterable<K> keys(AdvancedCache<K, V> cache) {
305-
return keys(cache, (KeyValueFilter<K, V>) AcceptAllKeyValueFilter.getInstance());
306-
}
307-
308304
public static <K, V> CollectableCloseableIterable<K> keys(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter) {
309-
if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) {
310-
// Dummy read to enlist the LocalTransaction as workaround for ISPN-5676
311-
cache.containsKey(false);
312-
}
313305
// HHH-10023: we can't use keySet()
314306
final CloseableIterable<CacheEntry<K, Void>> entryIterable = cache
315307
.filterEntries( filter )
316308
.converter( NullValueConverter.getInstance() );
317309
return new CollectableCloseableIterableImpl<K, Void, K>(entryIterable, Selector.KEY);
318310
}
319311

320-
public static <K, V> CollectableCloseableIterable<V> values(AdvancedCache<K, V> cache) {
321-
return values(cache, (KeyValueFilter<K, V>) AcceptAllKeyValueFilter.getInstance());
322-
}
323-
324312
public static <K, V> CollectableCloseableIterable<V> values(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter) {
325313
if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) {
326314
// Dummy read to enlist the LocalTransaction as workaround for ISPN-5676
@@ -341,7 +329,6 @@ public static <K, V, T> CollectableCloseableIterable<T> values(AdvancedCache<K,
341329
return new CollectableCloseableIterableImpl<K, T, T>(entryIterable, Selector.VALUE);
342330
}
343331

344-
345332
public static <K, V> MapCollectableCloseableIterable<K, V> entrySet(AdvancedCache<K, V> cache) {
346333
return entrySet(cache, (KeyValueFilter<K, V>) AcceptAllKeyValueFilter.getInstance());
347334
}

hibernate-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
77
-->
88
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9-
xmlns="urn:infinispan:config:7.2"
10-
xsi:schemaLocation="urn:infinispan:config:7.2 http://www.infinispan.org/schemas/infinispan-config-7.2.xsd">
9+
xmlns="urn:infinispan:config:8.0"
10+
xsi:schemaLocation="urn:infinispan:config:8.0 http://www.infinispan.org/schemas/infinispan-config-8.0.xsd">
1111

1212
<jgroups>
1313
<stack-file name="hibernate-jgroups" path="${hibernate.cache.infinispan.jgroups_cfg:default-configs/default-jgroups-tcp.xml}"/>
@@ -16,51 +16,51 @@
1616
<cache-container name="SampleCacheManager" statistics="false" default-cache="the-default-cache" shutdown-hook="DEFAULT">
1717
<transport stack="hibernate-jgroups" cluster="infinispan-hibernate-cluster"/>
1818

19-
<local-cache name="the-default-cache" statistics="false" />
19+
<local-cache-configuration name="the-default-cache" statistics="false" />
2020

2121
<!-- Default configuration is appropriate for entity/collection caching. -->
22-
<invalidation-cache name="entity" mode="SYNC" remote-timeout="20000">
22+
<invalidation-cache-configuration name="entity" mode="SYNC" remote-timeout="20000">
2323
<locking concurrency-level="1000" acquire-timeout="15000"/>
2424
<transaction mode="NONE" />
2525
<eviction max-entries="10000" strategy="LRU"/>
2626
<expiration max-idle="100000" interval="5000"/>
27-
</invalidation-cache>
27+
</invalidation-cache-configuration>
2828

2929
<!-- Default configuration for immutable entities -->
30-
<invalidation-cache name="immutable-entity" mode="SYNC" remote-timeout="20000">
30+
<invalidation-cache-configuration name="immutable-entity" mode="SYNC" remote-timeout="20000">
3131
<locking concurrency-level="1000" acquire-timeout="15000"/>
3232
<transaction mode="NONE"/>
3333
<eviction max-entries="10000" strategy="LRU"/>
3434
<expiration max-idle="100000" interval="5000"/>
35-
</invalidation-cache>
35+
</invalidation-cache-configuration>
3636

3737
<!-- A config appropriate for query caching. Does not replicate queries. -->
38-
<local-cache name="local-query">
38+
<local-cache-configuration name="local-query">
3939
<locking concurrency-level="1000" acquire-timeout="15000"/>
4040
<transaction mode="NONE" />
4141
<eviction max-entries="10000" strategy="LRU"/>
4242
<expiration max-idle="100000" interval="5000"/>
43-
</local-cache>
43+
</local-cache-configuration>
4444

4545
<!-- A query cache that replicates queries. Replication is asynchronous. -->
46-
<replicated-cache name="replicated-query" mode="ASYNC">
46+
<replicated-cache-configuration name="replicated-query" mode="ASYNC">
4747
<locking concurrency-level="1000" acquire-timeout="15000"/>
4848
<transaction mode="NONE" />
4949
<eviction max-entries="10000" strategy="LRU"/>
5050
<expiration max-idle="100000" interval="5000"/>
51-
</replicated-cache>
51+
</replicated-cache-configuration>
5252

5353
<!-- Optimized for timestamp caching. A clustered timestamp cache
5454
is required if query caching is used, even if the query cache
5555
itself is configured with CacheMode=LOCAL. -->
56-
<replicated-cache name="timestamps" mode="ASYNC">
56+
<replicated-cache-configuration name="timestamps" mode="ASYNC">
5757
<locking concurrency-level="1000" acquire-timeout="15000"/>
5858
<!-- Explicitly non transactional -->
5959
<transaction mode="NONE"/>
6060
<!-- Don't ever evict modification timestamps -->
6161
<eviction strategy="NONE"/>
6262
<expiration interval="0"/>
63-
</replicated-cache>
63+
</replicated-cache-configuration>
6464
</cache-container>
6565

6666
</infinispan>

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ private void evictOrRemoveAllTest(String configName) throws Exception {
170170
SessionImplementor remoteSession = (SessionImplementor) sessionFactories.get(1).openSession();
171171

172172
try {
173-
Set localKeys = Caches.keys(localCache).toSet();
173+
Set localKeys = localCache.keySet();
174174
assertEquals( "No valid children in " + localKeys, 0, localKeys.size() );
175175

176-
Set remoteKeys = Caches.keys(remoteCache).toSet();
176+
Set remoteKeys = remoteCache.keySet();
177177
assertEquals( "No valid children in " + remoteKeys, 0, remoteKeys.size() );
178178

179179
assertNull( "local is clean", localRegion.get(null, KEY ) );
@@ -197,14 +197,14 @@ private void evictOrRemoveAllTest(String configName) throws Exception {
197197
sleep( 250 );
198198
// This should re-establish the region root node in the optimistic case
199199
assertNull( localRegion.get(null, KEY ) );
200-
localKeys = Caches.keys(localCache).toSet();
200+
localKeys = localCache.keySet();
201201
assertEquals( "No valid children in " + localKeys, 0, localKeys.size() );
202202

203203
// Re-establishing the region root on the local node doesn't
204204
// propagate it to other nodes. Do a get on the remote node to re-establish
205205
// This only adds a node in the case of optimistic locking
206206
assertEquals( null, remoteRegion.get(null, KEY ) );
207-
remoteKeys = Caches.keys(remoteCache).toSet();
207+
remoteKeys = remoteCache.keySet();
208208
assertEquals( "No valid children in " + remoteKeys, 0, remoteKeys.size() );
209209

210210
assertEquals( "local is clean", null, localRegion.get(null, KEY ) );

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void insertAndClearCache() throws Exception {
7171
Item item = new Item("my item", "Original item");
7272
withTxSession(s -> s.persist(item));
7373
entityCache.clear();
74-
assertEquals("Cache is not empty", Collections.EMPTY_SET, Caches.keys(entityCache).toSet());
74+
assertEquals("Cache is not empty", Collections.EMPTY_SET, entityCache.keySet());
7575
itemId = item.getId();
7676
log.info("Insert and clear finished");
7777
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.hibernate.testing.env.ConnectionProviderBuilder;
1414
import org.infinispan.AdvancedCache;
1515
import org.infinispan.commons.util.CloseableIterable;
16+
import org.infinispan.commons.util.CloseableIterator;
1617
import org.infinispan.context.Flag;
1718
import org.junit.Test;
1819

@@ -101,8 +102,9 @@ public void testMultiTenancy() throws Exception {
101102
// }
102103
EntityRegionImpl region = (EntityRegionImpl) sessionFactory().getSecondLevelCacheRegion(Item.class.getName());
103104
AdvancedCache localCache = region.getCache().withFlags(Flag.CACHE_MODE_LOCAL);
104-
CloseableIterable keys = Caches.keys(localCache);
105105
assertEquals(1, localCache.size());
106-
assertEquals("OldCacheKeyImplementation", keys.iterator().next().getClass().getSimpleName());
106+
try (CloseableIterator iterator = localCache.keySet().iterator()) {
107+
assertEquals("OldCacheKeyImplementation", iterator.next().getClass().getSimpleName());
108+
}
107109
}
108110
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.hibernate.test.cache.infinispan.functional.entities.Item;
66
import org.infinispan.AdvancedCache;
77
import org.infinispan.commons.util.CloseableIterable;
8+
import org.infinispan.commons.util.CloseableIterator;
89
import org.infinispan.context.Flag;
910
import org.junit.Test;
1011

@@ -38,8 +39,9 @@ public void testNoTenancy() throws Exception {
3839
}
3940
EntityRegionImpl region = (EntityRegionImpl) sessionFactory().getSecondLevelCacheRegion(Item.class.getName());
4041
AdvancedCache localCache = region.getCache().withFlags(Flag.CACHE_MODE_LOCAL);
41-
CloseableIterable keys = Caches.keys(localCache);
4242
assertEquals(1, localCache.size());
43-
assertEquals(sessionFactory().getClassMetadata(Item.class).getIdentifierType().getReturnedClass(), keys.iterator().next().getClass());
43+
try (CloseableIterator iterator = localCache.keySet().iterator()) {
44+
assertEquals(sessionFactory().getClassMetadata(Item.class).getIdentifierType().getReturnedClass(), iterator.next().getClass());
45+
}
4446
}
4547
}

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void testAll() throws Exception {
122122
deleteCitizenWithCriteria(remoteFactory);
123123
sleep(250);
124124

125-
Set localKeys = Caches.keys(localNaturalIdCache.getAdvancedCache()).toSet();
125+
Set localKeys = localNaturalIdCache.keySet();
126126
assertEquals(1, localKeys.size());
127127
// Only key left is the one for the citizen *not* in France
128128
localKeys.toString().contains("000");

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/timestamp/TimestampsRegionImplTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.infinispan.notifications.Listener;
3131
import org.infinispan.notifications.cachelistener.annotation.CacheEntryActivated;
3232
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
33-
import org.infinispan.notifications.cachelistener.annotation.CacheEntryEvicted;
3433
import org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated;
3534
import org.infinispan.notifications.cachelistener.annotation.CacheEntryLoaded;
3635
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
@@ -132,7 +131,6 @@ public static class MockClassLoaderAwareListener extends ClassLoaderAwareCache.C
132131

133132
@CacheEntryActivated
134133
@CacheEntryCreated
135-
@CacheEntryEvicted
136134
@CacheEntryInvalidated
137135
@CacheEntryLoaded
138136
@CacheEntryModified

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/ClassLoaderAwareCache.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.infinispan.notifications.Listener;
2727
import org.infinispan.notifications.cachelistener.annotation.CacheEntryActivated;
2828
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
29-
import org.infinispan.notifications.cachelistener.annotation.CacheEntryEvicted;
3029
import org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated;
3130
import org.infinispan.notifications.cachelistener.annotation.CacheEntryLoaded;
3231
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
@@ -95,7 +94,6 @@ protected Object handleDefault(InvocationContext ctx, VisitableCommand command)
9594
static {
9695
events.put(CacheEntryActivated.class, Event.Type.CACHE_ENTRY_ACTIVATED);
9796
events.put(CacheEntryCreated.class, Event.Type.CACHE_ENTRY_CREATED);
98-
events.put(CacheEntryEvicted.class, Event.Type.CACHE_ENTRY_EVICTED);
9997
events.put(CacheEntryInvalidated.class, Event.Type.CACHE_ENTRY_INVALIDATED);
10098
events.put(CacheEntryLoaded.class, Event.Type.CACHE_ENTRY_LOADED);
10199
events.put(CacheEntryModified.class, Event.Type.CACHE_ENTRY_MODIFIED);
@@ -130,7 +128,6 @@ public ClassLoaderAwareListener(Object listener, ClassLoaderAwareCache cache) {
130128

131129
@CacheEntryActivated
132130
@CacheEntryCreated
133-
@CacheEntryEvicted
134131
@CacheEntryInvalidated
135132
@CacheEntryLoaded
136133
@CacheEntryModified

0 commit comments

Comments
 (0)