Permalink
Browse files

ISPN-2323 Make RemoteCacheStore support rawValues

	Introduce a GetWithMetadata operation
  • Loading branch information...
1 parent 26a64f8 commit 91e927b783d00f8bd8f8b7fd88544fb3d34768e5 @tristantarrant tristantarrant committed Nov 26, 2012
Showing with 791 additions and 220 deletions.
  1. +40 −8 cachestore/remote/src/main/java/org/infinispan/loaders/remote/RemoteCacheStore.java
  2. +11 −1 cachestore/remote/src/main/java/org/infinispan/loaders/remote/RemoteCacheStoreConfig.java
  3. +5 −0 ...rg/infinispan/loaders/remote/configuration/AbstractRemoteCacheStoreConfigurationChildBuilder.java
  4. +1 −0 cachestore/remote/src/main/java/org/infinispan/loaders/remote/configuration/Attribute.java
  5. +8 −1 ...mote/src/main/java/org/infinispan/loaders/remote/configuration/RemoteCacheStoreConfiguration.java
  6. +9 −1 ...c/main/java/org/infinispan/loaders/remote/configuration/RemoteCacheStoreConfigurationBuilder.java
  7. +10 −0 ...n/java/org/infinispan/loaders/remote/configuration/RemoteCacheStoreConfigurationChildBuilder.java
  8. +4 −0 .../main/java/org/infinispan/loaders/remote/configuration/RemoteCacheStoreConfigurationParser52.java
  9. +8 −0 cachestore/remote/src/main/resources/schema/infinispan-cachestore-remote-config-5.2.xsd
  10. +3 −5 cachestore/remote/src/test/java/org/infinispan/loaders/remote/RemoteCacheStoreConfigTest.java
  11. +2 −1 cachestore/remote/src/test/java/org/infinispan/loaders/remote/RemoteCacheStoreFunctionalTest.java
  12. +125 −0 cachestore/remote/src/test/java/org/infinispan/loaders/remote/RemoteCacheStoreMixedAccessTest.java
  13. +128 −0 cachestore/remote/src/test/java/org/infinispan/loaders/remote/RemoteCacheStoreRawValuesTest.java
  14. +3 −2 cachestore/remote/src/test/java/org/infinispan/loaders/remote/RemoteCacheStoreTest.java
  15. +0 −42 cachestore/remote/src/test/resources/hotrod-client.properties
  16. +23 −10 cachestore/remote/src/test/resources/remote-cl-config.xml
  17. +11 −34 .../src/main/java/org/infinispan/client/hotrod/{impl/BinaryVersionedValue.java → MetadataValue.java}
  18. +6 −1 client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCache.java
  19. +9 −10 client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java
  20. +70 −0 client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/MetadataValueImpl.java
  21. +20 −4 client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/RemoteCacheImpl.java
  22. +84 −0 ...d-client/src/main/java/org/infinispan/client/hotrod/impl/operations/GetWithMetadataOperation.java
  23. +6 −5 ...od-client/src/main/java/org/infinispan/client/hotrod/impl/operations/GetWithVersionOperation.java
  24. +5 −0 ...t/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/operations/OperationsFactory.java
  25. +2 −0 client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/protocol/HeaderParams.java
  26. +5 −0 client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/protocol/HotRodConstants.java
  27. +0 −87 client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/protocol/HotRodOperations.java
  28. +0 −1 client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/Transport.java
  29. +27 −0 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java
  30. +10 −1 core/src/main/java/org/infinispan/CacheImpl.java
  31. +21 −0 core/src/test/java/org/infinispan/configuration/ConfigurationCompatibilityTest.java
  32. +2 −2 server/core/src/main/scala/org/infinispan/server/core/AbstractProtocolDecoder.scala
  33. +16 −0 server/hotrod/src/main/scala/org/infinispan/server/hotrod/AbstractEncoder1x.scala
  34. +2 −0 server/hotrod/src/main/scala/org/infinispan/server/hotrod/Constants.scala
  35. +32 −0 server/hotrod/src/main/scala/org/infinispan/server/hotrod/Decoder10.scala
  36. +1 −1 server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodOperation.scala
  37. +22 −0 server/hotrod/src/main/scala/org/infinispan/server/hotrod/Response.scala
  38. +10 −1 server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodFunctionalTest.scala
  39. +43 −1 server/hotrod/src/test/scala/org/infinispan/server/hotrod/test/HotRodClient.scala
  40. +7 −1 server/hotrod/src/test/scala/org/infinispan/server/hotrod/test/HotRodTestingUtil.scala
