Terracotta Logo (http://www.terracotta.org)

Terracotta Documentation Home

Terracotta 3.2.1 Documentation

Table of Contents •  Back  •  Forward


Register

1.1 Distributed Ehcache Express Installation

This document shows you how to add Terracotta clustering to an application that is using an Ehcache cache.

Use this express installation if you have been running your application:

To set up the cluster with Terracotta, you will add a Terracotta JAR to each application and run a Terracotta server array. Except as noted below, you can continue to use Ehcache in your application as specified in the Ehcache documentation .

To add Terracotta clustering to an application that is using Ehcache, follow these steps:

1.1.1 Step 1: Requirements

1.1.2 Step 2: Install the Distributed Cache

To install the distributed cache in your application, add the following JAR files to your application's classpath:

If you are using a WAR file, add these JAR files to its WEB-INF/lib directory.

NOTE: Application Servers

Most application servers (or web containers) should work with this installation of the Terracotta Distributed Cache. However, note the following:
- GlassFish application server – You must add the following to domains.xml :
<jvm-options>-Dcom.sun.enterprise.server.ss.ASQuickStartup=false</jvm-options>
- WebLogic application server – You must use the supported version of WebLogic.

1.1.3 Step 3: Configure the Distributed Cache

The Ehcache configuration file, ehcache.xml by default, must be on your application's classpath. If you are using a WAR file, add the Ehcache configuration file to WEB-INF/classes or to a JAR file that is included in WEB-INF/lib .

Create a basic Ehcache configuration file, ehcache.xml by default:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache name="myCache" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="ehcache.xsd">
   <defaultCache
      maxElementsInMemory="0"
      eternal="false"
      timeToIdleSeconds="1200"
      timeToLiveSeconds="1200">
          <terracotta />
   </defaultCache>
   <terracottaConfig url="localhost:9510" />
</ehcache>

This defaultCache configuration includes Terracotta clustering. The Terracotta client must load the configuration from a file or a Terracotta server. The value of the <terracottaConfig /> element’s url attribute should contain a path to the file or the address and DSO port (9510 by default) of a server. In the example value, "localhost:9510" means that the Terracotta server is on the local host.

TIP: Terracotta Clients and Servers

In a Terracotta cluster, the application server is also known as the client.

1.1.3a Add Terracotta to Specific Caches

For any cache that should be clustered by Terracotta, add the sub-element <terracotta /> to that cache's <cache> block in ehcache.xml . For example, the following cache is clustered with Terracotta:

<cache name="myCache" maxElementsInMemory="1000" 
       maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600" 
       timeToLiveSeconds="0" memoryStoreEvictionPolicy="LFU"> 
  <!-- Adding the element <terracotta /> turns on Terracotta clustering for the cache myCache. -->
  <terracotta /> 
</cache> 

1.1.3b Edit Incompatible Configuration

For any clustered cache, you must delete, disable, or edit configuration elements that are incompatible when clustering with Terracotta. Clustered caches have a <terracotta> or <terracotta clustered="true"> element.

The following Ehcache configuration attributes or elements should be deleted or disabled:

  • DiskStore-related attributes overflowToDisk and diskPersistent .
  • The Terracotta server automatically provides a disk store.

  • Replication-related attributes such as replicateAsynchronously and replicatePuts .
  • The attribute MemoryStoreEvictionPolicy must be set to either LFU or LRU.
  • Setting MemoryStoreEvictionPolicy to FIFO causes the error IllegalArgumentException .

1.1.4 Step 4: Start the Cluster

UNIX/Linux
[PROMPT] ${TERRACOTTA_HOME}/bin/start-tc-server.sh &
Microsoft Windows
[PROMPT] ${TERRACOTTA_HOME}\bin\start-tc-server.bat
  • 2. Start the application servers.
  • 3. Start the Terracotta Developer Console:
UNIX/Linux
[PROMPT] ${TERRACOTTA_HOME}/bin/dev-console.sh &
Microsoft Windows
[PROMPT] ${TERRACOTTA_HOME}\bin\dev-console.bat
  • 4. Connect to the Terracotta cluster.
  • Click Connect... in the Terracotta Developer Console.

Terracotta Developer Console Connection Panel

  • 5. Click the Ehcache node in the cluster navigation window to see the caches in the Terracotta cluster.
  • Your console should have a similar appearance to the following annotated figure.

Terracotta Developer Console With Ehcache Node

1.1.5 Step 5: Edit the Terracotta Configuration

This step shows you how to how run clients and servers on separate machines and add failover (High Availability). You will expand the Terracotta cluster and add High Availability by doing the following:

These tasks bring your cluster closer to a production architecture.

1.1.5a Procedure:

  • 1. Shut down the Terracotta cluster.
  • 2. Create a Terracotta configuration file called tc-config.xml with contents similar to the following:
<?xml version="1.0" encoding="UTF-8"?>
<!-- All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved. -->
<tc:tc-config xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-5.xsd" 
xmlns:tc="http://www.terracotta.org/config" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  
  <servers>
    <!-- Sets where the Terracotta server can be found. Replace the value of host with the server's IP address. -->
    <server host="server.1.ip.address" name="Server1">
      <data>%(user.home)/terracotta/server-data</data>
      <logs>%(user.home)/terracotta/server-logs</logs>
    </server>
    <!-- If using a standby Terracotta server, also referred to as an ACTIVE-PASSIVE configuration, add the second server here. -->
    <server host="server.2.ip.address" name="Server2">
      <data>%(user.home)/terracotta/server-data</data>
      <logs>%(user.home)/terracotta/server-logs</logs>
  </server>
<!-- If using more than one server, add an <ha> section. -->
    <ha>
      <mode>networked-active-passive</mode>
      <networked-active-passive>
        <election-time>5</election-time>
      </networked-active-passive>
    </ha>
  </servers>
  <!-- Sets where the generated client logs are saved on clients. Note that the exact location of Terracotta logs on client machines may vary based on the value of user.home and the local disk layout. -->  
  <clients>
    <logs>%(user.home)/terracotta/client-logs</logs>
  </clients>
</tc:tc-config>
  • 3. Install Terracotta 3.2.1 on a separate machine for each server you configure in tc-config.xml .
  • 4. Copy the tc-config.xml to a location accessible to the Terracotta servers.
  • 5. Perform Step 2: Install the Distributed Cache and Step 3: Configure the Distributed Cache on each application node you want to run in the cluster.
  • Be sure to install your application and any application servers on each node.

  • 6. Add the following to the Ehcache configuration file, ehcache.xml :
<!-- Add the servers that are configured in tc-config.xml. -->
<terracottaConfig url="server.1.ip.address:9510,server.2.ip.address:9510" />
  • 7. Copy ehcache.xml to each application node and ensure that it is on your application's classpath. If you are using a WAR file, add the Ehcache configuration file to WEB-INF/classes or to a JAR file that is included in WEB-INF/lib .
  • 8. Start the Terracotta server in the following way, replacing "Server1" with the name you gave your server in tc-config.xml :
UNIX/Linux
[PROMPT] ${TERRACOTTA_HOME}/bin/start-tc-server.sh -f <path/to/tc-config.xml> -n Server1 &
Microsoft Windows
[PROMPT] ${TERRACOTTA_HOME}\bin\start-tc-server.bat -f <path\to\tc-config.xml> -n Server1 &

    If you configured a second server, start that server in the same way on its machine, entering its name after the -n flag. The second server to start up becomes the "hot" standby, or PASSIVE. Any other servers you configured will also start up as standby servers.

  • 9. Start all application servers.
  • 10. Start the Terracotta Developer Console and view the cluster.

1.1.6 Step 6: Learn More

To learn more about using Terracotta Ehcache distributed cache, start with the following document:

To learn more about working with a Terracotta cluster, see the following documents:


Top of 1.1 Distributed Ehcache Express Installation