Infinispan's CassandraCacheStore leverages Apache Cassandra's distributed database architecture to provide a virtually unlimited, horizontally scalable persistent store for Infinispan's caches.
Version
The Cassandra CacheStore was added in Infinspan 4.2.0 "Ursus". You'll need this release or later in order to use it.
Configuration
In order to use this CacheStore you need to create an appropriate keyspace on your Cassandra database. The following storage-conf.xml excerpt shows the declaration of the keyspace:
<Keyspace Name="Infinispan">
<ColumnFamily CompareWith="BytesType" Name="InfinispanEntries" KeysCached="10%" />
<ColumnFamily CompareWith="LongType" Name="InfinispanExpiration" KeysCached="10%" ColumnType="Super" CompareSubcolumnsWith="BytesType"/>
<ColumnFamily CompareWith="BytesType" Name="InfinispanEntries" KeysCached="0" />
<ColumnFamily CompareWith="LongType" Name="InfinispanExpiration" KeysCached="0" ColumnType="Super" CompareSubcolumnsWith="BytesType"/>
<ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
<ReplicationFactor>2</ReplicationFactor>
<EndPointSnitch>org.apache.cassandra.locator.EndPointSnitch</EndPointSnitch>
</Keyspace>
The important bits are the CompareWith, ColumnType and CompareSubColumnsWith declarations. Everything else can be changed at will. You can also have more than one Keyspace to accomodate for multiple caches. Also bear in mind that the current version of the CassandraCacheStore only supports the OrderPreservingPartitioner.
You then need to add an appropriate cache declaration to your infinispan.xml (or whichever file you use to configure Infinispan):
<namedCache name="cassandraCache">
<loaders passivation="false" shared="true" preload="false">
<loader
class="org.infinispan.loaders.cassandra.CassandraCacheStore"
fetchPersistentState="true" ignoreModifications="false"
purgeOnStartup="false">
<properties>
<property name="host" value="localhost" />
<property name="keySpace" value="Infinispan" />
<property name="entryColumnFamily" value="InfinispanEntries" />
<property name="expirationColumnFamily" value="InfinispanExpiration" />
<property name="sharedKeyspace" value="false" />
<property name="readConsistencyLevel" value="ONE" />
<property name="writeConsistencyLevel" value="ONE" />
<property name="configurationPropertiesFile" value="cassandrapool.properties" />
<property name="keyMapper" value="org.infinispan.loaders.keymappers.DefaultTwoWayKey2StringMapper" />
</properties>
</loader>
</loaders>
</namedCache>
It is important the the shared property on the loader element is set to true because all the Infinispan nodes will share the same Cassandra cluster.
Since the Cassandra client library doesn't provide connection pooling, a separate project has been created at
http://github.com/tristantarrant/cassandra-connection-pool.
Configuration of the connection pool can be done by creating an appropriate properties file and specifying its name in the configuration (
configurationPropertiesFile).
The following is an example file:
socketTimeout = 5000
initialSize = 10
maxActive = 100
maxIdle = 20
minIdle = 10
maxWait = 30000testOnBorrow = false
testOnReturn = false
testWhileIdle = false
timeBetweenEvictionRunsMillis = 5000removeAbandoned = false
removeAbandonedTimeout = 60
logAbandoned = false
Here is a description of the various properties which can be configured:
host
|
a hostname (or a comma-separated list of hostnames)
|
port
|
the thrift port (usually 9160)
|
keySpace
|
the keyspace to use (defaults to Infinispan)
|
entryColumnFamily
|
the column family where entry values will be stored. Make sure you configure your keyspace accordingly (defaults to InfinispanEntries)
|
expirationColumnFamily
|
the column family where element expiration information is stored. Make sure your (defaults to InfinispanExpiration)
|
sharedKeyspace
|
whether multiple caches are to be stored in a single keyspace. In this case the cache name is prefixed to the key entries (defaults to false).
|
readConsistencyLevel
|
The consistency level to use when reading from Cassandra. Possible values are ONE, QUORUM, DCQUORUM, ALL. For an explanation of these refer to the Cassandra API documentation. (defaults to ONE)
|
writeConsistencyLevel
|
The consistency level to use when writing to Cassandra. Possible values are ZERO, ANY, ONE, QUORUM, DCQUORUM, ALL. For an explanation of these refer to the Cassandra API documentation. (defaults to ONE)
|
keyMapper
|
A class which implements Infinispan's TwoWayKey2StringMapper interface for mapping cache keys to Cassandra row keys (defaults to org.infinispan.loaders.keymappers.DefaultTwoWayKey2StringMapper)
|