JBoss Community Archive (Read Only)

Infinispan 6.0

Cassandra CacheStore

Infinispan's CassandraCacheStore leverages Apache Cassandra's distributed database architecture to provide a virtually unlimited, horizontally scalable persistent store for Infinispan's caches.


The Cassandra CacheStore was added in Infinspan 4.2.0 "Ursus". You'll need this release or later in order to use it.


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"/>

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">
                        fetchPersistentState="true" ignoreModifications="false"
                                <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" />
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:


a hostname (or a comma-separated list of hostnames)


the thrift port (usually 9160)


the keyspace to use (defaults to Infinispan)


the column family where entry values will be stored. Make sure you configure your keyspace accordingly (defaults to InfinispanEntries)


the column family where element expiration information is stored. Make sure your  (defaults to InfinispanExpiration)


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).


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)


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)


A class which implements Infinispan's TwoWayKey2StringMapper interface for mapping cache keys to Cassandra row keys (defaults to org.infinispan.loaders.keymappers.DefaultTwoWayKey2StringMapper)

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-11 09:39:19 UTC, last content change 2013-03-07 14:18:39 UTC.