Configuring a MapStore
This topic explains how to configure a map with a MapStore. It includes configuration options for loading data, as well as caching behaviors, and MapStore reuse.
Before you Begin
If you use Hazelcast in client/server mode, make sure to add the MapStore to the cluster’s classpath.
Quickstart Configuration
To configure a MapStore, you must provide the the name of your class that implements the MapStore.
Follow the instructions in Using the generic MapLoader or Using the generic MapStore for this step if you are using a pre-built Mapstore. |
<hazelcast>
...
<map name="default">
<map-store enabled="true">
<class-name>com.hazelcast.examples.DummyStore</class-name>
</map-store>
</map>
...
</hazelcast>
hazelcast:
map:
default:
map-store:
enabled: true
class-name: com.hazelcast.examples.DummyStore
MapConfig mapConfig = new MapConfig("default");
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setClassName("com.hazelcast.examples.DummyStore");
mapConfig.setMapStoreConfig(mapStoreConfig);
Configuring for Write-Behind Caching
To configure a MapStore to use write-behind caching, set the write-delay-seconds
configuration to a number greater than 0.
Configuring the Offloading of MapStore Operations
To improve cluster throughput, MapStore API calls, such as load()
and store()
operations, are offloaded by default. This way partition threads are not blocked by them.
Because each partition in a member is managed by a single thread, the write operations to a given partition are handled one at a time in first-in-first-out order. However, MapStore operations may take a long time to connect to the data store and complete, blocking the affected partitions. To avoid blocking partition threads, MapStore operations communicate with the data store asynchronously, using an executor.
|
You can configure the executor service that handles asynchronous MapStore operations.
The offload executor’s name is hz:map-store-offloadable
. You can configure the number of threads for this executor and its task queue capacity. See Configuring Executor Service for a guide.
Blocking Partition Threads
You can choose not to offload MapStore operations, which is the behavior in previous Hazelcast Platform releases before version 5.2. To block partition threads during MapStore API operations, set the offload
configuration to false
.
Delaying the Loading Process of a MapStore
By default, the MapStore is loaded as soon as the first cluster member starts. If you want the cluster to wait until a certain number of members are available, you can use the hazelcast.initial.min.cluster.size
system property. For example, if you set this value to 3
, the MapStore is not loaded until three cluster members are running.
Applying the Same MapStore to Multiple Maps
A MapStore can be applied to more than one map, using wildcards. But a MapStore does not know which entries to store when there is one configuration applied to multiple maps. To store entries when there is one configuration applied to multiple maps, use the Java MapStoreFactory
interface. Using the MapStoreFactory
interface, a MapStore for each map can be created when a wildcard configuration is used.
This option applies only to custom MapStore implementations, not the generic MapStore. |
To initialize the MapStore with the given map name, configuration properties, and Hazelcast instance, the MapStore must implement the MapLoaderLifecycleSupport
interface.
Config config = new Config();
MapConfig mapConfig = config.getMapConfig( "*" );
MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig();
mapStoreConfig.setFactoryImplementation( new MapStoreFactory<Object, Object>() {
@Override
public MapLoader<Object, Object> newMapStore( String mapName, Properties properties ) {
return null;
}
});
Configuration Options for All MapStores
Use these configuration options to configure the Mapstore for specific maps.
If you are using Java to configure the Mapstore, use the MapStoreConfig
object.
Option | Description | Default | Example | ||
---|---|---|---|---|---|
Whether the MapStore is enabled for the map. |
|
|
|||
Name of a class that implements the MapStore. |
|
|
|||
Whether MapStore operations are handled asychronously to avoid blocking partition threads. |
|
|
|||
Number of seconds of delay before the |
|
|
|||
Number of batches to group map entries into before writing them to the data store. By default, all map entries are written in one go. |
|
|
|||
When |
|
|
|||
The load mode for populating empty maps:
|
|
|
Related Resources
More configuration options:
-
For the generic MapStore, see Using the generic MapStore.
-
For the generic MapLoader, see Using the generic MapLoader.