[infinispan-commits] Infinispan SVN: r127 - in trunk/core/src: main/java/org/infinispan/config/parsing and 6 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Apr 15 10:35:06 EDT 2009
Author: manik.surtani at jboss.com
Date: 2009-04-15 10:35:02 -0400 (Wed, 15 Apr 2009)
New Revision: 127
Added:
trunk/core/src/main/java/org/infinispan/interceptors/DistributionInterceptor.java
Modified:
trunk/core/src/main/java/org/infinispan/config/Configuration.java
trunk/core/src/main/java/org/infinispan/config/parsing/XmlConfigurationParserImpl.java
trunk/core/src/main/java/org/infinispan/distribution/ConsistentHash.java
trunk/core/src/main/java/org/infinispan/distribution/DefaultConsistentHash.java
trunk/core/src/main/java/org/infinispan/distribution/DistributionManager.java
trunk/core/src/main/java/org/infinispan/distribution/DistributionManagerImpl.java
trunk/core/src/main/resources/config-samples/all.xml
trunk/core/src/main/resources/schema/infinispan-config-4.0.xsd
trunk/core/src/test/java/org/infinispan/config/parsing/ConfigurationParserTest.java
trunk/core/src/test/java/org/infinispan/config/parsing/XmlFileParsingTest.java
trunk/core/src/test/resources/configs/named-cache-test.xml
Log:
[ISPN-30] (DIST - Distributed cache) Configuration changes for DIST, plus some basic classes and interfaces
Modified: trunk/core/src/main/java/org/infinispan/config/Configuration.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/Configuration.java 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/main/java/org/infinispan/config/Configuration.java 2009-04-15 14:35:02 UTC (rev 127)
@@ -27,6 +27,7 @@
import org.infinispan.factories.annotations.Start;
import org.infinispan.lock.IsolationLevel;
import org.infinispan.util.ReflectionUtil;
+import org.infinispan.distribution.DefaultConsistentHash;
import java.util.Collections;
import java.util.List;
@@ -100,9 +101,19 @@
/**
* Data invalidated asynchronously.
*/
- INVALIDATION_ASYNC;
+ INVALIDATION_ASYNC,
/**
+ * Synchronous DIST
+ */
+ DIST_SYNC,
+
+ /**
+ * Async DIST
+ */
+ DIST_ASYNC;
+
+ /**
* Returns true if the mode is invalidation, either sync or async.
*/
public boolean isInvalidation() {
@@ -110,12 +121,42 @@
}
public boolean isSynchronous() {
- return this == REPL_SYNC || this == INVALIDATION_SYNC || this == LOCAL;
+ return this == REPL_SYNC || this == DIST_SYNC || this == INVALIDATION_SYNC || this == LOCAL;
}
public boolean isClustered() {
return this != LOCAL;
}
+
+ public boolean isDistributed() {
+ return this == DIST_SYNC || this == DIST_ASYNC;
+ }
+
+ public CacheMode toSync() {
+ switch (this) {
+ case REPL_ASYNC:
+ return REPL_SYNC;
+ case INVALIDATION_ASYNC:
+ return INVALIDATION_SYNC;
+ case DIST_ASYNC:
+ return DIST_SYNC;
+ default:
+ return this;
+ }
+ }
+
+ public CacheMode toAsync() {
+ switch (this) {
+ case REPL_SYNC:
+ return REPL_ASYNC;
+ case INVALIDATION_SYNC:
+ return INVALIDATION_ASYNC;
+ case DIST_SYNC:
+ return DIST_ASYNC;
+ default:
+ return this;
+ }
+ }
}
// ------------------------------------------------------------------------------------------------------------
@@ -153,6 +194,12 @@
private int evictionMaxEntries = -1;
private long expirationLifespan = -1;
private long expirationMaxIdle = -1;
+ private boolean l1CacheEnabled = true;
+ private long l1Lifespan = 600000;
+ private boolean l1OnRehash = true;
+ private String consistentHashClass = DefaultConsistentHash.class.getName();
+ private int numOwners = 2;
+ private long rehashWaitTime = 60000;
@Start(priority = 1)
private void correctIsolationLevels() {
@@ -372,6 +419,36 @@
this.useAsyncSerialization = useAsyncSerialization;
}
+ public void setL1CacheEnabled(boolean l1CacheEnabled) {
+ testImmutability("l1CacheEnabled");
+ this.l1CacheEnabled = l1CacheEnabled;
+ }
+
+ public void setL1Lifespan(long l1Lifespan) {
+ testImmutability("l1Lifespan");
+ this.l1Lifespan = l1Lifespan;
+ }
+
+ public void setL1OnRehash(boolean l1OnRehash) {
+ testImmutability("l1OnRehash");
+ this.l1OnRehash = l1OnRehash;
+ }
+
+ public void setConsistentHashClass(String consistentHashClass) {
+ testImmutability("consistentHashClass");
+ this.consistentHashClass = consistentHashClass;
+ }
+
+ public void setNumOwners(int numOwners) {
+ testImmutability("numOwners");
+ this.numOwners = numOwners;
+ }
+
+ public void setRehashWaitTime(long rehashWaitTime) {
+ testImmutability("rehashWaitTime");
+ this.rehashWaitTime = rehashWaitTime;
+ }
+
// ------------------------------------------------------------------------------------------------------------
// GETTERS
// ------------------------------------------------------------------------------------------------------------
@@ -445,6 +522,30 @@
return useLazyDeserialization;
}
+ public boolean isL1CacheEnabled() {
+ return l1CacheEnabled;
+ }
+
+ public long getL1Lifespan() {
+ return l1Lifespan;
+ }
+
+ public boolean isL1OnRehash() {
+ return l1OnRehash;
+ }
+
+ public String getConsistentHashClass() {
+ return consistentHashClass;
+ }
+
+ public int getNumOwners() {
+ return numOwners;
+ }
+
+ public long getRehashWaitTime() {
+ return rehashWaitTime;
+ }
+
// ------------------------------------------------------------------------------------------------------------
// HELPERS
// ------------------------------------------------------------------------------------------------------------
@@ -468,7 +569,12 @@
if (exposeJmxStatistics != that.exposeJmxStatistics) return false;
if (fetchInMemoryState != that.fetchInMemoryState) return false;
if (invocationBatchingEnabled != that.invocationBatchingEnabled) return false;
+ if (l1CacheEnabled != that.l1CacheEnabled) return false;
+ if (l1Lifespan != that.l1Lifespan) return false;
+ if (rehashWaitTime != that.rehashWaitTime) return false;
+ if (l1OnRehash != that.l1OnRehash) return false;
if (lockAcquisitionTimeout != that.lockAcquisitionTimeout) return false;
+ if (numOwners != that.numOwners) return false;
if (replQueueInterval != that.replQueueInterval) return false;
if (replQueueMaxElements != that.replQueueMaxElements) return false;
if (stateRetrievalTimeout != that.stateRetrievalTimeout) return false;
@@ -483,6 +589,8 @@
if (cacheLoaderManagerConfig != null ? !cacheLoaderManagerConfig.equals(that.cacheLoaderManagerConfig) : that.cacheLoaderManagerConfig != null)
return false;
if (cacheMode != that.cacheMode) return false;
+ if (consistentHashClass != null ? !consistentHashClass.equals(that.consistentHashClass) : that.consistentHashClass != null)
+ return false;
if (customInterceptors != null ? !customInterceptors.equals(that.customInterceptors) : that.customInterceptors != null)
return false;
if (evictionStrategy != that.evictionStrategy) return false;
@@ -524,6 +632,12 @@
result = 31 * result + evictionMaxEntries;
result = 31 * result + (int) (expirationLifespan ^ (expirationLifespan >>> 32));
result = 31 * result + (int) (expirationMaxIdle ^ (expirationMaxIdle >>> 32));
+ result = 31 * result + (l1CacheEnabled ? 1 : 0);
+ result = 31 * result + (int) (l1Lifespan ^ (l1Lifespan >>> 32));
+ result = 31 * result + (int) (rehashWaitTime ^ (rehashWaitTime >>> 32));
+ result = 31 * result + (l1OnRehash ? 1 : 0);
+ result = 31 * result + (consistentHashClass != null ? consistentHashClass.hashCode() : 0);
+ result = 31 * result + numOwners;
return result;
}
Modified: trunk/core/src/main/java/org/infinispan/config/parsing/XmlConfigurationParserImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/parsing/XmlConfigurationParserImpl.java 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/main/java/org/infinispan/config/parsing/XmlConfigurationParserImpl.java 2009-04-15 14:35:02 UTC (rev 127)
@@ -8,10 +8,10 @@
import org.infinispan.config.GlobalConfiguration;
import org.infinispan.config.parsing.element.CustomInterceptorsElementParser;
import org.infinispan.config.parsing.element.LoadersElementParser;
+import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.lock.IsolationLevel;
import org.infinispan.transaction.GenericTransactionManagerLookup;
import org.infinispan.util.FileLookup;
-import org.infinispan.eviction.EvictionStrategy;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -113,7 +113,11 @@
namedCaches = null;
throw new DuplicateCacheNameException("Named cache " + configurationName + " is declared more than once!");
}
- namedCaches.put(configurationName, parseConfiguration(e));
+ try {
+ namedCaches.put(configurationName, parseConfiguration(e));
+ } catch (ConfigurationException ce) {
+ throw new ConfigurationException("Problems configuring named cache '" + configurationName + "'", ce);
+ }
}
}
@@ -166,13 +170,15 @@
void configureClustering(Element e, Configuration config) {
if (e == null) return; //we might not have this configured
- // there are 2 attribs - mode and clusterName
- boolean repl = true;
+
+ Configuration.CacheMode cacheMode;
String mode = getAttributeValue(e, "mode").toUpperCase();
if (mode.startsWith("R"))
- repl = true;
+ cacheMode = Configuration.CacheMode.REPL_SYNC;
else if (mode.startsWith("I"))
- repl = false;
+ cacheMode = Configuration.CacheMode.INVALIDATION_SYNC;
+ else
+ cacheMode = Configuration.CacheMode.DIST_SYNC; // the default
Element asyncEl = getSingleElementInCoreNS("async", e);
Element syncEl = getSingleElementInCoreNS("sync", e);
@@ -180,16 +186,43 @@
throw new ConfigurationException("Cannot have sync and async elements within the same cluster element!");
boolean sync = asyncEl == null; // even if both are null, we default to sync
if (sync) {
- config.setCacheMode(repl ? Configuration.CacheMode.REPL_SYNC : Configuration.CacheMode.INVALIDATION_SYNC);
+ config.setCacheMode(cacheMode);
configureSyncMode(syncEl, config);
} else {
- config.setCacheMode(repl ? Configuration.CacheMode.REPL_ASYNC : Configuration.CacheMode.INVALIDATION_ASYNC);
+ cacheMode = cacheMode.toAsync(); // get the async version of this mode
+ config.setCacheMode(cacheMode);
configureAsyncMode(asyncEl, config);
}
- String cn = getAttributeValue(e, "clusterName");
-// if (existsAttribute(cn)) config.setClusterName(cn);
- configureStateRetrieval(getSingleElementInCoreNS("stateRetrieval", e), config);
-// configureTransport(getSingleElementInCoreNS("jgroupsConfig", e), config);
+
+ if (cacheMode.isDistributed()) {
+ // L1 cache
+ Element l1 = getSingleElementInCoreNS("l1", e);
+ String tmp = getAttributeValue(l1, "enabled");
+ if (existsAttribute(tmp)) config.setL1CacheEnabled(getBoolean(tmp));
+ tmp = getAttributeValue(l1, "lifespan");
+ if (existsAttribute(tmp)) config.setL1Lifespan(getLong(tmp));
+ tmp = getAttributeValue(l1, "onRehash");
+ if (existsAttribute(tmp)) config.setL1OnRehash(getBoolean(tmp));
+
+ // consistent hash algo
+ Element hash = getSingleElementInCoreNS("hash", e);
+ tmp = getAttributeValue(hash, "class");
+ if (existsAttribute(tmp)) config.setConsistentHashClass(tmp);
+ tmp = getAttributeValue(hash, "numOwners");
+ if (existsAttribute(tmp)) config.setNumOwners(getInt(tmp));
+ tmp = getAttributeValue(hash, "rehashWait");
+ if (existsAttribute(tmp)) config.setRehashWaitTime(getLong(tmp));
+
+ config.setFetchInMemoryState(false);
+
+ // sanity check against the presence of a stateRetrieval element
+ if (getSingleElementInCoreNS("stateRetrieval", e) != null)
+ throw new ConfigurationException("stateRetrieval cannot be used with cache mode 'DISTRIBUTION'!");
+ } else {
+ configureStateRetrieval(getSingleElementInCoreNS("stateRetrieval", e), config);
+ if (getSingleElementInCoreNS("l1", e) != null || getSingleElementInCoreNS("hash", e) != null)
+ throw new ConfigurationException("l1 and hash elements cannot be used with cache modes 'REPLICATION' and 'INVALIDATION'!");
+ }
}
void configureStateRetrieval(Element element, Configuration config) {
Modified: trunk/core/src/main/java/org/infinispan/distribution/ConsistentHash.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/distribution/ConsistentHash.java 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/main/java/org/infinispan/distribution/ConsistentHash.java 2009-04-15 14:35:02 UTC (rev 127)
@@ -14,6 +14,8 @@
*/
public interface ConsistentHash {
+ void setCaches(Collection<Address> caches);
+
List<Address> locate(Object key, int replCount);
Map<Object, List<Address>> locate(Collection<Object> keys, int replCount);
Modified: trunk/core/src/main/java/org/infinispan/distribution/DefaultConsistentHash.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/distribution/DefaultConsistentHash.java 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/main/java/org/infinispan/distribution/DefaultConsistentHash.java 2009-04-15 14:35:02 UTC (rev 127)
@@ -14,8 +14,21 @@
public class DefaultConsistentHash implements ConsistentHash {
private SortedMap<Integer, Address> caches = new TreeMap<Integer, Address>();
- private final static int HASH_SPACE = 10000; // must be > max number of nodes in a cluster
+ // must be > max number of nodes in a cluster. Assume no more than a million nodes in a cluster? :-)
+ private final static int HASH_SPACE = 1000000;
+
+ public void setCaches(Collection<Address> caches) {
+ this.caches.clear();
+ // evenly distribute the caches across this space.
+ int increaseFactor = HASH_SPACE / caches.size();
+ int nextIndex = increaseFactor;
+ for (Address a: caches) {
+ this.caches.put(nextIndex, a);
+ nextIndex += increaseFactor;
+ }
+ }
+
public List<Address> locate(Object key, int replicationCount) {
int hash = Math.abs(key.hashCode());
int index = hash % HASH_SPACE;
Modified: trunk/core/src/main/java/org/infinispan/distribution/DistributionManager.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/distribution/DistributionManager.java 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/main/java/org/infinispan/distribution/DistributionManager.java 2009-04-15 14:35:02 UTC (rev 127)
@@ -2,7 +2,11 @@
import org.infinispan.factories.scopes.Scope;
import org.infinispan.factories.scopes.Scopes;
+import org.infinispan.remoting.transport.Address;
+import java.util.List;
+import java.util.Map;
+
/**
* A component that manages the distribution of elements across a cache cluster
*
@@ -14,10 +18,24 @@
void rehash();
- ConsistentHash getConsistentHash();
-
boolean isLocal(Object key);
- Object retrieveFromRemote(Object key) throws Exception;
+ /**
+ * Locates a key in a cluster. The returned addresses <i>may not</i> be owners of the keys if a rehash happens to
+ * be in progress or is pending, so when querying these servers, invalid responses should be checked for and the
+ * next address checked accordingly.
+ * @param key key to test
+ * @return a list of addresses where the key may reside
+ */
+ List<Address> locate(Object key);
+
+ /**
+ * Locates a list of keys in a cluster. Like {@link #locate(Object)} the returned addresses <i>may not</i> be owners
+ * of the keys if a rehash happens to be in progress or is pending, so when querying these servers, invalid responses
+ * should be checked for and the next address checked accordingly.
+ * @param keys list of keys to test
+ * @return a list of addresses where the key may reside
+ */
+ Map<Object, List<Address>> locate(List<Object> keys);
}
Modified: trunk/core/src/main/java/org/infinispan/distribution/DistributionManagerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/distribution/DistributionManagerImpl.java 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/main/java/org/infinispan/distribution/DistributionManagerImpl.java 2009-04-15 14:35:02 UTC (rev 127)
@@ -1,14 +1,14 @@
package org.infinispan.distribution;
import org.infinispan.Cache;
-import org.infinispan.commands.remote.ClusteredGetCommand;
import org.infinispan.config.Configuration;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.factories.annotations.Start;
-import org.infinispan.remoting.ResponseMode;
import org.infinispan.remoting.RpcManager;
+import org.infinispan.remoting.transport.Address;
import java.util.List;
+import java.util.Map;
/**
* // TODO: Manik: Document this
@@ -41,23 +41,15 @@
// TODO: Customise this generated block
}
- public ConsistentHash getConsistentHash() {
- return consistentHash;
- }
-
public boolean isLocal(Object key) {
return consistentHash.locate(key, replCount).contains(rpcManager.getLocalAddress());
}
- public Object retrieveFromRemote(Object key) throws Exception {
- // do a clustered get, unicast to the specific servers
- ClusteredGetCommand command = new ClusteredGetCommand(key, cache.getName());
- List<Object> responses = rpcManager.invokeRemotely(consistentHash.locate(key, replCount), command, ResponseMode.SYNCHRONOUS,
- configuration.getSyncReplTimeout(), false);
- for (Object r: responses) {
- if (!(r instanceof Throwable))
- return r;
- }
- return null;
+ public List<Address> locate(Object key) {
+ return null; // TODO: Customise this generated block
}
+
+ public Map<Object, List<Address>> locate(List<Object> keys) {
+ return null; // TODO: Customise this generated block
+ }
}
Added: trunk/core/src/main/java/org/infinispan/interceptors/DistributionInterceptor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/interceptors/DistributionInterceptor.java (rev 0)
+++ trunk/core/src/main/java/org/infinispan/interceptors/DistributionInterceptor.java 2009-04-15 14:35:02 UTC (rev 127)
@@ -0,0 +1,16 @@
+package org.infinispan.interceptors;
+
+import org.infinispan.interceptors.base.BaseRpcInterceptor;
+import org.infinispan.distribution.DistributionManager;
+
+/**
+ * // TODO: Document this
+ *
+ * @author manik
+ * @since 4.0
+ */
+public class DistributionInterceptor extends BaseRpcInterceptor {
+
+ DistributionManager dm;
+
+}
Property changes on: trunk/core/src/main/java/org/infinispan/interceptors/DistributionInterceptor.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/core/src/main/resources/config-samples/all.xml
===================================================================
--- trunk/core/src/main/resources/config-samples/all.xml 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/main/resources/config-samples/all.xml 2009-04-15 14:35:02 UTC (rev 127)
@@ -124,7 +124,7 @@
</namedCache>
- <namedCache name="jdbcBackedCache">
+ <namedCache name="persistentCache">
<!--
Cache loaders.
@@ -143,19 +143,12 @@
<!--
We can have multiple cache loaders, which get chained
-->
- <loader class="org.infinispan.loader.jdbc.stringbased.JdbcStringBasedCacheStore" fetchPersistentState="true"
+ <loader class="org.infinispan.loader.file.FileCacheStore" fetchPersistentState="true"
ignoreModifications="true" purgeOnStartup="true">
<!-- See the documentation for more configuration examples and flags. -->
<properties>
- <property name="connectionFactoryClass" value="org.infinispan.loader.jdbc.connectionfactory.PooledConnectionFactory"/>
- <property name="connectionUrl" value="org.infinispan.loader.jdbc.connectionfactory.PooledConnectionFactory"/>
- <property name="userName" value="root"/>
- <property name="driverClass" value="org.dbms.Driver"/>
- <property name="idColumnType" value="VARCHAR2(256)"/>
- <property name="dataColumnType" value="BLOB"/>
- <property name="dropTableOnExit" value="false"/>
- <property name="createTableOnStart" value="true"/>
+ <property name="location" value="/tmp" />
</properties>
<singletonStore enabled="true" pushStateWhenCoordinator="true" pushStateTimeout="20000"/>
<async enabled="true" batchSize="1000" threadPoolSize="5"/>
@@ -164,6 +157,14 @@
</namedCache>
+ <namedCache name="distributedCache">
+ <clustering mode="distribution">
+ <sync />
+ <hash numOwners="3" rehashWait="120000" />
+ <l1 enabled="true" lifespan="600000" />
+ </clustering>
+ </namedCache>
+
<namedCache name="withReplicatinQueue">
<clustering>
<async useReplQueue="true" replQueueInterval="100" replQueueMaxElements="200"/>
Modified: trunk/core/src/main/resources/schema/infinispan-config-4.0.xsd
===================================================================
--- trunk/core/src/main/resources/schema/infinispan-config-4.0.xsd 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/main/resources/schema/infinispan-config-4.0.xsd 2009-04-15 14:35:02 UTC (rev 127)
@@ -30,8 +30,8 @@
</xs:complexType>
<xs:complexType name="sharedSerializationType">
- <xs:attribute name="objectInputStreamPoolSize" type="tns:positiveInteger"/>
- <xs:attribute name="objectOutputStreamPoolSize" type="tns:positiveInteger"/>
+ <xs:attribute name="objectInputStreamPoolSize" type="tns:positiveNumber"/>
+ <xs:attribute name="objectOutputStreamPoolSize" type="tns:positiveNumber"/>
<xs:attribute name="version" type="xs:string"/>
<xs:attribute name="marshallerClass" type="xs:string"/>
</xs:complexType>
@@ -71,12 +71,14 @@
<xs:element name="sync" type="tns:syncType" minOccurs="0" maxOccurs="1"/>
<xs:element name="async" type="tns:asyncType" minOccurs="0" maxOccurs="1"/>
<xs:element name="stateRetrieval" type="tns:stateRetrievalType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="hash" type="tns:hashType" minOccurs="0" maxOccurs="1" />
+ <xs:element name="l1" type="tns:l1Type" minOccurs="0" maxOccurs="1" />
</xs:all>
<xs:attribute name="mode">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern
- value="[Rr][Ee][Pp][Ll][Ii][Cc][Aa][Tt][Ii][Oo][Nn]|[Ii][Nn][Vv][Aa][Ll][Ii][Dd][Aa][Tt][Ii][Oo][Nn]|[Rr]|[Ii]|\$\{.*\}"/>
+ value="[Rr][Ee][Pp][Ll][Ii][Cc][Aa][Tt][Ii][Oo][Nn]|[Ii][Nn][Vv][Aa][Ll][Ii][Dd][Aa][Tt][Ii][Oo][Nn]|[Dd][Ii][Ss][Tt][Rr][Ii][Bb][Uu][Tt][Ii][Oo][Nn]|[Rr]|[Ii]|[Dd]|[Rr][Ee][Pp][Ll]|[Ii][Nn][Vv][Aa][Ll]|[Dd][Ii][Ss][Tt]|\$\{.*\}"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
@@ -91,7 +93,7 @@
</xs:restriction>
</xs:simpleType>
</xs:attribute>
- <xs:attribute name="lockAcquisitionTimeout" type="tns:positiveInteger"/>
+ <xs:attribute name="lockAcquisitionTimeout" type="tns:positiveNumber"/>
<xs:attribute name="writeSkewCheck" type="tns:booleanType"/>
<xs:attribute name="useLockStriping" type="tns:booleanType"/>
<xs:attribute name="concurrencyLevel" type="xs:integer"/>
@@ -105,9 +107,21 @@
<xs:complexType name="stateRetrievalType">
<xs:attribute name="fetchInMemoryState" type="tns:booleanType"/>
- <xs:attribute name="timeout" type="tns:positiveInteger"/>
+ <xs:attribute name="timeout" type="tns:positiveNumber"/>
</xs:complexType>
+ <xs:complexType name="hashType">
+ <xs:attribute name="class" type="xs:string"/>
+ <xs:attribute name="numOwners" type="tns:positiveNumber"/>
+ <xs:attribute name="rehashWait" type="tns:positiveNumber"/>
+ </xs:complexType>
+
+ <xs:complexType name="l1Type">
+ <xs:attribute name="enabled" type="tns:booleanType"/>
+ <xs:attribute name="onRehash" type="tns:booleanType"/>
+ <xs:attribute name="lifespan" type="tns:positiveNumber"/>
+ </xs:complexType>
+
<xs:complexType name="shutdownType">
<xs:attribute name="hookBehavior">
<xs:simpleType>
@@ -125,7 +139,7 @@
</xs:restriction>
</xs:simpleType>
- <xs:simpleType name="positiveInteger">
+ <xs:simpleType name="positiveNumber">
<xs:restriction base="xs:string">
<xs:pattern value="\$\{.*\}|\+?[0-9]*"/>
</xs:restriction>
@@ -149,22 +163,22 @@
</xs:sequence>
<xs:attribute name="transportClass" type="xs:string"/>
<xs:attribute name="clusterName" type="xs:string"/>
- <xs:attribute name="distributedSyncTimeout" type="xs:long"/>
+ <xs:attribute name="distributedSyncTimeout" type="tns:positiveNumber"/>
</xs:complexType>
<xs:complexType name="syncType">
- <xs:attribute name="replTimeout" type="tns:positiveInteger"/>
+ <xs:attribute name="replTimeout" type="tns:positiveNumber"/>
</xs:complexType>
<xs:complexType name="asyncType">
<xs:attribute name="useReplQueue" type="tns:booleanType"/>
- <xs:attribute name="replQueueInterval" type="tns:positiveInteger"/>
- <xs:attribute name="replQueueMaxElements" type="tns:positiveInteger"/>
+ <xs:attribute name="replQueueInterval" type="tns:positiveNumber"/>
+ <xs:attribute name="replQueueMaxElements" type="tns:positiveNumber"/>
<xs:attribute name="useAsyncSerialization" type="tns:booleanType"/>
</xs:complexType>
<xs:complexType name="evictionType">
- <xs:attribute name="wakeUpInterval" type="tns:positiveInteger" use="required"/>
+ <xs:attribute name="wakeUpInterval" type="tns:positiveNumber" use="required"/>
<xs:attribute name="strategy">
<xs:simpleType>
<xs:restriction base="xs:string">
@@ -173,12 +187,12 @@
</xs:restriction>
</xs:simpleType>
</xs:attribute>
- <xs:attribute name="maxEntries" type="xs:positiveInteger"/>
+ <xs:attribute name="maxEntries" type="tns:positiveNumber"/>
</xs:complexType>
<xs:complexType name="expirationType">
- <xs:attribute name="lifespan" type="tns:positiveInteger"/>
- <xs:attribute name="maxIdle" type="xs:positiveInteger"/>
+ <xs:attribute name="lifespan" type="tns:positiveNumber"/>
+ <xs:attribute name="maxIdle" type="tns:positiveNumber"/>
</xs:complexType>
<xs:complexType name="loadersType">
@@ -191,16 +205,16 @@
<xs:complexType>
<xs:attribute name="enabled" type="tns:booleanType"/>
<xs:attribute name="pushStateWhenCoordinator" type="tns:booleanType"/>
- <xs:attribute name="pushStateTimeout" type="xs:positiveInteger"/>
+ <xs:attribute name="pushStateTimeout" type="tns:positiveNumber"/>
</xs:complexType>
</xs:element>
<xs:element name="async" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="enabled" type="tns:booleanType"/>
- <xs:attribute name="batchSize" type="xs:positiveInteger"/>
- <xs:attribute name="pollWait" type="xs:positiveInteger"/>
- <xs:attribute name="queueSize" type="xs:positiveInteger"/>
- <xs:attribute name="threadPoolSize" type="xs:positiveInteger"/>
+ <xs:attribute name="batchSize" type="tns:positiveNumber"/>
+ <xs:attribute name="pollWait" type="tns:positiveNumber"/>
+ <xs:attribute name="queueSize" type="tns:positiveNumber"/>
+ <xs:attribute name="threadPoolSize" type="tns:positiveNumber"/>
</xs:complexType>
</xs:element>
</xs:all>
@@ -239,7 +253,7 @@
</xs:attribute>
<xs:attribute name="before" type="xs:string"/>
<xs:attribute name="after" type="xs:string"/>
- <xs:attribute name="index" type="tns:positiveInteger"/>
+ <xs:attribute name="index" type="tns:positiveNumber"/>
</xs:complexType>
</xs:element>
</xs:sequence>
Modified: trunk/core/src/test/java/org/infinispan/config/parsing/ConfigurationParserTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/config/parsing/ConfigurationParserTest.java 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/test/java/org/infinispan/config/parsing/ConfigurationParserTest.java 2009-04-15 14:35:02 UTC (rev 127)
@@ -9,6 +9,7 @@
import org.infinispan.loader.file.FileCacheStoreConfig;
import org.infinispan.lock.IsolationLevel;
import org.infinispan.transaction.GenericTransactionManagerLookup;
+import org.infinispan.distribution.DefaultConsistentHash;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -144,10 +145,10 @@
Configuration c = new Configuration();
parser.configureClustering(e, c);
- assert c.getCacheMode() == Configuration.CacheMode.REPL_SYNC;
- assert c.getStateRetrievalTimeout() == 10000;
- assert c.isFetchInMemoryState();
+ assert c.getCacheMode() == Configuration.CacheMode.DIST_SYNC;
+ assert !c.isFetchInMemoryState();
assert !c.isUseReplQueue();
+ assert c.isL1CacheEnabled();
}
public void testCacheLoaders() throws Exception {
@@ -263,4 +264,42 @@
assert c.getExpirationLifespan() == 2000;
assert c.getExpirationMaxIdle() == 500;
}
+
+ public void testClusteringDist() throws Exception {
+ XmlConfigurationParserImpl parser = new XmlConfigurationParserImpl();
+ String xml = "<clustering mode=\"d\">\n" +
+ " <async />" +
+ " <l1 enabled=\"false\"/>\n" +
+ " <hash class=\"org.blah.Blah\" numOwners=\"900\" rehashWait=\"-1\" />" +
+ " </clustering>";
+ Element e = XmlConfigHelper.stringToElement(xml);
+
+ Configuration c = new Configuration();
+ parser.configureClustering(e, c);
+
+ assert c.getCacheMode() == Configuration.CacheMode.DIST_ASYNC;
+ assert !c.isFetchInMemoryState();
+ assert !c.isL1CacheEnabled();
+ assert c.getConsistentHashClass().equals("org.blah.Blah");
+ assert c.getNumOwners() == 900;
+ assert c.getRehashWaitTime() == -1;
+ }
+
+ public void testClusteringDistDefaults() throws Exception {
+ XmlConfigurationParserImpl parser = new XmlConfigurationParserImpl();
+ String xml = "<clustering mode=\"d\" />";
+ Element e = XmlConfigHelper.stringToElement(xml);
+
+ Configuration c = new Configuration();
+ parser.configureClustering(e, c);
+
+ assert c.getCacheMode() == Configuration.CacheMode.DIST_SYNC;
+ assert !c.isFetchInMemoryState();
+ assert c.isL1CacheEnabled();
+ assert c.getConsistentHashClass().equals(DefaultConsistentHash.class.getName());
+ assert c.getNumOwners() == 2;
+ assert c.getRehashWaitTime() == 60000;
+ assert c.getL1Lifespan() == 600000;
+ assert c.isL1OnRehash();
+ }
}
Modified: trunk/core/src/test/java/org/infinispan/config/parsing/XmlFileParsingTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/config/parsing/XmlFileParsingTest.java 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/test/java/org/infinispan/config/parsing/XmlFileParsingTest.java 2009-04-15 14:35:02 UTC (rev 127)
@@ -5,6 +5,7 @@
import org.infinispan.config.GlobalConfiguration;
import org.infinispan.loader.file.FileCacheStoreConfig;
import org.infinispan.lock.IsolationLevel;
+import org.infinispan.distribution.DefaultConsistentHash;
import org.testng.annotations.Test;
import java.io.IOException;
@@ -107,6 +108,14 @@
assert gc.isAllowDuplicateDomains();
assert gc.getJmxDomain().equals("funky_domain");
assert gc.getMBeanServerLookup().equals("org.infinispan.jmx.PerThreadMBeanServerLookup");
+
+ c = namedCaches.get("dist");
+ assert c.getCacheMode() == Configuration.CacheMode.DIST_SYNC;
+ assert c.getL1Lifespan() == 600000;
+ assert c.getRehashWaitTime() == 120000;
+ assert c.getConsistentHashClass().equals(DefaultConsistentHash.class.getName());
+ assert c.getNumOwners() == 3;
+ assert c.isL1CacheEnabled();
}
public void testConfigurationMerging() throws IOException {
Modified: trunk/core/src/test/resources/configs/named-cache-test.xml
===================================================================
--- trunk/core/src/test/resources/configs/named-cache-test.xml 2009-04-15 14:34:45 UTC (rev 126)
+++ trunk/core/src/test/resources/configs/named-cache-test.xml 2009-04-15 14:35:02 UTC (rev 127)
@@ -40,21 +40,21 @@
</namedCache>
<namedCache name="syncRepl">
- <clustering>
+ <clustering mode="repl">
<stateRetrieval fetchInMemoryState="false"/>
<sync replTimeout="15000"/>
</clustering>
</namedCache>
<namedCache name="asyncRepl">
- <clustering>
+ <clustering mode="repl">
<stateRetrieval fetchInMemoryState="false"/>
<async useAsyncSerialization="false"/>
</clustering>
</namedCache>
<namedCache name="asyncReplQueue">
- <clustering>
+ <clustering mode="repl">
<stateRetrieval fetchInMemoryState="false"/>
<async useReplQueue="true" replQueueInterval="1234" replQueueMaxElements="100"/>
</clustering>
@@ -62,7 +62,7 @@
<namedCache name="txSyncRepl">
<transaction/>
- <clustering>
+ <clustering mode="repl">
<stateRetrieval fetchInMemoryState="false"/>
<sync replTimeout="15000"/>
</clustering>
@@ -96,6 +96,14 @@
</loaders>
</namedCache>
+ <namedCache name="dist">
+ <clustering mode="distribution">
+ <sync />
+ <hash numOwners="3" rehashWait="120000" />
+ <l1 enabled="true" lifespan="600000" />
+ </clustering>
+ </namedCache>
+
<namedCache name="withouthJmxEnabled">
<clustering>
<async useReplQueue="true" replQueueInterval="100" replQueueMaxElements="200"/>
More information about the infinispan-commits
mailing list