About this task
By defining the maps in the same map set, you can easily
store the data in a single partition. Data that is stored in a partition
can reference related data in that same partition by storing the key
of the related cache entry in the other map, or within the same map.
Use the PartitionableKey mixin interface or the DataGrid API, which
bypasses the native key routing of the cache keys. Data can also be
stored as reference data, where it is duplicated in each partition,
rather than partitioned itself.
When you used fixed-partition routing,
data is routed to the appropriate partition based on the hash code
of the key. To collocate data into the same partition, WebSphere® eXtreme Scale provides the following
methods:
Example
Data can be routed to specific partitions with the DataGrid
API, allowing storing reference data and other advanced patterns where
traditional key routing does not work. The DataGrid API is useful,
for example, to store reference data in each partition, allowing look-ups
to always be collocated with larger, partitioned data sets.
In the
following example, a customer in the data grid has one or more addresses.
However, an address has only one customer, and an address has one
country.
CustomerKey <--> AddressKey
Address -> CountryKey
CustomerKey in the Customer map
is a bidirectional one-to-many relationship with AddressKey in the
Address map. AddressKey can implement the PartitionableKey interface,
embedding the CustomerKey within it, and returning CustomerKey from
the ibmGetParittion() method. Alternatively, you can annotate the
embedded CustomerKey field in the AddressKey with the @PartitionKey
annotation when XDF is enabled.
The CountryKey can be embedded
in the Address value and the CountryKey and Country value can be stored
in each partition with the DataGrid API or a loader, overriding the
default key based routing.