@@ -26,15 +26,20 @@
import org.infinispan.Cache;
import org.infinispan.api.BasicCacheContainer;
import org.infinispan.client.hotrod.Flag;
+import org.infinispan.client.hotrod.MetadataValue;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
+import org.infinispan.client.hotrod.impl.ConfigurationProperties;
+import org.infinispan.container.InternalEntryFactory;
import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.loaders.AbstractCacheStore;
import org.infinispan.loaders.CacheLoaderConfig;
import org.infinispan.loaders.CacheLoaderException;
import org.infinispan.loaders.CacheLoaderMetadata;
import org.infinispan.loaders.remote.logging.Log;
+import org.infinispan.marshall.Marshaller;
import org.infinispan.marshall.StreamingMarshaller;
+import org.infinispan.marshall.jboss.GenericJBossMarshaller;
import org.infinispan.util.logging.LogFactory;
import java.io.IOException;
@@ -69,12 +74,22 @@
private volatile RemoteCacheStoreConfig config;
private volatile RemoteCacheManager remoteCacheManager;
private volatile RemoteCache<Object, Object> remoteCache;
+
+ private InternalEntryFactory iceFactory;
private static final String LIFESPAN = "lifespan";
private static final String MAXIDLE = "maxidle";
@Override
public InternalCacheEntry load(Object key) throws CacheLoaderException {
- return (InternalCacheEntry) remoteCache.get(key);
+ if (config.isRawValues()) {
+ MetadataValue<?> value = remoteCache.getWithMetadata(key);
+ if (value != null)
+ return iceFactory.create(key, value.getValue(), null, value.getCreated(), TimeUnit.SECONDS.toMillis(value.getLifespan()), value.getLastUsed(), TimeUnit.SECONDS.toMillis(value.getMaxIdle()));
+ else
+ return null;
+ } else {
+ return (InternalCacheEntry) remoteCache.get(key);
+ }
}
@Override
@@ -94,7 +109,7 @@ public void store(InternalCacheEntry entry) throws CacheLoaderException {
if (log.isTraceEnabled()) {
log.tracef("Adding entry: %s", entry);
}
- remoteCache.put(entry.getKey(), entry, toSeconds(entry.getLifespan(), entry, LIFESPAN), TimeUnit.SECONDS, toSeconds(entry.getMaxIdle(), entry, MAXIDLE), TimeUnit.SECONDS);
+ remoteCache.put(entry.getKey(), config.isRawValues() ? entry.getValue() : entry, toSeconds(entry.getLifespan(), entry, LIFESPAN), TimeUnit.SECONDS, toSeconds(entry.getMaxIdle(), entry, MAXIDLE), TimeUnit.SECONDS);
}
@Override
@@ -158,14 +173,20 @@ public void init(CacheLoaderConfig config, Cache<?, ?> cache, StreamingMarshalle
@Override
public void start() throws CacheLoaderException {
super.start();
- StreamingMarshaller marshaller = getMarshaller();
-
- if (marshaller == null) {throw new IllegalStateException("Null marshaller not allowed!");}
- remoteCacheManager = new RemoteCacheManager(marshaller, config.getHotRodClientProperties(), true, config.getClassLoader(), config.getAsyncExecutorFactory());
+ if (config.getHotRodClientProperties().containsKey(ConfigurationProperties.MARSHALLER)) {
+ remoteCacheManager = new RemoteCacheManager(config.getHotRodClientProperties(), true, config.getClassLoader(), config.getAsyncExecutorFactory());
+ } else {
+ Marshaller marshaller = config.isRawValues() ? new GenericJBossMarshaller() : getMarshaller();
+ if (marshaller == null) {throw new IllegalStateException("Null marshaller not allowed!");}
+ remoteCacheManager = new RemoteCacheManager(marshaller, config.getHotRodClientProperties(), true, config.getClassLoader(), config.getAsyncExecutorFactory());
+ }
if (config.getRemoteCacheName().equals(BasicCacheContainer.DEFAULT_CACHE_NAME))
remoteCache = remoteCacheManager.getCache();
else
remoteCache = remoteCacheManager.getCache(config.getRemoteCacheName());
+ if (config.isRawValues() && iceFactory == null) {
+ iceFactory = cache.getAdvancedCache().getComponentRegistry().getComponent(InternalEntryFactory.class);
+ }
}
@Override
@@ -190,12 +211,23 @@ private long toSeconds(long millis, InternalCacheEntry entry, String desc) {
return TimeUnit.MILLISECONDS.toSeconds(millis);
}
- private Set<InternalCacheEntry> convertToInternalCacheEntries(Map<Object, Object> map) {
+ private Set<InternalCacheEntry> convertToInternalCacheEntries(Map<Object, Object> map) throws CacheLoaderException {
Set<InternalCacheEntry> result = new HashSet<InternalCacheEntry>(map.size());
Set<Map.Entry<Object, Object>> set = map.entrySet();
for (Map.Entry<Object, Object> e : set) {
- result.add((InternalCacheEntry) e.getValue());
+ if (config.isRawValues()) {
+ result.add(load(e.getKey())); // Inefficient: should probably have a getBulkWithMetadata
+ } else {
+ result.add((InternalCacheEntry) e.getValue());
+ }
}
return result;
}
+
+ public void setInternalCacheEntryFactory(InternalEntryFactory iceFactory) {
+ if (this.iceFactory != null) {
+ throw new IllegalStateException();
+ }
+ this.iceFactory = iceFactory;
+ }
}
@@ -45,7 +45,7 @@
* Parameters:
* <ul>
* <li>HotRodClientPropertiesFile-the file that contains the configuration of Hot Rod client. See <a href="http://community.jboss.org/wiki/JavaHotRodclient">Hotrod Java Client</a>
- * for more details on the Hot Rod client.
+ * for more details on the Hot Rod client.
* <li>remoteCacheName-the name of the remote cache in the remote infinispan cluster, to which to connect to</li>
* <li>UseDefaultRemoteCache-if set to true, the default remote cache will be used, as obtained by {@link org.infinispan.manager.CacheContainer#getCache()}.
* </ul>
@@ -56,6 +56,7 @@
public class RemoteCacheStoreConfig extends AbstractCacheStoreConfig {
private volatile String remoteCacheName;
+ private boolean rawValues;
private static final Log log = LogFactory.getLog(RemoteCacheStoreConfig.class);
private final Properties hotRodClientProperties = new Properties();
private ExecutorFactory asyncExecutorFactory = null;
@@ -73,6 +74,15 @@ public String getRemoteCacheName() {
return remoteCacheName;
}
+ public void setRawValues(boolean rawValues) {
+ this.rawValues = rawValues;
+ setProperty("rawValues", Boolean.toString(rawValues));
+ }
+
+ public boolean isRawValues() {
+ return rawValues;
+ }
+
public void setUseDefaultRemoteCache(boolean useDefaultRemoteCache) {
if (useDefaultRemoteCache) {
setRemoteCacheName(BasicCacheContainer.DEFAULT_CACHE_NAME);
@@ -91,6 +91,11 @@ public RemoteCacheStoreConfigurationBuilder protocolVersion(String protocolVersi
return builder.protocolVersion(protocolVersion);
}
+ @Override
+ public RemoteCacheStoreConfigurationBuilder rawValues(boolean rawValues) {
+ return builder.rawValues(rawValues);
+ }
+
@Override
public RemoteCacheStoreConfigurationBuilder remoteCacheName(String remoteCacheName) {
return builder.remoteCacheName(remoteCacheName);
@@ -47,6 +47,7 @@
PING_ON_STARTUP("pingOnStartup"),
PORT("port"),
PROTOCOL_VERSION("protocolVersion"),
+ RAW_VALUES("rawValues"),
REMOTE_CACHE_NAME("remoteCacheName"),
SOCKET_TIMEOUT("socketTimeout"),
TCP_NO_DELAY("tcpNoDelay"),
@@ -45,6 +45,7 @@
private final String marshaller;
private final boolean pingOnStartup;
private final String protocolVersion;
+ private final boolean rawValues;
private final String remoteCacheName;
private final List<RemoteServerConfiguration> servers;
private final long socketTimeout;
@@ -54,7 +55,7 @@
RemoteCacheStoreConfiguration(ExecutorFactoryConfiguration asyncExecutorFactory, String balancingStrategy,
ConnectionPoolConfiguration connectionPool, long connectionTimeout, boolean forceReturnValues,
- int keySizeEstimate, String marshaller, boolean pingOnStartup, String protocolVersion, String remoteCacheName,
+ int keySizeEstimate, String marshaller, boolean pingOnStartup, String protocolVersion, boolean rawValues, String remoteCacheName,
List<RemoteServerConfiguration> servers, long socketTimeout, boolean tcpNoDelay, String transportFactory,
int valueSizeEstimate, boolean purgeOnStartup, boolean purgeSynchronously, int purgerThreads,
boolean fetchPersistentState, boolean ignoreModifications, TypedProperties properties,
@@ -70,6 +71,7 @@
this.marshaller = marshaller;
this.pingOnStartup = pingOnStartup;
this.protocolVersion = protocolVersion;
+ this.rawValues = rawValues;
this.remoteCacheName = remoteCacheName;
this.servers = Collections.unmodifiableList(servers);
this.socketTimeout = socketTimeout;
@@ -114,6 +116,10 @@ public String protocolVersion() {
return protocolVersion;
}
+ public boolean rawValues() {
+ return rawValues;
+ }
+
public String remoteCacheName() {
return remoteCacheName;
}
@@ -145,6 +151,7 @@ public RemoteCacheStoreConfig adapt() {
LegacyConfigurationAdaptor.adapt(this, config);
// RemoteCacheStoreConfiguration
+ config.setRawValues(rawValues);
config.setRemoteCacheName(remoteCacheName);
config.setAsyncExecutorFactory(asyncExecutorFactory.factory());
@@ -49,6 +49,7 @@
private String marshaller;
private boolean pingOnStartup = true;
private String protocolVersion;
+ private boolean rawValues;
private String remoteCacheName = BasicCacheContainer.DEFAULT_CACHE_NAME;
private List<RemoteServerConfigurationBuilder> servers = new ArrayList<RemoteServerConfigurationBuilder>();
private long socketTimeout = ConfigurationProperties.DEFAULT_SO_TIMEOUT;
@@ -125,6 +126,12 @@ public RemoteCacheStoreConfigurationBuilder protocolVersion(String protocolVersi
return this;
}
+ @Override
+ public RemoteCacheStoreConfigurationBuilder rawValues(boolean rawValues) {
+ this.rawValues = rawValues;
+ return this;
+ }
+
@Override
public RemoteCacheStoreConfigurationBuilder remoteCacheName(String remoteCacheName) {
this.remoteCacheName = remoteCacheName;
@@ -176,7 +183,7 @@ public RemoteCacheStoreConfiguration create() {
}
return new RemoteCacheStoreConfiguration(asyncExecutorFactory.create(), balancingStrategy,
connectionPool.create(), connectionTimeout, forceReturnValues, keySizeEstimate, marshaller, pingOnStartup,
- protocolVersion, remoteCacheName, remoteServers, socketTimeout, tcpNoDelay, transportFactory,
+ protocolVersion, rawValues, remoteCacheName, remoteServers, socketTimeout, tcpNoDelay, transportFactory,
valueSizeEstimate, purgeOnStartup, purgeSynchronously, purgerThreads, fetchPersistentState,
ignoreModifications, TypedProperties.toTypedProperties(properties), async.create(), singletonStore.create());
}
@@ -192,6 +199,7 @@ public RemoteCacheStoreConfigurationBuilder read(RemoteCacheStoreConfiguration t
this.marshaller = template.marshaller();
this.pingOnStartup = template.pingOnStartup();
this.protocolVersion = template.protocolVersion();
+ this.rawValues = template.rawValues();
this.remoteCacheName = template.remoteCacheName();
this.socketTimeout = template.socketTimeout();
this.tcpNoDelay = template.tcpNoDelay();
@@ -18,8 +18,11 @@
*/
package org.infinispan.loaders.remote.configuration;
+import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.impl.transport.TransportFactory;
import org.infinispan.configuration.cache.StoreConfigurationChildBuilder;
+import org.infinispan.container.entries.InternalCacheEntry;
+import org.infinispan.loaders.remote.RemoteCacheStore;
import org.infinispan.marshall.Marshaller;
public interface RemoteCacheStoreConfigurationChildBuilder<S> extends StoreConfigurationChildBuilder<S> {
@@ -85,6 +88,13 @@
*/
RemoteCacheStoreConfigurationBuilder protocolVersion(String protocolVersion);
+ /**
+ * Normally the {@link RemoteCacheStore} stores values wrapped in {@link InternalCacheEntry}. Setting
+ * this property to true causes the raw values to be stored instead for interoperability with direct
+ * access by {@link RemoteCacheManager}s
+ */
+ RemoteCacheStoreConfigurationBuilder rawValues(boolean rawValues);
+
/**
* The name of the remote cache in the remote infinispan cluster, to which to connect to. If
* unspecified, the default cache will be used
@@ -248,6 +248,10 @@ private void parseRemoteStoreAttributes(XMLExtendedStreamReader reader, RemoteCa
builder.protocolVersion(value);
break;
}
+ case RAW_VALUES: {
+ builder.rawValues(Boolean.parseBoolean(value));
+ break;
+ }
case REMOTE_CACHE_NAME: {
builder.remoteCacheName(value);
break;
@@ -97,6 +97,14 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
+ <xs:attribute name="rawValues" type="xs:boolean" default="false">
+ <xs:annotation>
+ <xs:documentation>
+ Normally the RemoteCacheStore stores values wrapped in InternalCacheEntry. Setting this property to true causes the raw values to be stored instead for interoperability with direct
+ access by RemoteCacheManager. Defaults to false (disabled)
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
<xs:attribute name="remoteCacheName" type="xs:string">
<xs:annotation>
<xs:documentation>
@@ -24,6 +24,7 @@
import org.infinispan.Cache;
import org.infinispan.client.hotrod.TestHelper;
+import org.infinispan.client.hotrod.test.HotRodClientTestingUtil;
import org.infinispan.loaders.CacheLoader;
import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.DefaultCacheManager;
@@ -91,10 +92,7 @@ public void call() {
@AfterTest(alwaysRun = true)
public void tearDown() {
- try {
- if (hotRodServer != null) hotRodServer.stop();
- } finally {
- if (cacheManager != null) cacheManager.stop();
- }
+ HotRodClientTestingUtil.killServers(hotRodServer);
+ TestingUtil.killCacheManagers(cacheManager);
}
}
@@ -23,6 +23,7 @@
package org.infinispan.loaders.remote;
import org.infinispan.client.hotrod.TestHelper;
+import org.infinispan.client.hotrod.test.HotRodClientTestingUtil;
import org.infinispan.loaders.BaseCacheStoreFunctionalTest;
import org.infinispan.loaders.CacheStoreConfig;
import org.infinispan.manager.CacheContainer;
@@ -60,7 +61,7 @@ protected CacheStoreConfig createCacheStoreConfig() throws Exception {
@AfterMethod(alwaysRun = true)
public void tearDown() {
- hrServer.stop();
+ HotRodClientTestingUtil.killServers(hrServer);
TestingUtil.killCacheManagers(localCacheManager);
}
Oops, something went wrong.

0 comments on commit 91e927b

Please sign in to comment.