Partitioned Data Caching Example

Partitioned Data Caching Example

If a data set is too large for one member to hold, you can store it in more than one member and work with it as if it were a single entity.

You set up a partitioned region by creating region instances with the same name in all members that will hold the data, and enable partitioning during region creation. GemFire handles the physical location of data in the members that participate in a partitioned region.

You can configure your partitioned region to store redundant copies of each member's data in other members where the region is defined. This way, every data entry is hosted by multiple members, giving the region seamless high availability in the case of a member failure.

Running the Example

In this example, two members have the same partitioned region configured, with one extra copy of data entries. The example creates three entries in the partitioned region and reads them, then destroys an entry, invalidates an entry, and reads them all again.

Note: To run this example, you must have terminal sessions configured for the QuickStart examples, as described in Setting Up Your Environment for Running the Examples.
  1. In one session, start the first member:

    $ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.PartitionedRegionVM1
  2. When the first member tells you to do so, in the other session, start the second member:

    $ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.PartitionedRegionVM2

    This example deliberately compromises redundancy by closing PartitionedRegionVM2. Because of this, you will see this warning from PartitionedRegionVM1:

    [warning 2008/09/08 11:34:41.587 PDT PartitionedRegion /PartitionedRegion 
        Message Processor1> tid=0x2b]
    Redundancy has dropped below 1 configured copy to 0 actual copies for 

Example Source Files

Program and cache configuration source files for the partitioned region shared by JVMs 1 and 2, which use the same cache XML configuration file.

Table 1. Cache configuration files, located in SampleCode/quickstart/xml
PartitionedRegion.xml Configures the partitioned region.

Table 2. Java program files, located in SampleCode/quickstart/quickstart The initial member, which creates entries in the partitioned region then destroys them. The second member, which reads entries from the partitioned region.

Related Javadocs

See also:
  • com.gemstone.gemfire.cache.CacheFactory
  • com.gemstone.gemfire.cache.Region
  • com.gemstone.gemfire.cache.PartitionAttributes
  • com.gemstone.gemfire.cache.PartitionAttributesFactory
  • PARTITION_REDUNDANT in com.gemstone.gemfire.cache.RegionShortcut
  • PartitionAttributes in com.gemstone.gemfire.cache.RegionFactory