Enabling Persistence

You can persist data structures and job snapshots on disk with some minimal configuration changes on your cluster.

Before you Begin

Configuration changes do not take effect until members are restarted. See Shutting Down Members and Clusters.

Learn about persistence in Hazelcast.

Step 1. Enable Persistence

By default, persistence is disabled on all clusters. To start persisting data on disk, you must first enable it in your configuration.

  • XML

  • YAML

  • Java

<hazelcast>
  <persistence enabled="true">
  </persistence>
</hazelcast>
hazelcast:
  persistence:
    enabled: true
Config config = new Config();

PersistenceConfig PersistenceConfig = new PersistenceConfig()
.setEnabled(true);

config.setPersistenceConfig(PersistenceConfig);

Step 2. Persist Map Entries

Even after enabling persistence, your members won’t start persisting any data until you configure maps, JCache data structures, or job snapshots to be persisted.

This example configures a member to persist entries on disk for a map called test-map.

  • XML

  • YAML

  • Java

<hazelcast>
  <persistence enabled="true">
  </persistence>
  <map name="test-map">
    <data-persistence enabled="true">
    </data-persistence>
  </map>
</hazelcast>
hazelcast:
  persistence:
    enabled: true
  map:
  test-map:
    data-persistence:
      enabled: true
Config config = new Config();

PersistenceConfig PersistenceConfig = new PersistenceConfig()
.setEnabled(true);

config.setPersistenceConfig(PersistenceConfig);

MapConfig mapConfig = config.getMapConfig("test-map");
mapConfig.getDataPersistenceConfig().setEnabled(true);
config.addMapConfig(mapConfig);

Next Steps

Explore all the options for configuring persistence.