Terracotta DB 10.1 | Ehcache API Developer Guide | Clustered Caches | Creating a Cluster with Multiple Stripes
 
Creating a Cluster with Multiple Stripes
Server-side tasks for setting up a Multi-Stripe Cluster
*Before you create a cluster, start at least one server on each of the stripes which are going to be part of the cluster.
*Use the configure command of the cluster tool to configure a cluster, specifying the Terracotta configuration file for all required stripes.
For more details about usage of the cluster tool, refer to the cluster tool documentation in the section The Cluster Tool.
Client Side Code
The client-side code for connecting to a cluster will be similar to the following:

PersistentCacheManager cacheManager =
CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create(
"terracotta://localhost:9410/multi-stripe-cm")).autoCreate()) // 1
.withCache("myCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(
Long.class, String.class, ResourcePoolsBuilder.heap(10)
.with(ClusteredResourcePoolBuilder.clusteredDedicated(
"primary-server-resource", 10, MemoryUnit.MB)))) // 2
.build(true);

Cache<Long, String> myCache = cacheManager.getCache("myCache",
Long.class, String.class);

myCache.put(42L, "Success!");
System.out.println(myCache.get(42L));
1
Connection to a multi-stripe cluster requires a URI with the host:port of all servers that belong to one of the stripes.
2
The size of the resource pool on each stripe is the total pool size divided by the numbers of stripes in the cluster.
*It's recommended to check the availability of resources across all stripes in the cluster before configuring a cache, otherwise cache creation will fail on the stripes with insufficient resources.
*Creating cluster with cluster tool is a mandatory first step, otherwise cache creation will succeed on only one of the stripes represented by the provided URI. Creating a cluster after creating clustered resources is not supported and will result in errors.

Copyright © 2010-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release