For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Distributed Maps

Create and use distributed maps in GridGain 9 to store key-value pairs, with synchronous and asynchronous put, get, remove, and destroy operations.

In GridGain 9, you can create distributed maps to store key-value pairs, where each key maps to a specific value or object. These maps enable efficient access to values by their unique keys. You can interact with these distributed maps by using either the synchronous or asynchronous API. Below is an example of how to create and use them:

By default, maps are created and stored in the default distribution zone and use the default storage engine for your cluster.

The examples on this page require the gridgain-map-structure module (the org.gridgain.structure API) in addition to the ignite-client module. For repository and dependency configuration, see Project Setup and Required Modules.

Creating Distributed Maps

To create a distributed map, use the getOrCreateMap method:

IgniteMap<Integer, String> mapFromNode2 = client2.structures().getOrCreateMap(MapConfiguration.builder("map1", Integer.class, String.class)
        .distributionZone("ZONENAME")
        .storageProfile("profileName")
        .build());
CompletableFuture<IgniteMap<Integer, String>> mapFuture = client1.structures().getOrCreateMapAsync(
        MapConfiguration.builder("map1", Integer.class, String.class)
                .distributionZone("ZONENAME")
                .storageProfile("profileName")
                .build());

Configuring Map Storage

When maps are created, they use the default storage profile and distribution zone. You can configure the following properties:

Configuration name
Description

distributionZone

The name of the distribution zone to use.

storageProfile

The name of the storage profile to use. The storage profile must be declared in the distribution zone.

The example below demonstrates how you can set configuration via Java code:

IgniteMap<Integer, String> mapFromNode2 = client2.structures().getOrCreateMap(MapConfiguration.builder("map1", Integer.class, String.class)
        .distributionZone("ZONENAME")
        .storageProfile("profileName")
        .build());
CompletableFuture<IgniteMap<Integer, String>> mapFuture = client1.structures().getOrCreateMapAsync(
        MapConfiguration.builder("map1", Integer.class, String.class)
                .distributionZone("ZONENAME")
                .storageProfile("profileName")
                .build());

Adding Data to Distributed Maps

Once the map is created, you can start putting data into it and retrieving data as needed.

Put Operations

Use put() to insert or update a value without returning the previous value:

The put() method returns void and does not retrieve the previous value, making it more efficient when you don't need the old value.

Get-and-Put Operations

Use getAndPut() when you need to insert or update a value and retrieve the previous value:

The getAndPut() method returns the previous value associated with the key, or null if there was no mapping.

Removing Data from Distributed Maps

GridGain provides several methods for removing data from distributed maps, each serving different use cases.

Remove Operations

Use remove() to delete a mapping and check if the key existed:

The remove() method returns true if the key was present and removed, or false if the key did not exist.

Get-and-Remove Operations

Use getAndRemove() when you need to delete a mapping and retrieve its value:

The getAndRemove() method returns the value that was associated with the key, or null if the key did not exist.

Batch Remove Operations

Use removeAll() to efficiently remove multiple keys in a single operation:

The removeAll() method removes all mappings for the specified keys. It is more efficient than calling remove() multiple times, as it performs the operation in a single network round-trip.

Destroying Maps

When a map is no longer needed, you can destroy it to remove all data and the map definition from the cluster.

Destroying via Map Instance

Use the destroy() method on the map instance:

Destroying by Name

You can also destroy a map by name without having a map instance:

Type Safety

GridGain ensures type safety when working with distributed maps. If you attempt to open an existing map with incompatible key or value types, a MapTypeMismatchException will be thrown with a clear error message indicating the type mismatch.

The exception message will clearly indicate which type (key or value) does not match and show both the expected and actual types.

Extended Example

The example below demonstrates how you can use data structures API to create a distributed map:

This page is: Copyright © 2026 MariaDB. All rights reserved.

Last updated

Was this helpful?