When you define related data in map sets
that are organized in the same partition, you can avoid data duplication
and allow for fine-grained data access.
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:
Procedure
- Implement the PartitionableKey interface to collocate related
data in multiple maps in the same partition.
The PartitionableKey
mixin interface is used for custom key classes. The key that you
use for partition routing is embedded in the key and returned by PartitionableKey.ibmGetPartition()
method. For more information, see
Routing cache objects to the same partition.
Manually
replicate reference, natively partitioned data that does not have
the ParititonableKey interface defined.
- Implement the @PartitionKey annotation
to identify one or more attributes in a custom key class that is used
in an eXtreme data format (XDF) configured map.
If you
are using an enterprise data grid, you must enable XDF so that both Java™ and .NET can access the same
data grid objects. Therefore, the Partitionkey annotation provides
an alternative to the ParittionableKey interface and allows interoperability
with the eXtreme Scale .NET Framework client.
- Use data access APIs to manage relational data by implementing
the EntityManager API.
The EntityManager API enforces partition
routing by developing a constrained tree relationship where all entities
must provide a path to the root of the tree, and the root key is used
for partition routing and is embedded in each related key.
Use the
schemaRoot configuration option to specify one root of a constrained
tree schema. For more information, see Caching objects and their relationships (EntityManager API).
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.