Skip to content

Commit

Permalink
ISPN-2281 Hot Rod uses raw values with Cache taking versions
Browse files Browse the repository at this point in the history
* AdvancedCache adds a couple of new methods that take metadata
as parameter. This can be used by users to provide version, and
also for server implementations to add their own metadata (i.e.
REST servers and MIME data).
* The implementation of these methods is temporary and is bound
to change in order to feed the metadata object all the way to
the cache entry.
* There's an initial stab at the compatibility testing with
initial focus on Embedded and Hot Rod server. Tests here are not
yet working.
  • Loading branch information
galderz committed Apr 7, 2013
1 parent 8eaa267 commit a35956f
Show file tree
Hide file tree
Showing 63 changed files with 1,479 additions and 421 deletions.
Expand Up @@ -41,6 +41,7 @@
import org.infinispan.marshall.Marshaller;
import org.infinispan.marshall.StreamingMarshaller;
import org.infinispan.marshall.jboss.GenericJBossMarshaller;
import org.infinispan.server.core.ServerEntryVersion;
import org.infinispan.util.logging.LogFactory;

import java.io.IOException;
Expand Down Expand Up @@ -75,7 +76,6 @@ public class RemoteCacheStore extends AbstractCacheStore {
private volatile RemoteCacheStoreConfig config;
private volatile RemoteCacheManager remoteCacheManager;
private volatile RemoteCache<Object, Object> remoteCache;
private EntryWrapper<?, ?> entryWrapper;

private InternalEntryFactory iceFactory;
private static final String LIFESPAN = "lifespan";
Expand All @@ -86,7 +86,9 @@ public InternalCacheEntry load(Object key) throws CacheLoaderException {
if (config.isRawValues()) {
MetadataValue<?> value = remoteCache.getWithMetadata(key);
if (value != null)
return iceFactory.create(entryWrapper.wrapKey(key), entryWrapper.wrapValue(value), null, value.getCreated(), TimeUnit.SECONDS.toMillis(value.getLifespan()), value.getLastUsed(), TimeUnit.SECONDS.toMillis(value.getMaxIdle()));
return iceFactory.create(key, value.getValue(), new ServerEntryVersion(value.getVersion()),
value.getCreated(), TimeUnit.SECONDS.toMillis(value.getLifespan()),
value.getLastUsed(), TimeUnit.SECONDS.toMillis(value.getMaxIdle()));
else
return null;
} else {
Expand Down Expand Up @@ -189,7 +191,6 @@ public void start() throws CacheLoaderException {
if (config.isRawValues() && iceFactory == null) {
iceFactory = cache.getAdvancedCache().getComponentRegistry().getComponent(InternalEntryFactory.class);
}
this.entryWrapper = config.getEntryWrapper();
}

@Override
Expand Down
Expand Up @@ -26,7 +26,9 @@
*
* @author Tristan Tarrant
* @since 5.2
* @deprecated No longer needed since raw types are stored now in Hot Rod
*/
@Deprecated
public interface EntryWrapper<K, V> {

K wrapKey(Object key) throws CacheLoaderException;
Expand Down
Expand Up @@ -56,7 +56,7 @@ public class RemoteCacheStoreMixedAccessTest extends AbstractInfinispanTest {

@BeforeClass
public void setup() throws Exception {
ConfigurationBuilder serverBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(true);
ConfigurationBuilder serverBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
serverBuilder.eviction().maxEntries(100).strategy(EvictionStrategy.UNORDERED)
.expiration().wakeUpInterval(10L);
serverCacheManager = TestCacheManagerFactory.createCacheManager(
Expand Down
Expand Up @@ -58,7 +58,7 @@ public class RemoteCacheStoreRawValuesTest extends BaseCacheStoreTest {

@Override
protected CacheStore createCacheStore() throws Exception {
ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(true);
ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
cb.eviction().maxEntries(100).strategy(EvictionStrategy.UNORDERED)
.expiration().wakeUpInterval(10L);

Expand Down
Expand Up @@ -59,7 +59,7 @@ protected CacheStore createCacheStore() throws Exception {
remoteCacheStoreConfig.setUseDefaultRemoteCache(true);
assert remoteCacheStoreConfig.isUseDefaultRemoteCache();

ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(true);
ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
cb.eviction().maxEntries(100).strategy(EvictionStrategy.UNORDERED)
.expiration().wakeUpInterval(10L);

Expand Down
Expand Up @@ -27,7 +27,6 @@
import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.loaders.remote.configuration.RemoteCacheStoreConfigurationBuilder;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.server.core.CacheValue;
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.AbstractInfinispanTest;
import org.infinispan.test.TestingUtil;
Expand All @@ -46,17 +45,17 @@ public class RemoteCacheStoreWrapperTest extends AbstractInfinispanTest {
private HotRodServer sourceServer;
private HotRodServer targetServer;
private EmbeddedCacheManager serverCacheManager;
private Cache<byte[], CacheValue> serverCache;
private Cache<byte[], byte[]> serverCache;
private EmbeddedCacheManager targetCacheManager;
private Cache<byte[], CacheValue> targetCache;
private Cache<byte[], byte[]> targetCache;
private RemoteCacheManager remoteSourceCacheManager;
private RemoteCache<String, String> remoteSourceCache;
private RemoteCacheManager remoteTargetCacheManager;
private RemoteCache<String, String> remoteTargetCache;

@BeforeClass
public void setup() throws Exception {
ConfigurationBuilder serverBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(true);
ConfigurationBuilder serverBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
serverBuilder.eviction().maxEntries(100).strategy(EvictionStrategy.UNORDERED)
.expiration().wakeUpInterval(10L);
serverCacheManager = TestCacheManagerFactory
Expand Down
Expand Up @@ -47,7 +47,7 @@ protected int numberOfHotRodServers() {
@Override
protected ConfigurationBuilder clusterConfig() {
return hotRodCacheConfiguration(getDefaultClusteredCacheConfig(
CacheMode.DIST_SYNC, true));
CacheMode.DIST_SYNC, false));
}

public void testDistribution() {
Expand Down
Expand Up @@ -54,7 +54,7 @@ public class DroppedConnectionsTest extends SingleCacheManagerTest {
@Override
protected EmbeddedCacheManager createCacheManager() throws Exception {
cacheManager = TestCacheManagerFactory.createCacheManager(
hotRodCacheConfiguration(getDefaultStandaloneCacheConfig(true)));
hotRodCacheConfiguration(getDefaultStandaloneCacheConfig(false)));
hotRodServer = TestHelper.startHotRodServer(cacheManager);
Properties hrClientConfig = new Properties();
hrClientConfig.put("testWhileIdle", "false");
Expand Down
Expand Up @@ -21,6 +21,7 @@

import org.infinispan.client.hotrod.test.MultiHotRodServersTest;
import org.infinispan.commands.write.PutKeyValueCommand;
import org.infinispan.commands.write.VersionedPutKeyValueCommand;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.test.ReplListener;
Expand Down Expand Up @@ -52,8 +53,8 @@ public void testPutKeyValue(Method m) {
ReplListener replList0 = getReplListener(0);
ReplListener replList1 = getReplListener(1);

replList0.expect(PutKeyValueCommand.class);
replList1.expect(PutKeyValueCommand.class);
replList0.expect(VersionedPutKeyValueCommand.class);
replList1.expect(VersionedPutKeyValueCommand.class);

final String v1 = v(m);
remoteCache0.put(1, v1);
Expand Down
Expand Up @@ -196,6 +196,21 @@ public CacheEntry getCacheEntry(Object key, EnumSet<Flag> explicitFlags, ClassLo
return cache.getCacheEntry(key, explicitFlags, explicitClassLoader);
}

@Override
public CacheEntry getCacheEntry(K key) {
return cache.getCacheEntry(key, null, null);
}

@Override
public V put(K key, V value, Metadata metadata) {
return cache.put(key, value, metadata);
}

@Override
public boolean replace(K key, V oldValue, V value, Metadata metadata) {
return cache.replace(key, oldValue, value, metadata);
}

protected final void putForExternalRead(K key, V value, EnumSet<Flag> flags, ClassLoader classLoader) {
((CacheImpl<K, V>) cache).putForExternalRead(key, value, flags, classLoader);
}
Expand Down
22 changes: 22 additions & 0 deletions core/src/main/java/org/infinispan/AdvancedCache.java
Expand Up @@ -26,6 +26,7 @@
import org.infinispan.batch.BatchContainer;
import org.infinispan.container.DataContainer;
import org.infinispan.container.entries.CacheEntry;
import org.infinispan.container.versioning.EntryVersion;
import org.infinispan.context.Flag;
import org.infinispan.context.InvocationContextContainer;
import org.infinispan.distribution.DistributionManager;
Expand All @@ -46,6 +47,7 @@
* An advanced interface that exposes additional methods not available on {@link Cache}.
*
* @author Manik Surtani
* @author Galder Zamarreño
* @since 4.0
*/
public interface AdvancedCache<K, V> extends Cache<K, V> {
Expand Down Expand Up @@ -301,6 +303,26 @@ public interface AdvancedCache<K, V> extends Cache<K, V> {
* @param explicitFlags
* @param explicitClassLoader
* @return
* @deprecated
*/
@Deprecated
CacheEntry getCacheEntry(Object key, EnumSet<Flag> explicitFlags, ClassLoader explicitClassLoader);

// AdvancedCache<K, V> withMetadata(Metadata metadata);

V put(K key, V value, Metadata metadata);

boolean replace(K key, V oldValue, V value, Metadata metadata);

// V putIfAbsent(K key, V value, Metadata metadata);
//
// void putAll(Map<? extends K, ? extends V> map, Metadata metadata);
//
// V replace(K key, V value, Metadata metadata);
//

// TODO: You could have replace calls that compare not only value, but also version internally?

CacheEntry getCacheEntry(K key);

}

0 comments on commit a35956f

Please sign in to comment.