Persisting Data to Disk Example

Persistence creates a complete backup of the region data on disk, which gives you a highly available copy of your data. At region creation time, if the disk files are already present, the data is recovered from disk and used to initialize the region.

Running the Example

In this example, region data is persisted to the subdirectory persistData1. You run the example twice so you can see how the persisted data is loaded into the region on the second run.

Note: To run this example, you must have terminal sessions configured for the QuickStart examples, as described in Setting Up Your Environment.

  1. In a single session, run the example:

    $ java quickstart.DataPersistence

    No data is in the region on the first run, so the get operation returns null and the program reports that no entry was found. Then the program puts the entry with value, 'value1'.

  2. When the program exits, look in the persistData1 directory. You will see the data files used for persistence.

  3. Run the program again with the same command.

    The second time, at creation, the region is initialized from disk, so the get operation returns 'value1'.

Example Source Files

Program and cache configuration source files:

Table 1. Cache configuration files, located in $SamplesDirectory/quickstart/xml
DataPersistence.xml Configures a region to persist its data to disk. The data files are written to the directories specified in the disk-dirs elements.

Table 2. Java program files, located in $SamplesDirectory/quickstart/quickstart Demonstrates how to create persistent data and how the region is initialized from persistent data, if it exists.

Related Topics
Persistence and Overflow

Related Javadocs

See also:
  • com.gemstone.gemfire.cache.DiskStoreFactory
  • com.gemstone.gemfire.cache.DiskStore
  • options with PERSISTENT in com.gemstone.gemfire.cache.RegionShortcut